Mana
Loading...
Searching...
No Matches
window.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
22#include "gui/widgets/window.h"
23
24#include "configuration.h"
25#include "log.h"
26
27#include "gui/gui.h"
28#include "gui/viewport.h"
29
30#include "gui/widgets/layout.h"
33
34#include <guichan/exception.hpp>
35#include <guichan/focushandler.hpp>
36
37#include <algorithm>
38#include <cassert>
39
40int Window::instances = 0;
42
43Window::Window(const std::string &caption, bool modal, Window *parent)
44 : Window(SkinType::Window, caption, modal, parent)
45{}
46
47Window::Window(SkinType skinType, const std::string &caption, bool modal, Window *parent)
48 : gcn::Window(caption)
49 , mParent(parent)
50 , mModal(modal)
51 , mSkinType(skinType)
52 , mMaxWinWidth(graphics->getWidth())
53 , mMaxWinHeight(graphics->getHeight())
54{
55 Log::debug("Window::Window(\"%s\")", caption.c_str());
56
57 if (!windowContainer)
58 throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
59
60 instances++;
61
62 auto &skin = getSkin();
63 setFrameSize(skin.frameSize);
64 setPadding(skin.padding);
65 setTitleBarHeight(skin.titleBarHeight);
66
67 // Add this window to the window container
68 windowContainer->add(this);
69
70 if (mModal)
71 {
73 requestModalFocus();
74 }
75
76 // Windows are invisible by default
77 setVisible(false);
78
79 addWidgetListener(this);
80}
81
83{
84 Log::debug("Window::~Window(\"%s\")", getCaption().c_str());
85
87
88 delete mLayout;
89
90 while (!mWidgets.empty())
91 delete mWidgets.front();
92
93 removeWidgetListener(this);
94
95 instances--;
96}
97
102
103void Window::draw(gcn::Graphics *graphics)
104{
105 if (getFrameSize() == 0)
107
108 auto g = static_cast<Graphics*>(graphics);
109
110 if (mCloseButton)
111 {
114 }
115
116 if (mStickyButton)
117 {
120 }
121
122 drawChildren(graphics);
123}
124
125void Window::drawFrame(gcn::Graphics *graphics)
126{
127 auto g = static_cast<Graphics*>(graphics);
128
129 WidgetState widgetState(this);
130 widgetState.width += getFrameSize() * 2;
131 widgetState.height += getFrameSize() * 2;
132
133 auto &skin = getSkin();
134 skin.draw(g, widgetState);
135
136 if (mShowTitle)
137 {
138 if (auto skinState = skin.getState(widgetState.flags))
139 {
140 auto &textFormat = skinState->textFormat;
141 g->drawText(getCaption(),
142 getFrameSize() + skin.titleOffsetX,
143 getFrameSize() + skin.titleOffsetY,
144 gcn::Graphics::LEFT,
145 textFormat.bold ? boldFont : getFont(),
146 textFormat);
147 }
148 }
149}
150
151void Window::setContentSize(int width, int height)
152{
153 width += 2 * getPadding();
154 height += getPadding() + getTitleBarHeight();
155
156 if (getMinWidth() > width)
157 width = getMinWidth();
158 else if (getMaxWidth() < width)
159 width = getMaxWidth();
160 if (getMinHeight() > height)
161 height = getMinHeight();
162 else if (getMaxHeight() < height)
163 height = getMaxHeight();
164
165 setSize(width, height);
166}
167
168void Window::setMinimumContentSize(int width, int height)
169{
170 const int padding = getPadding();
171 const int titleBarHeight = getTitleBarHeight();
172 auto &skin = getSkin();
173
174 setMinWidth(std::max(skin.getMinWidth(), width + 2 * padding));
175 setMinHeight(std::max(skin.getMinHeight(), height + padding + titleBarHeight));
176}
177
178void Window::setLocationRelativeTo(gcn::Widget *widget)
179{
180 int wx;
181 int wy;
182 widget->getAbsolutePosition(wx, wy);
183
184 int x;
185 int y;
186 getAbsolutePosition(x, y);
187
188 setPosition(getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x),
189 getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y));
190}
191
192void Window::setMinWidth(int width)
193{
194 mMinWinWidth = std::max(getSkin().getMinWidth(), width);
195}
196
197void Window::setMinHeight(int height)
198{
199 mMinWinHeight = std::max(getSkin().getMinHeight(), height);
200}
201
202void Window::setMaxWidth(int width)
203{
204 mMaxWinWidth = width;
205}
206
207void Window::setMaxHeight(int height)
208{
209 mMaxWinHeight = height;
210}
211
213{
214 if ((bool) mGrip == r)
215 return;
216
217 if (r)
218 {
219 mGrip = new ResizeGrip;
220 mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x);
221 mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y);
222 add(mGrip);
223 }
224 else
225 {
226 remove(mGrip);
227 delete mGrip;
228 mGrip = nullptr;
229 }
230}
231
232void Window::widgetResized(const gcn::Event &event)
233{
234 const gcn::Rectangle area = getChildrenArea();
235
236 if (mGrip)
237 mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x,
238 getHeight() - mGrip->getHeight() - area.y);
239
240 if (mLayout)
241 {
242 int w = area.width;
243 int h = area.height;
244 mLayout->reflow(w, h);
245 }
246}
247
248void Window::widgetHidden(const gcn::Event &event)
249{
250 if (gui)
252
253 WidgetListIterator it;
254
255 for (it = mWidgets.begin(); it != mWidgets.end(); it++)
256 {
257 if (mFocusHandler->isFocused(*it))
258 mFocusHandler->focusNone();
259 }
260}
261
263{
264 mCloseButton = flag;
265}
266
268{
269 return mGrip;
270}
271
273{
274 mStickyButton = flag;
275}
276
277void Window::setSticky(bool sticky)
278{
279 mSticky = sticky;
280}
281
282void Window::setVisible(bool visible)
283{
284 setVisible(visible, false);
285}
286
287void Window::setVisible(bool visible, bool forceSticky)
288{
289 if (visible == isVisible())
290 return; // Nothing to do
291
292 // Check if the window is off screen...
293 if (visible)
295
296 gcn::Window::setVisible((!forceSticky && isSticky()) || visible);
297}
298
303
304void Window::mousePressed(gcn::MouseEvent &event)
305{
306 // Let Guichan move window to top and figure out title bar drag
307 gcn::Window::mousePressed(event);
308
309 if (event.getButton() == gcn::MouseEvent::LEFT)
310 {
311 const int x = event.getX();
312 const int y = event.getY();
313
314 if (mCloseButton && getCloseButtonRect().isPointInRect(x, y))
315 close();
316
317 if (mStickyButton && getStickyButtonRect().isPointInRect(x, y))
319
320 // Update resizing state and disable moving if we're resizing the window
322 if (mouseResize)
323 mMoved = false;
324 }
325}
326
328{
329 setVisible(false);
330}
331
332const Skin &Window::getSkin() const
333{
334 return gui->getTheme()->getSkin(mSkinType);
335}
336
337void Window::mouseReleased(gcn::MouseEvent &event)
338{
339 mouseResize = 0;
340
341 gcn::Window::mouseReleased(event);
342}
343
344void Window::mouseExited(gcn::MouseEvent &event)
345{
346 if (mGrip && !mouseResize)
348
349 mCloseButtonHovered = false;
350}
351
352void Window::mouseMoved(gcn::MouseEvent &event)
353{
354 mCloseButtonHovered = false;
355
356 // Make sure BeingPopup is hidden (Viewport does not receive mouseExited)
357 if (viewport)
359
360 // Don't change mouse cursor when event was consumed by child widget
361 // (in this case child widget is responsible for mouse cursor)
362 if (event.isConsumed())
363 return;
364
365 mCloseButtonHovered = getCloseButtonRect().isPointInRect(event.getX(), event.getY());
366 Cursor cursor = Cursor::Pointer;
367
368 // Changes the custom mouse cursor based on its current position.
370 {
371 switch (getResizeHandles(event))
372 {
373 case BOTTOM | RIGHT:
374 case TOP | LEFT:
376 break;
377 case BOTTOM | LEFT:
378 case TOP | RIGHT:
379 cursor = Cursor::ResizeDownLeft;
380 break;
381 case BOTTOM:
382 case TOP:
383 cursor = Cursor::ResizeDown;
384 break;
385 case RIGHT:
386 case LEFT:
387 cursor = Cursor::ResizeAcross;
388 break;
389 default:
390 break;
391 }
392 }
393
394 gui->setCursorType(cursor);
395}
396
397void Window::mouseDragged(gcn::MouseEvent &event)
398{
399 // Let Guichan handle title bar drag
400 gcn::Window::mouseDragged(event);
401
402 // Keep guichan window inside screen when it may be moved
403 if (isMovable() && mMoved)
405
406 if (mouseResize && !mMoved)
407 {
408 const int dx = event.getX() - mDragOffsetX;
409 const int dy = event.getY() - mDragOffsetY;
410 gcn::Rectangle newDim = getDimension();
411
412 if (mouseResize & (TOP | BOTTOM))
413 {
414 int newHeight = newDim.height + ((mouseResize & TOP) ? -dy : dy);
415 newDim.height = std::min(mMaxWinHeight,
416 std::max(mMinWinHeight, newHeight));
417
418 if (mouseResize & TOP)
419 newDim.y -= newDim.height - getHeight();
420 }
421
422 if (mouseResize & (LEFT | RIGHT))
423 {
424 int newWidth = newDim.width + ((mouseResize & LEFT) ? -dx : dx);
425 newDim.width = std::min(mMaxWinWidth,
426 std::max(mMinWinWidth, newWidth));
427
428 if (mouseResize & LEFT)
429 newDim.x -= newDim.width - getWidth();
430 }
431
432 // Keep guichan window inside screen (supports resizing any side)
433 if (newDim.x < 0)
434 {
435 newDim.width += newDim.x;
436 newDim.x = 0;
437 }
438 if (newDim.y < 0)
439 {
440 newDim.height += newDim.y;
441 newDim.y = 0;
442 }
443 if (newDim.x + newDim.width > graphics->getWidth())
444 {
445 newDim.width = graphics->getWidth() - newDim.x;
446 }
447 if (newDim.y + newDim.height > graphics->getHeight())
448 {
449 newDim.height = graphics->getHeight() - newDim.y;
450 }
451
452 // Update mouse offset when dragging bottom or right border
453 if (mouseResize & BOTTOM)
454 {
455 mDragOffsetY += newDim.height - getHeight();
456 }
457 if (mouseResize & RIGHT)
458 {
459 mDragOffsetX += newDim.width - getWidth();
460 }
461
462 // Set the new window and content dimensions
463 setDimension(newDim);
464 }
465}
466
468{
469 assert(!mWindowName.empty());
470
471 constexpr WindowState defaultState;
472 auto s = config.windows.find(mWindowName);
473 const WindowState state = s == config.windows.end() ? defaultState
474 : s->second;
475
476 setPosition(state.x.value_or(mDefaultX),
477 state.y.value_or(mDefaultY));
478
479 if (mSaveVisible)
480 setVisible(state.visible.value_or(mDefaultVisible));
481
482 if (mStickyButton)
483 setSticky(state.sticky.value_or(isSticky()));
484
485 if (mGrip)
486 {
487 const int width = state.width.value_or(mDefaultWidth);
488 const int height = state.height.value_or(mDefaultHeight);
489
490 setSize(std::clamp(width, getMinWidth(), getMaxWidth()),
491 std::clamp(height, getMinHeight(), getMaxHeight()));
492 }
493 else
494 {
496 }
497
498 // Check if the window is off screen...
500}
501
503{
504 // Saving X, Y and Width and Height for resizables in the config
505 if (mWindowName.empty())
506 return;
507
508 WindowState state;
509 state.x = getX();
510 state.y = getY();
511
512 if (mSaveVisible)
513 state.visible = isVisible();
514
515 if (mStickyButton)
516 state.sticky = isSticky();
517
518 if (mGrip)
519 {
520 state.width = getWidth();
521 state.height = getHeight();
522 }
523
524 config.windows[mWindowName] = state;
525}
526
527void Window::setDefaultSize(int defaultX, int defaultY,
528 int defaultWidth, int defaultHeight)
529{
530 if (getMinWidth() > defaultWidth)
531 defaultWidth = getMinWidth();
532 else if (getMaxWidth() < defaultWidth)
533 defaultWidth = getMaxWidth();
534 if (getMinHeight() > defaultHeight)
535 defaultHeight = getMinHeight();
536 else if (getMaxHeight() < defaultHeight)
537 defaultHeight = getMaxHeight();
538
539 mDefaultX = defaultX;
540 mDefaultY = defaultY;
541 mDefaultWidth = defaultWidth;
542 mDefaultHeight = defaultHeight;
543}
544
546{
547 mDefaultX = getX();
548 mDefaultY = getY();
549 mDefaultWidth = getWidth();
550 mDefaultHeight = getHeight();
551}
552
553void Window::setDefaultSize(int defaultWidth, int defaultHeight,
554 WindowAlignment alignment,
555 int offsetX, int offsetY)
556{
557 int x = 0;
558 int y = 0;
559
560 switch (alignment)
561 {
563 break;
565 x = (graphics->getWidth() - defaultWidth) / 2;
566 break;
568 x = graphics->getWidth() - defaultWidth;
569 break;
571 y = (graphics->getHeight() - defaultHeight) / 2;
572 break;
574 x = (graphics->getWidth() - defaultWidth) / 2;
575 y = (graphics->getHeight() - defaultHeight) / 2;
576 break;
578 x = graphics->getWidth() - defaultWidth;
579 y = (graphics->getHeight() - defaultHeight) / 2;
580 break;
582 y = graphics->getHeight() - defaultHeight;
583 break;
585 x = (graphics->getWidth() - defaultWidth) / 2;
586 y = graphics->getHeight() - defaultHeight;
587 break;
589 x = graphics->getWidth() - defaultWidth;
590 y = graphics->getHeight() - defaultHeight;
591 break;
592 }
593
594 mDefaultX = x - offsetX;
595 mDefaultY = y - offsetY;
596 mDefaultWidth = defaultWidth;
597 mDefaultHeight = defaultHeight;
598}
599
601{
602 setPosition(mDefaultX, mDefaultY);
605}
606
607void Window::adjustPositionAfterResize(int oldScreenWidth, int oldScreenHeight)
608{
609 gcn::Rectangle dimension = getDimension();
610
611 // If window was aligned to the right or bottom, keep it there
612 const int rightMargin = oldScreenWidth - (getX() + getWidth());
613 const int bottomMargin = oldScreenHeight - (getY() + getHeight());
614 if (getX() > 0 && getX() > rightMargin)
615 dimension.x = graphics->getWidth() - rightMargin - getWidth();
616 if (getY() > 0 && getY() > bottomMargin)
617 dimension.y = graphics->getHeight() - bottomMargin - getHeight();
618
619 setDimension(dimension);
621}
622
623int Window::getResizeHandles(gcn::MouseEvent &event)
624{
625 int resizeHandles = 0;
626
627 if (mGrip)
628 {
629 const int x = event.getX();
630 const int y = event.getY();
631 const int p = getPadding();
632
633 const bool inPadding = (x < p || x >= getWidth() - p) ||
634 (y < p || y >= getHeight() - p);
635
636 if (inPadding && event.getSource() == this)
637 {
643 const int resizeBorderWidth = std::max(mGrip->getWidth(), 10);
644
645 resizeHandles |= (x >= getWidth() - resizeBorderWidth) ? RIGHT :
646 (x < resizeBorderWidth) ? LEFT : 0;
647 resizeHandles |= (y >= getHeight() - resizeBorderWidth) ? BOTTOM :
648 (y < resizeBorderWidth) ? TOP : 0;
649 }
650
651 if (event.getSource() == mGrip)
652 {
653 mDragOffsetX = x;
654 mDragOffsetY = y;
655 resizeHandles |= BOTTOM | RIGHT;
656 }
657 }
658
659 return resizeHandles;
660}
661
662gcn::Rectangle Window::getCloseButtonRect() const
663{
664 if (!mCloseButton)
665 return {};
666
667 auto theme = gui->getTheme();
668
669 auto &closeSkin = theme->getSkin(SkinType::ButtonClose);
670 const int closeWidth = closeSkin.getMinWidth();
671 const int closeHeight = closeSkin.getMinHeight();
672
673 return {
674 getWidth() - closeWidth - closeSkin.padding,
675 closeSkin.padding,
676 closeWidth,
677 closeHeight
678 };
679}
680
681gcn::Rectangle Window::getStickyButtonRect() const
682{
683 if (!mStickyButton)
684 return {};
685
686 auto theme = gui->getTheme();
687
688 auto &closeSkin = theme->getSkin(SkinType::ButtonClose);
689 const int closeWidth = closeSkin.getMinWidth();
690
691 auto &stickySkin = theme->getSkin(SkinType::ButtonSticky);
692 const int stickyWidth = stickySkin.getMinWidth();
693 const int stickyHeight = stickySkin.getMinHeight();
694
695 int stickyX = getWidth() - stickyWidth - stickySkin.padding - stickySkin.spacing;
696 if (mCloseButton)
697 stickyX -= closeWidth + closeSkin.padding;
698
699 return {
700 stickyX,
701 stickySkin.padding,
702 stickyWidth,
703 stickyHeight
704 };
705}
706
708{
709 float alpha = std::max(config.guiAlpha,
711 return (int) (alpha * 255.0f);
712}
713
715{
716 if (!mLayout)
717 mLayout = new Layout;
718 return *mLayout;
719}
720
722{
723 clear();
724
725 // Restore the resize grip
726 if (mGrip)
727 add(mGrip);
728
729 // Recreate layout instance when one is present
730 if (mLayout)
731 {
732 delete mLayout;
733 mLayout = new Layout;
734 }
735}
736
737LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h)
738{
739 add(wg);
740 return getLayout().place(wg, x, y, w, h);
741}
742
744{
745 return ContainerPlacer(this, &getLayout().at(x, y));
746}
747
748void Window::reflowLayout(int w, int h)
749{
750 assert(mLayout);
751 mLayout->reflow(w, h);
752 delete mLayout;
753 mLayout = nullptr;
754 setContentSize(w, h);
755}
756
758{
759 if (mLayout)
760 {
761 const gcn::Rectangle area = getChildrenArea();
762 int w = area.width;
763 int h = area.height;
764 mLayout->reflow(w, h);
765 }
766}
767
769{
770 if (auto window = getParentWindow())
771 setLocationRelativeTo(window);
772 else
773 setLocationRelativeTo(getParent());
774}
775
777{
778 // Skip when a window hasn't got any size initialized yet
779 if (getWidth() == 0 && getHeight() == 0)
780 return;
781
782 gcn::Rectangle dim = getDimension();
783
784 // Check the left and bottom screen boundaries
785 dim.x = std::min(graphics->getWidth() - dim.width, dim.x);
786 dim.y = std::min(graphics->getHeight() - dim.height, dim.y);
787
788 // But never allow the windows to disappear in to the right and top
789 dim.x = std::max(0, dim.x);
790 dim.y = std::max(0, dim.y);
791
792 setPosition(dim.x, dim.y);
793}
This class is a helper for adding widgets to nested tables in a window.
Definition layout.h:34
A central point of control for graphics.
Definition graphics.h:78
int getHeight() const
Returns the logical height of the screen.
Definition graphics.h:226
int getWidth() const
Returns the logical width of the screen.
Definition graphics.h:221
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
void setCursorType(Cursor cursor)
Sets which cursor should be used.
Definition gui.cpp:231
This class describes the formatting of a widget in the cell of a layout table.
Definition layout.h:159
LayoutCell & place(gcn::Widget *wg, int x, int y, int w=1, int h=1)
Definition layout.h:203
This class is an helper for setting the position of widgets.
Definition layout.h:281
void reflow(int &nW, int &nH)
Sets the positions of all the widgets.
Definition layout.cpp:321
Resize grip.
Definition resizegrip.h:34
Definition theme.h:154
int getMinWidth() const
Returns the minimum width which can be used with this skin.
Definition theme.cpp:177
const Skin & getSkin(SkinType skinType) const
Definition theme.cpp:434
float getMinimumOpacity() const
Get the minimum opacity allowed to skins.
Definition theme.h:326
void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const
Definition theme.cpp:373
void hideBeingPopup()
Hides the BeingPopup.
Definition viewport.cpp:600
A window container.
void scheduleDelete(gcn::Widget *widget)
Schedule a widget for deletion.
A window.
Definition window.h:59
void mouseReleased(gcn::MouseEvent &event) override
When the mouse button has been let go, this ensures that the mouse custom cursor is restored back to ...
Definition window.cpp:337
int mDefaultY
Default window Y position.
Definition window.h:431
void draw(gcn::Graphics *graphics) override
Draws the window contents.
Definition window.cpp:103
const Skin & getSkin() const
Returns the Skin used by this window.
Definition window.cpp:332
void center()
Positions the window in the center of it's parent.
Definition window.cpp:768
int mMinWinWidth
Minimum window width.
Definition window.h:426
std::string mWindowName
Name of the window.
Definition window.h:416
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
gcn::Rectangle getStickyButtonRect() const
Definition window.cpp:681
int mDefaultHeight
Default window height.
Definition window.h:433
void adjustPositionAfterResize(int oldScreenWidth, int oldScreenHeight)
Adjusts the window position after the application window has been resized.
Definition window.cpp:607
void setMinHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:197
void setStickyButton(bool flag)
Sets whether or not the window has a sticky button.
Definition window.cpp:272
virtual void close()
Overrideable functionality for when the window is to close.
Definition window.cpp:327
void clearLayout()
Clears the window's layout (useful for redesigning the window).
Definition window.cpp:721
void setContentSize(int width, int height)
Sets the size of this window.
Definition window.cpp:151
bool mShowTitle
Window has a title bar.
Definition window.h:417
@ RIGHT
Definition window.h:389
@ TOP
Definition window.h:388
@ BOTTOM
Definition window.h:390
@ LEFT
Definition window.h:391
Window * getParentWindow() const
Returns the parent window.
Definition window.h:232
Layout & getLayout()
Gets the layout handler for this window.
Definition window.cpp:714
~Window() override
Destructor.
Definition window.cpp:82
void ensureOnScreen()
Ensures the window is on the screen, moving it if necessary.
Definition window.cpp:776
bool isSticky() const
Returns whether the window is sticky.
Definition window.h:193
void mouseDragged(gcn::MouseEvent &event) override
Implements window resizing and makes sure the window is not dragged/resized outside of the screen.
Definition window.cpp:397
int mMinWinHeight
Minimum window height.
Definition window.h:427
bool mDefaultVisible
Window's default visibility.
Definition window.h:421
virtual void resetToDefaultSize()
Reset the win pos and size to default.
Definition window.cpp:600
int getMinWidth() const
Definition window.h:150
int mDefaultWidth
Default window width.
Definition window.h:432
bool mSaveVisible
Window will save visibility.
Definition window.h:422
void saveWindowState() const
Saves the window state so that when the window is reloaded, it'll maintain its previous state and loc...
Definition window.cpp:502
Layout * mLayout
Layout handler.
Definition window.h:415
void setMinimumContentSize(int width, int height)
Sets the minimum size of the window content.
Definition window.cpp:168
void setSticky(bool sticky)
Sets whether the window is sticky.
Definition window.cpp:277
static void setWindowContainer(WindowContainer *windowContainer)
Sets the window container to be used by new windows.
Definition window.cpp:98
SkinType mSkinType
The skin type used when drawing the window.
Definition window.h:425
static int getGuiAlpha()
Gets the alpha value used by the window, in a Guichan usable format.
Definition window.cpp:707
ContainerPlacer getPlacer(int x, int y)
Returns a proxy for adding widgets in an inner table of the layout.
Definition window.cpp:743
void setResizable(bool resize)
Sets whether or not the window can be resized.
Definition window.cpp:212
int mMaxWinHeight
Maximum window height.
Definition window.h:429
bool mSticky
Window resists hiding.
Definition window.h:424
int getMaxWidth() const
Definition window.h:164
void reflowLayout(int w=0, int h=0)
Computes the position of the widgets according to the current layout.
Definition window.cpp:748
void drawFrame(gcn::Graphics *graphics) override
Draws the window frame.
Definition window.cpp:125
void mouseMoved(gcn::MouseEvent &event) override
Implements custom cursor image changing context, based on mouse relative position.
Definition window.cpp:352
void widgetHidden(const gcn::Event &event) override
Called whenever the widget is hidden.
Definition window.cpp:248
gcn::Rectangle getCloseButtonRect() const
Definition window.cpp:662
int getResizeHandles(gcn::MouseEvent &event)
Determines if the mouse is in a resize area and returns appropriate resize handles.
Definition window.cpp:623
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
Definition window.cpp:737
void widgetResized(const gcn::Event &event) override
Called whenever the widget changes size.
Definition window.cpp:232
void mouseExited(gcn::MouseEvent &event) override
When the mouse leaves the window this ensures that the custom cursor is restored back to it's standar...
Definition window.cpp:344
int getMaxHeight() const
Definition window.h:171
void scheduleDelete()
Schedule this window for deletion.
Definition window.cpp:299
bool mCloseButton
Window has a close button.
Definition window.h:419
bool mCloseButtonHovered
Definition window.h:420
int mMaxWinWidth
Maximum window width.
Definition window.h:428
Window(const std::string &caption="Window", bool modal=false, Window *parent=nullptr)
Constructor.
Definition window.cpp:43
static int instances
Number of Window instances.
Definition window.h:435
void setCloseButton(bool flag)
Sets whether or not the window has a close button.
Definition window.cpp:262
void setLocationRelativeTo(gcn::Widget *widget)
Sets the location relative to the given widget.
Definition window.cpp:178
void setDefaultSize()
Set the default win pos and size to the current ones.
Definition window.cpp:545
int mDefaultX
Default window X position.
Definition window.h:430
bool mStickyButton
Window has a sticky button.
Definition window.h:423
bool isResizable() const
Returns whether the window can be resized.
Definition window.cpp:267
ResizeGrip * mGrip
Resize grip.
Definition window.h:413
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
Definition window.cpp:467
void mousePressed(gcn::MouseEvent &event) override
Starts window resizing when appropriate.
Definition window.cpp:304
static int mouseResize
Active resize handles.
Definition window.h:383
void redraw()
Definition window.cpp:757
int getMinHeight() const
Definition window.h:157
void setMaxHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:207
void setMinWidth(int width)
Sets the minimum width of the window.
Definition window.cpp:192
void setMaxWidth(int width)
Sets the maximum width of the window.
Definition window.cpp:202
bool mModal
Window is modal.
Definition window.h:418
Config config
Global settings (config.xml)
Definition client.cpp:97
Graphics * graphics
Definition client.cpp:104
Viewport * viewport
Viewport on the map.
Definition game.cpp:115
Gui * gui
The GUI system.
Definition gui.cpp:50
gcn::Font * boldFont
Bolded text font.
Definition gui.cpp:54
Cursor
Cursors are in graphic order from left to right.
Definition gui.h:55
@ ResizeDownRight
@ ResizeDown
@ ResizeAcross
@ ResizeDownLeft
void debug(const char *log_text,...) LOG_PRINTF_ATTR
float guiAlpha
std::map< std::string, WindowState > windows
uint8_t flags
Definition theme.h:150
int width
Definition theme.h:148
int height
Definition theme.h:149
std::optional< int > height
std::optional< bool > visible
std::optional< int > x
std::optional< int > y
std::optional< bool > sticky
std::optional< int > width
@ STATE_HOVERED
Definition theme.h:105
@ STATE_SELECTED
Definition theme.h:106
SkinType
Definition theme.h:69
WindowAlignment
Definition window.h:40
WindowContainer * windowContainer