9 protected float m_fRatio;
11 protected SizeLayoutWidget m_wRoot;
14 override protected void HandlerAttached(Widget w)
16 m_wRoot = SizeLayoutWidget.Cast(w);
19 Print(
"SCR_ForceAspectRatioComponent must be attached to size widget!", LogLevel.ERROR);
23 override bool OnUpdate(Widget w)
29 GetGame().GetCallqueue().CallLater(UpdateSize, 0);
35 protected void UpdateSize()
40 Widget wParent =
m_wRoot.GetParent();
47 m_wRoot.EnableHeightOverride(
true);
48 m_wRoot.EnableWidthOverride(
true);
49 AlignableSlot.SetVerticalAlign(
m_wRoot, LayoutVerticalAlign.Center);
50 AlignableSlot.SetHorizontalAlign(
m_wRoot, LayoutHorizontalAlign.Center);
53 float parentWidth, parentHeight;
54 wParent.GetScreenSize(parentWidth, parentHeight);
57 if (parentHeight == 0)
63 float parentRatio = parentWidth / parentHeight;
65 if (parentRatio > m_fRatio)
67 width = parentHeight * m_fRatio;
68 height = parentHeight;
73 height = parentWidth / m_fRatio;
76 auto workspace =
GetGame().GetWorkspace();
77 float widthUnscaled = workspace.DPIUnscale(width);
78 float heightUnscaled = workspace.DPIUnscale(height);
79 m_wRoot.SetWidthOverride(widthUnscaled);
80 m_wRoot.SetHeightOverride(heightUnscaled);