pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3501 - in trunk/pingus/src: . components


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3501 - in trunk/pingus/src: . components
Date: Thu, 8 Nov 2007 15:24:30 +0100

Author: grumbel
Date: 2007-11-08 15:24:30 +0100 (Thu, 08 Nov 2007)
New Revision: 3501

Modified:
   trunk/pingus/src/components/check_box.cpp
   trunk/pingus/src/components/choice_box.cpp
   trunk/pingus/src/components/choice_box.hpp
   trunk/pingus/src/components/label.cpp
   trunk/pingus/src/components/slider_box.cpp
   trunk/pingus/src/components/slider_box.hpp
   trunk/pingus/src/option_menu.cpp
   trunk/pingus/src/option_menu.hpp
Log:
- some more work on the option menu

Modified: trunk/pingus/src/components/check_box.cpp
===================================================================
--- trunk/pingus/src/components/check_box.cpp   2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/check_box.cpp   2007-11-08 14:24:30 UTC (rev 
3501)
@@ -17,6 +17,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "globals.hpp"
 #include "fonts.hpp"
 #include "display/drawing_context.hpp"
 #include "check_box.hpp"
@@ -36,7 +37,8 @@
 void
 CheckBox::draw(DrawingContext& gc)
 {
-  //gc.draw_rect(rect, Color(255, 255, 255));
+  if (maintainer_mode)
+    gc.draw_rect(rect, Color(0, 255, 255));
 
   if (state)
     gc.print_center(Fonts::chalk_normal, rect.left+rect.get_width()/2, 
rect.top, "X");

Modified: trunk/pingus/src/components/choice_box.cpp
===================================================================
--- trunk/pingus/src/components/choice_box.cpp  2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/choice_box.cpp  2007-11-08 14:24:30 UTC (rev 
3501)
@@ -17,6 +17,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "globals.hpp"
 #include "fonts.hpp"
 #include "display/drawing_context.hpp"
 #include "choice_box.hpp"
@@ -33,27 +34,37 @@
 void
 ChoiceBox::draw(DrawingContext& gc)
 {
+  if (maintainer_mode)
+    gc.draw_rect(rect, Color(0, 255, 255));  
+
   if (current_choice >= 0 && current_choice < int(choices.size()))
     {
-      gc.print_center(Fonts::chalk_normal, rect.left+rect.get_width()/2, 
rect.top, 
-                      "< " + choices[current_choice] + " >");
+      gc.print_left(Fonts::chalk_normal,  rect.left,  rect.top, "<");
+      gc.print_right(Fonts::chalk_normal, rect.right, rect.top, ">");
+
+
+      gc.print_center(Fonts::chalk_normal, rect.left + rect.get_width()/2, 
rect.top, 
+                      choices[current_choice]);
     }
 }
 
 void
 ChoiceBox::on_primary_button_press(int x, int y)
 {
-  current_choice += 1;
-  if (current_choice >= int(choices.size()))
-    current_choice = choices.size() - 1;
+  x -= rect.left;
+  
+  if (x > rect.get_width()/2)
+    {   
+      current_choice += 1;
+      if (current_choice >= int(choices.size()))
+        current_choice = choices.size() - 1;
+    }
+  else
+    {
+      current_choice -= 1;
+      if (current_choice < 0)
+        current_choice = 0;
+    }
 }
 
-void
-ChoiceBox::on_secondary_button_press(int x, int y)
-{
-  current_choice -= 1;
-  if (current_choice < 0)
-    current_choice = 0;
-}
-
 /* EOF */

Modified: trunk/pingus/src/components/choice_box.hpp
===================================================================
--- trunk/pingus/src/components/choice_box.hpp  2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/choice_box.hpp  2007-11-08 14:24:30 UTC (rev 
3501)
@@ -36,7 +36,6 @@
 
   void draw(DrawingContext& gc);
   void on_primary_button_press(int x, int y);
-  void on_secondary_button_press(int x, int y);
   void update_layout() {}
 
 private:

Modified: trunk/pingus/src/components/label.cpp
===================================================================
--- trunk/pingus/src/components/label.cpp       2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/label.cpp       2007-11-08 14:24:30 UTC (rev 
3501)
@@ -17,6 +17,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "globals.hpp"
 #include "fonts.hpp"
 #include "display/drawing_context.hpp"
 #include "label.hpp"
@@ -30,7 +31,9 @@
 void
 Label::draw(DrawingContext& gc)
 {
-  //gc.draw_rect(rect, Color(255, 255, 255));
+  if (maintainer_mode)
+    gc.draw_rect(rect, Color(0, 255, 255));
+
   gc.print_left(Fonts::chalk_normal, rect.left, rect.top, label);
 }
 

Modified: trunk/pingus/src/components/slider_box.cpp
===================================================================
--- trunk/pingus/src/components/slider_box.cpp  2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/slider_box.cpp  2007-11-08 14:24:30 UTC (rev 
3501)
@@ -17,35 +17,72 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "globals.hpp"
 #include "fonts.hpp"
 #include "display/drawing_context.hpp"
 #include "slider_box.hpp"
 
 SliderBox::SliderBox(const Rect& rect)
   : RectComponent(rect),
-    value(10)
+    value(10),
+    drag_drop(false)
 {
 }
 
 void
 SliderBox::draw(DrawingContext& gc)
 {
-  gc.print_right(Fonts::chalk_normal, rect.left+rect.get_width()/2, rect.top, 
-                 std::string(value, '|'));
+  if (maintainer_mode)
+    gc.draw_rect(rect, Color(0, 255, 255));
+
+  if (value == 0)
+    {
+      gc.print_center(Fonts::chalk_normal, rect.left + rect.get_width()/2, 
rect.top, "off");
+    }
+  else
+    {
+      for(int i = 0; i < 20; ++i)
+        {
+          if (i < value)
+            gc.print_left(Fonts::chalk_normal, rect.left + 
i*(rect.get_width()-12)/20 + 6, rect.top, "l");
+          //gc.print_left(Fonts::chalk_normal, rect.left + 
i*(rect.get_width()-12)/20 + 6, rect.top, "l");
+        }
+    }
+  
+  gc.print_left(Fonts::chalk_normal, rect.left, rect.top, 
+                "[");
+  gc.print_right(Fonts::chalk_normal, rect.right, rect.top, 
+                 "]");
 }
 
 void
 SliderBox::on_primary_button_press(int x, int y)
 {
-  value += 1;
+  drag_drop = true;
+  on_pointer_move(x, y);
 }
 
 void
