AMFP Enhanced
C++ reference: the code this unofficial fork added
Toggle main menu visibility
Loading...
Searching...
No Matches
LuxGuiAspect.h
Go to the documentation of this file.
1
/*
2
* AMFP-2026: GUI virtual-size aspect calculation, kept free of engine types so it can be
3
* unit tested on its own (tests/cpp/test_gui_aspect.cpp).
4
*
5
* The GUI is authored for a 4:3 virtual canvas (e.g. 800x600). On a wider screen the canvas
6
* is widened so one virtual unit stays square, and the original 4:3 area is centred.
7
*/
8
#ifndef LUX_GUI_ASPECT_H
9
#define LUX_GUI_ASPECT_H
10
11
struct
cLuxGuiAspectResult
12
{
13
float
mfSizeX
,
mfSizeY
;
// size of the whole screen in virtual units
14
float
mfOffsetX
,
mfOffsetY
;
// where the authored canvas starts
15
};
16
17
/**
18
* abFixAspect=false reproduces the stock exe exactly (the extra width is scaled by the
19
* virtual WIDTH, so everything is about 7.7% too narrow at 16:9).
20
*/
21
inline
cLuxGuiAspectResult
LuxCalcGuiAspect
(
float
afVirtualX,
float
afVirtualY,
22
float
afScreenX,
float
afScreenY,
bool
abFixAspect)
23
{
24
cLuxGuiAspectResult
res;
25
float
fWantedRatio = afVirtualX / afVirtualY;
26
float
fScreenRatio = afScreenX / afScreenY;
27
28
if
(fScreenRatio >= (4.0f / 3.0f)-0.001f)
29
{
30
//The "left overs" on both sides. Stock scaled by the virtual width; the correct
31
//extra width is virtualY * screenRatio - virtualX = virtualY * (ratio difference).
32
float
fBase = abFixAspect ? afVirtualY : afVirtualX;
33
float
fAddX = fBase * (fScreenRatio-fWantedRatio);
34
res.
mfSizeX
= afVirtualX + fAddX;
35
res.
mfSizeY
= afVirtualY;
36
res.
mfOffsetX
= fAddX*0.5f;
37
res.
mfOffsetY
= 0;
38
}
39
else
40
{
41
res.
mfSizeX
= afVirtualX;
42
res.
mfSizeY
= afVirtualY;
43
res.
mfOffsetX
= 0;
44
res.
mfOffsetY
= 0;
45
}
46
return
res;
47
}
48
49
#endif
LuxCalcGuiAspect
cLuxGuiAspectResult LuxCalcGuiAspect(float afVirtualX, float afVirtualY, float afScreenX, float afScreenY, bool abFixAspect)
abFixAspect=false reproduces the stock exe exactly (the extra width is scaled by the virtual WIDTH,...
Definition
LuxGuiAspect.h:21
cLuxGuiAspectResult
Definition
LuxGuiAspect.h:12
cLuxGuiAspectResult::mfSizeX
float mfSizeX
Definition
LuxGuiAspect.h:13
cLuxGuiAspectResult::mfOffsetY
float mfOffsetY
Definition
LuxGuiAspect.h:14
cLuxGuiAspectResult::mfOffsetX
float mfOffsetX
Definition
LuxGuiAspect.h:14
cLuxGuiAspectResult::mfSizeY
float mfSizeY
Definition
LuxGuiAspect.h:13
Game
src
game
LuxGuiAspect.h
Generated by
1.18.0