GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/progs/manaplus/gui/viewport.h Lines: 0 8 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
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-2017  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
28
#include "enums/simpletypes/beingid.h"
29
30
#include "gui/widgets/windowcontainer.h"
31
32
#include "listeners/mouselistener.h"
33
34
class ActorSprite;
35
class Being;
36
class FloorItem;
37
class Graphics;
38
class Map;
39
class MapItem;
40
41
/**
42
 * The viewport on the map. Displays the current map and handles mouse input
43
 * and the popup menu.
44
 */
45
class Viewport final : public WindowContainer,
46
                       public MouseListener,
47
                       public ConfigListener
48
{
49
    public:
50
        /**
51
         * Constructor.
52
         */
53
        Viewport();
54
55
        A_DELETE_COPY(Viewport)
56
57
        /**
58
         * Destructor.
59
         */
60
        ~Viewport();
61
62
        /**
63
         * Sets the map displayed by the viewport.
64
         */
65
        void setMap(Map *const map);
66
67
        /**
68
         * Draws the viewport.
69
         */
70
        void draw(Graphics *const graphics) override final A_NONNULL(2);
71
72
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
73
74
        /**
75
         * Implements player to keep following mouse.
76
         */
77
        void logic() override final;
78
79
        /**
80
         * Toggles whether the path debug graphics are shown. normal,
81
         * debug with all images and grid, debug with out big images
82
         * and with out grid.
83
         */
84
        void toggleMapDrawType();
85
86
        void toggleCameraMode();
87
88
        /**
89
         * Handles mouse press on map.
90
         */
91
        void mousePressed(MouseEvent &event) override final;
92
93
        /**
94
         * Handles mouse move on map
95
         */
96
        void mouseDragged(MouseEvent &event) override final;
97
98
        /**
99
         * Handles mouse button release on map.
100
         */
101
        void mouseReleased(MouseEvent &event) override final;
102
103
        /**
104
         * Handles mouse move on map.
105
         */
106
        void mouseMoved(MouseEvent &event) override final;
107
108
        /**
109
         * A relevant config option changed.
110
         */
111
        void optionChanged(const std::string &name) override final;
112
113
        /**
114
         * Returns camera x offset in pixels.
115
         */
116
        int getCameraX() const noexcept2 A_WARN_UNUSED
117
        { return mPixelViewX; }
118
119
        /**
120
         * Returns camera y offset in pixels.
121
         */
122
        int getCameraY() const noexcept2 A_WARN_UNUSED
123
        { return mPixelViewY; }
124
125
        /**
126
         * Changes viewpoint by relative pixel coordinates.
127
         */
128
        void scrollBy(const int x, const int y)
129
        { mPixelViewX += x; mPixelViewY += y; }
130
131
        /**
132
         * Clear all hover item, being etc
133
         */
134
        void cleanHoverItems();
135
136
        Map *getMap() const noexcept2 A_WARN_UNUSED
137
        { return mMap; }
138
139
        void moveCamera(const int dx, const int dy);
140
141
        int getCameraRelativeX() const noexcept2 A_WARN_UNUSED
142
        { return mCameraRelativeX; }
143
144
        int getCameraRelativeY() const noexcept2 A_WARN_UNUSED
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 = 0,
155
                               const int y = 0);
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;                /**< Current mouse position in pixels. */
168
        int mMouseY;                /**< Current mouse position in pixels. */
169
170
    protected:
171
        friend class ActorManager;
172
173
        /// Clears any matching hovers
174
        void clearHover(const ActorSprite *const actor);
175
176
        void updateMidVars();
177
178
        void updateMaxVars();
179
180
        static void validateSpeed();
181
182
    private:
183
        /**
184
         * Finds a path from the player to the mouse, and draws it. This is for
185
         * debug purposes.
186
         */
187
        void drawDebugPath(Graphics *const graphics) A_NONNULL(2);
188
189
        /**
190
         * Draws the given path.
191
         */
192
        void drawPath(Graphics *const graphics,
193
                      const Path &path,
194
                      const Color &color = Color(255, 0, 0))
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
208
        /**
209
         * Make the player go to the mouse position.
210
         */
211
        void followMouse();
212
213
        Map *mMap;                   /**< The current map. */
214
215
        Being *mHoverBeing;          /**< Being mouse is currently over. */
216
        FloorItem *mHoverItem;       /**< FloorItem mouse is currently over. */
217
        MapItem *mHoverSign;         /**< Map sign mouse is currently over. */
218
219
        int mScrollRadius;
220
        int mScrollLaziness;
221
        int mScrollCenterOffsetX;
222
        int mScrollCenterOffsetY;
223
        int mMousePressX;
224
        int mMousePressY;
225
        int mPixelViewX;            /**< Current viewpoint in pixels. */
226
        int mPixelViewY;            /**< Current viewpoint in pixels. */
227
        int mMidTileX;
228
        int mMidTileY;
229
        int mViewXmax;
230
        int mViewYmax;
231
232
        time_t mLocalWalkTime;
233
234
        int mCameraRelativeX;
235
        int mCameraRelativeY;
236
237
        bool mShowBeingPopup;
238
        bool mSelfMouseHeal;
239
        bool mEnableLazyScrolling;
240
        bool mMouseDirectionMove;
241
        bool mLongMouseClick;
242
        bool mAllowMoveByMouse;
243
        bool mMouseClicked;
244
        bool mPlayerFollowMouse;
245
};
246
247
extern Viewport *viewport;           /**< The viewport. */
248
249
#endif  // PROGS_MANAPLUS_GUI_VIEWPORT_H