Skip to content

Commit

Permalink
add a wrapper for getting fake/real parents and use them for recursives
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Nov 26, 2018
1 parent 67d15fc commit 5249e8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ Actor::IsOver(float mx, float my)
auto y = GetTrueY();
auto hal = GetHorizAlign();
auto val = GetVertAlign();
auto wi = GetZoomedWidth() * GetParent()->GetTrueZoom();
auto hi = GetZoomedHeight() * GetParent()->GetTrueZoom();
auto wi = GetZoomedWidth() * GetFakeParentOrParent()->GetTrueZoom();
auto hi = GetZoomedHeight() * GetFakeParentOrParent()->GetTrueZoom();
auto lr = x - (hal * wi);
auto rr = x + wi - (hal * wi);
auto ur = y - (val * hi);
Expand All @@ -319,44 +319,57 @@ Actor::IsOver(float mx, float my)
bool withinY = my >= ur && my <= br;
return withinX && withinY;
}
Actor*
Actor::GetFakeParentOrParent()
{
if (!this)
return nullptr;
if (m_FakeParent)
return m_FakeParent;
if (m_pParent)
return m_pParent;
return nullptr;
}
float
Actor::GetTrueX()
{
if (!this)
return 0.f;
if (!m_pParent)
auto* mfp = GetFakeParentOrParent();
if (!mfp)
return GetX();
return GetX() * GetParent()->GetTrueZoom() +
GetParent()->GetTrueX();
return GetX() * mfp->GetTrueZoom() + mfp->GetTrueX();
}

float
Actor::GetTrueY()
{
if (!this)
return 0.f;
if (!m_pParent)
auto* mfp = GetFakeParentOrParent();
if (!mfp)
return GetY();
return GetY() * GetParent()->GetTrueZoom() +
GetParent()->GetTrueY();
return GetY() * mfp->GetTrueZoom() + mfp->GetTrueY();
}
float
Actor::GetTrueZoom()
{
if (!this)
return 1.f;
if (!m_pParent)
auto* mfp = GetFakeParentOrParent();
if (!mfp)
return GetZoom();
return GetZoom() * GetParent()->GetTrueZoom();
return GetZoom() * mfp->GetTrueZoom();
}
bool
Actor::IsVisible()
{
if (!this)
return false;
if (!m_pParent)
auto* mfp = GetFakeParentOrParent();
if (!mfp)
return GetVisible();
return GetVisible() && GetParent()->IsVisible();
return GetVisible() && mfp->IsVisible();
}
void
Actor::Draw()
Expand Down Expand Up @@ -2844,7 +2857,7 @@ class LunaActor : public Luna<Actor>
ADD_METHOD(GetWrapperState);

ADD_METHOD(Draw);

ADD_METHOD(SaveXY);
ADD_METHOD(LoadXY);

Expand Down
1 change: 1 addition & 0 deletions src/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Actor : public MessageSubscriber
bool PartiallyOpaque();
bool IsOver(float mx, float my);

Actor* GetFakeParentOrParent(); // fake parent > parent -mina
float GetTrueX(); // recursive with parent (for mouseovers) -mina
float GetTrueY(); // same
float GetTrueZoom(); // same
Expand Down

0 comments on commit 5249e8f

Please sign in to comment.