pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2590 - in trunk/src: editor gui


From: jave27
Subject: [Pingus-CVS] r2590 - in trunk/src: editor gui
Date: Sun, 15 Jan 2006 00:34:49 +0100

Author: jave27
Date: 2006-01-15 00:34:39 +0100 (Sun, 15 Jan 2006)
New Revision: 2590

Modified:
   trunk/src/editor/editor_panel.cxx
   trunk/src/editor/editor_panel.hxx
   trunk/src/editor/panel_buttons.cxx
   trunk/src/editor/panel_buttons.hxx
   trunk/src/gui/combobox.cxx
   trunk/src/gui/combobox.hxx
Log:
Added a groundpiece button to the editor and re-organized the Combobox class 
a little.



Modified: trunk/src/editor/editor_panel.cxx
===================================================================
--- trunk/src/editor/editor_panel.cxx   2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/editor/editor_panel.cxx   2006-01-14 23:34:39 UTC (rev 2590)
@@ -45,7 +45,7 @@
 // Destructor
 EditorPanel::~EditorPanel()
 {
-       delete combo_groundpieces;
+       delete combobox;
 }
 
 // Wait to run this until after the panel has been added to the gui_manager
@@ -58,15 +58,12 @@
        add((PanelButton*)(new PanelButtonExit(this)));
        add((PanelButton*)(new PanelButtonLoad(this)));
        add((PanelButton*)(new PanelButtonSave(this)));
+       add((PanelButton*)(new PanelButtonGroundpiece(this)));
 
-       // Create groundpiece Combobox (FIXME: Temporary testing)
-       combo_groundpieces = new GUI::Combobox(Vector(500, 30));
-       combo_groundpieces->add(new GUI::ComboItem(0, "Test 1"));
-       combo_groundpieces->add(new GUI::ComboItem(0, "Test 2"));
-       combo_groundpieces->add(new GUI::ComboItem(0, "Test 3"));
-       combo_groundpieces->add(new GUI::ComboItem(0, "Test 4"));
-       combo_groundpieces->add(new GUI::ComboItem(0, "Test 5"));
-       get_screen()->get_gui_manager()->add(combo_groundpieces);
+       // Create Combobox
+       combobox = new GUI::Combobox(Vector(500, 30));
+       get_screen()->get_gui_manager()->add(combobox);
+       combobox->set_enabled(false);
 }
 
 // Draw the panel
@@ -76,9 +73,6 @@
        // Draw the panel
        gc.draw_fillrect(0, 0, (float)CL_Display::get_width(), 
                50.0f, CL_Color::lightgray, -50);
-
-       // Draw any labels for comboboxes that might be needed
-       gc.print_left(Fonts::smallfont, 390, 30, "Groundpieces");
 }
 
 // Add the button to the vector, set it's position, and add to the gui_manager
@@ -105,4 +99,3 @@
 
 } // Editor namespace
 } // Pingus namespace
-

Modified: trunk/src/editor/editor_panel.hxx
===================================================================
--- trunk/src/editor/editor_panel.hxx   2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/editor/editor_panel.hxx   2006-01-14 23:34:39 UTC (rev 2590)
@@ -44,7 +44,7 @@
        /** Collection of buttons on this panel */
        std::vector<PanelButton*> panel_buttons;
 
-       GUI::Combobox* combo_groundpieces;
+       GUI::Combobox* combobox;
 
 public:
        /** Constructor
@@ -67,6 +67,9 @@
 
        /** Return the editor screen */
        EditorScreen* get_screen() { return editor; }
+       
+       /** Return the combobox object */
+       GUI::Combobox* get_combobox() { return combobox; }
 
 private:
        EditorPanel();

Modified: trunk/src/editor/panel_buttons.cxx
===================================================================
--- trunk/src/editor/panel_buttons.cxx  2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/editor/panel_buttons.cxx  2006-01-14 23:34:39 UTC (rev 2590)
@@ -19,6 +19,7 @@
 
 #include <ClanLib/Display/sprite.h>
 #include "panel_buttons.hxx"
