mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-05 22:09:59 +03:00
Add proportionality support for GameUI panels (#35)
* Add proportionality support for GameUI panels * Add Android platform define * Fix button wrong state on fast clicking Co-authored-by: JusicP <slender87844@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
//========= Copyright <20> 1996-2003, Valve LLC, All rights reserved. ============
|
||||
//========= Copyright <20> 1996-2003, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
|
||||
@@ -71,7 +71,6 @@ void Button::Init()
|
||||
_keyFocusBorder = NULL;
|
||||
m_bSelectionStateSaved = false;
|
||||
m_bStaySelectedOnClick = false;
|
||||
m_bStaySelectedOnClick = false;
|
||||
m_bStayArmedOnClick = false;
|
||||
m_sArmedSoundName = UTL_INVAL_SYMBOL;
|
||||
m_sDepressedSoundName = UTL_INVAL_SYMBOL;
|
||||
@@ -140,11 +139,12 @@ void Button::SetSelected( bool state )
|
||||
InvalidateLayout(false);
|
||||
}
|
||||
|
||||
if ( !m_bStayArmedOnClick && state && _buttonFlags.IsFlagSet( ARMED ) )
|
||||
{
|
||||
_buttonFlags.SetFlag( ARMED, false );
|
||||
InvalidateLayout(false);
|
||||
}
|
||||
// Jusic: idk what is it for
|
||||
//if (!m_bStayArmedOnClick && state && _buttonFlags.IsFlagSet(ARMED))
|
||||
//{
|
||||
// _buttonFlags.SetFlag( ARMED, false );
|
||||
// InvalidateLayout(false);
|
||||
//}
|
||||
}
|
||||
|
||||
void Button::SetBlink( bool state )
|
||||
@@ -877,7 +877,11 @@ void Button::ApplySettings( KeyValues *inResourceData )
|
||||
SetReleasedSound(sound);
|
||||
}
|
||||
|
||||
_activationType = (ActivationType_t)inResourceData->GetInt( "button_activation_type", ACTIVATE_ONRELEASED );
|
||||
int iButtonActivationType = inResourceData->GetInt( "button_activation_type", -1 );
|
||||
if (iButtonActivationType != -1)
|
||||
{
|
||||
_activationType = (ActivationType_t)iButtonActivationType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1224,12 +1224,24 @@ void Frame::PerformLayout()
|
||||
// move everything into place
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
|
||||
float scale = 1;
|
||||
if (IsProportional())
|
||||
{
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize(screenW, screenH);
|
||||
|
||||
int proW, proH;
|
||||
surface()->GetProportionalBase(proW, proH);
|
||||
|
||||
scale = ((float)(screenH) / (float)(proH));
|
||||
}
|
||||
|
||||
#if !defined( _X360 )
|
||||
int DRAGGER_SIZE = GetDraggerSize();
|
||||
int CORNER_SIZE = GetCornerSize();
|
||||
int CORNER_SIZE2 = CORNER_SIZE * 2;
|
||||
int BOTTOMRIGHTSIZE = GetBottomRightSize();
|
||||
int BOTTOMRIGHTSIZE = GetBottomRightSize() * scale;
|
||||
|
||||
_topGrip->SetBounds(CORNER_SIZE, 0, wide - CORNER_SIZE2, DRAGGER_SIZE);
|
||||
_leftGrip->SetBounds(0, CORNER_SIZE, DRAGGER_SIZE, tall - CORNER_SIZE2);
|
||||
@@ -1260,18 +1272,6 @@ void Frame::PerformLayout()
|
||||
_minimizeToSysTrayButton->MoveToFront();
|
||||
_menuButton->SetBounds(5+2, 5+3, GetCaptionHeight()-5, GetCaptionHeight()-5);
|
||||
#endif
|
||||
|
||||
float scale = 1;
|
||||
if (IsProportional())
|
||||
{
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize( screenW, screenH );
|
||||
|
||||
int proW,proH;
|
||||
surface()->GetProportionalBase( proW, proH );
|
||||
|
||||
scale = ( (float)( screenH ) / (float)( proH ) );
|
||||
}
|
||||
|
||||
#if !defined( _X360 )
|
||||
int offset_start = (int)( 20 * scale );
|
||||
|
||||
@@ -90,6 +90,21 @@ void ImagePanel::SetImage(const char *imageName)
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_strncpy(m_pszImageName, imageName, len );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
|
||||
if (IsProportional() && m_pImage && !m_bScaleImage)
|
||||
{
|
||||
float scale = 1;
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize(screenW, screenH);
|
||||
|
||||
int proW, proH;
|
||||
surface()->GetProportionalBase(proW, proH);
|
||||
|
||||
scale = ((float)(screenH) / (float)(proH));
|
||||
|
||||
m_fScaleAmount = scale;
|
||||
m_bScaleImage = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -145,9 +145,15 @@ void MessageBox::ApplySchemeSettings(IScheme *pScheme)
|
||||
int wide, tall;
|
||||
m_pMessageLabel->GetContentSize(wide, tall);
|
||||
m_pMessageLabel->SetSize(wide, tall);
|
||||
|
||||
int indent = 100;
|
||||
if (IsProportional())
|
||||
{
|
||||
indent = scheme()->GetProportionalScaledValueEx(GetScheme(), 100);
|
||||
}
|
||||
|
||||
wide += 100;
|
||||
tall += 100;
|
||||
wide += indent;
|
||||
tall += indent;
|
||||
SetSize(wide, tall);
|
||||
|
||||
if ( m_bShowMessageBoxOverCursor )
|
||||
@@ -243,7 +249,7 @@ void MessageBox::ShowWindow(Frame *pFrameOver)
|
||||
// Purpose: Put the text and OK buttons in correct place
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::PerformLayout()
|
||||
{
|
||||
{
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
wide += x;
|
||||
@@ -255,38 +261,51 @@ void MessageBox::PerformLayout()
|
||||
int oldWide, oldTall;
|
||||
m_pOkButton->GetSize(oldWide, oldTall);
|
||||
|
||||
// calc proportionality scale
|
||||
float scale = 1;
|
||||
if (IsProportional())
|
||||
{
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize(screenW, screenH);
|
||||
|
||||
int proW, proH;
|
||||
surface()->GetProportionalBase(proW, proH);
|
||||
|
||||
scale = ((float)(screenH) / (float)(proH));
|
||||
}
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pOkButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
btnWide = max(oldWide, btnWide + 10 * scale);
|
||||
btnTall = max(oldTall, btnTall + 10 * scale);
|
||||
m_pOkButton->SetSize(btnWide, btnTall);
|
||||
|
||||
|
||||
int btnWide2 = 0, btnTall2 = 0;
|
||||
if ( m_pCancelButton->IsVisible() )
|
||||
{
|
||||
m_pCancelButton->GetSize(oldWide, oldTall);
|
||||
|
||||
m_pCancelButton->GetContentSize(btnWide2, btnTall2);
|
||||
btnWide2 = max(oldWide, btnWide2 + 10);
|
||||
btnTall2 = max(oldTall, btnTall2 + 10);
|
||||
m_pCancelButton->SetSize(btnWide2, btnTall2);
|
||||
btnWide2 = max(oldWide, btnWide2 + 10 * scale);
|
||||
btnTall2 = max(oldTall, btnTall2 + 10 * scale);
|
||||
m_pCancelButton->SetSize(btnWide2, boxTall);
|
||||
}
|
||||
|
||||
boxWidth = max(boxWidth, m_pMessageLabel->GetWide() + 100);
|
||||
boxWidth = max(boxWidth, (btnWide + btnWide2) * 2 + 30);
|
||||
boxWidth = max(boxWidth, m_pMessageLabel->GetWide() + 100 * scale);
|
||||
boxWidth = max(boxWidth, (btnWide + btnWide2) * 2 + 30 * scale);
|
||||
SetSize(boxWidth, boxTall);
|
||||
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
m_pMessageLabel->SetPos((wide/2)-(m_pMessageLabel->GetWide()/2) + x, y + 5 );
|
||||
m_pMessageLabel->SetPos((wide/2)-(m_pMessageLabel->GetWide()/2) + x, y + 5 * scale);
|
||||
if ( !m_pCancelButton->IsVisible() )
|
||||
{
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15);
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15 * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pOkButton->SetPos((wide/4)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15);
|
||||
m_pCancelButton->SetPos((3*wide/4)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15);
|
||||
m_pOkButton->SetPos((wide/4)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15 * scale);
|
||||
m_pCancelButton->SetPos((3*wide/4)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15 * scale);
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
@@ -115,24 +115,36 @@ void PropertyDialog::PerformLayout()
|
||||
GetClientArea(x, y, wide, tall);
|
||||
_propertySheet->SetBounds(x, y, wide, tall - iBottom);
|
||||
|
||||
// calc button size and indent for proportionality
|
||||
int iBtnWide = 72;
|
||||
int iBtnTall = 24;
|
||||
int iWideIndent = 8;
|
||||
int iTallIndent = 4;
|
||||
if (IsProportional())
|
||||
{
|
||||
iBtnWide = scheme()->GetProportionalScaledValueEx(GetScheme(), iBtnWide);
|
||||
iBtnTall = scheme()->GetProportionalScaledValueEx(GetScheme(), iBtnTall);
|
||||
iWideIndent = scheme()->GetProportionalScaledValueEx(GetScheme(), iWideIndent);
|
||||
iTallIndent = scheme()->GetProportionalScaledValueEx(GetScheme(), iTallIndent);
|
||||
}
|
||||
|
||||
// move the buttons to the bottom-right corner
|
||||
int xpos = x + wide - 80;
|
||||
int ypos = tall + y - 28;
|
||||
int xpos = x + wide - iBtnWide - iWideIndent;
|
||||
int ypos = tall + y - iBtnTall - iTallIndent;
|
||||
|
||||
if (_applyButton->IsVisible())
|
||||
{
|
||||
_applyButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
_applyButton->SetBounds(xpos, ypos, iBtnWide, iBtnTall);
|
||||
xpos -= iBtnWide + iWideIndent;
|
||||
}
|
||||
|
||||
if (_cancelButton->IsVisible())
|
||||
{
|
||||
_cancelButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
_cancelButton->SetBounds(xpos, ypos, iBtnWide, iBtnTall);
|
||||
xpos -= iBtnWide + iWideIndent;
|
||||
}
|
||||
|
||||
_okButton->SetBounds(xpos, ypos, 72, 24);
|
||||
_okButton->SetBounds(xpos, ypos, iBtnWide, iBtnTall);
|
||||
|
||||
_propertySheet->InvalidateLayout(); // tell the propertysheet to redraw!
|
||||
Repaint();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <vgui/ISurface.h>
|
||||
|
||||
#include <vgui_controls/QueryBox.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
@@ -89,10 +90,23 @@ void QueryBox::PerformLayout()
|
||||
int oldWide, oldTall;
|
||||
m_pCancelButton->GetSize(oldWide, oldTall);
|
||||
|
||||
// calc proportionality scale
|
||||
float scale = 1;
|
||||
if (IsProportional())
|
||||
{
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize(screenW, screenH);
|
||||
|
||||
int proW, proH;
|
||||
surface()->GetProportionalBase(proW, proH);
|
||||
|
||||
scale = ((float)(screenH) / (float)(proH));
|
||||
}
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pCancelButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
btnWide = max(oldWide, btnWide + 10 * scale);
|
||||
btnTall = max(oldTall, btnTall + 10 * scale);
|
||||
m_pCancelButton->SetSize(btnWide, btnTall);
|
||||
|
||||
//nt boxWidth, boxTall;
|
||||
@@ -100,8 +114,8 @@ void QueryBox::PerformLayout()
|
||||
// wide = max(wide, btnWide * 2 + 100);
|
||||
// SetSize(wide, tall);
|
||||
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide())-1 + x, tall - m_pOkButton->GetTall() - 15);
|
||||
m_pCancelButton->SetPos((wide/2) + x+16, tall - m_pCancelButton->GetTall() - 15);
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide())-1 + x, tall - m_pOkButton->GetTall() - 15 * scale);
|
||||
m_pCancelButton->SetPos((wide/2) + x+16*scale, tall - m_pCancelButton->GetTall() - 15 * scale);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -844,12 +844,24 @@ void CConsolePanel::PerformLayout()
|
||||
|
||||
if ( !m_bStatusVersion )
|
||||
{
|
||||
const int inset = 8;
|
||||
const int entryHeight = 24;
|
||||
const int topHeight = 4;
|
||||
const int entryInset = 4;
|
||||
const int submitWide = 64;
|
||||
const int submitInset = 7; // x inset to pull the submit button away from the frame grab
|
||||
float scale = 1;
|
||||
if (IsProportional())
|
||||
{
|
||||
int screenW, screenH;
|
||||
surface()->GetScreenSize(screenW, screenH);
|
||||
|
||||
int proW, proH;
|
||||
surface()->GetProportionalBase(proW, proH);
|
||||
|
||||
scale = ((float)(screenH) / (float)(proH));
|
||||
}
|
||||
|
||||
const int inset = 8 * scale;
|
||||
const int entryHeight = 24 * scale;
|
||||
const int topHeight = 4 * scale;
|
||||
const int entryInset = 4 * scale;
|
||||
const int submitWide = 64 * scale;
|
||||
const int submitInset = 7 * scale; // x inset to pull the submit button away from the frame grab
|
||||
|
||||
m_pHistory->SetPos(inset, inset + topHeight);
|
||||
m_pHistory->SetSize(wide - (inset * 2), tall - (entryInset * 2 + inset * 2 + topHeight + entryHeight));
|
||||
@@ -931,6 +943,7 @@ void CConsolePanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
m_DPrintColor = GetSchemeColor("Console.DevTextColor", pScheme);
|
||||
m_pHistory->SetFont( pScheme->GetFont( "ConsoleText", IsProportional() ) );
|
||||
m_pCompletionList->SetFont( pScheme->GetFont( "DefaultSmall", IsProportional() ) );
|
||||
m_pEntry->SetFont( pScheme->GetFont( "DefaultSmall", IsProportional() ) );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user