diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-10 12:43:27 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-25 14:05:30 +0000 |
commit | ca29443d65152fde5ad960f5c02b5fc0f2dd378f (patch) | |
tree | d92aa74f5a01fc04e67dbb6ac4cdddbc60033ebd | |
parent | cd5aebcdd3443b1be8fe5fe177df058879512307 (diff) | |
download | mana-ca29443d65152fde5ad960f5c02b5fc0f2dd378f.tar.gz mana-ca29443d65152fde5ad960f5c02b5fc0f2dd378f.tar.bz2 mana-ca29443d65152fde5ad960f5c02b5fc0f2dd378f.tar.xz mana-ca29443d65152fde5ad960f5c02b5fc0f2dd378f.zip |
GUI: Added support for hiding the scroll area buttons
And made the Jewelry theme hide those buttons.
-rw-r--r-- | data/graphics/gui/jewelry/theme.xml | 2 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 129 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.h | 18 | ||||
-rw-r--r-- | src/resources/theme.cpp | 1 | ||||
-rw-r--r-- | src/resources/theme.h | 1 |
5 files changed, 141 insertions, 10 deletions
diff --git a/data/graphics/gui/jewelry/theme.xml b/data/graphics/gui/jewelry/theme.xml index ea173658..15db87fb 100644 --- a/data/graphics/gui/jewelry/theme.xml +++ b/data/graphics/gui/jewelry/theme.xml @@ -227,7 +227,7 @@ </state> </skin> - <skin type="ScrollArea" frameSize="3" padding="4" baseColor="#f1d9a9"> + <skin type="ScrollArea" frameSize="3" padding="4" baseColor="#f1d9a9" showButtons="false"> <state> <img src="window.png" x="1" y="186" width="32" height="31" left="4" right="4" top="4" bottom="4" /> </state> diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index a7e94971..095dc209 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -43,6 +43,11 @@ ScrollArea::~ScrollArea() delete getContent(); } +void ScrollArea::setShowButtons(bool showButtons) +{ + mShowButtons = showButtons; +} + void ScrollArea::init() { // Draw background by default @@ -54,8 +59,11 @@ void ScrollArea::init() if (scrollBarWidth > 0) setScrollbarWidth(scrollBarWidth); + auto &scrollAreaSkin = theme->getSkin(SkinType::ScrollArea); + setShowButtons(scrollAreaSkin.showButtons); + if (auto content = getContent()) - content->setFrameSize(theme->getSkin(SkinType::ScrollArea).padding); + content->setFrameSize(scrollAreaSkin.padding); // The base color is only used when rendering a square in the corner where // the scrollbars meet. We disable rendering of this square by setting the @@ -161,21 +169,33 @@ void ScrollArea::drawBackground(gcn::Graphics *graphics) void ScrollArea::drawUpButton(gcn::Graphics *graphics) { + if (!mShowButtons) + return; + drawButton(graphics, SkinType::ButtonUp, mUpButtonPressed, getUpButtonDimension()); } void ScrollArea::drawDownButton(gcn::Graphics *graphics) { + if (!mShowButtons) + return; + drawButton(graphics, SkinType::ButtonDown, mDownButtonPressed, getDownButtonDimension()); } void ScrollArea::drawLeftButton(gcn::Graphics *graphics) { + if (!mShowButtons) + return; + drawButton(graphics, SkinType::ButtonLeft, mLeftButtonPressed, getLeftButtonDimension()); } void ScrollArea::drawRightButton(gcn::Graphics *graphics) { + if (!mShowButtons) + return; + drawButton(graphics, SkinType::ButtonRight, mRightButtonPressed, getRightButtonDimension()); } @@ -471,26 +491,115 @@ void ScrollArea::mouseDragged(gcn::MouseEvent &mouseEvent) mouseEvent.consume(); } +gcn::Rectangle ScrollArea::getUpButtonDimension() +{ + if (!mVBarVisible || !mShowButtons) + return gcn::Rectangle(); + + return gcn::Rectangle(getWidth() - mScrollbarWidth, 0, mScrollbarWidth, mScrollbarWidth); +} + +gcn::Rectangle ScrollArea::getDownButtonDimension() +{ + if (!mVBarVisible || !mShowButtons) + return gcn::Rectangle(); + + gcn::Rectangle dim(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + + if (mHBarVisible) + dim.y -= mScrollbarWidth; + + return dim; +} + +gcn::Rectangle ScrollArea::getLeftButtonDimension() +{ + if (!mHBarVisible || !mShowButtons) + return gcn::Rectangle(); + + return gcn::Rectangle(0, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); +} + +gcn::Rectangle ScrollArea::getRightButtonDimension() +{ + if (!mHBarVisible || !mShowButtons) + return gcn::Rectangle(); + + gcn::Rectangle dim(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + + if (mVBarVisible) + dim.x -= mScrollbarWidth; + + return dim; +} + +gcn::Rectangle ScrollArea::getVerticalBarDimension() +{ + if (!mVBarVisible) + return gcn::Rectangle(); + + gcn::Rectangle dim(getWidth() - mScrollbarWidth, + getUpButtonDimension().height, + mScrollbarWidth, + getHeight() + - getUpButtonDimension().height + - getDownButtonDimension().height); + + if (mHBarVisible) + dim.height -= mScrollbarWidth; + + if (dim.height < 0) + dim.height = 0; + + return dim; +} + +gcn::Rectangle ScrollArea::getHorizontalBarDimension() +{ + if (!mHBarVisible) + return gcn::Rectangle(); + + gcn::Rectangle dim(getLeftButtonDimension().width, + getHeight() - mScrollbarWidth, + getWidth() + - getLeftButtonDimension().width + - getRightButtonDimension().width, + mScrollbarWidth); + + if (mVBarVisible) + dim.width -= mScrollbarWidth; + + if (dim.width < 0) + dim.width = 0; + + return dim; +} + static void getMarkerValues(int barSize, int maxScroll, int scrollAmount, int contentHeight, int viewHeight, int fixedMarkerSize, int minMarkerSize, int &markerSize, int &markerPos) { - markerSize = barSize; - markerPos = 0; - if (fixedMarkerSize == 0) { if (contentHeight != 0 && contentHeight > viewHeight) markerSize = std::max((barSize * viewHeight) / contentHeight, minMarkerSize); + else + markerSize = barSize; } else { - if (viewHeight > contentHeight) - markerSize = 0; - else + if (contentHeight > viewHeight) markerSize = fixedMarkerSize; + else + markerSize = 0; } // Hide the marker when it doesn't fit @@ -499,12 +608,14 @@ static void getMarkerValues(int barSize, if (maxScroll != 0) markerPos = ((barSize - markerSize) * scrollAmount + maxScroll / 2) / maxScroll; + else + markerPos = 0; } gcn::Rectangle ScrollArea::getVerticalMarkerDimension() { if (!mVBarVisible) - return gcn::Rectangle(0, 0, 0, 0); + return gcn::Rectangle(); auto &markerSkin = gui->getTheme()->getSkin(SkinType::ScrollAreaVMarker); const gcn::Rectangle barDim = getVerticalBarDimension(); @@ -532,7 +643,7 @@ gcn::Rectangle ScrollArea::getVerticalMarkerDimension() gcn::Rectangle ScrollArea::getHorizontalMarkerDimension() { if (!mHBarVisible) - return gcn::Rectangle(0, 0, 0, 0); + return gcn::Rectangle(); auto &markerSkin = gui->getTheme()->getSkin(SkinType::ScrollAreaHMarker); const gcn::Rectangle barDim = getHorizontalBarDimension(); diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 7cdcfa19..7ad0ed00 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -58,6 +58,11 @@ class ScrollArea : public gcn::ScrollArea ~ScrollArea() override; /** + * Sets whether the scroll bar buttons are shown. + */ + void setShowButtons(bool showButtons); + + /** * Logic function optionally adapts width or height of contents. This * depends on the scrollbar settings. */ @@ -131,6 +136,18 @@ class ScrollArea : public gcn::ScrollArea /** * Shadowing these functions from gcn::ScrollArea with versions that + * support hiding the buttons. We need to make sure we always use these + * versions. + */ + gcn::Rectangle getUpButtonDimension(); + gcn::Rectangle getDownButtonDimension(); + gcn::Rectangle getLeftButtonDimension(); + gcn::Rectangle getRightButtonDimension(); + gcn::Rectangle getVerticalBarDimension(); + gcn::Rectangle getHorizontalBarDimension(); + + /** + * Shadowing these functions from gcn::ScrollArea with versions that * supports fixed-size scroll bar markers. We need to make sure we * always use these versions. */ @@ -141,4 +158,5 @@ class ScrollArea : public gcn::ScrollArea int mY = 0; bool mHasMouse = false; bool mOpaque = true; + bool mShowButtons = true; }; diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index d4d59ede..9fb87dcd 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -498,6 +498,7 @@ void Theme::readSkinNode(XML::Node node) node.attribute("titleBarHeight", skin.titleBarHeight); node.attribute("titleOffsetX", skin.titleOffsetX); node.attribute("titleOffsetY", skin.titleOffsetY); + node.attribute("showButtons", skin.showButtons); for (auto childNode : node.children()) if (childNode.name() == "state") diff --git a/src/resources/theme.h b/src/resources/theme.h index 51f1e94f..18a0b54a 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -162,6 +162,7 @@ class Skin int titleBarHeight = 0; int titleOffsetX = 0; int titleOffsetY = 0; + bool showButtons = true; private: std::vector<SkinState> mStates; |