Mana
Loading...
Searching...
No Matches
window.h
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#pragma once
23
24#include "graphics.h"
25#include "guichanfwd.h"
26
27#include "resources/theme.h"
28
29#include <guichan/widgetlistener.hpp>
30#include <guichan/widgets/window.hpp>
31
32class ContainerPlacer;
33class Layout;
34class LayoutCell;
35class ResizeGrip;
36class Skin;
37class WindowContainer;
38
40{
41 TopLeft,
42 Top,
44 Left,
45 Center,
46 Right,
48 Bottom,
50};
51
58class Window : public gcn::Window, gcn::WidgetListener
59{
60 public:
71 Window(const std::string &caption = "Window",
72 bool modal = false,
73 Window *parent = nullptr);
74
78 Window(SkinType skinType,
79 const std::string &caption = "Window",
80 bool modal = false,
81 Window *parent = nullptr);
82
86 ~Window() override;
87
92
96 void draw(gcn::Graphics *graphics) override;
97
101 void drawFrame(gcn::Graphics *graphics) override;
102
106 void setContentSize(int width, int height);
107
111 void setMinimumContentSize(int width, int height);
112
116 void setLocationRelativeTo(gcn::Widget *widget);
117
121 void setResizable(bool resize);
122
123 void redraw();
124
128 void widgetResized(const gcn::Event &event) override;
129
133 void widgetHidden(const gcn::Event &event) override;
134
138 void setCloseButton(bool flag);
139
143 bool isResizable() const;
144
148 void setMinWidth(int width);
149
150 int getMinWidth() const { return mMinWinWidth; }
151
155 void setMinHeight(int height);
156
157 int getMinHeight() const { return mMinWinHeight; }
158
162 void setMaxWidth(int width);
163
164 int getMaxWidth() const { return mMaxWinWidth; }
165
169 void setMaxHeight(int height);
170
171 int getMaxHeight() const { return mMaxWinHeight; }
172
176 void setShowTitle(bool flag) { mShowTitle = flag; }
177
181 void setStickyButton(bool flag);
182
188 void setSticky(bool sticky);
189
193 bool isSticky() const { return mSticky; }
194
199 virtual void setVisible(bool visible);
200
205 void setVisible(bool visible, bool forceSticky);
206
210 bool isDefaultVisible() const { return mDefaultVisible; }
211
215 void setDefaultVisible(bool save) { mDefaultVisible = save; }
216
220 bool willSaveVisible() const { return mSaveVisible; }
221
225 void setSaveVisible(bool save) { mSaveVisible = save; }
226
232 Window *getParentWindow() const { return mParent; }
233
238 void scheduleDelete();
239
243 void mousePressed(gcn::MouseEvent &event) override;
244
249 void mouseDragged(gcn::MouseEvent &event) override;
250
255 void mouseMoved(gcn::MouseEvent &event) override;
256
261 void mouseReleased(gcn::MouseEvent &event) override;
262
267 void mouseExited(gcn::MouseEvent &event) override;
268
272 void setWindowName(const std::string &name) { mWindowName = name; }
273
277 const std::string &getWindowName() const { return mWindowName; }
278
286 void loadWindowState();
287
292 void saveWindowState() const;
293
298 void setDefaultSize(int defaultX, int defaultY,
299 int defaultWidth, int defaultHeight);
300
304 void setDefaultSize();
305
312 void setDefaultSize(int defaultWidth, int defaultHeight,
313 WindowAlignment alignment,
314 int offsetx = 0, int offsetY = 0);
315
320 virtual void resetToDefaultSize();
321
326 void adjustPositionAfterResize(int oldScreenWidth,
327 int oldScreenHeight);
328
332 Layout &getLayout();
333
338 void clearLayout();
339
348 void reflowLayout(int w = 0, int h = 0);
349
353 LayoutCell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1);
354
358 ContainerPlacer getPlacer(int x, int y);
359
363 void center();
364
370 virtual void close();
371
375 const Skin &getSkin() const;
376
380 static int getGuiAlpha();
381
382 protected:
383 static int mouseResize;
385 private:
387 {
388 TOP = 0x01,
389 RIGHT = 0x02,
390 BOTTOM = 0x04,
391 LEFT = 0x08
392 };
393
399 void ensureOnScreen();
400
408 int getResizeHandles(gcn::MouseEvent &event);
409
410 gcn::Rectangle getCloseButtonRect() const;
411 gcn::Rectangle getStickyButtonRect() const;
412
413 ResizeGrip *mGrip = nullptr;
415 Layout *mLayout = nullptr;
416 std::string mWindowName;
417 bool mShowTitle = true;
418 bool mModal;
419 bool mCloseButton = false;
421 bool mDefaultVisible = false;
422 bool mSaveVisible = false;
423 bool mStickyButton = false;
424 bool mSticky = false;
426 int mMinWinWidth = 100;
427 int mMinWinHeight = 40;
435 static int instances;
436};
This class is a helper for adding widgets to nested tables in a window.
Definition layout.h:34
This class describes the formatting of a widget in the cell of a layout table.
Definition layout.h:159
This class is an helper for setting the position of widgets.
Definition layout.h:281
Resize grip.
Definition resizegrip.h:34
Definition theme.h:154
A window container.
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
bool willSaveVisible() const
Returns whether the window will save it's visibility.
Definition window.h:220
void setDefaultVisible(bool save)
Sets whether the window is visible by default.
Definition window.h:215
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
Window * mParent
The parent window.
Definition window.h:414
ResizeHandles
Definition window.h:387
@ 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
void setWindowName(const std::string &name)
Sets the name of the window.
Definition window.h:272
~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 isDefaultVisible() const
Returns whether the window is visible by default.
Definition window.h:210
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
void setSaveVisible(bool save)
Sets whether the window will save it's visibility.
Definition window.h:225
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 setShowTitle(bool flag)
Sets flag to show a title or not.
Definition window.h:176
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
const std::string & getWindowName() const
Returns the name of the window.
Definition window.h:277
bool mCloseButtonHovered
Definition window.h:420
int mMaxWinWidth
Maximum window width.
Definition window.h:428
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
Graphics * graphics
Definition client.cpp:104
SkinType
Definition theme.h:69
WindowAlignment
Definition window.h:40
WindowContainer * windowContainer