ManaPlus
window.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 /* _______ __ __ __ ______ __ __ _______ __ __
24  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
25  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
26  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
27  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
28  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
29  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
30  *
31  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
32  *
33  *
34  * Per Larsson a.k.a finalman
35  * Olof Naessén a.k.a jansem/yakslem
36  *
37  * Visit: http://guichan.sourceforge.net
38  *
39  * License: (BSD)
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  * notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  * notice, this list of conditions and the following disclaimer in
47  * the documentation and/or other materials provided with the
48  * distribution.
49  * 3. Neither the name of Guichan nor the names of its contributors may
50  * be used to endorse or promote products derived from this software
51  * without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
59  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  */
65 
66 #ifndef GUI_WIDGETS_WINDOW_H
67 #define GUI_WIDGETS_WINDOW_H
68 
70 #include "enums/simpletypes/move.h"
71 
73 
74 #include "gui/fonts/textchunk.h"
75 
77 
80 
81 #include "render/graphics.h"
82 
83 #include "localconsts.h"
84 
85 class ContainerPlacer;
86 class ImageCollection;
87 class Layout;
88 class LayoutCell;
89 class Skin;
90 class WindowContainer;
91 
99  public MouseListener,
100  public WidgetListener
101 {
102  public:
114  Window(const std::string &caption,
115  const Modal modal,
116  Window *const parent,
117  std::string skin);
118 
120 
121 
124  ~Window() override;
125 
130 
134  void draw(Graphics *const graphics) override A_NONNULL(2);
135 
136  void safeDraw(Graphics *const graphics) override A_NONNULL(2);
137 
141  void setContentSize(int width, int height);
142 
146  void setLocationRelativeTo(const Widget *const widget);
147 
152  *const widget);
153 
157  void setLocationRelativeTo(const ImagePosition::Type &position,
158  int offsetX,
159  int offsetY);
160 
164  void setResizable(const bool resize);
165 
166  void redraw();
167 
171  void widgetResized(const Event &event) override;
172 
173  void widgetMoved(const Event& event) override;
174 
178  void widgetHidden(const Event &event) override;
179 
183  void setCloseButton(const bool flag);
184 
186  { return mCloseWindowButton; }
187 
188  void setAllowClose(const bool b)
189  { mAllowClose = b; }
190 
192  { return mCloseWindowButton || mAllowClose; }
193 
197  bool isResizable() const A_WARN_UNUSED;
198 
202  void setMinWidth(const int width);
203 
204  int getMinWidth() const noexcept2 A_WARN_UNUSED
205  { return mMinWinWidth; }
206 
210  void setMinHeight(const int height);
211 
212  int getMinHeight() const noexcept2 A_WARN_UNUSED
213  { return mMinWinHeight; }
214 
218  void setMaxWidth(const int width);
219 
220  int getMaxWidth() const noexcept2 A_WARN_UNUSED
221  { return mMaxWinWidth; }
222 
226  void setMaxHeight(const int height);
227 
228  int getMaxHeight() const noexcept2 A_WARN_UNUSED
229  { return mMaxWinHeight; }
230 
234  void setShowTitle(bool flag)
235  { mShowTitle = flag; }
236 
240  void setStickyButton(const bool flag);
241 
247  void setSticky(const bool sticky);
248 
252  bool isSticky() const noexcept2 A_WARN_UNUSED
253  { return mSticky; }
254 
258  void setStickyButtonLock(const bool sticky);
259 
263  bool isStickyButtonLock() const noexcept2 A_WARN_UNUSED
264  { return mStickyButtonLock; }
265 
270  virtual void setVisible(Visible visible);
271 
276  void setVisible(const Visible visible, const bool forceSticky);
277 
281  bool isDefaultVisible() const noexcept2 A_WARN_UNUSED
282  { return mDefaultVisible; }
283 
287  void setDefaultVisible(const bool save)
288  { mDefaultVisible = save; }
289 
293  bool willSaveVisible() const
294  { return mSaveVisible; }
295 
299  void setSaveVisible(const bool save)
300  { mSaveVisible = save; }
301 
302  void postInit() override;
303 
310  { return mParentWindow; }
311 
316  virtual void scheduleDelete();
317 
321  void mousePressed(MouseEvent &event) override;
322 
327  void mouseDragged(MouseEvent &event) override;
328 
333  void mouseMoved(MouseEvent &event) override;
334 
339  void mouseReleased(MouseEvent &event) override;
340 
345  void mouseExited(MouseEvent &event) override;
346 
347  void mouseEntered(MouseEvent &event) override;
348 
349  void updateResizeHandler(MouseEvent &event);
350 
354  void setWindowName(const std::string &name)
355  { mWindowName = name; }
356 
360  const std::string &getWindowName() const noexcept2 A_WARN_UNUSED
361  { return mWindowName; }
362 
370  void loadWindowState();
371 
376  void saveWindowState();
377 
382  void setDefaultSize(const int defaultX, const int defaultY,
383  int defaultWidth, int defaultHeight);
384 
388  void setDefaultSize();
389 
396  void setDefaultSize(const int defaultWidth,
397  const int defaultHeight,
398  const ImagePosition::Type &position,
399  const int offsetx,
400  const int offsetY);
401 
406  virtual void resetToDefaultSize();
407 
412  void adjustPositionAfterResize(const int oldScreenWidth,
413  const int oldScreenHeight);
414 
419 
424  void clearLayout();
425 
434  void reflowLayout(int w,
435  int h);
436 
440  LayoutCell &place(const int x,
441  const int y,
442  Widget *const wg,
443  const int w,
444  const int h);
445 
449  ContainerPlacer getPlacer(const int x, const int y) A_WARN_UNUSED;
450 
454  void center();
455 
459  void centerHorisontally();
460 
466  virtual void close();
467 
471  void setModal(const Modal modal);
472 
474 
475  bool isResizeAllowed(const MouseEvent &event) const A_WARN_UNUSED;
476 
478  { mCaptionFont = font; }
479 
480  void enableVisibleSound(bool b)
481  { mPlayVisibleSound = b; }
482 
483  bool isWindowVisible() const noexcept2 A_WARN_UNUSED
484  { return mVisible == Visible_true; }
485 
493  void setPadding(int padding)
494  { mPadding = padding; }
495 
503  int getPadding() const
504  { return mPadding; }
505 
512  void setTitleBarHeight(unsigned int height)
513  { mTitleBarHeight = height; }
514 
521  unsigned int getTitleBarHeight() const
522  { return mTitleBarHeight; }
523 
530  void setCaption(const std::string& caption)
531  { mCaption = caption; mTextChanged = true; }
532 
539  const std::string& getCaption() const
540  { return mCaption; }
541 
549  { mAlignment = alignment; }
550 
558  { return mAlignment; }
559 
566  void setMovable(Move movable)
567  { mMovable = movable; }
568 
575  bool isMovable() const
576  { return mMovable == Move_true; }
577 
578  Rect getChildrenArea() override;
579 
583  virtual void resizeToContent();
584 
585 #ifdef USE_PROFILER
586  virtual void logic();
587 #endif // USE_PROFILER
588 
589  protected:
590  bool canMove() const A_WARN_UNUSED;
591 
592  int getOption(const std::string &name,
593  const int def) const A_WARN_UNUSED;
594 
595  bool getOptionBool(const std::string &name,
596  const bool def) const A_WARN_UNUSED;
597 
598  void setTitlePadding(const int p) noexcept2
599  { mTitlePadding = p; }
600 
601  int getTitlePadding() const noexcept2 A_WARN_UNUSED
602  { return mTitlePadding; }
603 
607  std::string mCaption;
608 
613 
617  int mPadding;
618 
622  unsigned int mTitleBarHeight;
623 
628 
635 
642 
646  bool mMoved;
647 
649  int mDefaultX;
650  int mDefaultY;
655  bool mShowTitle;
657 
658  private:
660  {
661  TOP = 0x01,
662  RIGHT = 0x02,
663  BOTTOM = 0x04,
664  LEFT = 0x08,
665  CLOSE = 0x10
666  };
667 
673  void ensureOnScreen();
674 
675  void adjustSizeToScreen();
676 
684  int getResizeHandles(const MouseEvent &event) A_WARN_UNUSED;
685 
693  std::string mWindowName;
699  static int mouseResize;
700  static int windowInstances;
708  static const unsigned resizeBorderWidth = 10;
724  bool mSticky;
727  bool mInit;
730 };
731 
732 #endif // GUI_WIDGETS_WINDOW_H
bool mShowTitle
Definition: window.h:655
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
void setDefaultSize()
Definition: window.cpp:1197
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
Rect mGripRect
Definition: window.h:691
unsigned int getTitleBarHeight() const
Definition: window.h:521
bool isResizable() const
Definition: window.cpp:755
std::string mWindowName
Definition: window.h:693
void updateResizeHandler(MouseEvent &event)
Definition: window.cpp:929
void redraw()
Definition: window.cpp:1405
Font * mCaptionFont
Definition: window.h:718
void setDefaultVisible(const bool save)
Definition: window.h:287
Skin * mSkin
Definition: window.h:648
TextChunk mTextChunk
Definition: window.h:692
void adjustSizeToScreen()
Definition: window.cpp:1284
int mGripPadding
Definition: window.h:712
Definition: skin.h:35
int mDragOffsetY
Definition: window.h:641
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1465
int mPadding
Definition: window.h:617
#define A_NONNULLPOINTER
Definition: localconsts.h:265
Definition: font.h:88
void setLocationHorisontallyRelativeTo(const Widget *const widget)
Definition: window.cpp:527
const bool Visible_true
Definition: visible.h:29
void setMaxWidth(const int width)
Definition: window.cpp:616
void loadWindowState()
Definition: window.cpp:1086
WindowContainer * windowContainer
virtual void resetToDefaultSize()
Definition: window.cpp:1258
static int mouseResize
Definition: window.h:699
Rect getChildrenArea()
Definition: window.cpp:1472
void setMaxHeight(const int height)
Definition: window.cpp:621
virtual void resizeToContent()
Definition: window.cpp:1480
int mOldResizeHandles
Definition: window.h:714
bool mTextChanged
Definition: window.h:728
bool mStickyButtonLock
Definition: window.h:725
int mCaptionOffsetY
Definition: window.h:654
bool isDefaultVisible() const
Definition: window.h:281
Definition: rect.h:72
void setMinWidth(const int width)
Definition: window.cpp:590
#define A_WARN_UNUSED
Definition: localconsts.h:160
Definition: window.h:98
int mStickySpacing
Definition: window.h:716
void setShowTitle(bool flag)
Definition: window.h:234
bool mDefaultVisible
Definition: window.h:721
void centerHorisontally()
Definition: window.cpp:1421
int getOption(const std::string &name, const int def) const
Definition: window.cpp:1453
ImageCollection * mVertexes
Definition: window.h:709
void mouseMoved(MouseEvent &event)
Definition: window.cpp:966
Rect mCloseRect
Definition: window.h:689
bool mStickyButton
Definition: window.h:723
Window * getParentWindow() const
Definition: window.h:309
bool mMoved
Definition: window.h:646
#define A_NONNULL(...)
Definition: localconsts.h:167
int mCaptionOffsetX
Definition: window.h:653
int mDragOffsetX
Definition: window.h:634
bool isMovable() const
Definition: window.h:575
int mMaxWinWidth
Definition: window.h:696
int mDefaultY
Definition: window.h:650
Visible mVisible
Definition: widget.h:962
void ensureOnScreen()
Definition: window.cpp:1426
virtual void close()
Definition: window.cpp:901
void widgetHidden(const Event &event)
Definition: window.cpp:724
void setContentSize(int width, int height)
Definition: window.cpp:491
bool mAllowClose
Definition: window.h:729
int getMinHeight() const
Definition: window.h:212
void widgetResized(const Event &event)
Definition: window.cpp:654
int getTitlePadding() const
Definition: window.h:601
void setCaptionFont(Font *font)
Definition: window.h:477
int mTitlePadding
Definition: window.h:711
void setSticky(const bool sticky)
Definition: window.cpp:765
void draw(Graphics *const graphics)
Definition: window.cpp:310
bool canMove() const
Definition: window.cpp:976
int mDefaultWidth
Definition: window.h:651
bool mLastRedraw
Definition: window.h:656
int mStickyPadding
Definition: window.h:717
bool mInit
Definition: window.h:727
Graphics::Alignment mCaptionAlign
Definition: window.h:710
#define notfinal
Definition: localconsts.h:260
static const unsigned resizeBorderWidth
Definition: window.h:708
bool isWindowVisible() const
Definition: window.h:483
int mClosePadding
Definition: window.h:715
~Window()
Definition: window.cpp:259
bool willSaveVisible() const
Definition: window.h:293
void setCloseButton(const bool flag)
Definition: window.cpp:748
bool mCloseWindowButton
Definition: window.h:720
Rect getWindowArea() const
Definition: window.cpp:1445
int mResizeHandles
Definition: window.h:713
bool mSticky
Definition: window.h:724
void enableVisibleSound(bool b)
Definition: window.h:480
const std::string & getWindowName() const
Definition: window.h:360
const bool Move_true
Definition: move.h:29
void setMinHeight(const int height)
Definition: window.cpp:603
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1390
static int windowInstances
Definition: window.h:700
Rect mStickyRect
Definition: window.h:690
virtual void scheduleDelete()
Definition: window.cpp:830
Modal mModal
Definition: window.h:719
bool mPlayVisibleSound
Definition: window.h:726
Layout & getLayout()
Definition: window.cpp:1364
void widgetMoved(const Event &event)
Definition: window.cpp:719
int getMaxHeight() const
Definition: window.h:228
std::string mCaption
Definition: window.h:607
void setAllowClose(const bool b)
Definition: window.h:188
void setTitlePadding(const int p)
Definition: window.h:598
ResizeHandles
Definition: window.h:659
void mouseReleased(MouseEvent &event)
Definition: window.cpp:906
void setSaveVisible(const bool save)
Definition: window.h:299
bool mSaveVisible
Definition: window.h:722
virtual void setVisible(Visible visible)
Definition: window.cpp:777
void center()
Definition: window.cpp:1416
Move mMovable
Definition: window.h:627
Definition: widget.h:97
int mDefaultHeight
Definition: window.h:652
Definition: event.h:77
int getMaxWidth() const
Definition: window.h:220
int mDefaultX
Definition: window.h:649
void mouseDragged(MouseEvent &event)
Definition: window.cpp:981
bool isStickyButtonLock() const
Definition: window.h:263
void setMovable(Move movable)
Definition: window.h:566
bool isResizeAllowed(const MouseEvent &event) const
Definition: window.cpp:1344
void mouseEntered(MouseEvent &event)
Definition: window.cpp:918
void mousePressed(MouseEvent &event)
Definition: window.cpp:835
Definition: image.h:61
void mouseExited(MouseEvent &event)
Definition: window.cpp:923
Layout * mLayout
Definition: window.h:688
bool getAlowClose() const
Definition: window.h:191
void setResizable(const bool resize)
Definition: window.cpp:626
bool isSticky() const
Definition: window.h:252
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:771
static void setWindowContainer(WindowContainer *const windowContainer)
Definition: window.cpp:305
void setPadding(int padding)
Definition: window.h:493
bool getCloseButton() const
Definition: window.h:185
void setTitleBarHeight(unsigned int height)
Definition: window.h:512
Graphics::Alignment getAlignment() const
Definition: window.h:557
void setStickyButton(const bool flag)
Definition: window.cpp:760
Definition: layout.h:43
Window * mParentWindow
Definition: window.h:687
void saveWindowState()
Definition: window.cpp:1148
void clearLayout()
Definition: window.cpp:1371
void setCaption(const std::string &caption)
Definition: window.h:530
unsigned int mTitleBarHeight
Definition: window.h:622
const std::string & getCaption() const
Definition: window.h:539
int mMinWinWidth
Definition: window.h:694
Graphics::Alignment mAlignment
Definition: window.h:612
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:508
int getResizeHandles(const MouseEvent &event)
Definition: window.cpp:1305
#define noexcept2
Definition: localconsts.h:49
int getMinWidth() const
Definition: window.h:204
int getPadding() const
Definition: window.h:503
void setModal(const Modal modal)
Definition: window.cpp:1068
void setAlignment(Graphics::Alignment alignment)
Definition: window.h:548
int mMaxWinHeight
Definition: window.h:697
void reflowLayout(int w, int h)
Definition: window.cpp:1395
void postInit()
Definition: window.cpp:248
int mMinWinHeight
Definition: window.h:695
void safeDraw(Graphics *const graphics)
Definition: window.cpp:422
void setWindowName(const std::string &name)
Definition: window.h:354
Image * mGrip
Definition: window.h:686
void adjustPositionAfterResize(const int oldScreenWidth, const int oldScreenHeight)
Definition: window.cpp:1265