pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2570 - in trunk/src: . editor


From: jave27
Subject: [Pingus-CVS] r2570 - in trunk/src: . editor
Date: Thu, 29 Dec 2005 22:18:22 +0100

Author: jave27
Date: 2005-12-29 22:18:16 +0100 (Thu, 29 Dec 2005)
New Revision: 2570

Modified:
   trunk/src/editor/editor_screen.cxx
   trunk/src/editor/editor_viewport.cxx
   trunk/src/editor/editor_viewport.hxx
   trunk/src/editor/level_objs.cxx
   trunk/src/editor/level_objs.hxx
   trunk/src/file_dialog_item.cxx
Log:
Allow multiple objects to be selected/draggged, etc in the editor.

Selecting the exits isn't quite working due to the translation_origin tag in 
the sprite.

Selecting a bunch of objects and rotating them causes heap overflows.

Modified: trunk/src/editor/editor_screen.cxx
===================================================================
--- trunk/src/editor/editor_screen.cxx  2005-12-29 19:10:07 UTC (rev 2569)
+++ trunk/src/editor/editor_screen.cxx  2005-12-29 21:18:16 UTC (rev 2570)
@@ -118,6 +118,7 @@
 {
        close_dialog = true;
        plf->load_level(file);
+       viewport->refresh();
 }
 
 // Play the current level (save to a temporary file 

Modified: trunk/src/editor/editor_viewport.cxx
===================================================================
--- trunk/src/editor/editor_viewport.cxx        2005-12-29 19:10:07 UTC (rev 
2569)
+++ trunk/src/editor/editor_viewport.cxx        2005-12-29 21:18:16 UTC (rev 
2570)
@@ -39,10 +39,11 @@
        state(CL_Display::get_width(), CL_Display::get_height()),
        scene_context(new SceneContext()),
        editor(e),
-       current_obj(0),
+       highlighted_area(0,0,0,0),
        context_menu(0),
        snap_to(true),
-       autoscroll(true)
+       autoscroll(true),
+       current_action(NOTHING)
 {
        // FIXME: Hardcoded values should be determined by level size
        state.set_limit(CL_Rect(-30, -50, 1600, 1300));
@@ -66,37 +67,124 @@
        std::cout << "Right-click at " << mouse_pos.x << ", " 
                << mouse_pos.y << std::endl;
        
-       LevelObj* obj = object_at((int)mouse_pos.x, (int)mouse_pos.y);
-       if (obj)
+//     LevelObj* obj = object_at((int)mouse_pos.x, (int)mouse_pos.y);
+       if (!current_objs.empty())
        {
-               std::vector<LevelObj*> objs;
-               objs.push_back(obj);
-               context_menu = new ContextMenu(objs, Vector((float)x, 
(float)y), this);
+       //      std::vector<LevelObj*> objs;
+       //      objs.push_back(obj);
+               context_menu = new ContextMenu(current_objs, Vector((float)x, 
(float)y), this);
                editor->get_gui_manager()->add(context_menu, true);
        }
 }
 
-// Select a LevelObj
+// Select 1 or more LevelObjs, or drag them.
 void 
 EditorViewport::on_primary_button_press(int x, int y)
 {
        remove_context_menu();
 
-       LevelObj* obj = object_at(x - (state.get_width()/2 - 
(int)state.get_pos().x),
-               y - (state.get_height()/2 - (int)state.get_pos().y));
-       if (obj)
-               current_obj = obj;
+       if (current_action == NOTHING)
+       {
+               LevelObj* obj = object_at(x - (state.get_width()/2 - 
(int)state.get_pos().x),
+                       y - (state.get_height()/2 - (int)state.get_pos().y));
+
+               if (obj)
+               {
+                       // If the currently selected object isn't selected, 
select it and deselect the rest
+                       if (!obj->is_selected())
+                       {
+                               for (unsigned i = 0; i < current_objs.size(); 
i++)
+                                       current_objs[i]->unselect();
+                               current_objs.clear();
+                               obj->select();
+                               current_objs.push_back(obj);
+                       }
+                       // Allow dragging of the currently selected objects
+                       current_action = DRAGGING;
+                       drag_start_pos = mouse_at_world;
+               }
+               else
+               {
+                       current_objs.clear();
+                       current_action = HIGHLIGHTING;
+                       highlighted_area.left = highlighted_area.right = x;
+                       highlighted_area.top = highlighted_area.bottom = y;
+               }
+       }
 }
 
 
