Allow scaling non-menu WIN_DESKTOP GUIs to 4:3

WIN_DESKTOP means that this can currently only be set for the top-level
window in a .gui (all its subwindows/widgets will be scaled implicitly)

There are two ways to make a GUI use this:
1. in the .gui add a window variable "scaleto43 1", like
    windowDef Desktop {
	rect	0 ,0 ,640 ,480
	nocursor	1
	float	talk 	0

	scaleto43 1

	// .. etc rest of windowDef

2. When creating the GUI from C++ code, you can afterwards make the
   UserInterface scale to 4:3 like this:
    idUserInterface* ui = Whatever(); // create it
    ui->SetStateBool("scaleto43", true);
    ui->StateChanged(gameLocal.time);
   Both lines are important!

As you can see in my changes to Player.cpp, my primary usecase for this
is the cursor/crosshair GUI.
This commit is contained in:
Daniel Gibson 2018-11-05 04:32:04 +01:00
parent 6c1efd5a29
commit cd0a11f974
5 changed files with 47 additions and 4 deletions

View file

@ -1779,6 +1779,13 @@ void idPlayer::Spawn( void ) {
cursor = uiManager->FindGui( temp, true, gameLocal.isMultiplayer, gameLocal.isMultiplayer );
}
if ( cursor ) {
// DG: make it scale to 4:3 so crosshair looks properly round
// yes, like so many scaling-related things this is a bit hacky
// and note that this is special cased in StateChanged and you
// can *not* generally set windowDef properties like this.
cursor->SetStateBool("scaleto43", true);
cursor->StateChanged(gameLocal.time); // DG end
cursor->Activate( true, gameLocal.time );
}

View file

@ -1464,6 +1464,13 @@ void idPlayer::Spawn( void ) {
cursor = uiManager->FindGui( temp, true, gameLocal.isMultiplayer, gameLocal.isMultiplayer );
}
if ( cursor ) {
// DG: make it scale to 4:3 so crosshair looks properly round
// yes, like so many scaling-related things this is a bit hacky
// and note that this is special cased in StateChanged and you
// can *not* generally set windowDef properties like this.
cursor->SetStateBool("scaleto43", true);
cursor->StateChanged(gameLocal.time); // DG end
cursor->Activate( true, gameLocal.time );
}

View file

@ -462,6 +462,19 @@ float idUserInterfaceLocal::GetStateFloat( const char *varName, const char* defa
void idUserInterfaceLocal::StateChanged( int _time, bool redraw ) {
time = _time;
if (desktop) {
// DG: little hack: allow game DLLs to do
// ui->SetStateBool("scaleto43", true);
// ui->StateChanged(gameLocal.time);
// so we can force cursors.gui (crosshair) to be scaled, for example
bool scaleTo43 = false;
if(state.GetBool("scaleto43", "0", scaleTo43)) {
if(scaleTo43)
desktop->SetFlag(WIN_SCALETO43);
else
desktop->ClearFlag(WIN_SCALETO43);
}
// DG end
desktop->StateChanged( redraw );
}
if ( state.GetBool( "noninteractive" ) ) {

View file

@ -1210,10 +1210,15 @@ void idWindow::Redraw(float x, float y) {
// DG: allow scaling menus to 4:3
bool fixupFor43 = false;
if ( (flags & (WIN_MENUGUI | WIN_DESKTOP)) == (WIN_MENUGUI | WIN_DESKTOP)
&& r_scaleMenusTo43.GetBool() ) {
fixupFor43 = true;
dc->SetMenuScaleFix(true);
if ( flags & WIN_DESKTOP ) {
// only scale desktop windows (will automatically scale its sub-windows)
// that EITHER have the scaleto43 flag set OR are fullscreen menus and r_scaleMenusTo43 is 1
if( (flags & WIN_SCALETO43) ||
((flags & WIN_MENUGUI) && r_scaleMenusTo43.GetBool()) )
{
fixupFor43 = true;
dc->SetMenuScaleFix(true);
}
}
if ( flags & WIN_SHOWTIME ) {
@ -1941,6 +1946,15 @@ bool idWindow::ParseInternalVar(const char *_name, idParser *src) {
}
return true;
}
// DG: added this window flag for Windows that should be scaled to 4:3
// (with "empty" bars left/right or above/below)
if (idStr::Icmp(_name, "scaleto43") == 0) {
if ( src->ParseBool() ) {
flags |= WIN_SCALETO43;
}
return true;
}
// DG end
if (idStr::Icmp(_name, "forceaspectwidth") == 0) {
forceAspectWidth = src->ParseFloat();
return true;

View file

@ -65,6 +65,8 @@ const int WIN_WANTENTER = 0x01000000;
const int WIN_DESKTOP = 0x10000000;
const int WIN_SCALETO43 = 0x20000000; // DG: for the "scaleto43" window flag (=> scale window to 4:3 with "empty" bars left/right or above/below)
const char CAPTION_HEIGHT[] = "16.0";
const char SCROLLER_SIZE[] = "16.0";
const int SCROLLBAR_SIZE = 16;