C++ port of Ricarod Cruz's menu-handling code patch.
authorTobias Gläßer <tobi.web@gmx.de>
Fri, 26 Mar 2004 23:54:47 +0000 (23:54 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Fri, 26 Mar 2004 23:54:47 +0000 (23:54 +0000)
SVN-Revision: 384

src/mousecursor.cpp [new file with mode: 0644]
src/mousecursor.h [new file with mode: 0644]

diff --git a/src/mousecursor.cpp b/src/mousecursor.cpp
new file mode 100644 (file)
index 0000000..0eab129
--- /dev/null
@@ -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 <rick2@aeiou.pt>
+
+#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 (file)
index 0000000..2778756
--- /dev/null
@@ -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 <rick2@aeiou.pt>
+
+#ifndef SUPERTUX_MOUSECURSOR_H
+#define SUPERTUX_MOUSECURSOR_H
+
+#include <string>
+#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*/