pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3703 - in trunk/pingus/src: components gui


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3703 - in trunk/pingus/src: components gui
Date: Mon, 7 Jul 2008 08:35:38 +0200

Author: grumbel
Date: 2008-07-07 08:35:38 +0200 (Mon, 07 Jul 2008)
New Revision: 3703

Modified:
   trunk/pingus/src/components/action_button.cpp
   trunk/pingus/src/components/action_button.hpp
   trunk/pingus/src/gui/rect_component.hpp
Log:
Turned ActionButtons into RectComponets

Modified: trunk/pingus/src/components/action_button.cpp
===================================================================
--- trunk/pingus/src/components/action_button.cpp       2008-07-07 06:34:57 UTC 
(rev 3702)
+++ trunk/pingus/src/components/action_button.cpp       2008-07-07 06:35:38 UTC 
(rev 3703)
@@ -26,36 +26,23 @@
 #include "../string_util.hpp"
 #include "../math/vector3f.hpp"
 
-
 using namespace Actions;
 
 ActionButton::ActionButton(ActionHolder* h,
                            int x, int y, ActionName name_, int owner_id)
-  : action_holder(h),
+  : RectComponent(Rect(Vector2i(x, y), Size(60, 38))),
+    action_holder(h),
     background (Sprite("core/buttons/buttonbackground")),
-    backgroundhl (Sprite("core/buttons/buttonbackgroundhl"))
+    backgroundhl (Sprite("core/buttons/buttonbackgroundhl")),
+    name(name_)
 {
-  init(x, y, name_, owner_id);
+  sprite = Sprite("pingus/player0/" + action_to_string(name) + "/right");
+  sprite.set_play_loop(true);
 }
 
 ActionButton::~ActionButton() {}
 
 void
-ActionButton::init(int x, int y, ActionName name_, int owner_id)
-{
-  //  make_action = func;
-  x_pos = x;
-  y_pos = y;
-  name = name_;
-
-  font   = Fonts::pingus_small;
-  font_b = Fonts::pingus_large;
-
-  sprite = Sprite("pingus/player0/" + action_to_string(name) + "/right");
-  sprite.set_play_loop(true);
-}
-
-void
 ActionButton::update(float delta)
 {
   sprite.update(delta);
@@ -67,109 +54,58 @@
   return name;
 }
 
-bool
-ActionButton::is_at (int x, int y)
-{
-  if (x > x_pos && x < x_pos + 60
-      && y > y_pos && y <= y_pos + 35)
-    {
-      return true;
-    }
-  else
-    {
-      return false;
-    }
-}
-
 void
 ActionButton::draw (DrawingContext& gc)
 {
+  Vector2i pos(rect.left, rect.top);
+
   if (pressed)
     {
-      if (fast_mode) 
-        {
-          gc.draw_fillrect(x_pos, y_pos, x_pos + 60, y_pos + 35,
-                           Color(255, 255, 255));
-        } 
-      else 
-        {
-          //CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
-          //1.0, 1.0, 1.0, 0.5);
-          gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
-        }
+      gc.draw(backgroundhl, pos);
     }
   else
     {
       sprite.set_frame(0);
-
-      if (fast_mode) {
-        // do nothing
-      } else {
-        gc.draw(background, Vector2i(x_pos, y_pos));
-      }
+      gc.draw(background, pos);
     }
-
-  if (this->get_action_name() == Climber) {
-         gc.draw(sprite, Vector2i(x_pos + 32, y_pos + 32));
-  } else {
-         gc.draw(sprite, Vector2i(x_pos + 20, y_pos + 32));
-  }
-
-  Font myfont  = font;
-  Font myfontb = font_b;
-
-  // print the action name next to the button, when mouse pointer is on
-  // the button.
-  // FIXME: this should use the GUI events, not SDL_GetMouseState
-  int x, y;
-  SDL_GetMouseState(&x, &y);
-  if (action_help
-      && x > x_pos      && x < x_pos + 60
-      && y < y_pos + 35 && y > y_pos)
-    {
-      gc.print_left(myfontb, x_pos + 65, y_pos-10, action_to_screenname(name));
-    }
-
-  if (Cheat::unlimited_actions)
-    {
-      // FIXME: insert unlimited surface here
-      gc.print_center(myfont, x_pos + 46, y_pos + 5, "oo");
-    }
-  else
-    {
-      std::string str = 
StringUtil::to_string(action_holder->get_available(name));
-      gc.print_center(myfont, x_pos + 46, y_pos + 5, str);
-    }
+  
+  gc.draw(sprite, Vector2i(pos.x + 20, pos.y + 32));
+  
+  std::string str = StringUtil::to_string(action_holder->get_available(name));
+  gc.print_center(Fonts::pingus_small, pos.x + 46, pos.y + 5, str);
 }
 
 ArmageddonButton::ArmageddonButton(Server* s, int x, int y)
