pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3500 - in trunk/pingus/src: . components
Date: Wed, 7 Nov 2007 11:40:05 +0100

Author: grumbel
Date: 2007-11-07 11:40:05 +0100 (Wed, 07 Nov 2007)
New Revision: 3500

Modified:
   trunk/pingus/src/components/check_box.hpp
   trunk/pingus/src/components/choice_box.cpp
   trunk/pingus/src/components/choice_box.hpp
   trunk/pingus/src/components/slider_box.cpp
   trunk/pingus/src/components/slider_box.hpp
   trunk/pingus/src/option_menu.cpp
Log:
- implemented a bit of  SliderBox and ChoiceBox

Modified: trunk/pingus/src/components/check_box.hpp
===================================================================
--- trunk/pingus/src/components/check_box.hpp   2007-11-07 10:21:00 UTC (rev 
3499)
+++ trunk/pingus/src/components/check_box.hpp   2007-11-07 10:40:05 UTC (rev 
3500)
@@ -35,6 +35,7 @@
   void draw(DrawingContext& gc);
   void on_primary_button_press(int x, int y);
   void update_layout() {}
+
 private:
   CheckBox (const CheckBox&);
   CheckBox& operator= (const CheckBox&);

Modified: trunk/pingus/src/components/choice_box.cpp
===================================================================
--- trunk/pingus/src/components/choice_box.cpp  2007-11-07 10:21:00 UTC (rev 
3499)
+++ trunk/pingus/src/components/choice_box.cpp  2007-11-07 10:40:05 UTC (rev 
3500)
@@ -17,8 +17,43 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "fonts.hpp"
+#include "display/drawing_context.hpp"
 #include "choice_box.hpp"
 
+ChoiceBox::ChoiceBox(const Rect& rect)
+  : RectComponent(rect)
+{
+  current_choice = 0;
+  choices.push_back("Choice 1");
+  choices.push_back("Choice 2");
+  choices.push_back("Choice 3");
+}
 
+void
+ChoiceBox::draw(DrawingContext& gc)
+{
+  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] + " >");
+    }
+}
 
+void
+ChoiceBox::on_primary_button_press(int x, int y)
+{
+  current_choice += 1;
+  if (current_choice >= int(choices.size()))
+    current_choice = choices.size() - 1;
+}
+
+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:21:00 UTC (rev 
3499)
+++ trunk/pingus/src/components/choice_box.hpp  2007-11-07 10:40:05 UTC (rev 
3500)
@@ -20,12 +20,25 @@
 #ifndef HEADER_CHOICE_BOX_HPP
 #define HEADER_CHOICE_BOX_HPP
 
+#include <string>
+#include <vector>
+#include "gui/rect_component.hpp"
+
 /** */
-class ChoiceBox
+class ChoiceBox : public GUI::RectComponent
 {
 private:
+  int current_choice;
+  std::vector<std::string> choices;
+  
 public:
-  
+  ChoiceBox(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 update_layout() {}
+
 private:
   ChoiceBox (const ChoiceBox&);
   ChoiceBox& operator= (const ChoiceBox&);

Modified: trunk/pingus/src/components/slider_box.cpp
===================================================================
--- trunk/pingus/src/components/slider_box.cpp  2007-11-07 10:21:00 UTC (rev 
3499)
+++ trunk/pingus/src/components/slider_box.cpp  2007-11-07 10:40:05 UTC (rev 
3500)
@@ -17,8 +17,35 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "fonts.hpp"
+#include "display/drawing_context.hpp"
 #include "slider_box.hpp"
 
+SliderBox::SliderBox(const Rect& rect)
+  : RectComponent(rect),
+    value(10)
+{
+}
 
+void
+SliderBox::draw(DrawingContext& gc)
+{
+  gc.print_right(Fonts::chalk_normal, rect.left+rect.get_width()/2, rect.top, 
+                 std::string(value, '|'));
+}
 
+void
+SliderBox::on_primary_button_press(int x, int y)
+{
+  value += 1;
+}
+
+void
+SliderBox::on_secondary_button_press(int x, int y)
+{
+  value -= 1;
+  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:21:00 UTC (rev 
3499)
+++ trunk/pingus/src/components/slider_box.hpp  2007-11-07 10:40:05 UTC (rev 
3500)
@@ -20,12 +20,23 @@
 #ifndef HEADER_SLIDER_BOX_HPP
 #define HEADER_SLIDER_BOX_HPP
 
+#include <string>
+#include "gui/rect_component.hpp"
+
 /** */
-class SliderBox
+class SliderBox : public GUI::RectComponent
 {
 private:
+  int value;
+
 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 update_layout() {}
+
 private:
   SliderBox (const SliderBox&);
   SliderBox& operator= (const SliderBox&);

Modified: trunk/pingus/src/option_menu.cpp
===================================================================
--- trunk/pingus/src/option_menu.cpp    2007-11-07 10:21:00 UTC (rev 3499)
+++ trunk/pingus/src/option_menu.cpp    2007-11-07 10:40:05 UTC (rev 3500)
@@ -24,6 +24,8 @@
 #include "display/drawing_context.hpp"
 #include "components/label.hpp"
 #include "components/check_box.hpp"
+#include "components/slider_box.hpp"
+#include "components/choice_box.hpp"
 #include "gui/gui_manager.hpp"
 #include "option_menu.hpp"
 
@@ -56,10 +58,25 @@
   gui_manager->add(new Label(label, Rect(Vector2i(120 + x_pos * 312,
                                                   177 + y_pos*32), Size(160, 
32))), true);
 
-  gui_manager->add(new CheckBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 32+28,
-                                              177 + y_pos*32), 
-                                     Size(32, 32))), true);
-    
+  if (0)
+    {
+      gui_manager->add(new ChoiceBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
+                                                   177 + y_pos*32), 
+                                          Size(32, 32))), true);
+    }
+  else if (1)
+    {
+      gui_manager->add(new SliderBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
+                                                   177 + y_pos*32), 
+                                          Size(32, 32))), true);
+    }
+  else
+    {
+      gui_manager->add(new CheckBox(Rect(Vector2i(120 + x_pos * 312 + 156 + 
32+28,
+                                                  177 + y_pos*32), 
+                                         Size(32, 32))), true);
+    }
+
   y_pos += 1;  
   if (y_pos > 5)
     {





reply via email to

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