FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
cursor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_CURSOR_H
23 #define FIFE_CURSOR_H
24 
25 // Standard C++ library includes
26 
27 // 3rd party library includes
28 
29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder
33 
34 #include "animation.h"
35 
36 struct SDL_Cursor;
37 
38 namespace FIFE {
39 
40  class RenderBackend;
41  class TimeManager;
42 
53  };
54 
55  enum NativeCursor {
56  // Start on 1000000 to avoid id-clashes with SDL
57  NC_ARROW = 1000000, // Standard arrow
58  NC_IBEAM, // I-beam for text selection
59  NC_WAIT, // Hourglass
60  NC_CROSS, // Crosshair
61  NC_WAITARROW, // Small wait cursor (or Wait if not available)
62  NC_RESIZENWSE, // Double arrow pointing northwest and southeast
63  NC_RESIZENESW, // Double arrow pointing northeast and southwest
64  NC_RESIZEWE, // Double arrow pointing west and east
65  NC_RESIZENS, // Double arrow pointing north and south
66  NC_RESIZEALL, // Four-pointed arrow pointing north, south, east, and west
67  NC_NO, // Slashed circle
68  NC_HAND // Hand. Common for links, etc.
69  };
70 
73  class Cursor {
74  public:
77  Cursor(RenderBackend* renderbackend);
78 
81  virtual ~Cursor() { invalidate(); }
82 
83  void invalidate();
84 
87  virtual void draw();
88 
92  void set(uint32_t cursor_id=0);
93 
97  void set(ImagePtr image);
98 
102  void set(AnimationPtr anim);
103 
110  void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
111 
118  void setDrag(AnimationPtr anim, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
119 
122  void resetDrag();
123 
127 
130  uint32_t getId() const { return m_cursor_id; }
131 
135 
139 
143 
147 
151 
154  uint32_t getX() const { return m_mx; }
155 
158  uint32_t getY() const { return m_my; }
159 
163  void setPosition(uint32_t x, uint32_t y);
164 
167  void getPosition(int32_t* x, int32_t* y);
168 
175  void setNativeImageCursorEnabled(bool native_image_cursor_enabled);
176 
180  bool isNativeImageCursorEnabled() const;
181 
182  protected:
186  void setNativeCursor(uint32_t cursor_id);
187 
192  bool setNativeImageCursor(ImagePtr image);
193 
201  uint32_t getNativeId(uint32_t cursor_id);
202 
203  private:
207 
208  SDL_Cursor* m_native_cursor;
209 
212 
215 
217 
220 
223  int32_t m_mx;
224  int32_t m_my;
226 
230  };
231 
232 } //FIFE
233 
234 #endif
uint32_t m_animtime
Definition: cursor.h:218
Abstract interface for all the renderbackends.
MouseCursorType m_cursor_type
Definition: cursor.h:205
MouseCursorType m_drag_type
Definition: cursor.h:206
TimeManager * m_timemanager
Definition: cursor.h:225
int32_t m_drag_offset_x
Definition: cursor.h:221
bool isNativeImageCursorEnabled() const
Returns whether cursors set to an image or an animation are drawn natively.
Definition: cursor.cpp:341
virtual ~Cursor()
Destructor.
Definition: cursor.h:81
ImagePtr m_cursor_image
Definition: cursor.h:210
ImagePtr getImage()
Gets the current mouse image.
Definition: cursor.h:134
int32_t m_my
Definition: cursor.h:224
bool m_native_image_cursor_enabled
Definition: cursor.h:228
ImagePtr m_cursor_drag_image
Definition: cursor.h:211
MouseCursorType
Defines the type of shown cursor native -> default cursor image -> cursor from image pool animation -...
Definition: cursor.h:48
void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0)
Sets the current drag image cursor.
Definition: cursor.cpp:123
AnimationPtr m_cursor_animation
Definition: cursor.h:213
bool m_invalidated
Definition: cursor.h:227
void setNativeCursor(uint32_t cursor_id)
Sets the cursor to a native type.
Definition: cursor.cpp:272
void invalidate()
Definition: cursor.cpp:169
MouseCursorType getType() const
Gets the current mouse cursor type.
Definition: cursor.h:126
void setNativeImageCursorEnabled(bool native_image_cursor_enabled)
Enables or disables the native image cursor feature.
Definition: cursor.cpp:329
virtual void draw()
draws cursor on screen
Definition: cursor.cpp:179
int32_t m_drag_offset_y
Definition: cursor.h:222
AnimationPtr getAnimation()
Gets the current mouse animation.
Definition: cursor.h:138
uint32_t m_drag_animtime
Definition: cursor.h:219
uint32_t getId() const
Gets the current mouse cursor handle.
Definition: cursor.h:130
MouseCursorType getDragType() const
Gets the current mouse cursor type.
Definition: cursor.h:142
uint32_t m_cursor_id
Definition: cursor.h:204
Time Manager.
Definition: timemanager.h:50
void resetDrag()
Resets the cursor drag type to CURSOR_NONE.
Definition: cursor.cpp:147
uint32_t getNativeId(uint32_t cursor_id)
To get some consistancy between platforms, this function checks if cursor_id matches any of the value...
Definition: cursor.cpp:242
ImagePtr m_native_cursor_image
Definition: cursor.h:229
AnimationPtr m_cursor_drag_animation
Definition: cursor.h:214
Cursor(RenderBackend *renderbackend)
Constructor.
Definition: cursor.cpp:47
Cursor class manages mouse cursor handling.
Definition: cursor.h:73
AnimationPtr getDragAnimation()
Gets the current mouse drag animation.
Definition: cursor.h:150
bool setNativeImageCursor(ImagePtr image)
Sets the SDL cursor to the specified image.
Definition: cursor.cpp:286
void getPosition(int32_t *x, int32_t *y)
Get the current mouse position.
Definition: cursor.cpp:164
uint32_t getY() const
Gets the current mouse y position.
Definition: cursor.h:158
int32_t m_mx
Definition: cursor.h:223
RenderBackend * m_renderbackend
Definition: cursor.h:216
unsigned int uint32_t
Definition: core.h:40
SDL_Cursor * m_native_cursor
Definition: cursor.h:208
NativeCursor
Definition: cursor.h:55
ImagePtr getDragImage()
Gets the current mouse drag image.
Definition: cursor.h:146
uint32_t getX() const
Gets the current mouse x position.
Definition: cursor.h:154
void setPosition(uint32_t x, uint32_t y)
Set the mouse position.
Definition: cursor.cpp:158