Skip to content

Commit

Permalink
Merge pull request #49 from Jarod42/font_and_tabbarea
Browse files Browse the repository at this point in the history
Font and tabbarea
  • Loading branch information
Jarod42 authored Aug 22, 2024
2 parents d1a0b35 + 1187387 commit 1dd9960
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 43 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Version 1.1.0
=============
* TabbedArea::isOpaque and TabbedArea::setOpaque have been added to
control if a tabbed area should draw its background or not.
* ScrollArea::isOpaque and ScrollArea::setOpaque have been added to
control if a scroll area should draw its background or not.
* Widget::showPart has been added to be used when a specific
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Continue rebasing from a813cccba0894a7a027212409dc949c95409a792
* Continue rebasing from 112ad7b3be4a069c22a74e7904b109f825d7fa11
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/defaultfont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace gcn

virtual int getHeight() const;

virtual int getStringIndexAt(const std::string& text, int x);
virtual int getStringIndexAt(const std::string& text, int x) const;
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/guisan/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace gcn
*
* @return A string index in a string providing an x coordinate.
*/
virtual int getStringIndexAt(const std::string& text, int x);
virtual int getStringIndexAt(const std::string& text, int x) const;

/**
* Draws a string.
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/imagefont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode

virtual int getHeight() const;

virtual int getStringIndexAt(const std::string& text, int x);
virtual int getStringIndexAt(const std::string& text, int x) const;

protected:
/**
Expand Down
4 changes: 3 additions & 1 deletion include/guisan/widgets/tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace gcn
* An implementation of a simple tab to be used in a tabbed area.
*
* @see TabbedArea
* @since 0.8.0
*/
class GCN_CORE_DECLSPEC Tab:
public BasicContainer,
Expand All @@ -91,7 +92,8 @@ namespace gcn
virtual ~Tab();

/**
* Adjusts the size of the tab fit the caption.
* Adjusts the size of the tab to fit the caption. If this tab was
* added to a TabbedArea, it will also adjust the tab positions.
*/
void adjustSize();

Expand Down
39 changes: 36 additions & 3 deletions include/guisan/widgets/tabbedarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace gcn
/**
* An implementation of a tabbed area where a user can display a widget by
* selecting a tab.
*
* @since 0.8.0
*/
class GCN_CORE_DECLSPEC TabbedArea:
public ActionListener,
Expand All @@ -97,7 +99,32 @@ namespace gcn
virtual ~TabbedArea();

/**
* Adds a tab to the tabbed area.
* Sets the tabbed area to be opaque or not. If the tabbed area is
* opaque its background will be drawn, if it's not opaque its
* background will not be drawn. By default, a tabbed area is not
* opaque.
*
* The tabbed area's background is normally only visible behind the
* tabs, since the container holding the tab contents is opaque by
* default.
*
* @param opaque True if the tabbed area should be opaque, false
* otherwise.
* @see isOpaque
*/
void setOpaque(bool opaque);

/**
* Checks if the tabbed area is opaque or not.
*
* @return true if the tabbed area is opaque, false otherwise.
* @see setOpaque
*/
bool isOpaque() const;

/**
* Adds a tab to the tabbed area. The newly created tab will be
* automatically deleted by the tabbed area when it is removed.
*
* @param caption The caption of the tab to add.
* @param widget The widget to view when the tab is selected.
Expand All @@ -106,7 +133,8 @@ namespace gcn
virtual void addTab(const std::string& caption, Widget* widget);

/**
* Adds a tab to the tabbed area.
* Adds a tab to the tabbed area. The tab will not be deleted by the
* tabbed area when it is removed.
*
* @param tab The tab widget for the tab.
* @param widget The widget to view when the tab is selected.
Expand Down Expand Up @@ -217,7 +245,7 @@ namespace gcn

protected:
/**
* Adjusts the size of the tabbed area.
* Adjusts the size of the tab container and the widget container.
*/
void adjustSize();

Expand Down Expand Up @@ -253,6 +281,11 @@ namespace gcn
* tab is selected.
*/
std::vector<std::pair<Tab*, Widget*> > mTabs;

