From 6f3472b8dac425a697ddd0d57b34ac91973eefa7 Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Mon, 10 Dec 2018 17:34:03 -0300 Subject: [PATCH] [Actor] Get Global Scale [InputText] Use Global Scale to position cursor --- oxygine/src/oxygine/InputText.cpp | 4 ++-- oxygine/src/oxygine/actor/Actor.cpp | 19 ++++++++++++++++++- oxygine/src/oxygine/actor/Actor.h | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/oxygine/src/oxygine/InputText.cpp b/oxygine/src/oxygine/InputText.cpp index fae18d692..3c9390e0a 100644 --- a/oxygine/src/oxygine/InputText.cpp +++ b/oxygine/src/oxygine/InputText.cpp @@ -113,8 +113,8 @@ namespace oxygine void InputText::updateText() { _textActor->setText(_txt); - float x = static_cast(_textActor->getTextRect().getRight()); - _cursor->setX(x); + float x = static_cast(_textActor->getTextRect(_textActor->globalScaleX()).getRight()); + _cursor->setX(x+1); Event evnt(EVENT_TEXT_CHANGED); diff --git a/oxygine/src/oxygine/actor/Actor.cpp b/oxygine/src/oxygine/actor/Actor.cpp index 59bcc0f4f..b6d57ce2e 100644 --- a/oxygine/src/oxygine/actor/Actor.cpp +++ b/oxygine/src/oxygine/actor/Actor.cpp @@ -306,6 +306,24 @@ namespace oxygine return stream.str(); } + float Actor::globalScaleX() const { + float scale = getScaleX(); + const Actor* a = this; + while (a->getParent()) { + a = a->getParent(); + scale*=a->getScaleX(); + } + return scale; + } + float Actor::globalScaleY() const { + float scale = getScaleY(); + const Actor* a = this; + while (a->getParent()) { + a = a->getParent(); + scale*=a->getScaleY(); + } + return scale; + } pointer_index Actor::getPressed(MouseButton b) const { return _pressedButton[b]; @@ -1487,7 +1505,6 @@ namespace oxygine } - spTween setTimeout(timeMS dur, const EventCallback& cb, Actor* root) { if (!root) diff --git a/oxygine/src/oxygine/actor/Actor.h b/oxygine/src/oxygine/actor/Actor.h index d604a4868..b64402680 100644 --- a/oxygine/src/oxygine/actor/Actor.h +++ b/oxygine/src/oxygine/actor/Actor.h @@ -268,6 +268,8 @@ namespace oxygine //converts global position (position in Stage space) to local space Vector2 stage2local(const Vector2& pos = Vector2(0, 0), Actor* stage = 0) const; Vector2 stage2local(float x, float y, Actor* stage = 0) const; + float globalScaleX() const; + float globalScaleY() const; typedef Property2Args TweenPosition; typedef Property TweenX;