From 0772ca1063db070e70844ab619aa2baa86b3dea0 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 16 Apr 2022 12:20:36 +0300 Subject: [PATCH] GameUI: fix propotional scale --- engine/vgui_baseui_interface.cpp | 5 ++--- gameui/BasePanel.cpp | 12 ++++++++---- gameui/GameConsoleDialog.cpp | 2 ++ gameui/GameUI_Interface.cpp | 8 ++++---- gameui/OptionsSubAudio.cpp | 4 ---- gameui/OptionsSubKeyboard.cpp | 10 +++++++++- gameui/OptionsSubVideo.cpp | 3 ++- gameui/matchmaking/achievementsdialog.cpp | 11 +++++++++-- public/vgui/VGUI.h | 2 ++ vgui2/vgui_controls/Panel.cpp | 21 +++++++++++---------- vgui2/vgui_controls/ScrollBar.cpp | 6 ++++-- vgui2/vgui_controls/Slider.cpp | 9 ++++----- 12 files changed, 57 insertions(+), 36 deletions(-) diff --git a/engine/vgui_baseui_interface.cpp b/engine/vgui_baseui_interface.cpp index 8d5f6f1d..2f29683c 100644 --- a/engine/vgui_baseui_interface.cpp +++ b/engine/vgui_baseui_interface.cpp @@ -696,10 +696,9 @@ void CEngineVGui::Init() COM_TimestampedLog( "Building Panels (staticGameUIPanel)" ); staticGameUIPanel = new CEnginePanel( staticPanel, "GameUI Panel" ); - if (IsAndroid() || CommandLine()->CheckParm("-gameuiproportionality")) - { + + if(NeedProportional()) staticGameUIPanel->SetProportional(true); - } staticGameUIPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() ); staticGameUIPanel->SetPaintBorderEnabled(false); diff --git a/gameui/BasePanel.cpp b/gameui/BasePanel.cpp index 5391c5f7..09a4ece2 100644 --- a/gameui/BasePanel.cpp +++ b/gameui/BasePanel.cpp @@ -242,8 +242,12 @@ public: { BaseClass::ApplySchemeSettings(pScheme); + int height = atoi(pScheme->GetResourceString("MainMenu.MenuItemHeight")); + if( IsProportional() ) + height = scheme()->GetProportionalScaledValue( height ); + // make fully transparent - SetMenuItemHeight(atoi(pScheme->GetResourceString("MainMenu.MenuItemHeight"))); + SetMenuItemHeight(height); SetBgColor(Color(0, 0, 0, 0)); SetBorder(NULL); } @@ -292,7 +296,6 @@ public: MenuItem *item = new CGameMenuItem(this, itemName); item->AddActionSignalTarget(target); item->SetCommand(command); - item->SetProportional(true); item->SetText(itemText); item->SetUserData(userData); return BaseClass::AddMenuItem(item); @@ -303,7 +306,6 @@ public: MenuItem *item = new CGameMenuItem(this, itemName); item->AddActionSignalTarget(target); item->SetCommand(command); - item->SetProportional(true); item->SetText(itemText); item->SetUserData(userData); return BaseClass::AddMenuItem(item); @@ -659,7 +661,6 @@ void CGameMenu::OnCursorEnteredMenuItem(int VPanel) static CBackgroundMenuButton* CreateMenuButton( CBasePanel *parent, const char *panelName, const wchar_t *panelText ) { CBackgroundMenuButton *pButton = new CBackgroundMenuButton( parent, panelName ); - pButton->SetProportional(true); pButton->SetCommand("OpenGameMenu"); pButton->SetText(panelText); @@ -673,6 +674,9 @@ bool g_bIsCreatingNewGameMenuForPreFetching = false; //----------------------------------------------------------------------------- CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel") { + if( NeedProportional() ) + SetProportional( true ); + g_pBasePanel = this; m_bLevelLoading = false; m_eBackgroundState = BACKGROUND_INITIAL; diff --git a/gameui/GameConsoleDialog.cpp b/gameui/GameConsoleDialog.cpp index 430102cb..dd66736b 100644 --- a/gameui/GameConsoleDialog.cpp +++ b/gameui/GameConsoleDialog.cpp @@ -12,6 +12,7 @@ #include "vgui/KeyCode.h" #include "LoadingDialog.h" #include "IGameUIFuncs.h" +#include "tier0/icommandline.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -24,6 +25,7 @@ using namespace vgui; //----------------------------------------------------------------------------- CGameConsoleDialog::CGameConsoleDialog() : BaseClass( NULL, "GameConsole", false ) { + if( NeedProportional() ) SetProportional(true); AddActionSignalTarget( this ); } diff --git a/gameui/GameUI_Interface.cpp b/gameui/GameUI_Interface.cpp index 01c7b39b..6fc27af3 100644 --- a/gameui/GameUI_Interface.cpp +++ b/gameui/GameUI_Interface.cpp @@ -203,6 +203,8 @@ void CGameUI::Initialize( CreateInterfaceFn factory ) Error( "CGameUI::Initialize() failed to get necessary interfaces\n" ); } + vgui::VPANEL rootpanel = enginevguifuncs->GetPanel( PANEL_GAMEUIDLL ); + // setup base panel staticPanel = new CBasePanel(); staticPanel->SetBounds(0, 0, 400, 300 ); @@ -212,9 +214,7 @@ void CGameUI::Initialize( CreateInterfaceFn factory ) staticPanel->SetVisible( true ); staticPanel->SetMouseInputEnabled( false ); staticPanel->SetKeyBoardInputEnabled( false ); - - vgui::VPANEL rootpanel = enginevguifuncs->GetPanel( PANEL_GAMEUIDLL ); - staticPanel->SetParent( rootpanel ); + staticPanel->SetParent(rootpanel); } void CGameUI::PostInit() @@ -1282,4 +1282,4 @@ void CGameUI::SendMainMenuCommand( const char *pszCommand ) { pBasePanel->RunMenuCommand( pszCommand ); } -} \ No newline at end of file +} diff --git a/gameui/OptionsSubAudio.cpp b/gameui/OptionsSubAudio.cpp index d1fffeba..bb82cefc 100644 --- a/gameui/OptionsSubAudio.cpp +++ b/gameui/OptionsSubAudio.cpp @@ -362,10 +362,6 @@ void COptionsSubAudio::OnCommand( const char *command ) RunTestSpeakers(); } } - else if ( !stricmp( command, "ShowThirdPartyAudioCredits" ) ) - { - OpenThirdPartySoundCreditsDialog(); - } BaseClass::OnCommand( command ); } diff --git a/gameui/OptionsSubKeyboard.cpp b/gameui/OptionsSubKeyboard.cpp index f545917b..25b02a5c 100644 --- a/gameui/OptionsSubKeyboard.cpp +++ b/gameui/OptionsSubKeyboard.cpp @@ -30,6 +30,7 @@ #include #include "tier2/tier2.h" #include "inputsystem/iinputsystem.h" +#include "tier0/icommandline.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -760,8 +761,15 @@ public: { // parent is ignored, since we want look like we're steal focus from the parent (we'll become modal below) + if( NeedProportional() ) + SetProportional(true); + SetTitle("#GameUI_KeyboardAdvanced_Title", true); - SetSize( 280, 140 ); + if( IsProportional() ) + SetSize( scheme()->GetProportionalScaledValue( 280 ), scheme()->GetProportionalScaledValue( 140 ) ); + else + SetSize( 280, 140 ); + LoadControlSettings( "resource/OptionsSubKeyboardAdvancedDlg.res" ); MoveToCenterOfScreen(); SetSizeable( false ); diff --git a/gameui/OptionsSubVideo.cpp b/gameui/OptionsSubVideo.cpp index 353f2d40..71844f96 100644 --- a/gameui/OptionsSubVideo.cpp +++ b/gameui/OptionsSubVideo.cpp @@ -1030,7 +1030,8 @@ COptionsSubVideo::COptionsSubVideo(vgui::Panel *parent) : PropertyPage(parent, N m_pBenchmark = new Button( this, "BenchmarkButton", "#GameUI_LaunchBenchmark" ); m_pBenchmark->SetCommand(new KeyValues("LaunchBenchmark")); m_pThirdPartyCredits = new URLButton(this, "ThirdPartyVideoCredits", "#GameUI_ThirdPartyTechCredits"); - m_pThirdPartyCredits->SetCommand(new KeyValues("OpenThirdPartyVideoCreditsDialog")); +// m_pThirdPartyCredits->SetCommand(new KeyValues("OpenThirdPartyVideoCreditsDialog")); + m_pThirdPartyCredits->SetVisible(false); m_pHDContent = new CheckButton( this, "HDContentButton", "#GameUI_HDContent" ); char pszAspectName[3][64]; diff --git a/gameui/matchmaking/achievementsdialog.cpp b/gameui/matchmaking/achievementsdialog.cpp index 82931b26..8dd1fa87 100644 --- a/gameui/matchmaking/achievementsdialog.cpp +++ b/gameui/matchmaking/achievementsdialog.cpp @@ -366,7 +366,12 @@ void CAchievementsDialog_XBox::OnClose() CAchievementsDialog::CAchievementsDialog(vgui::Panel *parent) : BaseClass(parent, "AchievementsDialog") { SetDeleteSelfOnClose(true); - SetBounds(0, 0, 512, 384); + + if( IsProportional() ) + SetBounds(0, 0, scheme()->GetProportionalScaledValue(512), scheme()->GetProportionalScaledValue(384)); + else + SetBounds(0, 0, 512, 384); + SetMinimumSize( 256, 300 ); SetSizeable( true ); @@ -506,7 +511,8 @@ void CAchievementsDialog::CreateNewAchievementGroup( int iMinRange, int iMaxRang //---------------------------------------------------------- void CAchievementsDialog::ApplySettings( KeyValues *pResourceData ) { - m_iFixedWidth = pResourceData->GetInt( "wide", 512 ); + int width = pResourceData->GetInt( "wide", 512 ); + m_iFixedWidth = IsProportional() ? scheme()->GetProportionalScaledValue(width) : width; BaseClass::ApplySettings( pResourceData ); } @@ -1073,3 +1079,4 @@ void CAchievementDialogItemPanel::OnCheckButtonChecked(Panel *panel) m_pSourceAchievement->SetShowOnHUD( m_pShowOnHUDCheck->IsSelected() ); } } + diff --git a/public/vgui/VGUI.h b/public/vgui/VGUI.h index 01557119..2faff5df 100644 --- a/public/vgui/VGUI.h +++ b/public/vgui/VGUI.h @@ -14,6 +14,8 @@ #define null 0L +#define NeedProportional() (IsAndroid() || CommandLine()->CheckParm("-gameuiproportionality")) + #ifndef NULL #ifdef __cplusplus #define NULL 0 diff --git a/vgui2/vgui_controls/Panel.cpp b/vgui2/vgui_controls/Panel.cpp index eda828cc..7a8628e0 100644 --- a/vgui2/vgui_controls/Panel.cpp +++ b/vgui2/vgui_controls/Panel.cpp @@ -226,7 +226,6 @@ KeyBindingMap_t::~KeyBindingMap_t() class CKeyBindingsMgr { public: - CKeyBindingsMgr() : m_Bindings( 0, 0, KeyBindingContextHandleLessFunc ), m_nKeyBindingContexts( 0 ) @@ -1450,8 +1449,10 @@ void Panel::SetParent(Panel *newParent) //----------------------------------------------------------------------------- void Panel::SetParent(VPANEL newParent) { + if (newParent) { + ipanel()->SetParent(GetVPanel(), newParent); } else @@ -1459,19 +1460,19 @@ void Panel::SetParent(VPANEL newParent) ipanel()->SetParent(GetVPanel(), NULL); } - if (GetVParent() && !IsPopup()) + if (GetVParent() ) { - SetProportional(ipanel()->IsProportional(GetVParent())); + if( ipanel()->IsProportional(GetVParent()) ) + SetProportional(true); - // most of the time KBInput == parents kbinput - if (ipanel()->IsKeyBoardInputEnabled(GetVParent()) != IsKeyBoardInputEnabled()) + if( IsPopup() ) { - SetKeyBoardInputEnabled(ipanel()->IsKeyBoardInputEnabled(GetVParent())); - } + // most of the time KBInput == parents kbinput + if (ipanel()->IsKeyBoardInputEnabled(GetVParent()) != IsKeyBoardInputEnabled()) + SetKeyBoardInputEnabled(ipanel()->IsKeyBoardInputEnabled(GetVParent())); - if (ipanel()->IsMouseInputEnabled(GetVParent()) != IsMouseInputEnabled()) - { - SetMouseInputEnabled(ipanel()->IsMouseInputEnabled(GetVParent())); + if (ipanel()->IsMouseInputEnabled(GetVParent()) != IsMouseInputEnabled()) + SetMouseInputEnabled(ipanel()->IsMouseInputEnabled(GetVParent())); } } diff --git a/vgui2/vgui_controls/ScrollBar.cpp b/vgui2/vgui_controls/ScrollBar.cpp index 94d76088..79ccb0d3 100644 --- a/vgui2/vgui_controls/ScrollBar.cpp +++ b/vgui2/vgui_controls/ScrollBar.cpp @@ -149,6 +149,8 @@ ScrollBar::ScrollBar(Panel *parent, const char *panelName, bool vertical) : Pane m_pOverriddenButtons[0] = NULL; m_pOverriddenButtons[1] = NULL; + int width = IsProportional() ? scheme()->GetProportionalScaledValue(SCROLLBAR_DEFAULT_WIDTH) : SCROLLBAR_DEFAULT_WIDTH; + if (vertical) { // FIXME: proportional changes needed??? @@ -158,7 +160,7 @@ ScrollBar::ScrollBar(Panel *parent, const char *panelName, bool vertical) : Pane _button[0]->SetTextInset(0, 1); _button[1]->SetTextInset(0, -1); - SetSize(SCROLLBAR_DEFAULT_WIDTH, 64); + SetSize(width, 64); } else { @@ -168,7 +170,7 @@ ScrollBar::ScrollBar(Panel *parent, const char *panelName, bool vertical) : Pane _button[0]->SetTextInset(0, 0); _button[1]->SetTextInset(0, 0); - SetSize(64, SCROLLBAR_DEFAULT_WIDTH); + SetSize(64, width); } Panel::SetPaintBorderEnabled(true); diff --git a/vgui2/vgui_controls/Slider.cpp b/vgui2/vgui_controls/Slider.cpp index a05454a2..cc64a6ed 100644 --- a/vgui2/vgui_controls/Slider.cpp +++ b/vgui2/vgui_controls/Slider.cpp @@ -230,7 +230,6 @@ void Slider::SetInverted( bool bInverted ) m_bInverted = bInverted; } - //----------------------------------------------------------------------------- // Purpose: Send a message to interested parties when the slider moves //----------------------------------------------------------------------------- @@ -386,9 +385,9 @@ void Slider::GetTrackRect( int& x, int& y, int& w, int& h ) GetPaintSize( wide, tall ); x = 0; - y = 8; + y = IsProportional() ? scheme()->GetProportionalScaledValue( 8.f ) : 8;; w = wide - (int)_nobSize; - h = 4; + h = IsProportional() ? scheme()->GetProportionalScaledValue( 4.f ) : 4; } //----------------------------------------------------------------------------- @@ -524,7 +523,7 @@ void Slider::DrawNob() #endif surface()->DrawSetColor(col); - int nobheight = 16; + int nobheight = IsProportional() ? scheme()->GetProportionalScaledValue( 16.f ) : 16.f; surface()->DrawFilledRect( _nobPos[0], @@ -941,7 +940,7 @@ void Slider::SetButtonOffset(int buttonOffset) void Slider::SetThumbWidth( int width ) { - _nobSize = (float)width; + _nobSize = IsProportional() ? scheme()->GetProportionalScaledValue( (float)width) : (float)width; }