Mana
Loading...
Searching...
No Matches
windowcontainer.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "gui/gui.h"
25#include "gui/widgets/window.h"
26
27#include <guichan/focushandler.hpp>
28
30
32{
33 for (auto widget : mScheduledDeletions)
34 delete widget;
35 mScheduledDeletions.clear();
36
37 gcn::Container::logic();
38}
39
40void WindowContainer::draw(gcn::Graphics *graphics)
41{
42 gcn::Container::draw(graphics);
43
46}
47
48void WindowContainer::scheduleDelete(gcn::Widget *widget)
49{
50 mScheduledDeletions.insert(widget);
51}
52
53void WindowContainer::adjustAfterResize(int oldScreenWidth,
54 int oldScreenHeight)
55{
56 for (auto &widget : mWidgets)
57 if (auto *window = dynamic_cast<Window*>(widget))
58 window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
59}
60
62{
63 auto focusHandler = _getFocusHandler();
64 auto focused = focusHandler->getFocused();
65 auto modalFocused = focusHandler->getModalFocused();
66 auto modalMouseFocused = focusHandler->getModalMouseInputFocused();
67
68 for (auto widget : gcn::Widget::mWidgets)
69 {
70 if (!widgetIsVisible(widget))
71 continue;
72
73 int x;
74 int y;
75 widget->getAbsolutePosition(x, y);
76
77 if (widget == modalMouseFocused)
78 {
79 graphics->setColor(gcn::Color(0, 255, 0, 128));
80 graphics->fillRectangle(gcn::Rectangle(x, y,
81 widget->getWidth(),
82 widget->getHeight()));
83 }
84
85 if (widget == modalFocused)
86 {
87 graphics->setColor(gcn::Color(255, 0, 0, 128));
88 graphics->fillRectangle(gcn::Rectangle(x, y,
89 widget->getWidth(),
90 widget->getHeight()));
91 }
92
93 if (widget == focused)
94 {
95 graphics->setColor(gcn::Color(255, 0, 0, 32));
96 graphics->fillRectangle(gcn::Rectangle(x, y,
97 widget->getWidth(),
98 widget->getHeight()));
99 }
100
101 graphics->setColor(gcn::Color(255, 0, 0));
102 graphics->drawRectangle(gcn::Rectangle(x, y,
103 widget->getWidth(),
104 widget->getHeight()));
105 }
106}
107
111bool WindowContainer::widgetIsVisible(gcn::Widget *widget)
112{
113 if (!widget->isVisible())
114 return false;
115
116 while (widget)
117 {
118 if (widget == this)
119 return true;
120
121 widget = widget->getParent();
122 }
123
124 return false;
125}
void setColor(const gcn::Color &color) override
Definition graphics.h:255
static bool debugDraw
Definition gui.h:141
A window container.
void adjustAfterResize(int oldScreenWidth, int oldScreenHeight)
Ensures that all visible windows are on the screen after the screen has been resized.
void logic() override
Do GUI logic.
bool widgetIsVisible(gcn::Widget *widget)
Returns whether the widget is visible and part of the hierarchy.
void draw(gcn::Graphics *graphics) override
Adds debug drawing.
void scheduleDelete(gcn::Widget *widget)
Schedule a widget for deletion.
std::set< gcn::Widget * > mScheduledDeletions
Set of widgets that are scheduled to be deleted.
void debugDraw(gcn::Graphics *graphics)
Draws the outlines of the container and all its children.
A window.
Definition window.h:59
Graphics * graphics
Definition client.cpp:104
WindowContainer * windowContainer