X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=inline;f=src%2Fgui%2Fmousecursor.cpp;h=f56e7ef5981f71fb5ad2e9e2b64503156e613218;hb=d794aac09d4a3b3f5f93985cd74381bb4de4ce84;hp=f9a000d3c645d44d887ef4d6e000629d54bc9975;hpb=08813a74da6ac1fd045a105e4e8105f1d7f716f0;p=supertux.git diff --git a/src/gui/mousecursor.cpp b/src/gui/mousecursor.cpp index f9a000d3c..f56e7ef59 100644 --- a/src/gui/mousecursor.cpp +++ b/src/gui/mousecursor.cpp @@ -18,65 +18,64 @@ #include -#include "supertux/main.hpp" +#include "supertux/globals.hpp" #include "video/drawing_context.hpp" +#include "video/renderer.hpp" +#include "video/video_system.hpp" MouseCursor* MouseCursor::current_ = 0; -extern SDL_Surface* g_screen; -MouseCursor::MouseCursor(std::string cursor_file) : mid_x(0), mid_y(0) +MouseCursor::MouseCursor(const std::string& cursor_file, + const std::string& cursor_click_file, + const std::string& cursor_link_file) : + m_mid_x(0), + m_mid_y(0), + m_state(MC_NORMAL), + m_cursor() { - cursor = new Surface(cursor_file); - - cur_state = MC_NORMAL; + m_cursor.push_back(Surface::create(cursor_file)); + m_cursor.push_back(Surface::create(cursor_click_file)); + m_cursor.push_back(Surface::create(cursor_link_file)); } MouseCursor::~MouseCursor() { - delete cursor; -} - -int MouseCursor::state() -{ - return cur_state; } -void MouseCursor::set_state(int nstate) +void MouseCursor::set_state(MouseCursorState nstate) { - cur_state = nstate; + m_state = nstate; } void MouseCursor::set_mid(int x, int y) { - mid_x = x; - mid_y = y; + m_mid_x = x; + m_mid_y = y; } void MouseCursor::draw(DrawingContext& context) { - if(cur_state == MC_HIDE) - return; + if (m_state != MC_HIDE) + { + int x; + int y; + Uint8 ispressed = SDL_GetMouseState(&x, &y); - int x,y,w,h; - Uint8 ispressed = SDL_GetMouseState(&x,&y); + Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(x, y); - x = int(x * float(SCREEN_WIDTH)/g_screen->w); - y = int(y * float(SCREEN_HEIGHT)/g_screen->h); + x = int(mouse_pos.x); + y = int(mouse_pos.y); - w = (int) cursor->get_width(); - h = (int) (cursor->get_height() / MC_STATES_NB); - if(ispressed &SDL_BUTTON(1) || ispressed &SDL_BUTTON(2)) { - if(cur_state != MC_CLICK) { - state_before_click = cur_state; - cur_state = MC_CLICK; + int tmp_state = m_state; + if (ispressed & SDL_BUTTON(1) || ispressed & SDL_BUTTON(2)) + { + tmp_state = MC_CLICK; } - } else { - if(cur_state == MC_CLICK) - cur_state = state_before_click; - } - context.draw_surface_part(cursor, Vector(0, h*cur_state), - Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100); + context.draw_surface(m_cursor[static_cast(tmp_state)], + Vector(x - m_mid_x, y - m_mid_y), + LAYER_GUI + 100); + } } /* EOF */