pingus-cvs
[Top][All Lists]
Advanced

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

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


From: jave27
Subject: [Pingus-CVS] r2619 - trunk/src/editor
Date: Mon, 23 Jan 2006 03:36:03 +0100

Author: jave27
Date: 2006-01-23 03:35:52 +0100 (Mon, 23 Jan 2006)
New Revision: 2619

Modified:
   trunk/src/editor/level_objs.cxx
   trunk/src/editor/level_objs.hxx
Log:
Editor takes "translation origin" of a sprite into account now when 
drawing.



Modified: trunk/src/editor/level_objs.cxx
===================================================================
--- trunk/src/editor/level_objs.cxx     2006-01-22 15:12:58 UTC (rev 2618)
+++ trunk/src/editor/level_objs.cxx     2006-01-23 02:35:52 UTC (rev 2619)
@@ -19,6 +19,7 @@
 
 #include <string>
 #include <iostream>
+#include <ClanLib/Display/sprite.h>
 #include "level_objs.hxx"
 #include "level_impl.hxx"
 #include "../blitter.hxx"
@@ -33,7 +34,7 @@
 
 // Default constructor
 LevelObj::LevelObj(std::string obj_name, LevelImpl* level_) :
-       level(level_),  
+       level(level_),
        section_name(obj_name),
        speed(0),
        parallax(0.0),
@@ -71,8 +72,9 @@
        {
                // 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), 5000);
+                       gc.draw_rect(translated_pos.x, translated_pos.y, 
translated_pos.x 
+                               + sprite.get_width(), translated_pos.y + 
sprite.get_height(), 
+                               CL_Color(255,255,255,150), 5000);
                if (attribs & HAS_WIDTH)
                {
                        for(int x = static_cast<int>(pos.x); x < pos.x + width; 
x += sprite.get_width())
@@ -94,14 +96,12 @@
 LevelObj::is_at(int x, int y)
 {
        if (!removed && attribs & (HAS_SURFACE | HAS_SURFACE_FAKE))
-               return (x > pos.x && x < pos.x + sprite.get_width()
-                       && y > pos.y && y < pos.y + sprite.get_height());
+       {
+               return (x > translated_pos.x && x < translated_pos.x + 
sprite.get_width()
+                       && y > translated_pos.y && y < translated_pos.y + 
sprite.get_height());
+       }
        else
                return false;
-               
-       // FIXME: The above method doesn't take translation origins into 
account.
-       // FIXME: This means that some objects (entrances & exits, for example)
-       // FIXME: are drawn incorrectly.
 }
 
 void
@@ -170,6 +170,7 @@
 
                sprite.set_alignment(origin, x, y);
        }
+       set_translated_pos();
 }
 
 // Set the modifier and actually modify the sprite loaded in memory
@@ -255,6 +256,63 @@
        }
 }
 
+// The translated pos is where the object appears to be "at" instead
+// of using it's "translation origin" specified in the sprite resource files
+void
+LevelObj::set_translated_pos()
+{
+       if (!sprite)
+               return;
+       
+       translated_pos = pos;
+       
+       CL_Origin orig;
+       int x, y;
+       float w = (float)sprite.get_width();
+       float h = (float)sprite.get_height();
+       
+       sprite.get_alignment(orig, x, y);
+       switch (orig)
+       {
+               case origin_top_left :
+                       break;
+               case origin_top_center :
+                       translated_pos.x -= w / 2;
+                       break;
+               case origin_top_right :
+                       translated_pos.x -= w;
+                       break;
+               case origin_center_left :
+                       translated_pos.y -= w / 2;
+                       break;
+               case origin_center :
+                       translated_pos.x -= w / 2;
+                       translated_pos.y -= h / 2;
+                       break;
+               case origin_center_right :
+                       translated_pos.x -= w;  
+                       translated_pos.y -= h / 2;
+                       break;
+               case origin_bottom_left :
+                       translated_pos.y -= h;
+                       break;
+               case origin_bottom_center :
+                       translated_pos.x -= w / 2;
+                       translated_pos.y -= h;
+                       break;
+               case origin_bottom_right :
+                       translated_pos.x -= w;
+                       translated_pos.y -= h;
+       }
+}
+
+void
+LevelObj::set_pos(Vector p)
+{
+       pos = p;
+       set_translated_pos();
+}
+
 }              // Editor namespace
 }              // Pingus namespace
 

Modified: trunk/src/editor/level_objs.hxx
===================================================================
--- trunk/src/editor/level_objs.hxx     2006-01-22 15:12:58 UTC (rev 2618)
+++ trunk/src/editor/level_objs.hxx     2006-01-23 02:35:52 UTC (rev 2619)
@@ -89,6 +89,10 @@
        /** Location of this object in the World */
        Vector pos;
 
+       /** Only used for display functions - this is the pos Vector adjusted
+       by the translation origin of the sprite */
+       Vector translated_pos;
+
        /** Location of this object before moving it around */
        Vector orig_pos;
 
@@ -157,6 +161,10 @@
 
        /** Write any additional properties to the XML file for this type */
        virtual void write_extra_properties(XMLFileWriter& xml) { }
+       
+       /** Sets a position vector of where the sprite is located based 
+               on the "translation origin" specified in the sprite file. */
+       void set_translated_pos();
 
 
 /////////////////////////////////////////////////////////
@@ -227,7 +235,7 @@
 /// Operations
 public:
        /** Set the object's position */
-       void set_pos(const Vector p) { pos = p; }
+       void set_pos(const Vector p);
        
        /** Original position of the objects before being dragged around */
        void set_orig_pos(const Vector p) { orig_pos = p; }





reply via email to

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