From 81f44c7d476db3845299a1df5b0a4d3a599dffee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Fri, 26 Mar 2004 23:54:47 +0000 Subject: [PATCH] C++ port of Ricarod Cruz's menu-handling code patch. SVN-Revision: 384 --- src/mousecursor.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mousecursor.h | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/mousecursor.cpp create mode 100644 src/mousecursor.h diff --git a/src/mousecursor.cpp b/src/mousecursor.cpp new file mode 100644 index 000000000..0eab12914 --- /dev/null +++ b/src/mousecursor.cpp @@ -0,0 +1,63 @@ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// by Ricardo Cruz + +#include "screen.h" +#include "mousecursor.h" + +MouseCursor::MouseCursor(std::string cursor_file, int frames) +{ +texture_load(&cursor,cursor_file.c_str(),USE_ALPHA); + +cur_state = MC_NORMAL; +cur_frame = 0; +tot_frames = frames; + +timer_init(&timer, false); +timer_start(&timer,MC_FRAME_PERIOD); + +SDL_ShowCursor(SDL_DISABLE); +} + +MouseCursor::~MouseCursor() +{ + texture_free(&cursor); + + SDL_ShowCursor(SDL_ENABLE); +} + +int MouseCursor::state() +{ +return cur_state; +} + +void MouseCursor::set_state(int nstate) +{ +cur_state = nstate; +} + +void MouseCursor::draw(int x, int y) +{ +int w,h; +w = cursor.w / tot_frames; +h = cursor.h / MC_STATES_NB; + +if(timer_get_left(&timer) < 0 && tot_frames > 1) + { + cur_frame++; + if(cur_frame++ >= tot_frames) + cur_frame = 0; + + timer_start(&timer,MC_FRAME_PERIOD); + } + +texture_draw_part(&cursor, w*cur_frame, h*cur_state , x, y, w, h); +} diff --git a/src/mousecursor.h b/src/mousecursor.h new file mode 100644 index 000000000..27787562c --- /dev/null +++ b/src/mousecursor.h @@ -0,0 +1,45 @@ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// by Ricardo Cruz + +#ifndef SUPERTUX_MOUSECURSOR_H +#define SUPERTUX_MOUSECURSOR_H + +#include +#include "timer.h" +#include "texture.h" + +#define MC_FRAME_PERIOD 800 // in ms + +#define MC_STATES_NB 3 +enum { + MC_NORMAL, + MC_CLICK, + MC_LINK +}; + +class MouseCursor + { + public: + MouseCursor(std::string cursor_file, int frames); + ~MouseCursor(); + int state(); + void set_state(int nstate); + void draw(int x, int y); + + private: + int cur_state; + int cur_frame, tot_frames; + texture_type cursor; + timer_type timer; + }; + +#endif /*SUPERTUX_MOUSECURSOR_H*/ -- 2.11.0