ManaPlus
viewport.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  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef PROGS_MANAPLUS_GUI_VIEWPORT_H
25 #define PROGS_MANAPLUS_GUI_VIEWPORT_H
26 
27 #include "position.h"
28 
30 
32 
34 
35 class ActorSprite;
36 class Being;
37 class FloorItem;
38 class Graphics;
39 class Map;
40 class MapItem;
41 
46 class Viewport final : public WindowContainer,
47  public MouseListener,
48  public ConfigListener
49 {
50  public:
55 
57 
58 
62 
66  void setMap(Map *const map);
67 
71  void draw(Graphics *const graphics) override final A_NONNULL(2);
72 
73  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
74 
79 
86 
88 
93 
98 
103 
108 
112  void optionChanged(const std::string &name) override final;
113 
118  { return mPixelViewX; }
119 
124  { return mPixelViewY; }
125 
129  void scrollBy(const int x, const int y)
130  { mPixelViewX += x; mPixelViewY += y; }
131 
136 
138  { return mMap; }
139 
140  void moveCamera(const int dx, const int dy);
141 
143  { return mCameraRelativeX; }
144 
146  { return mCameraRelativeY; }
147 
148  void setCameraRelativeX(const int n)
149  { mCameraRelativeX = n; updateMidVars(); }
150 
151  void setCameraRelativeY(const int n)
152  { mCameraRelativeY = n; updateMidVars(); }
153 
154  void moveCameraToActor(const BeingId actorId,
155  const int x,
156  const int y);
157 
158  void moveCameraToPosition(const int x, const int y);
159 
160  void moveCameraRelative(const int x, const int y);
161 
162  void returnCamera();
163 
164  void getMouseTile(int &destX, int &destY) const;
165 
166  void videoResized();
167 
168  int mMouseX;
169  int mMouseY;
171  protected:
172  friend class ActorManager;
173 
175  void clearHover(const ActorSprite *const actor);
176 
177  void updateMidVars();
178 
179  void updateMaxVars();
180 
181  static void validateSpeed();
182 
183  private:
188  void drawDebugPath(Graphics *const graphics) A_NONNULL(2);
189 
193  void drawPath(Graphics *const graphics,
194  const Path &path,
195  const Color &color)
196  const A_NONNULL(2);
197 
199 
200  bool openContextMenu(const MouseEvent &event);
201 
202  void walkByMouse(const MouseEvent &event);
203 
204  void getMouseTile(const int x,
205  const int y,
206  int &destX,
207  int &destY) const;
208 
212  void followMouse();
213 
214  Map *mMap;
216  Being *mHoverBeing;
220  int mScrollRadius;
221  int mScrollLaziness;
224  int mMousePressX;
225  int mMousePressY;
226  int mPixelViewX;
227  int mPixelViewY;
232 
234 
235  int mCameraRelativeX;
236  int mCameraRelativeY;
237 
238  bool mShowBeingPopup;
239  bool mSelfMouseHeal;
241  bool mMouseDirectionMove;
242  bool mLongMouseClick;
244  bool mMouseClicked;
245  bool mPlayerFollowMouse;
246 };
247 
248 extern Viewport *viewport;
250 #endif // PROGS_MANAPLUS_GUI_VIEWPORT_H
int BeingId
Definition: beingid.h:30
Definition: being.h:96
Definition: color.h:76
Definition: map.h:75
int mMouseX
Definition: viewport.h:154
void clearHover(const ActorSprite *const actor)
Clears any matching hovers.
Definition: viewport.cpp:1054
void setCameraRelativeX(const int n)
Definition: viewport.h:148
void scrollBy(const int x, const int y)
Definition: viewport.h:129
void updateMaxVars()
Definition: viewport.cpp:1137
bool mAllowMoveByMouse
Definition: viewport.h:243
Being * mHoverBeing
Definition: viewport.h:185
void logic()
Definition: viewport.cpp:116
int mScrollLaziness
Definition: viewport.h:190
void toggleMapDrawType()
Definition: viewport.cpp:251
int mMousePressX
Definition: viewport.h:193
Map * mMap
Definition: viewport.h:183
void getMouseTile(int &destX, int &destY) const
Definition: viewport.cpp:614
int mCameraRelativeY
Definition: viewport.h:201
int mPixelViewX
Definition: viewport.h:195
int mViewXmax
Definition: viewport.h:230
void moveCameraToActor(const BeingId actorId, const int x, const int y)
Definition: viewport.cpp:1077
bool openContextMenu(const MouseEvent &event)
bool mLongMouseClick
Definition: viewport.h:207
bool mMouseClicked
Definition: viewport.h:208
bool leftMouseAction()
void moveCamera(const int dx, const int dy)
static void validateSpeed()
Definition: viewport.cpp:1119
bool mPlayerFollowMouse
Definition: viewport.h:209
Map * getMap() const
Definition: viewport.h:137
void toggleCameraMode()
Definition: viewport.cpp:255
int mScrollCenterOffsetX
Definition: viewport.h:191
void followMouse()
bool mEnableLazyScrolling
Definition: viewport.h:205
bool mShowBeingPopup
Definition: viewport.h:203
void optionChanged(const std::string &name)
Definition: viewport.cpp:229
void drawPath(Graphics *const graphics, const Path &path, const Color &color) const
void mouseMoved(MouseEvent &event)
Definition: viewport.cpp:247
void mousePressed(MouseEvent &event)
Definition: viewport.cpp:138
void moveCameraRelative(const int x, const int y)
Definition: viewport.cpp:1103
void videoResized()
FloorItem * mHoverItem
Definition: viewport.h:186
void draw(Graphics *const graphics)
Definition: viewport.cpp:93
int getCameraY() const
Definition: viewport.h:123
bool mMouseDirectionMove
Definition: viewport.h:206
bool mSelfMouseHeal
Definition: viewport.h:204
int mCameraRelativeX
Definition: viewport.h:200
void walkByMouse(const MouseEvent &event)
void mouseDragged(MouseEvent &event)
Definition: viewport.cpp:179
void updateMidVars()
Definition: viewport.cpp:1129
MapItem * mHoverSign
Definition: viewport.h:187
int mMidTileY
Definition: viewport.h:229
int mPixelViewY
Definition: viewport.h:196
void setCameraRelativeY(const int n)
Definition: viewport.h:151
int mViewYmax
Definition: viewport.h:231
int mScrollRadius
Definition: viewport.h:189
void setMap(Map *const map)
Definition: viewport.cpp:89
int mMidTileX
Definition: viewport.h:228
void drawDebugPath(Graphics *const graphics)
int getCameraRelativeY() const
Definition: viewport.h:145
void safeDraw(Graphics *const graphics)
Definition: viewport.cpp:111
void cleanHoverItems()
void returnCamera()
Definition: viewport.cpp:1111
time_t mLocalWalkTime
Definition: viewport.h:233
void moveCameraToPosition(const int x, const int y)
Definition: viewport.cpp:1092
int mScrollCenterOffsetY
Definition: viewport.h:192
int getCameraRelativeX() const
Definition: viewport.h:142
int getCameraX() const
Definition: viewport.h:115
void mouseReleased(MouseEvent &event)
Definition: viewport.cpp:198
int mMouseY
Definition: viewport.h:155
int mMousePressY
Definition: viewport.h:194
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
std::list< Position > Path
Definition: position.h:49
Viewport * viewport
Definition: viewport.cpp:36