+#include "../gui/combobox.hxx"
 #include "../display/scene_context.hxx"
 #include "../path_manager.hxx"
 #include "../fonts.hxx"
@@ -103,7 +104,6 @@
 void
 PanelButtonLoad::on_primary_button_click(int x, int y)
 {
-       // TODO: Open a file dialog box to load a level.
        panel->get_screen()->show_file_dialog(true);
 }
 
@@ -123,5 +123,28 @@
        panel->get_screen()->save(path_manager.complete("levels/test.pingus"), 
".pingus");
 }
 
+
+// Load the groundpieces
+PanelButtonGroundpiece::PanelButtonGroundpiece(EditorPanel *p) :
+       PanelButton(p)
+{
+       sur = Resource::load_sprite("core/editor/save"); // FIXME: Update this 
sprite 
+       tooltip = "Load a groundpiece";
+}
+
+void
+PanelButtonGroundpiece::on_primary_button_click(int x, int y)
+{
+       UNUSED_ARG(x);
+       UNUSED_ARG(y);
+       
+       // FIXME: Add actual groundpieces
+       panel->get_combobox()->clear();
+       panel->get_combobox()->set_label("Groundpieces");
+       panel->get_combobox()->add(new GUI::ComboItem(1, "Testing 1"));
+       panel->get_combobox()->add(new GUI::ComboItem(2, "Testing 2"));
+       panel->get_combobox()->set_enabled(true);
+}
+
 } // Editor namespace
 } // Pingus namespace

Modified: trunk/src/editor/panel_buttons.hxx
===================================================================
--- trunk/src/editor/panel_buttons.hxx  2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/editor/panel_buttons.hxx  2006-01-14 23:34:39 UTC (rev 2590)
@@ -41,19 +41,19 @@
 
 protected:
        /** The actual button image */
-  CL_Sprite sur;
+       CL_Sprite sur;
 
        /** The button background image when not pressed */
-  CL_Sprite button;
+       CL_Sprite button;
 
        /** The button background image while pressed */
-  CL_Sprite button_pressed;
+       CL_Sprite button_pressed;
 
        /** The panel to which this button belongs */
        EditorPanel* panel;
 
        /** The string that appears when the mouse is hovering over this button 
*/
-  std::string tooltip;
+       std::string tooltip;
 
        /** The location of this button on the screen  (set by the EditorPanel) 
*/
        Vector pos;
@@ -96,6 +96,7 @@
        PanelButton& operator= (const PanelButton&);
 };     // PanelButton class
 
+
 /** Standard exit button */
 class PanelButtonExit : PanelButton
 {
@@ -113,6 +114,7 @@
   PanelButtonExit& operator= (const PanelButtonExit&);
 };             // PanelButtonExit class
 
+
 /** Standard load button */
 class PanelButtonLoad : PanelButton
 {
@@ -130,6 +132,7 @@
   PanelButtonLoad& operator= (const PanelButtonLoad&);
 };             // PanelButtonLoad class
 
+
 /** Standard save button */
 class PanelButtonSave : PanelButton
 {
@@ -147,9 +150,28 @@
   PanelButtonSave& operator= (const PanelButtonSave&);
 };             // PanelButtonSave class
 
+
+/** Display all of the groundpiece objects */
+class PanelButtonGroundpiece : PanelButton
+{
+public:
+       /** Constructor
+               @param p the EditorPanel to which this button belongs */
+       PanelButtonGroundpiece (EditorPanel* p);
+
+       /** This function is called by the gui_manager when the button is 
clicked */
+       void on_primary_button_click (int x, int y);
+
+private:
+       PanelButtonGroundpiece ();
+  PanelButtonGroundpiece (const PanelButtonGroundpiece&);
+  PanelButtonGroundpiece& operator= (const PanelButtonGroundpiece&);
+};             // PanelButtonGroundpiece class
+
 }              // Editor namespace
 }              // Pingus namespace
 
+
 #endif
 
 /* EOF */

