Skip to content

Commit 30a97f8

Browse files
committed
gameui: fix console size on android
1 parent 1d39be1 commit 30a97f8

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

gameui/BasePanel.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "materialsystem/materialsystem_config.h"
2828
#include "materialsystem/imaterialsystem.h"
2929
#include "sourcevr/isourcevirtualreality.h"
30+
#include "VGuiMatSurface/IMatSystemSurface.h"
3031

3132
using namespace vgui;
3233

@@ -86,6 +87,10 @@ using namespace vgui;
8687
#include "tier1/utlstring.h"
8788
#include "steam/steam_api.h"
8889

90+
#ifdef USE_SDL
91+
#include <SDL_misc.h>
92+
#endif
93+
8994
#undef MessageBox // Windows helpfully #define's this to MessageBoxA, we're using vgui::MessageBox
9095

9196
// memdbgon must be the last include file in a .cpp file!!!
@@ -197,6 +202,98 @@ void CGameMenuItem::SetRightAlignedText(bool state)
197202
m_bRightAligned = state;
198203
}
199204

205+
class ImageButton : public vgui::Panel
206+
{
207+
public:
208+
ImageButton(Panel *parent, const char *imageName) : Panel(parent)
209+
{
210+
m_szUrl = NULL;
211+
212+
m_textureID = vgui::surface()->CreateNewTextureID();
213+
vgui::surface()->DrawSetTextureFile( m_textureID, imageName, true, false);
214+
m_bSelected = false;
215+
}
216+
217+
virtual void Paint()
218+
{
219+
if( GameUI().IsInLevel() ) return;
220+
221+
int color = m_bSelected ? 120 : 160;
222+
223+
vgui::surface()->DrawSetColor(color, color, color, 100);
224+
vgui::surface()->DrawFilledRect( 0, 0, GetWide(), GetTall() );
225+
vgui::surface()->DrawSetTexture( m_textureID );
226+
227+
vgui::surface()->DrawSetColor( 255, 255, 255, 255 );
228+
vgui::surface()->DrawTexturedRect( 0, 0, GetWide(), GetTall() );
229+
}
230+
231+
virtual void OnMousePressed(MouseCode code)
232+
{
233+
if( GameUI().IsInLevel() ) return;
234+
235+
m_bSelected = true;
236+
input()->SetMouseCapture(GetVPanel());
237+
}
238+
239+
virtual void OnMouseReleased(MouseCode code)
240+
{
241+
if( GameUI().IsInLevel() ) return;
242+
243+
m_bSelected = false;
244+
#ifdef USE_SDL
245+
if( m_szUrl ) SDL_OpenURL( m_szUrl );
246+
#endif
247+
248+
input()->SetMouseCapture(NULL);
249+
}
250+
251+
void SetUrl( const char *url )
252+
{
253+
m_szUrl = url;
254+
}
255+
256+
virtual void OnScreenSizeChanged( int nOldWidth, int nOldHeight )
257+
{
258+
int nw, nh;
259+
surface()->GetScreenSize(nw, nh);
260+
int scaled_w = scheme()->GetProportionalScaledValue(m_iOldW);
261+
262+
Panel::SetPos(nw-scheme()->GetProportionalScaledValue(m_iOldX)-scaled_w, m_iOldY);
263+
Panel::SetSize(scaled_w, scheme()->GetProportionalScaledValue(m_iOldH));
264+
}
265+
266+
void SetBounds( int x, int y, int w, int h )
267+
{
268+
m_iOldX = x; m_iOldY = y;
269+
m_iOldW = w; m_iOldH = h;
270+
271+
int nw, nh;
272+
surface()->GetScreenSize(nw, nh);
273+
int scaled_w = scheme()->GetProportionalScaledValue(m_iOldW);
274+
275+
Panel::SetPos(nw-scheme()->GetProportionalScaledValue(m_iOldX)-scaled_w, m_iOldY);
276+
Panel::SetSize(scaled_w, scheme()->GetProportionalScaledValue(m_iOldH));
277+
}
278+
279+
private:
280+
int m_iOldX, m_iOldY;
281+
int m_iOldW, m_iOldH;
282+
283+
bool m_bSelected;
284+
int m_textureID;
285+
const char *m_szUrl;
286+
};
287+
288+
void AddUrlButton(vgui::Panel *parent, const char *imgName, const char *url )
289+
{
290+
static int i = 0;
291+
ImageButton *panel = new ImageButton( parent, imgName );
292+
panel->SetUrl( url );
293+
panel->SetBounds( 15+i*52, 10, 48, 48 );
294+
i++;
295+
}
296+
200297
//-----------------------------------------------------------------------------
201298
// Purpose: General purpose 1 of N menu
202299
//-----------------------------------------------------------------------------
@@ -816,7 +913,14 @@ CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel")
816913
m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS;
817914
m_bSinglePlayer = false;
818915
}
916+
}
819917

918+
if( IsAndroid() )
919+
{
920+
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" );
921+
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" );
922+
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" );
923+
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" );
820924
}
821925
}
822926

gameui/GameConsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CGameConsole::Initialize()
6666
swide / 2 - offsetx,
6767
offsety,
6868
swide / 2,
69-
stall - (offsety * 2));
69+
(IsAndroid() ? 0.5f : 1.f )*(stall - (offsety * 2)));
7070

7171
m_bInitialized = true;
7272
#endif

0 commit comments

Comments
 (0)