Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into original
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Sep 18, 2024
2 parents 582d2db + 9fa5873 commit 72031ba
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 33 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Version 1.1.0
=============
* SDLImage::convertToDisplayFormat now throws an exception if conversion fails.
* Fixed text drawn outside of a TextField.
* Fixed focus issues when having a TextField inside a Tab.
* Fixed selecting with arrow keys when DropDown is open skipping items
* Fixed DropDown inside a TabbedArea looking odd when dropped down.
* BasicContainer and Widget has been merged making every Widget
a possible container. The merge makes it a lot easier to
implement container widgets. With the merge there is no need
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
* Continue rebasing from 636e1837a62cb3126d6a8554856c1219160161a9
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
24 changes: 15 additions & 9 deletions include/guisan/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ namespace gcn
/**
* @mainpage
* @section Introduction
* This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release.
* This documentation is mostly intended as a reference to the API.
* If you want to get started with Guisan,
* we suggest you check out the programs
* in the examples directory of the Guisan release.
* @n
* @n
* This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us.
* This documentation is, and will always be, work in progress.
* If you find any errors, typos or inconsistencies,
* or if you feel something needs to be explained in more detail,
* don't hesitate to tell us.
*/

/**
* Contains a Guisan GUI. This is the core class of Guisan to which
* implementations of back ends are passed, to make Guisan work with
* a specific library, and to where the top widget (root widget of GUI)
* is added. If you want to be able to have more then one widget in your
* is added. If you want to be able to have more then one widget in your
* GUI, the top widget should be a container.
*
* A Gui object cannot work properly without passing back end
Expand Down Expand Up @@ -300,7 +306,7 @@ namespace gcn
virtual void handleMouseReleased(const MouseInput& mouseInput);

/**
* Handles modal focus. Modal focus needs to be checked at
* Handles modal focus. Modal focus needs to be checked at
* each logic iteration as it might be necessary to distribute
* mouse entered or mouse exited events.
*
Expand All @@ -309,24 +315,24 @@ namespace gcn
virtual void handleModalFocus();

/**
* Handles modal mouse input focus. Modal mouse input focus needs
* to be checked at each logic iteration as it might be necessary to
* Handles modal mouse input focus. Modal mouse input focus needs
* to be checked at each logic iteration as it might be necessary to
* distribute mouse entered or mouse exited events.
*
* @since 0.8.0
*/
virtual void handleModalMouseInputFocus();

/**
* Handles modal focus gained. If modal focus has been gaind it might
* Handles modal focus gained. If modal focus has been gained it might
* be necessary to distribute mouse entered or mouse exited events.
*
* @since 0.8.0
*/
virtual void handleModalFocusGained();

/**
* Handles modal mouse input focus gained. If modal focus has been gaind
* Handles modal mouse input focus gained. If modal focus has been gained
* it might be necessary to distribute mouse entered or mouse exited events.
*
* @since 0.8.0
Expand All @@ -343,7 +349,7 @@ namespace gcn
* @param fource indicates whether the distribution should be forced or not.
* A forced distribution distributes the event even if a widget
* is not enabled, not visible, another widget has modal
* focus or another widget has modal mouse input focus.
* focus or another widget has modal mouse input focus.
* Default value is false.
* @param toSourceOnly indicates whether the distribution should be to the
* source widget only or to it's parent's mouse listeners
Expand Down
3 changes: 2 additions & 1 deletion include/guisan/key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ namespace gcn
Space = ' ',
Tab = '\t',
Enter = '\n',
LeftAlt = 1000,
// Negative values, to avoid conflicts with higher character codes
LeftAlt = -1000,
RightAlt,
LeftShift,
RightShift,
Expand Down
6 changes: 3 additions & 3 deletions include/guisan/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,19 @@ namespace gcn
* Holds the position of the caret. This variable should
* always be valid.
*/
unsigned int mCaretPosition;
unsigned int mCaretPosition = 0;

/**
* Holds the row the caret is in. This variable should always
* be valid.
*/
unsigned int mCaretRow;
unsigned int mCaretRow = 0;

/**
* Holds the column the caret is in. This variable should always
* be valid.
*/
unsigned int mCaretColumn;
unsigned int mCaretColumn = 0;
};
} // namespace gcn
#endif
19 changes: 19 additions & 0 deletions include/guisan/widgets/tabbedarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ namespace gcn
*/
bool isOpaque() const;

/**
* Checks if the tabbed area is active or not.
*
* @return true if the tabbed area is active, false otherwise.
*/
bool isTabActive() const;

/**
* Adds a tab to the tabbed area. The newly created tab will be
* automatically deleted by the tabbed area when it is removed.
Expand Down Expand Up @@ -158,6 +165,13 @@ namespace gcn
*/
virtual void removeTab(Tab* tab);

/**
* Returns the number of tabs in this tabbed area.
*
* @since 1.1.0
*/
int getNumberOfTabs() const;

/**
* Checks if a tab given an index is selected or not.
*
Expand Down Expand Up @@ -286,6 +300,11 @@ namespace gcn
* True if the tabbed area is opaque, false otherwise.
*/
bool mOpaque;

/**
* True if the tabbed area is active, false otherwise.
*/
bool tabActive;
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/sdl/sdlimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ namespace gcn
SDL_FreeSurface(mSurface);
mSurface = NULL;

