2 /***************************************************************************
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 ***************************************************************************/
11 // by Ricardo Cruz <rick2@aeiou.pt>
14 #include "mousecursor.h"
16 MouseCursor::MouseCursor(std::string cursor_file, int frames)
18 cursor = new Surface(cursor_file, USE_ALPHA);
20 cur_state = MC_NORMAL;
25 timer.start(MC_FRAME_PERIOD);
27 SDL_ShowCursor(SDL_DISABLE);
30 MouseCursor::~MouseCursor()
34 SDL_ShowCursor(SDL_ENABLE);
37 int MouseCursor::state()
42 void MouseCursor::set_state(int nstate)
47 void MouseCursor::draw()
50 Uint8 ispressed = SDL_GetMouseState(&x,&y);
51 w = cursor->w / tot_frames;
52 h = cursor->h / MC_STATES_NB;
53 if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2))
55 if(cur_state != MC_CLICK)
57 state_before_click = cur_state;
63 if(cur_state == MC_CLICK)
64 cur_state = state_before_click;
67 if(timer.get_left() < 0 && tot_frames > 1)
70 if(cur_frame++ >= tot_frames)
73 timer.start(MC_FRAME_PERIOD);
76 cursor->draw_part(w*cur_frame, h*cur_state , x, y, w, h);