FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
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 struct SDL_Cursor;
35 
36 namespace FIFE {
37 
38  class ImagePool;
39  class AnimationPool;
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(ImagePool* imgpool, AnimationPool* animpool, RenderBackend* renderbackend);
89 
92  virtual ~Cursor() { invalidate(); }
93 
94  void invalidate();
95 
98  virtual void draw();
99 
104  void set(MouseCursorType ctype, unsigned int cursor_id=0);
105 
111  void setDrag(MouseCursorType ctype, unsigned int drag_id=0, int drag_offset_x=0, int drag_offset_y=0);
112 
115  MouseCursorType getType() const { return m_cursor_type; }
116 
119  unsigned int getId() const { return m_cursor_id; }
120 
123  MouseCursorType getDragType() const { return m_drag_type; }
124 
127  unsigned int getDragId() const { return m_drag_id; }
128 
131  unsigned int getX() const {return m_mx;}
132 
135  unsigned int getY() const {return m_my;}
136 
137  protected:
141  void setNativeCursor(unsigned int cursor_id);
142 
150  unsigned int getNativeId(unsigned int cursor_id);
151 
152  private:
153  unsigned int m_cursor_id;
154  unsigned int m_drag_id;
155  MouseCursorType m_cursor_type;
156  MouseCursorType m_drag_type;
157 
158  SDL_Cursor* m_native_cursor;
159 
160  RenderBackend* m_renderbackend;
161  ImagePool* m_imgpool;
162  AnimationPool* m_animpool;
163 
164  unsigned int m_animtime;
165  unsigned int m_drag_animtime;
166 
167  int m_drag_offset_x;
168  int m_drag_offset_y;
169  int m_mx;
170  int m_my;
171  TimeManager* m_timemanager;
172 
173  bool m_invalidated;
174  };
175 
176 } //FIFE
177 
178 #endif