pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/editor generic_property_frame.cxx,1.1


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/editor generic_property_frame.cxx,1.1,1.2 generic_property_frame.hxx,1.1,1.2 level_resizer.cxx,1.1,1.2 property_window.cxx,1.12,1.13 property_window.hxx,1.9,1.10
Date: 30 Nov 2002 15:06:34 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/editor
In directory dark:/tmp/cvs-serv21128/editor

Modified Files:
        generic_property_frame.cxx generic_property_frame.hxx 
        level_resizer.cxx property_window.cxx property_window.hxx 
Log Message:
- added buttons and enums to the GenericPropertyFrame


Index: generic_property_frame.cxx
===================================================================
RCS file: 
/usr/local/cvsroot/Games/Pingus/src/editor/generic_property_frame.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- generic_property_frame.cxx  29 Nov 2002 00:17:05 -0000      1.1
+++ generic_property_frame.cxx  30 Nov 2002 15:06:31 -0000      1.2
@@ -20,6 +20,8 @@
 #include <iostream>
 #include <ClanLib/GUI/label.h>
 #include <ClanLib/GUI/inputbox.h>
+#include <ClanLib/GUI/radiogroup.h>
+#include <ClanLib/GUI/radiobutton.h>
 #include <ClanLib/GUI/listbox.h>
 #include <ClanLib/GUI/checkbox.h>
 #include "../string_converter.hxx"
@@ -152,11 +154,23 @@
 class EnumDataBox : public DataBox
 {
 public:
-  CL_ListBox list_box;
+  CL_Component* parent;
+  int start_y_pos;
+  int y_pos;
+  CL_RadioGroup radio_group;
+  CL_Label      radio_label;
+  typedef std::vector<std::pair<int, CL_RadioButton*> >::iterator RButtonIter;
+  std::vector<std::pair<int, CL_RadioButton*> > radio_buttons;
+
+  /** Pointer to the value that should be changed */
   int* value;
 
-  EnumDataBox(CL_Component* parent, int y_pos, const std::string& name, int* 
_value) 
-    : list_box(CL_Rect(110, y_pos, 190, y_pos+20), parent), value(_value)
+  EnumDataBox(CL_Component* p, int y, const std::string& name, int* _value) 
+    : parent(p), 
+      start_y_pos(y),
+      y_pos(y),
+      radio_label(CL_Rect(10, y_pos, 90, y_pos+20), name, parent),
+      value(_value)
   {
   }
 
@@ -164,16 +178,46 @@
 
   void read_data() 
   {
-    
+    for (RButtonIter i = radio_buttons.begin(); i != radio_buttons.end(); ++i)
+      {
+        if (i->first == *value)
+          {
+            i->second->set_checked(true);
+            return;
+          }
+      }
   }
   
   void write_data() 
   {
-    
+    for (RButtonIter i = radio_buttons.begin(); i != radio_buttons.end(); ++i)
+      {
+        if (i->second->is_checked())
+          {
+            *value = i->first;
+            return;
+          }
+      }    
   }
 
-  void add_item(const std::string&)
+  void add_item(const std::string& name, int item_value)
   {
+    CL_RadioButton* rbutton = new CL_RadioButton(CL_Point(110, y_pos), name, 
parent);
+    radio_buttons.push_back(std::pair<int, CL_RadioButton*>(item_value, 
rbutton));
+    radio_group.add(rbutton);
+
+    std::cout << "Value: " << *value << " ItemValue: " << item_value << 
std::endl;
+
+    if (item_value == *value)
+      rbutton->set_checked(true);
+    else
+      rbutton->set_checked(false);
+
+    y_pos += 20;
+  }
+  
+  int get_height() {
+    return y_pos - start_y_pos + 5;
   }
 };
 
@@ -197,7 +241,7 @@
 {
   data_boxes.push_back(new StringDataBox(this, y_pos, name, value));
   y_pos += 20;
-  set_height(y_pos);
+  set_height(y_pos + 5);
 }
 
 void
