pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2573 - trunk/src/editor


From: jave27
Subject: [Pingus-CVS] r2573 - trunk/src/editor
Date: Tue, 3 Jan 2006 22:06:53 +0100

Author: jave27
Date: 2006-01-03 22:06:48 +0100 (Tue, 03 Jan 2006)
New Revision: 2573

Modified:
   trunk/src/editor/context_menu.cxx
   trunk/src/editor/context_menu.hxx
   trunk/src/editor/editor_viewport.cxx
   trunk/src/editor/editor_viewport.hxx
Log:
Added submenus to ContextMenu's.

Modified: trunk/src/editor/context_menu.cxx
===================================================================
--- trunk/src/editor/context_menu.cxx   2006-01-03 17:19:28 UTC (rev 2572)
+++ trunk/src/editor/context_menu.cxx   2006-01-03 21:06:48 UTC (rev 2573)
@@ -21,6 +21,8 @@
 #include "context_menu.hxx"
 #include "level_objs.hxx"
 #include "editor_viewport.hxx"
+#include "editor_screen.hxx"
+#include "../gui/gui_manager.hxx"
 #include "../fonts.hxx"
 
 namespace Pingus {
@@ -28,19 +30,26 @@
 namespace Editor {
 
        // Determine which actions are available for these objects
-       ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector p, 
EditorViewport* vp)
+       ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector p, 
EditorViewport* vp, bool base_menu)
                : objs(o), 
                        viewport(vp),
                        pos(p),
-                       width(200),
                        item_height(Fonts::pingus_small.get_height()),
-                       selected_action_offset(0)
+                       selected_action_offset(0),
+                       displayed_child(0)
        {
-               actions.push_back("Remove");
-               actions.push_back("ROT0");
-               actions.push_back("ROT90");
-               actions.push_back("ROT180");
-               actions.push_back("ROT270");
+               if (base_menu)
+               {
+                       // Create all available child menus
+                       width = 80;
+                       show = true;
+                       create_child_menus();
+               }
+               else
+               {
+                       width = 200;
+                       show = false;
+               }
 
                total_height  = item_height * actions.size();
        }
@@ -48,6 +57,9 @@
 
        ContextMenu::~ContextMenu()
        {
+               for (unsigned i = 0; i < actions.size(); i++)
+                       if (actions[i].child)
+                               delete actions[i].child;
        }
 
 
@@ -64,44 +76,60 @@
        void
        ContextMenu::draw(DrawingContext &gc)
        {
-               // Draw the box
-               gc.draw_fillrect(pos.x, pos.y, pos.x + 200, pos.y + 
total_height, 
-                       CL_Color(211,211,211,100));
-               // Draw the border
-               gc.draw_rect(pos.x, pos.y, pos.x + 200, pos.y + total_height, 
-                       CL_Color::black);
-               // Draw the highlighted action if the mouse is in the box
-               if (hover)
-                       gc.draw_fillrect(pos.x, pos.y + selected_action_offset 
* 
-                               item_height, pos.x + 200, pos.y + 
(selected_action_offset + 1) * item_height,
-                               CL_Color(128,128,128,100));
+               if (show)
+               {
+                       // Draw the box
+                       gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + 
total_height, 
+                               CL_Color(211,211,211,100));
+                       // Draw the border
+                       gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + 
total_height, 
+                               CL_Color::black);
+                       // Draw the highlighted action if the mouse is in the 
box
+                       if (hover)
+                       {
+                               gc.draw_fillrect(pos.x, pos.y + 
selected_action_offset * 
+                                       item_height, pos.x + width, pos.y + 
(selected_action_offset + 1) * item_height,
+                                       CL_Color(128,128,128,150));
+                       }
 
