MouseCursor Class Reference

Used to create mouse cursors. More...

#include <mousecursor.hpp>

List of all members.

Public Member Functions

 MouseCursor (std::string cursor_file)
 Expects an imagefile for the cursor and the number of animation frames it contains.
 ~MouseCursor ()
int state ()
 (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE)
void set_state (int nstate)
 (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE)
void set_mid (int x, int y)
 Useful for cross mouse cursor images in example.
void draw (DrawingContext &context)
 Draw MouseCursor on screen.

Static Public Member Functions

static MouseCursorcurrent ()
 Return the current cursor.
static void set_current (MouseCursor *pcursor)
 Set current cursor.

Private Member Functions

 MouseCursor (const MouseCursor &)
MouseCursoroperator= (const MouseCursor &)

Private Attributes

int mid_x
int mid_y
int state_before_click
int cur_state
SurfacePtr cursor

Static Private Attributes

static MouseCursorcurrent_


Detailed Description

Used to create mouse cursors.

The mouse cursors can be animated and can be used in four different states. (MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE)

Definition at line 40 of file mousecursor.hpp.


Constructor & Destructor Documentation

MouseCursor::MouseCursor ( std::string  cursor_file  ) 

Expects an imagefile for the cursor and the number of animation frames it contains.

Definition at line 26 of file mousecursor.cpp.

References Surface::create(), cur_state, cursor, and MC_NORMAL.

00026                                               : 
00027   mid_x(0), 
00028   mid_y(0),
00029   state_before_click(),
00030   cur_state(),
00031   cursor()
00032 {
00033   cursor = Surface::create(cursor_file);
00034 
00035   cur_state = MC_NORMAL;
00036 }

MouseCursor::~MouseCursor (  ) 

Definition at line 38 of file mousecursor.cpp.

00039 {
00040 }

MouseCursor::MouseCursor ( const MouseCursor  )  [private]


Member Function Documentation

int MouseCursor::state (  ) 

(MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE)

Definition at line 42 of file mousecursor.cpp.

References cur_state.

00043 {
00044   return cur_state;
00045 }

void MouseCursor::set_state ( int  nstate  ) 

(MC_NORMAL, MC_CLICK, MC_LINK or MC_HIDE)

Definition at line 47 of file mousecursor.cpp.

References cur_state.

Referenced by Menu::event().

00048 {
00049   cur_state = nstate;
00050 }

void MouseCursor::set_mid ( int  x,
int  y 
)

Useful for cross mouse cursor images in example.

Definition at line 52 of file mousecursor.cpp.

References mid_x, and mid_y.

00053 {
00054   mid_x = x;
00055   mid_y = y;
00056 }

void MouseCursor::draw ( DrawingContext context  ) 

Draw MouseCursor on screen.

Definition at line 58 of file mousecursor.cpp.

References cur_state, cursor, DrawingContext::draw_surface_part(), g_screen, LAYER_GUI, MC_CLICK, MC_HIDE, MC_STATES_NB, mid_x, mid_y, SCREEN_HEIGHT, SCREEN_WIDTH, and state_before_click.

Referenced by Menu::draw().

00059 {
00060   if(cur_state == MC_HIDE)
00061     return;
00062 
00063   int x,y,w,h;
00064   Uint8 ispressed = SDL_GetMouseState(&x,&y);
00065 
00066   x = int(x * float(SCREEN_WIDTH)/g_screen->w);
00067   y = int(y * float(SCREEN_HEIGHT)/g_screen->h);
00068 
00069   w = (int) cursor->get_width();
00070   h = (int) (cursor->get_height() / MC_STATES_NB);
00071   if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2)) {
00072     if(cur_state != MC_CLICK) {
00073       state_before_click = cur_state;
00074       cur_state = MC_CLICK;
00075     }
00076   } else {
00077     if(cur_state == MC_CLICK)
00078       cur_state = state_before_click;
00079   }
00080 
00081   context.draw_surface_part(cursor, Vector(0, h*cur_state),
00082                             Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);
00083 }

static MouseCursor* MouseCursor::current (  )  [inline, static]

Return the current cursor.

Definition at line 61 of file mousecursor.hpp.

References current_.

Referenced by Menu::draw(), and Menu::event().

00062   {        return current_;      };

static void MouseCursor::set_current ( MouseCursor pcursor  )  [inline, static]

Set current cursor.

Definition at line 64 of file mousecursor.hpp.

Referenced by Resources::load_shared().

00065   {        current_ = pcursor;      };

MouseCursor& MouseCursor::operator= ( const MouseCursor  )  [private]


Member Data Documentation

int MouseCursor::mid_x [private]

Definition at line 65 of file mousecursor.hpp.

Referenced by draw(), and set_mid().

int MouseCursor::mid_y [private]

Definition at line 69 of file mousecursor.hpp.

Referenced by draw(), and set_mid().

int MouseCursor::state_before_click [private]

Definition at line 70 of file mousecursor.hpp.

Referenced by draw().

int MouseCursor::cur_state [private]

Definition at line 71 of file mousecursor.hpp.

Referenced by draw(), MouseCursor(), set_state(), and state().

SurfacePtr MouseCursor::cursor [private]

Definition at line 72 of file mousecursor.hpp.

Referenced by draw(), and MouseCursor().

MouseCursor * MouseCursor::current_ [static, private]

Definition at line 75 of file mousecursor.hpp.

Referenced by current().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:32 2014 for SuperTux by  doxygen 1.5.1