-SliderBox::on_secondary_button_press(int x, int y)
+SliderBox::on_primary_button_release(int x, int y)
 {
-  value -= 1;
-  if (value < 0)
-    value = 0;
+  drag_drop = false;
+  on_pointer_move(x, y);
 }
 
+void
+SliderBox::on_pointer_move(int x, int y)
+{
+  if (drag_drop)
+    {
+      x -= rect.left;
+  
+      value = 20 * x / rect.get_width();
+  
+      if (value > 20)
+        value = 20;
+      else if (value < 0)
+        value = 0; 
+    }
+}
+
 /* EOF */

Modified: trunk/pingus/src/components/slider_box.hpp
===================================================================
--- trunk/pingus/src/components/slider_box.hpp  2007-11-07 10:40:05 UTC (rev 
3500)
+++ trunk/pingus/src/components/slider_box.hpp  2007-11-08 14:24:30 UTC (rev 
3501)
@@ -28,13 +28,15 @@
 {
 private:
   int value;
+  bool drag_drop;
 
 public:
   SliderBox(const Rect& rect);
 
   void draw(DrawingContext& gc);
   void on_primary_button_press(int x, int y);
-  void on_secondary_button_press(int x, int y);
+  void on_primary_button_release(int x, int y);
+  void on_pointer_move(int x, int y);
   void update_layout() {}
 
 private:

Modified: trunk/pingus/src/option_menu.cpp
===================================================================
--- trunk/pingus/src/option_menu.cpp    2007-11-07 10:40:05 UTC (rev 3500)
+++ trunk/pingus/src/option_menu.cpp    2007-11-08 14:24:30 UTC (rev 3501)
@@ -37,44 +37,47 @@
   x_pos = 0;
   y_pos = 0;
 
-  add_item("Resolution:");
-  add_item("Fullscreen:");
-  add_item("Allow Resize:");
-  add_item("Fast Mode:");
-  add_item("Frame Skip:");
-  add_item("Software Cursor:");
+  add_item("Resolution:",      new ChoiceBox(Rect()));
+  add_item("Fullscreen:",      new CheckBox(Rect()));
+  add_item("Allow Resize:",    new CheckBox(Rect()));
+  add_item("Fast Mode:",       new CheckBox(Rect()));
+  add_item("Frame Skip:",      new CheckBox(Rect()));
+  add_item("Software Cursor:", new CheckBox(Rect()));
 
-  add_item("Language:");
-  add_item("Master Volume:");
-  add_item("Sound Volume:");
-  add_item("Music Volume:");
-  add_item("Scroll Mode:");
-  add_item("Mouse Grab:");
+  add_item("Language:",        new ChoiceBox(Rect()));
+  add_item("Master Volume:",   new SliderBox(Rect()));
+  add_item("Sound Volume:",    new SliderBox(Rect()));
+  add_item("Music Volume:",    new SliderBox(Rect()));
+  add_item("Scroll Mode:",     new ChoiceBox(Rect()));
+  add_item("Mouse Grab:",      new CheckBox(Rect()));
 }
 
 void
