Rename variables and Named Event for GUI scripts, add more such vars

"gui::horPad" is now called "gui::cstHorPad", "gui::vertPad" is now
called "gui::cstVertPad", so it's clearer that they belong to the
CST anchor system.

I also added "gui::cstAspectRatio", the aspect ratio of screen or Doom3's
window resolution (when using windowed mode).
Furthermore "gui::cstWidth" and "gui::cstHeigh" with the screen
(or Doom3 window) resolution in *virtual* pixels, based on that GUI
640x480 coordinate system.
For widescreen resolutions, "gui::cstHeight" is always 480 and
"gui::cstWidth" is scaled according to the aspect ratio (>640).
For tall resolutions, "gui::cstWidth" is always 640 and "gui::cstHeight"
is scaled according to the aspect ratio (> 480).
This commit is contained in:
Daniel Gibson 2025-02-23 06:33:27 +01:00
parent 15285e268a
commit c41ac185cc
2 changed files with 18 additions and 13 deletions

View file

@ -531,13 +531,13 @@ void idUserInterfaceLocal::Redraw( int _time ) {
if ( !loading && desktop ) {
if ( desktop->GetFlags() & WIN_MENUGUI ) {
// if the (SDL) window size has changed, calculate and set the
// "gui::horPad" and "gui::vertPad" window variables accordingly
if ( MaybeSetPaddingWinVars() ) {
// "gui::cst*" window register variables accordingly
if ( MaybeSetCstWinRegs() ) {
// tell the GUI script about it in case it wants to handle the size change in
// some way (though usually it's enough to use sth like
// `rect 0, 200, "gui::horPad", 100"` and `cstAnchor CST_ANCHOR_LEFT`
// `rect 0, 200, "gui::cstHorPad", 100"` and `cstAnchor CST_ANCHOR_LEFT`
// for a windowDef that should fill part of the left side)
HandleNamedEvent( "UpdateWindowSize" );
HandleNamedEvent( "CstScreenSizeChange" );
}
}
@ -645,9 +645,9 @@ const char *idUserInterfaceLocal::Activate(bool activate, int _time) {
activateStr = "";
if ( desktop->GetFlags() & WIN_MENUGUI ) {
// DG: calculate and set the "gui::horPad" and "gui::vertPad"
// window variables so the GUI can use them
MaybeSetPaddingWinVars(true);
// DG: calculate and set the "gui::cst*" window register variables
// so the GUI can use them
MaybeSetCstWinRegs(true);
}
desktop->Activate( activate, activateStr );
return activateStr;
@ -841,7 +841,7 @@ void idUserInterfaceLocal::SetCursor( float x, float y ) {
}
bool idUserInterfaceLocal::MaybeSetPaddingWinVars(bool force) {
bool idUserInterfaceLocal::MaybeSetCstWinRegs(bool force) {
if ( desktop == NULL ) {
return false;
}
@ -861,17 +861,22 @@ bool idUserInterfaceLocal::MaybeSetPaddingWinVars(bool force) {
float horizPadding = 0;
float vertPadding = 0;
float modWidth = desktopWidth;
float modHeight = desktopHeight;
if (glAspectRatio >= vidAspectRatio) {
float modWidth = desktopHeight * glAspectRatio;
modWidth = desktopHeight * glAspectRatio;
horizPadding = 0.5f * (modWidth - desktopWidth);
} else {
float modHeight = desktopWidth / glAspectRatio;
modHeight = desktopWidth / glAspectRatio;
vertPadding = 0.5f * (modHeight - desktopHeight);
}
SetStateFloat( "horPad", horizPadding );
SetStateFloat( "vertPad", vertPadding );
SetStateFloat( "cstAspectRatio", glAspectRatio );
SetStateFloat( "cstWidth", modWidth );
SetStateFloat( "cstHeight", modHeight );
SetStateFloat( "cstHorPad", horizPadding );
SetStateFloat( "cstVertPad", vertPadding );
return true;
}

View file

@ -123,7 +123,7 @@ private:
// to fill up the gap
// if force=true, the variables are set no matter if the size has changed or not
// returns true if the windowSize has changed and thus the variables were updated, otherwise false
bool MaybeSetPaddingWinVars(bool force=false);
bool MaybeSetCstWinRegs(bool force=false);
int lastGlWidth;
int lastGlHeight;
};