X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fgui%2Fmousecursor.cpp;h=f56e7ef5981f71fb5ad2e9e2b64503156e613218;hb=2740fa90c947ec4d1ff9c7d3eeb12cf31ce4d26e;hp=d2a082e2013c658af57c41062d747636f1f322af;hpb=5b7f9214cb929399f1a855ef5807018a9447d510;p=supertux.git diff --git a/src/gui/mousecursor.cpp b/src/gui/mousecursor.cpp index d2a082e20..f56e7ef59 100644 --- a/src/gui/mousecursor.cpp +++ b/src/gui/mousecursor.cpp @@ -1,12 +1,10 @@ -// $Id$ +// SuperTux +// Copyright (C) 2006 Matthias Braun // -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Ricardo Cruz -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,72 +12,70 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include +// along with this program. If not, see . -#include "video/drawing_context.hpp" #include "gui/mousecursor.hpp" -#include "main.hpp" -MouseCursor* MouseCursor::current_ = 0; -extern SDL_Surface* screen; +#include -MouseCursor::MouseCursor(std::string cursor_file) : mid_x(0), mid_y(0) -{ - cursor = new Surface(cursor_file, true); - - cur_state = MC_NORMAL; +#include "supertux/globals.hpp" +#include "video/drawing_context.hpp" +#include "video/renderer.hpp" +#include "video/video_system.hpp" - SDL_ShowCursor(SDL_DISABLE); -} +MouseCursor* MouseCursor::current_ = 0; -MouseCursor::~MouseCursor() +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() { - delete cursor; - - SDL_ShowCursor(SDL_ENABLE); + 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)); } -int MouseCursor::state() +MouseCursor::~MouseCursor() { - 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)/screen->w); - y = int(y * float(SCREEN_HEIGHT)/screen->h); + x = int(mouse_pos.x); + y = int(mouse_pos.y); - w = cursor->w; - h = cursor->h / 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 */