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-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 #ifndef PROGS_MANAPLUS_GUI_VIEWPORT_H
24 #define PROGS_MANAPLUS_GUI_VIEWPORT_H
25 
26 #include "position.h"
27 
29 
31 
33 
34 class ActorSprite;
35 class Being;
36 class FloorItem;
37 class Graphics;
38 class Map;
39 class MapItem;
40 
45 class Viewport final : public WindowContainer,
46  public MouseListener,
47  public ConfigListener
48 {
49  public:
53  Viewport();
54 
56 
57 
61 
65  void setMap(Map *const map);
66 
70  void draw(Graphics *const graphics) override final A_NONNULL(2);
71 
72  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
73 
77  void logic() override final;
78 
84  void toggleMapDrawType();
85 
86  void toggleCameraMode();
87 
91  void mousePressed(MouseEvent &event) override final;
92 
96  void mouseDragged(MouseEvent &event) override final;
97 
101  void mouseReleased(MouseEvent &event) override final;
102 
106  void mouseMoved(MouseEvent &event) override final;
107 
111  void optionChanged(const std::string &name) override final;
112 
117  { return mPixelViewX; }
118 
123  { return mPixelViewY; }
124 
128  void scrollBy(const int x, const int y)
129  { mPixelViewX += x; mPixelViewY += y; }
130 
134  void cleanHoverItems();
135 
137  { return mMap; }
138 
139  void moveCamera(const int dx, const int dy);
140 
142  { return mCameraRelativeX; }
143 
145  { return mCameraRelativeY; }
146 
147  void setCameraRelativeX(const int n)
148  { mCameraRelativeX = n; updateMidVars(); }
149 
150  void setCameraRelativeY(const int n)
151  { mCameraRelativeY = n; updateMidVars(); }
152 
153  void moveCameraToActor(const BeingId actorId,
154  const int x,
155  const int y);
156 
157  void moveCameraToPosition(const int x, const int y);
158 
159  void moveCameraRelative(const int x, const int y);
160 
161  void returnCamera();
162 
163  void getMouseTile(int &destX, int &destY) const;
164 
165  void videoResized();
166 
167  int mMouseX;
168  int mMouseY;
170  protected:
171  friend class ActorManager;
172 
174  void clearHover(const ActorSprite *const actor);
175 
176  void updateMidVars();
177 
178  void updateMaxVars();
179 
180  static void validateSpeed();
181 
182  private:
187  void drawDebugPath(Graphics *const graphics) A_NONNULL(2);
188 
192  void drawPath(Graphics *const graphics,
193  const Path &path,
194  const Color &color)
195  const A_NONNULL(2);
196 
197  bool leftMouseAction();
198 
199  bool openContextMenu(const MouseEvent &event);
200 
201  void walkByMouse(const MouseEvent &event);
202 
203  void getMouseTile(const int x,
204  const int y,
205  int &destX,
206  int &destY) const;
207 
211  void followMouse();
212 
213  Map *mMap;
215  Being *mHoverBeing;
219  int mScrollRadius;
220  int mScrollLaziness;
223  int mMousePressX;
224  int mMousePressY;
225  int mPixelViewX;
226  int mPixelViewY;
231 
233 
234  int mCameraRelativeX;
235  int mCameraRelativeY;
236 
237  bool mShowBeingPopup;
238  bool mSelfMouseHeal;
240  bool mMouseDirectionMove;
241  bool mLongMouseClick;
243  bool mMouseClicked;
244  bool mPlayerFollowMouse;
245 };
246 
247 extern Viewport *viewport;
249 #endif // PROGS_MANAPLUS_GUI_VIEWPORT_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
int mViewXmax
Definition: viewport.h:229
void moveCameraToPosition(const int x, const int y)
Definition: viewport.cpp:1091
void setCameraRelativeY(const int n)
Definition: viewport.h:150
int mPixelViewX
Definition: viewport.h:194
void toggleMapDrawType()
Definition: viewport.cpp:250
void moveCameraRelative(const int x, const int y)
Definition: viewport.cpp:1102
void drawPath(Graphics *const graphics, const Path &path, const Color &color) const
Definition: viewport.cpp:353
void walkByMouse(const MouseEvent &event)
Definition: viewport.cpp:174
bool mMouseDirectionMove
Definition: viewport.h:205
void updateMaxVars()
Definition: viewport.cpp:1136
void moveCameraToActor(const BeingId actorId, const int x, const int y)
Definition: viewport.cpp:1076
void followMouse()
Definition: viewport.cpp:124
void mouseDragged(MouseEvent &event)
Definition: viewport.cpp:178
~Viewport()
Definition: viewport.cpp:82
Being * mHoverBeing
Definition: viewport.h:184
void mouseReleased(MouseEvent &event)
Definition: viewport.cpp:197
int mCameraRelativeX
Definition: viewport.h:199
#define A_WARN_UNUSED
Definition: localconsts.h:152
int mScrollCenterOffsetX
Definition: viewport.h:190
#define final
Definition: localconsts.h:45
int BeingId
Definition: beingid.h:29
bool mMouseClicked
Definition: viewport.h:207
int getCameraRelativeY() const
Definition: viewport.h:144
void toggleCameraMode()
Definition: viewport.cpp:254
int mMouseX
Definition: viewport.h:153
#define A_NONNULL(...)
Definition: localconsts.h:159
int mCameraRelativeY
Definition: viewport.h:200
bool mPlayerFollowMouse
Definition: viewport.h:208
int mScrollRadius
Definition: viewport.h:188
Viewport()
Definition: viewport.cpp:39
void returnCamera()
Definition: viewport.cpp:1110
void scrollBy(const int x, const int y)
Definition: viewport.h:128
bool mAllowMoveByMouse
Definition: viewport.h:242
FloorItem * mHoverItem
Definition: viewport.h:185
int mViewYmax
Definition: viewport.h:230
void safeDraw(Graphics *const graphics)
Definition: viewport.cpp:110
int mMidTileY
Definition: viewport.h:228
void videoResized()
Definition: viewport.cpp:270
time_t mLocalWalkTime
Definition: viewport.h:232
bool mShowBeingPopup
Definition: viewport.h:202
int getCameraY() const
Definition: viewport.h:122
static void validateSpeed()
Definition: viewport.cpp:1118
void moveCamera(const int dx, const int dy)
Definition: viewport.cpp:1069
int mMousePressY
Definition: viewport.h:193
int mScrollCenterOffsetY
Definition: viewport.h:191
void setMap(Map *const map)
Definition: viewport.cpp:88
void cleanHoverItems()
Definition: viewport.cpp:258
bool mSelfMouseHeal
Definition: viewport.h:203
void updateMidVars()
Definition: viewport.cpp:1128
int mScrollLaziness
Definition: viewport.h:189
void getMouseTile(int &destX, int &destY) const
Definition: viewport.cpp:613
Definition: map.h:71
bool mLongMouseClick
Definition: viewport.h:206
int mPixelViewY
Definition: viewport.h:195
int mMouseY
Definition: viewport.h:154
int getCameraX() const
Definition: viewport.h:114
MapItem * mHoverSign
Definition: viewport.h:186
Map * mMap
Definition: viewport.h:182
void mouseMoved(MouseEvent &event)
Definition: viewport.cpp:246
void logic()
Definition: viewport.cpp:115
bool mEnableLazyScrolling
Definition: viewport.h:204
void drawDebugPath(Graphics *const graphics)
Definition: viewport.cpp:128
int mMidTileX
Definition: viewport.h:227
int getCameraRelativeX() const
Definition: viewport.h:141
std::list< Position > Path
Definition: position.h:48
bool openContextMenu(const MouseEvent &event)
Definition: viewport.cpp:132
Definition: color.h:74
void optionChanged(const std::string &name)
Definition: viewport.cpp:228
void setCameraRelativeX(const int n)
Definition: viewport.h:147
#define override
Definition: localconsts.h:46
Map * getMap() const
Definition: viewport.h:136
void mousePressed(MouseEvent &event)
Definition: viewport.cpp:137
bool leftMouseAction()
Definition: viewport.cpp:265
Definition: being.h:93
void draw(Graphics *const graphics)
Definition: viewport.cpp:92
#define noexcept2
Definition: localconsts.h:49
int mMousePressX
Definition: viewport.h:192
Viewport * viewport
Definition: viewport.cpp:35
void clearHover(const ActorSprite *const actor)
Clears any matching hovers.
Definition: viewport.cpp:1053