From cd0a11f974f8c3295b7b9b5c7e06b4414ba2c705 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 5 Nov 2018 04:32:04 +0100 Subject: [PATCH] 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. --- neo/d3xp/Player.cpp | 7 +++++++ neo/game/Player.cpp | 7 +++++++ neo/ui/UserInterface.cpp | 13 +++++++++++++ neo/ui/Window.cpp | 22 ++++++++++++++++++---- neo/ui/Window.h | 2 ++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/neo/d3xp/Player.cpp b/neo/d3xp/Player.cpp index dc779dfe..34956f38 100644 --- a/neo/d3xp/Player.cpp +++ b/neo/d3xp/Player.cpp @@ -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 ); } diff --git a/neo/game/Player.cpp b/neo/game/Player.cpp index e3878fa7..b8018182 100644 --- a/neo/game/Player.cpp +++ b/neo/game/Player.cpp @@ -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 ); } diff --git a/neo/ui/UserInterface.cpp b/neo/ui/UserInterface.cpp index 5a60a22b..9e595e36 100644 --- a/neo/ui/UserInterface.cpp +++ b/neo/ui/UserInterface.cpp @@ -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" ) ) { diff --git a/neo/ui/Window.cpp b/neo/ui/Window.cpp index 3de88f0b..5658d0c9 100644 --- a/neo/ui/Window.cpp +++ b/neo/ui/Window.cpp @@ -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; diff --git a/neo/ui/Window.h b/neo/ui/Window.h index 2d2af631..96f6534e 100644 --- a/neo/ui/Window.h +++ b/neo/ui/Window.h @@ -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;