-// Release the LevelObj
 void 
 EditorViewport::on_primary_button_release(int x, int y)
 {
-       if (current_obj)
-               current_obj = 0;
+       if (current_action == HIGHLIGHTING)
+       {
+               // Make sure CL_Rect starts at the top left
+               if (highlighted_area.right < highlighted_area.left)
+                       std::swap(highlighted_area.left, 
highlighted_area.right);
+               if (highlighted_area.bottom < highlighted_area.top)
+                       std::swap(highlighted_area.top, 
highlighted_area.bottom);
+
+               for (unsigned i = 0; i < objs.size(); i++)
+               {
+                       // Calculate the object's position
+                       CL_Point obj_pos((int)objs[i]->get_pos().x + 
(state.get_width()/2 - 
+                               (int)state.get_pos().x), 
(int)objs[i]->get_pos().y + (state.get_height()/2 - 
+                               (int)state.get_pos().y));
+                       //CL_Point obj_pos((int)objs[i]->get_pos().x, 
(int)objs[i]->get_pos().y);
+                       if (highlighted_area.is_inside(obj_pos))
+                       {
+                               current_objs.push_back(objs[i]);
+                               objs[i]->select();
+                       }
+                       else
+                               objs[i]->unselect();
+               }
+       }
+       current_action = NOTHING;
+       //highlighted_area.set_size(CL_Size(0,0));
 }
 
+void
+EditorViewport::on_pointer_move(int x, int y)
+{
+       mouse_at = Vector(float(x), float(y));
+       mouse_at_world = Vector(x - (state.get_width()/2 - state.get_pos().x),
+               y - (state.get_height()/2 - state.get_pos().y));
+
+       if (current_action == HIGHLIGHTING)
+       {
+               highlighted_area.right = x;
+               highlighted_area.bottom = y;
+       }
+       else if (current_action == DRAGGING)
+       {
+               float new_x, new_y;
+
+               for (unsigned i = 0; i < current_objs.size(); i++)
+               {
+                       Vector orig_pos(current_objs[i]->get_pos());
+                       float x_offset = mouse_at_world.x - drag_start_pos.x;
+                       float y_offset = mouse_at_world.y - drag_start_pos.y;
+                       // FIXME: Snap_to not working correctly with offsets.
+                       //if (snap_to)
+                       if (0)
+                       {
+                               // FIXME: May need to adjust the snap-to offset 
here.
+                               new_x = (float)((int)((x_offset + orig_pos.x) / 
10) * 10);
+                               new_y = (float)((int)((y_offset + orig_pos.y) / 
10) * 10);
+                       }
+                       else
+                       {
+                               new_x = x_offset + orig_pos.x;
+                               new_y = y_offset + orig_pos.y;
+                       }
+                       current_objs[i]->set_pos(Vector(new_x, new_y, 
orig_pos.z));
+               }
+               drag_start_pos = mouse_at_world;
+       }
+}
+
 // Draws all of the objects in the viewport and the background (if any)
 void
 EditorViewport::draw(DrawingContext &gc)
@@ -107,10 +195,14 @@
        // Now, draw all of the objects
 
        // Draw the level objects
-       std::vector<LevelObj*> objs = editor->get_level()->get_objects();
        for (unsigned i = 0; i < objs.size(); i++)
                objs[i]->draw(scene_context->color());
 
+       if (current_action == HIGHLIGHTING)
+               gc.draw_rect((float)highlighted_area.left, 
(float)highlighted_area.top, 
+                       (float)highlighted_area.right, 
(float)highlighted_area.bottom, 
+                       CL_Color(255,255,255,150));
+
        state.pop(*scene_context);
        gc.draw(new SceneContextDrawingRequest(scene_context, CL_Vector(0, 0, 
-5000)));
 }
@@ -123,28 +215,7 @@
        return true;
 }
 
-// 
 void
-EditorViewport::on_pointer_move(int x, int y)
-{
-       mouse_at = Vector(float(x), float(y));
-       if (current_obj)
-       {
-               Vector new_pos;
-               new_pos.x = (float)(x - (state.get_width()/2 - 
state.get_pos().x));
-               new_pos.y = (float)(y - (state.get_height()/2 - 
state.get_pos().y));
-               new_pos.z = current_obj->get_pos().z;
-               if (snap_to)
-               {
-                       // FIXME: May need to adjust the snap-to offset here.
-                       new_pos.x = (float)((int)(new_pos.x / 10) * 10);
-                       new_pos.y = (float)((int)(new_pos.y / 10) * 10);
-               }
-               current_obj->set_pos(new_pos);
-       }
-}
-
-void
 EditorViewport::update(float delta)
 {
        // Autoscroll if necessary
@@ -170,9 +241,8 @@
 {
        // we travel reversly through the object list, so that we get the
        // top-most object
-       std::vector<LevelObj*> levelobjs = editor->get_level()->get_objects();
-       for (std::vector<LevelObj*>::reverse_iterator i = levelobjs.rbegin ();
-               i != levelobjs.rend (); ++i)
+       for (std::vector<LevelObj*>::reverse_iterator i = objs.rbegin ();
+               i != objs.rend (); ++i)
        {
                if ((*i)->is_at (x, y))
                        return *i;
@@ -191,6 +261,12 @@
        }
 }
 
+void
+EditorViewport::refresh()
+{
+       objs = editor->get_level()->get_objects();
+}
+
 } // Editor namespace
 } // Pingus namespace
 

Modified: trunk/src/editor/editor_viewport.hxx
===================================================================
--- trunk/src/editor/editor_viewport.hxx        2005-12-29 19:10:07 UTC (rev 
2569)
+++ trunk/src/editor/editor_viewport.hxx        2005-12-29 21:18:16 UTC (rev 
2570)
@@ -50,9 +50,6 @@
        /** Destructor */
        ~EditorViewport ();
 