@@ -205,7 +249,7 @@
 {
   data_boxes.push_back(new IntegerDataBox(this, y_pos, name, value));
   y_pos += 20;
-  set_height(y_pos);
+  set_height(y_pos + 5);
 }
 
 void
@@ -213,22 +257,32 @@
 {
   data_boxes.push_back(new FloatDataBox(this, y_pos, name, value));
   y_pos += 20;
-  set_height(y_pos);
+  set_height(y_pos + 5);
 }
 
 void
-GenericPropertyFrame::begin_add_enum_box(const std::string& title, int*)
+GenericPropertyFrame::begin_add_enum_box(const std::string& title, int* value)
 {
+  assert(enum_data_box == 0);
+  enum_data_box = new EnumDataBox(this, y_pos, title, value);
 }
 
 void
-GenericPropertyFrame::add_enum_value(const std::string name, int value)
+GenericPropertyFrame::add_enum_value(const std::string& name, int value)
 {
+  assert(enum_data_box);
+  enum_data_box->add_item(name, value);
 }
 
 void
 GenericPropertyFrame::end_add_enum_box()
 {
+  assert(enum_data_box);
+
+  data_boxes.push_back(enum_data_box);
+  y_pos += enum_data_box->get_height();
+  set_height(y_pos + 5);
+
   enum_data_box = 0;
 }
 
@@ -237,7 +291,7 @@
 {
   data_boxes.push_back(new BoolDataBox(this, y_pos, name, value));
   y_pos += 20;
-  set_height(y_pos);
+  set_height(y_pos + 5);
 }
 
 } // namespace EditorNS

Index: generic_property_frame.hxx
===================================================================
RCS file: 
/usr/local/cvsroot/Games/Pingus/src/editor/generic_property_frame.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- generic_property_frame.hxx  29 Nov 2002 00:17:05 -0000      1.1
+++ generic_property_frame.hxx  30 Nov 2002 15:06:31 -0000      1.2
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <string>
+#include <ClanLib/GUI/button.h>
 #include "property_frame.hxx"
 
 class CL_Component;
@@ -38,6 +39,30 @@
   virtual void write_data() =0;
 };
 
+template<class Func>
+class ButtonDataBox : public DataBox
+{
+private:
+  CL_Button button;
+  CL_Slot slot;
+  Func func;
+
+public:
+  ButtonDataBox(CL_Component* parent, int y_pos, const std::string& name, Func 
f)
+    : button(CL_Rect(10, y_pos, 190, y_pos + 20), name, parent), 
+      func(f)
+  {
+    slot = button.sig_clicked().connect(this, &ButtonDataBox<Func>::on_click);
+  }
+  
+  virtual ~ButtonDataBox() {}
+
+  void on_click() { func(); }
+
+  void read_data() {}
+  void write_data() {}
+};
+
 class EnumDataBox;
 
 /** PropertyFrame which can be used for simple name/value configurations */
@@ -72,10 +97,19 @@
 
   /** Representation of a boolean value */
   void add_check_box(const std::string& name, bool* value);
+
+  /** Adds a button */
+  template<class Func>
+  void add_button_box(const std::string& name, Func func)
+  {
+    data_boxes.push_back(new ButtonDataBox<Func>(this, y_pos, name, func));
+    y_pos += 25;
+    set_height(y_pos + 5);
+  }
   
   /** Creates a listbox to represent an enumeration */
   void begin_add_enum_box(const std::string& title, int*);
-  void add_enum_value(const std::string name, int value);
+  void add_enum_value(const std::string& name, int value);
   void end_add_enum_box();
 
 private:

Index: level_resizer.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/level_resizer.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- level_resizer.cxx   29 Nov 2002 22:54:22 -0000      1.1
+++ level_resizer.cxx   30 Nov 2002 15:06:31 -0000      1.2
@@ -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 <stdio.h>
 #include <ClanLib/Display/Font/font.h>
 #include "../fonts.hxx"
 #include "object_manager.hxx"