-OptionMenu::add_item(const std::string& label)
+OptionMenu::add_item(const std::string& label, GUI::RectComponent* control)
 {
-  gui_manager->add(new Label(label, Rect(Vector2i(120 + x_pos * 312,
-                                                  177 + y_pos*32), Size(160, 
32))), true);
+  gui_manager->add(new Label(label, Rect(Vector2i(120 + x_pos * 312, 177 + 
y_pos*32), 
+                                         Size(140, 32))),
+                             true);
+  gui_manager->add(control, true);
 
-  if (0)
+  if (dynamic_cast<ChoiceBox*>(control))
     {
-      gui_manager->add(new ChoiceBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
-                                                   177 + y_pos*32), 
-                                          Size(32, 32))), true);
+      control->set_rect(Rect(120 + x_pos * 312 + 140, 177 + y_pos*32,
+                             120 + x_pos * 312 + 256, 177 + y_pos*32 + 32));   
                          
     }
-  else if (1)
+  else if (dynamic_cast<SliderBox*>(control))
     {
-      gui_manager->add(new SliderBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
-                                                   177 + y_pos*32), 
-                                          Size(32, 32))), true);
+      control->set_rect(Rect(120 + x_pos * 312 + 140, 177 + y_pos*32,
+                             120 + x_pos * 312 + 256, 177 + y_pos*32 + 32));
     }
+  else if (dynamic_cast<CheckBox*>(control))
+    {
+      control->set_rect(Rect(Vector2i(120 + x_pos * 312 + 156 + 32+28+8, 177 + 
y_pos*32), 
+                             Size(32, 32)));
+    }
   else
     {
-      gui_manager->add(new CheckBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
-                                                  177 + y_pos*32), 
-                                         Size(32, 32))), true);
+      assert(!"Unhandled control type");
     }
 
   y_pos += 1;  
@@ -113,43 +116,45 @@
   gc.draw(background, Vector2i(gc.get_width()/2 - background.get_width()/2, 
gc.get_height()/2 - background.get_height()/2));
 
   gc.print_center(Fonts::chalk_large, gc.get_width()/2, 90, "Option Menu");
-  
-  std::vector<OptionEntry> strs;
-  strs.push_back(OptionEntry("Resolution:",    "<800x600>"));
-  strs.push_back(OptionEntry("Fullscreen:",    "[X]"));
-  strs.push_back(OptionEntry("Allow Resize:",  "[X]"));
-  strs.push_back(OptionEntry("Fast Mode:",     "[X]"));
-  strs.push_back(OptionEntry("Frame Skip:",      "<5>"));
-  strs.push_back(OptionEntry("Software Cursor:", "[X]"));
 
-  int y = 145;
-  for(std::vector<OptionEntry>::iterator i = strs.begin(); i != strs.end(); 
++i)
+  if (0)  
     {
-      //gc.print_left(Fonts::chalk_normal,  120, y += 32, i->left);
-      y += 32;
-      if (i->right != "[X]")
-      gc.print_right(Fonts::chalk_normal, gc.get_width()/2 - 32, y, i->right);
-    }
+      std::vector<OptionEntry> strs;
+      strs.push_back(OptionEntry("Resolution:",    "<800x600>"));
+      strs.push_back(OptionEntry("Fullscreen:",    "[X]"));
+      strs.push_back(OptionEntry("Allow Resize:",  "[X]"));
+      strs.push_back(OptionEntry("Fast Mode:",     "[X]"));
+      strs.push_back(OptionEntry("Frame Skip:",      "<5>"));
+      strs.push_back(OptionEntry("Software Cursor:", "[X]"));
 