-       /** Returns the list of objects inside the viewport */
-       std::vector<std::string> get_objects() { return objs; }
-
        /** Draws all of the objects in the viewport */
        void draw(DrawingContext &gc);
 
@@ -69,6 +66,9 @@
        /** Get rid of context menu if it exists */
        void remove_context_menu();
 
+       /** Refresh the list of objects (do when loading or creating a new 
level) */
+       void refresh();
+
 private:
        EditorViewport();
        EditorViewport (const EditorViewport&);
@@ -80,18 +80,27 @@
        /** The EditorScreen to which this viewport belongs */
        EditorScreen* editor;
 
-       /** Collection of objects inside the viewport (groundpieces, traps, 
etc.) */
-       std::vector<std::string> objs;
-
        /** Whether or not Autoscrolling is turned on */
        bool autoscroll;
 
        /** Where the mouse is right now - used for autoscrolling */
        Vector mouse_at;
 
-       /** The currently selected LevelObj */
-       LevelObj* current_obj;
+       /** Where the mouse is at in relation to the world/level */
+       Vector mouse_at_world;
 
+       /** Where the mouse started dragging from */
+       Vector drag_start_pos;
+
+       /** All objects in the level */
+       std::vector<LevelObj*> objs;
+
+       /** The currently selected LevelObjs */
+       std::vector<LevelObj*> current_objs;
+
+       /** The region that is currently highlighted */
+       CL_Rect highlighted_area;
+
        /** Returns the topmost object at this x, y location */
        LevelObj* object_at(int x, int y);
 
@@ -101,6 +110,9 @@
        /** Whether or not the "snap-to-grid" functionality is on. */
        bool snap_to;
 
+       /** What is the currently selected action that the mouse is doing */
+       enum ActionType { NOTHING = 0, HIGHLIGHTING = 1, DRAGGING = 2 } 
current_action;
+
        /// Mouse actions
        void on_primary_button_press(int x, int y);
        void on_primary_button_release(int x, int y);

Modified: trunk/src/editor/level_objs.cxx
===================================================================
--- trunk/src/editor/level_objs.cxx     2005-12-29 19:10:07 UTC (rev 2569)
+++ trunk/src/editor/level_objs.cxx     2005-12-29 21:18:16 UTC (rev 2570)
@@ -48,6 +48,7 @@
        para_y(0),
        color(0,0,0,0),
        removed(false),
+       selected(false),
        attribs(get_attributes(obj_name))
 {
        
@@ -66,6 +67,10 @@
 {
        if (!removed && attribs & HAS_SURFACE)
        {
+               // If selected, draw a highlighted box around it
+               if (selected)
+                       gc.draw_rect(pos.x, pos.y, pos.x + sprite.get_width(), 
+                               pos.y + sprite.get_height(), 
CL_Color(255,255,255,150));
                if (attribs & HAS_WIDTH)
                {
                        for(int x = static_cast<int>(pos.x); x < pos.x + width; 
x += sprite.get_width())

Modified: trunk/src/editor/level_objs.hxx
===================================================================
--- trunk/src/editor/level_objs.hxx     2005-12-29 19:10:07 UTC (rev 2569)
+++ trunk/src/editor/level_objs.hxx     2005-12-29 21:18:16 UTC (rev 2570)
@@ -140,6 +140,9 @@
        /** Marks if this object has been deleted or not */
        bool removed;
 
+       /** Marks is this object is currently selected */
+       bool selected;
+
        /** Write any additional properties to the XML file for this type */
        virtual void write_extra_properties(XMLFileWriter& xml) { }
 
@@ -201,6 +204,8 @@
        /** Returns the parallax speed multiplier in the y direction */
        float get_para_y() const { return para_y; }
 
+       bool is_selected() { return selected; }
+
        /** Retrieve the object's direction */
        std::string get_direction() { return direction; }
 
@@ -270,6 +275,13 @@
        /** Soft delete of the object (needed for Undo action) */
        void remove() { removed = true; }
 
+       /** Undelete this object if it's been removed */
+       void unremove() { removed = false; }
+
+       /** Select or unselect this object */
+       void select() { selected = true; }
+       void unselect() { selected = false; }
+
        /** Write basic properties to the XML file for this type */
        virtual void write_properties(XMLFileWriter &xml);
 

Modified: trunk/src/file_dialog_item.cxx
===================================================================
--- trunk/src/file_dialog_item.cxx      2005-12-29 19:10:07 UTC (rev 2569)
+++ trunk/src/file_dialog_item.cxx      2005-12-29 21:18:16 UTC (rev 2570)
@@ -125,7 +125,7 @@
                        gc.print_left(Fonts::pingus_small, pos.x + 
(float)sprite.get_width(), 
                                pos.y, get_filename());
 
-                       // FIXME: If mouse over, draw a quick info box about 
the file item
+                       // If mouse over, draw a quick info box about the file 
item
                        if (mouse_over)
                        {
                                if (file_item.is_directory)





reply via email to

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