FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cursor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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 
60  enum NativeCursor {
61  // Start on 1000000 to avoid id-clashes with X11 and windows
62  NC_ARROW = 1000000, // Standard arrow
63  NC_IBEAM, // I-beam for text selection
64  NC_WAIT, // Hourglass
65  NC_CROSS, // Crosshair
66  NC_UPARROW, // Vertical arrow
67  NC_RESIZENW, // Cursor for resize in northwest corner
75  NC_RESIZEALL, // Four-pointed arrow pointing north, south, east, and west
76  NC_NO, // Slashed circle
77  NC_HAND, // Hand. Common for links, etc.
78  NC_APPSTARTING, // Standard arrow and small hourglass
79  NC_HELP // Arrow and question mark
80  };
81 
84  class Cursor {
85  public:
88  Cursor(RenderBackend* renderbackend);
89 
92  virtual ~Cursor() { invalidate(); }
93 
94  void invalidate();
95 
98  virtual void draw();
99 
103  void set(uint32_t cursor_id=0);
104 
108  void set(ImagePtr image);
109 
113  void set(AnimationPtr anim);
114 
121  void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
122 
129  void setDrag(AnimationPtr anim, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
130 
133  void resetDrag();
134 
138 
141  uint32_t getId() const { return m_cursor_id; }
142 
146 
150 
154 
158 
162 
165  uint32_t getX() const { return m_mx; }
166 
169  uint32_t getY() const { return m_my; }
170 
174  void setPosition(uint32_t x, uint32_t y);
175 
178  void getPosition(int32_t* x, int32_t* y);
179 
180  protected:
184  void setNativeCursor(uint32_t cursor_id);
185 
193  uint32_t getNativeId(uint32_t cursor_id);
194 
195  private:
199 
200  SDL_Cursor* m_native_cursor;
201 
204 
207 
209 
212 
215  int32_t m_mx;
216  int32_t m_my;
218 
220  };
221 
222 } //FIFE
223 
224 #endif
uint32_t m_animtime
Definition: cursor.h:210
Abstract interface for all the renderbackends.
Definition: renderbackend.h:92
MouseCursorType m_cursor_type
Definition: cursor.h:197
MouseCursorType m_drag_type
Definition: cursor.h:198
TimeManager * m_timemanager
Definition: cursor.h:217
int32_t m_drag_offset_x
Definition: cursor.h:213
virtual ~Cursor()
Destructor.
Definition: cursor.h:92
ImagePtr m_cursor_image
Definition: cursor.h:202
ImagePtr getImage()
Gets the current mouse image.
Definition: cursor.h:145
int32_t m_my
Definition: cursor.h:216
ImagePtr m_cursor_drag_image
Definition: cursor.h:203
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:138
AnimationPtr m_cursor_animation
Definition: cursor.h:205
bool m_invalidated
Definition: cursor.h:219
void setNativeCursor(uint32_t cursor_id)
Sets the cursor to a native type.
Definition: cursor.cpp:334
void invalidate()
Definition: cursor.cpp:184
MouseCursorType getType() const
Gets the current mouse cursor type.
Definition: cursor.h:137
virtual void draw()
draws cursor on screen
Definition: cursor.cpp:195
int32_t m_drag_offset_y
Definition: cursor.h:214
AnimationPtr getAnimation()
Gets the current mouse animation.
Definition: cursor.h:149
uint32_t m_drag_animtime
Definition: cursor.h:211
uint32_t getId() const
Gets the current mouse cursor handle.
Definition: cursor.h:141
MouseCursorType getDragType() const
Gets the current mouse cursor type.
Definition: cursor.h:153
uint32_t m_cursor_id
Definition: cursor.h:196
Time Manager.
Definition: timemanager.h:50
void set(uint32_t cursor_id=0)
Sets the current mouse cursor.
Definition: cursor.cpp:97
void resetDrag()
Resets the cursor drag type to CURSOR_NONE.
Definition: cursor.cpp:162
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:246
AnimationPtr m_cursor_drag_animation
Definition: cursor.h:206
Cursor(RenderBackend *renderbackend)
Constructor.
Definition: cursor.cpp:79
Cursor class manages mouse cursor handling.
Definition: cursor.h:84
AnimationPtr getDragAnimation()
Gets the current mouse drag animation.
Definition: cursor.h:161
void getPosition(int32_t *x, int32_t *y)
Get the current mouse position.
Definition: cursor.cpp:179
uint32_t getY() const
Gets the current mouse y position.
Definition: cursor.h:169
int32_t m_mx
Definition: cursor.h:215
RenderBackend * m_renderbackend
Definition: cursor.h:208
unsigned int uint32_t
Definition: core.h:40
SDL_Cursor * m_native_cursor
Definition: cursor.h:200
NativeCursor
Defines some common native cursors between platforms.
Definition: cursor.h:60
ImagePtr getDragImage()
Gets the current mouse drag image.
Definition: cursor.h:157
uint32_t getX() const
Gets the current mouse x position.
Definition: cursor.h:165
void setPosition(uint32_t x, uint32_t y)
Set the mouse position.
Definition: cursor.cpp:173