/**
* True if the tabbed area is opaque, false otherwise.
*/
bool mOpaque;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/defaultfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace gcn
}
}

int DefaultFont::getStringIndexAt(const std::string& text, int x)
int DefaultFont::getStringIndexAt(const std::string& text, int x) const
{
if (x > (int)text.size() * 8)
{
Expand Down
2 changes: 1 addition & 1 deletion src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

namespace gcn
{
int Font::getStringIndexAt(const std::string& text, int x)
int Font::getStringIndexAt(const std::string& text, int x) const
{
unsigned int i;
int size = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/imagefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace gcn
return size - mGlyphSpacing;
}

int ImageFont::getStringIndexAt(const std::string& text, int x)
int ImageFont::getStringIndexAt(const std::string& text, int x) const
{
unsigned int i;
int size = 0;
Expand Down
21 changes: 4 additions & 17 deletions src/widgets/scrollarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,23 +986,10 @@ namespace gcn

Rectangle ScrollArea::getChildrenArea()
{
if (mVBarVisible && mHBarVisible)
{
return Rectangle(0, 0, getWidth() - mScrollbarWidth,
getHeight() - mScrollbarWidth);
}

if (mVBarVisible)
{
return Rectangle(0, 0, getWidth() - mScrollbarWidth, getHeight());
}

if (mHBarVisible)
{
return Rectangle(0, 0, getWidth(), getHeight() - mScrollbarWidth);
}

return Rectangle(0, 0, getWidth(), getHeight());
return Rectangle(0,
0,
getWidth() - (mVBarVisible ? mScrollbarWidth : 0),
getHeight() - (mHBarVisible ? mScrollbarWidth : 0));
}

Rectangle ScrollArea::getVerticalBarDimension()
Expand Down
36 changes: 21 additions & 15 deletions src/widgets/tabbedarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@

namespace gcn
{
TabbedArea::TabbedArea()
:mSelectedTab(NULL)
TabbedArea::TabbedArea() : mSelectedTab(NULL), mOpaque(false)
{
setFrameSize(1);
setFocusable(true);
Expand All @@ -96,8 +95,7 @@ namespace gcn
delete mTabContainer;
delete mWidgetContainer;

unsigned int i;
for (i = 0; i < mTabsToDelete.size(); i++)
for (unsigned int i = 0; i < mTabsToDelete.size(); i++)
{
delete mTabsToDelete[i];
}
Expand Down Expand Up @@ -264,6 +262,15 @@ namespace gcn
return mSelectedTab;
}

void TabbedArea::setOpaque(bool opaque)
{
mOpaque = opaque;
}

bool TabbedArea::isOpaque() const
{
return mOpaque;
}

void TabbedArea::draw(Graphics *graphics)
{
Expand All @@ -282,8 +289,11 @@ namespace gcn
getWidth() - 1, mTabContainer->getHeight() + 1, getWidth() - 1, getHeight() - 1);
graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

graphics->setColor(getBaseColor());
graphics->fillRectangle(Rectangle(1, 1, getWidth() - 2, getHeight() - 2));
if (mOpaque)
{
graphics->setColor(getBaseColor());
graphics->fillRectangle(Rectangle(1, 1, getWidth() - 2, getHeight() - 2));
}

// Draw a line underneath the tabs.
graphics->setColor(highlightColor);
Expand All @@ -309,14 +319,12 @@ namespace gcn

void TabbedArea::logic()
{

}

void TabbedArea::adjustSize()
{
int maxTabHeight = 0;
unsigned int i;
for (i = 0; i < mTabs.size(); i++)
for (unsigned int i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
{
Expand Down Expand Up @@ -367,16 +375,14 @@ namespace gcn

void TabbedArea::setSize(int width, int height)
{
setWidth(width);
setHeight(height);
Widget::setSize(width, height);
adjustSize();
}

void TabbedArea::setDimension(const Rectangle& dimension)
{
setX(dimension.x);
setY(dimension.y);
setWidth(dimension.width);
setHeight(dimension.height);
Widget::setDimension(dimension);
adjustSize();
}

void TabbedArea::keyPressed(KeyEvent& keyEvent)
Expand Down

0 comments on commit 1dd9960

Please sign in to comment.