Skip to content

Commit 5249e8f

Browse files
add a wrapper for getting fake/real parents and use them for recursives
1 parent 67d15fc commit 5249e8f

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/Actor.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ Actor::IsOver(float mx, float my)
309309
auto y = GetTrueY();
310310
auto hal = GetHorizAlign();
311311
auto val = GetVertAlign();
312-
auto wi = GetZoomedWidth() * GetParent()->GetTrueZoom();
313-
auto hi = GetZoomedHeight() * GetParent()->GetTrueZoom();
312+
auto wi = GetZoomedWidth() * GetFakeParentOrParent()->GetTrueZoom();
313+
auto hi = GetZoomedHeight() * GetFakeParentOrParent()->GetTrueZoom();
314314
auto lr = x - (hal * wi);
315315
auto rr = x + wi - (hal * wi);
316316
auto ur = y - (val * hi);
@@ -319,44 +319,57 @@ Actor::IsOver(float mx, float my)
319319
bool withinY = my >= ur && my <= br;
320320
return withinX && withinY;
321321
}
322+
Actor*
323+
Actor::GetFakeParentOrParent()
324+
{
325+
if (!this)
326+
return nullptr;
327+
if (m_FakeParent)
328+
return m_FakeParent;
329+
if (m_pParent)
330+
return m_pParent;
331+
return nullptr;
332+
}
322333
float
323334
Actor::GetTrueX()
324335
{
325336
if (!this)
326337
return 0.f;
327-
if (!m_pParent)
338+
auto* mfp = GetFakeParentOrParent();
339+
if (!mfp)
328340
return GetX();
329-
return GetX() * GetParent()->GetTrueZoom() +
330-
GetParent()->GetTrueX();
341+
return GetX() * mfp->GetTrueZoom() + mfp->GetTrueX();
331342
}
332343

333344
float
334345
Actor::GetTrueY()
335346
{
336347
if (!this)
337348
return 0.f;
338-
if (!m_pParent)
349+
auto* mfp = GetFakeParentOrParent();
350+
if (!mfp)
339351
return GetY();
340-
return GetY() * GetParent()->GetTrueZoom() +
341-
GetParent()->GetTrueY();
352+
return GetY() * mfp->GetTrueZoom() + mfp->GetTrueY();
342353
}
343354
float
344355
Actor::GetTrueZoom()
345356
{
346357
if (!this)
347358
return 1.f;
348-
if (!m_pParent)
359+
auto* mfp = GetFakeParentOrParent();
360+
if (!mfp)
349361
return GetZoom();
350-
return GetZoom() * GetParent()->GetTrueZoom();
362+
return GetZoom() * mfp->GetTrueZoom();
351363
}
352364
bool
353365
Actor::IsVisible()
354366
{
355367
if (!this)
356368
return false;
357-
if (!m_pParent)
369+
auto* mfp = GetFakeParentOrParent();
370+
if (!mfp)
358371
return GetVisible();
359-
return GetVisible() && GetParent()->IsVisible();
372+
return GetVisible() && mfp->IsVisible();
360373
}
361374
void
362375
Actor::Draw()
@@ -2844,7 +2857,7 @@ class LunaActor : public Luna<Actor>
28442857
ADD_METHOD(GetWrapperState);
28452858

28462859
ADD_METHOD(Draw);
2847-
2860+
28482861
ADD_METHOD(SaveXY);
28492862
ADD_METHOD(LoadXY);
28502863

src/Actor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class Actor : public MessageSubscriber
260260
bool PartiallyOpaque();
261261
bool IsOver(float mx, float my);
262262

263+
Actor* GetFakeParentOrParent(); // fake parent > parent -mina
263264
float GetTrueX(); // recursive with parent (for mouseovers) -mina
264265
float GetTrueY(); // same
265266
float GetTrueZoom(); // same

0 commit comments

Comments
 (0)