- Added images for ducking big Super Tux.
[supertux.git] / src / button.h
index 5af5d35..a42254e 100644 (file)
@@ -1,63 +1,98 @@
+//  $Id$
 //
-// C Interface: button
+//  SuperTux
+//  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
 //
-// Description:
-//
-//
-// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
-//
-// Copyright: See COPYING file that comes with this distribution
+//  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 distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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.
 
 #ifndef SUPERTUX_BUTTON_H
 #define SUPERTUX_BUTTON_H
 
-#include "texture.h"
+#include <vector>
+
+#include "screen/surface.h"
+#include "timer.h"
 
 enum ButtonState {
   BUTTON_NONE = -1,
   BUTTON_CLICKED,
   BUTTON_PRESSED,
-  BUTTON_HOVER
+  BUTTON_HOVER,
+  BUTTON_WHEELUP,
+  BUTTON_WHEELDOWN,
+  BUTTON_DEACTIVE
 };
 
-struct button_type
+class ButtonPanel;
+
+class Button
 {
-  texture_type icon;
-  texture_type* bkgd;
-  char *info;
+  friend class ButtonPanel;
+
+public:
+  Button(Surface* icon_file, const std::string& info, SDLKey shortcut,
+      int x, int y, int mw = -1, int h = -1);
+  Button(const std::string& icon_name, const std::string& info, SDLKey shortcut,
+      int x, int y, int mw = -1, int h = -1);
+  
+  ~Button();
+  void event(SDL_Event& event);
+  void draw(DrawingContext& context);
+  int get_state();
+  void set_active(bool active) { active ? state = BUTTON_NONE : state = BUTTON_DEACTIVE; };
+  void add_icon(const std::string& imagefile, int mw, int mh);
+  SDL_Rect get_pos() { return rect; }
+  int get_tag(){return tag; }
+//  void set_drawable(Drawable* newdrawable)
+//  { drawable = newdrawable; }
+
+private:
+  static Timer popup_timer;
+//  Drawable* drawable;
+  std::vector<Surface*> icon;
+  std::string info;
   SDLKey shortcut;
-  int  x;
-  int  y;
-  int  w;
-  int  h;
+  SDL_Rect rect;
   bool show_info;
   ButtonState state;
   int tag;
 };
 
-void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortcut, int x, int y);
-button_type* button_create(char* icon_file, char* info, SDLKey shortcut, int x, int y);
-void button_change_icon(button_type* pbutton,char* icon_file);
-void button_draw(button_type* pbutton);
-void button_free(button_type* pbutton);
-void button_event(button_type* pbutton, SDL_Event* event);
-int  button_get_state(button_type* pbutton);
-
-struct button_panel_type
+class ButtonPanel
 {
-  int num_items;
-  int hidden;
-  int x,y;
-  int w,h;
-  button_type* item;
-};
+public:
+  ButtonPanel(int x, int y, int w, int h);
+  ~ButtonPanel();
+  void draw(DrawingContext& context);
+  Button* event(SDL_Event &event);
+  void additem(Button* pbutton, int tag);
+  Button* button_panel_event(SDL_Event& event);
+  void set_button_size(int w, int h);
+  Button* manipulate_button(int i);
+  void highlight_last(bool b);
+  void set_last_clicked(unsigned int last)
+  { if(hlast) { if(item.size() >= last) { last_clicked = item.begin() + last; } } };
 
-void button_panel_init(button_panel_type* pbutton_panel, int x, int y, int w, int h);
-void button_panel_free(button_panel_type* pbutton_panel);
-void button_panel_draw(button_panel_type* pbutton_panel);
-void button_panel_additem(button_panel_type* pbutton_panel, button_type* pbutton, int tag);
-button_type* button_panel_event(button_panel_type* pbutton_panel, SDL_Event* event);
+private:
+  int bw, bh;
+  bool hlast;
+  bool hidden;
+  SDL_Rect rect;
+  std::vector<Button*> item;
+  std::vector<Button*>::iterator last_clicked;
+};
 
 #endif /*SUPERTUX_BUTTON_H*/