-               // Draw the action names
-               for (unsigned i = 0; i < actions.size(); i++)
-                       gc.print_left(Fonts::pingus_small, pos.x, pos.y + 
-                               (i * item_height), actions[i]);
+                       // Draw the action names
+                       for (unsigned i = 0; i < actions.size(); i++)
+                               gc.print_left(Fonts::pingus_small, pos.x, pos.y 
+ 
+                                       (i * item_height), 
actions[i].friendly_name);
+               }
        }
 
        bool
        ContextMenu::is_at(int x, int y)
        {
-               return (x > pos.x && x < pos.x + 200 &&
-                       y > pos.y && y < pos.y + total_height);
+               if (show)
+                       return (x > pos.x && x < pos.x + width &&
+                               y > pos.y && y < pos.y + total_height);
+               else
+                       return false;
        }
 
        void 
        ContextMenu::on_primary_button_click(int x, int y)
        {
-               // FIXME: Call the correct object function based on the 
selected action.
-               // FIXME: This is a temporary hack to test the functionality.
-               for (unsigned i = 0; i < objs.size(); i++)
+               if (!actions[selected_action_offset].child)
                {
-                       if (selected_action_offset == 0)
-                               objs[i]->remove();
-                       else
-                               
objs[i]->set_modifier(actions[selected_action_offset]);
+                       for (unsigned i = 0; i < objs.size(); i++)
+                       {
+                               switch 
(actions[selected_action_offset].modifier)
+                               {
+                               case (REMOVE) : 
+                                       objs[i]->remove();
+                                       break;
+                               case (ROTATE) :
+                                       
objs[i]->set_modifier(actions[selected_action_offset].parameter);
+                                       break;
+                               default :
+                                       break;
+                               }
+                       }
+                       viewport->remove_context_menu();
                }
-               viewport->remove_context_menu();
        }
 
        void
@@ -111,6 +139,69 @@
                on_primary_button_click(x, y);
        }
 
+       void
+       ContextMenu::create_child_menus()
+       {
+               // Create Remove button - available to all objects
+               actions.push_back(ContextItem("Remove", "", REMOVE, 0));
+
+               // Determine which actions are available to the selected objects
+               unsigned available_attribs = 0xffff;
+               for (unsigned i = 0; i < (unsigned)objs.size(); i++)
+                       available_attribs = available_attribs & 
objs[i]->get_attribs();
+
+               ContextMenu* menu;
+               if (available_attribs & CAN_ROTATE)
+               {
+                       menu = new ContextMenu(objs, Vector(pos.x + width, 
pos.y), viewport, false);
+                       viewport->get_screen()->get_gui_manager()->add(menu);
+                       menu->add_action(ContextItem("0 degrees", "ROT0", 
ROTATE, 0));
+                       menu->add_action(ContextItem("90 Degrees", "ROT90", 
ROTATE, 0));
+                       menu->add_action(ContextItem("180 Degrees", "ROT180", 
ROTATE, 0));
+                       menu->add_action(ContextItem("270 Degrees", "ROT270", 
ROTATE, 0));
+                       menu->add_action(ContextItem("0 Degrees + Flip", 
"ROT0FLIP", ROTATE, 0));
+                       menu->add_action(ContextItem("90 Degrees + Flip", 
"ROT90FLIP", ROTATE, 0));
+                       menu->add_action(ContextItem("180 Degrees + Flip", 
"ROT180FLIP", ROTATE, 0));
+                       menu->add_action(ContextItem("270 Degrees + Flip", 
"ROT270FLIP", ROTATE, 0));
+                       add_action(ContextItem("Rotate", "", ROTATE, menu));
+               }
+       }
+
+       void
+       ContextMenu::add_action(ContextItem item)
+       {
+               actions.push_back(item);
+               total_height += item_height;
+       }
+
+       void
+       ContextMenu::display(bool should_display)
+       {
+               show = should_display;
+               if (!show && displayed_child)
+                       displayed_child->display(false);
+       }
+
+       void
+       ContextMenu::update(float delta)
+       {
+               UNUSED_ARG(delta);
+
+               if (displayed_child != actions[selected_action_offset].child)
+               {
+                       if (displayed_child)
+                       {
+                               displayed_child->display(false);
+                               displayed_child = 0;
+                       }
+                       if (actions[selected_action_offset].child)
+                       {
+                               displayed_child = 
actions[selected_action_offset].child;
+                               displayed_child->display(true);
+                       }
+               }
+       }
+
 }      // Editor namespace
 } // Pingus namespace
 

