ManaPlus
gui.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-2019 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_GUI_H
67 #define GUI_GUI_H
68 
69 #include "gui/color.h"
70 
73 
74 #include "enums/resources/cursor.h"
75 
76 #include <deque>
77 #include <list>
78 
79 #include "localconsts.h"
80 
81 class Event;
82 class FocusHandler;
83 class FocusListener;
84 class Graphics;
85 class GuiConfigListener;
86 class ImageSet;
87 class KeyEvent;
88 class KeyListener;
89 class MouseEvent;
90 class MouseInput;
91 class Font;
92 class SDLInput;
93 class Widget;
94 class Window;
95 
96 #ifdef USE_SDL2
97 #define MouseStateType uint32_t
98 #else // USE_SDL2
99 #define MouseStateType uint8_t
100 #endif // USE_SDL2
101 
115 class Gui final
116 {
117  public:
121  Gui();
122 
124 
125 
128  ~Gui();
129 
130  void postInit(Graphics *const graphics) A_NONNULL(2);
131 
136  void logic();
137 
138  void slowLogic();
139 
140  void clearFonts();
141 
146  void draw();
147 
151  void videoResized() const;
152 
154  { return mFocusHandler; }
155 
160  { return mGuiFont; }
161 
166  { return mHelpFont; }
167 
172  { return mSecureFont; }
173 
178  { return mNpcFont; }
179 
185  { return mInfoParticleFont; }
186 
190  void setUseCustomCursor(const bool customCursor);
191 
195  void setCursorType(const CursorT index)
196  { mCursorType = index; }
197 
198  void setDoubleClick(const bool b)
199  { mDoubleClick = b; }
200 
201  void updateFonts();
202 
203  bool handleInput();
204 
205  bool handleKeyInput();
206 
207  void resetClickCount();
208 
210 
211  static void getAbsolutePosition(Widget *restrict widget,
212  int &restrict x,
213  int &restrict y);
214 
215  void addGlobalFocusListener(FocusListener* focusListener);
216 
217  void removeGlobalFocusListener(FocusListener* focusListener);
218 
219  void distributeGlobalFocusGainedEvent(const Event &focusEvent);
220 
221  void removeDragged(const Widget *const widget);
222 
223  int getLastMouseX() const
224  { return mLastMouseX; }
225 
226  int getLastMouseY() const
227  { return mLastMouseY; }
228 
229  static MouseStateType getMouseState(int &x, int &y);
230 
239  void setTop(Widget *const top);
240 
248  { return mTop; }
249 
257  void setGraphics(Graphics *const graphics) A_NONNULL(2);
258 
268 
276  void setInput(SDLInput *const input) A_NONNULL(2);
277 
287 
297  void addGlobalKeyListener(KeyListener *const keyListener);
298 
306  void removeGlobalKeyListener(KeyListener *const keyListener);
307 
308  bool isLongPress() const
309  { return getMousePressLength() > 250; }
310 
311  int getMousePressLength() const;
312 
313  protected:
314  void handleMouseMoved(const MouseInput &mouseInput);
315 
316  void handleMouseReleased(const MouseInput &mouseInput);
317 
318  void handleMousePressed(const MouseInput &mouseInput);
319 
320  void handleMouseInput();
321 
322  void distributeMouseEvent(Widget *const source,
323  const MouseEventTypeT type,
324  const MouseButtonT button,
325  const int x, const int y,
326  const bool force,
327  const bool toSourceOnly);
328 
335  void handleMouseWheelMovedDown(const MouseInput& mouseInput);
336 
342  void handleMouseWheelMovedUp(const MouseInput& mouseInput);
343 
349  Widget* getWidgetAt(const int x, const int y) const A_WARN_UNUSED;
350 
356  Widget* getMouseEventSource(const int x,
357  const int y) const A_WARN_UNUSED;
358 
365 
372  void distributeKeyEvent(KeyEvent &event) const;
373 
381 
389 
396  void handleModalFocus();
397 
403  void handleModalFocusGained();
404 
412 
413  private:
418 
423 
428 
433 
437  typedef std::list<KeyListener*> KeyListenerList;
438 
443 
448 
453 
458 
463 
468 
474 
481 
487 
504 #ifdef ANDROID
505  uint16_t mLastMouseRealX;
506  uint16_t mLastMouseRealY;
507 #endif // ANDROID
508 
509  typedef std::list<FocusListener*> FocusListenerList;
510  typedef FocusListenerList::iterator FocusListenerIterator;
514  time_t mTime;
515  time_t mTime10;
518 };
519 
520 extern Gui *gui;
526 
527 #endif // GUI_GUI_H
FocusListener
Definition: focuslistener.h:77
Gui::mConfigListener
GuiConfigListener * mConfigListener
Definition: gui.h:488
Gui::removeGlobalFocusListener
void removeGlobalFocusListener(FocusListener *focusListener)
Definition: gui.cpp:1146
Gui::handleModalMouseInputFocus
void handleModalMouseInputFocus()
Definition: gui.cpp:1409
Gui::setInput
void setInput(SDLInput *const input)
Definition: gui.cpp:1199
Gui::mMouseInactivityTimer
int mMouseInactivityTimer
Definition: gui.h:502
Gui::mTime10
time_t mTime10
Definition: gui.h:515
Gui::handleKeyInput
bool handleKeyInput()
Definition: gui.cpp:394
Gui::getNpcFont
Font * getNpcFont() const
Definition: gui.h:177
Gui::FocusListenerList
std::list< FocusListener * > FocusListenerList
Definition: gui.h:509
boldFont
Font * boldFont
Definition: gui.cpp:111
SDLInput
Definition: sdlinput.h:103
Gui::getKeyEventSource
Widget * getKeyEventSource() const
Definition: gui.cpp:1305
Gui::setTop
void setTop(Widget *const top)
Definition: gui.cpp:1179
Gui::handleMouseWheelMovedUp
void handleMouseWheelMovedUp(const MouseInput &mouseInput)
Definition: gui.cpp:1243
Gui::removeDragged
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
Gui::mNpcFont
Font * mNpcFont
Definition: gui.h:498
Gui::getTop
Widget * getTop() const
Definition: gui.h:247
mousebutton.h
Gui::addGlobalKeyListener
void addGlobalKeyListener(KeyListener *const keyListener)
Definition: gui.cpp:1209
MouseInput
Definition: mouseinput.h:72
Gui::mGuiFont
Font * mGuiFont
Definition: gui.h:490
Window
Definition: window.h:98
Gui::mLastMousePressButton
MouseButtonT mLastMousePressButton
Definition: gui.h:452
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
Gui::handleMouseInput
void handleMouseInput()
Definition: gui.cpp:1022
Gui::mHelpFont
Font * mHelpFont
Definition: gui.h:494
Gui
Definition: gui.h:115
Gui::setDoubleClick
void setDoubleClick(const bool b)
Definition: gui.h:198
Gui::FocusListenerIterator
FocusListenerList::iterator FocusListenerIterator
Definition: gui.h:510
Gui::mLastMousePressTimeStamp
unsigned int mLastMousePressTimeStamp
Definition: gui.h:457
Gui::distributeGlobalFocusGainedEvent
void distributeGlobalFocusGainedEvent(const Event &focusEvent)
Definition: gui.cpp:1151
Gui::mFocusHandler
FocusHandler * mFocusHandler
Definition: gui.h:432
Gui::getWidgetAt
Widget * getWidgetAt(const int x, const int y) const
Definition: gui.cpp:1267
Gui::getMouseEventSource
Widget * getMouseEventSource(const int x, const int y) const
Definition: gui.cpp:1289
Graphics
Definition: graphics.h:107
A_NONNULLPOINTER
#define A_NONNULLPOINTER
Definition: localconsts.h:265
Gui::mDoubleClick
bool mDoubleClick
Definition: gui.h:517
localconsts.h
Gui::KeyListenerListIterator
KeyListenerList::iterator KeyListenerListIterator
Definition: gui.h:442
Gui::mGraphics
Graphics * mGraphics
Definition: gui.h:422
Gui::getFont
Font * getFont() const
Definition: gui.h:159
noexcept2
#define noexcept2
Definition: localconsts.h:49
KeyListener
Definition: keylistener.h:78
Gui::handleMouseWheelMovedDown
void handleMouseWheelMovedDown(const MouseInput &mouseInput)
Definition: gui.cpp:1219
Gui::mForegroundColor
Color mForegroundColor
Definition: gui.h:512
Gui::setCursorType
void setCursorType(const CursorT index)
Definition: gui.h:195
Gui::getMousePressLength
int getMousePressLength() const
Definition: gui.cpp:1529
Gui::isLongPress
bool isLongPress() const
Definition: gui.h:308
Gui::mKeyListeners
KeyListenerList mKeyListeners
Definition: gui.h:447
Gui::mLastMouseX
int mLastMouseX
Definition: gui.h:462
Event
Definition: event.h:77
final
#define final
Definition: localconsts.h:45
Gui::getHelpFont
Font * getHelpFont() const
Definition: gui.h:165
FocusHandler
Definition: focushandler.h:83
Gui::draw
void draw()
Definition: gui.cpp:469
Gui::getSecureFont
Font * getSecureFont() const
Definition: gui.h:171
Gui::mLastMouseY
int mLastMouseY
Definition: gui.h:467
Gui::~Gui
~Gui()
Definition: gui.cpp:267
Gui::updateFonts
void updateFonts()
Definition: gui.cpp:823
Gui::postInit
void postInit(Graphics *const graphics)
Definition: gui.cpp:150
Gui::mMouseCursorAlpha
float mMouseCursorAlpha
Definition: gui.h:501
Gui::resetClickCount
void resetClickCount()
Definition: gui.cpp:979
Gui::mTime
time_t mTime
Definition: gui.h:514
Gui::handleModalFocus
void handleModalFocus()
Definition: gui.cpp:1433
KeyEvent
Definition: keyevent.h:84
Gui::mSecureFont
Font * mSecureFont
Definition: gui.h:496
gui
Gui * gui
Definition: gui.cpp:110
Gui::mFocusListeners
FocusListenerList mFocusListeners
Definition: gui.h:511
Gui::getInfoParticleFont
Font * getInfoParticleFont() const
Definition: gui.h:184
Gui::handleModalFocusGained
void handleModalFocusGained()
Definition: gui.cpp:1458
x
x
Definition: graphics_calcImageRect.hpp:72
Font
Definition: font.h:88
mouseeventtype.h
Gui::mForegroundColor2
Color mForegroundColor2
Definition: gui.h:513
MouseEventTypeT
MouseEventType ::T MouseEventTypeT
Definition: mouseeventtype.h:82
Gui::handleMouseMoved
void handleMouseMoved(const MouseInput &mouseInput)
Definition: gui.cpp:592
Gui::getMouseState
static uint8_t getMouseState(int &x, int &y)
Definition: gui.cpp:1170
Gui::addGlobalFocusListener
void addGlobalFocusListener(FocusListener *focusListener)
Definition: gui.cpp:1141
Gui::mLastMouseDragButton
MouseButtonT mLastMouseDragButton
Definition: gui.h:480
RETURNS_NONNULL
#define RETURNS_NONNULL
Definition: localconsts.h:166
Gui::videoResized
void videoResized() const
Definition: gui.cpp:535
Gui::getFocusHandler
FocusHandler * getFocusHandler() const
Definition: gui.h:153
Gui::distributeMouseEvent
void distributeMouseEvent(Widget *const source, const MouseEventTypeT type, const MouseButtonT button, const int x, const int y, const bool force, const bool toSourceOnly)
Definition: gui.cpp:853
Gui::getGraphics
Graphics * getGraphics() const
Definition: gui.cpp:1194
Gui::KeyListenerList
std::list< KeyListener * > KeyListenerList
Definition: gui.h:437
Gui::mClickCount
int mClickCount
Definition: gui.h:473
Gui::distributeKeyEventToGlobalKeyListeners
void distributeKeyEventToGlobalKeyListeners(KeyEvent &event)
Definition: gui.cpp:1385
cursor.h
Gui::handleInput
bool handleInput()
Definition: gui.cpp:387
Gui::getInput
SDLInput * getInput() const
Definition: gui.cpp:1204
std
Definition: mseprimitives.h:398
Gui::mCursorType
CursorT mCursorType
Definition: gui.h:503
MouseButtonT
MouseButton ::T MouseButtonT
Definition: mousebutton.h:77
Gui::createMouseEvent
MouseEvent * createMouseEvent(Window *const widget)
Definition: gui.cpp:985
Gui::setUseCustomCursor
void setUseCustomCursor(const bool customCursor)
Definition: gui.cpp:553
GuiConfigListener
Definition: guiconfiglistener.h:34
Gui::slowLogic
void slowLogic()
Definition: gui.cpp:322
Gui::mTop
Widget * mTop
Definition: gui.h:417
Gui::logic
void logic()
Definition: gui.cpp:301
Gui::removeGlobalKeyListener
void removeGlobalKeyListener(KeyListener *const keyListener)
Definition: gui.cpp:1214
Gui::mMouseCursors
ImageSet * mMouseCursors
Definition: gui.h:500
Gui::handleMouseReleased
void handleMouseReleased(const MouseInput &mouseInput)
Definition: gui.cpp:1080
restrict
#define restrict
Definition: localconsts.h:164
Gui::getAbsolutePosition
static void getAbsolutePosition(Widget *widget, int &x, int &y)
Definition: gui.cpp:1006
color.h
Gui::handleModalFocusReleased
void handleModalFocusReleased()
Definition: gui.cpp:1483
Gui::distributeKeyEvent
void distributeKeyEvent(KeyEvent &event) const
Definition: gui.cpp:1319
Gui::mInfoParticleFont
Font * mInfoParticleFont
Definition: gui.h:492
Gui::Gui
Gui()
Definition: gui.cpp:113
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition: localconsts.h:160
Gui::getLastMouseX
int getLastMouseX() const
Definition: gui.h:223
Gui::setGraphics
void setGraphics(Graphics *const graphics)
Definition: gui.cpp:1189
Gui::handleMousePressed
void handleMousePressed(const MouseInput &mouseInput)
Definition: gui.cpp:773
Gui::clearFonts
void clearFonts()
Definition: gui.cpp:371
MouseEvent
Definition: mouseevent.h:79
ImageSet
Definition: imageset.h:37
Color
Definition: color.h:74
CursorT
Cursor ::T CursorT
Definition: cursor.h:43
y
y
Definition: graphics_calcImageRect.hpp:72
A_NONNULL
#define A_NONNULL(...)
Definition: localconsts.h:167
Gui::mCustomCursor
bool mCustomCursor
Definition: gui.h:516
MouseStateType
#define MouseStateType
Definition: gui.h:99
Gui::mWidgetWithMouseQueue
std::deque< Widget * > mWidgetWithMouseQueue
Definition: gui.h:486
Gui::mInput
SDLInput * mInput
Definition: gui.h:427
Widget
Definition: widget.h:97
top
const Image *const restrict top
Definition: graphics_calcImageRect.hpp:39
Gui::getLastMouseY
int getLastMouseY() const
Definition: gui.h:226