3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "app/globals.h"
23 #include "video/drawing_context.h"
24 #include "gui/mousecursor.h"
26 using namespace SuperTux;
28 MouseCursor* MouseCursor::current_ = 0;
29 extern SDL_Surface* screen;
31 MouseCursor::MouseCursor(std::string cursor_file, int frames) : mid_x(0), mid_y(0)
33 cursor = new Surface(cursor_file, true);
35 cur_state = MC_NORMAL;
40 timer.start(MC_FRAME_PERIOD);
42 SDL_ShowCursor(SDL_DISABLE);
45 MouseCursor::~MouseCursor()
49 SDL_ShowCursor(SDL_ENABLE);
52 int MouseCursor::state()
57 void MouseCursor::set_state(int nstate)
62 void MouseCursor::set_mid(int x, int y)
68 void MouseCursor::draw(DrawingContext& context)
70 if(cur_state == MC_HIDE)
74 Uint8 ispressed = SDL_GetMouseState(&x,&y);
76 x = int(x * float(SCREEN_WIDTH)/screen->w);
77 y = int(y * float(SCREEN_HEIGHT)/screen->h);
79 w = cursor->w / tot_frames;
80 h = cursor->h / MC_STATES_NB;
81 if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2))
83 if(cur_state != MC_CLICK)
85 state_before_click = cur_state;
91 if(cur_state == MC_CLICK)
92 cur_state = state_before_click;
95 if(timer.get_left() < 0 && tot_frames > 1)
98 if(cur_frame++ >= tot_frames)
101 timer.start(MC_FRAME_PERIOD);
104 context.draw_surface_part(cursor, Vector(w*cur_frame, h*cur_state), Vector(w,
105 h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);