Modified: trunk/src/gui/combobox.cxx
===================================================================
--- trunk/src/gui/combobox.cxx  2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/gui/combobox.cxx  2006-01-14 23:34:39 UTC (rev 2590)
@@ -27,10 +27,12 @@
 namespace GUI {
 
 // Constructor
-Combobox::Combobox (Vector p) :
+Combobox::Combobox (Vector p, std::string l) :
        current_item(0),
        drop_down(false),
-       pos(p)
+       pos(p),
+       enabled(false),
+       label(l)
 {
        // Default to 20 characters wide.
        width = Fonts::smallfont.get_width('O') * 20.0f;
@@ -40,12 +42,7 @@
 // Destructor
 Combobox::~Combobox ()
 {
-       for (std::vector<ComboItem*>::iterator i = item_list.begin();
-               i != item_list.end(); i++)
-       {
-               if ((*i)->delete_it())
-                       delete (*i);
-       }
+       clear();
 }
 
 // Add an item to the combobox
@@ -70,13 +67,28 @@
                }
        }
 }
-                       
+
+// Remove all items from this combobox
+void
+Combobox::clear()
+{
+       for (std::vector<ComboItem*>::iterator i = item_list.begin();
+               i != item_list.end(); i++)
+       {
+               if ((*i)->delete_it())
+                       delete (*i);
+       }
+}
+
 // Returns whether or not the combobox is at this location
 bool
 Combobox::is_at(int x, int y)
 {
-       return ((float)x > pos.x && (float)x < pos.x + get_width() &&
-               (float)y > pos.y && (float)y < pos.y + get_height());
+       if (enabled)
+               return ((float)x > pos.x && (float)x < pos.x + get_width() &&
+                       (float)y > pos.y && (float)y < pos.y + get_height());
+       else
+               return false;
 }
 
 // Returns the width of the box
@@ -117,9 +129,16 @@
 void
 Combobox::draw(DrawingContext &gc)
 {
-       // First off, Draw the rectangle
+       if (!enabled)
+               return;
+       
+       // Draw the label
+       gc.print_right(Fonts::smallfont, pos.x, pos.y, label);
+
+       // Draw the rectangle
        gc.draw_fillrect(pos.x, pos.y, pos.x + get_width(), pos.y + 
get_height(),
                CL_Color::white);
+
        // Next, draw the rectangle border
        gc.draw_rect(pos.x, pos.y, pos.x + get_width(), pos.y + get_height(),
                CL_Color::black);

Modified: trunk/src/gui/combobox.hxx
===================================================================
--- trunk/src/gui/combobox.hxx  2006-01-12 23:06:25 UTC (rev 2589)
+++ trunk/src/gui/combobox.hxx  2006-01-14 23:34:39 UTC (rev 2590)
@@ -101,9 +101,15 @@
        /** Location of the Combobox */
        Vector pos;
 
+       /** Whether or not this combobox is enabled */
+       bool enabled;
+       
+       /** Label that prints to the left of the drop-down */
+       std::string label;
+
 public:
        /** Constructor */
-       Combobox (Vector p);
+       Combobox (Vector p, std::string label = "");
        
        /** Destructor */
        virtual ~Combobox ();
@@ -116,6 +122,9 @@
        /** Remove an item from the list */
        virtual void remove(ComboItem* item);
 
+       /** Clears all items from combobox */
+       virtual void clear();
+
        /** Return a pointer to the selected item.  Returns 0 if nothing is 
selected */
        ComboItem* get_selected_item() { return current_item; }
 
@@ -139,6 +148,15 @@
   /** Gets emmited when a button is pressed and released over the
       same component */
   virtual void on_primary_button_click (int x, int y);
+       
+       /** Sets whether or not this combobox is clickable */
+       virtual void set_enabled(bool e) { enabled = e; }
+       
+       /** Returns whether or not the combobox is enabled */
+       virtual bool is_enabled() { return enabled; }
+       
+       /** Sets the label */
+       virtual void set_label(std::string l) { label = l; }
 
 private:
        Combobox();





reply via email to

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