From 30a97f855e7581b73ad5ce44231edd1ef5ed18f0 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Fri, 17 Feb 2023 02:41:53 +0300 Subject: [PATCH] gameui: fix console size on android --- gameui/BasePanel.cpp | 104 +++++++++++++++++++++++++++++++++++++++++ gameui/GameConsole.cpp | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/gameui/BasePanel.cpp b/gameui/BasePanel.cpp index 41d52d63..c9628dbd 100644 --- a/gameui/BasePanel.cpp +++ b/gameui/BasePanel.cpp @@ -27,6 +27,7 @@ #include "materialsystem/materialsystem_config.h" #include "materialsystem/imaterialsystem.h" #include "sourcevr/isourcevirtualreality.h" +#include "VGuiMatSurface/IMatSystemSurface.h" using namespace vgui; @@ -86,6 +87,10 @@ using namespace vgui; #include "tier1/utlstring.h" #include "steam/steam_api.h" +#ifdef USE_SDL +#include +#endif + #undef MessageBox // Windows helpfully #define's this to MessageBoxA, we're using vgui::MessageBox // memdbgon must be the last include file in a .cpp file!!! @@ -197,6 +202,98 @@ void CGameMenuItem::SetRightAlignedText(bool state) m_bRightAligned = state; } +class ImageButton : public vgui::Panel +{ +public: + ImageButton(Panel *parent, const char *imageName) : Panel(parent) + { + m_szUrl = NULL; + + m_textureID = vgui::surface()->CreateNewTextureID(); + vgui::surface()->DrawSetTextureFile( m_textureID, imageName, true, false); + m_bSelected = false; + } + + virtual void Paint() + { + if( GameUI().IsInLevel() ) return; + + int color = m_bSelected ? 120 : 160; + + vgui::surface()->DrawSetColor(color, color, color, 100); + vgui::surface()->DrawFilledRect( 0, 0, GetWide(), GetTall() ); + vgui::surface()->DrawSetTexture( m_textureID ); + + vgui::surface()->DrawSetColor( 255, 255, 255, 255 ); + vgui::surface()->DrawTexturedRect( 0, 0, GetWide(), GetTall() ); + } + + virtual void OnMousePressed(MouseCode code) + { + if( GameUI().IsInLevel() ) return; + + m_bSelected = true; + input()->SetMouseCapture(GetVPanel()); + } + + virtual void OnMouseReleased(MouseCode code) + { + if( GameUI().IsInLevel() ) return; + + m_bSelected = false; +#ifdef USE_SDL + if( m_szUrl ) SDL_OpenURL( m_szUrl ); +#endif + + input()->SetMouseCapture(NULL); + } + + void SetUrl( const char *url ) + { + m_szUrl = url; + } + + virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight ) + { + int nw, nh; + surface()->GetScreenSize(nw, nh); + int scaled_w = scheme()->GetProportionalScaledValue(m_iOldW); + + Panel::SetPos(nw-scheme()->GetProportionalScaledValue(m_iOldX)-scaled_w, m_iOldY); + Panel::SetSize(scaled_w, scheme()->GetProportionalScaledValue(m_iOldH)); + } + + void SetBounds( int x, int y, int w, int h ) + { + m_iOldX = x; m_iOldY = y; + m_iOldW = w; m_iOldH = h; + + int nw, nh; + surface()->GetScreenSize(nw, nh); + int scaled_w = scheme()->GetProportionalScaledValue(m_iOldW); + + Panel::SetPos(nw-scheme()->GetProportionalScaledValue(m_iOldX)-scaled_w, m_iOldY); + Panel::SetSize(scaled_w, scheme()->GetProportionalScaledValue(m_iOldH)); + } + +private: + int m_iOldX, m_iOldY; + int m_iOldW, m_iOldH; + + bool m_bSelected; + int m_textureID; + const char *m_szUrl; +}; + +void AddUrlButton(vgui::Panel *parent, const char *imgName, const char *url ) +{ + static int i = 0; + ImageButton *panel = new ImageButton( parent, imgName ); + panel->SetUrl( url ); + panel->SetBounds( 15+i*52, 10, 48, 48 ); + i++; +} + //----------------------------------------------------------------------------- // Purpose: General purpose 1 of N menu //----------------------------------------------------------------------------- @@ -816,7 +913,14 @@ CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel") m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS; m_bSinglePlayer = false; } + } + if( IsAndroid() ) + { + AddUrlButton( this, "vgui/\x64\x69\x73\x63\x6f\x72\x64\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x64\x69\x73\x63\x6f\x72\x64\x2e\x67\x67\x2f\x68\x5a\x52\x42\x37\x57\x4d\x67\x47\x77" ); + AddUrlButton( this, "vgui/\x74\x77\x69\x74\x74\x65\x72\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x77\x69\x74\x74\x65\x72\x2e\x63\x6f\x6d\x2f\x6e\x69\x6c\x6c\x65\x72\x75\x73\x72" ); + AddUrlButton( this, "vgui/\x74\x65\x6c\x65\x67\x72\x61\x6d\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x2e\x6d\x65\x2f\x6e\x69\x6c\x6c\x65\x72\x75\x73\x72\x5f\x73\x6f\x75\x72\x63\x65" ); + AddUrlButton( this, "vgui/\x67\x69\x74\x68\x75\x62\x5f\x6c\x6f\x67\x6f", "\x68\x74\x74\x70\x73\x3a\x2f\x2f\x67\x69\x74\x68\x75\x62\x2e\x63\x6f\x6d\x2f\x6e\x69\x6c\x6c\x65\x72\x75\x73\x72\x2f\x73\x6f\x75\x72\x63\x65\x2d\x65\x6e\x67\x69\x6e\x65" ); } } diff --git a/gameui/GameConsole.cpp b/gameui/GameConsole.cpp index 307d091e..3d6fba55 100644 --- a/gameui/GameConsole.cpp +++ b/gameui/GameConsole.cpp @@ -66,7 +66,7 @@ void CGameConsole::Initialize() swide / 2 - offsetx, offsety, swide / 2, - stall - (offsety * 2)); + (IsAndroid() ? 0.5f : 1.f )*(stall - (offsety * 2))); m_bInitialized = true; #endif