2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "gui/mousecursor.hpp"
21 #include "supertux/main.hpp"
22 #include "video/drawing_context.hpp"
24 MouseCursor* MouseCursor::current_ = 0;
25 extern SDL_Surface* g_screen;
27 MouseCursor::MouseCursor(std::string cursor_file) :
34 cursor = new Surface(cursor_file);
36 cur_state = MC_NORMAL;
39 MouseCursor::~MouseCursor()
44 int MouseCursor::state()
49 void MouseCursor::set_state(int nstate)
54 void MouseCursor::set_mid(int x, int y)
60 void MouseCursor::draw(DrawingContext& context)
62 if(cur_state == MC_HIDE)
66 Uint8 ispressed = SDL_GetMouseState(&x,&y);
68 x = int(x * float(SCREEN_WIDTH)/g_screen->w);
69 y = int(y * float(SCREEN_HEIGHT)/g_screen->h);
71 w = (int) cursor->get_width();
72 h = (int) (cursor->get_height() / MC_STATES_NB);
73 if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2)) {
74 if(cur_state != MC_CLICK) {
75 state_before_click = cur_state;
79 if(cur_state == MC_CLICK)
80 cur_state = state_before_click;
83 context.draw_surface_part(cursor, Vector(0, h*cur_state),
84 Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);