if (tmp == NULL)
{
throw GCN_EXCEPTION("Unable to convert image to display format.");
}

if (hasPink)
{
SDL_SetColorKey(tmp, SDL_TRUE,
Expand All @@ -191,7 +196,7 @@ namespace gcn
SDL_SetTextureBlendMode(tmpTexture, SDL_BLENDMODE_BLEND);
SDL_DestroyTexture(mTexture);
mTexture = tmpTexture;
}
}
}

void SDLImage::free()
Expand Down
4 changes: 2 additions & 2 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@

namespace gcn
{
Text::Text() : mCaretPosition(0), mCaretColumn(0), mCaretRow(0)
Text::Text()
{
mRows.emplace_back();
}

Text::Text(const std::string& content) : mCaretPosition(0), mCaretColumn(0), mCaretRow(0)
Text::Text(const std::string& content)
{
std::string::size_type pos, lastPos = 0;
int length;
Expand Down
11 changes: 4 additions & 7 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,7 @@ namespace gcn
x -= r.x;
y -= r.y;

std::list<Widget*>::const_reverse_iterator iter;
for (iter = mChildren.rbegin(); iter != mChildren.rend(); iter++)
for (auto iter = mChildren.rbegin(); iter != mChildren.rend(); ++iter)
{
Widget* widget = (*iter);
if (widget->isVisible() && widget->getDimension().isContaining(x, y))
Expand Down Expand Up @@ -1016,17 +1015,15 @@ namespace gcn

void Widget::focusPrevious()
{
std::list<Widget*>::const_reverse_iterator iter;

for (iter = mChildren.rbegin(); iter != mChildren.rend(); iter++)
auto iter = mChildren.rbegin();
for (; iter != mChildren.rend(); ++iter)
{
if ((*iter)->isFocused())
{
break;
}
}

std::list<Widget*>::const_reverse_iterator end = iter;
const auto end = iter;
iter++;

if (iter == mChildren.rend())
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ namespace gcn

void Button::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
{
return;
}
if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = true;
Expand Down
10 changes: 7 additions & 3 deletions src/widgets/tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace gcn
Tab::Tab() : mTabbedArea(NULL), mHasMouse(false)
{
mLabel = new Label();
mLabel->setPosition(4, 4);
mLabel->setPosition(6, 6);
add(mLabel);
setFrameSize(1);

Expand All @@ -85,7 +85,7 @@ namespace gcn

void Tab::adjustSize()
{
setSize(mLabel->getWidth() + 8, mLabel->getHeight() + 8);
setSize(mLabel->getWidth() + 12, mLabel->getHeight() + 12);

if (mTabbedArea != NULL)
{
Expand Down Expand Up @@ -159,12 +159,16 @@ namespace gcn
graphics->setColor(baseColor);
graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height));

if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this))
if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this)
// && mHasMouse)
&& mTabbedArea->isTabActive())
{
graphics->setColor(Color(0x000000));
graphics->drawRectangle(
Rectangle(2, 2, currentClipArea.width - 4, currentClipArea.height - 4));
}
mLabel->setAlignment(Graphics::Center);
mLabel->_draw(graphics);
graphics->popClipArea();
}

Expand Down
41 changes: 35 additions & 6 deletions src/widgets/tabbedarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ namespace gcn
adjustTabPositions();
}

int TabbedArea::getNumberOfTabs() const
{
return mTabs.size();
}

bool TabbedArea::isTabSelected(unsigned int index) const
{
if (index >= mTabs.size())
Expand Down Expand Up @@ -272,6 +277,11 @@ namespace gcn
return mOpaque;
}

bool TabbedArea::isTabActive() const
{
return tabActive;
}

void TabbedArea::draw(Graphics *graphics)
{
const Color& faceColor = getBaseColor();
Expand Down Expand Up @@ -313,7 +323,15 @@ namespace gcn
mTabContainer->getHeight());
}

//drawChildren(graphics);
// Draw the widget from a select tab.
for (const auto& p : mTabs)
{
p.first->_draw(graphics);
if (p.first == mSelectedTab)
{
p.second->_draw(graphics);
}
}
}

void TabbedArea::adjustSize()
Expand Down Expand Up @@ -351,8 +369,11 @@ namespace gcn
Tab* tab = mTabs[i].first;

tab->setPosition(x, maxTabHeight - tab->getHeight());

x += tab->getWidth();

Widget* widget = mTabs[i].second;
widget->setX(mWidgetContainer->getX());
widget->setY(mWidgetContainer->getY());
}
}

Expand Down Expand Up @@ -461,6 +482,17 @@ namespace gcn
if (tab != NULL)
{
setSelectedTab(tab);
tabActive = true;
mouseEvent.consume();
}
else
{
widget = mWidgetContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY());
if (widget == NULL)
{
mouseEvent.consume();
}
tabActive = false;
}
}

Expand All @@ -475,10 +507,7 @@ namespace gcn

void TabbedArea::death(const Event& event)
{
Widget* source = event.getSource();
Tab* tab = dynamic_cast<Tab*>(source);

if (tab != NULL)
if (Tab* tab = dynamic_cast<Tab*>(event.getSource()))
{
removeTab(tab);
}
Expand Down

0 comments on commit 72031ba

Please sign in to comment.