gameui: fix console size on android

This commit is contained in:
nillerusr 2023-02-17 02:41:53 +03:00
parent 1d39be1a97
commit 30a97f855e
2 changed files with 105 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#include "materialsystem/materialsystem_config.h" #include "materialsystem/materialsystem_config.h"
#include "materialsystem/imaterialsystem.h" #include "materialsystem/imaterialsystem.h"
#include "sourcevr/isourcevirtualreality.h" #include "sourcevr/isourcevirtualreality.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
using namespace vgui; using namespace vgui;
@ -86,6 +87,10 @@ using namespace vgui;
#include "tier1/utlstring.h" #include "tier1/utlstring.h"
#include "steam/steam_api.h" #include "steam/steam_api.h"
#ifdef USE_SDL
#include <SDL_misc.h>
#endif
#undef MessageBox // Windows helpfully #define's this to MessageBoxA, we're using vgui::MessageBox #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!!! // memdbgon must be the last include file in a .cpp file!!!
@ -197,6 +202,98 @@ void CGameMenuItem::SetRightAlignedText(bool state)
m_bRightAligned = 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 // Purpose: General purpose 1 of N menu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -816,7 +913,14 @@ CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel")
m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS; m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS;
m_bSinglePlayer = false; 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" );
} }
} }

View File

@ -66,7 +66,7 @@ void CGameConsole::Initialize()
swide / 2 - offsetx, swide / 2 - offsetx,
offsety, offsety,
swide / 2, swide / 2,
stall - (offsety * 2)); (IsAndroid() ? 0.5f : 1.f )*(stall - (offsety * 2)));
m_bInitialized = true; m_bInitialized = true;
#endif #endif