pingus-cvs
[Top][All Lists]
Advanced

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

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


From: jave27
Subject: [Pingus-CVS] r2565 - trunk/src/editor
Date: Tue, 27 Dec 2005 22:58:06 +0100

Author: jave27
Date: 2005-12-27 22:58:03 +0100 (Tue, 27 Dec 2005)
New Revision: 2565

Modified:
   trunk/src/editor/editor_viewport.cxx
   trunk/src/editor/editor_viewport.hxx
Log:
Added a "snap to" ability for moving the editor objects around.

Modified: trunk/src/editor/editor_viewport.cxx
===================================================================
--- trunk/src/editor/editor_viewport.cxx        2005-12-27 21:24:12 UTC (rev 
2564)
+++ trunk/src/editor/editor_viewport.cxx        2005-12-27 21:58:03 UTC (rev 
2565)
@@ -37,6 +37,8 @@
        state(CL_Display::get_width(), CL_Display::get_height()),
        scene_context(new SceneContext()),
        editor(e),
+       current_obj(0),
+       snap_to(true),
        autoscroll(true)
 {
        // FIXME: Hardcoded values should be determined by level size
@@ -62,6 +64,25 @@
                obj->on_primary_button_click(x, y);
 }
 
+// Select a LevelObj
+void 
+EditorViewport::on_primary_button_press(int x, int y)
+{
+       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;
+}
+
+
+// Release the LevelObj
+void 
+EditorViewport::on_primary_button_release(int x, int y)
+{
+       if (current_obj)
+               current_obj = 0;
+}
+
 // Draws all of the objects in the viewport and the background (if any)
 void
 EditorViewport::draw(DrawingContext &gc)
@@ -93,6 +114,20 @@
 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

Modified: trunk/src/editor/editor_viewport.hxx
===================================================================
--- trunk/src/editor/editor_viewport.hxx        2005-12-27 21:24:12 UTC (rev 
2564)
+++ trunk/src/editor/editor_viewport.hxx        2005-12-27 21:58:03 UTC (rev 
2565)
@@ -52,9 +52,6 @@
        /** Returns the list of objects inside the viewport */
        std::vector<std::string> get_objects() { return objs; }
 
-       /** When someone right-clicks inside the viewport */
-       void on_secondary_button_click(int x, int y);
-
        /** Draws all of the objects in the viewport */
        void draw(DrawingContext &gc);
 
@@ -88,8 +85,19 @@
        /** Where the mouse is right now - used for autoscrolling */
        Vector mouse_at;
 
+       /** The currently selected LevelObj */
+       LevelObj* current_obj;
+
        /** Returns the topmost object at this x, y location */
        LevelObj* object_at(int x, int y);
+
+       /** Whether or not the "snap-to-grid" functionality is on. */
+       bool snap_to;
+
+       /// Mouse actions
+       void on_primary_button_press(int x, int y);
+       void on_primary_button_release(int x, int y);
+       void on_secondary_button_click(int x, int y);
 };
 
 } // Editor namespace





reply via email to

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