Browse Source

local2stage, stage2local added to Actor

dmuratshin 9 years ago
parent
commit
4661140314

+ 1 - 1
examples/Demo/src/TestDrag.h

@@ -78,7 +78,7 @@ public:
                     c->setAnchor(0.5f, 0.5f);
                     c->setResAnim(resources.getResAnim("snow"));
                     c->addTween(Actor::TweenAlpha(0), 300)->setDetachActor(true);
-                    Vector2 pos = convert_local2stage(a, contact, content);
+                    Vector2 pos = a->local2stage(contact, content);
                     c->setPosition(pos);
                     c->attachTo(contacts);
                 }

+ 13 - 2
oxygine/src/Actor.cpp

@@ -301,7 +301,7 @@ namespace oxygine
 
         TouchEvent up = *te;
         up.bubbles = false;
-        up.localPosition = convert_stage2local(this, te->localPosition, _getStage());
+        up.localPosition = stage2local(te->localPosition, _getStage());
         dispatchEvent(&up);
     }
 
@@ -320,7 +320,7 @@ namespace oxygine
         TouchEvent up = *te;
         up.type = TouchEvent::OUT;
         up.bubbles = false;
-        up.localPosition = convert_stage2local(this, te->localPosition, _getStage());
+        up.localPosition = stage2local(te->localPosition, _getStage());
         dispatchEvent(&up);
 
         updateStateOvered();
@@ -1056,6 +1056,17 @@ namespace oxygine
         return t.transform(local);
     }
 
+    Vector2 Actor::local2stage(const Vector2& pos, Actor* stage) const
+    {
+        return convert_local2stage(this, pos, stage);
+    }
+
+    Vector2 Actor::stage2local(const Vector2& pos, Actor* stage) const
+    {
+        return convert_stage2local(this, pos, stage);
+    }
+
+
     bool Actor::prepareRender(RenderState& rs, const RenderState& parentRS)
     {
         if (!(_flags & flag_visible))

+ 9 - 1
oxygine/src/Actor.h

@@ -285,6 +285,10 @@ namespace oxygine
         //converts local position to parent space
         Vector2 local2global(const Vector2& pos) const;
 
+        //converts local position to Stage
+        Vector2 local2stage(const Vector2& pos, Actor* stage = 0) const;
+        //converts global position (position in Stage space) to local space
+        Vector2 stage2local(const Vector2& pos, Actor* stage = 0) const;
 
         typedef Property2Args<float, Vector2, const Vector2&, Actor, &Actor::getPosition, &Actor::setPosition>  TweenPosition;
         typedef Property<float, float, Actor, &Actor::getX, &Actor::setX>                                       TweenX;
@@ -307,7 +311,7 @@ namespace oxygine
         /**Returns detailed actor information. Used for debug purposes. */
         virtual std::string dump(const dumpOptions& opt) const;
 
-        /**Returns Stage where Actor attached to. Use if for multi stage (window) mode*/
+        /**Returns Stage where Actor attached to. Used for multi stage (window) mode*/
         Stage*              _getStage();
 
         void setNotPressed();
@@ -420,9 +424,13 @@ namespace oxygine
     OXYGINE_DEPRECATED
     Transform getGlobalTransform2(spActor child, Actor* parent = 0);
 
+
     RectF getActorTransformedDestRect(Actor* actor, const Transform& tr);
 
+    //deprecated, use reattachActor
+    OXYGINE_DEPRECATED
     void    changeParentAndSavePosition(spActor mutualParent, spActor actor, spActor newParent);
+
     /**changes actor parent but with the same position on the screen*/
     void    reattachActor(spActor actor, spActor newParent, spActor root = 0);
 

+ 1 - 1
oxygine/src/DebugActor.cpp

@@ -421,7 +421,7 @@ namespace oxygine
     void DebugActor::onDAEvent(Event* ev)
     {
         TouchEvent* t = safeCast<TouchEvent*>(ev);
-        Vector2 loc = convert_stage2local(this, t->localPosition, _getStage());
+        Vector2 loc = stage2local(t->localPosition, _getStage());
         setAlpha(isOn(loc) ? 64 : 255);
     }
 

+ 2 - 2
oxygine/src/Draggable.cpp

@@ -102,7 +102,7 @@ namespace oxygine
         _actor->_getStage()->addEventListener(TouchEvent::TOUCH_UP, CLOSURE(this, &Draggable::onEvent));
 
         Vector2 src = pointer->getPosition().cast<Vector2>();
-        Vector2 pos = convert_stage2local(actor->getParent(), src);
+        Vector2 pos = actor->getParent()->stage2local(src);
         actor->setPosition(pos - localPosition);
 
         startDrag(localPosition);
@@ -128,7 +128,7 @@ namespace oxygine
             Actor* client = _dragClient;
 
 
-            Vector2 localPos = convert_stage2local(client, position);
+            Vector2 localPos = client->stage2local(position);
 
             Vector2 dragOffset = localPos - _dragPos;