-// $Id$
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
-// SuperTux - A Jump'n Run
-// Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
-//
-// 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
// 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 <config.h>
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "video/drawing_context.h"
-#include "gui/mousecursor.h"
-#include "main.h"
+#include "gui/mousecursor.hpp"
-MouseCursor* MouseCursor::current_ = 0;
-extern SDL_Surface* screen;
+#include <SDL.h>
-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(w, h*cur_state),
- Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);
+ context.draw_surface(m_cursor[static_cast<int>(tmp_state)],
+ Vector(x - m_mid_x, y - m_mid_y),
+ LAYER_GUI + 100);
+ }
}
+
+/* EOF */