00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "gui/mousecursor.hpp"
00018
00019 #include <SDL.h>
00020
00021 #include "supertux/globals.hpp"
00022 #include "video/drawing_context.hpp"
00023
00024 MouseCursor* MouseCursor::current_ = 0;
00025
00026 MouseCursor::MouseCursor(std::string cursor_file) :
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 }
00037
00038 MouseCursor::~MouseCursor()
00039 {
00040 }
00041
00042 int MouseCursor::state()
00043 {
00044 return cur_state;
00045 }
00046
00047 void MouseCursor::set_state(int nstate)
00048 {
00049 cur_state = nstate;
00050 }
00051
00052 void MouseCursor::set_mid(int x, int y)
00053 {
00054 mid_x = x;
00055 mid_y = y;
00056 }
00057
00058 void MouseCursor::draw(DrawingContext& context)
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 }
00084
00085