diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/debugwindow.cpp | 9 | ||||
-rw-r--r-- | src/gui/gui.cpp | 2 | ||||
-rw-r--r-- | src/gui/gui.h | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 2 | ||||
-rw-r--r-- | src/gui/viewport.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/windowcontainer.cpp | 77 | ||||
-rw-r--r-- | src/gui/widgets/windowcontainer.h | 12 |
7 files changed, 104 insertions, 4 deletions
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 047e4170..3c514191 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -25,6 +25,7 @@ #include "game.h" #include "particle.h" #include "map.h" +#include "gui.h" #include "gui/setup.h" #include "gui/viewport.h" @@ -138,6 +139,7 @@ public: mBeingPath = new CheckBox(_("Being path")); mMousePath = new CheckBox(_("Mouse path")); mBeingIds = new CheckBox(_("Being Ids")); + mGuiDebug = new CheckBox(_("GUI debug")); auto *specialsLabel = new Label(_("Specials:")); mSpecialNormal = new RadioButton(_("Normal"), "mapdebug"); @@ -156,6 +158,7 @@ public: place(0, 5, mBeingPath, 1); place(0, 6, mMousePath, 1); place(0, 7, mBeingIds, 1); + place(0, 8, mGuiDebug, 1); place(1, 0, specialsLabel, 1); place(1, 1, mSpecialNormal, 1); place(1, 2, mSpecial1, 1); @@ -173,6 +176,7 @@ public: mBeingPath->addActionListener(this); mMousePath->addActionListener(this); mBeingIds->addActionListener(this); + mGuiDebug->addActionListener(this); mSpecialNormal->addActionListener(this); mSpecial1->addActionListener(this); mSpecial2->addActionListener(this); @@ -204,7 +208,9 @@ public: if (mSpecial3->isSelected()) flags |= Map::DEBUG_SPECIAL3; - viewport->setShowDebugPath(flags); + viewport->setDebugFlags(flags); + + Gui::debugDraw = mGuiDebug->isSelected(); } private: @@ -215,6 +221,7 @@ private: CheckBox *mBeingPath; CheckBox *mMousePath; CheckBox *mBeingIds; + CheckBox *mGuiDebug; RadioButton *mSpecialNormal; RadioButton *mSpecial1; RadioButton *mSpecial2; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index dd637170..93037db2 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -53,6 +53,8 @@ gcn::Font *boldFont = nullptr; // Mono font gcn::Font *monoFont = nullptr; +bool Gui::debugDraw; + Gui::Gui(Graphics *graphics) : mCustomCursorScale(graphics->getScale()) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 62a0b3aa..1cba3fbc 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -116,6 +116,8 @@ class Gui final : public gcn::Gui, public EventListener */ void setCursorType(Cursor cursor); + static bool debugDraw; + protected: void handleMouseMoved(const gcn::MouseInput &mouseInput) override; void handleTextInput(const TextInput &textInput); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 10c4bc1a..f02d2973 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -607,7 +607,7 @@ void Viewport::updateCursorType() } } -void Viewport::setShowDebugPath(int debugFlags) +void Viewport::setDebugFlags(int debugFlags) { mDebugFlags = debugFlags; if (mMap) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 6ea74b5e..32d9bd5c 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -77,9 +77,9 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void logic() override; /** - * Sets whether the path debug graphics are shown + * Sets which debug flags (see Map::DebugFlags) should be enabled. */ - void setShowDebugPath(int debugFlags); + void setDebugFlags(int debugFlags); /** * Handles mouse press on map. diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp index 8cee550b..36f0998f 100644 --- a/src/gui/widgets/windowcontainer.cpp +++ b/src/gui/widgets/windowcontainer.cpp @@ -21,10 +21,13 @@ #include "gui/widgets/windowcontainer.h" +#include "gui/gui.h" #include "gui/widgets/window.h" #include "utils/dtor.h" +#include <guichan/focushandler.hpp> + WindowContainer *windowContainer = nullptr; void WindowContainer::logic() @@ -35,6 +38,14 @@ void WindowContainer::logic() gcn::Container::logic(); } +void WindowContainer::draw(gcn::Graphics *graphics) +{ + gcn::Container::draw(graphics); + + if (Gui::debugDraw) + debugDraw(graphics); +} + void WindowContainer::scheduleDelete(gcn::Widget *widget) { mDeathList.push_back(widget); @@ -47,3 +58,69 @@ void WindowContainer::adjustAfterResize(int oldScreenWidth, if (auto *window = dynamic_cast<Window*>(widget)) window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight); } + +void WindowContainer::debugDraw(gcn::Graphics *graphics) +{ + auto focusHandler = _getFocusHandler(); + auto focused = focusHandler->getFocused(); + auto modalFocused = focusHandler->getModalFocused(); + auto modalMouseFocused = focusHandler->getModalMouseInputFocused(); + + for (auto widget : gcn::Widget::mWidgets) + { + if (!widgetIsVisible(widget)) + continue; + + int x; + int y; + widget->getAbsolutePosition(x, y); + + if (widget == modalMouseFocused) + { + graphics->setColor(gcn::Color(0, 255, 0, 128)); + graphics->fillRectangle(gcn::Rectangle(x, y, + widget->getWidth(), + widget->getHeight())); + } + + if (widget == modalFocused) + { + graphics->setColor(gcn::Color(255, 0, 0, 128)); + graphics->fillRectangle(gcn::Rectangle(x, y, + widget->getWidth(), + widget->getHeight())); + } + + if (widget == focused) + { + graphics->setColor(gcn::Color(255, 0, 0, 32)); + graphics->fillRectangle(gcn::Rectangle(x, y, + widget->getWidth(), + widget->getHeight())); + } + + graphics->setColor(gcn::Color(255, 0, 0)); + graphics->drawRectangle(gcn::Rectangle(x, y, + widget->getWidth(), + widget->getHeight())); + } +} + +/** + * Returns whether the widget is visible and part of the hierarchy. + */ +bool WindowContainer::widgetIsVisible(gcn::Widget *widget) +{ + if (!widget->isVisible()) + return false; + + while (widget) + { + if (widget == this) + return true; + + widget = widget->getParent(); + } + + return false; +} diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index 646e5d00..861839c9 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -40,6 +40,11 @@ class WindowContainer : public Container void logic() override; /** + * Adds debug drawing. + */ + void draw(gcn::Graphics *graphics) override; + + /** * Schedule a widget for deletion. It will be deleted at the start of * the next logic update. */ @@ -53,6 +58,13 @@ class WindowContainer : public Container private: /** + * Draws the outlines of the container and all its children. + */ + void debugDraw(gcn::Graphics *graphics); + + bool widgetIsVisible(gcn::Widget *widget); + + /** * List of widgets that are scheduled to be deleted. */ std::list<gcn::Widget *> mDeathList; |