Index: property_window.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/property_window.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- property_window.cxx 29 Nov 2002 22:54:22 -0000      1.12
+++ property_window.cxx 30 Nov 2002 15:06:31 -0000      1.13
@@ -29,13 +29,22 @@
 PropertyWindow::PropertyWindow (Editor* parent)
   : CL_Window (CL_Rect (0, 0, 200, 200), "Object Properties", 
parent->get_gui_manager ()),
     editor (parent),
-    current_frame (0), label (CL_Point (50, 0), "no properties available", 
get_client_area ())
+    current_frame (0),
+    label (CL_Point (50, 0), "no properties available", get_client_area ()),
+    close_button (CL_Rect(110, 20, 190, 40), "Close", get_client_area())
 {
+  close_button_slot = close_button.sig_clicked().connect(this, 
&PropertyWindow::on_close_click);
   label.show (true);
-  set_client_size (200, 20);
+  set_client_size (200, 50);
   show (false);
 }
 
+void 
+PropertyWindow::on_close_click()
+{
+  show(false);
+}
+
 void
 PropertyWindow::update_frame (EditorObj* obj)
 {
@@ -47,33 +56,22 @@
       current_frame = 0;
     }
   
-  if (obj)
-    {
-      // We are responsible to delete comp
-      PropertyFrame* comp = obj->get_gui_dialog (editor);
-   
-      if (comp)
-       {
-         set_title(comp->get_title ());
-         label.show (false);
-
-         std::cout << "Got GUI" << std::endl;
-         current_frame = comp;
-         set_client_size (comp->get_width (), comp->get_height ());
-       }
-      else
-       {
-         label.show (true);
-         set_title("Property Dialog");
-         std::cout << "No GUI" << std::endl;
-         current_frame = 0;
-         set_client_size (200, 20);
-       }
+  if (obj && (current_frame = obj->get_gui_dialog (editor)))
+    { // current object provides a GUI
+      set_title(current_frame->get_title ());
+      label.show (false);
+      std::cout << "Got GUI" << std::endl;
+      set_client_size (current_frame->get_width () + 1, 
+                       current_frame->get_height () + 40);
+      close_button.set_position(110, current_frame->get_height () +  10);
     }
-  else
+  else // current object doesn't have a GUI or no object is selected
     {
-      set_client_size (200, 20);
       label.show (true);
+      set_title("Property Dialog");
+      std::cout << "No GUI" << std::endl;
+      set_client_size (200, 50);
+      close_button.set_position(110, 20);
     }
 }
 

Index: property_window.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/property_window.hxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- property_window.hxx 28 Nov 2002 20:09:54 -0000      1.9
+++ property_window.hxx 30 Nov 2002 15:06:31 -0000      1.10
@@ -23,9 +23,11 @@
 #include "../pingus.hxx"
 #include <ClanLib/GUI/label.h>
 #include <ClanLib/GUI/window.h>
+#include <ClanLib/GUI/button.h>
 
 class EditorObj;
 class CL_Component;
+class PropertyFrame;
 
 namespace EditorNS {
 
@@ -38,10 +40,13 @@
   Editor* editor;
   
   /** Pointer to the frame of the current object */
-  CL_Component* current_frame;
+  PropertyFrame* current_frame;
 
   /** The empty frame that is shown when no object is selected */
   CL_Label label;
+
+  CL_Button close_button;
+  CL_Slot   close_button_slot;
       
 public:
   PropertyWindow (Editor* parent);
@@ -50,6 +55,7 @@
       update() is called. */
   void update_frame (EditorObj*);
       
+  void on_close_click();
 private:
   PropertyWindow (const PropertyWindow&);
   PropertyWindow& operator= (const PropertyWindow&);





reply via email to

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