From 3dd8aaf5d13d594339a08835795e9c2f870fa310 Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Fri, 23 Nov 2018 15:23:22 -0300 Subject: [PATCH 1/6] [Actor] Anchor modifies origin --- oxygine/src/oxygine/actor/Actor.cpp | 16 ++++++-- oxygine/src/oxygine/actor/Actor.h | 47 ++++++++++++------------ oxygine/src/oxygine/actor/DebugActor.cpp | 6 +++ 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/oxygine/src/oxygine/actor/Actor.cpp b/oxygine/src/oxygine/actor/Actor.cpp index 59bcc0f4f..32d0f55ed 100644 --- a/oxygine/src/oxygine/actor/Actor.cpp +++ b/oxygine/src/oxygine/actor/Actor.cpp @@ -20,6 +20,7 @@ namespace oxygine { CREATE_COPYCLONE_NEW(Actor); + unsigned int Actor::DEFAULT_FLAGS = flag_visible | flag_touchEnabled | flag_touchChildrenEnabled | flag_fastTransform; std::string div(const std::string& val, const Color& color) { @@ -33,7 +34,7 @@ namespace oxygine _zOrder(0), _scale(1, 1), _rotation(0), - _flags(flag_visible | flag_touchEnabled | flag_touchChildrenEnabled | flag_fastTransform), + _flags(Actor::DEFAULT_FLAGS), _parent(0), _alpha(255), _stage(0), @@ -1168,9 +1169,18 @@ namespace oxygine return true; } - void Actor::completeRender(const RenderState& rs) + void Actor::completeRender(RenderState& rs) { - + if (getAnchorAffectsOrigin() && Vector2() != getAnchor()) { + Vector2 offset; + if (_flags&flag_anchorInPixels) + offset = getAnchor(); + else { + offset.x = getAnchorX()*getWidth(); + offset.y = getAnchorY()*getHeight(); + } + rs.transform.translate(offset); + } } bool Actor::internalRender(RenderState& rs, const RenderState& parentRS) diff --git a/oxygine/src/oxygine/actor/Actor.h b/oxygine/src/oxygine/actor/Actor.h index d604a4868..820437608 100644 --- a/oxygine/src/oxygine/actor/Actor.h +++ b/oxygine/src/oxygine/actor/Actor.h @@ -42,7 +42,8 @@ namespace oxygine class Actor: public EventDispatcher, public intrusive_list_item, public Serializable { typedef intrusive_list_item intr_list; - + public: + static unsigned int DEFAULT_FLAGS; public: Actor(const Actor& src, cloneOptions opt = 0); virtual Actor* clone(cloneOptions opt = 0) const; @@ -95,6 +96,7 @@ namespace oxygine float getRotationDegrees() const {return _rotation / MATH_PI * 180.0f;} int getPriority() const {return _zOrder;} bool getVisible() const {return (_flags & flag_visible) != 0;} + bool getAnchorAffectsOrigin() const {return (_flags & flag_anchorAffectsOrigin) != 0;} Actor* getParent() {return _parent;} const Actor* getParent() const {return _parent;} const Vector2& getSize() const {return _size;} @@ -173,6 +175,7 @@ namespace oxygine /**Show/Hide actor and children. Invisible Actor doesn't receive Touch events.*/ void setVisible(bool vis) {_flags &= ~flag_visible; if (vis) _flags |= flag_visible;} + void setAnchorAffectsOrigin(bool aff) {_flags &= ~flag_anchorAffectsOrigin; if (aff) _flags |= flag_anchorAffectsOrigin;} /**Enable/Disable culling this actor outside of clip area (use it in pair with ClipRectActor)*/ void setCull(bool enable) {_flags &= ~flag_cull; if (enable) _flags |= flag_cull;} /**Sets transparency. if alpha is 0 actor and children are completely invisible. Invisible Actor doesn't receive Touch events.*/ @@ -334,7 +337,7 @@ namespace oxygine spTween _addTween(spTween tween, bool rel); bool prepareRender(RenderState& rs, const RenderState& parentRS); - void completeRender(const RenderState& rs); + void completeRender(RenderState& rs); void markTranformDirty(); @@ -348,24 +351,6 @@ namespace oxygine mutable Transform _transform; mutable Transform _transformInvert; - - enum flags - { - flag_anchorInPixels = 1, - flag_visible = 1 << 1, - flag_touchEnabled = 1 << 2, - flag_transformDirty = 1 << 3, - flag_transformInvertDirty = 1 << 4, - flag_touchChildrenEnabled = 1 << 5, - flag_cull = 1 << 6, - flag_fastTransform = 1 << 7, - flag_boundsNoChildren = 1 << 8, - flag_actorHasBounds = 1 << 9, - flag_clickableWithZeroAlpha = 1 << 10, - flag_reserved = 1 << 11, - flag_last = flag_reserved - }; - mutable unsigned int _flags; unsigned char _alpha; char _extendedIsOn; @@ -388,8 +373,24 @@ namespace oxygine }; int32_t _pressedOvered; }; - - + public: + enum flags + { + flag_anchorInPixels = 1, + flag_visible = 1 << 1, + flag_touchEnabled = 1 << 2, + flag_transformDirty = 1 << 3, + flag_transformInvertDirty = 1 << 4, + flag_touchChildrenEnabled = 1 << 5, + flag_cull = 1 << 6, + flag_fastTransform = 1 << 7, + flag_boundsNoChildren = 1 << 8, + flag_actorHasBounds = 1 << 9, + flag_clickableWithZeroAlpha = 1 << 10, + flag_reserved = 1 << 11, + flag_anchorAffectsOrigin = 1 << 12, + flag_last = flag_anchorAffectsOrigin + }; private: Vector2 _pos; @@ -439,4 +440,4 @@ namespace oxygine } -EDITOR_INCLUDE(Actor); \ No newline at end of file +EDITOR_INCLUDE(Actor); diff --git a/oxygine/src/oxygine/actor/DebugActor.cpp b/oxygine/src/oxygine/actor/DebugActor.cpp index 70e4cee9a..e9c53cea0 100644 --- a/oxygine/src/oxygine/actor/DebugActor.cpp +++ b/oxygine/src/oxygine/actor/DebugActor.cpp @@ -397,6 +397,12 @@ namespace oxygine pos.y -= realSize.y; break; } + Vector2 o = getStage()->getAnchor(); + if (getStage()->getAnchorAffectsOrigin() && o != Vector2()) { + Vector2 sz = getStage()->getSize(); + pos.x -= sz.x*o.x; + pos.y -= sz.y*o.y; + } setPosition(pos); setScale(1.0f / getStage()->getScaleX()); From 2e7aef89564a401e84685aa0ecf919ca4338ff64 Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Mon, 26 Nov 2018 17:16:31 -0300 Subject: [PATCH 2/6] [Fix] getDestRect with Anchor affects origin --- oxygine/src/oxygine/actor/Actor.cpp | 58 ++++++++++++++-------------- oxygine/src/oxygine/actor/Actor.h | 3 +- oxygine/src/oxygine/actor/Sprite.cpp | 3 ++ 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/oxygine/src/oxygine/actor/Actor.cpp b/oxygine/src/oxygine/actor/Actor.cpp index 32d0f55ed..15112f9a5 100644 --- a/oxygine/src/oxygine/actor/Actor.cpp +++ b/oxygine/src/oxygine/actor/Actor.cpp @@ -793,21 +793,22 @@ namespace oxygine -s * _scale.y, c * _scale.y, _pos.x, _pos.y); } - - Vector2 offset; - if (_flags & flag_anchorInPixels) - { - offset.x = -_anchor.x; - offset.y = -_anchor.y; - } - else - { - offset.x = -float(_size.x * _anchor.x); - offset.y = -float(_size.y * _anchor.y);//todo, what to do? (per pixel quality) + if (!(_flags&flag_anchorAffectsOrigin)) { + Vector2 offset; + if (_flags & flag_anchorInPixels) + { + offset.x = -_anchor.x; + offset.y = -_anchor.y; + } + else + { + offset.x = -float(_size.x * _anchor.x); + offset.y = -float(_size.y * _anchor.y);//todo, what to do? (per pixel quality) + } + + tr.translate(offset); } - tr.translate(offset); - _transform = tr; _flags &= ~flag_transformDirty; @@ -1155,8 +1156,6 @@ namespace oxygine } else Transform::multiply(rs.transform, tr, parentRS.transform); - - if (_flags & flag_cull) { RectF ss_rect = getActorTransformedDestRect(this, rs.transform); @@ -1169,18 +1168,7 @@ namespace oxygine return true; } - void Actor::completeRender(RenderState& rs) - { - if (getAnchorAffectsOrigin() && Vector2() != getAnchor()) { - Vector2 offset; - if (_flags&flag_anchorInPixels) - offset = getAnchor(); - else { - offset.x = getAnchorX()*getWidth(); - offset.y = getAnchorY()*getHeight(); - } - rs.transform.translate(offset); - } + void Actor::completeRender(const RenderState& rs) { } bool Actor::internalRender(RenderState& rs, const RenderState& parentRS) @@ -1225,7 +1213,8 @@ namespace oxygine RectF Actor::getDestRect() const { - return RectF(Vector2(0, 0), getSize()); + Vector2 origin; + return RectF(alterOrigin(origin), getSize()); } spTween Actor::_addTween(spTween tween, bool rel) @@ -1677,4 +1666,17 @@ namespace oxygine return false; } + Vector2 Actor::alterOrigin(const Vector2& pos) const { + Vector2 delta; + if (_flags&flag_anchorAffectsOrigin && delta!= getAnchor()) { + if (_flags&flag_anchorInPixels) { + delta = getAnchor()*-1; + } else { + delta.x = -getAnchorX()*getSize().x; + delta.y = -getAnchorY()*getSize().y; + } + return pos+delta; + } + return pos; + } } diff --git a/oxygine/src/oxygine/actor/Actor.h b/oxygine/src/oxygine/actor/Actor.h index 820437608..6b60a6304 100644 --- a/oxygine/src/oxygine/actor/Actor.h +++ b/oxygine/src/oxygine/actor/Actor.h @@ -264,6 +264,7 @@ namespace oxygine virtual Vector2 parent2local(const Vector2& pos) const; //converts local position to parent space virtual Vector2 local2parent(const Vector2& pos = Vector2(0, 0)) const; + virtual Vector2 alterOrigin(const Vector2& pos) const; //converts local position to Stage Vector2 local2stage(const Vector2& pos = Vector2(0, 0), Actor* stage = 0) const; @@ -337,7 +338,7 @@ namespace oxygine spTween _addTween(spTween tween, bool rel); bool prepareRender(RenderState& rs, const RenderState& parentRS); - void completeRender(RenderState& rs); + void completeRender(const RenderState& rs); void markTranformDirty(); diff --git a/oxygine/src/oxygine/actor/Sprite.cpp b/oxygine/src/oxygine/actor/Sprite.cpp index 9d6dc966e..f26fdc1ce 100644 --- a/oxygine/src/oxygine/actor/Sprite.cpp +++ b/oxygine/src/oxygine/actor/Sprite.cpp @@ -288,6 +288,9 @@ namespace oxygine RectF r = _frame.getDestRect(); r.pos = r.pos.mult(_localScale); r.size = r.size.mult(_localScale); + + r.pos = alterOrigin(r.pos); + return r; } From 3e03426332220d5bf0871eafc87c7a9e94d3d06e Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Thu, 13 Dec 2018 11:41:34 -0300 Subject: [PATCH 3/6] [Fix] Sprite isOn doesn't work with AAO --- oxygine/src/oxygine/actor/Sprite.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/oxygine/src/oxygine/actor/Sprite.cpp b/oxygine/src/oxygine/actor/Sprite.cpp index f26fdc1ce..9605fcc9f 100644 --- a/oxygine/src/oxygine/actor/Sprite.cpp +++ b/oxygine/src/oxygine/actor/Sprite.cpp @@ -95,8 +95,11 @@ namespace oxygine const int BITS = (sizeof(int32_t) * 8); const unsigned char* buff = ad.data; - Vector2 pos = localPosition * _frame.getResAnim()->getAppliedScale(); + + Vector2 pos = localPosition*_frame.getResAnim()->getAppliedScale(); pos = pos.div(_localScale); + pos = -alterOrigin(-pos); + Point lp = pos.cast() / HIT_TEST_DOWNSCALE; Rect r(0, 0, ad.w, ad.h); if (r.pointIn(lp)) @@ -105,7 +108,7 @@ namespace oxygine int n = lp.x / BITS; int b = lp.x % BITS; - + return (ints[n] >> b) & 1; } return false; From 28da6581050dedfdf083019da361015882c106ed Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Fri, 5 Jul 2019 16:38:12 -0300 Subject: [PATCH 4/6] [FIX] Textfield complies with AnchorAffectsOrigin --- oxygine/src/oxygine/actor/TextField.cpp | 22 ++++++++++++++++++---- oxygine/src/oxygine/text_utils/Node.cpp | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/oxygine/src/oxygine/actor/TextField.cpp b/oxygine/src/oxygine/actor/TextField.cpp index 9bcf1e49f..f296c0b6e 100644 --- a/oxygine/src/oxygine/actor/TextField.cpp +++ b/oxygine/src/oxygine/actor/TextField.cpp @@ -309,14 +309,29 @@ namespace oxygine _root = new text::TextNode(_text.c_str()); } + Vector2 offset; + if (getAnchorAffectsOrigin()) { + offset = getAnchor(); + if (!getIsAnchorInPixels()) { + offset.x *= getSize().x; + offset.y *= getSize().y; + } + } + text::Aligner rd(_style, _mat, font, scale, getSize()); rd.begin(); _root->resize(rd); rd.end(); - + + Point origin = rd.bounds.pos; + rd.bounds.pos.x = 0; + rd.bounds.pos -= offset.cast(); + _root->finalPass(rd); + rd.bounds.pos.x += origin.x; + rd.bounds = (rd.bounds.cast() / rd.getScale()).cast(); - + _textRect = rd.bounds; Event ev(EVENT_REBUILD); @@ -387,7 +402,6 @@ namespace oxygine { stream << " font='" << s.font->getName() << "'"; } - return stream.str(); } @@ -414,7 +428,7 @@ namespace oxygine Rect r = const_cast(this)->getTextRect(); stream << " textRect=(" << r.pos.x << ", " << r.pos.y << ", " << r.size.x << ", " << r.size.y << ")"; - + stream << "\n" << Actor::dump(options); return stream.str(); diff --git a/oxygine/src/oxygine/text_utils/Node.cpp b/oxygine/src/oxygine/text_utils/Node.cpp index b980cde64..3f50604f9 100644 --- a/oxygine/src/oxygine/text_utils/Node.cpp +++ b/oxygine/src/oxygine/text_utils/Node.cpp @@ -261,11 +261,14 @@ namespace oxygine float scaleFactor = rd.getScale(); int offsetY = rd.bounds.pos.y; + int offsetX = rd.bounds.pos.x; + for (size_t i = 0; i < _data.size(); ++i) { Symbol& s = _data[i]; s.y += offsetY; + s.x += offsetX; if (s.gl.texture) s.destRect = RectF(mlt(s.x, scaleFactor), mlt(s.y, scaleFactor), mlt(s.gl.sw, scaleFactor), mlt(s.gl.sh, scaleFactor)); From d3ab2125a9cf5c69d3e312c55e751269bacda28e Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Mon, 8 Jul 2019 15:22:17 -0300 Subject: [PATCH 5/6] [FIX] TF AffectOrigin --- oxygine/src/oxygine/actor/TextField.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/oxygine/src/oxygine/actor/TextField.cpp b/oxygine/src/oxygine/actor/TextField.cpp index f296c0b6e..3c6fe0386 100644 --- a/oxygine/src/oxygine/actor/TextField.cpp +++ b/oxygine/src/oxygine/actor/TextField.cpp @@ -309,14 +309,7 @@ namespace oxygine _root = new text::TextNode(_text.c_str()); } - Vector2 offset; - if (getAnchorAffectsOrigin()) { - offset = getAnchor(); - if (!getIsAnchorInPixels()) { - offset.x *= getSize().x; - offset.y *= getSize().y; - } - } + Vector2 offset = alterOrigin(Vector2(0,0)); text::Aligner rd(_style, _mat, font, scale, getSize()); rd.begin(); @@ -325,7 +318,7 @@ namespace oxygine Point origin = rd.bounds.pos; rd.bounds.pos.x = 0; - rd.bounds.pos -= offset.cast(); + rd.bounds.pos += offset.cast(); _root->finalPass(rd); rd.bounds.pos.x += origin.x; From 8f563025ab228eb2eae5bec7520b312c9d68a647 Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Mon, 8 Jul 2019 18:40:37 -0300 Subject: [PATCH 6/6] [FIX] Scale on textfield --- oxygine/src/oxygine/actor/TextField.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oxygine/src/oxygine/actor/TextField.cpp b/oxygine/src/oxygine/actor/TextField.cpp index 3c6fe0386..8d7f4efad 100644 --- a/oxygine/src/oxygine/actor/TextField.cpp +++ b/oxygine/src/oxygine/actor/TextField.cpp @@ -318,7 +318,7 @@ namespace oxygine Point origin = rd.bounds.pos; rd.bounds.pos.x = 0; - rd.bounds.pos += offset.cast(); + rd.bounds.pos += offset.cast()*rd.getScale(); _root->finalPass(rd); rd.bounds.pos.x += origin.x;