-  : server (s),
-    x_pos (x),
-    y_pos (y),
-    background  (Sprite("core/buttons/hbuttonbgb")),
-    backgroundhl(Sprite("core/buttons/hbuttonbg"))
+  : RectComponent(Rect(Vector2i(x, y), Size(38, 60))),
+    server(s),
+    background  ("core/buttons/hbuttonbgb"),
+    backgroundhl("core/buttons/hbuttonbg")
 {
   pressed      = false;
   sprite       = Sprite("core/buttons/armageddon_anim");
 }
 
-ArmageddonButton::~ArmageddonButton () { }
+ArmageddonButton::~ArmageddonButton () 
+{
+}
 
 void
 ArmageddonButton::draw (DrawingContext& gc)
 {
+  Vector2i pos(rect.left, rect.top);
+
   if (server->get_world()->check_armageddon ())
     {
-      gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
-      gc.draw(sprite, Vector2i(x_pos, y_pos));
+      gc.draw(backgroundhl, pos);
+      gc.draw(sprite, pos);
     }
   else
     {
       if (!fast_mode)
-        gc.draw(background, Vector2i(x_pos, y_pos));
+        gc.draw(background, pos);
 
       sprite.set_frame(7);
-      gc.draw(sprite, Vector2i(x_pos, y_pos));
+      gc.draw(sprite, pos);
     }
 }
 
@@ -194,18 +130,6 @@
     }
 }
 
-bool
-ArmageddonButton::is_at(int x, int y)
-{
-  if (x > x_pos && x < x_pos + sprite.get_width()
-      && y > y_pos && y < y_pos + sprite.get_height())
-    {
-      return true;
-    } else  {
-      return false;
-    }
-}
-
 void
 ArmageddonButton::on_primary_button_click (int x, int y)
 {
@@ -223,8 +147,8 @@
 }
 
 ForwardButton::ForwardButton(GameSession* s, int x, int y)
