diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-04 14:36:43 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-25 14:05:30 +0000 |
commit | 1c83a844551eadfb4db80258b9b3b55d97bbfe54 (patch) | |
tree | fb8a131ae24bfbf9723b2d7e330fcc203594941e | |
parent | 8c5d87b4068be6e92223fdf7960613aec1f1d3f3 (diff) | |
download | mana-1c83a844551eadfb4db80258b9b3b55d97bbfe54.tar.gz mana-1c83a844551eadfb4db80258b9b3b55d97bbfe54.tar.bz2 mana-1c83a844551eadfb4db80258b9b3b55d97bbfe54.tar.xz mana-1c83a844551eadfb4db80258b9b3b55d97bbfe54.zip |
GUI: Allow customizing the SkinType used by a Window
Now different windows can use different skin types. This also introduces
a new ToolWindow skin type, which is generally a window without title
bar nor close button. Customized windows are:
* Chat -> Popup skin
* MiniMap -> Popup skin
* ShortcutWindow (items and emotes) -> ToolWindow skin
Even though the MiniMap now appears as a Popup, it does have a title, so
appropriate attributes have been added to this skin type.
-rw-r--r-- | data/graphics/gui/jewelry/theme.xml | 11 | ||||
-rw-r--r-- | data/graphics/gui/theme.xml | 8 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 10 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 2 | ||||
-rw-r--r-- | src/gui/shortcutwindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 15 | ||||
-rw-r--r-- | src/resources/theme.cpp | 1 | ||||
-rw-r--r-- | src/resources/theme.h | 1 |
9 files changed, 50 insertions, 16 deletions
diff --git a/data/graphics/gui/jewelry/theme.xml b/data/graphics/gui/jewelry/theme.xml index 352f04c2..c90c59e9 100644 --- a/data/graphics/gui/jewelry/theme.xml +++ b/data/graphics/gui/jewelry/theme.xml @@ -123,15 +123,22 @@ </state> </skin> + <skin type="ToolWindow" padding="9" titleBarHeight="18"> + <state> + <img src="window.png" x="220" y="148" width="107" height="42" left="9" right="9" top="9" bottom="9" /> + </state> + </skin> + <skin type="ResizeGrip" padding="2"> <state> <img src="window.png" x="328" y="89" width="15" height="15" /> </state> </skin> - <skin type="Popup" padding="9"> + <skin type="Popup" padding="9" titleBarHeight="26" titleOffsetX="8" titleOffsetY="8"> <state> - <img src="window.png" x="221" y="106" width="105" height="42" left="7" right="7" top="7" bottom="7" /> + <text color="#f1d9a9" outlineColor="#000000"/> + <img src="window.png" x="220" y="106" width="107" height="42" left="9" right="9" top="9" bottom="9" /> </state> </skin> diff --git a/data/graphics/gui/theme.xml b/data/graphics/gui/theme.xml index b0484c45..1b790569 100644 --- a/data/graphics/gui/theme.xml +++ b/data/graphics/gui/theme.xml @@ -51,13 +51,19 @@ </state> </skin> + <skin type="ToolWindow" frameSize="0" padding="3" titleBarHeight="20" titleOffsetX="7" titleOffsetY="5"> + <state> + <img src="window.png" left="4" right="4" top="4" bottom="4" fill="repeat" /> + </state> + </skin> + <skin type="ResizeGrip" padding="3"> <state> <img src="resize.png" /> </state> </skin> - <skin type="Popup" padding="6"> + <skin type="Popup" padding="6" titleBarHeight="20" titleOffsetX="7" titleOffsetY="5"> <state> <img src="window.png" left="4" right="4" top="4" bottom="4" fill="repeat" /> </state> diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 8a34c961..ba11096c 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -82,7 +82,7 @@ class ChatAutoComplete : public AutoCompleteLister }; ChatWindow::ChatWindow(): - Window(_("Chat")), + Window(SkinType::Popup, _("Chat")), mItemLinkHandler(new ItemLinkHandler(this)), mChatInput(new ChatInput), mAutoComplete(new ChatAutoComplete), @@ -108,9 +108,13 @@ ChatWindow::ChatWindow(): mChatInput->setActionEventId("chatinput"); mChatInput->addActionListener(this); - getLayout().setPadding(3); + // Override the padding from the theme since we want the content very close + // to the border on this window. + setPadding(std::min<unsigned>(getPadding(), 6)); + getLayout().setPadding(0); + place(0, 0, mChatTabs, 3, 3); - place(0, 3, mChatInput, 3); + place(0, 3, mChatInput, 3).setPadding(mChatInput->getFrameSize()); loadWindowState(); diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 8924bc26..60bfadfa 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -41,7 +41,7 @@ #include <guichan/font.hpp> Minimap::Minimap(): - Window(_("Map")) + Window(SkinType::Popup, _("Map")) { setWindowName("Minimap"); setDefaultSize(5, 25, 100, 100); diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index 82c7678e..2cffbb81 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -31,6 +31,7 @@ static constexpr int GRAB_MARGIN = 4; ShortcutWindow::ShortcutWindow(const std::string &title, ShortcutContainer *content) + : Window(SkinType::ToolWindow, std::string()) { setWindowName(title); // no title presented, title bar gets some extra space so window can be moved. diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 61ed7896..94262f47 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -32,8 +32,6 @@ #include "gui/widgets/resizegrip.h" #include "gui/widgets/windowcontainer.h" -#include "resources/theme.h" - #include <guichan/exception.hpp> #include <guichan/focushandler.hpp> @@ -44,9 +42,14 @@ int Window::instances = 0; int Window::mouseResize = 0; Window::Window(const std::string &caption, bool modal, Window *parent) + : Window(SkinType::Window, caption, modal, parent) +{} + +Window::Window(SkinType skinType, const std::string &caption, bool modal, Window *parent) : gcn::Window(caption) , mParent(parent) , mModal(modal) + , mSkinType(skinType) , mMaxWinWidth(graphics->getWidth()) , mMaxWinHeight(graphics->getHeight()) { @@ -57,7 +60,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent) instances++; - auto &skin = gui->getTheme()->getSkin(SkinType::Window); + auto &skin = gui->getTheme()->getSkin(mSkinType); setFrameSize(skin.frameSize); setPadding(skin.padding); setTitleBarHeight(skin.titleBarHeight); @@ -129,7 +132,7 @@ void Window::drawFrame(gcn::Graphics *graphics) widgetState.width += getFrameSize() * 2; widgetState.height += getFrameSize() * 2; - auto &skin = theme->getSkin(SkinType::Window); + auto &skin = theme->getSkin(mSkinType); skin.draw(g, widgetState); if (mShowTitle) @@ -169,7 +172,7 @@ void Window::setMinimumContentSize(int width, int height) { const int padding = getPadding(); const int titleBarHeight = getTitleBarHeight(); - auto &skin = gui->getTheme()->getSkin(SkinType::Window); + auto &skin = gui->getTheme()->getSkin(mSkinType); setMinWidth(std::max(skin.getMinWidth(), width + 2 * padding)); setMinHeight(std::max(skin.getMinHeight(), height + padding + titleBarHeight)); @@ -237,12 +240,12 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, void Window::setMinWidth(int width) { - mMinWinWidth = std::max(gui->getTheme()->getMinWidth(SkinType::Window), width); + mMinWinWidth = std::max(gui->getTheme()->getMinWidth(mSkinType), width); } void Window::setMinHeight(int height) { - mMinWinHeight = std::max(gui->getTheme()->getMinHeight(SkinType::Window), height); + mMinWinHeight = std::max(gui->getTheme()->getMinHeight(mSkinType), height); } void Window::setMaxWidth(int width) diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index bf459a32..e9efa3a7 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -24,8 +24,9 @@ #include "graphics.h" #include "guichanfwd.h" -#include <guichan/widgetlistener.hpp> +#include "resources/theme.h" +#include <guichan/widgetlistener.hpp> #include <guichan/widgets/window.hpp> class ContainerPlacer; @@ -54,7 +55,16 @@ class Window : public gcn::Window, gcn::WidgetListener * this one in the window hiearchy. When reordering, * a window will never go below its parent window. */ - Window(const std::string &caption = "Window", bool modal = false, + Window(const std::string &caption = "Window", + bool modal = false, + Window *parent = nullptr); + + /** + * Constructor that allows customizing the SkinType used by the window. + */ + Window(SkinType skinType, + const std::string &caption = "Window", + bool modal = false, Window *parent = nullptr); /** @@ -400,6 +410,7 @@ class Window : public gcn::Window, gcn::WidgetListener bool mSaveVisible = false; /**< Window will save visibility */ bool mStickyButton = false; /**< Window has a sticky button */ bool mSticky = false; /**< Window resists hiding*/ + SkinType mSkinType; /**< The skin type used when drawing the window. */ int mMinWinWidth = 100; /**< Minimum window width */ int mMinWinHeight = 40; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 694f2210..ca39bbea 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -434,6 +434,7 @@ bool Theme::readTheme(const std::string &filename) static std::optional<SkinType> readSkinType(std::string_view type) { if (type == "Window") return SkinType::Window; + if (type == "ToolWindow") return SkinType::ToolWindow; if (type == "Popup") return SkinType::Popup; if (type == "SpeechBubble") return SkinType::SpeechBubble; if (type == "Button") return SkinType::Button; diff --git a/src/resources/theme.h b/src/resources/theme.h index 6d71b067..43057a39 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -47,6 +47,7 @@ class ProgressBar; enum class SkinType { Window, + ToolWindow, Popup, SpeechBubble, Button, |