little change to improve win32 portability
[supertux.git] / src / mousecursor.cpp
1
2 /***************************************************************************
3  *                                                                         *
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.                                   *
8  *                                                                         *
9  ***************************************************************************/
10
11 // by Ricardo Cruz <rick2@aeiou.pt>
12
13 #include "screen.h"
14 #include "mousecursor.h"
15
16 MouseCursor::MouseCursor(std::string cursor_file, int frames)
17 {
18 texture_load(&cursor,cursor_file.c_str(),USE_ALPHA);
19
20 cur_state = MC_NORMAL;
21 cur_frame = 0;
22 tot_frames = frames;
23
24 timer_init(&timer, false);
25 timer_start(&timer,MC_FRAME_PERIOD);
26
27 SDL_ShowCursor(SDL_DISABLE);
28 }
29
30 MouseCursor::~MouseCursor()
31 {
32   texture_free(&cursor);
33
34   SDL_ShowCursor(SDL_ENABLE);
35 }
36
37 int MouseCursor::state()
38 {
39 return cur_state;
40 }
41
42 void MouseCursor::set_state(int nstate)
43 {
44 cur_state = nstate;
45 }
46
47 void MouseCursor::draw(int x, int y)
48 {
49 int w,h;
50 w = cursor.w / tot_frames;
51 h = cursor.h / MC_STATES_NB;
52
53 if(timer_get_left(&timer) < 0 && tot_frames > 1)
54   {
55   cur_frame++;
56   if(cur_frame++ >= tot_frames)
57     cur_frame = 0;
58
59   timer_start(&timer,MC_FRAME_PERIOD);
60   }
61
62 texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h);
63 }