-  : session(s),
-    x_pos (x), y_pos (y),
+  : RectComponent(Rect(Vector2i(x, y), Size(38, 60))),
+    session(s),
     background  (Sprite("core/buttons/hbuttonbgb")),
     backgroundhl(Sprite("core/buttons/hbuttonbg"))
 {
@@ -236,31 +160,21 @@
 void
 ForwardButton::draw (DrawingContext& gc)
 {
+  Vector2i pos(rect.left, rect.top);
+
   if (session->get_fast_forward())
     {
-      gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
+      gc.draw(backgroundhl, pos);
     }
   else
     {
       if (!fast_mode)
-        gc.draw(background, Vector2i(x_pos, y_pos));
+        gc.draw(background, pos);
     }
 
-  gc.draw(surface, Vector2i(x_pos, y_pos));
+  gc.draw(surface, pos);
 }
 
-bool
-ForwardButton::is_at (int x, int y)
-{
-  if (   x > x_pos && x < x_pos + int(surface.get_width())
-      && y > y_pos && y < y_pos + int(surface.get_height()))
-    {
-      return true;
-    } else  {
-      return false;
-    }
-}
-
 void
 ForwardButton::on_primary_button_click (int x, int y)
 {
@@ -271,44 +185,36 @@
 }
 
 PauseButton::PauseButton(GameSession* s, int x, int y)
-  : session(s),
-    x_pos(x), y_pos(y),
+  : RectComponent(Rect(Vector2i(x, y), Size(38, 60))),
+    session(s),
     background  (Sprite("core/buttons/hbuttonbgb")),
     backgroundhl(Sprite("core/buttons/hbuttonbg"))
 {
   surface = Sprite("core/buttons/pause");
 }
 
-PauseButton::~PauseButton () {}
+PauseButton::~PauseButton () 
+{
+}
 
 void
 PauseButton::draw (DrawingContext& gc)
 {
+  Vector2i pos(rect.left, rect.top);
+
   if (session->get_pause())
     {
-      gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
+      gc.draw(backgroundhl, pos);
     }
   else
     {
     if (!fast_mode)
-      gc.draw(background, Vector2i(x_pos, y_pos));
+      gc.draw(background, pos);
     }
 
-  gc.draw(surface, Vector2i(x_pos, y_pos));
+  gc.draw(surface, pos);
 }
 
-bool
-PauseButton::is_at (int x, int y)
-{
-  if (x > x_pos && x < x_pos + int(surface.get_width())
-      && y > y_pos && y < y_pos + int(surface.get_height()))
-    {
-      return true;
-    } else  {
-      return false;
-    }
-}
-
 void
 PauseButton::on_primary_button_click (int x, int y)
 {

Modified: trunk/pingus/src/components/action_button.hpp
===================================================================
--- trunk/pingus/src/components/action_button.hpp       2008-07-07 06:34:57 UTC 
(rev 3702)
+++ trunk/pingus/src/components/action_button.hpp       2008-07-07 06:35:38 UTC 
(rev 3703)
@@ -22,22 +22,21 @@
 #include "../pingu_enums.hpp"
 #include "../state_sprite.hpp"
 #include "../gui/component.hpp"
+#include "../gui/rect_component.hpp"
 
 class Server;
 class GameSession;
 class ActionHolder;
 class Vector;
-
+
 /** ArmageddonButton, press it to start the armageddon and to turn all
     pingus into bomber
 
     \sa Client */
-class ArmageddonButton : public GUI::Component
+class ArmageddonButton : public GUI::RectComponent
 {
 private:
   Server* server;
-  int    x_pos;
-  int    y_pos;
   bool   pressed;
   float  press_time;
   Sprite sprite;
@@ -50,7 +49,6 @@
 
   void draw(DrawingContext& gc);
   void update(float);
-  bool is_at(int x, int y);
   void on_primary_button_click (int x, int y);
 
 private:
@@ -62,12 +60,10 @@
     again to return to normal speed
 
     \sa Client */
-class ForwardButton : public GUI::Component
+class ForwardButton : public GUI::RectComponent
 {
 private:
   GameSession* session;
-  int x_pos;
-  int y_pos;
   Sprite surface;
   Sprite background;
   Sprite backgroundhl;
@@ -77,7 +73,6 @@
   virtual ~ForwardButton();
 
   void draw(DrawingContext& gc);
-  bool is_at (int x, int y);
   void on_primary_button_click (int x, int y);
 
 private:
@@ -89,12 +84,11 @@
     continue
 
     \sa Client */
-class PauseButton : public GUI::Component
+class PauseButton : public GUI::RectComponent
 {
 private:
   GameSession* session;
-  int x_pos;
-  int y_pos;
+
   Sprite surface;
   Sprite background;
   Sprite backgroundhl;
@@ -104,7 +98,7 @@
   virtual ~PauseButton();
 
   void draw(DrawingContext& gc);
-  bool is_at (int x, int y);
+  
   void on_primary_button_click (int x, int y);
 
 private:
@@ -114,7 +108,7 @@
 
 /** The button class manage a simple button for the button_panel. It
     keeps his position, his surfaces and his font. */
-class ActionButton : public GUI::Component
+class ActionButton : public GUI::RectComponent
 {
 protected:
   ActionHolder* action_holder;
@@ -122,31 +116,20 @@
   Sprite background;
   Sprite backgroundhl;
 
-  int x_pos;
-  int y_pos;
-  Font    font;
-  // Added for printing action names next to the button.
-  Font    font_b;
-
   Actions::ActionName name;
-  bool is_multi_direct;
 
 public:
-  bool pressed;
+  bool pressed; // used in ButtonPanel
 
   ActionButton(ActionHolder* h, int x, int y, Actions::ActionName name_, int 
owner_id);
   virtual ~ActionButton();
 
-  void init(int x, int y, Actions::ActionName name_, int owner_id);
-
   void draw(DrawingContext& gc);
   void update(float delta);
 
   /// Returns the name of the action the button represents.
   Actions::ActionName get_action_name();
 
-  bool is_at(int x, int y);
-
 private:
   ActionButton (const ActionButton&);
   ActionButton& operator= (const ActionButton&);

Modified: trunk/pingus/src/gui/rect_component.hpp
===================================================================
--- trunk/pingus/src/gui/rect_component.hpp     2008-07-07 06:34:57 UTC (rev 
3702)
+++ trunk/pingus/src/gui/rect_component.hpp     2008-07-07 06:35:38 UTC (rev 
3703)
@@ -34,7 +34,7 @@
   {}
   
   virtual bool is_at (int x, int y) { return rect.is_inside(Vector2i(x, y)); }
-  virtual void update_layout() =0;
+  virtual void update_layout() {}
   
   void set_rect(const Rect& rect_) 
   {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]