FIFE  2008.0
cursor.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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 
49  CURSOR_NONE,
50  CURSOR_NATIVE,
51  CURSOR_IMAGE,
52  CURSOR_ANIMATION
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
68  NC_RESIZESE, //
69  NC_RESIZESW, //
70  NC_RESIZENE, //
71  NC_RESIZEE, //
72  NC_RESIZEW, //
73  NC_RESIZEN, //
74  NC_RESIZES, //
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 
119  void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
120 
125  void setDrag(AnimationPtr anim, int32_t drag_offset_x=0, int32_t drag_offset_y=0);
126 
129  void resetDrag();
130 
133  MouseCursorType getType() const { return m_cursor_type; }
134 
137  uint32_t getId() const { return m_cursor_id; }
138 
141  ImagePtr getImage() { return m_cursor_image; }
142 
145  AnimationPtr getAnimation() { return m_cursor_animation; }
146 
149  MouseCursorType getDragType() const { return m_drag_type; }
150 
153  ImagePtr getDragImage() { return m_cursor_drag_image; }
154 
157  AnimationPtr getDragAnimation() { return m_cursor_drag_animation; }
158 
161  uint32_t getX() const { return m_mx; }
162 
165  uint32_t getY() const { return m_my; }
166 
170  void setPosition(uint32_t x, uint32_t y);
171 
174  void getPosition(int32_t* x, int32_t* y);
175 
176  protected:
180  void setNativeCursor(uint32_t cursor_id);
181 
189  uint32_t getNativeId(uint32_t cursor_id);
190 
191  private:
192  uint32_t m_cursor_id;
193  uint32_t m_drag_id;
194  MouseCursorType m_cursor_type;
195  MouseCursorType m_drag_type;
196 
197  SDL_Cursor* m_native_cursor;
198 
199  ImagePtr m_cursor_image;
200  ImagePtr m_cursor_drag_image;
201 
202  AnimationPtr m_cursor_animation;
203  AnimationPtr m_cursor_drag_animation;
204 
205  RenderBackend* m_renderbackend;
206 
207  uint32_t m_animtime;
208  uint32_t m_drag_animtime;
209 
210  int32_t m_drag_offset_x;
211  int32_t m_drag_offset_y;
212  int32_t m_mx;
213  int32_t m_my;
214  TimeManager* m_timemanager;
215 
216  bool m_invalidated;
217  };
218 
219 } //FIFE
220 
221 #endif
virtual ~Cursor()
Definition: cursor.h:92
ImagePtr getImage()
Definition: cursor.h:141
MouseCursorType
Definition: cursor.h:48
void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0)
Definition: cursor.cpp:136
void setNativeCursor(uint32_t cursor_id)
Definition: cursor.cpp:332
MouseCursorType getType() const
Definition: cursor.h:133
virtual void draw()
Definition: cursor.cpp:193
AnimationPtr getAnimation()
Definition: cursor.h:145
uint32_t getId() const
Definition: cursor.h:137
MouseCursorType getDragType() const
Definition: cursor.h:149
void set(uint32_t cursor_id=0)
Definition: cursor.cpp:95
void resetDrag()
Definition: cursor.cpp:160
uint32_t getNativeId(uint32_t cursor_id)
Definition: cursor.cpp:244
Cursor(RenderBackend *renderbackend)
Definition: cursor.cpp:76
AnimationPtr getDragAnimation()
Definition: cursor.h:157
void getPosition(int32_t *x, int32_t *y)
Definition: cursor.cpp:177
uint32_t getY() const
Definition: cursor.h:165
NativeCursor
Definition: cursor.h:60
ImagePtr getDragImage()
Definition: cursor.h:153
uint32_t getX() const
Definition: cursor.h:161
void setPosition(uint32_t x, uint32_t y)
Definition: cursor.cpp:171
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39