From: Tobias Gläßer Date: Fri, 26 Mar 2004 23:54:47 +0000 (+0000) Subject: C++ port of Ricarod Cruz's menu-handling code patch. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=81f44c7d476db3845299a1df5b0a4d3a599dffee;p=supertux.git C++ port of Ricarod Cruz's menu-handling code patch. SVN-Revision: 384 --- 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*/