Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ForceAspectRatioComponent.c
Go to the documentation of this file.
1
/*
2
This component must be attached to a size widget inside an overlay.
3
It will try to rescale the size layout to fit it inside the parent widget while keeping the specified aspect ratio.
4
*/
5
6
class
SCR_ForceAspectRatioComponent
:
ScriptedWidgetComponent
7
{
8
[
Attribute
(
"1.777"
,
UIWidgets
.EditBox)]
9
protected
float
m_fRatio
;
10
11
protected
SizeLayoutWidget
m_wRoot
;
12
13
//------------------------------------------------------------------------------------------------
14
override
protected
void
HandlerAttached
(
Widget
w)
15
{
16
m_wRoot
=
SizeLayoutWidget
.Cast(w);
17
18
if
(!
m_wRoot
)
19
Print
(
"SCR_ForceAspectRatioComponent must be attached to size widget!"
,
LogLevel
.ERROR);
20
}
21
22
//------------------------------------------------------------------------------------------------
23
override
bool
OnUpdate
(
Widget
w)
24
{
25
// This will also get called on updates of children, ignore them
26
if
(w !=
m_wRoot
|| !
GetGame
().InPlayMode())
27
return
true
;
28
29
GetGame
().GetCallqueue().CallLater(
UpdateSize
, 0);
// This must not be performed during OnUpdate
30
31
return
true
;
32
}
33
34
//------------------------------------------------------------------------------------------------
35
protected
void
UpdateSize
()
36
{
37
if
(!
m_wRoot
)
38
return
;
39
40
Widget
wParent =
m_wRoot
.GetParent();
41
42
// Bail if it's called after all widgets are destroyed.
43
if
(!
m_wRoot
)
44
return
;
45
46
// Init size layout rules
47
m_wRoot
.EnableHeightOverride(
true
);
48
m_wRoot
.EnableWidthOverride(
true
);
49
AlignableSlot
.SetVerticalAlign(
m_wRoot
,
LayoutVerticalAlign
.Center);
50
AlignableSlot
.SetHorizontalAlign(
m_wRoot
,
LayoutHorizontalAlign
.Center);
51
52
// Get size of parent area
53
float
parentWidth, parentHeight;
54
wParent.GetScreenSize(parentWidth, parentHeight);
55
56
// Ensure width and height are not zero to prevent division by zero.
57
if
(parentHeight == 0)
58
parentHeight = 1;
59
if
(parentWidth == 0)
60
parentWidth = 1;
61
62
// Check ratio of parent widget
63
float
parentRatio = parentWidth / parentHeight;
64
float
width, height;
65
if
(parentRatio >
m_fRatio
)
66
{
67
width = parentHeight *
m_fRatio
;
68
height = parentHeight;
69
}
70
else
71
{
72
width = parentWidth;
73
height = parentWidth /
m_fRatio
;
74
}
75
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);
81
}
82
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
AlignableSlot
Definition
AlignableSlot.c:13
SCR_ForceAspectRatioComponent
Definition
SCR_ForceAspectRatioComponent.c:7
SCR_ForceAspectRatioComponent::HandlerAttached
void HandlerAttached(Widget w)
Definition
SCR_ForceAspectRatioComponent.c:14
SCR_ForceAspectRatioComponent::OnUpdate
override bool OnUpdate(Widget w)
Definition
SCR_ForceAspectRatioComponent.c:23
SCR_ForceAspectRatioComponent::m_wRoot
SizeLayoutWidget m_wRoot
Definition
SCR_ForceAspectRatioComponent.c:11
SCR_ForceAspectRatioComponent::m_fRatio
float m_fRatio
Definition
SCR_ForceAspectRatioComponent.c:9
SCR_ForceAspectRatioComponent::UpdateSize
void UpdateSize()
Definition
SCR_ForceAspectRatioComponent.c:35
ScriptedWidgetComponent
Definition
ScriptedWidgetComponent.c:13
SizeLayoutWidget
Definition
SizeLayoutWidget.c:16
UIWidgets
Definition
attributes.c:40
Widget
Definition
Widget.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
LayoutHorizontalAlign
LayoutHorizontalAlign
Definition
LayoutHorizontalAlign.c:13
LayoutVerticalAlign
LayoutVerticalAlign
Definition
LayoutVerticalAlign.c:13
scripts
Game
UI
Components
SCR_ForceAspectRatioComponent.c
Generated by
1.17.0