1 | /************************************************************************
|
---|
2 | filename: CEGUIMouseCursor.h
|
---|
3 | created: 21/2/2004
|
---|
4 | author: Paul D Turner
|
---|
5 |
|
---|
6 | purpose: Defines interface for the MouseCursor class
|
---|
7 | *************************************************************************/
|
---|
8 | /*************************************************************************
|
---|
9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUIMouseCursor_h_
|
---|
27 | #define _CEGUIMouseCursor_h_
|
---|
28 |
|
---|
29 | #include "CEGUIBase.h"
|
---|
30 | #include "CEGUIString.h"
|
---|
31 | #include "CEGUISingleton.h"
|
---|
32 | #include "CEGUIVector.h"
|
---|
33 | #include "CEGUIRect.h"
|
---|
34 | #include "CEGUIEventSet.h"
|
---|
35 | #include "CEGUIInputEvent.h"
|
---|
36 | #include "CEGUIUDim.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | #if defined(_MSC_VER)
|
---|
40 | # pragma warning(push)
|
---|
41 | # pragma warning(disable : 4275)
|
---|
42 | # pragma warning(disable : 4251)
|
---|
43 | #endif
|
---|
44 |
|
---|
45 |
|
---|
46 | // Start of CEGUI namespace section
|
---|
47 | namespace CEGUI
|
---|
48 | {
|
---|
49 |
|
---|
50 | /*!
|
---|
51 | \brief
|
---|
52 | Enumeration of special values used for mouse cursor settings in Window objects.
|
---|
53 | */
|
---|
54 | enum MouseCursorImage
|
---|
55 | {
|
---|
56 | BlankMouseCursor = 0, //!< No image should be displayed for the mouse cursor.
|
---|
57 | DefaultMouseCursor = -1 //!< The default mouse cursor image should be displayed.
|
---|
58 | };
|
---|
59 |
|
---|
60 |
|
---|
61 | /*!
|
---|
62 | \brief
|
---|
63 | Class that allows access to the GUI system mouse cursor.
|
---|
64 |
|
---|
65 | The MouseCursor provides functionality to access the position and imagery of the mouse cursor / pointer
|
---|
66 | */
|
---|
67 | class CEGUIEXPORT MouseCursor : public EventSet, public Singleton<MouseCursor>
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | static const String EventNamespace; //!< Namespace for global events
|
---|
71 |
|
---|
72 | /*************************************************************************
|
---|
73 | Event name constants
|
---|
74 | *************************************************************************/
|
---|
75 | // generated internally by MouseCursor
|
---|
76 | static const String EventImageChanged; //!< The cursor image of the widget has changed.
|
---|
77 |
|
---|
78 |
|
---|
79 | /*!
|
---|
80 | \brief
|
---|
81 | Constructor for MouseCursor objects
|
---|
82 | */
|
---|
83 | MouseCursor(void);
|
---|
84 |
|
---|
85 |
|
---|
86 | /*!
|
---|
87 | \brief
|
---|
88 | Destructor for MouseCursor objects
|
---|
89 | */
|
---|
90 | ~MouseCursor(void);
|
---|
91 |
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | \brief
|
---|
95 | Return singleton MouseCursor object
|
---|
96 |
|
---|
97 | \return
|
---|
98 | Singleton MouseCursor object
|
---|
99 | */
|
---|
100 | static MouseCursor& getSingleton(void);
|
---|
101 |
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | \brief
|
---|
105 | Return pointer to singleton MouseCursor object
|
---|
106 |
|
---|
107 | \return
|
---|
108 | Pointer to singleton MouseCursor object
|
---|
109 | */
|
---|
110 | static MouseCursor* getSingletonPtr(void);
|
---|
111 |
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | \brief
|
---|
115 | Set the current mouse cursor image
|
---|
116 |
|
---|
117 | \param imageset
|
---|
118 | String object holding the name of the Imageset that contains the desired Image.
|
---|
119 |
|
---|
120 | \param image_name
|
---|
121 | String object holding the name of the desired Image on Imageset \a imageset.
|
---|
122 |
|
---|
123 | \return
|
---|
124 | Nothing.
|
---|
125 |
|
---|
126 | \exception UnknownObjectException thrown if \a imageset is not known, or if \a imageset contains no Image named \a image_name.
|
---|
127 | */
|
---|
128 | void setImage(const String& imageset, const String& image_name);
|
---|
129 |
|
---|
130 |
|
---|
131 | /*!
|
---|
132 | \brief
|
---|
133 | Set the current mouse cursor image
|
---|
134 | */
|
---|
135 | void setImage(const Image* image);
|
---|
136 |
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | \brief
|
---|
140 | Get the current mouse cursor image
|
---|
141 | \return
|
---|
142 | The current image used to draw mouse cursor.
|
---|
143 | */
|
---|
144 | const Image* getImage(void) const {return d_cursorImage;}
|
---|
145 |
|
---|
146 |
|
---|
147 | /*!
|
---|
148 | \brief
|
---|
149 | Makes the cursor draw itself
|
---|
150 |
|
---|
151 | \return
|
---|
152 | Nothing
|
---|
153 | */
|
---|
154 | void draw(void) const;
|
---|
155 |
|
---|
156 |
|
---|
157 | /*!
|
---|
158 | \brief
|
---|
159 | Set the current mouse cursor position
|
---|
160 |
|
---|
161 | \param position
|
---|
162 | Point object describing the new location for the mouse. This will be clipped to within the renderer screen area.
|
---|
163 | */
|
---|
164 | void setPosition(const Point& position);
|
---|
165 |
|
---|
166 |
|
---|
167 | /*!
|
---|
168 | \brief
|
---|
169 | Offset the mouse cursor position by the deltas specified in \a offset.
|
---|
170 |
|
---|
171 | \param offset
|
---|
172 | Point object which describes the amount to move the cursor in each axis.
|
---|
173 |
|
---|
174 | \return
|
---|
175 | Nothing.
|
---|
176 | */
|
---|
177 | void offsetPosition(const Point& offset);
|
---|
178 |
|
---|
179 |
|
---|
180 | /*!
|
---|
181 | \brief
|
---|
182 | Set the area that the mouse cursor is constrained to.
|
---|
183 |
|
---|
184 | \param area
|
---|
185 | Pointer to a Rect object that describes the area of the display that the mouse is allowed to occupy. The given area will be clipped to
|
---|
186 | the current Renderer screen area - it is never possible for the mouse to leave this area. If this parameter is NULL, the
|
---|
187 | constraint is set to the size of the current Renderer screen area.
|
---|
188 |
|
---|
189 | \return
|
---|
190 | Nothing.
|
---|
191 | */
|
---|
192 | void setConstraintArea(const Rect* area);
|
---|
193 |
|
---|
194 |
|
---|
195 | /*!
|
---|
196 | \brief
|
---|
197 | Set the area that the mouse cursor is constrained to.
|
---|
198 |
|
---|
199 | \param area
|
---|
200 | Pointer to a URect object that describes the area of the display that the mouse is allowed to occupy. The given area will be clipped to
|
---|
201 | the current Renderer screen area - it is never possible for the mouse to leave this area. If this parameter is NULL, the
|
---|
202 | constraint is set to the size of the current Renderer screen area.
|
---|
203 |
|
---|
204 | \return
|
---|
205 | Nothing.
|
---|
206 | */
|
---|
207 | void setUnifiedConstraintArea(const URect* area);
|
---|
208 |
|
---|
209 |
|
---|
210 | /*!
|
---|
211 | \brief
|
---|
212 | Hides the mouse cursor.
|
---|
213 |
|
---|
214 | \return
|
---|
215 | Nothing.
|
---|
216 | */
|
---|
217 | void hide(void) {d_visible = false;}
|
---|
218 |
|
---|
219 |
|
---|
220 | /*!
|
---|
221 | \brief
|
---|
222 | Shows the mouse cursor.
|
---|
223 |
|
---|
224 | \return
|
---|
225 | Nothing.
|
---|
226 | */
|
---|
227 | void show(void) {d_visible = true;}
|
---|
228 |
|
---|
229 |
|
---|
230 | /*!
|
---|
231 | \brief
|
---|
232 | return whether the mouse cursor is visible.
|
---|
233 |
|
---|
234 | \return
|
---|
235 | true if the mouse cursor is visible, false if the mouse cursor is hidden.
|
---|
236 | */
|
---|
237 | bool isVisible(void) const {return d_visible;}
|
---|
238 |
|
---|
239 |
|
---|
240 | /*!
|
---|
241 | \brief
|
---|
242 | Return the current mouse cursor position as a pixel offset from the top-left corner of the display.
|
---|
243 |
|
---|
244 | \return
|
---|
245 | Point object describing the mouse cursor position in screen pixels.
|
---|
246 | */
|
---|
247 | Point getPosition(void) const {return Point(d_position.d_x, d_position.d_y);}
|
---|
248 |
|
---|
249 |
|
---|
250 | /*!
|
---|
251 | \brief
|
---|
252 | return the current constraint area of the mouse cursor.
|
---|
253 |
|
---|
254 | \return
|
---|
255 | Rect object describing the active area that the mouse cursor is constrained to.
|
---|
256 | */
|
---|
257 | Rect getConstraintArea(void) const;
|
---|
258 |
|
---|
259 |
|
---|
260 | /*!
|
---|
261 | \brief
|
---|
262 | return the current constraint area of the mouse cursor.
|
---|
263 |
|
---|
264 | \return
|
---|
265 | URect object describing the active area that the mouse cursor is constrained to.
|
---|
266 | */
|
---|
267 | const URect& getUnifiedConstraintArea(void) const;
|
---|
268 |
|
---|
269 |
|
---|
270 | /*!
|
---|
271 | \brief
|
---|
272 | Return the current mouse cursor position as display resolution independant values.
|
---|
273 |
|
---|
274 | \return
|
---|
275 | Point object describing the current mouse cursor position as resolution independant values that
|
---|
276 | range from 0.0f to 1.0f, where 0.0f represents the left-most and top-most positions, and 1.0f
|
---|
277 | represents the right-most and bottom-most positions.
|
---|
278 | */
|
---|
279 | Point getDisplayIndependantPosition(void) const;
|
---|
280 |
|
---|
281 |
|
---|
282 | protected:
|
---|
283 | /*************************************************************************
|
---|
284 | New event handlers
|
---|
285 | *************************************************************************/
|
---|
286 | /*!
|
---|
287 | \brief
|
---|
288 | event triggered internally when image of mouse cursor changes
|
---|
289 | */
|
---|
290 | virtual void onImageChanged(MouseCursorEventArgs& e);
|
---|
291 |
|
---|
292 |
|
---|
293 | /*************************************************************************
|
---|
294 | Implementation Functions
|
---|
295 | *************************************************************************/
|
---|
296 | /*!
|
---|
297 | \brief
|
---|
298 | Add mouse cursor specific events
|
---|
299 | */
|
---|
300 | void addMouseCursorEvents(void);
|
---|
301 |
|
---|
302 |
|
---|
303 | private:
|
---|
304 | /*************************************************************************
|
---|
305 | Implementation Methods
|
---|
306 | *************************************************************************/
|
---|
307 | /*!
|
---|
308 | \brief
|
---|
309 | Checks the mouse cursor position is within the current 'constrain' Rect and adjusts as required.
|
---|
310 | */
|
---|
311 | void constrainPosition(void);
|
---|
312 |
|
---|
313 |
|
---|
314 | /*************************************************************************
|
---|
315 | Implementation Data
|
---|
316 | *************************************************************************/
|
---|
317 | const Image* d_cursorImage; //!< Image that is currently set as the mouse cursor.
|
---|
318 | Vector3 d_position; //!< Current location of the cursor
|
---|
319 | bool d_visible; //!< true if the cursor will be drawn, else false.
|
---|
320 | URect d_constraints; //!< Specifies the area (in screen pixels) that the mouse can move around in.
|
---|
321 | };
|
---|
322 |
|
---|
323 | } // End of CEGUI namespace section
|
---|
324 |
|
---|
325 | #if defined(_MSC_VER)
|
---|
326 | # pragma warning(pop)
|
---|
327 | #endif
|
---|
328 |
|
---|
329 | #endif // end of guard _CEGUIMouseCursor_h_
|
---|