1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 03:56:10 +08:00

Sync with upstream (Issue #30).

Recompiled tier1 and mathlib  for all platforms will come in next commit.
This commit is contained in:
Nicholas Hastings
2016-11-30 10:01:15 -05:00
parent 98fe5b5a34
commit 3957adff10
491 changed files with 29846 additions and 10698 deletions

View File

@ -70,6 +70,8 @@ AnimationController::AnimationController(Panel *parent) : BaseClass(parent, NULL
m_sWide = g_ScriptSymbols.AddString("wide");
m_sTall = g_ScriptSymbols.AddString("tall");
m_sModelPos = g_ScriptSymbols.AddString( "model_pos" );
m_flCurrentTime = 0.0f;
}
@ -510,6 +512,34 @@ bool AnimationController::ParseScriptFile(char *pMem, int length)
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.timeDelay = (float)atof(token);
}
else if (!stricmp(token, "runeventchild"))
{
animCmd.commandType = CMD_RUNEVENTCHILD;
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token);
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token);
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.timeDelay = (float)atof(token);
}
else if (!stricmp(token, "firecommand"))
{
animCmd.commandType = CMD_FIRECOMMAND;
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.timeDelay = (float)atof(token);
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token);
}
else if (!stricmp(token, "setvisible"))
{
animCmd.commandType = CMD_SETVISIBLE;
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token);
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.variable2 = atoi(token);
pMem = ParseFile(pMem, token, NULL);
animCmd.cmdData.runEvent.timeDelay = (float)atof(token);
}
else if (!stricmp(token, "stopevent"))
{
animCmd.commandType = CMD_STOPEVENT;
@ -661,9 +691,11 @@ void AnimationController::UpdatePostedMessages(bool bRunToCompletion)
case CMD_RUNEVENT:
{
RanEvent_t curEvent;
curEvent.pParent = NULL;
curEvent.event = msg.event;
curEvent.pParent = msg.parent.Get();
curEvent.pParent = msg.parent.Get();
// run the event, but only if we haven't already run it this frame, for this parent
if (!eventsRanThisFrame.HasElement(curEvent))
{
@ -672,6 +704,37 @@ void AnimationController::UpdatePostedMessages(bool bRunToCompletion)
}
}
break;
case CMD_RUNEVENTCHILD:
{
RanEvent_t curEvent;
curEvent.pParent = NULL;
curEvent.event = msg.event;
curEvent.pParent = msg.parent.Get()->FindChildByName( g_ScriptSymbols.String(msg.variable) );
msg.parent = curEvent.pParent;
// run the event, but only if we haven't already run it this frame, for this parent
if (!eventsRanThisFrame.HasElement(curEvent))
{
eventsRanThisFrame.AddToTail(curEvent);
RunCmd_RunEvent(msg);
}
}
break;
case CMD_FIRECOMMAND:
{
msg.parent->OnCommand( g_ScriptSymbols.String(msg.variable) );
}
break;
case CMD_SETVISIBLE:
{
Panel* pPanel = msg.parent.Get()->FindChildByName( g_ScriptSymbols.String(msg.variable) );
if ( pPanel )
{
pPanel->SetVisible( msg.variable2 == 1 );
}
}
break;
case CMD_STOPEVENT:
RunCmd_StopEvent(msg);
break;
@ -948,6 +1011,63 @@ bool AnimationController::StartAnimationSequence(Panel *pWithinParent, const cha
return true;
}
//-----------------------------------------------------------------------------
// Purpose: stops an animation sequence script
//-----------------------------------------------------------------------------
bool AnimationController::StopAnimationSequence( Panel *pWithinParent, const char *sequenceName )
{
Assert( pWithinParent );
// lookup the symbol for the name
UtlSymId_t seqName = g_ScriptSymbols.Find( sequenceName );
if (seqName == UTL_INVAL_SYMBOL)
return false;
// remove the existing command from the queue
RemoveQueuedAnimationCommands( seqName, pWithinParent );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Runs a custom command from code, not from a script file
//-----------------------------------------------------------------------------
void AnimationController::CancelAnimationsForPanel( Panel *pWithinParent )
{
// Msg("Removing queued anims for sequence %s\n", g_ScriptSymbols.String(seqName));
// remove messages posted by this sequence
// if pWithinParent is specified, remove only messages under that parent
{
for (int i = 0; i < m_PostedMessages.Count(); i++)
{
if ( m_PostedMessages[i].parent == pWithinParent )
{
m_PostedMessages.Remove(i);
--i;
}
}
}
// remove all animations
// if pWithinParent is specified, remove only animations under that parent
for (int i = 0; i < m_ActiveAnimations.Count(); i++)
{
Panel *animPanel = m_ActiveAnimations[i].panel;
if ( !animPanel )
continue;
Panel *foundPanel = pWithinParent->FindChildByName(animPanel->GetName(),true);
if ( foundPanel != animPanel )
continue;
m_ActiveAnimations.Remove(i);
--i;
}
}
//-----------------------------------------------------------------------------
// Purpose: Runs a custom command from code, not from a script file
//-----------------------------------------------------------------------------

View File

@ -234,7 +234,7 @@ void ComboBox::RemoveAll()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int ComboBox::GetItemCount()
int ComboBox::GetItemCount() const
{
return m_pDropDown->GetItemCount();
}

View File

@ -26,9 +26,6 @@
using namespace vgui;
const int k_nMaxCustomCursors = 2; // the max number of custom cursors we keep cached PER html control
//-----------------------------------------------------------------------------
// Purpose: A simple passthrough panel to render the border onto the HTML widget
//-----------------------------------------------------------------------------
@ -48,54 +45,6 @@ private:
HTML *m_pHTML;
};
//-----------------------------------------------------------------------------
// Purpose: a vgui container for popup menus displayed by a control, only 1 menu for any control can be visible at a time
//-----------------------------------------------------------------------------
class HTMLComboBoxHost : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( HTMLComboBoxHost, EditablePanel );
public:
HTMLComboBoxHost( HTML *parent, const char *panelName ) : EditablePanel( parent, panelName )
{
m_pParent = parent;
MakePopup(false);
}
~HTMLComboBoxHost() {}
virtual void PaintBackground();
virtual void OnMousePressed(MouseCode code);
virtual void OnMouseReleased(MouseCode code);
virtual void OnCursorMoved(int x,int y);
virtual void OnMouseDoublePressed(MouseCode code);
virtual void OnKeyTyped(wchar_t unichar);
virtual void OnKeyCodeTyped(KeyCode code);
virtual void OnKeyCodeReleased(KeyCode code);
virtual void OnMouseWheeled(int delta);
virtual void OnKillFocus()
{
if ( vgui::input()->GetFocus() != m_pParent->GetVPanel() ) // if its not our parent trying to steal focus
{
BaseClass::OnKillFocus();
if ( m_pParent )
m_pParent->HidePopup();
}
}
virtual void PerformLayout()
{
// no op the perform layout as we just render the html controls popup texture into it
// we don't want the menu logic trying to play with its size
}
private:
HTML *m_pParent;
};
//-----------------------------------------------------------------------------
// Purpose: container class for any external popup windows the browser requests
//-----------------------------------------------------------------------------
@ -163,15 +112,12 @@ private:
//-----------------------------------------------------------------------------
HTML::HTML(Panel *parent, const char *name, bool allowJavaScript, bool bPopupWindow) : Panel(parent, name),
m_NeedsPaint( this, &HTML::BrowserNeedsPaint ),
m_ComboNeedsPaint( this, &HTML::BrowserComboNeedsPaint ),
m_StartRequest( this, &HTML::BrowserStartRequest ),
m_URLChanged( this, &HTML::BrowserURLChanged ),
m_FinishedRequest( this, &HTML::BrowserFinishedRequest ),
m_ShowPopup( this, &HTML::BrowserShowPopup ),
m_HidePopup( this, &HTML::BrowserHidePopup ),
m_SizePopup( this, &HTML::BrowserSizePopup ),
m_LinkInNewTab( this, &HTML::BrowserOpenNewTab ),
m_ChangeTitle( this, &HTML::BrowserSetHTMLTitle ),
m_NewWindow( this, &HTML::BrowserPopupHTMLWindow ),
m_FileLoadDialog( this, &HTML::BrowserFileLoadDialog ),
m_SearchResults( this, &HTML::BrowserSearchResults ),
m_CloseBrowser( this, &HTML::BrowserClose ),
@ -181,7 +127,6 @@ m_LinkAtPosResp( this, &HTML::BrowserLinkAtPositionResponse ),
m_JSAlert( this, &HTML::BrowserJSAlert ),
m_JSConfirm( this, &HTML::BrowserJSConfirm ),
m_CanGoBackForward( this, &HTML::BrowserCanGoBackandForward ),
m_NewWindow( this, &HTML::BrowserPopupHTMLWindow ),
m_SetCursor( this, &HTML::BrowserSetCursor ),
m_StatusText( this, &HTML::BrowserStatusText ),
m_ShowTooltip( this, &HTML::BrowserShowToolTip ),
@ -189,7 +134,6 @@ m_UpdateTooltip( this, &HTML::BrowserUpdateToolTip ),
m_HideTooltip( this, &HTML::BrowserHideToolTip )
{
m_iHTMLTextureID = 0;
m_iComboBoxTextureID = 0;
m_bCanGoBack = false;
m_bCanGoForward = false;
m_bInFind = false;
@ -201,7 +145,7 @@ m_HideTooltip( this, &HTML::BrowserHideToolTip )
m_pInteriorPanel = new HTMLInterior( this );
SetPostChildPaintEnabled( true );
m_unBrowserHandle = INVALID_HTTMLBROWSER;
m_unBrowserHandle = INVALID_HTMLBROWSER;
m_SteamAPIContext.Init();
if ( m_SteamAPIContext.SteamHTMLSurface() )
{
@ -233,10 +177,6 @@ m_HideTooltip( this, &HTML::BrowserHideToolTip )
m_pFindBar = new HTML::CHTMLFindBar( this );
m_pFindBar->SetZPos( 2 );
m_pFindBar->SetVisible( false );
m_pComboBoxHost = new HTMLComboBoxHost( this, "ComboBoxHost" );
m_pComboBoxHost->SetPaintBackgroundEnabled( true );
m_pComboBoxHost->SetVisible( false );
m_pContextMenu = new Menu( this, "contextmenu" );
m_pContextMenu->AddMenuItem( "#vgui_HTMLBack", new KeyValues( "Command", "command", "back" ), this );
@ -349,36 +289,6 @@ void HTML::Paint()
}
}
//-----------------------------------------------------------------------------
// Purpose: paint the combo box texture if we have one
//-----------------------------------------------------------------------------
void HTML::PaintComboBox()
{
BaseClass::Paint();
if ( m_iComboBoxTextureID != 0 )
{
surface()->DrawSetTexture( m_iComboBoxTextureID );
surface()->DrawSetColor( Color( 255, 255, 255, 255 ) );
int tw = m_allocedComboBoxWidth;
int tt = m_allocedComboBoxHeight;
surface()->DrawTexturedRect( 0, 0, tw, tt );
}
}
//-----------------------------------------------------------------------------
// Purpose: overrides panel class, paints a texture of the HTML window as a background
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::PaintBackground()
{
BaseClass::PaintBackground();
m_pParent->PaintComboBox();
}
//-----------------------------------------------------------------------------
// Purpose: causes a repaint when the layout changes
//-----------------------------------------------------------------------------
@ -431,11 +341,6 @@ void HTML::OnMove()
// tell cef where we are on the screen so plugins can correctly render
int nPanelAbsX, nPanelAbsY;
ipanel()->GetAbsPos( GetVPanel(), nPanelAbsX, nPanelAbsY );
if ( m_pComboBoxHost && m_pComboBoxHost->IsVisible() )
{
m_pComboBoxHost->SetVisible( false );
}
}
@ -452,7 +357,7 @@ void HTML::OpenURL(const char *URL, const char *postData, bool force)
//-----------------------------------------------------------------------------
void HTML::PostURL(const char *URL, const char *pchPostData, bool force)
{
if ( m_unBrowserHandle == INVALID_HTTMLBROWSER )
if ( m_unBrowserHandle == INVALID_HTMLBROWSER )
{
m_sPendingURLLoad = URL;
m_sPendingPostData = pchPostData;
@ -674,7 +579,7 @@ void HTML::OnMouseReleased(MouseCode code)
input()->SetMouseCapture( NULL );
input()->SetCursorOveride( 0 );
if ( !m_sDragURL.IsEmpty() && input()->GetMouseOver() != GetVPanel() && input()->GetMouseOver() != NULL )
if ( !m_sDragURL.IsEmpty() && input()->GetMouseOver() != GetVPanel() && input()->GetMouseOver() )
{
// post the text as a drag drop to the target panel
KeyValuesAD kv( "DragDrop" );
@ -709,7 +614,7 @@ void HTML::OnCursorMoved(int x,int y)
}
else if ( !m_sDragURL.IsEmpty() )
{
if ( input()->GetMouseOver() == NULL )
if ( !input()->GetMouseOver() )
{
// we're not over any vgui window, switch to the OS implementation of drag/drop
// BR FIXME
@ -749,18 +654,18 @@ int GetKeyModifiers()
// Any time a key is pressed reset modifier list as well
int nModifierCodes = 0;
if (vgui::input()->IsKeyDown( KEY_LCONTROL ) || vgui::input()->IsKeyDown( KEY_RCONTROL ))
nModifierCodes |= ISteamHTMLSurface::eHTMLKeyModifier_CrtlDown;
nModifierCodes |= ISteamHTMLSurface::k_eHTMLKeyModifier_CtrlDown;
if (vgui::input()->IsKeyDown( KEY_LALT ) || vgui::input()->IsKeyDown( KEY_RALT ))
nModifierCodes |= ISteamHTMLSurface::eHTMLKeyModifier_AltDown;
nModifierCodes |= ISteamHTMLSurface::k_eHTMLKeyModifier_AltDown;
if (vgui::input()->IsKeyDown( KEY_LSHIFT ) || vgui::input()->IsKeyDown( KEY_RSHIFT ))
nModifierCodes |= ISteamHTMLSurface::eHTMLKeyModifier_ShiftDown;
nModifierCodes |= ISteamHTMLSurface::k_eHTMLKeyModifier_ShiftDown;
#ifdef OSX
// for now pipe through the cmd-key to be like the control key so we get copy/paste
if (vgui::input()->IsKeyDown( KEY_LWIN ) || vgui::input()->IsKeyDown( KEY_RWIN ))
nModifierCodes |= ISteamHTMLSurface::eHTMLKeyModifier_CrtlDown;
nModifierCodes |= ISteamHTMLSurface::k_eHTMLKeyModifier_CtrlDown;
#endif
return nModifierCodes;
@ -925,8 +830,8 @@ void HTML::OnKeyCodeReleased(KeyCode code)
// Purpose: scrolls the vertical scroll bar on a web page
//-----------------------------------------------------------------------------
void HTML::OnMouseWheeled(int delta)
{
if (_vbar && ( ( m_pComboBoxHost && !m_pComboBoxHost->IsVisible() ) ) )
{
if (_vbar )
{
int val = _vbar->GetValue();
val -= (delta * 100.0/3.0 ); // 100 for every 3 lines matches chromes code
@ -954,7 +859,7 @@ void HTML::AddCustomURLHandler(const char *customProtocolName, vgui::Panel *targ
//-----------------------------------------------------------------------------
void HTML::BrowserResize()
{
if (m_unBrowserHandle == INVALID_HTTMLBROWSER)
if (m_unBrowserHandle == INVALID_HTMLBROWSER)
return;
int w,h;
@ -1120,16 +1025,12 @@ void HTML::OnSetFocus()
//-----------------------------------------------------------------------------
void HTML::OnKillFocus()
{
if ( vgui::input()->GetFocus() != m_pComboBoxHost->GetVPanel() ) // if its not the menu stealing our focus
BaseClass::OnKillFocus();
BaseClass::OnKillFocus();
// Don't clear the actual html focus if a context menu is what took focus
if ( m_pContextMenu->HasFocus() )
return;
if ( m_pComboBoxHost->HasFocus() )
return;
if (m_SteamAPIContext.SteamHTMLSurface())
m_SteamAPIContext.SteamHTMLSurface()->SetKeyFocus( m_unBrowserHandle, false );
}
@ -1279,83 +1180,6 @@ void HTML::OnTextChanged( Panel *pPanel )
Find( rgchText );
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse clicks to the control
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMousePressed(MouseCode code)
{
m_pParent->OnMousePressed(code);
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse up events
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseReleased(MouseCode code)
{
m_pParent->OnMouseReleased(code);
}
//-----------------------------------------------------------------------------
// Purpose: keeps track of where the cursor is
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnCursorMoved(int x,int y)
{
// Only do this when we are over the current panel
if ( vgui::input()->GetMouseOver() == GetVPanel() )
{
m_pParent->OnHTMLMouseMoved( x, y );
}
}
//-----------------------------------------------------------------------------
// Purpose: passes double click events to the browser
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseDoublePressed(MouseCode code)
{
m_pParent->OnMouseDoublePressed(code);
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser (we don't current do this)
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyTyped(wchar_t unichar)
{
m_pParent->OnKeyTyped(unichar);
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyCodeTyped(KeyCode code)
{
m_pParent->OnKeyCodeTyped(code);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyCodeReleased(KeyCode code)
{
m_pParent->OnKeyCodeReleased(code);
}
//-----------------------------------------------------------------------------
// Purpose: scrolls the vertical scroll bar on a web page
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseWheeled(int delta)
{
m_pParent->OnMouseWheeled( delta );
}
//-----------------------------------------------------------------------------
// Purpose: helper class for the find bar
//-----------------------------------------------------------------------------
@ -1441,43 +1265,6 @@ void HTML::BrowserNeedsPaint( HTML_NeedsPaint_t *pCallback )
Repaint();
}
//-----------------------------------------------------------------------------
// Purpose: we have a new texture to update
//-----------------------------------------------------------------------------
void HTML::BrowserComboNeedsPaint( HTML_ComboNeedsPaint_t *pCallback )
{
if ( m_pComboBoxHost->IsVisible() )
{
int tw = 0, tt = 0;
// update the combo box texture also
if ( m_iComboBoxTextureID != 0 )
{
tw = m_allocedComboBoxWidth;
tt = m_allocedComboBoxHeight;
}
if ( m_iComboBoxTextureID == 0 || tw != (int)pCallback->unWide || tt != (int)pCallback->unTall )
{
if ( m_iComboBoxTextureID != 0 )
surface()->DeleteTextureByID( m_iComboBoxTextureID );
// if the dimensions changed we also need to re-create the texture ID to support the overlay properly (it won't resize a texture on the fly, this is the only control that needs
// to so lets have a tiny bit more code here to support that)
m_iComboBoxTextureID = surface()->CreateNewTextureID( true );
surface()->DrawSetTextureRGBAEx( m_iComboBoxTextureID, (const unsigned char *)pCallback->pBGRA, pCallback->unWide, pCallback->unTall, IMAGE_FORMAT_BGRA8888 );
m_allocedComboBoxWidth = (int)pCallback->unWide;
m_allocedComboBoxHeight = (int)pCallback->unTall;
}
else
{
// same size texture, just bits changing in it, lets twiddle
surface()->DrawUpdateRegionTextureRGBA( m_iComboBoxTextureID, 0, 0, (const unsigned char *)pCallback->pBGRA, pCallback->unWide, pCallback->unTall, IMAGE_FORMAT_BGRA8888 );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: browser wants to start loading this url, do we let it?
//-----------------------------------------------------------------------------
@ -1579,45 +1366,6 @@ void HTML::BrowserFinishedRequest( HTML_FinishedRequest_t *pCmd )
OnFinishRequest( pCmd->pchURL, pCmd->pchPageTitle, mapHeaders );
}
//-----------------------------------------------------------------------------
// Purpose: show a popup dialog
//-----------------------------------------------------------------------------
void HTML::BrowserShowPopup( HTML_ShowPopup_t *pCmd )
{
m_pComboBoxHost->SetVisible( true );
}
//-----------------------------------------------------------------------------
// Purpose: hide the popup
//-----------------------------------------------------------------------------
void HTML::HidePopup()
{
m_pComboBoxHost->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Purpose: browser wants us to hide a popup
//-----------------------------------------------------------------------------
void HTML::BrowserHidePopup( HTML_HidePopup_t *pCmd )
{
HidePopup();
}
//-----------------------------------------------------------------------------
// Purpose: browser wants us to position a popup
//-----------------------------------------------------------------------------
void HTML::BrowserSizePopup( HTML_SizePopup_t *pCmd )
{
int nAbsX, nAbsY;
ipanel()->GetAbsPos( GetVPanel(), nAbsX, nAbsY );
m_pComboBoxHost->SetBounds( pCmd->unX + 1 + nAbsX, pCmd->unY+ nAbsY, pCmd->unWide, pCmd->unTall );
}
//-----------------------------------------------------------------------------
// Purpose: browser wants to open a new tab
//-----------------------------------------------------------------------------
@ -1627,9 +1375,8 @@ void HTML::BrowserOpenNewTab( HTML_OpenLinkInNewTab_t *pCmd )
// Not suppored by default, if a child class overrides us and knows how to handle tabs, then it can do this.
}
//-----------------------------------------------------------------------------
// Purpose: display a new html window
// Purpose: display a new html window
//-----------------------------------------------------------------------------
void HTML::BrowserPopupHTMLWindow( HTML_NewWindow_t *pCmd )
{

View File

@ -361,8 +361,14 @@ void Label::SetTextInset(int xInset, int yInset)
//-----------------------------------------------------------------------------
void Label::GetTextInset(int *xInset, int *yInset )
{
*xInset = _textInset[0];
*yInset = _textInset[1];
if ( xInset )
{
*xInset = _textInset[0];
}
if ( yInset )
{
*yInset = _textInset[1];
}
}
//-----------------------------------------------------------------------------

View File

@ -2107,7 +2107,7 @@ void Menu::ActivateItemByRow(int row)
//-----------------------------------------------------------------------------
// Purpose: Return the number of items currently in the menu list
//-----------------------------------------------------------------------------
int Menu::GetItemCount()
int Menu::GetItemCount() const
{
return m_MenuItems.Count();
}
@ -2701,3 +2701,33 @@ void Menu::Validate( CValidator &validator, char *pchName )
validator.Pop();
}
#endif // DBGFLAG_VALIDATE
MenuBuilder::MenuBuilder( Menu *pMenu, Panel *pActionTarget )
: m_pMenu( pMenu )
, m_pActionTarget( pActionTarget )
, m_pszLastCategory( NULL )
{}
MenuItem* MenuBuilder::AddMenuItem( const char *pszButtonText, const char *pszCommand, const char *pszCategoryName )
{
AddSepratorIfNeeded( pszCategoryName );
return m_pMenu->GetMenuItem( m_pMenu->AddMenuItem( pszButtonText, new KeyValues( pszCommand ), m_pActionTarget ) );
}
MenuItem* MenuBuilder::AddCascadingMenuItem( const char *pszButtonText, Menu *pSubMenu, const char *pszCategoryName )
{
AddSepratorIfNeeded( pszCategoryName );
return m_pMenu->GetMenuItem( m_pMenu->AddCascadingMenuItem( pszButtonText, m_pActionTarget, pSubMenu ) );
}
void MenuBuilder::AddSepratorIfNeeded( const char *pszCategoryName )
{
// Add a separator if the categories are different
if ( m_pszLastCategory && V_stricmp( pszCategoryName, m_pszLastCategory ) != 0 )
{
m_pMenu->AddSeparator();
}
m_pszLastCategory = pszCategoryName;
}

View File

@ -40,6 +40,7 @@
#include "mempool.h"
#include "filesystem.h"
#include "tier0/icommandline.h"
#include "tier0/minidump.h"
#include "tier0/vprof.h"
@ -50,7 +51,38 @@ using namespace vgui;
#define TRIPLE_PRESS_MSEC 300
const char *g_PinCornerStrings [] =
{
"PIN_TOPLEFT",
"PIN_TOPRIGHT",
"PIN_BOTTOMLEFT",
"PIN_BOTTOMRIGHT",
"PIN_CENTER_TOP",
"PIN_CENTER_RIGHT",
"PIN_CENTER_BOTTOM",
"PIN_CENTER_LEFT",
};
COMPILE_TIME_ASSERT( Panel::PIN_LAST == ARRAYSIZE( g_PinCornerStrings ) );
static const char *COM_GetModDirectory()
{
static char modDir[MAX_PATH];
if ( Q_strlen( modDir ) == 0 )
{
const char *gamedir = CommandLine()->ParmValue("-game", CommandLine()->ParmValue( "-defaultgamedir", "hl2" ) );
Q_strncpy( modDir, gamedir, sizeof(modDir) );
if ( strchr( modDir, '/' ) || strchr( modDir, '\\' ) )
{
Q_StripLastDir( modDir, sizeof(modDir) );
int dirlen = Q_strlen( modDir );
Q_strncpy( modDir, gamedir + dirlen, sizeof(modDir) - dirlen );
}
}
return modDir;
}
extern int GetBuildModeDialogCount();
static char *CopyString( const char *in )
@ -64,6 +96,13 @@ static char *CopyString( const char *in )
return n;
}
#ifdef STAGING_ONLY
ConVar tf_strict_mouse_up_events( "tf_strict_mouse_up_events", "0", FCVAR_ARCHIVE, "Only allow Mouse-Release events to happens on panels we also Mouse-Downed in" );
#endif
// Temporary convar to help debug why the MvMVictoryMannUpPanel TabContainer is sometimes way off to the left.
ConVar tf_debug_tabcontainer( "tf_debug_tabcontainer", "0", FCVAR_HIDDEN, "Spew TabContainer dimensions." );
#if defined( VGUI_USEDRAGDROP )
//-----------------------------------------------------------------------------
// Purpose:
@ -370,6 +409,8 @@ KeyBindingContextHandle_t Panel::CreateKeyBindingsContext( char const *filename,
return g_KBMgr.CreateContext( filename, pathID );
}
COMPILE_TIME_ASSERT( ( MOUSE_MIDDLE - MOUSE_LEFT ) == 2 );
Panel* Panel::m_sMousePressedPanels[] = { NULL, NULL, NULL };
//-----------------------------------------------------------------------------
// Purpose: static method
@ -722,7 +763,6 @@ void Panel::Init( int x, int y, int wide, int tall )
m_bForceStereoRenderToFrameBuffer = false;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
@ -732,7 +772,7 @@ Panel::~Panel()
if ( !m_bToolTipOverridden )
{
if ( m_pTooltips )
{
{
delete m_pTooltips;
}
}
@ -785,6 +825,13 @@ Panel::~Panel()
#if defined( VGUI_USEDRAGDROP )
delete m_pDragDrop;
#endif // VGUI_USEDRAGDROP
#if defined( VGUI_PANEL_VERIFY_DELETES )
// Zero out our vtbl pointer. This should hopefully help us catch bad guys using
// this panel after it has been deleted.
uintp *panel_vtbl = (uintp *)this;
*panel_vtbl = NULL;
#endif
}
//-----------------------------------------------------------------------------
@ -864,7 +911,7 @@ const char *Panel::GetClassName()
//-----------------------------------------------------------------------------
void Panel::SetPos(int x, int y)
{
if (!CommandLine()->FindParm("-hushasserts"))
if ( !HushAsserts() )
{
Assert( abs(x) < 32768 && abs(y) < 32768 );
}
@ -879,6 +926,26 @@ void Panel::GetPos(int &x, int &y)
ipanel()->GetPos(GetVPanel(), x, y);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int Panel::GetXPos()
{
int x,y;
GetPos( x, y );
return x;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int Panel::GetYPos()
{
int x,y;
GetPos( x, y );
return y;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@ -1063,6 +1130,15 @@ void Panel::Think()
OnThink();
}
void Panel::OnChildSettingsApplied( KeyValues *pInResourceData, Panel *pChild )
{
Panel* pParent = GetParent();
if( pParent )
{
pParent->OnChildSettingsApplied( pInResourceData, pChild );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@ -1577,7 +1653,6 @@ void Panel::CallParentFunction(KeyValues *message)
}
}
//-----------------------------------------------------------------------------
// Purpose: if set to true, panel automatically frees itself when parent is deleted
//-----------------------------------------------------------------------------
@ -1867,6 +1942,17 @@ void Panel::InternalMousePressed(int code)
}
#endif
#ifdef STAGING_ONLY
const char *pGameDir = COM_GetModDirectory();
if ( Q_stristr( pGameDir, "tf" ) )
{
if ( code >= MOUSE_LEFT && code <= MOUSE_MIDDLE )
{
m_sMousePressedPanels[ code - MOUSE_LEFT ] = this;
}
}
#endif
Panel *pMouseHandler = m_hMouseEventHandler.Get();
if ( pMouseHandler )
{
@ -2001,6 +2087,26 @@ void Panel::InternalMouseReleased(int code)
}
}
#ifdef STAGING_ONLY
const char *pGameDir = COM_GetModDirectory();
if ( Q_stristr( pGameDir, "tf" ) && tf_strict_mouse_up_events.GetBool() )
{
// Only allow mouse release events to go to panels that we also
// first clicked into
if ( code >= MOUSE_LEFT && code <= MOUSE_MIDDLE )
{
const int nIndex = code - MOUSE_LEFT;
Panel* pPressedPanel = m_sMousePressedPanels[ nIndex ];
m_sMousePressedPanels[ nIndex ] = NULL; // Clear out pressed panel
if ( pPressedPanel != this )
{
OnMouseMismatchedRelease( (MouseCode)code, pPressedPanel );
return;
}
}
}
#endif
OnMouseReleased((MouseCode)code);
}
@ -2951,6 +3057,10 @@ void Panel::OnMouseReleased(MouseCode code)
{
}
void Panel::OnMouseMismatchedRelease( MouseCode code, Panel* pPressedPanel )
{
}
void Panel::OnMouseWheeled(int delta)
{
CallParentFunction(new KeyValues("MouseWheeled", "delta", delta));
@ -4281,6 +4391,7 @@ int Panel::ComputePos( const char *pszInput, int &nPos, const int& nSize, const
const int nFlagProportionalParent = bX ? BUILDMODE_SAVE_XPOS_PROPORTIONAL_PARENT : BUILDMODE_SAVE_YPOS_PROPORTIONAL_PARENT;
int nFlags = 0;
int nPosDelta = 0;
if ( pszInput )
{
// look for alignment flags
@ -4319,7 +4430,6 @@ int Panel::ComputePos( const char *pszInput, int &nPos, const int& nSize, const
flProportion = (float)nPos / (float)nOldPos;
}
int nPosDelta = 0;
if ( nFlags & nFlagProportionalSlef )
{
nPosDelta = nSize * flPos;
@ -4348,9 +4458,40 @@ int Panel::ComputePos( const char *pszInput, int &nPos, const int& nSize, const
}
}
if ( tf_debug_tabcontainer.GetBool() && !Q_stricmp( "TabContainer", GetName() ) )
{
Msg( "TabContainer nFlags:%x nPos:%d nParentSize:%d nPosDelta:%d nSize:%d GetParent:%p (%s) pszInput:'%s'\n",
nFlags, nPos, nParentSize, nPosDelta, nSize, GetParent(), GetParent() ? GetParent()->GetName() : "??",
pszInput ? pszInput : "??" );
}
return nFlags;
}
Panel::PinCorner_e GetPinCornerFromString( const char* pszCornerName )
{
if ( pszCornerName == NULL )
{
return Panel::PIN_TOPLEFT;
}
// Optimize for all the old entries of a single digit
if ( strlen( pszCornerName ) == 1 )
{
return (Panel::PinCorner_e)atoi( pszCornerName );
}
for( int i=0; i<ARRAYSIZE( g_PinCornerStrings ); ++i )
{
if ( !Q_stricmp( g_PinCornerStrings[i], pszCornerName ) )
{
return (Panel::PinCorner_e)i;
}
}
return Panel::PIN_TOPLEFT;
}
//-----------------------------------------------------------------------------
// Purpose: Loads panel details from the resource info
//-----------------------------------------------------------------------------
@ -4622,6 +4763,19 @@ void Panel::ApplySettings(KeyValues *inResourceData)
SetName(newName);
}
// Automatically add an action signal target if one is specified. This allows for
// nested child buttons to add their distant parents as action signal targets.
int nActionSignalLevel = inResourceData->GetInt( "actionsignallevel", -1 );
if ( nActionSignalLevel != -1 )
{
Panel *pActionSignalTarget = this;
while( nActionSignalLevel-- )
{
pActionSignalTarget = pActionSignalTarget->GetParent();
}
AddActionSignalTarget( pActionSignalTarget );
}
// check to see if we need to render to the frame buffer even if
// stereo mode is trying to render all of the ui to a render target
m_bForceStereoRenderToFrameBuffer = inResourceData->GetBool( "ForceStereoRenderToFrameBuffer", false );
@ -4640,8 +4794,8 @@ void Panel::ApplySettings(KeyValues *inResourceData)
//=============================================================================
const char *pszSiblingName = inResourceData->GetString("pin_to_sibling", NULL);
PinCorner_e pinOurCornerToSibling = (PinCorner_e)inResourceData->GetInt( "pin_corner_to_sibling", PIN_TOPLEFT );
PinCorner_e pinSiblingCorner = (PinCorner_e)inResourceData->GetInt( "pin_to_sibling_corner", PIN_TOPLEFT );
PinCorner_e pinOurCornerToSibling = GetPinCornerFromString( inResourceData->GetString( "pin_corner_to_sibling", NULL ) );
PinCorner_e pinSiblingCorner = GetPinCornerFromString( inResourceData->GetString( "pin_to_sibling_corner", NULL ) );
PinToSibling( pszSiblingName, pinOurCornerToSibling, pinSiblingCorner );
@ -4680,6 +4834,8 @@ void Panel::ApplySettings(KeyValues *inResourceData)
{
SetKeyBoardInputEnabled( atoi( pKeyboardInputEnabled ) );
}
OnChildSettingsApplied( inResourceData, this );
}
//-----------------------------------------------------------------------------

View File

@ -248,7 +248,8 @@ void PanelListPanel::DeleteAllItems()
{
if ( m_DataItems[i].panel )
{
delete m_DataItems[i].panel;
m_DataItems[i].panel->MarkForDeletion();
m_DataItems[i].panel = NULL;
}
}

View File

@ -625,7 +625,7 @@ void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, con
}
else if ( m_pUpArrow )
{
m_pUpArrow->DeletePanel();
m_pUpArrow->MarkForDeletion();
m_pUpArrow = NULL;
}
@ -648,7 +648,7 @@ void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, con
}
else if ( m_pDownArrow )
{
m_pDownArrow->DeletePanel();
m_pDownArrow->MarkForDeletion();
m_pDownArrow = NULL;
}
@ -669,7 +669,7 @@ void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, con
}
else if ( m_pLine )
{
m_pLine->DeletePanel();
m_pLine->MarkForDeletion();
m_pLine = NULL;
}
@ -690,7 +690,7 @@ void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, con
}
else if ( m_pBox )
{
m_pBox->DeletePanel();
m_pBox->MarkForDeletion();
m_pBox = NULL;
}