-  std::vector<OptionEntry> strs2;
-  strs2.push_back(OptionEntry("Language:",        "<German>"));
-  strs2.push_back(OptionEntry("Master Volume:", 
"[||||||||||||||||||||||||||||||]"));
-  strs2.push_back(OptionEntry("Sound Volume:",  
"[||||||||||||||||||||||||||||||]"));
-  strs2.push_back(OptionEntry("Music Volume:",  
"[||||||||||||||||||||||||||||||]"));
-  strs2.push_back(OptionEntry("Scroll Mode:",     "<drag&drop>"));
-  strs2.push_back(OptionEntry("Mouse Grab:",     "[X]"));
-  //strs2.push_back(OptionEntry("Auto Online Updates:", "[X]"));
+      int y = 145;
+      for(std::vector<OptionEntry>::iterator i = strs.begin(); i != 
strs.end(); ++i)
+        {
+          //gc.print_left(Fonts::chalk_normal,  120, y += 32, i->left);
+          y += 32;
+          if (i->right != "[X]")
+            gc.print_right(Fonts::chalk_normal, gc.get_width()/2 - 32, y, 
i->right);
+        }
 
-  y = 145;
-  for(std::vector<OptionEntry>::iterator i = strs2.begin(); i != strs2.end(); 
++i)
-    {
-      //gc.print_left(Fonts::chalk_normal,  gc.get_width()/2 + 32, y += 32, 
i->left);
-      y += 32;
-      if (i->right != "[X]")
-        gc.print_right(Fonts::chalk_normal, gc.get_width()/2 + 280, y, 
i->right);
+      std::vector<OptionEntry> strs2;
+      strs2.push_back(OptionEntry("Language:",        "<German>"));
+      strs2.push_back(OptionEntry("Master Volume:", 
"[||||||||||||||||||||||||||||||]"));
+      strs2.push_back(OptionEntry("Sound Volume:",  
"[||||||||||||||||||||||||||||||]"));
+      strs2.push_back(OptionEntry("Music Volume:",  
"[||||||||||||||||||||||||||||||]"));
+      strs2.push_back(OptionEntry("Scroll Mode:",     "<drag&drop>"));
+      strs2.push_back(OptionEntry("Mouse Grab:",     "[X]"));
+      //strs2.push_back(OptionEntry("Auto Online Updates:", "[X]"));
+
+      y = 145;
+      for(std::vector<OptionEntry>::iterator i = strs2.begin(); i != 
strs2.end(); ++i)
+        {
+          //gc.print_left(Fonts::chalk_normal,  gc.get_width()/2 + 32, y += 
32, i->left);
+          y += 32;
+          if (i->right != "[X]")
+            gc.print_right(Fonts::chalk_normal, gc.get_width()/2 + 280, y, 
i->right);
+        }
     }
 
-
   gc.print_center(Fonts::chalk_normal, gc.get_width()/2 + 225 + 30, 
gc.get_height()/2 + 125 - 20, _("Close"));
   gc.draw(ok_button, Vector2i(gc.get_width()/2 + 225, gc.get_height()/2 + 
125));
 
@@ -164,4 +169,10 @@
   ScreenManager::instance()->pop_screen();
 }
 
+void
+OptionMenu::resize(const Size&)
+{
+  
+}
+
 /* EOF */

Modified: trunk/pingus/src/option_menu.hpp
===================================================================
--- trunk/pingus/src/option_menu.hpp    2007-11-07 10:40:05 UTC (rev 3500)
+++ trunk/pingus/src/option_menu.hpp    2007-11-08 14:24:30 UTC (rev 3501)
@@ -22,6 +22,8 @@
 
 #include "sprite.hpp"
 #include "screen/gui_screen.hpp"
+#include "components/label.hpp"
+#include "gui/rect_component.hpp"
 
 /** */
 class OptionMenu : public GUIScreen
@@ -31,6 +33,18 @@
   Sprite ok_button;
   int x_pos;
   int y_pos;
+
+  struct Option {
+    Label*         label;
+    GUI::RectComponent* control;
+
+    Option(Label* label, GUI::RectComponent* control)
+      : label(label), control(control)
+    {}
+  };
+
+  typedef std::vector<Option> Options;
+  Options options;
   
 public:
   OptionMenu();
@@ -40,7 +54,9 @@
   void update (const GameDelta& delta);
   void on_escape_press ();
 
-  void add_item(const std::string& label);
+  void add_item(const std::string& label, GUI::RectComponent* control);
+
+  void resize(const Size&);
 private:
   OptionMenu (const OptionMenu&);
   OptionMenu& operator= (const OptionMenu&);





reply via email to

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