diff options
Diffstat (limited to 'src/gui/widgets/popup.cpp')
-rw-r--r-- | src/gui/widgets/popup.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index b7c70fe5..c4c6f652 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -22,11 +22,14 @@ #include "gui/widgets/popup.h" +#include "browserbox.h" #include "graphics.h" #include "log.h" +#include "textbox.h" #include "gui/gui.h" #include "gui/viewport.h" +#include "gui/widgets/label.h" #include "gui/widgets/windowcontainer.h" #include <guichan/exception.hpp> @@ -37,12 +40,12 @@ Popup::Popup(const std::string &name, SkinType skinType) , mMaxHeight(graphics->getHeight()) , mSkinType(skinType) { - logger->log("Popup::Popup(\"%s\")", name.c_str()); + Log::debug("Popup::Popup(\"%s\")", name.c_str()); if (!windowContainer) throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); - auto &skin = gui->getTheme()->getSkin(skinType); + auto &skin = getSkin(); setFrameSize(skin.frameSize); setPadding(skin.padding); @@ -55,7 +58,7 @@ Popup::Popup(const std::string &name, SkinType skinType) Popup::~Popup() { - logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + Log::debug("Popup::~Popup(\"%s\")", mPopupName.c_str()); } void Popup::setWindowContainer(WindowContainer *wc) @@ -63,6 +66,41 @@ void Popup::setWindowContainer(WindowContainer *wc) windowContainer = wc; } +void Popup::add(gcn::Widget *widget) +{ + Container::add(widget); + widgetAdded(widget); +} + +void Popup::add(gcn::Widget *widget, int x, int y) +{ + Container::add(widget, x, y); + widgetAdded(widget); +} + +void Popup::widgetAdded(gcn::Widget *widget) const +{ + if (const int paletteId = getSkin().palette) + { + if (auto browserBox = dynamic_cast<BrowserBox*>(widget)) + { + browserBox->setPalette(paletteId); + } + else if (auto label = dynamic_cast<Label*>(widget)) + { + auto &palette = gui->getTheme()->getPalette(paletteId); + label->setForegroundColor(palette.getColor(Theme::TEXT)); + label->setOutlineColor(palette.getOutlineColor(Theme::TEXT)); + } + else if (auto textBox = dynamic_cast<TextBox*>(widget)) + { + auto &palette = gui->getTheme()->getPalette(paletteId); + textBox->setTextColor(&palette.getColor(Theme::TEXT)); + textBox->setOutlineColor(palette.getOutlineColor(Theme::TEXT)); + } + } +} + void Popup::draw(gcn::Graphics *graphics) { if (getFrameSize() == 0) @@ -76,7 +114,7 @@ void Popup::drawFrame(gcn::Graphics *graphics) WidgetState state(this); state.width += getFrameSize() * 2; state.height += getFrameSize() * 2; - gui->getTheme()->drawSkin(static_cast<Graphics *>(graphics), mSkinType, state); + getSkin().draw(static_cast<Graphics *>(graphics), state); } gcn::Rectangle Popup::getChildrenArea() @@ -119,12 +157,12 @@ void Popup::setLocationRelativeTo(gcn::Widget *widget) void Popup::setMinWidth(int width) { - mMinWidth = std::max(gui->getTheme()->getMinWidth(mSkinType), width); + mMinWidth = std::max(getSkin().getMinWidth(), width); } void Popup::setMinHeight(int height) { - mMinHeight = std::max(gui->getTheme()->getMinHeight(mSkinType), height); + mMinHeight = std::max(getSkin().getMinHeight(), height); } void Popup::setMaxWidth(int width) @@ -159,6 +197,11 @@ void Popup::position(int x, int y) requestMoveToTop(); } +const Skin &Popup::getSkin() const +{ + return gui->getTheme()->getSkin(mSkinType); +} + void Popup::mouseMoved(gcn::MouseEvent &event) { if (viewport) |