SDL++
C++wrapperfortheSDLlibrary.

devices/Cursor.h

Go to the documentation of this file.
00001 
00021 #ifndef SDL_DEVICES_CURSOR_H
00022 #define SDL_DEVICES_CURSOR_H
00023 
00024 #include <stdexcept>
00025 
00026 #include <SDL.h>
00027 
00028 #include "sdlpp/misc/Rect.h"
00029 #include "sdlpp/misc/Coordinate.h"
00030 
00031 namespace sdl {
00032 namespace devices {
00033     using namespace std;
00034     using namespace misc;
00035 
00040     class Cursor {
00041         public:
00047             Cursor () : cursor_ (SDL_GetCursor ()) {
00048                 if (cursor_ == NULL)
00049                     throw runtime_error ("Unable to get system cursor.");
00050             };
00051 
00062             Cursor (unsigned char* data, unsigned char* mask, const Rect& rect, const Coordinate<int>& pos)
00063                 : cursor_ (SDL_CreateCursor (data, mask, 
00064                                              rect.width (), rect.height (),
00065                                              pos.x (), pos.y ())) {
00066                 if (cursor_ == NULL)
00067                     throw runtime_error ("Failed to create the Cursor.");
00068             };
00069 
00073             ~Cursor () { SDL_FreeCursor (cursor_); };
00074 
00082             void move (const Coordinate<short>& pos) { SDL_WarpMouse (pos.x (), pos.y ()); };
00083 
00089             bool show () { return SDL_ShowCursor (SDL_ENABLE) == SDL_ENABLE; };
00090 
00096             bool hide () { return SDL_ShowCursor (SDL_DISABLE) == SDL_DISABLE; };
00097 
00103             bool isVisible () { return SDL_ShowCursor (SDL_QUERY) == SDL_ENABLE; };
00104 
00110             bool toggle () {
00111                 return isVisible () ? SDL_ShowCursor (SDL_DISABLE) == SDL_DISABLE : SDL_ShowCursor (SDL_ENABLE) == SDL_ENABLE;
00112             };
00113 
00117             void activate () { SDL_SetCursor (cursor_); };
00118 
00122             void redraw () { SDL_SetCursor (NULL); }; 
00123 
00124         private:
00130             Cursor (const Cursor& rhs);
00131 
00139             Cursor& operator= (const Cursor& rhs);
00140 
00141             /*
00142              * The system pointer.
00143              */
00144             SDL_Cursor* cursor_;
00145     }; //Cursor
00146 }; //devices
00147 }; //sdl
00148 
00149 #endif //SDL_DEVICES_CURSOR_H
00150 
 All Classes Namespaces Files Functions Variables Typedefs