Modified: trunk/src/editor/context_menu.hxx
===================================================================
--- trunk/src/editor/context_menu.hxx   2006-01-03 17:19:28 UTC (rev 2572)
+++ trunk/src/editor/context_menu.hxx   2006-01-03 21:06:48 UTC (rev 2573)
@@ -30,9 +30,32 @@
 
        class LevelObj;
        class EditorViewport;
+       class ContextMenu;
 
+       typedef enum ItemModifier { REMOVE, ROTATE, STRETCH };
+
+       class ContextItem {
+       public:
+               std::string friendly_name;
+               std::string parameter;
+               ItemModifier modifier;
+               ContextMenu* child;
+
+       public:
+               ContextItem(std::string friendly_name_, std::string parameter_, 
ItemModifier mod, 
+                       ContextMenu* child_menu)
+                       : friendly_name(friendly_name_),
+                               parameter(parameter_),
+                               modifier(mod),
+                               child(child_menu)
+               { }
+       };
+
        class ContextMenu : public GUI::Component {
        private:
+               /** Creates the child menu structure and detemines which 
actions are available */
+               void create_child_menus();
+
                /** Level objects to be affected by this menu */
                std::vector<LevelObj*> objs;
 
@@ -40,7 +63,7 @@
                EditorViewport* viewport;
 
                /** List of actions available in this menu */
-               std::vector<std::string> actions;
+               std::vector<ContextItem> actions;
 
                /** Where the mouse is located */
                Vector mouse_at;
@@ -51,8 +74,14 @@
                /** Is the mouse over the menu? */
                bool hover;
 
+               /** Should this be showing? */
+               bool show;
+
                /** The offset into actions vector of the currently highlighted 
action */
                unsigned selected_action_offset;
+               
+               /** Currently displayed child menu (if any) */
+               ContextMenu* displayed_child;
 
                /** Height of a single action */
                unsigned item_height;
@@ -62,20 +91,28 @@
 
        public:
                // Constructor
-               ContextMenu (std::vector<LevelObj*>, Vector p, EditorViewport* 
v);
+               ContextMenu (std::vector<LevelObj*>, Vector p, EditorViewport* 
v, bool base_menu = true);
                
                // Desctructor
                ~ContextMenu ();
 
+               /** Add an action to the list */
+               void add_action(ContextItem item);
+
+               void display (bool should_display);
+
                /// GUI Component Functions
                bool is_at(int x, int y);
                void draw (DrawingContext& gc);
+               void update (float delta);
                void on_pointer_move (int x, int y);
                void on_primary_button_click(int x, int y);
                void on_secondary_button_click(int x, int y);
                void on_pointer_enter () { hover = true; }
                void on_pointer_leave () { hover = false; }
 
+
+
        private:
                ContextMenu ();
                ContextMenu (const ContextMenu&);

Modified: trunk/src/editor/editor_viewport.cxx
===================================================================
--- trunk/src/editor/editor_viewport.cxx        2006-01-03 17:19:28 UTC (rev 
2572)
+++ trunk/src/editor/editor_viewport.cxx        2006-01-03 21:06:48 UTC (rev 
2573)
@@ -257,6 +257,7 @@
        if (context_menu)
        {
                editor->get_gui_manager()->remove(context_menu);
+               context_menu->display(false);
                context_menu = 0;
        }
 }

Modified: trunk/src/editor/editor_viewport.hxx
===================================================================
--- trunk/src/editor/editor_viewport.hxx        2006-01-03 17:19:28 UTC (rev 
2572)
+++ trunk/src/editor/editor_viewport.hxx        2006-01-03 21:06:48 UTC (rev 
2573)
@@ -69,6 +69,8 @@
        /** Refresh the list of objects (do when loading or creating a new 
level) */
        void refresh();
 
+       EditorScreen* get_screen() { return editor; }
+
 private:
        EditorViewport();
        EditorViewport (const EditorViewport&);





reply via email to

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