Fix line endings. WHAMMY.
This commit is contained in:
@@ -1,441 +1,441 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Creates a HTML control
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
#include "winlite.h"
|
||||
#include "html_chrome.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "reliabletimer.h"
|
||||
#include "htmlmanager.h"
|
||||
|
||||
#include "html/htmlprotobuf.h"
|
||||
#include <html/ichromehtmlwrapper.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: owner object that gets responses from the CEF thread and dispatches them
|
||||
//-----------------------------------------------------------------------------
|
||||
class CHTMLController : public IHTMLChromeController
|
||||
{
|
||||
public:
|
||||
CHTMLController() { m_BrowserSerial = 0; m_nCefTargetFrameRate = 0; SetDefLessFunc( m_mapBrowserRequests ); SetDefLessFunc( m_mapBrowsers ); }
|
||||
~CHTMLController() {}
|
||||
|
||||
bool Init( const char *pchHTMLCacheDir, const char *pchCookiePath );
|
||||
void Shutdown();
|
||||
|
||||
void SetWebCookie( const char *pchHostname, const char *pchKey, const char *pchValue, const char *pchPath, RTime32 nExpires );
|
||||
void GetWebCookiesForURL( CUtlString *pstrValue, const char *pchURL, const char *pchName );
|
||||
void SetClientBuildID( uint64 ulBuildID );
|
||||
|
||||
bool BHasPendingMessages();
|
||||
|
||||
void CreateBrowser( IHTMLResponses *pBrowser, bool bPopupWindow, const char *pchUserAgentIdentifier );
|
||||
void RemoveBrowser( IHTMLResponses *pBrowser );
|
||||
bool RunFrame();
|
||||
|
||||
void WakeThread() { AccessHTMLWrapper().WakeThread(); }
|
||||
HTMLCommandBuffer_t *GetFreeCommandBuffer( EHTMLCommands eCmd, int iBrowser ) { return AccessHTMLWrapper().GetFreeCommandBuffer( eCmd, iBrowser ); }
|
||||
void PushCommand( HTMLCommandBuffer_t *pCmd ) { AccessHTMLWrapper().PushCommand( pCmd ); }
|
||||
|
||||
|
||||
bool GetMainThreadCommand( HTMLCommandBuffer_t **pCmd ) { return AccessHTMLWrapper().GetMainThreadCommand( pCmd ); }
|
||||
void ReleaseCommandBuffer( HTMLCommandBuffer_t *pCmd ) { AccessHTMLWrapper().ReleaseCommandBuffer( pCmd ); }
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void Validate( CValidator &validator, const char *pchName );
|
||||
bool ChromePrepareForValidate();
|
||||
bool ChromeResumeFromValidate();
|
||||
#endif
|
||||
|
||||
void SetCefThreadTargetFrameRate( uint32 nFPS );
|
||||
|
||||
private:
|
||||
// keeps track of outstanding browser create requests
|
||||
CUtlMap< uint32, IHTMLResponses *, int > m_mapBrowserRequests;
|
||||
// the next unique identifier to use when doing a browser create
|
||||
uint32 m_BrowserSerial;
|
||||
// the map of browser handles to our html panel objects, used for cef thread command dispatching
|
||||
CUtlMap< uint32, IHTMLResponses *, int > m_mapBrowsers;
|
||||
|
||||
int m_nCefTargetFrameRate;
|
||||
};
|
||||
|
||||
|
||||
static CHTMLController s_HTMLController;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHTMLController, IHTMLChromeController, CHROMEHTML_CONTROLLER_INTERFACE_VERSION, s_HTMLController );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: request the cef thread to make a new browser
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::CreateBrowser( IHTMLResponses *pBrowser, bool bPopupWindow, const char *pchUserAgentIdentifier )
|
||||
{
|
||||
m_BrowserSerial++;
|
||||
m_mapBrowserRequests.Insert( m_BrowserSerial, pBrowser );
|
||||
|
||||
CHTMLProtoBufMsg<CMsgBrowserCreate> cmd( eHTMLCommands_BrowserCreate );
|
||||
cmd.Body().set_request_id( m_BrowserSerial );
|
||||
cmd.Body().set_popup( bPopupWindow );
|
||||
cmd.Body().set_useragent( pchUserAgentIdentifier );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_BrowserCreate, -1 );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: delete a browser we have
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::RemoveBrowser( IHTMLResponses *pBrowser )
|
||||
{
|
||||
|
||||
// pull ourselves from the browser handle list as we are doing away
|
||||
FOR_EACH_MAP_FAST( m_mapBrowsers, i)
|
||||
{
|
||||
if ( m_mapBrowsers[i] == pBrowser )
|
||||
{
|
||||
// tell the cef thread this browser is going away
|
||||
CHTMLProtoBufMsg<CMsgBrowserRemove> cmd( eHTMLCommands_BrowserRemove );
|
||||
cmd.Body().set_browser_handle( pBrowser->BrowserGetIndex() );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_BrowserRemove, pBrowser->BrowserGetIndex() );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
|
||||
// now kill it
|
||||
m_mapBrowsers.RemoveAt( i );
|
||||
}
|
||||
}
|
||||
|
||||
// also remove us from pending list if in it
|
||||
FOR_EACH_MAP_FAST( m_mapBrowserRequests, i)
|
||||
{
|
||||
if ( m_mapBrowserRequests[i] == pBrowser )
|
||||
m_mapBrowserRequests.RemoveAt( i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: turn on the cef engine
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::Init( const char *pchHTMLCacheDir, const char *pchCookiePath )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeInit( pchHTMLCacheDir, pchCookiePath );
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: shutdown chrome
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::Shutdown()
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeShutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// helper macro to dispatch messages from the cef thread
|
||||
#define HTML_MSG_FUNC( eHTMLCommand, bodyType, commandFunc ) \
|
||||
case eHTMLCommand: \
|
||||
{ \
|
||||
CHTMLProtoBufMsg< bodyType > cmd( pCmd->m_eCmd ); \
|
||||
if ( !cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) ) \
|
||||
{ \
|
||||
bError = true; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
int idx = m_mapBrowsers.Find( cmd.BodyConst().browser_handle() ); \
|
||||
if ( idx != m_mapBrowsers.InvalidIndex() ) \
|
||||
{ \
|
||||
if ( m_mapBrowsers[idx] ) \
|
||||
m_mapBrowsers[idx]->commandFunc( &cmd.BodyConst() ); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: process any ipc responses we have pending
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::RunFrame()
|
||||
{
|
||||
VPROF_BUDGET( "CHTMLController::RunFrame", VPROF_BUDGETGROUP_TENFOOT );
|
||||
HTMLCommandBuffer_t *pCmd;
|
||||
bool bError = false;
|
||||
bool bDidwork = false;
|
||||
|
||||
// Paint messages are dispatched last to avoid doing excessive work on
|
||||
// the main thread when two paint messages have stacked up in the queue.
|
||||
// This could be greatly optimized by doing atomic buffer swaps instead
|
||||
// of pushing the paint updates through a queue, but this helps for now.
|
||||
// -henryg
|
||||
CUtlVector< HTMLCommandBuffer_t * > vecDeferredPaint;
|
||||
|
||||
while( GetMainThreadCommand( &pCmd ) )
|
||||
{
|
||||
bool bRelease = true;
|
||||
bDidwork = true;
|
||||
//Msg( "Got response %d\n", pCmd->m_eCmd );
|
||||
switch( pCmd->m_eCmd )
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case eHTMLCommands_BrowserCreateResponse:
|
||||
{
|
||||
CHTMLProtoBufMsg< CMsgBrowserCreateResponse > cmd( pCmd->m_eCmd );
|
||||
if ( !cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) )
|
||||
{
|
||||
bError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = m_mapBrowserRequests.Find( cmd.BodyConst().request_id() );
|
||||
if ( idx != m_mapBrowserRequests.InvalidIndex() )
|
||||
{
|
||||
m_mapBrowsers.Insert( cmd.BodyConst().browser_handle(), m_mapBrowserRequests[idx] );
|
||||
m_mapBrowserRequests[idx]->BrowserSetIndex( cmd.BodyConst().browser_handle() );
|
||||
m_mapBrowserRequests.RemoveAt( idx );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eHTMLCommands_NeedsPaint:
|
||||
{
|
||||
bRelease = false;
|
||||
vecDeferredPaint.AddToTail( pCmd );
|
||||
}
|
||||
break;
|
||||
|
||||
HTML_MSG_FUNC( eHTMLCommands_BrowserReady, CMsgBrowserReady, BrowserReady );
|
||||
HTML_MSG_FUNC( eHTMLCommands_StartRequest, CMsgStartRequest, BrowserStartRequest );
|
||||
HTML_MSG_FUNC( eHTMLCommands_URLChanged, CMsgURLChanged, BrowserURLChanged );
|
||||
HTML_MSG_FUNC( eHTMLCommands_FinishedRequest, CMsgFinishedRequest, BrowserFinishedRequest );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ShowPopup, CMsgShowPopup, BrowserShowPopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HidePopup, CMsgHidePopup, BrowserHidePopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_OpenNewTab, CMsgOpenNewTab, BrowserOpenNewTab );
|
||||
HTML_MSG_FUNC( eHTMLCommands_PopupHTMLWindow, CMsgPopupHTMLWindow, BrowserPopupHTMLWindow );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SetHTMLTitle, CMsgSetHTMLTitle, BrowserSetHTMLTitle );
|
||||
HTML_MSG_FUNC( eHTMLCommands_LoadingResource, CMsgLoadingResource, BrowserLoadingResource );
|
||||
HTML_MSG_FUNC( eHTMLCommands_StatusText, CMsgStatusText, BrowserStatusText );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SetCursor, CMsgSetCursor, BrowserSetCursor );
|
||||
HTML_MSG_FUNC( eHTMLCommands_FileLoadDialog, CMsgFileLoadDialog, BrowserFileLoadDialog );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ShowToolTip, CMsgShowToolTip, BrowserShowToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_UpdateToolTip, CMsgUpdateToolTip, BrowserUpdateToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HideToolTip, CMsgHideToolTip, BrowserHideToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SearchResults, CMsgSearchResults, BrowserSearchResults );
|
||||
HTML_MSG_FUNC( eHTMLCommands_Close, CMsgClose, BrowserClose );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetZoomResponse, CMsgGetZoomResponse, BrowserGetZoomResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HorizontalScrollBarSizeResponse, CMsgHorizontalScrollBarSizeResponse, BrowserHorizontalScrollBarSizeResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_VerticalScrollBarSizeResponse, CMsgVerticalScrollBarSizeResponse, BrowserVerticalScrollBarSizeResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_LinkAtPositionResponse, CMsgLinkAtPositionResponse, BrowserLinkAtPositionResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ZoomToElementAtPositionResponse, CMsgZoomToElementAtPositionResponse, BrowserZoomToElementAtPositionResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_JSAlert, CMsgJSAlert, BrowserJSAlert );
|
||||
HTML_MSG_FUNC( eHTMLCommands_JSConfirm, CMsgJSConfirm, BrowserJSConfirm );
|
||||
HTML_MSG_FUNC( eHTMLCommands_OpenSteamURL, CMsgOpenSteamURL, BrowserOpenSteamURL );
|
||||
HTML_MSG_FUNC( eHTMLCommands_CanGoBackandForward, CMsgCanGoBackAndForward, BrowserCanGoBackandForward );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SizePopup, CMsgSizePopup, BrowserSizePopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ScaleToValueResponse, CMsgScalePageToValueResponse, BrowserScalePageToValueResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_RequestFullScreen, CMsgRequestFullScreen, BrowserRequestFullScreen );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ExitFullScreen, CMsgExitFullScreen, BrowserExitFullScreen );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetCookiesForURLResponse, CMsgGetCookiesForURLResponse, BrowserGetCookiesForURLResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_NodeGotFocus, CMsgNodeHasFocus, BrowserNodeGotFocus );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SavePageToJPEGResponse, CMsgSavePageToJPEGResponse, BrowserSavePageToJPEGResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetFocusedNodeValueResponse, CMsgFocusedNodeTextResponse, BrowserFocusedNodeValueResponse );
|
||||
}
|
||||
if ( bError )
|
||||
{
|
||||
Warning( "Failed to parse command %d", pCmd->m_eCmd );
|
||||
Assert( !"Bad Command" );
|
||||
}
|
||||
if ( bRelease )
|
||||
{
|
||||
ReleaseCommandBuffer( pCmd );
|
||||
}
|
||||
}
|
||||
|
||||
// Collapse deferred paints by browser ID and process them; the latest texture always
|
||||
// has fully updated bits, we simply union its dirty rect with the skipped updates.
|
||||
// Note: browser resizes always include a full dirty rect, we don't have to check here.
|
||||
while ( vecDeferredPaint.Count() )
|
||||
{
|
||||
// Pull the last paint off the queue
|
||||
pCmd = vecDeferredPaint[ vecDeferredPaint.Count() - 1 ];
|
||||
int iBrowser = pCmd->m_iBrowser;
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaint> cmd( eHTMLCommands_NeedsPaint );
|
||||
DbgVerify( cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) );
|
||||
ReleaseCommandBuffer( pCmd );
|
||||
vecDeferredPaint.Remove( vecDeferredPaint.Count() - 1 );
|
||||
|
||||
|
||||
CMsgNeedsPaint &body = cmd.Body();
|
||||
CChromeUpdateRegion region;
|
||||
if ( body.updatewide() && body.updatetall() )
|
||||
{
|
||||
region.MarkDirtyRect( body.updatex(), body.updatey(), body.updatex() + body.updatewide(), body.updatey() + body.updatetall() );
|
||||
}
|
||||
else
|
||||
{
|
||||
region.MarkAllDirty();
|
||||
}
|
||||
|
||||
// Remove earlier paints for the same browser from the queue
|
||||
for ( int i = vecDeferredPaint.Count() - 1; i >= 0; --i )
|
||||
{
|
||||
if ( vecDeferredPaint[i]->m_iBrowser == iBrowser )
|
||||
{
|
||||
// Decode
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaint> cmdMerge( eHTMLCommands_NeedsPaint );
|
||||
DbgVerify( cmdMerge.BDeserializeCrossProc( &vecDeferredPaint[i]->m_Buffer ) );
|
||||
CMsgNeedsPaint &bodyMerge = cmdMerge.Body();
|
||||
|
||||
if ( body.browser_handle() == bodyMerge.browser_handle() )
|
||||
{
|
||||
ReleaseCommandBuffer( vecDeferredPaint[i] );
|
||||
vecDeferredPaint.Remove( i );
|
||||
|
||||
// Merge update region
|
||||
if ( bodyMerge.updatewide() && bodyMerge.updatetall() )
|
||||
{
|
||||
region.MarkDirtyRect( bodyMerge.updatex(), bodyMerge.updatey(), bodyMerge.updatex() + bodyMerge.updatewide(), bodyMerge.updatey() + bodyMerge.updatetall() );
|
||||
}
|
||||
else
|
||||
{
|
||||
region.MarkAllDirty();
|
||||
}
|
||||
|
||||
// Send response to the skipped paint update to free up the texture slot
|
||||
pCmd = GetFreeCommandBuffer( eHTMLCommands_NeedsPaintResponse, bodyMerge.browser_handle() );
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaintResponse> cmdResponse( eHTMLCommands_NeedsPaintResponse );
|
||||
cmdResponse.Body().set_browser_handle( bodyMerge.browser_handle() );
|
||||
cmdResponse.Body().set_textureid( bodyMerge.textureid() );
|
||||
cmdResponse.SerializeCrossProc( &pCmd->m_Buffer );
|
||||
PushCommand( pCmd );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch the merged update
|
||||
int idxBrowser = m_mapBrowsers.Find( body.browser_handle() );
|
||||
if ( idxBrowser != m_mapBrowsers.InvalidIndex() )
|
||||
{
|
||||
if ( m_mapBrowsers[idxBrowser] )
|
||||
{
|
||||
int updateWide = region.GetUpdateWide( body.wide() );
|
||||
int updateTall = region.GetUpdateTall( body.tall() );
|
||||
if ( updateWide != body.wide() || updateTall != body.tall() )
|
||||
{
|
||||
body.set_updatex( region.GetUpdateX( body.wide() ) );
|
||||
body.set_updatey( region.GetUpdateY( body.tall() ) );
|
||||
body.set_updatewide( updateWide );
|
||||
body.set_updatetall( updateTall );
|
||||
}
|
||||
else
|
||||
{
|
||||
body.clear_updatex();
|
||||
body.clear_updatey();
|
||||
body.clear_updatewide();
|
||||
body.clear_updatetall();
|
||||
}
|
||||
m_mapBrowsers[idxBrowser]->BrowserNeedsPaint( &body );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bDidwork;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set a cef cookie
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetWebCookie( const char *pchHostname, const char *pchKey, const char *pchValue, const char *pchPath, RTime32 nExpires )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeSetWebCookie( pchHostname, pchKey, pchValue, pchPath, nExpires );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set the buildid to report
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetClientBuildID( uint64 ulBuildID )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeSetClientBuildID( ulBuildID );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get the cef cookies for a url
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::GetWebCookiesForURL( CUtlString *pstrValue, const char *pchURL, const char *pchName )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeGetWebCookiesForURL( pstrValue, pchURL, pchName );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: true if any pending html message in the queue
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::BHasPendingMessages()
|
||||
{
|
||||
return AccessHTMLWrapper().BHasPendingMessages();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: tell the cef thread the frame rate to use if it changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetCefThreadTargetFrameRate( uint32 nFPS )
|
||||
{
|
||||
if ( nFPS != m_nCefTargetFrameRate )
|
||||
{
|
||||
m_nCefTargetFrameRate = nFPS;
|
||||
CHTMLProtoBufMsg<CMsgSetTargetFrameRate> cmd( eHTMLCommands_SetTargetFrameRate );
|
||||
cmd.Body().set_ntargetframerate( nFPS );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_SetTargetFrameRate, -1 );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: validate mem
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::Validate( CValidator &validator, const char *pchName )
|
||||
{
|
||||
ChromeValidate( validator, "ChromeValidate" );
|
||||
|
||||
validator.Push( "CHTMLController::ValidateStatics", NULL, pchName );
|
||||
ValidateObj( m_mapBrowserRequests );
|
||||
ValidateObj( m_mapBrowsers );
|
||||
validator.Pop();
|
||||
}
|
||||
|
||||
bool CHTMLController::ChromeResumeFromValidate()
|
||||
{
|
||||
return ::ChromeResumeFromValidate();
|
||||
}
|
||||
|
||||
bool CHTMLController::ChromePrepareForValidate()
|
||||
{
|
||||
return ::ChromePrepareForValidate();
|
||||
}
|
||||
#endif // DBGFLAG_VALIDATE
|
||||
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Creates a HTML control
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
#include "winlite.h"
|
||||
#include "html_chrome.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "reliabletimer.h"
|
||||
#include "htmlmanager.h"
|
||||
|
||||
#include "html/htmlprotobuf.h"
|
||||
#include <html/ichromehtmlwrapper.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: owner object that gets responses from the CEF thread and dispatches them
|
||||
//-----------------------------------------------------------------------------
|
||||
class CHTMLController : public IHTMLChromeController
|
||||
{
|
||||
public:
|
||||
CHTMLController() { m_BrowserSerial = 0; m_nCefTargetFrameRate = 0; SetDefLessFunc( m_mapBrowserRequests ); SetDefLessFunc( m_mapBrowsers ); }
|
||||
~CHTMLController() {}
|
||||
|
||||
bool Init( const char *pchHTMLCacheDir, const char *pchCookiePath );
|
||||
void Shutdown();
|
||||
|
||||
void SetWebCookie( const char *pchHostname, const char *pchKey, const char *pchValue, const char *pchPath, RTime32 nExpires );
|
||||
void GetWebCookiesForURL( CUtlString *pstrValue, const char *pchURL, const char *pchName );
|
||||
void SetClientBuildID( uint64 ulBuildID );
|
||||
|
||||
bool BHasPendingMessages();
|
||||
|
||||
void CreateBrowser( IHTMLResponses *pBrowser, bool bPopupWindow, const char *pchUserAgentIdentifier );
|
||||
void RemoveBrowser( IHTMLResponses *pBrowser );
|
||||
bool RunFrame();
|
||||
|
||||
void WakeThread() { AccessHTMLWrapper().WakeThread(); }
|
||||
HTMLCommandBuffer_t *GetFreeCommandBuffer( EHTMLCommands eCmd, int iBrowser ) { return AccessHTMLWrapper().GetFreeCommandBuffer( eCmd, iBrowser ); }
|
||||
void PushCommand( HTMLCommandBuffer_t *pCmd ) { AccessHTMLWrapper().PushCommand( pCmd ); }
|
||||
|
||||
|
||||
bool GetMainThreadCommand( HTMLCommandBuffer_t **pCmd ) { return AccessHTMLWrapper().GetMainThreadCommand( pCmd ); }
|
||||
void ReleaseCommandBuffer( HTMLCommandBuffer_t *pCmd ) { AccessHTMLWrapper().ReleaseCommandBuffer( pCmd ); }
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void Validate( CValidator &validator, const char *pchName );
|
||||
bool ChromePrepareForValidate();
|
||||
bool ChromeResumeFromValidate();
|
||||
#endif
|
||||
|
||||
void SetCefThreadTargetFrameRate( uint32 nFPS );
|
||||
|
||||
private:
|
||||
// keeps track of outstanding browser create requests
|
||||
CUtlMap< uint32, IHTMLResponses *, int > m_mapBrowserRequests;
|
||||
// the next unique identifier to use when doing a browser create
|
||||
uint32 m_BrowserSerial;
|
||||
// the map of browser handles to our html panel objects, used for cef thread command dispatching
|
||||
CUtlMap< uint32, IHTMLResponses *, int > m_mapBrowsers;
|
||||
|
||||
int m_nCefTargetFrameRate;
|
||||
};
|
||||
|
||||
|
||||
static CHTMLController s_HTMLController;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHTMLController, IHTMLChromeController, CHROMEHTML_CONTROLLER_INTERFACE_VERSION, s_HTMLController );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: request the cef thread to make a new browser
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::CreateBrowser( IHTMLResponses *pBrowser, bool bPopupWindow, const char *pchUserAgentIdentifier )
|
||||
{
|
||||
m_BrowserSerial++;
|
||||
m_mapBrowserRequests.Insert( m_BrowserSerial, pBrowser );
|
||||
|
||||
CHTMLProtoBufMsg<CMsgBrowserCreate> cmd( eHTMLCommands_BrowserCreate );
|
||||
cmd.Body().set_request_id( m_BrowserSerial );
|
||||
cmd.Body().set_popup( bPopupWindow );
|
||||
cmd.Body().set_useragent( pchUserAgentIdentifier );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_BrowserCreate, -1 );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: delete a browser we have
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::RemoveBrowser( IHTMLResponses *pBrowser )
|
||||
{
|
||||
|
||||
// pull ourselves from the browser handle list as we are doing away
|
||||
FOR_EACH_MAP_FAST( m_mapBrowsers, i)
|
||||
{
|
||||
if ( m_mapBrowsers[i] == pBrowser )
|
||||
{
|
||||
// tell the cef thread this browser is going away
|
||||
CHTMLProtoBufMsg<CMsgBrowserRemove> cmd( eHTMLCommands_BrowserRemove );
|
||||
cmd.Body().set_browser_handle( pBrowser->BrowserGetIndex() );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_BrowserRemove, pBrowser->BrowserGetIndex() );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
|
||||
// now kill it
|
||||
m_mapBrowsers.RemoveAt( i );
|
||||
}
|
||||
}
|
||||
|
||||
// also remove us from pending list if in it
|
||||
FOR_EACH_MAP_FAST( m_mapBrowserRequests, i)
|
||||
{
|
||||
if ( m_mapBrowserRequests[i] == pBrowser )
|
||||
m_mapBrowserRequests.RemoveAt( i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: turn on the cef engine
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::Init( const char *pchHTMLCacheDir, const char *pchCookiePath )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeInit( pchHTMLCacheDir, pchCookiePath );
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: shutdown chrome
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::Shutdown()
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeShutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// helper macro to dispatch messages from the cef thread
|
||||
#define HTML_MSG_FUNC( eHTMLCommand, bodyType, commandFunc ) \
|
||||
case eHTMLCommand: \
|
||||
{ \
|
||||
CHTMLProtoBufMsg< bodyType > cmd( pCmd->m_eCmd ); \
|
||||
if ( !cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) ) \
|
||||
{ \
|
||||
bError = true; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
int idx = m_mapBrowsers.Find( cmd.BodyConst().browser_handle() ); \
|
||||
if ( idx != m_mapBrowsers.InvalidIndex() ) \
|
||||
{ \
|
||||
if ( m_mapBrowsers[idx] ) \
|
||||
m_mapBrowsers[idx]->commandFunc( &cmd.BodyConst() ); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: process any ipc responses we have pending
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::RunFrame()
|
||||
{
|
||||
VPROF_BUDGET( "CHTMLController::RunFrame", VPROF_BUDGETGROUP_TENFOOT );
|
||||
HTMLCommandBuffer_t *pCmd;
|
||||
bool bError = false;
|
||||
bool bDidwork = false;
|
||||
|
||||
// Paint messages are dispatched last to avoid doing excessive work on
|
||||
// the main thread when two paint messages have stacked up in the queue.
|
||||
// This could be greatly optimized by doing atomic buffer swaps instead
|
||||
// of pushing the paint updates through a queue, but this helps for now.
|
||||
// -henryg
|
||||
CUtlVector< HTMLCommandBuffer_t * > vecDeferredPaint;
|
||||
|
||||
while( GetMainThreadCommand( &pCmd ) )
|
||||
{
|
||||
bool bRelease = true;
|
||||
bDidwork = true;
|
||||
//Msg( "Got response %d\n", pCmd->m_eCmd );
|
||||
switch( pCmd->m_eCmd )
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case eHTMLCommands_BrowserCreateResponse:
|
||||
{
|
||||
CHTMLProtoBufMsg< CMsgBrowserCreateResponse > cmd( pCmd->m_eCmd );
|
||||
if ( !cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) )
|
||||
{
|
||||
bError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = m_mapBrowserRequests.Find( cmd.BodyConst().request_id() );
|
||||
if ( idx != m_mapBrowserRequests.InvalidIndex() )
|
||||
{
|
||||
m_mapBrowsers.Insert( cmd.BodyConst().browser_handle(), m_mapBrowserRequests[idx] );
|
||||
m_mapBrowserRequests[idx]->BrowserSetIndex( cmd.BodyConst().browser_handle() );
|
||||
m_mapBrowserRequests.RemoveAt( idx );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eHTMLCommands_NeedsPaint:
|
||||
{
|
||||
bRelease = false;
|
||||
vecDeferredPaint.AddToTail( pCmd );
|
||||
}
|
||||
break;
|
||||
|
||||
HTML_MSG_FUNC( eHTMLCommands_BrowserReady, CMsgBrowserReady, BrowserReady );
|
||||
HTML_MSG_FUNC( eHTMLCommands_StartRequest, CMsgStartRequest, BrowserStartRequest );
|
||||
HTML_MSG_FUNC( eHTMLCommands_URLChanged, CMsgURLChanged, BrowserURLChanged );
|
||||
HTML_MSG_FUNC( eHTMLCommands_FinishedRequest, CMsgFinishedRequest, BrowserFinishedRequest );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ShowPopup, CMsgShowPopup, BrowserShowPopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HidePopup, CMsgHidePopup, BrowserHidePopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_OpenNewTab, CMsgOpenNewTab, BrowserOpenNewTab );
|
||||
HTML_MSG_FUNC( eHTMLCommands_PopupHTMLWindow, CMsgPopupHTMLWindow, BrowserPopupHTMLWindow );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SetHTMLTitle, CMsgSetHTMLTitle, BrowserSetHTMLTitle );
|
||||
HTML_MSG_FUNC( eHTMLCommands_LoadingResource, CMsgLoadingResource, BrowserLoadingResource );
|
||||
HTML_MSG_FUNC( eHTMLCommands_StatusText, CMsgStatusText, BrowserStatusText );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SetCursor, CMsgSetCursor, BrowserSetCursor );
|
||||
HTML_MSG_FUNC( eHTMLCommands_FileLoadDialog, CMsgFileLoadDialog, BrowserFileLoadDialog );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ShowToolTip, CMsgShowToolTip, BrowserShowToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_UpdateToolTip, CMsgUpdateToolTip, BrowserUpdateToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HideToolTip, CMsgHideToolTip, BrowserHideToolTip );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SearchResults, CMsgSearchResults, BrowserSearchResults );
|
||||
HTML_MSG_FUNC( eHTMLCommands_Close, CMsgClose, BrowserClose );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetZoomResponse, CMsgGetZoomResponse, BrowserGetZoomResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_HorizontalScrollBarSizeResponse, CMsgHorizontalScrollBarSizeResponse, BrowserHorizontalScrollBarSizeResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_VerticalScrollBarSizeResponse, CMsgVerticalScrollBarSizeResponse, BrowserVerticalScrollBarSizeResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_LinkAtPositionResponse, CMsgLinkAtPositionResponse, BrowserLinkAtPositionResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ZoomToElementAtPositionResponse, CMsgZoomToElementAtPositionResponse, BrowserZoomToElementAtPositionResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_JSAlert, CMsgJSAlert, BrowserJSAlert );
|
||||
HTML_MSG_FUNC( eHTMLCommands_JSConfirm, CMsgJSConfirm, BrowserJSConfirm );
|
||||
HTML_MSG_FUNC( eHTMLCommands_OpenSteamURL, CMsgOpenSteamURL, BrowserOpenSteamURL );
|
||||
HTML_MSG_FUNC( eHTMLCommands_CanGoBackandForward, CMsgCanGoBackAndForward, BrowserCanGoBackandForward );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SizePopup, CMsgSizePopup, BrowserSizePopup );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ScaleToValueResponse, CMsgScalePageToValueResponse, BrowserScalePageToValueResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_RequestFullScreen, CMsgRequestFullScreen, BrowserRequestFullScreen );
|
||||
HTML_MSG_FUNC( eHTMLCommands_ExitFullScreen, CMsgExitFullScreen, BrowserExitFullScreen );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetCookiesForURLResponse, CMsgGetCookiesForURLResponse, BrowserGetCookiesForURLResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_NodeGotFocus, CMsgNodeHasFocus, BrowserNodeGotFocus );
|
||||
HTML_MSG_FUNC( eHTMLCommands_SavePageToJPEGResponse, CMsgSavePageToJPEGResponse, BrowserSavePageToJPEGResponse );
|
||||
HTML_MSG_FUNC( eHTMLCommands_GetFocusedNodeValueResponse, CMsgFocusedNodeTextResponse, BrowserFocusedNodeValueResponse );
|
||||
}
|
||||
if ( bError )
|
||||
{
|
||||
Warning( "Failed to parse command %d", pCmd->m_eCmd );
|
||||
Assert( !"Bad Command" );
|
||||
}
|
||||
if ( bRelease )
|
||||
{
|
||||
ReleaseCommandBuffer( pCmd );
|
||||
}
|
||||
}
|
||||
|
||||
// Collapse deferred paints by browser ID and process them; the latest texture always
|
||||
// has fully updated bits, we simply union its dirty rect with the skipped updates.
|
||||
// Note: browser resizes always include a full dirty rect, we don't have to check here.
|
||||
while ( vecDeferredPaint.Count() )
|
||||
{
|
||||
// Pull the last paint off the queue
|
||||
pCmd = vecDeferredPaint[ vecDeferredPaint.Count() - 1 ];
|
||||
int iBrowser = pCmd->m_iBrowser;
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaint> cmd( eHTMLCommands_NeedsPaint );
|
||||
DbgVerify( cmd.BDeserializeCrossProc( &pCmd->m_Buffer ) );
|
||||
ReleaseCommandBuffer( pCmd );
|
||||
vecDeferredPaint.Remove( vecDeferredPaint.Count() - 1 );
|
||||
|
||||
|
||||
CMsgNeedsPaint &body = cmd.Body();
|
||||
CChromeUpdateRegion region;
|
||||
if ( body.updatewide() && body.updatetall() )
|
||||
{
|
||||
region.MarkDirtyRect( body.updatex(), body.updatey(), body.updatex() + body.updatewide(), body.updatey() + body.updatetall() );
|
||||
}
|
||||
else
|
||||
{
|
||||
region.MarkAllDirty();
|
||||
}
|
||||
|
||||
// Remove earlier paints for the same browser from the queue
|
||||
for ( int i = vecDeferredPaint.Count() - 1; i >= 0; --i )
|
||||
{
|
||||
if ( vecDeferredPaint[i]->m_iBrowser == iBrowser )
|
||||
{
|
||||
// Decode
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaint> cmdMerge( eHTMLCommands_NeedsPaint );
|
||||
DbgVerify( cmdMerge.BDeserializeCrossProc( &vecDeferredPaint[i]->m_Buffer ) );
|
||||
CMsgNeedsPaint &bodyMerge = cmdMerge.Body();
|
||||
|
||||
if ( body.browser_handle() == bodyMerge.browser_handle() )
|
||||
{
|
||||
ReleaseCommandBuffer( vecDeferredPaint[i] );
|
||||
vecDeferredPaint.Remove( i );
|
||||
|
||||
// Merge update region
|
||||
if ( bodyMerge.updatewide() && bodyMerge.updatetall() )
|
||||
{
|
||||
region.MarkDirtyRect( bodyMerge.updatex(), bodyMerge.updatey(), bodyMerge.updatex() + bodyMerge.updatewide(), bodyMerge.updatey() + bodyMerge.updatetall() );
|
||||
}
|
||||
else
|
||||
{
|
||||
region.MarkAllDirty();
|
||||
}
|
||||
|
||||
// Send response to the skipped paint update to free up the texture slot
|
||||
pCmd = GetFreeCommandBuffer( eHTMLCommands_NeedsPaintResponse, bodyMerge.browser_handle() );
|
||||
CHTMLProtoBufMsg<CMsgNeedsPaintResponse> cmdResponse( eHTMLCommands_NeedsPaintResponse );
|
||||
cmdResponse.Body().set_browser_handle( bodyMerge.browser_handle() );
|
||||
cmdResponse.Body().set_textureid( bodyMerge.textureid() );
|
||||
cmdResponse.SerializeCrossProc( &pCmd->m_Buffer );
|
||||
PushCommand( pCmd );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch the merged update
|
||||
int idxBrowser = m_mapBrowsers.Find( body.browser_handle() );
|
||||
if ( idxBrowser != m_mapBrowsers.InvalidIndex() )
|
||||
{
|
||||
if ( m_mapBrowsers[idxBrowser] )
|
||||
{
|
||||
int updateWide = region.GetUpdateWide( body.wide() );
|
||||
int updateTall = region.GetUpdateTall( body.tall() );
|
||||
if ( updateWide != body.wide() || updateTall != body.tall() )
|
||||
{
|
||||
body.set_updatex( region.GetUpdateX( body.wide() ) );
|
||||
body.set_updatey( region.GetUpdateY( body.tall() ) );
|
||||
body.set_updatewide( updateWide );
|
||||
body.set_updatetall( updateTall );
|
||||
}
|
||||
else
|
||||
{
|
||||
body.clear_updatex();
|
||||
body.clear_updatey();
|
||||
body.clear_updatewide();
|
||||
body.clear_updatetall();
|
||||
}
|
||||
m_mapBrowsers[idxBrowser]->BrowserNeedsPaint( &body );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bDidwork;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set a cef cookie
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetWebCookie( const char *pchHostname, const char *pchKey, const char *pchValue, const char *pchPath, RTime32 nExpires )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeSetWebCookie( pchHostname, pchKey, pchValue, pchPath, nExpires );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set the buildid to report
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetClientBuildID( uint64 ulBuildID )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeSetClientBuildID( ulBuildID );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get the cef cookies for a url
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::GetWebCookiesForURL( CUtlString *pstrValue, const char *pchURL, const char *pchName )
|
||||
{
|
||||
#if !defined(WIN64) && !defined(STATIC_TIER0)
|
||||
ChromeGetWebCookiesForURL( pstrValue, pchURL, pchName );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: true if any pending html message in the queue
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CHTMLController::BHasPendingMessages()
|
||||
{
|
||||
return AccessHTMLWrapper().BHasPendingMessages();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: tell the cef thread the frame rate to use if it changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::SetCefThreadTargetFrameRate( uint32 nFPS )
|
||||
{
|
||||
if ( nFPS != m_nCefTargetFrameRate )
|
||||
{
|
||||
m_nCefTargetFrameRate = nFPS;
|
||||
CHTMLProtoBufMsg<CMsgSetTargetFrameRate> cmd( eHTMLCommands_SetTargetFrameRate );
|
||||
cmd.Body().set_ntargetframerate( nFPS );
|
||||
HTMLCommandBuffer_t *pBuf = AccessHTMLWrapper().GetFreeCommandBuffer( eHTMLCommands_SetTargetFrameRate, -1 );
|
||||
cmd.SerializeCrossProc( &pBuf->m_Buffer );
|
||||
AccessHTMLWrapper().PushCommand( pBuf );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: validate mem
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLController::Validate( CValidator &validator, const char *pchName )
|
||||
{
|
||||
ChromeValidate( validator, "ChromeValidate" );
|
||||
|
||||
validator.Push( "CHTMLController::ValidateStatics", NULL, pchName );
|
||||
ValidateObj( m_mapBrowserRequests );
|
||||
ValidateObj( m_mapBrowsers );
|
||||
validator.Pop();
|
||||
}
|
||||
|
||||
bool CHTMLController::ChromeResumeFromValidate()
|
||||
{
|
||||
return ::ChromeResumeFromValidate();
|
||||
}
|
||||
|
||||
bool CHTMLController::ChromePrepareForValidate()
|
||||
{
|
||||
return ::ChromePrepareForValidate();
|
||||
}
|
||||
#endif // DBGFLAG_VALIDATE
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,30 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef HTMLMANAGER_H
|
||||
#define HTMLMANAGER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: helper funcs to pump chrome
|
||||
//-----------------------------------------------------------------------------
|
||||
void ChromeInit( const char *pchHTMLCacheDir, const char *pchCookiePath );
|
||||
void ChromeShutdown();
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void ChromeValidate( CValidator &validator, const char *pchName );
|
||||
bool ChromeResumeFromValidate();
|
||||
bool ChromePrepareForValidate();
|
||||
#endif
|
||||
|
||||
bool ChromeSetWebCookie( const char *pchHostname, const char *pchName, const char *pchValue, const char *pchPath );
|
||||
void ChromeSetClientBuildID( uint64 ulBuildID );
|
||||
|
||||
enum EMouseState { UP,DOWN,MOVE,DBLCLICK };
|
||||
|
||||
#endif // HTMLMANAGER_H
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef HTMLMANAGER_H
|
||||
#define HTMLMANAGER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: helper funcs to pump chrome
|
||||
//-----------------------------------------------------------------------------
|
||||
void ChromeInit( const char *pchHTMLCacheDir, const char *pchCookiePath );
|
||||
void ChromeShutdown();
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void ChromeValidate( CValidator &validator, const char *pchName );
|
||||
bool ChromeResumeFromValidate();
|
||||
bool ChromePrepareForValidate();
|
||||
#endif
|
||||
|
||||
bool ChromeSetWebCookie( const char *pchHostname, const char *pchName, const char *pchValue, const char *pchPath );
|
||||
void ChromeSetClientBuildID( uint64 ulBuildID );
|
||||
|
||||
enum EMouseState { UP,DOWN,MOVE,DBLCLICK };
|
||||
|
||||
#endif // HTMLMANAGER_H
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
#ifndef STDAFX_H
|
||||
#define STDAFX_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "tier1/utlarray.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "fileio.h"
|
||||
//#include "constants.h"
|
||||
#include "steam/steamtypes.h"
|
||||
#include "tier0/validator.h"
|
||||
#include "tier1/utlmap.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier0/tslist.h"
|
||||
#include "html/ihtmlchrome.h"
|
||||
#include "html/htmlprotobuf.h"
|
||||
|
||||
#endif
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
#ifndef STDAFX_H
|
||||
#define STDAFX_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "tier1/utlarray.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "fileio.h"
|
||||
//#include "constants.h"
|
||||
#include "steam/steamtypes.h"
|
||||
#include "tier0/validator.h"
|
||||
#include "tier1/utlmap.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier0/tslist.h"
|
||||
#include "html/ihtmlchrome.h"
|
||||
#include "html/htmlprotobuf.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#if defined( WIN32 ) && !defined( _X360 )
|
||||
#include <wtypes.h>
|
||||
#include <winuser.h>
|
||||
#include "xbox/xboxstubs.h"
|
||||
#endif
|
||||
#include "tier0/dbg.h"
|
||||
#include "vgui_key_translation.h"
|
||||
#if defined( _X360 )
|
||||
#include "xbox/xbox_win32stubs.h"
|
||||
#endif
|
||||
#ifdef POSIX
|
||||
#define VK_RETURN -1
|
||||
#endif
|
||||
|
||||
#include "tier2/tier2.h"
|
||||
#include "inputsystem/iinputsystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return KEY_NONE;
|
||||
return g_pInputSystem->VirtualKeyToButtonCode( key );
|
||||
}
|
||||
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode code )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return VK_RETURN;
|
||||
|
||||
return g_pInputSystem->ButtonCodeToVirtualKey( code );
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#if defined( WIN32 ) && !defined( _X360 )
|
||||
#include <wtypes.h>
|
||||
#include <winuser.h>
|
||||
#include "xbox/xboxstubs.h"
|
||||
#endif
|
||||
#include "tier0/dbg.h"
|
||||
#include "vgui_key_translation.h"
|
||||
#if defined( _X360 )
|
||||
#include "xbox/xbox_win32stubs.h"
|
||||
#endif
|
||||
#ifdef POSIX
|
||||
#define VK_RETURN -1
|
||||
#endif
|
||||
|
||||
#include "tier2/tier2.h"
|
||||
#include "inputsystem/iinputsystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return KEY_NONE;
|
||||
return g_pInputSystem->VirtualKeyToButtonCode( key );
|
||||
}
|
||||
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode code )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return VK_RETURN;
|
||||
|
||||
return g_pInputSystem->ButtonCodeToVirtualKey( code );
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VGUI_KEY_TRANSLATION_H
|
||||
#define VGUI_KEY_TRANSLATION_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
// Convert from Windows scan codes to VGUI key codes.
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key );
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode keycode );
|
||||
|
||||
|
||||
#endif // VGUI_KEY_TRANSLATION_H
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VGUI_KEY_TRANSLATION_H
|
||||
#define VGUI_KEY_TRANSLATION_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
// Convert from Windows scan codes to VGUI key codes.
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key );
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode keycode );
|
||||
|
||||
|
||||
#endif // VGUI_KEY_TRANSLATION_H
|
||||
|
||||
@@ -1,460 +1,460 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/AnalogBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( AnalogBar );
|
||||
|
||||
|
||||
#define ANALOG_BAR_HOME_SIZE 4
|
||||
#define ANALOG_BAR_HOME_GAP 2
|
||||
#define ANALOG_BAR_LESS_TALL ( ANALOG_BAR_HOME_SIZE + ANALOG_BAR_HOME_GAP )
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnalogBar::AnalogBar(Panel *parent, const char *panelName) : Panel(parent, panelName)
|
||||
{
|
||||
_analogValue = 0.0f;
|
||||
m_pszDialogVar = NULL;
|
||||
SetSegmentInfo( 2, 6 );
|
||||
SetBarInset( 0 );
|
||||
m_iAnalogValueDirection = PROGRESS_EAST;
|
||||
|
||||
m_fHomeValue = 2.0f;
|
||||
m_HomeColor = GetFgColor();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnalogBar::~AnalogBar()
|
||||
{
|
||||
delete [] m_pszDialogVar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetSegmentInfo( int gap, int width )
|
||||
{
|
||||
_segmentGap = gap;
|
||||
_segmentWide = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of segment blocks drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetDrawnSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return (int)(segmentTotal * _analogValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the total number of segment blocks drawn (active and inactive)
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetTotalSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return segmentTotal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::PaintBackground()
|
||||
{
|
||||
// Don't draw a background
|
||||
}
|
||||
|
||||
void AnalogBar::PaintSegment( int &x, int &y, int tall, int wide, Color color, bool bHome )
|
||||
{
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
x += _segmentGap;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + ANALOG_BAR_HOME_SIZE );
|
||||
surface()->DrawFilledRect(x, y + tall - (y * 2) - ANALOG_BAR_HOME_SIZE, x + _segmentWide, y + tall - (y * 2) );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x, y + ANALOG_BAR_LESS_TALL, x + _segmentWide, y + tall - (y * 2) - ANALOG_BAR_LESS_TALL );
|
||||
x += _segmentWide;
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
x -= _segmentGap + _segmentWide;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + ANALOG_BAR_HOME_SIZE );
|
||||
surface()->DrawFilledRect(x, y + tall - (y * 2) - ANALOG_BAR_HOME_SIZE, x + _segmentWide, y + tall - (y * 2) );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x, y + ANALOG_BAR_LESS_TALL, x + _segmentWide, y + tall - (y * 2) - ANALOG_BAR_LESS_TALL );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
y -= _segmentGap + _segmentWide;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + ANALOG_BAR_HOME_SIZE, y + _segmentWide );
|
||||
surface()->DrawFilledRect(x + wide - (x * 2) - ANALOG_BAR_HOME_SIZE, y, x + wide - (x * 2), y + _segmentWide );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x + ANALOG_BAR_LESS_TALL, y, x + wide - (x * 2) - ANALOG_BAR_LESS_TALL, y + _segmentWide);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
y += _segmentGap;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + ANALOG_BAR_HOME_SIZE, y + _segmentWide );
|
||||
surface()->DrawFilledRect(x + wide - (x * 2) - ANALOG_BAR_HOME_SIZE, y, x + wide - (x * 2), y + _segmentWide );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x + ANALOG_BAR_LESS_TALL, y, x + wide - (x * 2) - ANALOG_BAR_LESS_TALL, y + _segmentWide);
|
||||
y += _segmentWide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::Paint()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
// gaps
|
||||
int segmentTotal = 0, segmentsDrawn = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_WEST:
|
||||
x = wide;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_EAST:
|
||||
x = 0;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
x = m_iBarInset;
|
||||
y = tall;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
x = m_iBarInset;
|
||||
y = 0;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
}
|
||||
|
||||
int iHomeIndex = (int)( segmentTotal * m_fHomeValue + 0.5f ) - 1;
|
||||
if ( iHomeIndex < 0 )
|
||||
iHomeIndex = 0;
|
||||
|
||||
for (int i = 0; i < segmentsDrawn; i++)
|
||||
PaintSegment( x, y, tall, wide, GetFgColor(), i == iHomeIndex );
|
||||
|
||||
for (int i = segmentsDrawn; i < segmentTotal; i++)
|
||||
PaintSegment( x, y, tall, wide, GetBgColor(), i == iHomeIndex );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetAnalogValue(float analogValue)
|
||||
{
|
||||
if (analogValue != _analogValue)
|
||||
{
|
||||
// clamp the analogValue value within the range
|
||||
if (analogValue < 0.0f)
|
||||
{
|
||||
analogValue = 0.0f;
|
||||
}
|
||||
else if (analogValue > 1.0f)
|
||||
{
|
||||
analogValue = 1.0f;
|
||||
}
|
||||
|
||||
_analogValue = analogValue;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
float AnalogBar::GetAnalogValue()
|
||||
{
|
||||
return _analogValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
Panel::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetBgColor( Color( 255 - GetFgColor().r(), 255 - GetFgColor().g(), 255 - GetFgColor().b(), GetFgColor().a() ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: utility function for calculating a time remaining string
|
||||
//-----------------------------------------------------------------------------
|
||||
bool AnalogBar::ConstructTimeRemainingString(wchar_t *output, int outputBufferSizeInBytes, float startTime, float currentTime, float currentAnalogValue, float lastAnalogValueUpdateTime, bool addRemainingSuffix)
|
||||
{
|
||||
Assert( outputBufferSizeInBytes >= sizeof(output[0]) );
|
||||
Assert(lastAnalogValueUpdateTime <= currentTime);
|
||||
output[0] = 0;
|
||||
|
||||
// calculate pre-extrapolation values
|
||||
float timeElapsed = lastAnalogValueUpdateTime - startTime;
|
||||
float totalTime = timeElapsed / currentAnalogValue;
|
||||
|
||||
// calculate seconds
|
||||
int secondsRemaining = (int)(totalTime - timeElapsed);
|
||||
if (lastAnalogValueUpdateTime < currentTime)
|
||||
{
|
||||
// old update, extrapolate
|
||||
float analogValueRate = currentAnalogValue / timeElapsed;
|
||||
float extrapolatedAnalogValue = analogValueRate * (currentTime - startTime);
|
||||
float extrapolatedTotalTime = (currentTime - startTime) / extrapolatedAnalogValue;
|
||||
secondsRemaining = (int)(extrapolatedTotalTime - timeElapsed);
|
||||
}
|
||||
// if there's some time, make sure it's at least one second left
|
||||
if ( secondsRemaining == 0 && ( ( totalTime - timeElapsed ) > 0 ) )
|
||||
{
|
||||
secondsRemaining = 1;
|
||||
}
|
||||
|
||||
// calculate minutes
|
||||
int minutesRemaining = 0;
|
||||
while (secondsRemaining >= 60)
|
||||
{
|
||||
minutesRemaining++;
|
||||
secondsRemaining -= 60;
|
||||
}
|
||||
|
||||
char minutesBuf[16];
|
||||
Q_snprintf(minutesBuf, sizeof( minutesBuf ), "%d", minutesRemaining);
|
||||
char secondsBuf[16];
|
||||
Q_snprintf(secondsBuf, sizeof( secondsBuf ), "%d", secondsRemaining);
|
||||
|
||||
if (minutesRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeMinutes[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(minutesBuf, unicodeMinutes, sizeof( unicodeMinutes ));
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftMinutesSeconds";
|
||||
if (minutesRemaining == 1 && secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSecond";
|
||||
}
|
||||
else if (minutesRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSeconds";
|
||||
}
|
||||
else if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinutesSecond";
|
||||
}
|
||||
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof( unlocString ));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining", sizeof(unlocString ), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 2, unicodeMinutes, unicodeSeconds);
|
||||
|
||||
}
|
||||
else if (secondsRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftSeconds";
|
||||
if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftSecond";
|
||||
}
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof(unlocString));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining",sizeof(unlocString), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 1, unicodeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetBarInset( int pixels )
|
||||
{
|
||||
m_iBarInset = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetBarInset( void )
|
||||
{
|
||||
return m_iBarInset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
_analogValue = inResourceData->GetFloat("analogValue", 0.0f);
|
||||
|
||||
const char *dialogVar = inResourceData->GetString("variable", "");
|
||||
if (dialogVar && *dialogVar)
|
||||
{
|
||||
m_pszDialogVar = new char[strlen(dialogVar) + 1];
|
||||
strcpy(m_pszDialogVar, dialogVar);
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
outResourceData->SetFloat("analogValue", _analogValue );
|
||||
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
outResourceData->SetString("variable", m_pszDialogVar);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a string description of the panel fields for use in the UI
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *AnalogBar::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string analogValue, string variable", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates analogValue bar bases on values
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::OnDialogVariablesChanged(KeyValues *dialogVariables)
|
||||
{
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
int val = dialogVariables->GetInt(m_pszDialogVar, -1);
|
||||
if (val >= 0.0f)
|
||||
{
|
||||
SetAnalogValue(val / 100.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DECLARE_BUILD_FACTORY( ContinuousAnalogBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ContinuousAnalogBar::ContinuousAnalogBar(Panel *parent, const char *panelName) : AnalogBar(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ContinuousAnalogBar::Paint()
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
surface()->DrawFilledRect( x, y, x + (int)( wide * _analogValue ), y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
surface()->DrawFilledRect( x + (int)( wide * ( 1.0f - _analogValue ) ), y, x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
surface()->DrawFilledRect( x, y + (int)( tall * ( 1.0f - _analogValue ) ), x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
surface()->DrawFilledRect( x, y, x + wide, y + (int)( tall * _analogValue ) );
|
||||
break;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/AnalogBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( AnalogBar );
|
||||
|
||||
|
||||
#define ANALOG_BAR_HOME_SIZE 4
|
||||
#define ANALOG_BAR_HOME_GAP 2
|
||||
#define ANALOG_BAR_LESS_TALL ( ANALOG_BAR_HOME_SIZE + ANALOG_BAR_HOME_GAP )
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnalogBar::AnalogBar(Panel *parent, const char *panelName) : Panel(parent, panelName)
|
||||
{
|
||||
_analogValue = 0.0f;
|
||||
m_pszDialogVar = NULL;
|
||||
SetSegmentInfo( 2, 6 );
|
||||
SetBarInset( 0 );
|
||||
m_iAnalogValueDirection = PROGRESS_EAST;
|
||||
|
||||
m_fHomeValue = 2.0f;
|
||||
m_HomeColor = GetFgColor();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnalogBar::~AnalogBar()
|
||||
{
|
||||
delete [] m_pszDialogVar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetSegmentInfo( int gap, int width )
|
||||
{
|
||||
_segmentGap = gap;
|
||||
_segmentWide = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of segment blocks drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetDrawnSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return (int)(segmentTotal * _analogValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the total number of segment blocks drawn (active and inactive)
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetTotalSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return segmentTotal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::PaintBackground()
|
||||
{
|
||||
// Don't draw a background
|
||||
}
|
||||
|
||||
void AnalogBar::PaintSegment( int &x, int &y, int tall, int wide, Color color, bool bHome )
|
||||
{
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
x += _segmentGap;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + ANALOG_BAR_HOME_SIZE );
|
||||
surface()->DrawFilledRect(x, y + tall - (y * 2) - ANALOG_BAR_HOME_SIZE, x + _segmentWide, y + tall - (y * 2) );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x, y + ANALOG_BAR_LESS_TALL, x + _segmentWide, y + tall - (y * 2) - ANALOG_BAR_LESS_TALL );
|
||||
x += _segmentWide;
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
x -= _segmentGap + _segmentWide;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + ANALOG_BAR_HOME_SIZE );
|
||||
surface()->DrawFilledRect(x, y + tall - (y * 2) - ANALOG_BAR_HOME_SIZE, x + _segmentWide, y + tall - (y * 2) );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x, y + ANALOG_BAR_LESS_TALL, x + _segmentWide, y + tall - (y * 2) - ANALOG_BAR_LESS_TALL );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
y -= _segmentGap + _segmentWide;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + ANALOG_BAR_HOME_SIZE, y + _segmentWide );
|
||||
surface()->DrawFilledRect(x + wide - (x * 2) - ANALOG_BAR_HOME_SIZE, y, x + wide - (x * 2), y + _segmentWide );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x + ANALOG_BAR_LESS_TALL, y, x + wide - (x * 2) - ANALOG_BAR_LESS_TALL, y + _segmentWide);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
y += _segmentGap;
|
||||
|
||||
if ( bHome )
|
||||
{
|
||||
surface()->DrawSetColor( GetHomeColor() );
|
||||
surface()->DrawFilledRect(x, y, x + ANALOG_BAR_HOME_SIZE, y + _segmentWide );
|
||||
surface()->DrawFilledRect(x + wide - (x * 2) - ANALOG_BAR_HOME_SIZE, y, x + wide - (x * 2), y + _segmentWide );
|
||||
}
|
||||
|
||||
surface()->DrawSetColor( color );
|
||||
surface()->DrawFilledRect(x + ANALOG_BAR_LESS_TALL, y, x + wide - (x * 2) - ANALOG_BAR_LESS_TALL, y + _segmentWide);
|
||||
y += _segmentWide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::Paint()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
// gaps
|
||||
int segmentTotal = 0, segmentsDrawn = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_WEST:
|
||||
x = wide;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_EAST:
|
||||
x = 0;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
x = m_iBarInset;
|
||||
y = tall;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
x = m_iBarInset;
|
||||
y = 0;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _analogValue + 0.5f);
|
||||
break;
|
||||
}
|
||||
|
||||
int iHomeIndex = (int)( segmentTotal * m_fHomeValue + 0.5f ) - 1;
|
||||
if ( iHomeIndex < 0 )
|
||||
iHomeIndex = 0;
|
||||
|
||||
for (int i = 0; i < segmentsDrawn; i++)
|
||||
PaintSegment( x, y, tall, wide, GetFgColor(), i == iHomeIndex );
|
||||
|
||||
for (int i = segmentsDrawn; i < segmentTotal; i++)
|
||||
PaintSegment( x, y, tall, wide, GetBgColor(), i == iHomeIndex );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetAnalogValue(float analogValue)
|
||||
{
|
||||
if (analogValue != _analogValue)
|
||||
{
|
||||
// clamp the analogValue value within the range
|
||||
if (analogValue < 0.0f)
|
||||
{
|
||||
analogValue = 0.0f;
|
||||
}
|
||||
else if (analogValue > 1.0f)
|
||||
{
|
||||
analogValue = 1.0f;
|
||||
}
|
||||
|
||||
_analogValue = analogValue;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
float AnalogBar::GetAnalogValue()
|
||||
{
|
||||
return _analogValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
Panel::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetBgColor( Color( 255 - GetFgColor().r(), 255 - GetFgColor().g(), 255 - GetFgColor().b(), GetFgColor().a() ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: utility function for calculating a time remaining string
|
||||
//-----------------------------------------------------------------------------
|
||||
bool AnalogBar::ConstructTimeRemainingString(wchar_t *output, int outputBufferSizeInBytes, float startTime, float currentTime, float currentAnalogValue, float lastAnalogValueUpdateTime, bool addRemainingSuffix)
|
||||
{
|
||||
Assert( outputBufferSizeInBytes >= sizeof(output[0]) );
|
||||
Assert(lastAnalogValueUpdateTime <= currentTime);
|
||||
output[0] = 0;
|
||||
|
||||
// calculate pre-extrapolation values
|
||||
float timeElapsed = lastAnalogValueUpdateTime - startTime;
|
||||
float totalTime = timeElapsed / currentAnalogValue;
|
||||
|
||||
// calculate seconds
|
||||
int secondsRemaining = (int)(totalTime - timeElapsed);
|
||||
if (lastAnalogValueUpdateTime < currentTime)
|
||||
{
|
||||
// old update, extrapolate
|
||||
float analogValueRate = currentAnalogValue / timeElapsed;
|
||||
float extrapolatedAnalogValue = analogValueRate * (currentTime - startTime);
|
||||
float extrapolatedTotalTime = (currentTime - startTime) / extrapolatedAnalogValue;
|
||||
secondsRemaining = (int)(extrapolatedTotalTime - timeElapsed);
|
||||
}
|
||||
// if there's some time, make sure it's at least one second left
|
||||
if ( secondsRemaining == 0 && ( ( totalTime - timeElapsed ) > 0 ) )
|
||||
{
|
||||
secondsRemaining = 1;
|
||||
}
|
||||
|
||||
// calculate minutes
|
||||
int minutesRemaining = 0;
|
||||
while (secondsRemaining >= 60)
|
||||
{
|
||||
minutesRemaining++;
|
||||
secondsRemaining -= 60;
|
||||
}
|
||||
|
||||
char minutesBuf[16];
|
||||
Q_snprintf(minutesBuf, sizeof( minutesBuf ), "%d", minutesRemaining);
|
||||
char secondsBuf[16];
|
||||
Q_snprintf(secondsBuf, sizeof( secondsBuf ), "%d", secondsRemaining);
|
||||
|
||||
if (minutesRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeMinutes[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(minutesBuf, unicodeMinutes, sizeof( unicodeMinutes ));
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftMinutesSeconds";
|
||||
if (minutesRemaining == 1 && secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSecond";
|
||||
}
|
||||
else if (minutesRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSeconds";
|
||||
}
|
||||
else if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinutesSecond";
|
||||
}
|
||||
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof( unlocString ));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining", sizeof(unlocString ), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 2, unicodeMinutes, unicodeSeconds);
|
||||
|
||||
}
|
||||
else if (secondsRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftSeconds";
|
||||
if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftSecond";
|
||||
}
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof(unlocString));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining",sizeof(unlocString), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 1, unicodeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::SetBarInset( int pixels )
|
||||
{
|
||||
m_iBarInset = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int AnalogBar::GetBarInset( void )
|
||||
{
|
||||
return m_iBarInset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
_analogValue = inResourceData->GetFloat("analogValue", 0.0f);
|
||||
|
||||
const char *dialogVar = inResourceData->GetString("variable", "");
|
||||
if (dialogVar && *dialogVar)
|
||||
{
|
||||
m_pszDialogVar = new char[strlen(dialogVar) + 1];
|
||||
strcpy(m_pszDialogVar, dialogVar);
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
outResourceData->SetFloat("analogValue", _analogValue );
|
||||
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
outResourceData->SetString("variable", m_pszDialogVar);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a string description of the panel fields for use in the UI
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *AnalogBar::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string analogValue, string variable", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates analogValue bar bases on values
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnalogBar::OnDialogVariablesChanged(KeyValues *dialogVariables)
|
||||
{
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
int val = dialogVariables->GetInt(m_pszDialogVar, -1);
|
||||
if (val >= 0.0f)
|
||||
{
|
||||
SetAnalogValue(val / 100.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DECLARE_BUILD_FACTORY( ContinuousAnalogBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ContinuousAnalogBar::ContinuousAnalogBar(Panel *parent, const char *panelName) : AnalogBar(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ContinuousAnalogBar::Paint()
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
switch( m_iAnalogValueDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
surface()->DrawFilledRect( x, y, x + (int)( wide * _analogValue ), y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
surface()->DrawFilledRect( x + (int)( wide * ( 1.0f - _analogValue ) ), y, x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
surface()->DrawFilledRect( x, y + (int)( tall * ( 1.0f - _analogValue ) ), x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
surface()->DrawFilledRect( x, y, x + wide, y + (int)( tall * _analogValue ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,216 +1,216 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IImage.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/AnimatingImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( AnimatingImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnimatingImagePanel::AnimatingImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
m_iFrameTimeMillis = 100; // 10Hz frame rate
|
||||
m_iNextFrameTime = 0;
|
||||
m_pImageName = NULL;
|
||||
m_bFiltered = false;
|
||||
m_bScaleImage = false;
|
||||
m_bAnimating = false;
|
||||
ivgui()->AddTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Layout the panel for drawing.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::PerformLayout()
|
||||
{
|
||||
Panel::PerformLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Add an image to the end of the list of animations
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::AddImage(IImage *image)
|
||||
{
|
||||
m_Frames.AddToTail(image);
|
||||
|
||||
if ( !m_bScaleImage && image != NULL )
|
||||
{
|
||||
int wide,tall;
|
||||
image->GetSize(wide,tall);
|
||||
SetSize(wide,tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Load a set of animations by name.
|
||||
// Input:
|
||||
// baseName: is the name of the animations without their frame number or
|
||||
// file extension, (e.g. c1.tga becomes just c.)
|
||||
// framecount: number of frames in the animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::LoadAnimation(const char *baseName, int frameCount)
|
||||
{
|
||||
m_Frames.RemoveAll();
|
||||
for (int i = 1; i <= frameCount; i++)
|
||||
{
|
||||
char imageName[512];
|
||||
Q_snprintf(imageName, sizeof( imageName ), "%s%d", baseName, i);
|
||||
AddImage(scheme()->GetImage(imageName, m_bFiltered));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw the current image
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::PaintBackground()
|
||||
{
|
||||
if ( m_Frames.IsValidIndex( m_iCurrentImage ) && m_Frames[m_iCurrentImage] != NULL )
|
||||
{
|
||||
IImage *pImage = m_Frames[m_iCurrentImage];
|
||||
|
||||
surface()->DrawSetColor( 255, 255, 255, 255 );
|
||||
pImage->SetPos(0, 0);
|
||||
|
||||
if ( m_bScaleImage )
|
||||
{
|
||||
// Image size is stored in the bitmap, so temporarily set its size
|
||||
// to our panel size and then restore after we draw it.
|
||||
|
||||
int imageWide, imageTall;
|
||||
pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
pImage->SetSize( wide, tall );
|
||||
|
||||
pImage->SetColor( Color( 255,255,255,255 ) );
|
||||
pImage->Paint();
|
||||
|
||||
pImage->SetSize( imageWide, imageTall );
|
||||
}
|
||||
else
|
||||
{
|
||||
pImage->Paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called every frame the panel is visible
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::OnTick()
|
||||
{
|
||||
if (m_bAnimating && system()->GetTimeMillis() >= m_iNextFrameTime)
|
||||
{
|
||||
m_iNextFrameTime = system()->GetTimeMillis() + m_iFrameTimeMillis;
|
||||
m_iCurrentImage++;
|
||||
if (!m_Frames.IsValidIndex(m_iCurrentImage))
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
}
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get control settings for editing
|
||||
// Output: outResourceData- a set of keyvalues of imagenames.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pImageName);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies resource settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", NULL);
|
||||
if (imageName)
|
||||
{
|
||||
m_bScaleImage = ( inResourceData->GetInt( "scaleImage", 0 ) == 1 );
|
||||
|
||||
delete [] m_pImageName;
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
m_pImageName = new char[len];
|
||||
Q_strncpy(m_pImageName, imageName, len);
|
||||
|
||||
// add in the command
|
||||
LoadAnimation(m_pImageName, inResourceData->GetInt("frames"));
|
||||
}
|
||||
|
||||
m_iFrameTimeMillis = inResourceData->GetInt( "anim_framerate", 100 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *AnimatingImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
Q_snprintf(buf, sizeof(buf), "%s, string image", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Starts the image doing its animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::StartAnimation()
|
||||
{
|
||||
m_bAnimating = true;
|
||||
// ivgui()->AddTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Stops the images animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::StopAnimation()
|
||||
{
|
||||
m_bAnimating = false;
|
||||
// ivgui()->RemoveTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Resets the animation to the start of the sequence.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::ResetAnimation(int frame)
|
||||
{
|
||||
if(m_Frames.IsValidIndex(frame))
|
||||
{
|
||||
m_iCurrentImage = frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
}
|
||||
Repaint();
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IImage.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/AnimatingImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( AnimatingImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
AnimatingImagePanel::AnimatingImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
m_iFrameTimeMillis = 100; // 10Hz frame rate
|
||||
m_iNextFrameTime = 0;
|
||||
m_pImageName = NULL;
|
||||
m_bFiltered = false;
|
||||
m_bScaleImage = false;
|
||||
m_bAnimating = false;
|
||||
ivgui()->AddTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Layout the panel for drawing.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::PerformLayout()
|
||||
{
|
||||
Panel::PerformLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Add an image to the end of the list of animations
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::AddImage(IImage *image)
|
||||
{
|
||||
m_Frames.AddToTail(image);
|
||||
|
||||
if ( !m_bScaleImage && image != NULL )
|
||||
{
|
||||
int wide,tall;
|
||||
image->GetSize(wide,tall);
|
||||
SetSize(wide,tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Load a set of animations by name.
|
||||
// Input:
|
||||
// baseName: is the name of the animations without their frame number or
|
||||
// file extension, (e.g. c1.tga becomes just c.)
|
||||
// framecount: number of frames in the animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::LoadAnimation(const char *baseName, int frameCount)
|
||||
{
|
||||
m_Frames.RemoveAll();
|
||||
for (int i = 1; i <= frameCount; i++)
|
||||
{
|
||||
char imageName[512];
|
||||
Q_snprintf(imageName, sizeof( imageName ), "%s%d", baseName, i);
|
||||
AddImage(scheme()->GetImage(imageName, m_bFiltered));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw the current image
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::PaintBackground()
|
||||
{
|
||||
if ( m_Frames.IsValidIndex( m_iCurrentImage ) && m_Frames[m_iCurrentImage] != NULL )
|
||||
{
|
||||
IImage *pImage = m_Frames[m_iCurrentImage];
|
||||
|
||||
surface()->DrawSetColor( 255, 255, 255, 255 );
|
||||
pImage->SetPos(0, 0);
|
||||
|
||||
if ( m_bScaleImage )
|
||||
{
|
||||
// Image size is stored in the bitmap, so temporarily set its size
|
||||
// to our panel size and then restore after we draw it.
|
||||
|
||||
int imageWide, imageTall;
|
||||
pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
pImage->SetSize( wide, tall );
|
||||
|
||||
pImage->SetColor( Color( 255,255,255,255 ) );
|
||||
pImage->Paint();
|
||||
|
||||
pImage->SetSize( imageWide, imageTall );
|
||||
}
|
||||
else
|
||||
{
|
||||
pImage->Paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called every frame the panel is visible
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::OnTick()
|
||||
{
|
||||
if (m_bAnimating && system()->GetTimeMillis() >= m_iNextFrameTime)
|
||||
{
|
||||
m_iNextFrameTime = system()->GetTimeMillis() + m_iFrameTimeMillis;
|
||||
m_iCurrentImage++;
|
||||
if (!m_Frames.IsValidIndex(m_iCurrentImage))
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
}
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get control settings for editing
|
||||
// Output: outResourceData- a set of keyvalues of imagenames.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pImageName);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies resource settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", NULL);
|
||||
if (imageName)
|
||||
{
|
||||
m_bScaleImage = ( inResourceData->GetInt( "scaleImage", 0 ) == 1 );
|
||||
|
||||
delete [] m_pImageName;
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
m_pImageName = new char[len];
|
||||
Q_strncpy(m_pImageName, imageName, len);
|
||||
|
||||
// add in the command
|
||||
LoadAnimation(m_pImageName, inResourceData->GetInt("frames"));
|
||||
}
|
||||
|
||||
m_iFrameTimeMillis = inResourceData->GetInt( "anim_framerate", 100 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *AnimatingImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
Q_snprintf(buf, sizeof(buf), "%s, string image", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Starts the image doing its animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::StartAnimation()
|
||||
{
|
||||
m_bAnimating = true;
|
||||
// ivgui()->AddTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Stops the images animation
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::StopAnimation()
|
||||
{
|
||||
m_bAnimating = false;
|
||||
// ivgui()->RemoveTickSignal(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Resets the animation to the start of the sequence.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AnimatingImagePanel::ResetAnimation(int frame)
|
||||
{
|
||||
if(m_Frames.IsValidIndex(frame))
|
||||
{
|
||||
m_iCurrentImage = frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iCurrentImage = 0;
|
||||
}
|
||||
Repaint();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,364 +1,364 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vgui_controls/BitmapImagePanel.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/IBorder.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* Simple utility function to allocate memory and duplicate a string
|
||||
*/
|
||||
static inline char *CloneString( const char *str )
|
||||
{
|
||||
char *cloneStr = new char [ strlen(str)+1 ];
|
||||
strcpy( cloneStr, str );
|
||||
return cloneStr;
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CBitmapImagePanel, BitmapImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CBitmapImagePanel::CBitmapImagePanel( Panel *parent, char const *panelName,
|
||||
char const *filename /*= NULL*/ ) : Panel( parent, panelName )
|
||||
{
|
||||
m_pImage = NULL;
|
||||
|
||||
SetBounds( 0, 0, 100, 100 );
|
||||
|
||||
m_pszImageName = NULL;
|
||||
m_pszColorName = NULL;
|
||||
|
||||
m_hardwareFiltered = false;
|
||||
m_preserveAspectRatio = false;
|
||||
m_contentAlignment = Label::a_center;
|
||||
|
||||
if ( filename && filename[ 0 ] )
|
||||
{
|
||||
m_pImage = scheme()->GetImage( filename, NULL );
|
||||
m_pszImageName = CloneString( filename );
|
||||
}
|
||||
|
||||
m_bgColor = Color(255, 255, 255, 255);
|
||||
}
|
||||
CBitmapImagePanel::~CBitmapImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszColorName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ComputeImagePosition(int &x, int &y, int &w, int &h)
|
||||
{
|
||||
if (!m_pImage)
|
||||
{
|
||||
x = y = w = h = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !m_preserveAspectRatio )
|
||||
{
|
||||
x = y = 0;
|
||||
GetSize( w, h );
|
||||
return;
|
||||
}
|
||||
|
||||
int panelWide, panelTall;
|
||||
GetSize( panelWide, panelTall );
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( panelWide > 0 && panelTall > 0 && imageWide > 0 && imageTall > 0 )
|
||||
{
|
||||
float xScale = (float)panelWide / (float)imageWide;
|
||||
float yScale = (float)panelTall / (float)imageTall;
|
||||
float scale = min( xScale, yScale );
|
||||
|
||||
w = (int) (imageWide * scale);
|
||||
h = (int) (imageTall * scale);
|
||||
|
||||
switch (m_contentAlignment)
|
||||
{
|
||||
case Label::a_northwest:
|
||||
x = y = 0;
|
||||
break;
|
||||
case Label::a_north:
|
||||
x = (panelWide - w) / 2;
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_northeast:
|
||||
x = (panelWide - w);
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_west:
|
||||
x = 0;
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_center:
|
||||
x = (panelWide - w) / 2;
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_east:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_southwest:
|
||||
x = (panelWide - w);
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_south:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_southeast:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h);
|
||||
break;
|
||||
default:
|
||||
x = y = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = y = 0;
|
||||
w = panelWide;
|
||||
h = panelTall;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::PaintBorder()
|
||||
{
|
||||
int x, y, w, h;
|
||||
ComputeImagePosition(x, y, w, h);
|
||||
|
||||
IBorder *pBorder = GetBorder();
|
||||
if ( pBorder )
|
||||
pBorder->Paint( x, y, x+w, y+h, -1, 0, 0 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::PaintBackground()
|
||||
{
|
||||
if (!m_pImage)
|
||||
return;
|
||||
|
||||
int x, y, w, h;
|
||||
ComputeImagePosition(x, y, w, h);
|
||||
|
||||
m_pImage->SetPos(x, y);
|
||||
m_pImage->SetSize( w, h );
|
||||
m_pImage->SetColor( m_bgColor );
|
||||
surface()->DrawSetColor( m_bgColor );
|
||||
m_pImage->Paint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::setTexture( char const *filename, bool hardwareFiltered )
|
||||
{
|
||||
m_hardwareFiltered = hardwareFiltered;
|
||||
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete[] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
if ( filename && filename[ 0 ] )
|
||||
{
|
||||
m_pImage = scheme()->GetImage( filename, m_hardwareFiltered );
|
||||
m_pszImageName = CloneString( filename );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::SetContentAlignment(Label::Alignment alignment)
|
||||
{
|
||||
m_contentAlignment=alignment;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
if (m_pszColorName)
|
||||
{
|
||||
outResourceData->SetString("imagecolor", m_pszColorName);
|
||||
}
|
||||
const char *alignmentString = "";
|
||||
switch ( m_contentAlignment )
|
||||
{
|
||||
case Label::a_northwest: alignmentString = "north-west"; break;
|
||||
case Label::a_north: alignmentString = "north"; break;
|
||||
case Label::a_northeast: alignmentString = "north-east"; break;
|
||||
case Label::a_center: alignmentString = "center"; break;
|
||||
case Label::a_east: alignmentString = "east"; break;
|
||||
case Label::a_southwest: alignmentString = "south-west"; break;
|
||||
case Label::a_south: alignmentString = "south"; break;
|
||||
case Label::a_southeast: alignmentString = "south-east"; break;
|
||||
case Label::a_west:
|
||||
default: alignmentString = "center"; break;
|
||||
}
|
||||
outResourceData->SetString( "imageAlignment", alignmentString );
|
||||
outResourceData->SetInt("preserveAspectRatio", m_preserveAspectRatio);
|
||||
outResourceData->SetInt("filtered", m_hardwareFiltered);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete[] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
if ( m_pszColorName )
|
||||
{
|
||||
delete[] m_pszColorName;
|
||||
m_pszColorName = NULL;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
setTexture( imageName );
|
||||
}
|
||||
|
||||
const char *colorName = inResourceData->GetString("imagecolor", "");
|
||||
if (*colorName)
|
||||
{
|
||||
m_pszColorName = CloneString( colorName );
|
||||
InvalidateLayout(false,true); // force ApplySchemeSettings to run
|
||||
}
|
||||
|
||||
const char *keyString = inResourceData->GetString("imageAlignment", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
int align = -1;
|
||||
|
||||
if ( !stricmp(keyString, "north-west") )
|
||||
{
|
||||
align = Label::a_northwest;
|
||||
}
|
||||
else if ( !stricmp(keyString, "north") )
|
||||
{
|
||||
align = Label::a_north;
|
||||
}
|
||||
else if ( !stricmp(keyString, "north-east") )
|
||||
{
|
||||
align = Label::a_northeast;
|
||||
}
|
||||
else if ( !stricmp(keyString, "west") )
|
||||
{
|
||||
align = Label::a_west;
|
||||
}
|
||||
else if ( !stricmp(keyString, "center") )
|
||||
{
|
||||
align = Label::a_center;
|
||||
}
|
||||
else if ( !stricmp(keyString, "east") )
|
||||
{
|
||||
align = Label::a_east;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south-west") )
|
||||
{
|
||||
align = Label::a_southwest;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south") )
|
||||
{
|
||||
align = Label::a_south;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south-east") )
|
||||
{
|
||||
align = Label::a_southeast;
|
||||
}
|
||||
|
||||
if ( align != -1 )
|
||||
{
|
||||
SetContentAlignment( (Label::Alignment)align );
|
||||
}
|
||||
}
|
||||
|
||||
keyString = inResourceData->GetString("preserveAspectRatio", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
m_preserveAspectRatio = atoi( keyString ) != 0;
|
||||
}
|
||||
|
||||
keyString = inResourceData->GetString("filtered", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
m_hardwareFiltered = atoi( keyString ) != 0;
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: load the image, this is done just before this control is displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
if ( m_pszColorName )
|
||||
{
|
||||
setImageColor( pScheme->GetColor( m_pszColorName, m_bgColor ) );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CBitmapImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string image, string imagecolor, alignment imageAlignment, int preserveAspectRatio, int filtered", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vgui_controls/BitmapImagePanel.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/IBorder.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* Simple utility function to allocate memory and duplicate a string
|
||||
*/
|
||||
static inline char *CloneString( const char *str )
|
||||
{
|
||||
char *cloneStr = new char [ strlen(str)+1 ];
|
||||
strcpy( cloneStr, str );
|
||||
return cloneStr;
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CBitmapImagePanel, BitmapImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CBitmapImagePanel::CBitmapImagePanel( Panel *parent, char const *panelName,
|
||||
char const *filename /*= NULL*/ ) : Panel( parent, panelName )
|
||||
{
|
||||
m_pImage = NULL;
|
||||
|
||||
SetBounds( 0, 0, 100, 100 );
|
||||
|
||||
m_pszImageName = NULL;
|
||||
m_pszColorName = NULL;
|
||||
|
||||
m_hardwareFiltered = false;
|
||||
m_preserveAspectRatio = false;
|
||||
m_contentAlignment = Label::a_center;
|
||||
|
||||
if ( filename && filename[ 0 ] )
|
||||
{
|
||||
m_pImage = scheme()->GetImage( filename, NULL );
|
||||
m_pszImageName = CloneString( filename );
|
||||
}
|
||||
|
||||
m_bgColor = Color(255, 255, 255, 255);
|
||||
}
|
||||
CBitmapImagePanel::~CBitmapImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszColorName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ComputeImagePosition(int &x, int &y, int &w, int &h)
|
||||
{
|
||||
if (!m_pImage)
|
||||
{
|
||||
x = y = w = h = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !m_preserveAspectRatio )
|
||||
{
|
||||
x = y = 0;
|
||||
GetSize( w, h );
|
||||
return;
|
||||
}
|
||||
|
||||
int panelWide, panelTall;
|
||||
GetSize( panelWide, panelTall );
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( panelWide > 0 && panelTall > 0 && imageWide > 0 && imageTall > 0 )
|
||||
{
|
||||
float xScale = (float)panelWide / (float)imageWide;
|
||||
float yScale = (float)panelTall / (float)imageTall;
|
||||
float scale = min( xScale, yScale );
|
||||
|
||||
w = (int) (imageWide * scale);
|
||||
h = (int) (imageTall * scale);
|
||||
|
||||
switch (m_contentAlignment)
|
||||
{
|
||||
case Label::a_northwest:
|
||||
x = y = 0;
|
||||
break;
|
||||
case Label::a_north:
|
||||
x = (panelWide - w) / 2;
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_northeast:
|
||||
x = (panelWide - w);
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_west:
|
||||
x = 0;
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_center:
|
||||
x = (panelWide - w) / 2;
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_east:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_southwest:
|
||||
x = (panelWide - w);
|
||||
y = 0;
|
||||
break;
|
||||
case Label::a_south:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h) / 2;
|
||||
break;
|
||||
case Label::a_southeast:
|
||||
x = (panelWide - w);
|
||||
y = (panelTall - h);
|
||||
break;
|
||||
default:
|
||||
x = y = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = y = 0;
|
||||
w = panelWide;
|
||||
h = panelTall;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::PaintBorder()
|
||||
{
|
||||
int x, y, w, h;
|
||||
ComputeImagePosition(x, y, w, h);
|
||||
|
||||
IBorder *pBorder = GetBorder();
|
||||
if ( pBorder )
|
||||
pBorder->Paint( x, y, x+w, y+h, -1, 0, 0 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::PaintBackground()
|
||||
{
|
||||
if (!m_pImage)
|
||||
return;
|
||||
|
||||
int x, y, w, h;
|
||||
ComputeImagePosition(x, y, w, h);
|
||||
|
||||
m_pImage->SetPos(x, y);
|
||||
m_pImage->SetSize( w, h );
|
||||
m_pImage->SetColor( m_bgColor );
|
||||
surface()->DrawSetColor( m_bgColor );
|
||||
m_pImage->Paint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::setTexture( char const *filename, bool hardwareFiltered )
|
||||
{
|
||||
m_hardwareFiltered = hardwareFiltered;
|
||||
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete[] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
if ( filename && filename[ 0 ] )
|
||||
{
|
||||
m_pImage = scheme()->GetImage( filename, m_hardwareFiltered );
|
||||
m_pszImageName = CloneString( filename );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::SetContentAlignment(Label::Alignment alignment)
|
||||
{
|
||||
m_contentAlignment=alignment;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
if (m_pszColorName)
|
||||
{
|
||||
outResourceData->SetString("imagecolor", m_pszColorName);
|
||||
}
|
||||
const char *alignmentString = "";
|
||||
switch ( m_contentAlignment )
|
||||
{
|
||||
case Label::a_northwest: alignmentString = "north-west"; break;
|
||||
case Label::a_north: alignmentString = "north"; break;
|
||||
case Label::a_northeast: alignmentString = "north-east"; break;
|
||||
case Label::a_center: alignmentString = "center"; break;
|
||||
case Label::a_east: alignmentString = "east"; break;
|
||||
case Label::a_southwest: alignmentString = "south-west"; break;
|
||||
case Label::a_south: alignmentString = "south"; break;
|
||||
case Label::a_southeast: alignmentString = "south-east"; break;
|
||||
case Label::a_west:
|
||||
default: alignmentString = "center"; break;
|
||||
}
|
||||
outResourceData->SetString( "imageAlignment", alignmentString );
|
||||
outResourceData->SetInt("preserveAspectRatio", m_preserveAspectRatio);
|
||||
outResourceData->SetInt("filtered", m_hardwareFiltered);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete[] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
if ( m_pszColorName )
|
||||
{
|
||||
delete[] m_pszColorName;
|
||||
m_pszColorName = NULL;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
setTexture( imageName );
|
||||
}
|
||||
|
||||
const char *colorName = inResourceData->GetString("imagecolor", "");
|
||||
if (*colorName)
|
||||
{
|
||||
m_pszColorName = CloneString( colorName );
|
||||
InvalidateLayout(false,true); // force ApplySchemeSettings to run
|
||||
}
|
||||
|
||||
const char *keyString = inResourceData->GetString("imageAlignment", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
int align = -1;
|
||||
|
||||
if ( !stricmp(keyString, "north-west") )
|
||||
{
|
||||
align = Label::a_northwest;
|
||||
}
|
||||
else if ( !stricmp(keyString, "north") )
|
||||
{
|
||||
align = Label::a_north;
|
||||
}
|
||||
else if ( !stricmp(keyString, "north-east") )
|
||||
{
|
||||
align = Label::a_northeast;
|
||||
}
|
||||
else if ( !stricmp(keyString, "west") )
|
||||
{
|
||||
align = Label::a_west;
|
||||
}
|
||||
else if ( !stricmp(keyString, "center") )
|
||||
{
|
||||
align = Label::a_center;
|
||||
}
|
||||
else if ( !stricmp(keyString, "east") )
|
||||
{
|
||||
align = Label::a_east;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south-west") )
|
||||
{
|
||||
align = Label::a_southwest;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south") )
|
||||
{
|
||||
align = Label::a_south;
|
||||
}
|
||||
else if ( !stricmp(keyString, "south-east") )
|
||||
{
|
||||
align = Label::a_southeast;
|
||||
}
|
||||
|
||||
if ( align != -1 )
|
||||
{
|
||||
SetContentAlignment( (Label::Alignment)align );
|
||||
}
|
||||
}
|
||||
|
||||
keyString = inResourceData->GetString("preserveAspectRatio", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
m_preserveAspectRatio = atoi( keyString ) != 0;
|
||||
}
|
||||
|
||||
keyString = inResourceData->GetString("filtered", "");
|
||||
if (keyString && *keyString)
|
||||
{
|
||||
m_hardwareFiltered = atoi( keyString ) != 0;
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: load the image, this is done just before this control is displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBitmapImagePanel::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
if ( m_pszColorName )
|
||||
{
|
||||
setImageColor( pScheme->GetColor( m_pszColorName, m_bgColor ) );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CBitmapImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string image, string imagecolor, alignment imageAlignment, int preserveAspectRatio, int filtered", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
#include "vgui/IVGui.h"
|
||||
#include "vgui_controls/MessageMap.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// Start with empty list
|
||||
CBuildFactoryHelper *CBuildFactoryHelper::m_sHelpers = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructs a panel factory
|
||||
// Input : pfnCreate - fn Ptr to a function which generates a panel
|
||||
//-----------------------------------------------------------------------------
|
||||
CBuildFactoryHelper::CBuildFactoryHelper( char const *className, PANELCREATEFUNC func )
|
||||
{
|
||||
// Make this fatal
|
||||
if ( HasFactory( className ) )
|
||||
{
|
||||
Error( "CBuildFactoryHelper: Factory for '%s' already exists!!!!\n", className );
|
||||
}
|
||||
|
||||
//List is empty, or element belongs at front, insert here
|
||||
m_pNext = m_sHelpers;
|
||||
m_sHelpers = this;
|
||||
|
||||
Assert( func );
|
||||
m_CreateFunc = func;
|
||||
Assert( className );
|
||||
m_pClassName = className;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns next object in list
|
||||
// Output : CBuildFactoryHelper
|
||||
//-----------------------------------------------------------------------------
|
||||
CBuildFactoryHelper *CBuildFactoryHelper::GetNext( void )
|
||||
{
|
||||
return m_pNext;
|
||||
}
|
||||
|
||||
char const *CBuildFactoryHelper::GetClassName() const
|
||||
{
|
||||
return m_pClassName;
|
||||
}
|
||||
|
||||
vgui::Panel *CBuildFactoryHelper::CreatePanel()
|
||||
{
|
||||
if ( !m_CreateFunc )
|
||||
return NULL;
|
||||
|
||||
return ( *m_CreateFunc )();
|
||||
}
|
||||
|
||||
// private static meethod
|
||||
bool CBuildFactoryHelper::HasFactory( char const *className )
|
||||
{
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
if ( !Q_stricmp( className, p->GetClassName() ) )
|
||||
return true;
|
||||
|
||||
p = p->GetNext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// static method
|
||||
vgui::Panel *CBuildFactoryHelper::InstancePanel( char const *className )
|
||||
{
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
if ( !Q_stricmp( className, p->GetClassName() ) )
|
||||
return p->CreatePanel();
|
||||
|
||||
p = p->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static method
|
||||
void CBuildFactoryHelper::GetFactoryNames( CUtlVector< char const * >& list )
|
||||
{
|
||||
list.RemoveAll();
|
||||
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
list.AddToTail( p->GetClassName() );
|
||||
p = p->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
#include "vgui/IVGui.h"
|
||||
#include "vgui_controls/MessageMap.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// Start with empty list
|
||||
CBuildFactoryHelper *CBuildFactoryHelper::m_sHelpers = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructs a panel factory
|
||||
// Input : pfnCreate - fn Ptr to a function which generates a panel
|
||||
//-----------------------------------------------------------------------------
|
||||
CBuildFactoryHelper::CBuildFactoryHelper( char const *className, PANELCREATEFUNC func )
|
||||
{
|
||||
// Make this fatal
|
||||
if ( HasFactory( className ) )
|
||||
{
|
||||
Error( "CBuildFactoryHelper: Factory for '%s' already exists!!!!\n", className );
|
||||
}
|
||||
|
||||
//List is empty, or element belongs at front, insert here
|
||||
m_pNext = m_sHelpers;
|
||||
m_sHelpers = this;
|
||||
|
||||
Assert( func );
|
||||
m_CreateFunc = func;
|
||||
Assert( className );
|
||||
m_pClassName = className;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns next object in list
|
||||
// Output : CBuildFactoryHelper
|
||||
//-----------------------------------------------------------------------------
|
||||
CBuildFactoryHelper *CBuildFactoryHelper::GetNext( void )
|
||||
{
|
||||
return m_pNext;
|
||||
}
|
||||
|
||||
char const *CBuildFactoryHelper::GetClassName() const
|
||||
{
|
||||
return m_pClassName;
|
||||
}
|
||||
|
||||
vgui::Panel *CBuildFactoryHelper::CreatePanel()
|
||||
{
|
||||
if ( !m_CreateFunc )
|
||||
return NULL;
|
||||
|
||||
return ( *m_CreateFunc )();
|
||||
}
|
||||
|
||||
// private static meethod
|
||||
bool CBuildFactoryHelper::HasFactory( char const *className )
|
||||
{
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
if ( !Q_stricmp( className, p->GetClassName() ) )
|
||||
return true;
|
||||
|
||||
p = p->GetNext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// static method
|
||||
vgui::Panel *CBuildFactoryHelper::InstancePanel( char const *className )
|
||||
{
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
if ( !Q_stricmp( className, p->GetClassName() ) )
|
||||
return p->CreatePanel();
|
||||
|
||||
p = p->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static method
|
||||
void CBuildFactoryHelper::GetFactoryNames( CUtlVector< char const * >& list )
|
||||
{
|
||||
list.RemoveAll();
|
||||
|
||||
CBuildFactoryHelper *p = m_sHelpers;
|
||||
while ( p )
|
||||
{
|
||||
list.AddToTail( p->GetClassName() );
|
||||
p = p->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,205 +1,205 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/CheckButton.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
void CheckImage::Paint()
|
||||
{
|
||||
DrawSetTextFont(GetFont());
|
||||
|
||||
// draw background
|
||||
if (_CheckButton->IsEnabled() && _CheckButton->IsCheckButtonCheckable() )
|
||||
{
|
||||
DrawSetTextColor(_bgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_CheckButton->GetDisabledBgColor());
|
||||
}
|
||||
DrawPrintChar(0, 1, 'g');
|
||||
|
||||
// draw border box
|
||||
DrawSetTextColor(_borderColor1);
|
||||
DrawPrintChar(0, 1, 'e');
|
||||
DrawSetTextColor(_borderColor2);
|
||||
DrawPrintChar(0, 1, 'f');
|
||||
|
||||
// draw selected check
|
||||
if (_CheckButton->IsSelected())
|
||||
{
|
||||
if ( !_CheckButton->IsEnabled() )
|
||||
{
|
||||
DrawSetTextColor( _CheckButton->GetDisabledFgColor() );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_checkColor);
|
||||
}
|
||||
|
||||
DrawPrintChar(0, 2, 'b');
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CheckButton, CheckButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButton::CheckButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
|
||||
{
|
||||
SetContentAlignment(a_west);
|
||||
m_bCheckButtonCheckable = true;
|
||||
|
||||
// create the image
|
||||
_checkBoxImage = new CheckImage(this);
|
||||
|
||||
SetTextImageIndex(1);
|
||||
SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
|
||||
|
||||
_selectedFgColor = Color( 196, 181, 80, 255 );
|
||||
_disabledFgColor = Color(130, 130, 130, 255);
|
||||
_disabledBgColor = Color(62, 70, 55, 255);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButton::~CheckButton()
|
||||
{
|
||||
delete _checkBoxImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetDefaultColor( GetSchemeColor("CheckButton.TextColor", pScheme), GetBgColor() );
|
||||
_checkBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(62, 70, 55, 255), pScheme);
|
||||
_checkBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 255), pScheme);
|
||||
_checkBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 255), pScheme);
|
||||
_checkBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 255), pScheme);
|
||||
_selectedFgColor = GetSchemeColor("CheckButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
|
||||
_disabledFgColor = GetSchemeColor("CheckButton.DisabledFgColor", Color(130, 130, 130, 255), pScheme);
|
||||
_disabledBgColor = GetSchemeColor("CheckButton.DisabledBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
|
||||
Color bgArmedColor = GetSchemeColor( "CheckButton.ArmedBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
SetArmedColor( GetFgColor(), bgArmedColor );
|
||||
|
||||
Color bgDepressedColor = GetSchemeColor( "CheckButton.DepressedBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
SetDepressedColor( GetFgColor(), bgDepressedColor );
|
||||
|
||||
_highlightFgColor = GetSchemeColor( "CheckButton.HighlightFgColor", Color(62, 70, 55, 255), pScheme);
|
||||
|
||||
SetContentAlignment(Label::a_west);
|
||||
|
||||
_checkBoxImage->SetFont( pScheme->GetFont("Marlett", IsProportional()) );
|
||||
_checkBoxImage->ResizeImageToContent();
|
||||
SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *CheckButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Check the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetSelected(bool state )
|
||||
{
|
||||
if (m_bCheckButtonCheckable)
|
||||
{
|
||||
// send a message saying we've been checked
|
||||
KeyValues *msg = new KeyValues("CheckButtonChecked", "state", (int)state);
|
||||
PostActionSignal(msg);
|
||||
|
||||
BaseClass::SetSelected(state);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the state of the check can be changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetCheckButtonCheckable(bool state)
|
||||
{
|
||||
m_bCheckButtonCheckable = state;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a different foreground text color if we are selected
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _X360
|
||||
Color CheckButton::GetButtonFgColor()
|
||||
{
|
||||
if (HasFocus())
|
||||
{
|
||||
return _selectedFgColor;
|
||||
}
|
||||
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
#else
|
||||
Color CheckButton::GetButtonFgColor()
|
||||
{
|
||||
if ( IsArmed() )
|
||||
{
|
||||
return _highlightFgColor;
|
||||
}
|
||||
|
||||
if (IsSelected())
|
||||
{
|
||||
return _selectedFgColor;
|
||||
}
|
||||
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::OnCheckButtonChecked(Panel *panel)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetHighlightColor(Color fgColor)
|
||||
{
|
||||
if ( _highlightFgColor != fgColor )
|
||||
{
|
||||
_highlightFgColor = fgColor;
|
||||
|
||||
InvalidateLayout(false);
|
||||
}
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/CheckButton.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
void CheckImage::Paint()
|
||||
{
|
||||
DrawSetTextFont(GetFont());
|
||||
|
||||
// draw background
|
||||
if (_CheckButton->IsEnabled() && _CheckButton->IsCheckButtonCheckable() )
|
||||
{
|
||||
DrawSetTextColor(_bgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_CheckButton->GetDisabledBgColor());
|
||||
}
|
||||
DrawPrintChar(0, 1, 'g');
|
||||
|
||||
// draw border box
|
||||
DrawSetTextColor(_borderColor1);
|
||||
DrawPrintChar(0, 1, 'e');
|
||||
DrawSetTextColor(_borderColor2);
|
||||
DrawPrintChar(0, 1, 'f');
|
||||
|
||||
// draw selected check
|
||||
if (_CheckButton->IsSelected())
|
||||
{
|
||||
if ( !_CheckButton->IsEnabled() )
|
||||
{
|
||||
DrawSetTextColor( _CheckButton->GetDisabledFgColor() );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_checkColor);
|
||||
}
|
||||
|
||||
DrawPrintChar(0, 2, 'b');
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CheckButton, CheckButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButton::CheckButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
|
||||
{
|
||||
SetContentAlignment(a_west);
|
||||
m_bCheckButtonCheckable = true;
|
||||
|
||||
// create the image
|
||||
_checkBoxImage = new CheckImage(this);
|
||||
|
||||
SetTextImageIndex(1);
|
||||
SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
|
||||
|
||||
_selectedFgColor = Color( 196, 181, 80, 255 );
|
||||
_disabledFgColor = Color(130, 130, 130, 255);
|
||||
_disabledBgColor = Color(62, 70, 55, 255);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButton::~CheckButton()
|
||||
{
|
||||
delete _checkBoxImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetDefaultColor( GetSchemeColor("CheckButton.TextColor", pScheme), GetBgColor() );
|
||||
_checkBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(62, 70, 55, 255), pScheme);
|
||||
_checkBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 255), pScheme);
|
||||
_checkBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 255), pScheme);
|
||||
_checkBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 255), pScheme);
|
||||
_selectedFgColor = GetSchemeColor("CheckButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
|
||||
_disabledFgColor = GetSchemeColor("CheckButton.DisabledFgColor", Color(130, 130, 130, 255), pScheme);
|
||||
_disabledBgColor = GetSchemeColor("CheckButton.DisabledBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
|
||||
Color bgArmedColor = GetSchemeColor( "CheckButton.ArmedBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
SetArmedColor( GetFgColor(), bgArmedColor );
|
||||
|
||||
Color bgDepressedColor = GetSchemeColor( "CheckButton.DepressedBgColor", Color(62, 70, 55, 255), pScheme);
|
||||
SetDepressedColor( GetFgColor(), bgDepressedColor );
|
||||
|
||||
_highlightFgColor = GetSchemeColor( "CheckButton.HighlightFgColor", Color(62, 70, 55, 255), pScheme);
|
||||
|
||||
SetContentAlignment(Label::a_west);
|
||||
|
||||
_checkBoxImage->SetFont( pScheme->GetFont("Marlett", IsProportional()) );
|
||||
_checkBoxImage->ResizeImageToContent();
|
||||
SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *CheckButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Check the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetSelected(bool state )
|
||||
{
|
||||
if (m_bCheckButtonCheckable)
|
||||
{
|
||||
// send a message saying we've been checked
|
||||
KeyValues *msg = new KeyValues("CheckButtonChecked", "state", (int)state);
|
||||
PostActionSignal(msg);
|
||||
|
||||
BaseClass::SetSelected(state);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the state of the check can be changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetCheckButtonCheckable(bool state)
|
||||
{
|
||||
m_bCheckButtonCheckable = state;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a different foreground text color if we are selected
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _X360
|
||||
Color CheckButton::GetButtonFgColor()
|
||||
{
|
||||
if (HasFocus())
|
||||
{
|
||||
return _selectedFgColor;
|
||||
}
|
||||
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
#else
|
||||
Color CheckButton::GetButtonFgColor()
|
||||
{
|
||||
if ( IsArmed() )
|
||||
{
|
||||
return _highlightFgColor;
|
||||
}
|
||||
|
||||
if (IsSelected())
|
||||
{
|
||||
return _selectedFgColor;
|
||||
}
|
||||
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::OnCheckButtonChecked(Panel *panel)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButton::SetHighlightColor(Color fgColor)
|
||||
{
|
||||
if ( _highlightFgColor != fgColor )
|
||||
{
|
||||
_highlightFgColor = fgColor;
|
||||
|
||||
InvalidateLayout(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,212 +1,212 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui_controls/CheckButtonList.h>
|
||||
#include <vgui_controls/CheckButton.h>
|
||||
#include <vgui_controls/ScrollBar.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButtonList::CheckButtonList(Panel *parent, const char *name) : BaseClass(parent, name)
|
||||
{
|
||||
m_pScrollBar = new ScrollBar(this, NULL, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButtonList::~CheckButtonList()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds a check button to the list
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::AddItem(const char *itemText, bool startsSelected, KeyValues *userData)
|
||||
{
|
||||
CheckItem_t newItem;
|
||||
newItem.checkButton = new vgui::CheckButton(this, NULL, itemText);
|
||||
newItem.checkButton->SetSilentMode( true );
|
||||
newItem.checkButton->SetSelected(startsSelected);
|
||||
newItem.checkButton->SetSilentMode( false );
|
||||
newItem.checkButton->AddActionSignalTarget(this);
|
||||
newItem.userData = userData;
|
||||
InvalidateLayout();
|
||||
return m_CheckItems.AddToTail(newItem);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears the list
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::RemoveAll()
|
||||
{
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
m_CheckItems[i].checkButton->MarkForDeletion();
|
||||
if (m_CheckItems[i].userData)
|
||||
{
|
||||
m_CheckItems[i].userData->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
m_CheckItems.RemoveAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of items in list that are checked
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetCheckedItemCount()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
if (m_CheckItems[i].checkButton->IsSelected())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
// get sizes
|
||||
int x = 4, y = 4, wide = GetWide() - ((x * 2) + m_pScrollBar->GetWide()), tall = 22;
|
||||
|
||||
// set scrollbar
|
||||
int totalHeight = y + (m_CheckItems.Count() * tall);
|
||||
if (totalHeight > GetTall())
|
||||
{
|
||||
m_pScrollBar->SetRange(0, totalHeight + 1);
|
||||
m_pScrollBar->SetRangeWindow(GetTall());
|
||||
m_pScrollBar->SetVisible(true);
|
||||
m_pScrollBar->SetBounds(GetWide() - 21, 0, 19, GetTall() - 2);
|
||||
SetPaintBorderEnabled(true);
|
||||
y -= m_pScrollBar->GetValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pScrollBar->SetVisible(false);
|
||||
SetPaintBorderEnabled(false);
|
||||
}
|
||||
|
||||
// position the items
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
CheckButton *btn = m_CheckItems[i].checkButton;
|
||||
btn->SetBounds(x, y, wide, tall);
|
||||
y += tall;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the border on the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CheckButtonList::IsItemIDValid(int itemID)
|
||||
{
|
||||
return m_CheckItems.IsValidIndex(itemID);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetHighestItemID()
|
||||
{
|
||||
return m_CheckItems.Count() - 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues *CheckButtonList::GetItemData(int itemID)
|
||||
{
|
||||
return m_CheckItems[itemID].userData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetItemCount()
|
||||
{
|
||||
return m_CheckItems.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CheckButtonList::IsItemChecked(int itemID)
|
||||
{
|
||||
return m_CheckItems[itemID].checkButton->IsSelected();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the state of the check button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::SetItemCheckable(int itemID, bool state)
|
||||
{
|
||||
m_CheckItems[itemID].checkButton->SetCheckButtonCheckable(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Forwards up check button selected message
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnCheckButtonChecked( KeyValues *pParams )
|
||||
{
|
||||
vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
|
||||
int c = m_CheckItems.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
if ( pPanel == m_CheckItems[i].checkButton )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "CheckButtonChecked", "itemid", i );
|
||||
kv->SetInt( "state", pParams->GetInt( "state" ) );
|
||||
PostActionSignal( kv );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates from scrollbar movement
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnScrollBarSliderMoved()
|
||||
{
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Mouse wheeled
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_pScrollBar->GetValue();
|
||||
val -= (delta * 15);
|
||||
m_pScrollBar->SetValue(val);
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui_controls/CheckButtonList.h>
|
||||
#include <vgui_controls/CheckButton.h>
|
||||
#include <vgui_controls/ScrollBar.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButtonList::CheckButtonList(Panel *parent, const char *name) : BaseClass(parent, name)
|
||||
{
|
||||
m_pScrollBar = new ScrollBar(this, NULL, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CheckButtonList::~CheckButtonList()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds a check button to the list
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::AddItem(const char *itemText, bool startsSelected, KeyValues *userData)
|
||||
{
|
||||
CheckItem_t newItem;
|
||||
newItem.checkButton = new vgui::CheckButton(this, NULL, itemText);
|
||||
newItem.checkButton->SetSilentMode( true );
|
||||
newItem.checkButton->SetSelected(startsSelected);
|
||||
newItem.checkButton->SetSilentMode( false );
|
||||
newItem.checkButton->AddActionSignalTarget(this);
|
||||
newItem.userData = userData;
|
||||
InvalidateLayout();
|
||||
return m_CheckItems.AddToTail(newItem);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears the list
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::RemoveAll()
|
||||
{
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
m_CheckItems[i].checkButton->MarkForDeletion();
|
||||
if (m_CheckItems[i].userData)
|
||||
{
|
||||
m_CheckItems[i].userData->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
m_CheckItems.RemoveAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of items in list that are checked
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetCheckedItemCount()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
if (m_CheckItems[i].checkButton->IsSelected())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
// get sizes
|
||||
int x = 4, y = 4, wide = GetWide() - ((x * 2) + m_pScrollBar->GetWide()), tall = 22;
|
||||
|
||||
// set scrollbar
|
||||
int totalHeight = y + (m_CheckItems.Count() * tall);
|
||||
if (totalHeight > GetTall())
|
||||
{
|
||||
m_pScrollBar->SetRange(0, totalHeight + 1);
|
||||
m_pScrollBar->SetRangeWindow(GetTall());
|
||||
m_pScrollBar->SetVisible(true);
|
||||
m_pScrollBar->SetBounds(GetWide() - 21, 0, 19, GetTall() - 2);
|
||||
SetPaintBorderEnabled(true);
|
||||
y -= m_pScrollBar->GetValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pScrollBar->SetVisible(false);
|
||||
SetPaintBorderEnabled(false);
|
||||
}
|
||||
|
||||
// position the items
|
||||
for (int i = 0; i < m_CheckItems.Count(); i++)
|
||||
{
|
||||
CheckButton *btn = m_CheckItems[i].checkButton;
|
||||
btn->SetBounds(x, y, wide, tall);
|
||||
y += tall;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the border on the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CheckButtonList::IsItemIDValid(int itemID)
|
||||
{
|
||||
return m_CheckItems.IsValidIndex(itemID);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetHighestItemID()
|
||||
{
|
||||
return m_CheckItems.Count() - 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues *CheckButtonList::GetItemData(int itemID)
|
||||
{
|
||||
return m_CheckItems[itemID].userData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int CheckButtonList::GetItemCount()
|
||||
{
|
||||
return m_CheckItems.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CheckButtonList::IsItemChecked(int itemID)
|
||||
{
|
||||
return m_CheckItems[itemID].checkButton->IsSelected();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the state of the check button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::SetItemCheckable(int itemID, bool state)
|
||||
{
|
||||
m_CheckItems[itemID].checkButton->SetCheckButtonCheckable(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Forwards up check button selected message
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnCheckButtonChecked( KeyValues *pParams )
|
||||
{
|
||||
vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
|
||||
int c = m_CheckItems.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
if ( pPanel == m_CheckItems[i].checkButton )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "CheckButtonChecked", "itemid", i );
|
||||
kv->SetInt( "state", pParams->GetInt( "state" ) );
|
||||
PostActionSignal( kv );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates from scrollbar movement
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnScrollBarSliderMoved()
|
||||
{
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Mouse wheeled
|
||||
//-----------------------------------------------------------------------------
|
||||
void CheckButtonList::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_pScrollBar->GetValue();
|
||||
val -= (delta * 15);
|
||||
m_pScrollBar->SetValue(val);
|
||||
}
|
||||
|
||||
@@ -1,292 +1,292 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/CircularProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CircularProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::CircularProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_iProgressDirection = CircularProgressBar::PROGRESS_CCW;
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
m_nTextureId[i] = -1;
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
m_iStartSegment = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::~CircularProgressBar()
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId[i] )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId[i] );
|
||||
m_nTextureId[i] = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName[i];
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
delete [] m_pszImageName[i];
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("fg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetFgImage( imageName );
|
||||
}
|
||||
imageName = inResourceData->GetString("bg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetBgImage( imageName );
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("CircularProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("CircularProgressBar.BgColor", pScheme));
|
||||
SetBorder(NULL);
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( m_pszImageName[i] && strlen( m_pszImageName[i] ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId[i] == -1 )
|
||||
{
|
||||
m_nTextureId[i] = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId[i], m_pszImageName[i], true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::SetImage(const char *imageName, progress_textures_t iPos)
|
||||
{
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
|
||||
if ( m_pszImageName[iPos] && ( m_lenImageName[iPos] < len ) )
|
||||
{
|
||||
// If we already have a buffer, but it is too short, then free the buffer
|
||||
delete [] m_pszImageName[iPos];
|
||||
m_pszImageName[iPos] = NULL;
|
||||
m_lenImageName[iPos] = 0;
|
||||
}
|
||||
|
||||
if ( !m_pszImageName[iPos] )
|
||||
{
|
||||
m_pszImageName[iPos] = new char[ len ];
|
||||
m_lenImageName[iPos] = len;
|
||||
}
|
||||
|
||||
Q_snprintf( m_pszImageName[iPos], len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::PaintBackground()
|
||||
{
|
||||
// If we don't have a Bg image, use the foreground
|
||||
int iTextureID = m_nTextureId[PROGRESS_TEXTURE_BG] != -1 ? m_nTextureId[PROGRESS_TEXTURE_BG] : m_nTextureId[PROGRESS_TEXTURE_FG];
|
||||
vgui::surface()->DrawSetTexture( iTextureID );
|
||||
vgui::surface()->DrawSetColor( GetBgColor() );
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::Paint()
|
||||
{
|
||||
float flProgress = GetProgress();
|
||||
float flEndAngle;
|
||||
|
||||
if ( m_iProgressDirection == PROGRESS_CW )
|
||||
{
|
||||
flEndAngle = flProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
flEndAngle = ( 1.0 - flProgress );
|
||||
}
|
||||
|
||||
DrawCircleSegment( GetFgColor(), flEndAngle, ( m_iProgressDirection == PROGRESS_CW ) );
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float minProgressRadians;
|
||||
|
||||
float vert1x;
|
||||
float vert1y;
|
||||
float vert2x;
|
||||
float vert2y;
|
||||
|
||||
int swipe_dir_x;
|
||||
int swipe_dir_y;
|
||||
} circular_progress_segment_t;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
// This defines the properties of the 8 circle segments
|
||||
// in the circular progress bar.
|
||||
circular_progress_segment_t Segments[8] =
|
||||
{
|
||||
{ 0.0, 0.5, 0.0, 1.0, 0.0, 1, 0 },
|
||||
{ M_PI * 0.25, 1.0, 0.0, 1.0, 0.5, 0, 1 },
|
||||
{ M_PI * 0.5, 1.0, 0.5, 1.0, 1.0, 0, 1 },
|
||||
{ M_PI * 0.75, 1.0, 1.0, 0.5, 1.0, -1, 0 },
|
||||
{ M_PI, 0.5, 1.0, 0.0, 1.0, -1, 0 },
|
||||
{ M_PI * 1.25, 0.0, 1.0, 0.0, 0.5, 0, -1 },
|
||||
{ M_PI * 1.5, 0.0, 0.5, 0.0, 0.0, 0, -1 },
|
||||
{ M_PI * 1.75, 0.0, 0.0, 0.5, 0.0, 1, 0 },
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#define SEGMENT_ANGLE ( M_PI / 4 )
|
||||
|
||||
// function to draw from A to B degrees, with a direction
|
||||
// we draw starting from the top ( 0 progress )
|
||||
void CircularProgressBar::DrawCircleSegment( Color c, float flEndProgress, bool bClockwise )
|
||||
{
|
||||
if ( m_nTextureId[PROGRESS_TEXTURE_FG] == -1 )
|
||||
return;
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
float flWide = (float)wide;
|
||||
float flTall = (float)tall;
|
||||
|
||||
float flHalfWide = (float)wide / 2;
|
||||
float flHalfTall = (float)tall / 2;
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId[PROGRESS_TEXTURE_FG] );
|
||||
vgui::surface()->DrawSetColor( c );
|
||||
|
||||
// TODO - if we want to progress CCW, reverse a few things
|
||||
|
||||
float flEndProgressRadians = flEndProgress * M_PI * 2;
|
||||
|
||||
int cur_wedge = m_iStartSegment;
|
||||
for ( int i=0;i<8;i++ )
|
||||
{
|
||||
if ( flEndProgressRadians > Segments[cur_wedge].minProgressRadians)
|
||||
{
|
||||
vgui::Vertex_t v[3];
|
||||
|
||||
// vert 0 is ( 0.5, 0.5 )
|
||||
v[0].m_Position.Init( flHalfWide, flHalfTall );
|
||||
v[0].m_TexCoord.Init( 0.5f, 0.5f );
|
||||
|
||||
float flInternalProgress = flEndProgressRadians - Segments[cur_wedge].minProgressRadians;
|
||||
|
||||
if ( flInternalProgress < SEGMENT_ANGLE )
|
||||
{
|
||||
// Calc how much of this slice we should be drawing
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flInternalProgress = SEGMENT_ANGLE - flInternalProgress;
|
||||
}
|
||||
|
||||
float flTan = tan(flInternalProgress);
|
||||
|
||||
float flDeltaX, flDeltaY;
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flDeltaX = ( flHalfWide - flHalfTall * flTan ) * Segments[i].swipe_dir_x;
|
||||
flDeltaY = ( flHalfTall - flHalfWide * flTan ) * Segments[i].swipe_dir_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
flDeltaX = flHalfTall * flTan * Segments[i].swipe_dir_x;
|
||||
flDeltaY = flHalfWide * flTan * Segments[i].swipe_dir_y;
|
||||
}
|
||||
|
||||
v[2].m_Position.Init( Segments[i].vert1x * flWide + flDeltaX, Segments[i].vert1y * flTall + flDeltaY );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert1x + ( flDeltaX / flHalfWide ) * 0.5, Segments[i].vert1y + ( flDeltaY / flHalfTall ) * 0.5 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// full segment, easy calculation
|
||||
v[2].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert2x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert2y - 0.5 ) );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert2x, Segments[i].vert2y );
|
||||
}
|
||||
|
||||
// vert 2 is ( Segments[i].vert1x, Segments[i].vert1y )
|
||||
v[1].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert1x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert1y - 0.5 ) );
|
||||
v[1].m_TexCoord.Init( Segments[i].vert1x, Segments[i].vert1y );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 3, v );
|
||||
}
|
||||
|
||||
cur_wedge++;
|
||||
if ( cur_wedge >= 8)
|
||||
cur_wedge = 0;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/CircularProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CircularProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::CircularProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_iProgressDirection = CircularProgressBar::PROGRESS_CCW;
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
m_nTextureId[i] = -1;
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
m_iStartSegment = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::~CircularProgressBar()
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId[i] )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId[i] );
|
||||
m_nTextureId[i] = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName[i];
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
delete [] m_pszImageName[i];
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("fg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetFgImage( imageName );
|
||||
}
|
||||
imageName = inResourceData->GetString("bg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetBgImage( imageName );
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("CircularProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("CircularProgressBar.BgColor", pScheme));
|
||||
SetBorder(NULL);
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( m_pszImageName[i] && strlen( m_pszImageName[i] ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId[i] == -1 )
|
||||
{
|
||||
m_nTextureId[i] = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId[i], m_pszImageName[i], true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::SetImage(const char *imageName, progress_textures_t iPos)
|
||||
{
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
|
||||
if ( m_pszImageName[iPos] && ( m_lenImageName[iPos] < len ) )
|
||||
{
|
||||
// If we already have a buffer, but it is too short, then free the buffer
|
||||
delete [] m_pszImageName[iPos];
|
||||
m_pszImageName[iPos] = NULL;
|
||||
m_lenImageName[iPos] = 0;
|
||||
}
|
||||
|
||||
if ( !m_pszImageName[iPos] )
|
||||
{
|
||||
m_pszImageName[iPos] = new char[ len ];
|
||||
m_lenImageName[iPos] = len;
|
||||
}
|
||||
|
||||
Q_snprintf( m_pszImageName[iPos], len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::PaintBackground()
|
||||
{
|
||||
// If we don't have a Bg image, use the foreground
|
||||
int iTextureID = m_nTextureId[PROGRESS_TEXTURE_BG] != -1 ? m_nTextureId[PROGRESS_TEXTURE_BG] : m_nTextureId[PROGRESS_TEXTURE_FG];
|
||||
vgui::surface()->DrawSetTexture( iTextureID );
|
||||
vgui::surface()->DrawSetColor( GetBgColor() );
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::Paint()
|
||||
{
|
||||
float flProgress = GetProgress();
|
||||
float flEndAngle;
|
||||
|
||||
if ( m_iProgressDirection == PROGRESS_CW )
|
||||
{
|
||||
flEndAngle = flProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
flEndAngle = ( 1.0 - flProgress );
|
||||
}
|
||||
|
||||
DrawCircleSegment( GetFgColor(), flEndAngle, ( m_iProgressDirection == PROGRESS_CW ) );
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float minProgressRadians;
|
||||
|
||||
float vert1x;
|
||||
float vert1y;
|
||||
float vert2x;
|
||||
float vert2y;
|
||||
|
||||
int swipe_dir_x;
|
||||
int swipe_dir_y;
|
||||
} circular_progress_segment_t;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
// This defines the properties of the 8 circle segments
|
||||
// in the circular progress bar.
|
||||
circular_progress_segment_t Segments[8] =
|
||||
{
|
||||
{ 0.0, 0.5, 0.0, 1.0, 0.0, 1, 0 },
|
||||
{ M_PI * 0.25, 1.0, 0.0, 1.0, 0.5, 0, 1 },
|
||||
{ M_PI * 0.5, 1.0, 0.5, 1.0, 1.0, 0, 1 },
|
||||
{ M_PI * 0.75, 1.0, 1.0, 0.5, 1.0, -1, 0 },
|
||||
{ M_PI, 0.5, 1.0, 0.0, 1.0, -1, 0 },
|
||||
{ M_PI * 1.25, 0.0, 1.0, 0.0, 0.5, 0, -1 },
|
||||
{ M_PI * 1.5, 0.0, 0.5, 0.0, 0.0, 0, -1 },
|
||||
{ M_PI * 1.75, 0.0, 0.0, 0.5, 0.0, 1, 0 },
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#define SEGMENT_ANGLE ( M_PI / 4 )
|
||||
|
||||
// function to draw from A to B degrees, with a direction
|
||||
// we draw starting from the top ( 0 progress )
|
||||
void CircularProgressBar::DrawCircleSegment( Color c, float flEndProgress, bool bClockwise )
|
||||
{
|
||||
if ( m_nTextureId[PROGRESS_TEXTURE_FG] == -1 )
|
||||
return;
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
float flWide = (float)wide;
|
||||
float flTall = (float)tall;
|
||||
|
||||
float flHalfWide = (float)wide / 2;
|
||||
float flHalfTall = (float)tall / 2;
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId[PROGRESS_TEXTURE_FG] );
|
||||
vgui::surface()->DrawSetColor( c );
|
||||
|
||||
// TODO - if we want to progress CCW, reverse a few things
|
||||
|
||||
float flEndProgressRadians = flEndProgress * M_PI * 2;
|
||||
|
||||
int cur_wedge = m_iStartSegment;
|
||||
for ( int i=0;i<8;i++ )
|
||||
{
|
||||
if ( flEndProgressRadians > Segments[cur_wedge].minProgressRadians)
|
||||
{
|
||||
vgui::Vertex_t v[3];
|
||||
|
||||
// vert 0 is ( 0.5, 0.5 )
|
||||
v[0].m_Position.Init( flHalfWide, flHalfTall );
|
||||
v[0].m_TexCoord.Init( 0.5f, 0.5f );
|
||||
|
||||
float flInternalProgress = flEndProgressRadians - Segments[cur_wedge].minProgressRadians;
|
||||
|
||||
if ( flInternalProgress < SEGMENT_ANGLE )
|
||||
{
|
||||
// Calc how much of this slice we should be drawing
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flInternalProgress = SEGMENT_ANGLE - flInternalProgress;
|
||||
}
|
||||
|
||||
float flTan = tan(flInternalProgress);
|
||||
|
||||
float flDeltaX, flDeltaY;
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flDeltaX = ( flHalfWide - flHalfTall * flTan ) * Segments[i].swipe_dir_x;
|
||||
flDeltaY = ( flHalfTall - flHalfWide * flTan ) * Segments[i].swipe_dir_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
flDeltaX = flHalfTall * flTan * Segments[i].swipe_dir_x;
|
||||
flDeltaY = flHalfWide * flTan * Segments[i].swipe_dir_y;
|
||||
}
|
||||
|
||||
v[2].m_Position.Init( Segments[i].vert1x * flWide + flDeltaX, Segments[i].vert1y * flTall + flDeltaY );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert1x + ( flDeltaX / flHalfWide ) * 0.5, Segments[i].vert1y + ( flDeltaY / flHalfTall ) * 0.5 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// full segment, easy calculation
|
||||
v[2].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert2x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert2y - 0.5 ) );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert2x, Segments[i].vert2y );
|
||||
}
|
||||
|
||||
// vert 2 is ( Segments[i].vert1x, Segments[i].vert1y )
|
||||
v[1].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert1x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert1y - 0.5 ) );
|
||||
v[1].m_TexCoord.Init( Segments[i].vert1x, Segments[i].vert1y );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 3, v );
|
||||
}
|
||||
|
||||
cur_wedge++;
|
||||
if ( cur_wedge >= 8)
|
||||
cur_wedge = 0;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,160 +1,160 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/ControllerMap.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
struct keystring_t
|
||||
{
|
||||
int code;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
static const keystring_t s_ControllerButtons[] = { { KEY_XBUTTON_UP, "KEY_XBUTTON_UP" },
|
||||
{ KEY_XBUTTON_DOWN, "KEY_XBUTTON_DOWN" },
|
||||
{ KEY_XBUTTON_LEFT, "KEY_XBUTTON_LEFT" },
|
||||
{ KEY_XBUTTON_RIGHT, "KEY_XBUTTON_RIGHT" },
|
||||
{ KEY_XBUTTON_START, "KEY_XBUTTON_START" },
|
||||
{ KEY_XBUTTON_BACK, "KEY_XBUTTON_BACK" },
|
||||
{ KEY_XBUTTON_STICK1, "KEY_XBUTTON_STICK1" },
|
||||
{ KEY_XBUTTON_STICK2, "KEY_XBUTTON_STICK2" },
|
||||
{ KEY_XBUTTON_A, "KEY_XBUTTON_A" },
|
||||
{ KEY_XBUTTON_B, "KEY_XBUTTON_B" },
|
||||
{ KEY_XBUTTON_X, "KEY_XBUTTON_X" },
|
||||
{ KEY_XBUTTON_Y, "KEY_XBUTTON_Y" },
|
||||
{ KEY_XBUTTON_LEFT_SHOULDER, "KEY_XBUTTON_LEFT_SHOULDER" },
|
||||
{ KEY_XBUTTON_RIGHT_SHOULDER, "KEY_XBUTTON_RIGHT_SHOULDER" },
|
||||
{ KEY_XBUTTON_LTRIGGER, "KEY_XBUTTON_LTRIGGER" },
|
||||
{ KEY_XBUTTON_RTRIGGER, "KEY_XBUTTON_RTRIGGER" },
|
||||
{ KEY_XSTICK1_UP, "KEY_XSTICK1_UP" },
|
||||
{ KEY_XSTICK1_DOWN, "KEY_XSTICK1_DOWN" },
|
||||
{ KEY_XSTICK1_LEFT, "KEY_XSTICK1_LEFT" },
|
||||
{ KEY_XSTICK1_RIGHT, "KEY_XSTICK1_RIGHT" },
|
||||
{ KEY_XSTICK2_UP, "KEY_XSTICK2_UP" },
|
||||
{ KEY_XSTICK2_DOWN, "KEY_XSTICK2_DOWN" },
|
||||
{ KEY_XSTICK2_LEFT, "KEY_XSTICK2_LEFT" },
|
||||
{ KEY_XSTICK2_RIGHT, "KEY_XSTICK2_RIGHT" } };
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: for the UtlMap
|
||||
//-----------------------------------------------------------------------------
|
||||
bool lessFunc( const int &lhs, const int &rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: converts a button name string to the equivalent keycode
|
||||
//-----------------------------------------------------------------------------
|
||||
int StringToButtonCode( const char *name )
|
||||
{
|
||||
for ( int i = 0; i < ARRAYSIZE( s_ControllerButtons ); ++i )
|
||||
{
|
||||
if ( !Q_stricmp( s_ControllerButtons[i].name, name ) )
|
||||
return s_ControllerButtons[i].code;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: intercepts the keycode from its parent, and handles it according to
|
||||
// the button map. If the keycode isn't handled, it gets passed on to the parent.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CControllerMap::OnKeyCodeTyped( vgui::KeyCode code )
|
||||
{
|
||||
int idx = m_buttonMap.Find( code );
|
||||
if ( idx != m_buttonMap.InvalidIndex() )
|
||||
{
|
||||
GetParent()->OnCommand( m_buttonMap[idx].cmd.String() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable input before forwarding the message
|
||||
// so it doesn't feed back here again.
|
||||
SetKeyBoardInputEnabled( false );
|
||||
GetParent()->OnKeyCodeTyped( code );
|
||||
SetKeyBoardInputEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CControllerMap::CControllerMap( vgui::Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_buttonMap.SetLessFunc( lessFunc );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up the button/command bindings
|
||||
//-----------------------------------------------------------------------------
|
||||
void CControllerMap::ApplySettings( KeyValues *inResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
|
||||
// loop through all the data adding items to the menu
|
||||
for (KeyValues *dat = inResourceData->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey())
|
||||
{
|
||||
if ( !Q_stricmp( dat->GetName(), "button" ) )
|
||||
{
|
||||
const char *buttonName = dat->GetString( "name", "" );
|
||||
int keycode = StringToButtonCode( buttonName );
|
||||
if ( keycode != -1 )
|
||||
{
|
||||
button_t b;
|
||||
b.cmd = CUtlSymbol( dat->GetString( "command", "" ) );
|
||||
|
||||
// text and icon are optional - their existence means this button
|
||||
// should be displayed in the footer panel.
|
||||
const char *helpText = dat->GetString( "text", NULL );
|
||||
if ( helpText )
|
||||
{
|
||||
b.text = CUtlSymbol( helpText );
|
||||
b.icon = CUtlSymbol( dat->GetString( "icon", NULL ) );
|
||||
}
|
||||
|
||||
m_buttonMap.Insert( keycode, b );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the help text for a binding, if it exists
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CControllerMap::GetBindingText( int idx )
|
||||
{
|
||||
CUtlSymbol s = m_buttonMap[idx].text;
|
||||
if ( s.IsValid() )
|
||||
{
|
||||
return s.String();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the icon for a binding, if it exists
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CControllerMap::GetBindingIcon( int idx )
|
||||
{
|
||||
CUtlSymbol s = m_buttonMap[idx].icon;
|
||||
if ( s.IsValid() )
|
||||
{
|
||||
return s.String();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY( CControllerMap );
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/ControllerMap.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
struct keystring_t
|
||||
{
|
||||
int code;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
static const keystring_t s_ControllerButtons[] = { { KEY_XBUTTON_UP, "KEY_XBUTTON_UP" },
|
||||
{ KEY_XBUTTON_DOWN, "KEY_XBUTTON_DOWN" },
|
||||
{ KEY_XBUTTON_LEFT, "KEY_XBUTTON_LEFT" },
|
||||
{ KEY_XBUTTON_RIGHT, "KEY_XBUTTON_RIGHT" },
|
||||
{ KEY_XBUTTON_START, "KEY_XBUTTON_START" },
|
||||
{ KEY_XBUTTON_BACK, "KEY_XBUTTON_BACK" },
|
||||
{ KEY_XBUTTON_STICK1, "KEY_XBUTTON_STICK1" },
|
||||
{ KEY_XBUTTON_STICK2, "KEY_XBUTTON_STICK2" },
|
||||
{ KEY_XBUTTON_A, "KEY_XBUTTON_A" },
|
||||
{ KEY_XBUTTON_B, "KEY_XBUTTON_B" },
|
||||
{ KEY_XBUTTON_X, "KEY_XBUTTON_X" },
|
||||
{ KEY_XBUTTON_Y, "KEY_XBUTTON_Y" },
|
||||
{ KEY_XBUTTON_LEFT_SHOULDER, "KEY_XBUTTON_LEFT_SHOULDER" },
|
||||
{ KEY_XBUTTON_RIGHT_SHOULDER, "KEY_XBUTTON_RIGHT_SHOULDER" },
|
||||
{ KEY_XBUTTON_LTRIGGER, "KEY_XBUTTON_LTRIGGER" },
|
||||
{ KEY_XBUTTON_RTRIGGER, "KEY_XBUTTON_RTRIGGER" },
|
||||
{ KEY_XSTICK1_UP, "KEY_XSTICK1_UP" },
|
||||
{ KEY_XSTICK1_DOWN, "KEY_XSTICK1_DOWN" },
|
||||
{ KEY_XSTICK1_LEFT, "KEY_XSTICK1_LEFT" },
|
||||
{ KEY_XSTICK1_RIGHT, "KEY_XSTICK1_RIGHT" },
|
||||
{ KEY_XSTICK2_UP, "KEY_XSTICK2_UP" },
|
||||
{ KEY_XSTICK2_DOWN, "KEY_XSTICK2_DOWN" },
|
||||
{ KEY_XSTICK2_LEFT, "KEY_XSTICK2_LEFT" },
|
||||
{ KEY_XSTICK2_RIGHT, "KEY_XSTICK2_RIGHT" } };
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: for the UtlMap
|
||||
//-----------------------------------------------------------------------------
|
||||
bool lessFunc( const int &lhs, const int &rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: converts a button name string to the equivalent keycode
|
||||
//-----------------------------------------------------------------------------
|
||||
int StringToButtonCode( const char *name )
|
||||
{
|
||||
for ( int i = 0; i < ARRAYSIZE( s_ControllerButtons ); ++i )
|
||||
{
|
||||
if ( !Q_stricmp( s_ControllerButtons[i].name, name ) )
|
||||
return s_ControllerButtons[i].code;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: intercepts the keycode from its parent, and handles it according to
|
||||
// the button map. If the keycode isn't handled, it gets passed on to the parent.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CControllerMap::OnKeyCodeTyped( vgui::KeyCode code )
|
||||
{
|
||||
int idx = m_buttonMap.Find( code );
|
||||
if ( idx != m_buttonMap.InvalidIndex() )
|
||||
{
|
||||
GetParent()->OnCommand( m_buttonMap[idx].cmd.String() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable input before forwarding the message
|
||||
// so it doesn't feed back here again.
|
||||
SetKeyBoardInputEnabled( false );
|
||||
GetParent()->OnKeyCodeTyped( code );
|
||||
SetKeyBoardInputEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CControllerMap::CControllerMap( vgui::Panel *parent, const char *name ) : BaseClass( parent, name )
|
||||
{
|
||||
m_buttonMap.SetLessFunc( lessFunc );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up the button/command bindings
|
||||
//-----------------------------------------------------------------------------
|
||||
void CControllerMap::ApplySettings( KeyValues *inResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
|
||||
// loop through all the data adding items to the menu
|
||||
for (KeyValues *dat = inResourceData->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey())
|
||||
{
|
||||
if ( !Q_stricmp( dat->GetName(), "button" ) )
|
||||
{
|
||||
const char *buttonName = dat->GetString( "name", "" );
|
||||
int keycode = StringToButtonCode( buttonName );
|
||||
if ( keycode != -1 )
|
||||
{
|
||||
button_t b;
|
||||
b.cmd = CUtlSymbol( dat->GetString( "command", "" ) );
|
||||
|
||||
// text and icon are optional - their existence means this button
|
||||
// should be displayed in the footer panel.
|
||||
const char *helpText = dat->GetString( "text", NULL );
|
||||
if ( helpText )
|
||||
{
|
||||
b.text = CUtlSymbol( helpText );
|
||||
b.icon = CUtlSymbol( dat->GetString( "icon", NULL ) );
|
||||
}
|
||||
|
||||
m_buttonMap.Insert( keycode, b );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the help text for a binding, if it exists
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CControllerMap::GetBindingText( int idx )
|
||||
{
|
||||
CUtlSymbol s = m_buttonMap[idx].text;
|
||||
if ( s.IsValid() )
|
||||
{
|
||||
return s.String();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the icon for a binding, if it exists
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CControllerMap::GetBindingIcon( int idx )
|
||||
{
|
||||
CUtlSymbol s = m_buttonMap[idx].icon;
|
||||
if ( s.IsValid() )
|
||||
{
|
||||
return s.String();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY( CControllerMap );
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,41 +1,41 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IScheme.h>
|
||||
|
||||
#include <vgui_controls/Divider.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( Divider );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Divider::Divider(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
SetSize(128, 2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Divider::~Divider()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up the border as the line to draw as a divider
|
||||
//-----------------------------------------------------------------------------
|
||||
void Divider::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IScheme.h>
|
||||
|
||||
#include <vgui_controls/Divider.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( Divider );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Divider::Divider(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
SetSize(128, 2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Divider::~Divider()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up the border as the line to draw as a divider
|
||||
//-----------------------------------------------------------------------------
|
||||
void Divider::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,114 +1,114 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/ExpandButton.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ExpandButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ExpandButton::ExpandButton( Panel *parent, const char *panelName ) : ToggleButton( parent, panelName, "" )
|
||||
{
|
||||
m_bExpandable = true;
|
||||
m_hFont = INVALID_FONT;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ExpandButton::~ExpandButton()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
m_Color = GetSchemeColor( "ExpandButton.Color", pScheme );
|
||||
m_hFont = pScheme->GetFont("Marlett", IsProportional() );
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *ExpandButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Expand the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::SetSelected(bool state)
|
||||
{
|
||||
if ( m_bExpandable && ( state != IsSelected() ) )
|
||||
{
|
||||
// send a message saying we've been checked
|
||||
KeyValues *msg = new KeyValues("Expanded", "state", (int)state);
|
||||
PostActionSignal(msg);
|
||||
|
||||
BaseClass::SetSelected(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the state of the check can be changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::SetExpandable(bool state)
|
||||
{
|
||||
m_bExpandable = state;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
|
||||
void ExpandButton::Paint()
|
||||
{
|
||||
surface()->DrawSetTextFont( m_hFont );
|
||||
|
||||
wchar_t code = IsSelected( ) ? L'6' : L'4';
|
||||
wchar_t pString[2] = { code, 0 };
|
||||
|
||||
// draw selected check
|
||||
int tw, th, w, h;
|
||||
GetSize( w, h );
|
||||
surface()->GetTextSize( m_hFont, pString, tw, th );
|
||||
surface()->DrawSetTextColor( m_Color );
|
||||
surface()->DrawSetTextPos( ( w - tw ) / 2, ( h - th ) / 2 );
|
||||
surface()->DrawUnicodeChar( code );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::OnExpanded(Panel *panel)
|
||||
{
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/ExpandButton.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ExpandButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ExpandButton::ExpandButton( Panel *parent, const char *panelName ) : ToggleButton( parent, panelName, "" )
|
||||
{
|
||||
m_bExpandable = true;
|
||||
m_hFont = INVALID_FONT;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ExpandButton::~ExpandButton()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
m_Color = GetSchemeColor( "ExpandButton.Color", pScheme );
|
||||
m_hFont = pScheme->GetFont("Marlett", IsProportional() );
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *ExpandButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Expand the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::SetSelected(bool state)
|
||||
{
|
||||
if ( m_bExpandable && ( state != IsSelected() ) )
|
||||
{
|
||||
// send a message saying we've been checked
|
||||
KeyValues *msg = new KeyValues("Expanded", "state", (int)state);
|
||||
PostActionSignal(msg);
|
||||
|
||||
BaseClass::SetSelected(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the state of the check can be changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::SetExpandable(bool state)
|
||||
{
|
||||
m_bExpandable = state;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
|
||||
void ExpandButton::Paint()
|
||||
{
|
||||
surface()->DrawSetTextFont( m_hFont );
|
||||
|
||||
wchar_t code = IsSelected( ) ? L'6' : L'4';
|
||||
wchar_t pString[2] = { code, 0 };
|
||||
|
||||
// draw selected check
|
||||
int tw, th, w, h;
|
||||
GetSize( w, h );
|
||||
surface()->GetTextSize( m_hFont, pString, tw, th );
|
||||
surface()->DrawSetTextColor( m_Color );
|
||||
surface()->DrawSetTextPos( ( w - tw ) / 2, ( h - th ) / 2 );
|
||||
surface()->DrawUnicodeChar( code );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ExpandButton::OnExpanded(Panel *panel)
|
||||
{
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,497 +1,497 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// This is a helper class designed to help with the chains of modal dialogs
|
||||
// encountered when trying to open or save a particular file
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/FileOpenStateMachine.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui_controls/FileOpenDialog.h"
|
||||
#include "vgui_controls/MessageBox.h"
|
||||
#include "vgui_controls/perforcefilelistframe.h"
|
||||
#include "vgui_controls/savedocumentquery.h"
|
||||
#include "filesystem.h"
|
||||
#include "p4lib/ip4.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "tier0/icommandline.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
FileOpenStateMachine::FileOpenStateMachine( vgui::Panel *pParent, IFileOpenStateMachineClient *pClient ) : BaseClass( pParent, "FileOpenStateMachine" )
|
||||
{
|
||||
m_pClient = pClient;
|
||||
m_CompletionState = SUCCESSFUL;
|
||||
m_CurrentState = STATE_NONE;
|
||||
m_pContextKeyValues = NULL;
|
||||
SetVisible( false );
|
||||
}
|
||||
|
||||
FileOpenStateMachine::~FileOpenStateMachine()
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cleans up keyvalues
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::CleanUpContextKeyValues()
|
||||
{
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
m_pContextKeyValues->deleteThis();
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the state machine completion state
|
||||
//-----------------------------------------------------------------------------
|
||||
FileOpenStateMachine::CompletionState_t FileOpenStateMachine::GetCompletionState()
|
||||
{
|
||||
return m_CompletionState;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility to set the completion state
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::SetCompletionState( FileOpenStateMachine::CompletionState_t state )
|
||||
{
|
||||
m_CompletionState = state;
|
||||
if ( m_CompletionState == IN_PROGRESS )
|
||||
return;
|
||||
|
||||
m_CurrentState = STATE_NONE;
|
||||
|
||||
KeyValues *kv = new KeyValues( "FileStateMachineFinished" );
|
||||
kv->SetInt( "completionState", m_CompletionState );
|
||||
kv->SetInt( "wroteFile", m_bWroteFile );
|
||||
kv->SetString( "fullPath", m_FileName.Get() );
|
||||
kv->SetString( "fileType", m_bIsOpeningFile ? m_OpenFileType.Get() : m_SaveFileType.Get() );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the message box in OverwriteFileDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnOverwriteFile( )
|
||||
{
|
||||
CheckOutDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelOverwriteFile( )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_OVERWRITTEN );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the overwrite existing file dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OverwriteFileDialog( )
|
||||
{
|
||||
if ( !g_pFullFileSystem->FileExists( m_FileName ) )
|
||||
{
|
||||
CheckOutDialog( );
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentState = STATE_SHOWING_OVERWRITE_DIALOG;
|
||||
|
||||
char pBuf[1024];
|
||||
Q_snprintf( pBuf, sizeof(pBuf), "File already exists. Overwrite it?\n\n\"%s\"\n", m_FileName.Get() );
|
||||
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Overwrite Existing File?", pBuf, GetParent() );
|
||||
pMessageBox->AddActionSignalTarget( this );
|
||||
pMessageBox->SetOKButtonVisible( true );
|
||||
pMessageBox->SetOKButtonText( "Yes" );
|
||||
pMessageBox->SetCancelButtonVisible( true );
|
||||
pMessageBox->SetCancelButtonText( "No" );
|
||||
pMessageBox->SetCloseButtonVisible( false );
|
||||
pMessageBox->SetCommand( new KeyValues( "OverwriteFile" ) );
|
||||
pMessageBox->SetCancelCommand( new KeyValues( "CancelOverwriteFile" ) );
|
||||
pMessageBox->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnFileSelectionCancelled()
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_SAVE_DIALOG )
|
||||
{
|
||||
SetCompletionState( FILE_SAVE_NAME_NOT_SPECIFIED );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_OPEN_DIALOG )
|
||||
{
|
||||
SetCompletionState( FILE_OPEN_NAME_NOT_SPECIFIED );
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnFileSelected( KeyValues *pKeyValues )
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_SAVE_DIALOG )
|
||||
{
|
||||
m_FileName = pKeyValues->GetString( "fullpath" );
|
||||
const char *pFilterInfo = pKeyValues->GetString( "filterinfo" );
|
||||
if ( pFilterInfo )
|
||||
{
|
||||
m_SaveFileType = pFilterInfo;
|
||||
}
|
||||
OverwriteFileDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_OPEN_DIALOG )
|
||||
{
|
||||
m_FileName = pKeyValues->GetString( "fullpath" );
|
||||
const char *pFilterInfo = pKeyValues->GetString( "filterinfo" );
|
||||
if ( pFilterInfo )
|
||||
{
|
||||
m_OpenFileType = pFilterInfo;
|
||||
}
|
||||
ReadFile( );
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Writes the file out
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::WriteFile()
|
||||
{
|
||||
m_CurrentState = STATE_WRITING_FILE;
|
||||
if ( !m_pClient->OnWriteFileToDisk( m_FileName, m_SaveFileType, m_pContextKeyValues ) )
|
||||
{
|
||||
SetCompletionState( ERROR_WRITING_FILE );
|
||||
return;
|
||||
}
|
||||
|
||||
m_bWroteFile = true;
|
||||
if ( m_bShowPerforceDialogs )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_PERFORCE_ADD_DIALOG;
|
||||
ShowPerforceQuery( GetParent(), m_FileName, this, NULL, PERFORCE_ACTION_FILE_ADD );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the message box in MakeFileWriteableDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnMakeFileWriteable( )
|
||||
{
|
||||
if ( !g_pFullFileSystem->SetFileWritable( m_FileName, true ) )
|
||||
{
|
||||
SetCompletionState( ERROR_MAKING_FILE_WRITEABLE );
|
||||
return;
|
||||
}
|
||||
|
||||
WriteFile();
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelMakeFileWriteable( )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_MADE_WRITEABLE );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the make file writeable dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::MakeFileWriteableDialog( )
|
||||
{
|
||||
// If the file is writeable, write it!
|
||||
if ( !g_pFullFileSystem->FileExists( m_FileName ) || g_pFullFileSystem->IsFileWritable( m_FileName ) )
|
||||
{
|
||||
WriteFile();
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's in perforce, and not checked out, then we must abort.
|
||||
bool bIsInPerforce = p4->IsFileInPerforce( m_FileName );
|
||||
bool bIsOpened = ( p4->GetFileState( m_FileName ) != P4FILE_UNOPENED );
|
||||
if ( bIsInPerforce && !bIsOpened )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_CHECKED_OUT );
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentState = STATE_SHOWING_MAKE_FILE_WRITEABLE_DIALOG;
|
||||
|
||||
char pBuf[1024];
|
||||
Q_snprintf( pBuf, sizeof(pBuf), "Encountered read-only file. Should it be made writeable?\n\n\"%s\"\n", m_FileName.Get() );
|
||||
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Make File Writeable?", pBuf, GetParent() );
|
||||
pMessageBox->AddActionSignalTarget( this );
|
||||
pMessageBox->SetOKButtonVisible( true );
|
||||
pMessageBox->SetOKButtonText( "Yes" );
|
||||
pMessageBox->SetCancelButtonVisible( true );
|
||||
pMessageBox->SetCancelButtonText( "No" );
|
||||
pMessageBox->SetCloseButtonVisible( false );
|
||||
pMessageBox->SetCommand( new KeyValues( "MakeFileWriteable" ) );
|
||||
pMessageBox->SetCancelCommand( new KeyValues( "CancelMakeFileWriteable" ) );
|
||||
pMessageBox->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when ShowPerforceQuery completes
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnPerforceQueryCompleted( KeyValues *pKeyValues )
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_CHECK_OUT_DIALOG )
|
||||
{
|
||||
if ( pKeyValues->GetInt( "operationPerformed" ) == 0 )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_CHECKED_OUT );
|
||||
return;
|
||||
}
|
||||
|
||||
MakeFileWriteableDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_PERFORCE_ADD_DIALOG )
|
||||
{
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::CheckOutDialog( )
|
||||
{
|
||||
if ( m_bShowPerforceDialogs )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_CHECK_OUT_DIALOG;
|
||||
ShowPerforceQuery( GetParent(), m_FileName, this, NULL, PERFORCE_ACTION_FILE_EDIT );
|
||||
return;
|
||||
}
|
||||
|
||||
WriteFile();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These 3 messages come from the savedocumentquery dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnSaveFile()
|
||||
{
|
||||
if ( !m_FileName[0] || !Q_IsAbsolutePath( m_FileName ) )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_SAVE_DIALOG;
|
||||
|
||||
FileOpenDialog *pDialog = new FileOpenDialog( GetParent(), "Save As", false );
|
||||
m_pClient->SetupFileOpenDialog( pDialog, false, m_SaveFileType, m_pContextKeyValues );
|
||||
pDialog->SetDeleteSelfOnClose( true );
|
||||
pDialog->AddActionSignalTarget( this );
|
||||
pDialog->DoModal( );
|
||||
return;
|
||||
}
|
||||
|
||||
CheckOutDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnMarkNotDirty()
|
||||
{
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
// Jump right to opening the file
|
||||
OpenFileDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelSaveDocument()
|
||||
{
|
||||
SetCompletionState( FILE_SAVE_CANCELLED );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::ShowSaveQuery( )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_SAVE_DIRTY_FILE_DIALOG;
|
||||
ShowSaveDocumentQuery( GetParent(), m_FileName, m_SaveFileType, 0, this, NULL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to save a specified file, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::SaveFile( KeyValues *pContextKeyValues, const char *pFileName, const char *pFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pFileName;
|
||||
m_SaveFileType = pFileType;
|
||||
m_OpenFileType = NULL;
|
||||
m_OpenFileName = NULL;
|
||||
|
||||
// Clear the P4 dialog flag for SDK users and licensees without Perforce
|
||||
if ( CommandLine()->FindParm( "-nop4" ) )
|
||||
{
|
||||
nFlags &= ~FOSM_SHOW_PERFORCE_DIALOGS;
|
||||
}
|
||||
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = false;
|
||||
m_bWroteFile = false;
|
||||
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OnSaveFile();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reads the file in
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::ReadFile()
|
||||
{
|
||||
m_CurrentState = STATE_READING_FILE;
|
||||
if ( !m_pClient->OnReadFileFromDisk( m_FileName, m_OpenFileType, m_pContextKeyValues ) )
|
||||
{
|
||||
SetCompletionState( ERROR_READING_FILE );
|
||||
return;
|
||||
}
|
||||
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the open file dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFileDialog( )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_OPEN_DIALOG;
|
||||
|
||||
if ( m_OpenFileName.IsEmpty() )
|
||||
{
|
||||
FileOpenDialog *pDialog = new FileOpenDialog( GetParent(), "Open", true );
|
||||
m_pClient->SetupFileOpenDialog( pDialog, true, m_OpenFileType, m_pContextKeyValues );
|
||||
pDialog->SetDeleteSelfOnClose( true );
|
||||
pDialog->AddActionSignalTarget( this );
|
||||
pDialog->DoModal( );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FileName = m_OpenFileName;
|
||||
ReadFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens a file, saves an existing one if necessary
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFile( const char *pOpenFileType, KeyValues *pContextKeyValues, const char *pSaveFileName, const char *pSaveFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pSaveFileName;
|
||||
m_SaveFileType = pSaveFileType;
|
||||
m_OpenFileType = pOpenFileType;
|
||||
m_OpenFileName = NULL;
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = true;
|
||||
m_bWroteFile = false;
|
||||
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Version of OpenFile that skips browsing for a particular file to open
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFile( const char *pOpenFileName, const char *pOpenFileType, KeyValues *pContextKeyValues, const char *pSaveFileName, const char *pSaveFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pSaveFileName;
|
||||
m_SaveFileType = pSaveFileType;
|
||||
m_OpenFileType = pOpenFileType;
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = true;
|
||||
m_bWroteFile = false;
|
||||
m_OpenFileName = pOpenFileName;
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// This is a helper class designed to help with the chains of modal dialogs
|
||||
// encountered when trying to open or save a particular file
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/FileOpenStateMachine.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui_controls/FileOpenDialog.h"
|
||||
#include "vgui_controls/MessageBox.h"
|
||||
#include "vgui_controls/perforcefilelistframe.h"
|
||||
#include "vgui_controls/savedocumentquery.h"
|
||||
#include "filesystem.h"
|
||||
#include "p4lib/ip4.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "tier0/icommandline.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
FileOpenStateMachine::FileOpenStateMachine( vgui::Panel *pParent, IFileOpenStateMachineClient *pClient ) : BaseClass( pParent, "FileOpenStateMachine" )
|
||||
{
|
||||
m_pClient = pClient;
|
||||
m_CompletionState = SUCCESSFUL;
|
||||
m_CurrentState = STATE_NONE;
|
||||
m_pContextKeyValues = NULL;
|
||||
SetVisible( false );
|
||||
}
|
||||
|
||||
FileOpenStateMachine::~FileOpenStateMachine()
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cleans up keyvalues
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::CleanUpContextKeyValues()
|
||||
{
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
m_pContextKeyValues->deleteThis();
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the state machine completion state
|
||||
//-----------------------------------------------------------------------------
|
||||
FileOpenStateMachine::CompletionState_t FileOpenStateMachine::GetCompletionState()
|
||||
{
|
||||
return m_CompletionState;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility to set the completion state
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::SetCompletionState( FileOpenStateMachine::CompletionState_t state )
|
||||
{
|
||||
m_CompletionState = state;
|
||||
if ( m_CompletionState == IN_PROGRESS )
|
||||
return;
|
||||
|
||||
m_CurrentState = STATE_NONE;
|
||||
|
||||
KeyValues *kv = new KeyValues( "FileStateMachineFinished" );
|
||||
kv->SetInt( "completionState", m_CompletionState );
|
||||
kv->SetInt( "wroteFile", m_bWroteFile );
|
||||
kv->SetString( "fullPath", m_FileName.Get() );
|
||||
kv->SetString( "fileType", m_bIsOpeningFile ? m_OpenFileType.Get() : m_SaveFileType.Get() );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the message box in OverwriteFileDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnOverwriteFile( )
|
||||
{
|
||||
CheckOutDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelOverwriteFile( )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_OVERWRITTEN );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the overwrite existing file dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OverwriteFileDialog( )
|
||||
{
|
||||
if ( !g_pFullFileSystem->FileExists( m_FileName ) )
|
||||
{
|
||||
CheckOutDialog( );
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentState = STATE_SHOWING_OVERWRITE_DIALOG;
|
||||
|
||||
char pBuf[1024];
|
||||
Q_snprintf( pBuf, sizeof(pBuf), "File already exists. Overwrite it?\n\n\"%s\"\n", m_FileName.Get() );
|
||||
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Overwrite Existing File?", pBuf, GetParent() );
|
||||
pMessageBox->AddActionSignalTarget( this );
|
||||
pMessageBox->SetOKButtonVisible( true );
|
||||
pMessageBox->SetOKButtonText( "Yes" );
|
||||
pMessageBox->SetCancelButtonVisible( true );
|
||||
pMessageBox->SetCancelButtonText( "No" );
|
||||
pMessageBox->SetCloseButtonVisible( false );
|
||||
pMessageBox->SetCommand( new KeyValues( "OverwriteFile" ) );
|
||||
pMessageBox->SetCancelCommand( new KeyValues( "CancelOverwriteFile" ) );
|
||||
pMessageBox->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnFileSelectionCancelled()
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_SAVE_DIALOG )
|
||||
{
|
||||
SetCompletionState( FILE_SAVE_NAME_NOT_SPECIFIED );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_OPEN_DIALOG )
|
||||
{
|
||||
SetCompletionState( FILE_OPEN_NAME_NOT_SPECIFIED );
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnFileSelected( KeyValues *pKeyValues )
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_SAVE_DIALOG )
|
||||
{
|
||||
m_FileName = pKeyValues->GetString( "fullpath" );
|
||||
const char *pFilterInfo = pKeyValues->GetString( "filterinfo" );
|
||||
if ( pFilterInfo )
|
||||
{
|
||||
m_SaveFileType = pFilterInfo;
|
||||
}
|
||||
OverwriteFileDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_OPEN_DIALOG )
|
||||
{
|
||||
m_FileName = pKeyValues->GetString( "fullpath" );
|
||||
const char *pFilterInfo = pKeyValues->GetString( "filterinfo" );
|
||||
if ( pFilterInfo )
|
||||
{
|
||||
m_OpenFileType = pFilterInfo;
|
||||
}
|
||||
ReadFile( );
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Writes the file out
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::WriteFile()
|
||||
{
|
||||
m_CurrentState = STATE_WRITING_FILE;
|
||||
if ( !m_pClient->OnWriteFileToDisk( m_FileName, m_SaveFileType, m_pContextKeyValues ) )
|
||||
{
|
||||
SetCompletionState( ERROR_WRITING_FILE );
|
||||
return;
|
||||
}
|
||||
|
||||
m_bWroteFile = true;
|
||||
if ( m_bShowPerforceDialogs )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_PERFORCE_ADD_DIALOG;
|
||||
ShowPerforceQuery( GetParent(), m_FileName, this, NULL, PERFORCE_ACTION_FILE_ADD );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the message box in MakeFileWriteableDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnMakeFileWriteable( )
|
||||
{
|
||||
if ( !g_pFullFileSystem->SetFileWritable( m_FileName, true ) )
|
||||
{
|
||||
SetCompletionState( ERROR_MAKING_FILE_WRITEABLE );
|
||||
return;
|
||||
}
|
||||
|
||||
WriteFile();
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelMakeFileWriteable( )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_MADE_WRITEABLE );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the make file writeable dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::MakeFileWriteableDialog( )
|
||||
{
|
||||
// If the file is writeable, write it!
|
||||
if ( !g_pFullFileSystem->FileExists( m_FileName ) || g_pFullFileSystem->IsFileWritable( m_FileName ) )
|
||||
{
|
||||
WriteFile();
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's in perforce, and not checked out, then we must abort.
|
||||
bool bIsInPerforce = p4->IsFileInPerforce( m_FileName );
|
||||
bool bIsOpened = ( p4->GetFileState( m_FileName ) != P4FILE_UNOPENED );
|
||||
if ( bIsInPerforce && !bIsOpened )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_CHECKED_OUT );
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentState = STATE_SHOWING_MAKE_FILE_WRITEABLE_DIALOG;
|
||||
|
||||
char pBuf[1024];
|
||||
Q_snprintf( pBuf, sizeof(pBuf), "Encountered read-only file. Should it be made writeable?\n\n\"%s\"\n", m_FileName.Get() );
|
||||
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Make File Writeable?", pBuf, GetParent() );
|
||||
pMessageBox->AddActionSignalTarget( this );
|
||||
pMessageBox->SetOKButtonVisible( true );
|
||||
pMessageBox->SetOKButtonText( "Yes" );
|
||||
pMessageBox->SetCancelButtonVisible( true );
|
||||
pMessageBox->SetCancelButtonText( "No" );
|
||||
pMessageBox->SetCloseButtonVisible( false );
|
||||
pMessageBox->SetCommand( new KeyValues( "MakeFileWriteable" ) );
|
||||
pMessageBox->SetCancelCommand( new KeyValues( "CancelMakeFileWriteable" ) );
|
||||
pMessageBox->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when ShowPerforceQuery completes
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnPerforceQueryCompleted( KeyValues *pKeyValues )
|
||||
{
|
||||
if ( m_CurrentState == STATE_SHOWING_CHECK_OUT_DIALOG )
|
||||
{
|
||||
if ( pKeyValues->GetInt( "operationPerformed" ) == 0 )
|
||||
{
|
||||
SetCompletionState( FILE_NOT_CHECKED_OUT );
|
||||
return;
|
||||
}
|
||||
|
||||
MakeFileWriteableDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_CurrentState == STATE_SHOWING_PERFORCE_ADD_DIALOG )
|
||||
{
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to open a particular file in perforce, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::CheckOutDialog( )
|
||||
{
|
||||
if ( m_bShowPerforceDialogs )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_CHECK_OUT_DIALOG;
|
||||
ShowPerforceQuery( GetParent(), m_FileName, this, NULL, PERFORCE_ACTION_FILE_EDIT );
|
||||
return;
|
||||
}
|
||||
|
||||
WriteFile();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These 3 messages come from the savedocumentquery dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OnSaveFile()
|
||||
{
|
||||
if ( !m_FileName[0] || !Q_IsAbsolutePath( m_FileName ) )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_SAVE_DIALOG;
|
||||
|
||||
FileOpenDialog *pDialog = new FileOpenDialog( GetParent(), "Save As", false );
|
||||
m_pClient->SetupFileOpenDialog( pDialog, false, m_SaveFileType, m_pContextKeyValues );
|
||||
pDialog->SetDeleteSelfOnClose( true );
|
||||
pDialog->AddActionSignalTarget( this );
|
||||
pDialog->DoModal( );
|
||||
return;
|
||||
}
|
||||
|
||||
CheckOutDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnMarkNotDirty()
|
||||
{
|
||||
if ( !m_bIsOpeningFile )
|
||||
{
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
return;
|
||||
}
|
||||
|
||||
// Jump right to opening the file
|
||||
OpenFileDialog( );
|
||||
}
|
||||
|
||||
void FileOpenStateMachine::OnCancelSaveDocument()
|
||||
{
|
||||
SetCompletionState( FILE_SAVE_CANCELLED );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::ShowSaveQuery( )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_SAVE_DIRTY_FILE_DIALOG;
|
||||
ShowSaveDocumentQuery( GetParent(), m_FileName, m_SaveFileType, 0, this, NULL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to save a specified file, and deal with all the lovely dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::SaveFile( KeyValues *pContextKeyValues, const char *pFileName, const char *pFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pFileName;
|
||||
m_SaveFileType = pFileType;
|
||||
m_OpenFileType = NULL;
|
||||
m_OpenFileName = NULL;
|
||||
|
||||
// Clear the P4 dialog flag for SDK users and licensees without Perforce
|
||||
if ( CommandLine()->FindParm( "-nop4" ) )
|
||||
{
|
||||
nFlags &= ~FOSM_SHOW_PERFORCE_DIALOGS;
|
||||
}
|
||||
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = false;
|
||||
m_bWroteFile = false;
|
||||
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OnSaveFile();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reads the file in
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::ReadFile()
|
||||
{
|
||||
m_CurrentState = STATE_READING_FILE;
|
||||
if ( !m_pClient->OnReadFileFromDisk( m_FileName, m_OpenFileType, m_pContextKeyValues ) )
|
||||
{
|
||||
SetCompletionState( ERROR_READING_FILE );
|
||||
return;
|
||||
}
|
||||
|
||||
SetCompletionState( SUCCESSFUL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the open file dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFileDialog( )
|
||||
{
|
||||
m_CurrentState = STATE_SHOWING_OPEN_DIALOG;
|
||||
|
||||
if ( m_OpenFileName.IsEmpty() )
|
||||
{
|
||||
FileOpenDialog *pDialog = new FileOpenDialog( GetParent(), "Open", true );
|
||||
m_pClient->SetupFileOpenDialog( pDialog, true, m_OpenFileType, m_pContextKeyValues );
|
||||
pDialog->SetDeleteSelfOnClose( true );
|
||||
pDialog->AddActionSignalTarget( this );
|
||||
pDialog->DoModal( );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FileName = m_OpenFileName;
|
||||
ReadFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens a file, saves an existing one if necessary
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFile( const char *pOpenFileType, KeyValues *pContextKeyValues, const char *pSaveFileName, const char *pSaveFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pSaveFileName;
|
||||
m_SaveFileType = pSaveFileType;
|
||||
m_OpenFileType = pOpenFileType;
|
||||
m_OpenFileName = NULL;
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = true;
|
||||
m_bWroteFile = false;
|
||||
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Version of OpenFile that skips browsing for a particular file to open
|
||||
//-----------------------------------------------------------------------------
|
||||
void FileOpenStateMachine::OpenFile( const char *pOpenFileName, const char *pOpenFileType, KeyValues *pContextKeyValues, const char *pSaveFileName, const char *pSaveFileType, int nFlags )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
SetCompletionState( IN_PROGRESS );
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
m_FileName = pSaveFileName;
|
||||
m_SaveFileType = pSaveFileType;
|
||||
m_OpenFileType = pOpenFileType;
|
||||
m_bShowPerforceDialogs = ( nFlags & FOSM_SHOW_PERFORCE_DIALOGS ) != 0;
|
||||
m_bShowSaveQuery = ( nFlags & FOSM_SHOW_SAVE_QUERY ) != 0;
|
||||
m_bIsOpeningFile = true;
|
||||
m_bWroteFile = false;
|
||||
m_OpenFileName = pOpenFileName;
|
||||
if ( m_bShowSaveQuery )
|
||||
{
|
||||
ShowSaveQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,433 +1,433 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/VGUI.h>
|
||||
#include <KeyValues.h>
|
||||
#include <tier0/dbg.h>
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/FocusNavGroup.h>
|
||||
#include <vgui_controls/Panel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
// Input : *panel - parent panel
|
||||
//-----------------------------------------------------------------------------
|
||||
FocusNavGroup::FocusNavGroup(Panel *panel) : _mainPanel(panel)
|
||||
{
|
||||
_currentFocus = NULL;
|
||||
_topLevelFocus = false;
|
||||
_defaultButton = NULL;
|
||||
_currentDefaultButton = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
FocusNavGroup::~FocusNavGroup()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the focus to the previous panel in the tab order
|
||||
// Input : *panel - panel currently with focus
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::RequestFocusPrev(VPANEL panel)
|
||||
{
|
||||
if(panel==0)
|
||||
return false;
|
||||
|
||||
_currentFocus = NULL;
|
||||
int newPosition = 9999999;
|
||||
if (panel)
|
||||
{
|
||||
newPosition = ipanel()->GetTabPosition(panel);
|
||||
}
|
||||
|
||||
bool bFound = false;
|
||||
bool bRepeat = true;
|
||||
Panel *best = NULL;
|
||||
while (1)
|
||||
{
|
||||
newPosition--;
|
||||
if (newPosition > 0)
|
||||
{
|
||||
int bestPosition = 0;
|
||||
|
||||
// look for the next tab position
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition())
|
||||
{
|
||||
int tabPosition = child->GetTabPosition();
|
||||
if (tabPosition == newPosition)
|
||||
{
|
||||
// we've found the right tab
|
||||
best = child;
|
||||
bestPosition = newPosition;
|
||||
|
||||
// don't loop anymore since we've found the correct panel
|
||||
break;
|
||||
}
|
||||
else if (tabPosition < newPosition && tabPosition > bestPosition)
|
||||
{
|
||||
// record the match since this is the closest so far
|
||||
bestPosition = tabPosition;
|
||||
best = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRepeat)
|
||||
break;
|
||||
|
||||
if (best)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset new position for next loop
|
||||
newPosition = 9999999;
|
||||
}
|
||||
|
||||
// haven't found an item
|
||||
|
||||
if (!_topLevelFocus)
|
||||
{
|
||||
// check to see if we should push the focus request up
|
||||
if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel())
|
||||
{
|
||||
// we're not a top level panel, so forward up the request instead of looping
|
||||
if (ipanel()->RequestFocusPrev(_mainPanel->GetVParent(), _mainPanel->GetVPanel()))
|
||||
{
|
||||
bFound = true;
|
||||
SetCurrentDefaultButton(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found an item, loop back
|
||||
newPosition = 9999999;
|
||||
bRepeat = false;
|
||||
}
|
||||
|
||||
if (best)
|
||||
{
|
||||
_currentFocus = best->GetVPanel();
|
||||
best->RequestFocus(-1);
|
||||
bFound = true;
|
||||
|
||||
if (!CanButtonBeDefault(best->GetVPanel()))
|
||||
{
|
||||
if (_defaultButton)
|
||||
{
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(NULL);
|
||||
|
||||
// we need to ask the parent to set its default button
|
||||
if (_mainPanel->GetVParent())
|
||||
{
|
||||
ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(best->GetVPanel());
|
||||
}
|
||||
}
|
||||
return bFound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the focus to the previous panel in the tab order
|
||||
// Input : *panel - panel currently with focus
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::RequestFocusNext(VPANEL panel)
|
||||
{
|
||||
// basic recursion guard, in case user has set up a bad focus hierarchy
|
||||
static int stack_depth = 0;
|
||||
stack_depth++;
|
||||
|
||||
_currentFocus = NULL;
|
||||
int newPosition = 0;
|
||||
if (panel)
|
||||
{
|
||||
newPosition = ipanel()->GetTabPosition(panel);
|
||||
}
|
||||
|
||||
bool bFound = false;
|
||||
bool bRepeat = true;
|
||||
Panel *best = NULL;
|
||||
while (1)
|
||||
{
|
||||
newPosition++;
|
||||
int bestPosition = 999999;
|
||||
|
||||
// look for the next tab position
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition())
|
||||
{
|
||||
int tabPosition = child->GetTabPosition();
|
||||
if (tabPosition == newPosition)
|
||||
{
|
||||
// we've found the right tab
|
||||
best = child;
|
||||
bestPosition = newPosition;
|
||||
|
||||
// don't loop anymore since we've found the correct panel
|
||||
break;
|
||||
}
|
||||
else if (tabPosition > newPosition && tabPosition < bestPosition)
|
||||
{
|
||||
// record the match since this is the closest so far
|
||||
bestPosition = tabPosition;
|
||||
best = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRepeat)
|
||||
break;
|
||||
|
||||
if (best)
|
||||
break;
|
||||
|
||||
// haven't found an item
|
||||
|
||||
// check to see if we should push the focus request up
|
||||
if (!_topLevelFocus)
|
||||
{
|
||||
if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel())
|
||||
{
|
||||
// we're not a top level panel, so forward up the request instead of looping
|
||||
if (stack_depth < 15)
|
||||
{
|
||||
if (ipanel()->RequestFocusNext(_mainPanel->GetVParent(), _mainPanel->GetVPanel()))
|
||||
{
|
||||
bFound = true;
|
||||
SetCurrentDefaultButton(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
// if we find one then we break, otherwise we loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loop back
|
||||
newPosition = 0;
|
||||
bRepeat = false;
|
||||
}
|
||||
|
||||
if (best)
|
||||
{
|
||||
_currentFocus = best->GetVPanel();
|
||||
best->RequestFocus(1);
|
||||
bFound = true;
|
||||
|
||||
if (!CanButtonBeDefault(best->GetVPanel()))
|
||||
{
|
||||
if (_defaultButton)
|
||||
{
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(NULL);
|
||||
|
||||
// we need to ask the parent to set its default button
|
||||
if (_mainPanel->GetVParent())
|
||||
{
|
||||
ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(best->GetVPanel());
|
||||
}
|
||||
}
|
||||
|
||||
stack_depth--;
|
||||
return bFound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the panel that owns this FocusNavGroup to be the root in the focus traversal heirarchy
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetFocusTopLevel(bool state)
|
||||
{
|
||||
_topLevelFocus = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetDefaultButton(Panel *panel)
|
||||
{
|
||||
VPANEL vpanel = panel ? panel->GetVPanel() : NULL;
|
||||
if ( vpanel == _defaultButton.Get() )
|
||||
return;
|
||||
|
||||
// Assert(CanButtonBeDefault(vpanel));
|
||||
|
||||
_defaultButton = vpanel;
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetCurrentDefaultButton(VPANEL panel, bool sendCurrentDefaultButtonMessage)
|
||||
{
|
||||
if (panel == _currentDefaultButton.Get())
|
||||
return;
|
||||
|
||||
if ( sendCurrentDefaultButtonMessage && _currentDefaultButton.Get() != 0)
|
||||
{
|
||||
ivgui()->PostMessage(_currentDefaultButton, new KeyValues("SetAsCurrentDefaultButton", "state", 0), NULL);
|
||||
}
|
||||
|
||||
_currentDefaultButton = panel;
|
||||
|
||||
if ( sendCurrentDefaultButtonMessage && _currentDefaultButton.Get() != 0)
|
||||
{
|
||||
ivgui()->PostMessage(_currentDefaultButton, new KeyValues("SetAsCurrentDefaultButton", "state", 1), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::GetCurrentDefaultButton()
|
||||
{
|
||||
return _currentDefaultButton;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::GetDefaultButton()
|
||||
{
|
||||
return _defaultButton;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: finds the panel which is activated by the specified key
|
||||
// Input : code - the keycode of the hotkey
|
||||
// Output : Panel * - NULL if no panel found
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::FindPanelByHotkey(wchar_t key)
|
||||
{
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
Panel *hot = child->HasHotkey(key);
|
||||
if (hot && hot->IsVisible() && hot->IsEnabled())
|
||||
{
|
||||
return hot;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::GetDefaultPanel()
|
||||
{
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
if (child->GetTabPosition() == 1)
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL; // no specific panel set
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::GetCurrentFocus()
|
||||
{
|
||||
return _currentFocus ? ipanel()->GetPanel(_currentFocus, vgui::GetControlsModuleName()) : NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the current focus
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::SetCurrentFocus(VPANEL focus, VPANEL defaultPanel)
|
||||
{
|
||||
_currentFocus = focus;
|
||||
|
||||
// if we haven't found a default panel yet, let's see if we know of one
|
||||
if (defaultPanel == 0)
|
||||
{
|
||||
// can this focus itself by the default
|
||||
if (CanButtonBeDefault(focus))
|
||||
{
|
||||
defaultPanel = focus;
|
||||
}
|
||||
else if (_defaultButton) // do we know of a default button
|
||||
{
|
||||
defaultPanel = _defaultButton;
|
||||
}
|
||||
}
|
||||
|
||||
SetCurrentDefaultButton(defaultPanel);
|
||||
return defaultPanel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns true if the specified panel can be the default
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::CanButtonBeDefault(VPANEL panel)
|
||||
{
|
||||
if( panel == 0 )
|
||||
return false;
|
||||
|
||||
KeyValues *data = new KeyValues("CanBeDefaultButton");
|
||||
|
||||
bool bResult = false;
|
||||
if (ipanel()->RequestInfo(panel, data))
|
||||
{
|
||||
bResult = (data->GetInt("result") == 1);
|
||||
}
|
||||
data->deleteThis();
|
||||
return bResult;
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/VGUI.h>
|
||||
#include <KeyValues.h>
|
||||
#include <tier0/dbg.h>
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/FocusNavGroup.h>
|
||||
#include <vgui_controls/Panel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
// Input : *panel - parent panel
|
||||
//-----------------------------------------------------------------------------
|
||||
FocusNavGroup::FocusNavGroup(Panel *panel) : _mainPanel(panel)
|
||||
{
|
||||
_currentFocus = NULL;
|
||||
_topLevelFocus = false;
|
||||
_defaultButton = NULL;
|
||||
_currentDefaultButton = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
FocusNavGroup::~FocusNavGroup()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the focus to the previous panel in the tab order
|
||||
// Input : *panel - panel currently with focus
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::RequestFocusPrev(VPANEL panel)
|
||||
{
|
||||
if(panel==0)
|
||||
return false;
|
||||
|
||||
_currentFocus = NULL;
|
||||
int newPosition = 9999999;
|
||||
if (panel)
|
||||
{
|
||||
newPosition = ipanel()->GetTabPosition(panel);
|
||||
}
|
||||
|
||||
bool bFound = false;
|
||||
bool bRepeat = true;
|
||||
Panel *best = NULL;
|
||||
while (1)
|
||||
{
|
||||
newPosition--;
|
||||
if (newPosition > 0)
|
||||
{
|
||||
int bestPosition = 0;
|
||||
|
||||
// look for the next tab position
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition())
|
||||
{
|
||||
int tabPosition = child->GetTabPosition();
|
||||
if (tabPosition == newPosition)
|
||||
{
|
||||
// we've found the right tab
|
||||
best = child;
|
||||
bestPosition = newPosition;
|
||||
|
||||
// don't loop anymore since we've found the correct panel
|
||||
break;
|
||||
}
|
||||
else if (tabPosition < newPosition && tabPosition > bestPosition)
|
||||
{
|
||||
// record the match since this is the closest so far
|
||||
bestPosition = tabPosition;
|
||||
best = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRepeat)
|
||||
break;
|
||||
|
||||
if (best)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset new position for next loop
|
||||
newPosition = 9999999;
|
||||
}
|
||||
|
||||
// haven't found an item
|
||||
|
||||
if (!_topLevelFocus)
|
||||
{
|
||||
// check to see if we should push the focus request up
|
||||
if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel())
|
||||
{
|
||||
// we're not a top level panel, so forward up the request instead of looping
|
||||
if (ipanel()->RequestFocusPrev(_mainPanel->GetVParent(), _mainPanel->GetVPanel()))
|
||||
{
|
||||
bFound = true;
|
||||
SetCurrentDefaultButton(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found an item, loop back
|
||||
newPosition = 9999999;
|
||||
bRepeat = false;
|
||||
}
|
||||
|
||||
if (best)
|
||||
{
|
||||
_currentFocus = best->GetVPanel();
|
||||
best->RequestFocus(-1);
|
||||
bFound = true;
|
||||
|
||||
if (!CanButtonBeDefault(best->GetVPanel()))
|
||||
{
|
||||
if (_defaultButton)
|
||||
{
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(NULL);
|
||||
|
||||
// we need to ask the parent to set its default button
|
||||
if (_mainPanel->GetVParent())
|
||||
{
|
||||
ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(best->GetVPanel());
|
||||
}
|
||||
}
|
||||
return bFound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the focus to the previous panel in the tab order
|
||||
// Input : *panel - panel currently with focus
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::RequestFocusNext(VPANEL panel)
|
||||
{
|
||||
// basic recursion guard, in case user has set up a bad focus hierarchy
|
||||
static int stack_depth = 0;
|
||||
stack_depth++;
|
||||
|
||||
_currentFocus = NULL;
|
||||
int newPosition = 0;
|
||||
if (panel)
|
||||
{
|
||||
newPosition = ipanel()->GetTabPosition(panel);
|
||||
}
|
||||
|
||||
bool bFound = false;
|
||||
bool bRepeat = true;
|
||||
Panel *best = NULL;
|
||||
while (1)
|
||||
{
|
||||
newPosition++;
|
||||
int bestPosition = 999999;
|
||||
|
||||
// look for the next tab position
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
if (child && child->IsVisible() && child->IsEnabled() && child->GetTabPosition())
|
||||
{
|
||||
int tabPosition = child->GetTabPosition();
|
||||
if (tabPosition == newPosition)
|
||||
{
|
||||
// we've found the right tab
|
||||
best = child;
|
||||
bestPosition = newPosition;
|
||||
|
||||
// don't loop anymore since we've found the correct panel
|
||||
break;
|
||||
}
|
||||
else if (tabPosition > newPosition && tabPosition < bestPosition)
|
||||
{
|
||||
// record the match since this is the closest so far
|
||||
bestPosition = tabPosition;
|
||||
best = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRepeat)
|
||||
break;
|
||||
|
||||
if (best)
|
||||
break;
|
||||
|
||||
// haven't found an item
|
||||
|
||||
// check to see if we should push the focus request up
|
||||
if (!_topLevelFocus)
|
||||
{
|
||||
if (_mainPanel->GetVParent() && _mainPanel->GetVParent() != surface()->GetEmbeddedPanel())
|
||||
{
|
||||
// we're not a top level panel, so forward up the request instead of looping
|
||||
if (stack_depth < 15)
|
||||
{
|
||||
if (ipanel()->RequestFocusNext(_mainPanel->GetVParent(), _mainPanel->GetVPanel()))
|
||||
{
|
||||
bFound = true;
|
||||
SetCurrentDefaultButton(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
// if we find one then we break, otherwise we loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loop back
|
||||
newPosition = 0;
|
||||
bRepeat = false;
|
||||
}
|
||||
|
||||
if (best)
|
||||
{
|
||||
_currentFocus = best->GetVPanel();
|
||||
best->RequestFocus(1);
|
||||
bFound = true;
|
||||
|
||||
if (!CanButtonBeDefault(best->GetVPanel()))
|
||||
{
|
||||
if (_defaultButton)
|
||||
{
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(NULL);
|
||||
|
||||
// we need to ask the parent to set its default button
|
||||
if (_mainPanel->GetVParent())
|
||||
{
|
||||
ivgui()->PostMessage(_mainPanel->GetVParent(), new KeyValues("FindDefaultButton"), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentDefaultButton(best->GetVPanel());
|
||||
}
|
||||
}
|
||||
|
||||
stack_depth--;
|
||||
return bFound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the panel that owns this FocusNavGroup to be the root in the focus traversal heirarchy
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetFocusTopLevel(bool state)
|
||||
{
|
||||
_topLevelFocus = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetDefaultButton(Panel *panel)
|
||||
{
|
||||
VPANEL vpanel = panel ? panel->GetVPanel() : NULL;
|
||||
if ( vpanel == _defaultButton.Get() )
|
||||
return;
|
||||
|
||||
// Assert(CanButtonBeDefault(vpanel));
|
||||
|
||||
_defaultButton = vpanel;
|
||||
SetCurrentDefaultButton(_defaultButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void FocusNavGroup::SetCurrentDefaultButton(VPANEL panel, bool sendCurrentDefaultButtonMessage)
|
||||
{
|
||||
if (panel == _currentDefaultButton.Get())
|
||||
return;
|
||||
|
||||
if ( sendCurrentDefaultButtonMessage && _currentDefaultButton.Get() != 0)
|
||||
{
|
||||
ivgui()->PostMessage(_currentDefaultButton, new KeyValues("SetAsCurrentDefaultButton", "state", 0), NULL);
|
||||
}
|
||||
|
||||
_currentDefaultButton = panel;
|
||||
|
||||
if ( sendCurrentDefaultButtonMessage && _currentDefaultButton.Get() != 0)
|
||||
{
|
||||
ivgui()->PostMessage(_currentDefaultButton, new KeyValues("SetAsCurrentDefaultButton", "state", 1), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::GetCurrentDefaultButton()
|
||||
{
|
||||
return _currentDefaultButton;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets panel which receives input when ENTER is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::GetDefaultButton()
|
||||
{
|
||||
return _defaultButton;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: finds the panel which is activated by the specified key
|
||||
// Input : code - the keycode of the hotkey
|
||||
// Output : Panel * - NULL if no panel found
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::FindPanelByHotkey(wchar_t key)
|
||||
{
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
Panel *hot = child->HasHotkey(key);
|
||||
if (hot && hot->IsVisible() && hot->IsEnabled())
|
||||
{
|
||||
return hot;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::GetDefaultPanel()
|
||||
{
|
||||
for (int i = 0; i < _mainPanel->GetChildCount(); i++)
|
||||
{
|
||||
Panel *child = _mainPanel->GetChild(i);
|
||||
if ( !child )
|
||||
continue;
|
||||
|
||||
if (child->GetTabPosition() == 1)
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL; // no specific panel set
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *FocusNavGroup::GetCurrentFocus()
|
||||
{
|
||||
return _currentFocus ? ipanel()->GetPanel(_currentFocus, vgui::GetControlsModuleName()) : NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the current focus
|
||||
//-----------------------------------------------------------------------------
|
||||
VPANEL FocusNavGroup::SetCurrentFocus(VPANEL focus, VPANEL defaultPanel)
|
||||
{
|
||||
_currentFocus = focus;
|
||||
|
||||
// if we haven't found a default panel yet, let's see if we know of one
|
||||
if (defaultPanel == 0)
|
||||
{
|
||||
// can this focus itself by the default
|
||||
if (CanButtonBeDefault(focus))
|
||||
{
|
||||
defaultPanel = focus;
|
||||
}
|
||||
else if (_defaultButton) // do we know of a default button
|
||||
{
|
||||
defaultPanel = _defaultButton;
|
||||
}
|
||||
}
|
||||
|
||||
SetCurrentDefaultButton(defaultPanel);
|
||||
return defaultPanel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns true if the specified panel can be the default
|
||||
//-----------------------------------------------------------------------------
|
||||
bool FocusNavGroup::CanButtonBeDefault(VPANEL panel)
|
||||
{
|
||||
if( panel == 0 )
|
||||
return false;
|
||||
|
||||
KeyValues *data = new KeyValues("CanBeDefaultButton");
|
||||
|
||||
bool bResult = false;
|
||||
if (ipanel()->RequestInfo(panel, data))
|
||||
{
|
||||
bResult = (data->GetInt("result") == 1);
|
||||
}
|
||||
data->deleteThis();
|
||||
return bResult;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,308 +1,308 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <vgui_controls/GraphPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( GraphPanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
GraphPanel::GraphPanel(Panel *parent, const char *name) : BaseClass(parent, name)
|
||||
{
|
||||
m_flDomainSize = 100.0f;
|
||||
m_flLowRange = 0.0f;
|
||||
m_flHighRange = 1.0f;
|
||||
m_bUseDynamicRange = true;
|
||||
m_flMinDomainSize = 0.0f;
|
||||
m_flMaxDomainSize = 0.0f;
|
||||
m_bMaxDomainSizeSet = false;
|
||||
|
||||
// rendering, need to pull these from scheme/res file
|
||||
m_iGraphBarWidth = 2;
|
||||
m_iGraphBarGapWidth = 2;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: domain settings (x-axis settings)
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetDisplayDomainSize(float size)
|
||||
{
|
||||
m_flDomainSize = size;
|
||||
|
||||
// set the max domain size if it hasn't been set yet
|
||||
if (!m_bMaxDomainSizeSet)
|
||||
{
|
||||
SetMaxDomainSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the smallest domain that will be displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetMinDomainSize(float size)
|
||||
{
|
||||
m_flMinDomainSize = size;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the samples to keep
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetMaxDomainSize(float size)
|
||||
{
|
||||
m_flMaxDomainSize = size;
|
||||
m_bMaxDomainSizeSet = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: range settings (y-axis settings)
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetUseFixedRange(float lowRange, float highRange)
|
||||
{
|
||||
m_bUseDynamicRange = false;
|
||||
m_flLowRange = lowRange;
|
||||
m_flHighRange = highRange;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the graph to dynamically determine the range
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetUseDynamicRange(float *rangeList, int numRanges)
|
||||
{
|
||||
m_bUseDynamicRange = true;
|
||||
m_RangeList.CopyArray(rangeList, numRanges);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets the currently displayed range
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::GetDisplayedRange(float &lowRange, float &highRange)
|
||||
{
|
||||
lowRange = m_flLowRange;
|
||||
highRange = m_flHighRange;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds an item to the end of the list
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::AddItem(float sampleEnd, float sampleValue)
|
||||
{
|
||||
if (m_Samples.Count() && m_Samples[m_Samples.Tail()].value == sampleValue)
|
||||
{
|
||||
// collapse identical samples
|
||||
m_Samples[m_Samples.Tail()].sampleEnd = sampleEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add to the end of the samples list
|
||||
Sample_t item;
|
||||
item.value = sampleValue;
|
||||
item.sampleEnd = sampleEnd;
|
||||
m_Samples.AddToTail(item);
|
||||
}
|
||||
|
||||
// see if this frees up any samples past the end
|
||||
if (m_bMaxDomainSizeSet)
|
||||
{
|
||||
float freePoint = sampleEnd - m_flMaxDomainSize;
|
||||
while (m_Samples[m_Samples.Head()].sampleEnd < freePoint)
|
||||
{
|
||||
m_Samples.Remove(m_Samples.Head());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// see the max number of samples necessary to display this information reasonably precisely
|
||||
static const int MAX_LIKELY_GRAPH_WIDTH = 800;
|
||||
int maxSamplesNeeded = 2 * MAX_LIKELY_GRAPH_WIDTH / (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
if (m_Samples.Count() > 2)
|
||||
{
|
||||
// see if we can collapse some items
|
||||
float highestSample = m_Samples[m_Samples.Tail()].sampleEnd;
|
||||
|
||||
// iterate the items
|
||||
// always keep the head around so we have something to go against
|
||||
int sampleIndex = m_Samples.Next(m_Samples.Head());
|
||||
int nextSampleIndex = m_Samples.Next(sampleIndex);
|
||||
|
||||
while (m_Samples.IsInList(nextSampleIndex))
|
||||
{
|
||||
// calculate what sampling precision is actually needed to display this data
|
||||
float distanceFromEnd = highestSample - m_Samples[sampleIndex].sampleEnd;
|
||||
|
||||
// if (distanceFromEnd < m_flDomainSize)
|
||||
// break;
|
||||
|
||||
//!! this calculation is very incorrect
|
||||
float minNeededSampleSize = distanceFromEnd / (m_flMinDomainSize * maxSamplesNeeded);
|
||||
float sampleSize = m_Samples[nextSampleIndex].sampleEnd - m_Samples[sampleIndex].sampleEnd;
|
||||
|
||||
if (sampleSize < minNeededSampleSize)
|
||||
{
|
||||
// collapse the item into the next index
|
||||
m_Samples[nextSampleIndex].value = 0.5f * (m_Samples[nextSampleIndex].value + m_Samples[sampleIndex].value);
|
||||
|
||||
// remove the item from the list
|
||||
m_Samples.Remove(sampleIndex);
|
||||
|
||||
// move to the next item
|
||||
sampleIndex = nextSampleIndex;
|
||||
nextSampleIndex = m_Samples.Next(sampleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this item didn't need collapsing, so assume the next item won't
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns number of items that can be displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
int GraphPanel::GetVisibleItemCount()
|
||||
{
|
||||
return GetWide() / (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out the graph
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the graph
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::Paint()
|
||||
{
|
||||
if (!m_Samples.Count())
|
||||
return;
|
||||
|
||||
// walk from right to left drawing the resampled data
|
||||
int sampleIndex = m_Samples.Tail();
|
||||
int x = GetWide() - (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
|
||||
// calculate how big each sample should be
|
||||
float sampleSize = m_flDomainSize / GetVisibleItemCount();
|
||||
|
||||
// calculate where in the domain we start resampling
|
||||
float resampleStart = m_Samples[sampleIndex].sampleEnd - sampleSize;
|
||||
// always resample from a sample point that is a multiple of the sampleSize
|
||||
resampleStart -= (float)fmod(resampleStart, sampleSize);
|
||||
|
||||
// bar size multiplier
|
||||
float barSizeMultiplier = GetTall() / (m_flHighRange - m_flLowRange);
|
||||
|
||||
// set render color
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
// recalculate the sample range for dynamic resizing
|
||||
float flMinValue = m_Samples[m_Samples.Head()].value;
|
||||
float flMaxValue = m_Samples[m_Samples.Head()].value;
|
||||
|
||||
// iterate the bars to draw
|
||||
while (x > 0 && m_Samples.IsInList(sampleIndex))
|
||||
{
|
||||
// move back the drawing point
|
||||
x -= (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
|
||||
// collect the samples
|
||||
float value = 0.0f;
|
||||
float maxValue = 0.0f;
|
||||
int samplesTouched = 0;
|
||||
int prevSampleIndex = m_Samples.Previous(sampleIndex);
|
||||
while (m_Samples.IsInList(prevSampleIndex))
|
||||
{
|
||||
// take the value
|
||||
value += m_Samples[sampleIndex].value;
|
||||
samplesTouched++;
|
||||
|
||||
// do some work to calculate the sample range
|
||||
if (m_Samples[sampleIndex].value < flMinValue)
|
||||
{
|
||||
flMinValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
if (m_Samples[sampleIndex].value > flMaxValue)
|
||||
{
|
||||
flMaxValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
if (m_Samples[sampleIndex].value > maxValue)
|
||||
{
|
||||
maxValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
|
||||
if (resampleStart < m_Samples[prevSampleIndex].sampleEnd)
|
||||
{
|
||||
// we're out of the sampling range, we need to move on to the next sample
|
||||
sampleIndex = prevSampleIndex;
|
||||
prevSampleIndex = m_Samples.Previous(sampleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're done with this resample
|
||||
// move back the resample start
|
||||
resampleStart -= sampleSize;
|
||||
// draw the current item
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// draw the item
|
||||
// show the max value in the sample, not the average
|
||||
int size = (int)(maxValue * barSizeMultiplier);
|
||||
// int size = (int)((value * barSizeMultiplier) / samplesTouched);
|
||||
surface()->DrawFilledRect(x, GetTall() - size, x + m_iGraphBarWidth, GetTall());
|
||||
}
|
||||
|
||||
// calculate our final range (for use next frame)
|
||||
if (m_bUseDynamicRange)
|
||||
{
|
||||
flMinValue = 0;
|
||||
|
||||
// find the range that fits
|
||||
for (int i = 0; i < m_RangeList.Count(); i++)
|
||||
{
|
||||
if (m_RangeList[i] > flMaxValue)
|
||||
{
|
||||
flMaxValue = m_RangeList[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_flLowRange = flMinValue;
|
||||
m_flHighRange = flMaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up colors
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("GraphPanel.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("GraphPanel.BgColor", pScheme));
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <vgui_controls/GraphPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( GraphPanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
GraphPanel::GraphPanel(Panel *parent, const char *name) : BaseClass(parent, name)
|
||||
{
|
||||
m_flDomainSize = 100.0f;
|
||||
m_flLowRange = 0.0f;
|
||||
m_flHighRange = 1.0f;
|
||||
m_bUseDynamicRange = true;
|
||||
m_flMinDomainSize = 0.0f;
|
||||
m_flMaxDomainSize = 0.0f;
|
||||
m_bMaxDomainSizeSet = false;
|
||||
|
||||
// rendering, need to pull these from scheme/res file
|
||||
m_iGraphBarWidth = 2;
|
||||
m_iGraphBarGapWidth = 2;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: domain settings (x-axis settings)
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetDisplayDomainSize(float size)
|
||||
{
|
||||
m_flDomainSize = size;
|
||||
|
||||
// set the max domain size if it hasn't been set yet
|
||||
if (!m_bMaxDomainSizeSet)
|
||||
{
|
||||
SetMaxDomainSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the smallest domain that will be displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetMinDomainSize(float size)
|
||||
{
|
||||
m_flMinDomainSize = size;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the samples to keep
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetMaxDomainSize(float size)
|
||||
{
|
||||
m_flMaxDomainSize = size;
|
||||
m_bMaxDomainSizeSet = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: range settings (y-axis settings)
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetUseFixedRange(float lowRange, float highRange)
|
||||
{
|
||||
m_bUseDynamicRange = false;
|
||||
m_flLowRange = lowRange;
|
||||
m_flHighRange = highRange;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the graph to dynamically determine the range
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::SetUseDynamicRange(float *rangeList, int numRanges)
|
||||
{
|
||||
m_bUseDynamicRange = true;
|
||||
m_RangeList.CopyArray(rangeList, numRanges);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets the currently displayed range
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::GetDisplayedRange(float &lowRange, float &highRange)
|
||||
{
|
||||
lowRange = m_flLowRange;
|
||||
highRange = m_flHighRange;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds an item to the end of the list
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::AddItem(float sampleEnd, float sampleValue)
|
||||
{
|
||||
if (m_Samples.Count() && m_Samples[m_Samples.Tail()].value == sampleValue)
|
||||
{
|
||||
// collapse identical samples
|
||||
m_Samples[m_Samples.Tail()].sampleEnd = sampleEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add to the end of the samples list
|
||||
Sample_t item;
|
||||
item.value = sampleValue;
|
||||
item.sampleEnd = sampleEnd;
|
||||
m_Samples.AddToTail(item);
|
||||
}
|
||||
|
||||
// see if this frees up any samples past the end
|
||||
if (m_bMaxDomainSizeSet)
|
||||
{
|
||||
float freePoint = sampleEnd - m_flMaxDomainSize;
|
||||
while (m_Samples[m_Samples.Head()].sampleEnd < freePoint)
|
||||
{
|
||||
m_Samples.Remove(m_Samples.Head());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// see the max number of samples necessary to display this information reasonably precisely
|
||||
static const int MAX_LIKELY_GRAPH_WIDTH = 800;
|
||||
int maxSamplesNeeded = 2 * MAX_LIKELY_GRAPH_WIDTH / (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
if (m_Samples.Count() > 2)
|
||||
{
|
||||
// see if we can collapse some items
|
||||
float highestSample = m_Samples[m_Samples.Tail()].sampleEnd;
|
||||
|
||||
// iterate the items
|
||||
// always keep the head around so we have something to go against
|
||||
int sampleIndex = m_Samples.Next(m_Samples.Head());
|
||||
int nextSampleIndex = m_Samples.Next(sampleIndex);
|
||||
|
||||
while (m_Samples.IsInList(nextSampleIndex))
|
||||
{
|
||||
// calculate what sampling precision is actually needed to display this data
|
||||
float distanceFromEnd = highestSample - m_Samples[sampleIndex].sampleEnd;
|
||||
|
||||
// if (distanceFromEnd < m_flDomainSize)
|
||||
// break;
|
||||
|
||||
//!! this calculation is very incorrect
|
||||
float minNeededSampleSize = distanceFromEnd / (m_flMinDomainSize * maxSamplesNeeded);
|
||||
float sampleSize = m_Samples[nextSampleIndex].sampleEnd - m_Samples[sampleIndex].sampleEnd;
|
||||
|
||||
if (sampleSize < minNeededSampleSize)
|
||||
{
|
||||
// collapse the item into the next index
|
||||
m_Samples[nextSampleIndex].value = 0.5f * (m_Samples[nextSampleIndex].value + m_Samples[sampleIndex].value);
|
||||
|
||||
// remove the item from the list
|
||||
m_Samples.Remove(sampleIndex);
|
||||
|
||||
// move to the next item
|
||||
sampleIndex = nextSampleIndex;
|
||||
nextSampleIndex = m_Samples.Next(sampleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this item didn't need collapsing, so assume the next item won't
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns number of items that can be displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
int GraphPanel::GetVisibleItemCount()
|
||||
{
|
||||
return GetWide() / (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out the graph
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the graph
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::Paint()
|
||||
{
|
||||
if (!m_Samples.Count())
|
||||
return;
|
||||
|
||||
// walk from right to left drawing the resampled data
|
||||
int sampleIndex = m_Samples.Tail();
|
||||
int x = GetWide() - (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
|
||||
// calculate how big each sample should be
|
||||
float sampleSize = m_flDomainSize / GetVisibleItemCount();
|
||||
|
||||
// calculate where in the domain we start resampling
|
||||
float resampleStart = m_Samples[sampleIndex].sampleEnd - sampleSize;
|
||||
// always resample from a sample point that is a multiple of the sampleSize
|
||||
resampleStart -= (float)fmod(resampleStart, sampleSize);
|
||||
|
||||
// bar size multiplier
|
||||
float barSizeMultiplier = GetTall() / (m_flHighRange - m_flLowRange);
|
||||
|
||||
// set render color
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
// recalculate the sample range for dynamic resizing
|
||||
float flMinValue = m_Samples[m_Samples.Head()].value;
|
||||
float flMaxValue = m_Samples[m_Samples.Head()].value;
|
||||
|
||||
// iterate the bars to draw
|
||||
while (x > 0 && m_Samples.IsInList(sampleIndex))
|
||||
{
|
||||
// move back the drawing point
|
||||
x -= (m_iGraphBarWidth + m_iGraphBarGapWidth);
|
||||
|
||||
// collect the samples
|
||||
float value = 0.0f;
|
||||
float maxValue = 0.0f;
|
||||
int samplesTouched = 0;
|
||||
int prevSampleIndex = m_Samples.Previous(sampleIndex);
|
||||
while (m_Samples.IsInList(prevSampleIndex))
|
||||
{
|
||||
// take the value
|
||||
value += m_Samples[sampleIndex].value;
|
||||
samplesTouched++;
|
||||
|
||||
// do some work to calculate the sample range
|
||||
if (m_Samples[sampleIndex].value < flMinValue)
|
||||
{
|
||||
flMinValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
if (m_Samples[sampleIndex].value > flMaxValue)
|
||||
{
|
||||
flMaxValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
if (m_Samples[sampleIndex].value > maxValue)
|
||||
{
|
||||
maxValue = m_Samples[sampleIndex].value;
|
||||
}
|
||||
|
||||
if (resampleStart < m_Samples[prevSampleIndex].sampleEnd)
|
||||
{
|
||||
// we're out of the sampling range, we need to move on to the next sample
|
||||
sampleIndex = prevSampleIndex;
|
||||
prevSampleIndex = m_Samples.Previous(sampleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're done with this resample
|
||||
// move back the resample start
|
||||
resampleStart -= sampleSize;
|
||||
// draw the current item
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// draw the item
|
||||
// show the max value in the sample, not the average
|
||||
int size = (int)(maxValue * barSizeMultiplier);
|
||||
// int size = (int)((value * barSizeMultiplier) / samplesTouched);
|
||||
surface()->DrawFilledRect(x, GetTall() - size, x + m_iGraphBarWidth, GetTall());
|
||||
}
|
||||
|
||||
// calculate our final range (for use next frame)
|
||||
if (m_bUseDynamicRange)
|
||||
{
|
||||
flMinValue = 0;
|
||||
|
||||
// find the range that fits
|
||||
for (int i = 0; i < m_RangeList.Count(); i++)
|
||||
{
|
||||
if (m_RangeList[i] > flMaxValue)
|
||||
{
|
||||
flMaxValue = m_RangeList[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_flLowRange = flMinValue;
|
||||
m_flHighRange = flMaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up colors
|
||||
//-----------------------------------------------------------------------------
|
||||
void GraphPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("GraphPanel.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("GraphPanel.BgColor", pScheme));
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,282 +1,282 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <Color.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Conctructor. Start with default position and default color.
|
||||
//-----------------------------------------------------------------------------
|
||||
Image::Image()
|
||||
{
|
||||
SetPos(0,0);
|
||||
SetSize(0,0);
|
||||
SetColor(Color(255,255,255,255));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Image::~Image()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the position of the image, you need to reset this every time you
|
||||
// call Paint()
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetPos(int x,int y)
|
||||
{
|
||||
_pos[0]=x;
|
||||
_pos[1]=y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the position of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetPos(int& x,int& y)
|
||||
{
|
||||
x=_pos[0];
|
||||
y=_pos[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the size of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = _size[0];
|
||||
tall = _size[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets the size of the image contents (by default the set size)
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
GetSize(wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the size of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetSize(int wide, int tall)
|
||||
{
|
||||
_size[0]=wide;
|
||||
_size[1]=tall;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the draw color using a Color struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetColor(Color col)
|
||||
{
|
||||
surface()->DrawSetColor(col[0], col[1], col[2], col[3]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the draw color using RGBA ints
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetColor(int r,int g,int b,int a)
|
||||
{
|
||||
surface()->DrawSetColor(r,g,b,a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a filled rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawFilledRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawFilledRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw an outlined rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawOutlinedRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawOutlinedRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a line between two points
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawLine(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawLine(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a line between a list of 'numPoints' points
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPolyLine(int *px, int *py, int numPoints)
|
||||
{
|
||||
// update the positions to be relative to this panel
|
||||
for(int i=0;i<numPoints;i++)
|
||||
{
|
||||
px[i] += _pos[0];
|
||||
py[i] += _pos[1];
|
||||
}
|
||||
|
||||
surface()->DrawPolyLine(px, py, numPoints);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the font
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextFont(HFont font)
|
||||
{
|
||||
surface()->DrawSetTextFont(font);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text color using a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextColor(Color sc)
|
||||
{
|
||||
surface()->DrawSetTextColor(sc[0], sc[1], sc[2], sc[3]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text color useing RGBA ints
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextColor(int r,int g,int b,int a)
|
||||
{
|
||||
surface()->DrawSetTextColor(r,g,b,a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text position
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextPos(int x,int y)
|
||||
{
|
||||
x+=_pos[0];
|
||||
y+=_pos[1];
|
||||
surface()->DrawSetTextPos(x,y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a text string
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintText(const wchar_t *str,int strlen)
|
||||
{
|
||||
surface()->DrawPrintText(str, strlen);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a text string at the given coords.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintText(int x, int y, const wchar_t *str, int strlen)
|
||||
{
|
||||
x += _pos[0];
|
||||
y += _pos[1];
|
||||
|
||||
surface()->DrawSetTextPos(x, y);
|
||||
surface()->DrawPrintText(str, strlen);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a character
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintChar(wchar_t ch)
|
||||
{
|
||||
surface()->DrawUnicodeChar(ch);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a character at the given coords
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintChar(int x, int y, wchar_t ch)
|
||||
{
|
||||
x+=_pos[0];
|
||||
y+=_pos[1];
|
||||
|
||||
surface()->DrawSetTextPos(x, y);
|
||||
surface()->DrawUnicodeChar(ch);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTexture(int id)
|
||||
{
|
||||
surface()->DrawSetTexture(id);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a rectangle filled with the current texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawTexturedRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
surface()->DrawTexturedRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Paint the contents of the image on screen.
|
||||
// You must call this explicitly each frame.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::Paint()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the current color using a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetColor(Color color)
|
||||
{
|
||||
_color=color;
|
||||
DrawSetTextColor(color); // now update the device context underneath us :)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the current color as a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
Color Image::GetColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
bool Image::Evict()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int Image::GetNumFrames()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Image::SetFrame( int nFrame )
|
||||
{
|
||||
}
|
||||
|
||||
HTexture Image::GetID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <Color.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Conctructor. Start with default position and default color.
|
||||
//-----------------------------------------------------------------------------
|
||||
Image::Image()
|
||||
{
|
||||
SetPos(0,0);
|
||||
SetSize(0,0);
|
||||
SetColor(Color(255,255,255,255));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Image::~Image()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the position of the image, you need to reset this every time you
|
||||
// call Paint()
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetPos(int x,int y)
|
||||
{
|
||||
_pos[0]=x;
|
||||
_pos[1]=y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the position of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetPos(int& x,int& y)
|
||||
{
|
||||
x=_pos[0];
|
||||
y=_pos[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the size of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = _size[0];
|
||||
tall = _size[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets the size of the image contents (by default the set size)
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
GetSize(wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the size of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetSize(int wide, int tall)
|
||||
{
|
||||
_size[0]=wide;
|
||||
_size[1]=tall;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the draw color using a Color struct.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetColor(Color col)
|
||||
{
|
||||
surface()->DrawSetColor(col[0], col[1], col[2], col[3]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the draw color using RGBA ints
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetColor(int r,int g,int b,int a)
|
||||
{
|
||||
surface()->DrawSetColor(r,g,b,a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a filled rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawFilledRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawFilledRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw an outlined rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawOutlinedRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawOutlinedRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a line between two points
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawLine(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
x0+=_pos[0];
|
||||
y0+=_pos[1];
|
||||
x1+=_pos[0];
|
||||
y1+=_pos[1];
|
||||
surface()->DrawLine(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a line between a list of 'numPoints' points
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPolyLine(int *px, int *py, int numPoints)
|
||||
{
|
||||
// update the positions to be relative to this panel
|
||||
for(int i=0;i<numPoints;i++)
|
||||
{
|
||||
px[i] += _pos[0];
|
||||
py[i] += _pos[1];
|
||||
}
|
||||
|
||||
surface()->DrawPolyLine(px, py, numPoints);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the font
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextFont(HFont font)
|
||||
{
|
||||
surface()->DrawSetTextFont(font);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text color using a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextColor(Color sc)
|
||||
{
|
||||
surface()->DrawSetTextColor(sc[0], sc[1], sc[2], sc[3]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text color useing RGBA ints
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextColor(int r,int g,int b,int a)
|
||||
{
|
||||
surface()->DrawSetTextColor(r,g,b,a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the text position
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTextPos(int x,int y)
|
||||
{
|
||||
x+=_pos[0];
|
||||
y+=_pos[1];
|
||||
surface()->DrawSetTextPos(x,y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a text string
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintText(const wchar_t *str,int strlen)
|
||||
{
|
||||
surface()->DrawPrintText(str, strlen);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a text string at the given coords.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintText(int x, int y, const wchar_t *str, int strlen)
|
||||
{
|
||||
x += _pos[0];
|
||||
y += _pos[1];
|
||||
|
||||
surface()->DrawSetTextPos(x, y);
|
||||
surface()->DrawPrintText(str, strlen);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a character
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintChar(wchar_t ch)
|
||||
{
|
||||
surface()->DrawUnicodeChar(ch);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a character at the given coords
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawPrintChar(int x, int y, wchar_t ch)
|
||||
{
|
||||
x+=_pos[0];
|
||||
y+=_pos[1];
|
||||
|
||||
surface()->DrawSetTextPos(x, y);
|
||||
surface()->DrawUnicodeChar(ch);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawSetTexture(int id)
|
||||
{
|
||||
surface()->DrawSetTexture(id);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draw a rectangle filled with the current texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::DrawTexturedRect(int x0,int y0,int x1,int y1)
|
||||
{
|
||||
surface()->DrawTexturedRect(x0,y0,x1,y1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Paint the contents of the image on screen.
|
||||
// You must call this explicitly each frame.
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::Paint()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the current color using a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
void Image::SetColor(Color color)
|
||||
{
|
||||
_color=color;
|
||||
DrawSetTextColor(color); // now update the device context underneath us :)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the current color as a color struct
|
||||
//-----------------------------------------------------------------------------
|
||||
Color Image::GetColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
bool Image::Evict()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int Image::GetNumFrames()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Image::SetFrame( int nFrame )
|
||||
{
|
||||
}
|
||||
|
||||
HTexture Image::GetID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <Color.h>
|
||||
|
||||
#include <vgui_controls/ImageList.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: blank image, intentially draws nothing
|
||||
//-----------------------------------------------------------------------------
|
||||
class BlankImage : public IImage
|
||||
{
|
||||
public:
|
||||
virtual void Paint() {}
|
||||
virtual void SetPos(int x, int y) {}
|
||||
virtual void GetContentSize(int &wide, int &tall) { wide = 0; tall = 0; }
|
||||
virtual void GetSize(int &wide, int &tall) { wide = 0; tall = 0; }
|
||||
virtual void SetSize(int wide, int tall) {}
|
||||
virtual void SetColor(Color col) {}
|
||||
virtual bool Evict() { return false; }
|
||||
virtual int GetNumFrames() { return 0; }
|
||||
virtual void SetFrame( int nFrame ) {}
|
||||
virtual HTexture GetID() { return 0; }
|
||||
virtual void SetRotation( int iRotation ) { return; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageList::ImageList(bool deleteImagesWhenDone)
|
||||
{
|
||||
m_bDeleteImagesWhenDone = deleteImagesWhenDone;
|
||||
AddImage(new BlankImage());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageList::~ImageList()
|
||||
{
|
||||
if (m_bDeleteImagesWhenDone)
|
||||
{
|
||||
// delete all the images, except for the first image (which is always the blank image)
|
||||
for (int i = 1; i < m_Images.Count(); i++)
|
||||
{
|
||||
delete m_Images[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds a new image to the list, returning the index it was placed at
|
||||
//-----------------------------------------------------------------------------
|
||||
int ImageList::AddImage(vgui::IImage *image)
|
||||
{
|
||||
return m_Images.AddToTail(image);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image at a specified index, growing and adding NULL images if necessary
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageList::SetImageAtIndex(int index, vgui::IImage *image)
|
||||
{
|
||||
// allocate more images if necessary
|
||||
while (m_Images.Count() <= index)
|
||||
{
|
||||
m_Images.AddToTail(NULL);
|
||||
}
|
||||
|
||||
m_Images[index] = image;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of images
|
||||
//-----------------------------------------------------------------------------
|
||||
int ImageList::GetImageCount()
|
||||
{
|
||||
return m_Images.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets an image, imageIndex is of range [0, GetImageCount)
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::IImage *ImageList::GetImage(int imageIndex)
|
||||
{
|
||||
return m_Images[imageIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns true if an index is valid
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ImageList::IsValidIndex(int imageIndex)
|
||||
{
|
||||
return m_Images.IsValidIndex(imageIndex);
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <Color.h>
|
||||
|
||||
#include <vgui_controls/ImageList.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: blank image, intentially draws nothing
|
||||
//-----------------------------------------------------------------------------
|
||||
class BlankImage : public IImage
|
||||
{
|
||||
public:
|
||||
virtual void Paint() {}
|
||||
virtual void SetPos(int x, int y) {}
|
||||
virtual void GetContentSize(int &wide, int &tall) { wide = 0; tall = 0; }
|
||||
virtual void GetSize(int &wide, int &tall) { wide = 0; tall = 0; }
|
||||
virtual void SetSize(int wide, int tall) {}
|
||||
virtual void SetColor(Color col) {}
|
||||
virtual bool Evict() { return false; }
|
||||
virtual int GetNumFrames() { return 0; }
|
||||
virtual void SetFrame( int nFrame ) {}
|
||||
virtual HTexture GetID() { return 0; }
|
||||
virtual void SetRotation( int iRotation ) { return; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageList::ImageList(bool deleteImagesWhenDone)
|
||||
{
|
||||
m_bDeleteImagesWhenDone = deleteImagesWhenDone;
|
||||
AddImage(new BlankImage());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageList::~ImageList()
|
||||
{
|
||||
if (m_bDeleteImagesWhenDone)
|
||||
{
|
||||
// delete all the images, except for the first image (which is always the blank image)
|
||||
for (int i = 1; i < m_Images.Count(); i++)
|
||||
{
|
||||
delete m_Images[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds a new image to the list, returning the index it was placed at
|
||||
//-----------------------------------------------------------------------------
|
||||
int ImageList::AddImage(vgui::IImage *image)
|
||||
{
|
||||
return m_Images.AddToTail(image);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image at a specified index, growing and adding NULL images if necessary
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageList::SetImageAtIndex(int index, vgui::IImage *image)
|
||||
{
|
||||
// allocate more images if necessary
|
||||
while (m_Images.Count() <= index)
|
||||
{
|
||||
m_Images.AddToTail(NULL);
|
||||
}
|
||||
|
||||
m_Images[index] = image;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of images
|
||||
//-----------------------------------------------------------------------------
|
||||
int ImageList::GetImageCount()
|
||||
{
|
||||
return m_Images.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets an image, imageIndex is of range [0, GetImageCount)
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::IImage *ImageList::GetImage(int imageIndex)
|
||||
{
|
||||
return m_Images[imageIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns true if an index is valid
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ImageList::IsValidIndex(int imageIndex)
|
||||
{
|
||||
return m_Images.IsValidIndex(imageIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,463 +1,463 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/ImagePanel.h>
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ImagePanel::ImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_pImage = NULL;
|
||||
m_pszImageName = NULL;
|
||||
m_pszFillColorName = NULL;
|
||||
m_pszDrawColorName = NULL; // HPE addition
|
||||
m_bCenterImage = false;
|
||||
m_bScaleImage = false;
|
||||
m_bTileImage = false;
|
||||
m_bTileHorizontally = false;
|
||||
m_bTileVertically = false;
|
||||
m_fScaleAmount = 0.0f;
|
||||
m_FillColor = Color(0, 0, 0, 0);
|
||||
m_DrawColor = Color(255,255,255,255);
|
||||
m_iRotation = ROTATED_UNROTATED;
|
||||
|
||||
SetImage( m_pImage );
|
||||
|
||||
REGISTER_COLOR_AS_OVERRIDABLE( m_FillColor, "fillcolor_override" );
|
||||
REGISTER_COLOR_AS_OVERRIDABLE( m_DrawColor, "drawcolor_override" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ImagePanel::~ImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszFillColorName;
|
||||
delete [] m_pszDrawColorName; // HPE addition
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles size changing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::OnSizeChanged(int newWide, int newTall)
|
||||
{
|
||||
BaseClass::OnSizeChanged(newWide, newTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetImage(IImage *image)
|
||||
{
|
||||
m_pImage = image;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetImage(const char *imageName)
|
||||
{
|
||||
if ( imageName && m_pszImageName && V_stricmp( imageName, m_pszImageName ) == 0 )
|
||||
return;
|
||||
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_strncpy(m_pszImageName, imageName, len );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IImage *ImagePanel::GetImage()
|
||||
{
|
||||
return m_pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ImagePanel::GetDrawColor( void )
|
||||
{
|
||||
return m_DrawColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetDrawColor( Color drawColor )
|
||||
{
|
||||
m_DrawColor = drawColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::PaintBackground()
|
||||
{
|
||||
if (m_FillColor[3] > 0)
|
||||
{
|
||||
// draw the specified fill color
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
surface()->DrawSetColor(m_FillColor);
|
||||
surface()->DrawFilledRect(0, 0, wide, tall);
|
||||
}
|
||||
if ( m_pImage )
|
||||
{
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Color should be always set from GetDrawColor(), not just when
|
||||
// scaling is true (see previous code)
|
||||
//=============================================================================
|
||||
|
||||
// surface()->DrawSetColor( 255, 255, 255, GetAlpha() );
|
||||
m_pImage->SetColor( GetDrawColor() );
|
||||
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
if ( m_bCenterImage )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( m_bScaleImage && m_fScaleAmount > 0.0f )
|
||||
{
|
||||
imageWide = static_cast<int>( static_cast<float>(imageWide) * m_fScaleAmount );
|
||||
imageTall = static_cast<int>( static_cast<float>(imageTall) * m_fScaleAmount );
|
||||
}
|
||||
|
||||
m_pImage->SetPos( (wide - imageWide) / 2, (tall - imageTall) / 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage->SetPos(0, 0);
|
||||
}
|
||||
|
||||
if (m_bScaleImage)
|
||||
{
|
||||
// Image size is stored in the bitmap, so temporarily set its size
|
||||
// to our panel size and then restore after we draw it.
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( m_fScaleAmount > 0.0f )
|
||||
{
|
||||
float wide, tall;
|
||||
wide = static_cast<float>(imageWide) * m_fScaleAmount;
|
||||
tall = static_cast<float>(imageTall) * m_fScaleAmount;
|
||||
m_pImage->SetSize( static_cast<int>(wide), static_cast<int>(tall) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
m_pImage->SetSize( wide, tall );
|
||||
}
|
||||
|
||||
m_pImage->Paint();
|
||||
|
||||
m_pImage->SetSize( imageWide, imageTall );
|
||||
}
|
||||
else if ( m_bTileImage || m_bTileHorizontally || m_bTileVertically )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
int y = 0;
|
||||
while ( y < tall )
|
||||
{
|
||||
int x = 0;
|
||||
while (x < wide)
|
||||
{
|
||||
m_pImage->SetPos(x,y);
|
||||
m_pImage->Paint();
|
||||
|
||||
x += imageWide;
|
||||
|
||||
if ( !m_bTileHorizontally )
|
||||
break;
|
||||
}
|
||||
|
||||
y += imageTall;
|
||||
|
||||
if ( !m_bTileVertically )
|
||||
break;
|
||||
}
|
||||
m_pImage->SetPos(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage->SetColor( GetDrawColor() );
|
||||
m_pImage->Paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
if (m_pszFillColorName)
|
||||
{
|
||||
outResourceData->SetString("fillcolor", m_pszFillColorName);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Added support for specifying drawcolor
|
||||
//=============================================================================
|
||||
if (m_pszDrawColorName)
|
||||
{
|
||||
outResourceData->SetString("drawcolor", m_pszDrawColorName);
|
||||
}
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
if (GetBorder())
|
||||
{
|
||||
outResourceData->SetString("border", GetBorder()->GetName());
|
||||
}
|
||||
|
||||
outResourceData->SetInt("scaleImage", m_bScaleImage);
|
||||
outResourceData->SetFloat("scaleAmount", m_fScaleAmount);
|
||||
outResourceData->SetInt("tileImage", m_bTileImage);
|
||||
outResourceData->SetInt("tileHorizontally", m_bTileHorizontally);
|
||||
outResourceData->SetInt("tileVertically", m_bTileVertically);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszFillColorName;
|
||||
delete [] m_pszDrawColorName; // HPE addition
|
||||
m_pszImageName = NULL;
|
||||
m_pszFillColorName = NULL;
|
||||
m_pszDrawColorName = NULL; // HPE addition
|
||||
|
||||
m_bScaleImage = inResourceData->GetInt("scaleImage", 0);
|
||||
m_fScaleAmount = inResourceData->GetFloat("scaleAmount", 0.0f);
|
||||
m_bTileImage = inResourceData->GetInt("tileImage", 0);
|
||||
m_bTileHorizontally = inResourceData->GetInt("tileHorizontally", m_bTileImage);
|
||||
m_bTileVertically = inResourceData->GetInt("tileVertically", m_bTileImage);
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if ( *imageName )
|
||||
{
|
||||
SetImage( imageName );
|
||||
}
|
||||
|
||||
const char *pszFillColor = inResourceData->GetString("fillcolor", "");
|
||||
if (*pszFillColor)
|
||||
{
|
||||
int r = 0, g = 0, b = 0, a = 255;
|
||||
int len = Q_strlen(pszFillColor) + 1;
|
||||
m_pszFillColorName = new char[ len ];
|
||||
Q_strncpy( m_pszFillColorName, pszFillColor, len );
|
||||
|
||||
if (sscanf(pszFillColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_FillColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_FillColor = pScheme->GetColor(pszFillColor, Color(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Added support for specifying drawcolor
|
||||
//=============================================================================
|
||||
const char *pszDrawColor = inResourceData->GetString("drawcolor", "");
|
||||
if (*pszDrawColor)
|
||||
{
|
||||
int r = 255, g = 255, b = 255, a = 255;
|
||||
int len = Q_strlen(pszDrawColor) + 1;
|
||||
m_pszDrawColorName = new char[ len ];
|
||||
Q_strncpy( m_pszDrawColorName, pszDrawColor, len );
|
||||
|
||||
if (sscanf(pszDrawColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_DrawColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_DrawColor = pScheme->GetColor(pszDrawColor, Color(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
const char *pszBorder = inResourceData->GetString("border", "");
|
||||
if (*pszBorder)
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
SetBorder(pScheme->GetBorder(pszBorder));
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: load the image, this is done just before this control is displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
if ( m_pszImageName && strlen( m_pszImageName ) > 0 )
|
||||
{
|
||||
SetImage(scheme()->GetImage(m_pszImageName, m_bScaleImage));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string image, string border, string fillcolor, bool scaleImage", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the image should scale to fit the size of the ImagePanel (defaults to false)
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetShouldScaleImage( bool state )
|
||||
{
|
||||
m_bScaleImage = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets whether or not the image should be scaled to fit the size of the ImagePanel
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ImagePanel::GetShouldScaleImage()
|
||||
{
|
||||
return m_bScaleImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: used in conjunction with setting that the image should scale and defines an absolute scale amount
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetScaleAmount( float scale )
|
||||
{
|
||||
m_fScaleAmount = scale;
|
||||
}
|
||||
|
||||
float ImagePanel::GetScaleAmount( void )
|
||||
{
|
||||
return m_fScaleAmount;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set the color to fill with, if no Image is specified
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetFillColor( Color col )
|
||||
{
|
||||
m_FillColor = col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ImagePanel::GetFillColor()
|
||||
{
|
||||
return m_FillColor;
|
||||
}
|
||||
|
||||
char *ImagePanel::GetImageName()
|
||||
{
|
||||
return m_pszImageName;
|
||||
}
|
||||
|
||||
bool ImagePanel::EvictImage()
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
// nothing to do
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !scheme()->DeleteImage( m_pszImageName ) )
|
||||
{
|
||||
// no eviction occured, could have an outstanding reference
|
||||
return false;
|
||||
}
|
||||
|
||||
// clear out our cached concept of it
|
||||
// as it may change
|
||||
// the next SetImage() will re-establish
|
||||
m_pImage = NULL;
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ImagePanel::GetNumFrames()
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_pImage->GetNumFrames();
|
||||
}
|
||||
|
||||
void ImagePanel::SetFrame( int nFrame )
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return m_pImage->SetFrame( nFrame );
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/ImagePanel.h>
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ImagePanel::ImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_pImage = NULL;
|
||||
m_pszImageName = NULL;
|
||||
m_pszFillColorName = NULL;
|
||||
m_pszDrawColorName = NULL; // HPE addition
|
||||
m_bCenterImage = false;
|
||||
m_bScaleImage = false;
|
||||
m_bTileImage = false;
|
||||
m_bTileHorizontally = false;
|
||||
m_bTileVertically = false;
|
||||
m_fScaleAmount = 0.0f;
|
||||
m_FillColor = Color(0, 0, 0, 0);
|
||||
m_DrawColor = Color(255,255,255,255);
|
||||
m_iRotation = ROTATED_UNROTATED;
|
||||
|
||||
SetImage( m_pImage );
|
||||
|
||||
REGISTER_COLOR_AS_OVERRIDABLE( m_FillColor, "fillcolor_override" );
|
||||
REGISTER_COLOR_AS_OVERRIDABLE( m_DrawColor, "drawcolor_override" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ImagePanel::~ImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszFillColorName;
|
||||
delete [] m_pszDrawColorName; // HPE addition
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles size changing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::OnSizeChanged(int newWide, int newTall)
|
||||
{
|
||||
BaseClass::OnSizeChanged(newWide, newTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetImage(IImage *image)
|
||||
{
|
||||
m_pImage = image;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetImage(const char *imageName)
|
||||
{
|
||||
if ( imageName && m_pszImageName && V_stricmp( imageName, m_pszImageName ) == 0 )
|
||||
return;
|
||||
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_strncpy(m_pszImageName, imageName, len );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IImage *ImagePanel::GetImage()
|
||||
{
|
||||
return m_pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ImagePanel::GetDrawColor( void )
|
||||
{
|
||||
return m_DrawColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetDrawColor( Color drawColor )
|
||||
{
|
||||
m_DrawColor = drawColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::PaintBackground()
|
||||
{
|
||||
if (m_FillColor[3] > 0)
|
||||
{
|
||||
// draw the specified fill color
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
surface()->DrawSetColor(m_FillColor);
|
||||
surface()->DrawFilledRect(0, 0, wide, tall);
|
||||
}
|
||||
if ( m_pImage )
|
||||
{
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Color should be always set from GetDrawColor(), not just when
|
||||
// scaling is true (see previous code)
|
||||
//=============================================================================
|
||||
|
||||
// surface()->DrawSetColor( 255, 255, 255, GetAlpha() );
|
||||
m_pImage->SetColor( GetDrawColor() );
|
||||
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
if ( m_bCenterImage )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( m_bScaleImage && m_fScaleAmount > 0.0f )
|
||||
{
|
||||
imageWide = static_cast<int>( static_cast<float>(imageWide) * m_fScaleAmount );
|
||||
imageTall = static_cast<int>( static_cast<float>(imageTall) * m_fScaleAmount );
|
||||
}
|
||||
|
||||
m_pImage->SetPos( (wide - imageWide) / 2, (tall - imageTall) / 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage->SetPos(0, 0);
|
||||
}
|
||||
|
||||
if (m_bScaleImage)
|
||||
{
|
||||
// Image size is stored in the bitmap, so temporarily set its size
|
||||
// to our panel size and then restore after we draw it.
|
||||
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
if ( m_fScaleAmount > 0.0f )
|
||||
{
|
||||
float wide, tall;
|
||||
wide = static_cast<float>(imageWide) * m_fScaleAmount;
|
||||
tall = static_cast<float>(imageTall) * m_fScaleAmount;
|
||||
m_pImage->SetSize( static_cast<int>(wide), static_cast<int>(tall) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
m_pImage->SetSize( wide, tall );
|
||||
}
|
||||
|
||||
m_pImage->Paint();
|
||||
|
||||
m_pImage->SetSize( imageWide, imageTall );
|
||||
}
|
||||
else if ( m_bTileImage || m_bTileHorizontally || m_bTileVertically )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int imageWide, imageTall;
|
||||
m_pImage->GetSize( imageWide, imageTall );
|
||||
|
||||
int y = 0;
|
||||
while ( y < tall )
|
||||
{
|
||||
int x = 0;
|
||||
while (x < wide)
|
||||
{
|
||||
m_pImage->SetPos(x,y);
|
||||
m_pImage->Paint();
|
||||
|
||||
x += imageWide;
|
||||
|
||||
if ( !m_bTileHorizontally )
|
||||
break;
|
||||
}
|
||||
|
||||
y += imageTall;
|
||||
|
||||
if ( !m_bTileVertically )
|
||||
break;
|
||||
}
|
||||
m_pImage->SetPos(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImage->SetColor( GetDrawColor() );
|
||||
m_pImage->Paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
if (m_pszFillColorName)
|
||||
{
|
||||
outResourceData->SetString("fillcolor", m_pszFillColorName);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Added support for specifying drawcolor
|
||||
//=============================================================================
|
||||
if (m_pszDrawColorName)
|
||||
{
|
||||
outResourceData->SetString("drawcolor", m_pszDrawColorName);
|
||||
}
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
if (GetBorder())
|
||||
{
|
||||
outResourceData->SetString("border", GetBorder()->GetName());
|
||||
}
|
||||
|
||||
outResourceData->SetInt("scaleImage", m_bScaleImage);
|
||||
outResourceData->SetFloat("scaleAmount", m_fScaleAmount);
|
||||
outResourceData->SetInt("tileImage", m_bTileImage);
|
||||
outResourceData->SetInt("tileHorizontally", m_bTileHorizontally);
|
||||
outResourceData->SetInt("tileVertically", m_bTileVertically);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszFillColorName;
|
||||
delete [] m_pszDrawColorName; // HPE addition
|
||||
m_pszImageName = NULL;
|
||||
m_pszFillColorName = NULL;
|
||||
m_pszDrawColorName = NULL; // HPE addition
|
||||
|
||||
m_bScaleImage = inResourceData->GetInt("scaleImage", 0);
|
||||
m_fScaleAmount = inResourceData->GetFloat("scaleAmount", 0.0f);
|
||||
m_bTileImage = inResourceData->GetInt("tileImage", 0);
|
||||
m_bTileHorizontally = inResourceData->GetInt("tileHorizontally", m_bTileImage);
|
||||
m_bTileVertically = inResourceData->GetInt("tileVertically", m_bTileImage);
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if ( *imageName )
|
||||
{
|
||||
SetImage( imageName );
|
||||
}
|
||||
|
||||
const char *pszFillColor = inResourceData->GetString("fillcolor", "");
|
||||
if (*pszFillColor)
|
||||
{
|
||||
int r = 0, g = 0, b = 0, a = 255;
|
||||
int len = Q_strlen(pszFillColor) + 1;
|
||||
m_pszFillColorName = new char[ len ];
|
||||
Q_strncpy( m_pszFillColorName, pszFillColor, len );
|
||||
|
||||
if (sscanf(pszFillColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_FillColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_FillColor = pScheme->GetColor(pszFillColor, Color(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// HPE_BEGIN:
|
||||
// [pfreese] Added support for specifying drawcolor
|
||||
//=============================================================================
|
||||
const char *pszDrawColor = inResourceData->GetString("drawcolor", "");
|
||||
if (*pszDrawColor)
|
||||
{
|
||||
int r = 255, g = 255, b = 255, a = 255;
|
||||
int len = Q_strlen(pszDrawColor) + 1;
|
||||
m_pszDrawColorName = new char[ len ];
|
||||
Q_strncpy( m_pszDrawColorName, pszDrawColor, len );
|
||||
|
||||
if (sscanf(pszDrawColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_DrawColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_DrawColor = pScheme->GetColor(pszDrawColor, Color(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
//=============================================================================
|
||||
// HPE_END
|
||||
//=============================================================================
|
||||
|
||||
const char *pszBorder = inResourceData->GetString("border", "");
|
||||
if (*pszBorder)
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
SetBorder(pScheme->GetBorder(pszBorder));
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: load the image, this is done just before this control is displayed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
if ( m_pszImageName && strlen( m_pszImageName ) > 0 )
|
||||
{
|
||||
SetImage(scheme()->GetImage(m_pszImageName, m_bScaleImage));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string image, string border, string fillcolor, bool scaleImage", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the image should scale to fit the size of the ImagePanel (defaults to false)
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetShouldScaleImage( bool state )
|
||||
{
|
||||
m_bScaleImage = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets whether or not the image should be scaled to fit the size of the ImagePanel
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ImagePanel::GetShouldScaleImage()
|
||||
{
|
||||
return m_bScaleImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: used in conjunction with setting that the image should scale and defines an absolute scale amount
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetScaleAmount( float scale )
|
||||
{
|
||||
m_fScaleAmount = scale;
|
||||
}
|
||||
|
||||
float ImagePanel::GetScaleAmount( void )
|
||||
{
|
||||
return m_fScaleAmount;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: set the color to fill with, if no Image is specified
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImagePanel::SetFillColor( Color col )
|
||||
{
|
||||
m_FillColor = col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ImagePanel::GetFillColor()
|
||||
{
|
||||
return m_FillColor;
|
||||
}
|
||||
|
||||
char *ImagePanel::GetImageName()
|
||||
{
|
||||
return m_pszImageName;
|
||||
}
|
||||
|
||||
bool ImagePanel::EvictImage()
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
// nothing to do
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !scheme()->DeleteImage( m_pszImageName ) )
|
||||
{
|
||||
// no eviction occured, could have an outstanding reference
|
||||
return false;
|
||||
}
|
||||
|
||||
// clear out our cached concept of it
|
||||
// as it may change
|
||||
// the next SetImage() will re-establish
|
||||
m_pImage = NULL;
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ImagePanel::GetNumFrames()
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_pImage->GetNumFrames();
|
||||
}
|
||||
|
||||
void ImagePanel::SetFrame( int nFrame )
|
||||
{
|
||||
if ( !m_pImage )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return m_pImage->SetFrame( nFrame );
|
||||
}
|
||||
|
||||
@@ -1,236 +1,236 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui_controls/InputDialog.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui/IInput.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseInputDialog::BaseInputDialog( vgui::Panel *parent, const char *title ) :
|
||||
BaseClass( parent, NULL )
|
||||
{
|
||||
m_pContextKeyValues = NULL;
|
||||
|
||||
SetDeleteSelfOnClose( true );
|
||||
SetTitle(title, true);
|
||||
SetSize(320, 180);
|
||||
SetSizeable( false );
|
||||
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#VGui_Cancel");
|
||||
m_pOKButton = new Button(this, "OKButton", "#VGui_OK");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOKButton->SetCommand("OK");
|
||||
m_pOKButton->SetAsDefaultButton( true );
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
AddActionSignalTarget( parent );
|
||||
}
|
||||
}
|
||||
|
||||
BaseInputDialog::~BaseInputDialog()
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Cleans up the keyvalues
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::CleanUpContextKeyValues()
|
||||
{
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
m_pContextKeyValues->deleteThis();
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::DoModal( KeyValues *pContextKeyValues )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
BaseClass::DoModal();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out controls
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
// lay out all the controls
|
||||
int topy = IsSmallCaption() ? 15 : 30;
|
||||
int halfw = w / 2;
|
||||
|
||||
PerformLayout( 12, topy, w - 24, h - 100 );
|
||||
|
||||
m_pOKButton->SetBounds( halfw - 84, h - 30, 72, 24 );
|
||||
m_pCancelButton->SetBounds( halfw + 12, h - 30, 72, 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles button commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::OnCommand(const char *command)
|
||||
{
|
||||
KeyValues *kv = NULL;
|
||||
if ( !stricmp( command, "OK" ) )
|
||||
{
|
||||
kv = new KeyValues( "InputCompleted" );
|
||||
kv->SetPtr( "dialog", this );
|
||||
}
|
||||
else if ( !stricmp( command, "Cancel" ) )
|
||||
{
|
||||
kv = new KeyValues( "InputCanceled" );
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility dialog, used to ask yes/no questions of the user
|
||||
//-----------------------------------------------------------------------------
|
||||
InputMessageBox::InputMessageBox( vgui::Panel *parent, const char *title, char const *prompt )
|
||||
: BaseClass( parent, title )
|
||||
{
|
||||
SetSize( 320, 120 );
|
||||
|
||||
m_pPrompt = new Label( this, "Prompt", prompt );
|
||||
}
|
||||
|
||||
InputMessageBox::~InputMessageBox()
|
||||
{
|
||||
}
|
||||
|
||||
void InputMessageBox::PerformLayout( int x, int y, int w, int h )
|
||||
{
|
||||
m_pPrompt->SetBounds( x, y, w, 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
InputDialog::InputDialog(vgui::Panel *parent, const char *title, char const *prompt, char const *defaultValue /*=""*/ ) :
|
||||
BaseClass(parent, title)
|
||||
{
|
||||
SetSize( 320, 120 );
|
||||
|
||||
m_pPrompt = new Label( this, "Prompt", prompt );
|
||||
|
||||
m_pInput = new TextEntry( this, "Text" );
|
||||
m_pInput->SetText( defaultValue );
|
||||
m_pInput->SelectAllText( true );
|
||||
m_pInput->RequestFocus();
|
||||
}
|
||||
|
||||
|
||||
InputDialog::~InputDialog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the dialog to be multiline
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::SetMultiline( bool state )
|
||||
{
|
||||
m_pInput->SetMultiline( state );
|
||||
m_pInput->SetCatchEnterKey( state );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allow numeric input only
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::AllowNumericInputOnly( bool bOnlyNumeric )
|
||||
{
|
||||
if ( m_pInput )
|
||||
{
|
||||
m_pInput->SetAllowNumericInputOnly( bOnlyNumeric );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out controls
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::PerformLayout( int x, int y, int w, int h )
|
||||
{
|
||||
m_pPrompt->SetBounds( x, y, w, 24 );
|
||||
m_pInput ->SetBounds( x, y + 30, w, m_pInput->IsMultiline() ? h - 30 : 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles button commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::OnCommand(const char *command)
|
||||
{
|
||||
// overriding OnCommand for backwards compatability
|
||||
// it'd be nice at some point to find all uses of InputDialog and just use BaseInputDialog's OnCommand
|
||||
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
int nTextLength = m_pInput->GetTextLength() + 1;
|
||||
char* txt = (char*)_alloca( nTextLength * sizeof(char) );
|
||||
m_pInput->GetText( txt, nTextLength );
|
||||
KeyValues *kv = new KeyValues( "InputCompleted", "text", txt );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "InputCanceled" );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui_controls/InputDialog.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui/IInput.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseInputDialog::BaseInputDialog( vgui::Panel *parent, const char *title ) :
|
||||
BaseClass( parent, NULL )
|
||||
{
|
||||
m_pContextKeyValues = NULL;
|
||||
|
||||
SetDeleteSelfOnClose( true );
|
||||
SetTitle(title, true);
|
||||
SetSize(320, 180);
|
||||
SetSizeable( false );
|
||||
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#VGui_Cancel");
|
||||
m_pOKButton = new Button(this, "OKButton", "#VGui_OK");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOKButton->SetCommand("OK");
|
||||
m_pOKButton->SetAsDefaultButton( true );
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
AddActionSignalTarget( parent );
|
||||
}
|
||||
}
|
||||
|
||||
BaseInputDialog::~BaseInputDialog()
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Cleans up the keyvalues
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::CleanUpContextKeyValues()
|
||||
{
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
m_pContextKeyValues->deleteThis();
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::DoModal( KeyValues *pContextKeyValues )
|
||||
{
|
||||
CleanUpContextKeyValues();
|
||||
m_pContextKeyValues = pContextKeyValues;
|
||||
BaseClass::DoModal();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out controls
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
// lay out all the controls
|
||||
int topy = IsSmallCaption() ? 15 : 30;
|
||||
int halfw = w / 2;
|
||||
|
||||
PerformLayout( 12, topy, w - 24, h - 100 );
|
||||
|
||||
m_pOKButton->SetBounds( halfw - 84, h - 30, 72, 24 );
|
||||
m_pCancelButton->SetBounds( halfw + 12, h - 30, 72, 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles button commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseInputDialog::OnCommand(const char *command)
|
||||
{
|
||||
KeyValues *kv = NULL;
|
||||
if ( !stricmp( command, "OK" ) )
|
||||
{
|
||||
kv = new KeyValues( "InputCompleted" );
|
||||
kv->SetPtr( "dialog", this );
|
||||
}
|
||||
else if ( !stricmp( command, "Cancel" ) )
|
||||
{
|
||||
kv = new KeyValues( "InputCanceled" );
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( command );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Utility dialog, used to ask yes/no questions of the user
|
||||
//-----------------------------------------------------------------------------
|
||||
InputMessageBox::InputMessageBox( vgui::Panel *parent, const char *title, char const *prompt )
|
||||
: BaseClass( parent, title )
|
||||
{
|
||||
SetSize( 320, 120 );
|
||||
|
||||
m_pPrompt = new Label( this, "Prompt", prompt );
|
||||
}
|
||||
|
||||
InputMessageBox::~InputMessageBox()
|
||||
{
|
||||
}
|
||||
|
||||
void InputMessageBox::PerformLayout( int x, int y, int w, int h )
|
||||
{
|
||||
m_pPrompt->SetBounds( x, y, w, 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
InputDialog::InputDialog(vgui::Panel *parent, const char *title, char const *prompt, char const *defaultValue /*=""*/ ) :
|
||||
BaseClass(parent, title)
|
||||
{
|
||||
SetSize( 320, 120 );
|
||||
|
||||
m_pPrompt = new Label( this, "Prompt", prompt );
|
||||
|
||||
m_pInput = new TextEntry( this, "Text" );
|
||||
m_pInput->SetText( defaultValue );
|
||||
m_pInput->SelectAllText( true );
|
||||
m_pInput->RequestFocus();
|
||||
}
|
||||
|
||||
|
||||
InputDialog::~InputDialog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the dialog to be multiline
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::SetMultiline( bool state )
|
||||
{
|
||||
m_pInput->SetMultiline( state );
|
||||
m_pInput->SetCatchEnterKey( state );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allow numeric input only
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::AllowNumericInputOnly( bool bOnlyNumeric )
|
||||
{
|
||||
if ( m_pInput )
|
||||
{
|
||||
m_pInput->SetAllowNumericInputOnly( bOnlyNumeric );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: lays out controls
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::PerformLayout( int x, int y, int w, int h )
|
||||
{
|
||||
m_pPrompt->SetBounds( x, y, w, 24 );
|
||||
m_pInput ->SetBounds( x, y + 30, w, m_pInput->IsMultiline() ? h - 30 : 24 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles button commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void InputDialog::OnCommand(const char *command)
|
||||
{
|
||||
// overriding OnCommand for backwards compatability
|
||||
// it'd be nice at some point to find all uses of InputDialog and just use BaseInputDialog's OnCommand
|
||||
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
int nTextLength = m_pInput->GetTextLength() + 1;
|
||||
char* txt = (char*)_alloca( nTextLength * sizeof(char) );
|
||||
m_pInput->GetText( txt, nTextLength );
|
||||
KeyValues *kv = new KeyValues( "InputCompleted", "text", txt );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "InputCanceled" );
|
||||
if ( m_pContextKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pContextKeyValues );
|
||||
m_pContextKeyValues = NULL;
|
||||
}
|
||||
PostActionSignal( kv );
|
||||
CloseModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,355 +1,355 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/KeyBindingHelpDialog.h"
|
||||
#include "vgui_controls/ListPanel.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IVGui.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "KeyValues.h"
|
||||
#include "vgui/Cursor.h"
|
||||
#include "tier1/utldict.h"
|
||||
#include "vgui_controls/KeyBoardEditorDialog.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// If the user holds the key bound to help down for this long, then the dialog will stay on automatically
|
||||
#define KB_HELP_CONTINUE_SHOWING_TIME 1.0
|
||||
|
||||
static bool BindingLessFunc( KeyValues * const & lhs, KeyValues * const &rhs )
|
||||
{
|
||||
KeyValues *p1, *p2;
|
||||
|
||||
p1 = const_cast< KeyValues * >( lhs );
|
||||
p2 = const_cast< KeyValues * >( rhs );
|
||||
return ( Q_stricmp( p1->GetString( "Action" ), p2->GetString( "Action" ) ) < 0 ) ? true : false;
|
||||
}
|
||||
|
||||
CKeyBindingHelpDialog::CKeyBindingHelpDialog( Panel *parent, Panel *panelToView, KeyBindingContextHandle_t handle, KeyCode code, int modifiers )
|
||||
: BaseClass( parent, "KeyBindingHelpDialog" ),
|
||||
m_Handle( handle ),
|
||||
m_KeyCode( code ),
|
||||
m_Modifiers( modifiers ),
|
||||
m_bPermanent( false )
|
||||
{
|
||||
Assert( panelToView );
|
||||
m_hPanel = panelToView;
|
||||
|
||||
m_pList = new ListPanel( this, "KeyBindings" );
|
||||
m_pList->SetIgnoreDoubleClick( true );
|
||||
m_pList->AddColumnHeader(0, "Action", "#KBEditorBindingName", 175, 0);
|
||||
m_pList->AddColumnHeader(1, "Binding", "#KBEditorBinding", 175, 0);
|
||||
m_pList->AddColumnHeader(2, "Description", "#KBEditorDescription", 300, 0);
|
||||
|
||||
LoadControlSettings( "resource/KeyBindingHelpDialog.res" );
|
||||
|
||||
if ( panelToView && panelToView->GetName() && panelToView->GetName()[0] )
|
||||
{
|
||||
SetTitle( panelToView->GetName(), true );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTitle( "#KBHelpDialogTitle", true );
|
||||
}
|
||||
|
||||
SetSmallCaption( true );
|
||||
SetMinimumSize( 400, 400 );
|
||||
SetMinimizeButtonVisible( false );
|
||||
SetMaximizeButtonVisible( false );
|
||||
SetSizeable( true );
|
||||
SetMoveable( true );
|
||||
SetMenuButtonVisible( false );
|
||||
|
||||
SetVisible( true );
|
||||
|
||||
MoveToCenterOfScreen();
|
||||
|
||||
PopulateList();
|
||||
|
||||
m_flShowTime = system()->GetCurrentTime();
|
||||
ivgui()->AddTickSignal( GetVPanel(), 0 );
|
||||
|
||||
input()->SetAppModalSurface( GetVPanel() );
|
||||
}
|
||||
|
||||
CKeyBindingHelpDialog::~CKeyBindingHelpDialog()
|
||||
{
|
||||
if ( input()->GetAppModalSurface() == GetVPanel() )
|
||||
{
|
||||
input()->SetAppModalSurface( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnTick()
|
||||
{
|
||||
BaseClass::OnTick();
|
||||
|
||||
bool keyStillDown = IsHelpKeyStillBeingHeld();
|
||||
|
||||
double curtime = system()->GetCurrentTime();
|
||||
double elapsed = curtime - m_flShowTime;
|
||||
// After a second of holding the key, releasing the key will close the dialog
|
||||
if ( elapsed > KB_HELP_CONTINUE_SHOWING_TIME )
|
||||
{
|
||||
if ( !keyStillDown )
|
||||
{
|
||||
MarkForDeletion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Otherwise, if they tapped the key within a second and now have released...
|
||||
else if ( !keyStillDown )
|
||||
{
|
||||
// Continue showing dialog indefinitely
|
||||
ivgui()->RemoveTickSignal( GetVPanel() );
|
||||
m_bPermanent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The key originally bound to help was pressed
|
||||
void CKeyBindingHelpDialog::HelpKeyPressed()
|
||||
{
|
||||
// Don't kill while editor is being shown...
|
||||
if ( m_hKeyBindingsEditor.Get() )
|
||||
return;
|
||||
|
||||
if ( m_bPermanent )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
bool CKeyBindingHelpDialog::IsHelpKeyStillBeingHeld()
|
||||
{
|
||||
bool keyDown = input()->IsKeyDown( m_KeyCode );
|
||||
if ( !keyDown )
|
||||
return false;
|
||||
|
||||
bool shift = (input()->IsKeyDown(KEY_LSHIFT) || input()->IsKeyDown(KEY_RSHIFT));
|
||||
bool ctrl = (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL));
|
||||
bool alt = (input()->IsKeyDown(KEY_LALT) || input()->IsKeyDown(KEY_RALT));
|
||||
|
||||
int modifiers = 0;
|
||||
if ( shift )
|
||||
{
|
||||
modifiers |= MODIFIER_SHIFT;
|
||||
}
|
||||
if ( ctrl )
|
||||
{
|
||||
modifiers |= MODIFIER_CONTROL;
|
||||
}
|
||||
if ( alt )
|
||||
{
|
||||
modifiers |= MODIFIER_ALT;
|
||||
}
|
||||
|
||||
if ( modifiers != m_Modifiers )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnCommand( char const *cmd )
|
||||
{
|
||||
if ( !Q_stricmp( cmd, "OK" ) ||
|
||||
!Q_stricmp( cmd, "cancel" ) ||
|
||||
!Q_stricmp( cmd, "Close" ) )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "edit" ) )
|
||||
{
|
||||
// Show the keybindings edit dialog
|
||||
if ( m_hKeyBindingsEditor.Get() )
|
||||
{
|
||||
delete m_hKeyBindingsEditor.Get();
|
||||
}
|
||||
|
||||
// Don't delete panel if H key is released...
|
||||
|
||||
m_hKeyBindingsEditor = new CKeyBoardEditorDialog( this, m_hPanel, m_Handle );
|
||||
m_hKeyBindingsEditor->DoModal();
|
||||
|
||||
ivgui()->RemoveTickSignal( GetVPanel() );
|
||||
m_bPermanent = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnKeyCodeTyped(vgui::KeyCode code)
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped( code );
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::GetMappingList( Panel *panel, CUtlVector< PanelKeyBindingMap * >& maps )
|
||||
{
|
||||
PanelKeyBindingMap *map = panel->GetKBMap();
|
||||
while ( map )
|
||||
{
|
||||
maps.AddToTail( map );
|
||||
map = map->baseMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CKeyBindingHelpDialog::AnsiText( char const *token, char *out, size_t buflen )
|
||||
{
|
||||
out[ 0 ] = 0;
|
||||
|
||||
wchar_t *str = g_pVGuiLocalize->Find( token );
|
||||
if ( !str )
|
||||
{
|
||||
Q_strncpy( out, token, buflen );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pVGuiLocalize->ConvertUnicodeToANSI( str, out, buflen );
|
||||
}
|
||||
}
|
||||
|
||||
struct ListInfo_t
|
||||
{
|
||||
PanelKeyBindingMap *m_pMap;
|
||||
Panel *m_pPanel;
|
||||
};
|
||||
|
||||
void CKeyBindingHelpDialog::PopulateList()
|
||||
{
|
||||
m_pList->DeleteAllItems();
|
||||
|
||||
int i, j;
|
||||
|
||||
CUtlVector< ListInfo_t > maps;
|
||||
vgui::Panel *pPanel = m_hPanel;
|
||||
while ( pPanel->IsKeyBindingChainToParentAllowed() )
|
||||
{
|
||||
PanelKeyBindingMap *map = pPanel->GetKBMap();
|
||||
while ( map )
|
||||
{
|
||||
int k;
|
||||
int c = maps.Count();
|
||||
for ( k = 0; k < c; ++k )
|
||||
{
|
||||
if ( maps[k].m_pMap == map )
|
||||
break;
|
||||
}
|
||||
if ( k == c )
|
||||
{
|
||||
int k = maps.AddToTail( );
|
||||
maps[k].m_pMap = map;
|
||||
maps[k].m_pPanel = pPanel;
|
||||
}
|
||||
map = map->baseMap;
|
||||
}
|
||||
|
||||
pPanel = pPanel->GetParent();
|
||||
if ( !pPanel )
|
||||
break;
|
||||
}
|
||||
|
||||
CUtlRBTree< KeyValues *, int > sorted( 0, 0, BindingLessFunc );
|
||||
|
||||
// add header item
|
||||
int c = maps.Count();
|
||||
for ( i = 0; i < c; ++i )
|
||||
{
|
||||
PanelKeyBindingMap *m = maps[ i ].m_pMap;
|
||||
Panel *pPanel = maps[i].m_pPanel;
|
||||
Assert( m );
|
||||
|
||||
int bindings = m->boundkeys.Count();
|
||||
for ( j = 0; j < bindings; ++j )
|
||||
{
|
||||
BoundKey_t *kbMap = &m->boundkeys[ j ];
|
||||
Assert( kbMap );
|
||||
|
||||
// Create a new: blank item
|
||||
KeyValues *item = new KeyValues( "Item" );
|
||||
|
||||
// Fill in data
|
||||
char loc[ 128 ];
|
||||
Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname );
|
||||
|
||||
char ansi[ 256 ];
|
||||
AnsiText( loc, ansi, sizeof( ansi ) );
|
||||
|
||||
item->SetString( "Action", ansi );
|
||||
item->SetWString( "Binding", Panel::KeyCodeModifiersToDisplayString( (KeyCode)kbMap->keycode, kbMap->modifiers ) );
|
||||
|
||||
// Find the binding
|
||||
KeyBindingMap_t *bindingMap = pPanel->LookupBinding( kbMap->bindingname );
|
||||
if ( bindingMap &&
|
||||
bindingMap->helpstring )
|
||||
{
|
||||
AnsiText( bindingMap->helpstring, ansi, sizeof( ansi ) );
|
||||
item->SetString( "Description", ansi );
|
||||
}
|
||||
|
||||
item->SetPtr( "Item", kbMap );
|
||||
|
||||
sorted.Insert( item );
|
||||
}
|
||||
|
||||
// Now try and find any "unbound" keys...
|
||||
int mappings = m->entries.Count();
|
||||
for ( j = 0; j < mappings; ++j )
|
||||
{
|
||||
KeyBindingMap_t *kbMap = &m->entries[ j ];
|
||||
|
||||
// See if it's bound
|
||||
CUtlVector< BoundKey_t * > list;
|
||||
pPanel->LookupBoundKeys( kbMap->bindingname, list );
|
||||
if ( list.Count() > 0 )
|
||||
continue;
|
||||
|
||||
// Not bound, add a placeholder entry
|
||||
// Create a new: blank item
|
||||
KeyValues *item = new KeyValues( "Item" );
|
||||
|
||||
// fill in data
|
||||
char loc[ 128 ];
|
||||
Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname );
|
||||
|
||||
char ansi[ 256 ];
|
||||
AnsiText( loc, ansi, sizeof( ansi ) );
|
||||
|
||||
item->SetString( "Action", ansi );
|
||||
item->SetWString( "Binding", L"" );
|
||||
if ( kbMap->helpstring )
|
||||
{
|
||||
AnsiText( kbMap->helpstring, ansi, sizeof( ansi ) );
|
||||
item->SetString( "Description", ansi );
|
||||
}
|
||||
|
||||
item->SetPtr( "Unbound", kbMap );
|
||||
|
||||
sorted.Insert( item );
|
||||
}
|
||||
}
|
||||
|
||||
for ( j = sorted.FirstInorder() ; j != sorted.InvalidIndex(); j = sorted.NextInorder( j ) )
|
||||
{
|
||||
KeyValues *item = sorted[ j ];
|
||||
|
||||
// Add to list
|
||||
m_pList->AddItem( item, 0, false, false );
|
||||
|
||||
item->deleteThis();
|
||||
}
|
||||
|
||||
sorted.RemoveAll();
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/KeyBindingHelpDialog.h"
|
||||
#include "vgui_controls/ListPanel.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IVGui.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "KeyValues.h"
|
||||
#include "vgui/Cursor.h"
|
||||
#include "tier1/utldict.h"
|
||||
#include "vgui_controls/KeyBoardEditorDialog.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// If the user holds the key bound to help down for this long, then the dialog will stay on automatically
|
||||
#define KB_HELP_CONTINUE_SHOWING_TIME 1.0
|
||||
|
||||
static bool BindingLessFunc( KeyValues * const & lhs, KeyValues * const &rhs )
|
||||
{
|
||||
KeyValues *p1, *p2;
|
||||
|
||||
p1 = const_cast< KeyValues * >( lhs );
|
||||
p2 = const_cast< KeyValues * >( rhs );
|
||||
return ( Q_stricmp( p1->GetString( "Action" ), p2->GetString( "Action" ) ) < 0 ) ? true : false;
|
||||
}
|
||||
|
||||
CKeyBindingHelpDialog::CKeyBindingHelpDialog( Panel *parent, Panel *panelToView, KeyBindingContextHandle_t handle, KeyCode code, int modifiers )
|
||||
: BaseClass( parent, "KeyBindingHelpDialog" ),
|
||||
m_Handle( handle ),
|
||||
m_KeyCode( code ),
|
||||
m_Modifiers( modifiers ),
|
||||
m_bPermanent( false )
|
||||
{
|
||||
Assert( panelToView );
|
||||
m_hPanel = panelToView;
|
||||
|
||||
m_pList = new ListPanel( this, "KeyBindings" );
|
||||
m_pList->SetIgnoreDoubleClick( true );
|
||||
m_pList->AddColumnHeader(0, "Action", "#KBEditorBindingName", 175, 0);
|
||||
m_pList->AddColumnHeader(1, "Binding", "#KBEditorBinding", 175, 0);
|
||||
m_pList->AddColumnHeader(2, "Description", "#KBEditorDescription", 300, 0);
|
||||
|
||||
LoadControlSettings( "resource/KeyBindingHelpDialog.res" );
|
||||
|
||||
if ( panelToView && panelToView->GetName() && panelToView->GetName()[0] )
|
||||
{
|
||||
SetTitle( panelToView->GetName(), true );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTitle( "#KBHelpDialogTitle", true );
|
||||
}
|
||||
|
||||
SetSmallCaption( true );
|
||||
SetMinimumSize( 400, 400 );
|
||||
SetMinimizeButtonVisible( false );
|
||||
SetMaximizeButtonVisible( false );
|
||||
SetSizeable( true );
|
||||
SetMoveable( true );
|
||||
SetMenuButtonVisible( false );
|
||||
|
||||
SetVisible( true );
|
||||
|
||||
MoveToCenterOfScreen();
|
||||
|
||||
PopulateList();
|
||||
|
||||
m_flShowTime = system()->GetCurrentTime();
|
||||
ivgui()->AddTickSignal( GetVPanel(), 0 );
|
||||
|
||||
input()->SetAppModalSurface( GetVPanel() );
|
||||
}
|
||||
|
||||
CKeyBindingHelpDialog::~CKeyBindingHelpDialog()
|
||||
{
|
||||
if ( input()->GetAppModalSurface() == GetVPanel() )
|
||||
{
|
||||
input()->SetAppModalSurface( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnTick()
|
||||
{
|
||||
BaseClass::OnTick();
|
||||
|
||||
bool keyStillDown = IsHelpKeyStillBeingHeld();
|
||||
|
||||
double curtime = system()->GetCurrentTime();
|
||||
double elapsed = curtime - m_flShowTime;
|
||||
// After a second of holding the key, releasing the key will close the dialog
|
||||
if ( elapsed > KB_HELP_CONTINUE_SHOWING_TIME )
|
||||
{
|
||||
if ( !keyStillDown )
|
||||
{
|
||||
MarkForDeletion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Otherwise, if they tapped the key within a second and now have released...
|
||||
else if ( !keyStillDown )
|
||||
{
|
||||
// Continue showing dialog indefinitely
|
||||
ivgui()->RemoveTickSignal( GetVPanel() );
|
||||
m_bPermanent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The key originally bound to help was pressed
|
||||
void CKeyBindingHelpDialog::HelpKeyPressed()
|
||||
{
|
||||
// Don't kill while editor is being shown...
|
||||
if ( m_hKeyBindingsEditor.Get() )
|
||||
return;
|
||||
|
||||
if ( m_bPermanent )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
bool CKeyBindingHelpDialog::IsHelpKeyStillBeingHeld()
|
||||
{
|
||||
bool keyDown = input()->IsKeyDown( m_KeyCode );
|
||||
if ( !keyDown )
|
||||
return false;
|
||||
|
||||
bool shift = (input()->IsKeyDown(KEY_LSHIFT) || input()->IsKeyDown(KEY_RSHIFT));
|
||||
bool ctrl = (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL));
|
||||
bool alt = (input()->IsKeyDown(KEY_LALT) || input()->IsKeyDown(KEY_RALT));
|
||||
|
||||
int modifiers = 0;
|
||||
if ( shift )
|
||||
{
|
||||
modifiers |= MODIFIER_SHIFT;
|
||||
}
|
||||
if ( ctrl )
|
||||
{
|
||||
modifiers |= MODIFIER_CONTROL;
|
||||
}
|
||||
if ( alt )
|
||||
{
|
||||
modifiers |= MODIFIER_ALT;
|
||||
}
|
||||
|
||||
if ( modifiers != m_Modifiers )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnCommand( char const *cmd )
|
||||
{
|
||||
if ( !Q_stricmp( cmd, "OK" ) ||
|
||||
!Q_stricmp( cmd, "cancel" ) ||
|
||||
!Q_stricmp( cmd, "Close" ) )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "edit" ) )
|
||||
{
|
||||
// Show the keybindings edit dialog
|
||||
if ( m_hKeyBindingsEditor.Get() )
|
||||
{
|
||||
delete m_hKeyBindingsEditor.Get();
|
||||
}
|
||||
|
||||
// Don't delete panel if H key is released...
|
||||
|
||||
m_hKeyBindingsEditor = new CKeyBoardEditorDialog( this, m_hPanel, m_Handle );
|
||||
m_hKeyBindingsEditor->DoModal();
|
||||
|
||||
ivgui()->RemoveTickSignal( GetVPanel() );
|
||||
m_bPermanent = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::OnKeyCodeTyped(vgui::KeyCode code)
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped( code );
|
||||
}
|
||||
|
||||
void CKeyBindingHelpDialog::GetMappingList( Panel *panel, CUtlVector< PanelKeyBindingMap * >& maps )
|
||||
{
|
||||
PanelKeyBindingMap *map = panel->GetKBMap();
|
||||
while ( map )
|
||||
{
|
||||
maps.AddToTail( map );
|
||||
map = map->baseMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CKeyBindingHelpDialog::AnsiText( char const *token, char *out, size_t buflen )
|
||||
{
|
||||
out[ 0 ] = 0;
|
||||
|
||||
wchar_t *str = g_pVGuiLocalize->Find( token );
|
||||
if ( !str )
|
||||
{
|
||||
Q_strncpy( out, token, buflen );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pVGuiLocalize->ConvertUnicodeToANSI( str, out, buflen );
|
||||
}
|
||||
}
|
||||
|
||||
struct ListInfo_t
|
||||
{
|
||||
PanelKeyBindingMap *m_pMap;
|
||||
Panel *m_pPanel;
|
||||
};
|
||||
|
||||
void CKeyBindingHelpDialog::PopulateList()
|
||||
{
|
||||
m_pList->DeleteAllItems();
|
||||
|
||||
int i, j;
|
||||
|
||||
CUtlVector< ListInfo_t > maps;
|
||||
vgui::Panel *pPanel = m_hPanel;
|
||||
while ( pPanel->IsKeyBindingChainToParentAllowed() )
|
||||
{
|
||||
PanelKeyBindingMap *map = pPanel->GetKBMap();
|
||||
while ( map )
|
||||
{
|
||||
int k;
|
||||
int c = maps.Count();
|
||||
for ( k = 0; k < c; ++k )
|
||||
{
|
||||
if ( maps[k].m_pMap == map )
|
||||
break;
|
||||
}
|
||||
if ( k == c )
|
||||
{
|
||||
int k = maps.AddToTail( );
|
||||
maps[k].m_pMap = map;
|
||||
maps[k].m_pPanel = pPanel;
|
||||
}
|
||||
map = map->baseMap;
|
||||
}
|
||||
|
||||
pPanel = pPanel->GetParent();
|
||||
if ( !pPanel )
|
||||
break;
|
||||
}
|
||||
|
||||
CUtlRBTree< KeyValues *, int > sorted( 0, 0, BindingLessFunc );
|
||||
|
||||
// add header item
|
||||
int c = maps.Count();
|
||||
for ( i = 0; i < c; ++i )
|
||||
{
|
||||
PanelKeyBindingMap *m = maps[ i ].m_pMap;
|
||||
Panel *pPanel = maps[i].m_pPanel;
|
||||
Assert( m );
|
||||
|
||||
int bindings = m->boundkeys.Count();
|
||||
for ( j = 0; j < bindings; ++j )
|
||||
{
|
||||
BoundKey_t *kbMap = &m->boundkeys[ j ];
|
||||
Assert( kbMap );
|
||||
|
||||
// Create a new: blank item
|
||||
KeyValues *item = new KeyValues( "Item" );
|
||||
|
||||
// Fill in data
|
||||
char loc[ 128 ];
|
||||
Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname );
|
||||
|
||||
char ansi[ 256 ];
|
||||
AnsiText( loc, ansi, sizeof( ansi ) );
|
||||
|
||||
item->SetString( "Action", ansi );
|
||||
item->SetWString( "Binding", Panel::KeyCodeModifiersToDisplayString( (KeyCode)kbMap->keycode, kbMap->modifiers ) );
|
||||
|
||||
// Find the binding
|
||||
KeyBindingMap_t *bindingMap = pPanel->LookupBinding( kbMap->bindingname );
|
||||
if ( bindingMap &&
|
||||
bindingMap->helpstring )
|
||||
{
|
||||
AnsiText( bindingMap->helpstring, ansi, sizeof( ansi ) );
|
||||
item->SetString( "Description", ansi );
|
||||
}
|
||||
|
||||
item->SetPtr( "Item", kbMap );
|
||||
|
||||
sorted.Insert( item );
|
||||
}
|
||||
|
||||
// Now try and find any "unbound" keys...
|
||||
int mappings = m->entries.Count();
|
||||
for ( j = 0; j < mappings; ++j )
|
||||
{
|
||||
KeyBindingMap_t *kbMap = &m->entries[ j ];
|
||||
|
||||
// See if it's bound
|
||||
CUtlVector< BoundKey_t * > list;
|
||||
pPanel->LookupBoundKeys( kbMap->bindingname, list );
|
||||
if ( list.Count() > 0 )
|
||||
continue;
|
||||
|
||||
// Not bound, add a placeholder entry
|
||||
// Create a new: blank item
|
||||
KeyValues *item = new KeyValues( "Item" );
|
||||
|
||||
// fill in data
|
||||
char loc[ 128 ];
|
||||
Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname );
|
||||
|
||||
char ansi[ 256 ];
|
||||
AnsiText( loc, ansi, sizeof( ansi ) );
|
||||
|
||||
item->SetString( "Action", ansi );
|
||||
item->SetWString( "Binding", L"" );
|
||||
if ( kbMap->helpstring )
|
||||
{
|
||||
AnsiText( kbMap->helpstring, ansi, sizeof( ansi ) );
|
||||
item->SetString( "Description", ansi );
|
||||
}
|
||||
|
||||
item->SetPtr( "Unbound", kbMap );
|
||||
|
||||
sorted.Insert( item );
|
||||
}
|
||||
}
|
||||
|
||||
for ( j = sorted.FirstInorder() ; j != sorted.InvalidIndex(); j = sorted.NextInorder( j ) )
|
||||
{
|
||||
KeyValues *item = sorted[ j ];
|
||||
|
||||
// Add to list
|
||||
m_pList->AddItem( item, 0, false, false );
|
||||
|
||||
item->deleteThis();
|
||||
}
|
||||
|
||||
sorted.RemoveAll();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,98 +1,98 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/pch_vgui_controls.h"
|
||||
#include <vgui_controls/KeyRepeat.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::KeyCode g_iCodesForAliases[FM_NUM_KEYREPEAT_ALIASES] =
|
||||
{
|
||||
KEY_XBUTTON_UP,
|
||||
KEY_XBUTTON_DOWN,
|
||||
KEY_XBUTTON_LEFT,
|
||||
KEY_XBUTTON_RIGHT,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyDown( vgui::KeyCode code )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
if ( m_bAliasDown[ iIndex ] )
|
||||
return;
|
||||
|
||||
Reset();
|
||||
m_bAliasDown[ iIndex ] = true;
|
||||
m_flNextKeyRepeat = system()->GetCurrentTime() + 0.4;
|
||||
m_bHaveKeyDown = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyUp( vgui::KeyCode code )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
m_bAliasDown[ GetIndexForCode(code) ] = false;
|
||||
|
||||
m_bHaveKeyDown = false;
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
if ( m_bAliasDown[i] )
|
||||
{
|
||||
m_bHaveKeyDown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::KeyCode CKeyRepeatHandler::KeyRepeated( void )
|
||||
{
|
||||
if ( IsPC() )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
if ( !m_bHaveKeyDown )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
if ( m_flNextKeyRepeat < system()->GetCurrentTime() )
|
||||
{
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
if ( m_bAliasDown[i] )
|
||||
{
|
||||
m_flNextKeyRepeat = system()->GetCurrentTime() + m_flRepeatTimes[i];
|
||||
return g_iCodesForAliases[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BUTTON_CODE_NONE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::SetKeyRepeatTime( vgui::KeyCode code, float flRepeat )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
Assert( iIndex != -1 );
|
||||
m_flRepeatTimes[ iIndex ] = flRepeat;
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/pch_vgui_controls.h"
|
||||
#include <vgui_controls/KeyRepeat.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::KeyCode g_iCodesForAliases[FM_NUM_KEYREPEAT_ALIASES] =
|
||||
{
|
||||
KEY_XBUTTON_UP,
|
||||
KEY_XBUTTON_DOWN,
|
||||
KEY_XBUTTON_LEFT,
|
||||
KEY_XBUTTON_RIGHT,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyDown( vgui::KeyCode code )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
if ( m_bAliasDown[ iIndex ] )
|
||||
return;
|
||||
|
||||
Reset();
|
||||
m_bAliasDown[ iIndex ] = true;
|
||||
m_flNextKeyRepeat = system()->GetCurrentTime() + 0.4;
|
||||
m_bHaveKeyDown = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyUp( vgui::KeyCode code )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
m_bAliasDown[ GetIndexForCode(code) ] = false;
|
||||
|
||||
m_bHaveKeyDown = false;
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
if ( m_bAliasDown[i] )
|
||||
{
|
||||
m_bHaveKeyDown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::KeyCode CKeyRepeatHandler::KeyRepeated( void )
|
||||
{
|
||||
if ( IsPC() )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
if ( !m_bHaveKeyDown )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
if ( m_flNextKeyRepeat < system()->GetCurrentTime() )
|
||||
{
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
if ( m_bAliasDown[i] )
|
||||
{
|
||||
m_flNextKeyRepeat = system()->GetCurrentTime() + m_flRepeatTimes[i];
|
||||
return g_iCodesForAliases[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BUTTON_CODE_NONE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::SetKeyRepeatTime( vgui::KeyCode code, float flRepeat )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
Assert( iIndex != -1 );
|
||||
m_flRepeatTimes[ iIndex ] = flRepeat;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,252 +1,252 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/MenuBar.h>
|
||||
#include <vgui_controls/MenuButton.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
MENUBARINDENT = 4, // indent from top and bottom of panel.
|
||||
};
|
||||
|
||||
DECLARE_BUILD_FACTORY( MenuBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuBar::MenuBar(Panel *parent, const char *panelName) :
|
||||
Panel(parent, panelName),
|
||||
m_nRightEdge( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuBar::~MenuBar()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::AddButton(MenuButton *button)
|
||||
{
|
||||
button->SetParent(this);
|
||||
button->AddActionSignalTarget(this);
|
||||
m_pMenuButtons.AddToTail(button);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This will add the menu to the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::AddMenu( const char *pButtonName, Menu *pMenu )
|
||||
{
|
||||
MenuButton *pMenuButton = new MenuButton(this, pButtonName, pButtonName);
|
||||
pMenuButton->SetMenu(pMenu);
|
||||
AddButton(pMenuButton);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle key presses, Activate shortcuts
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
// iterate the menu items looking for one that is open
|
||||
// if we find one open, open the one to the right
|
||||
for (int i = 0; i < m_pMenuButtons.Count() - 1; i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsDepressed())
|
||||
{
|
||||
m_pMenuButtons[i]->DoClick();
|
||||
m_pMenuButtons[i+1]->DoClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
{
|
||||
// iterate the menu items looking for one that is open
|
||||
// if we find one open, open the one to the left
|
||||
for (int i = 1; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsDepressed())
|
||||
{
|
||||
m_pMenuButtons[i]->DoClick();
|
||||
m_pMenuButtons[i-1]->DoClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// don't chain back
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle key presses, Activate shortcuts
|
||||
// Input : code -
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnKeyTyped(wchar_t unichar)
|
||||
{
|
||||
if (unichar)
|
||||
{
|
||||
// iterate the menu items looking for one with the matching hotkey
|
||||
for (int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsVisible())
|
||||
{
|
||||
Panel *hot = panel->HasHotkey(unichar);
|
||||
if (hot)
|
||||
{
|
||||
// post a message to the menuitem telling it it's hotkey was pressed
|
||||
PostMessage(hot, new KeyValues("Hotkey"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't chain back
|
||||
}
|
||||
|
||||
void MenuBar::Paint()
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
if (!m_pMenuButtons[i]->IsArmed())
|
||||
m_pMenuButtons[i]->SetDefaultBorder(NULL);
|
||||
else
|
||||
{
|
||||
m_pMenuButtons[i]->SetDefaultBorder(pScheme->GetBorder( "ButtonBorder"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
// get the borders we need
|
||||
SetBorder(pScheme->GetBorder("ButtonBorder"));
|
||||
|
||||
// get the background color
|
||||
SetBgColor(pScheme->GetColor( "MenuBar.BgColor", GetBgColor() ));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reformat according to the new layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::PerformLayout()
|
||||
{
|
||||
int nBarWidth, nBarHeight;
|
||||
GetSize( nBarWidth, nBarHeight );
|
||||
|
||||
// Now position + resize all buttons
|
||||
int x = MENUBARINDENT;
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); ++i )
|
||||
{
|
||||
int nWide, nTall;
|
||||
|
||||
m_pMenuButtons[i]->GetContentSize(nWide, nTall);
|
||||
m_pMenuButtons[i]->SetPos( x, MENUBARINDENT );
|
||||
m_pMenuButtons[i]->SetSize( nWide + Label::Content, nBarHeight - 2 * MENUBARINDENT );
|
||||
|
||||
x += nWide + MENUBARINDENT;
|
||||
}
|
||||
|
||||
m_nRightEdge = x;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the size of the menus in the bar (so other children can be added to menu bar)
|
||||
// Input : w -
|
||||
// int&h -
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::GetContentSize( int& w, int&h )
|
||||
{
|
||||
w = m_nRightEdge + 2;
|
||||
h = GetTall();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnMenuClose()
|
||||
{
|
||||
RequestFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnCursorEnteredMenuButton(int VPanel)
|
||||
{
|
||||
VPANEL menuButton = (VPANEL)VPanel;
|
||||
// see if we had a menu open
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
// one of our buttons was pressed.
|
||||
if (m_pMenuButtons[i]->IsDepressed())
|
||||
{
|
||||
int oldbutton = i;
|
||||
// now see if menuButton is one of ours.
|
||||
for ( int j = 0; j < m_pMenuButtons.Count(); j++)
|
||||
{
|
||||
MenuButton *button = static_cast<MenuButton *>(ipanel()->GetPanel(menuButton, GetModuleName()));
|
||||
// it is one of ours.
|
||||
if ( button == m_pMenuButtons[j])
|
||||
{
|
||||
// if its a different button than the one we already had open,
|
||||
if (j != oldbutton)
|
||||
{
|
||||
// close this menu and open the one we just entered
|
||||
m_pMenuButtons[oldbutton]->DoClick();
|
||||
button->DoClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/MenuBar.h>
|
||||
#include <vgui_controls/MenuButton.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
MENUBARINDENT = 4, // indent from top and bottom of panel.
|
||||
};
|
||||
|
||||
DECLARE_BUILD_FACTORY( MenuBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuBar::MenuBar(Panel *parent, const char *panelName) :
|
||||
Panel(parent, panelName),
|
||||
m_nRightEdge( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuBar::~MenuBar()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::AddButton(MenuButton *button)
|
||||
{
|
||||
button->SetParent(this);
|
||||
button->AddActionSignalTarget(this);
|
||||
m_pMenuButtons.AddToTail(button);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This will add the menu to the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::AddMenu( const char *pButtonName, Menu *pMenu )
|
||||
{
|
||||
MenuButton *pMenuButton = new MenuButton(this, pButtonName, pButtonName);
|
||||
pMenuButton->SetMenu(pMenu);
|
||||
AddButton(pMenuButton);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle key presses, Activate shortcuts
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
// iterate the menu items looking for one that is open
|
||||
// if we find one open, open the one to the right
|
||||
for (int i = 0; i < m_pMenuButtons.Count() - 1; i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsDepressed())
|
||||
{
|
||||
m_pMenuButtons[i]->DoClick();
|
||||
m_pMenuButtons[i+1]->DoClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
{
|
||||
// iterate the menu items looking for one that is open
|
||||
// if we find one open, open the one to the left
|
||||
for (int i = 1; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsDepressed())
|
||||
{
|
||||
m_pMenuButtons[i]->DoClick();
|
||||
m_pMenuButtons[i-1]->DoClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// don't chain back
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle key presses, Activate shortcuts
|
||||
// Input : code -
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnKeyTyped(wchar_t unichar)
|
||||
{
|
||||
if (unichar)
|
||||
{
|
||||
// iterate the menu items looking for one with the matching hotkey
|
||||
for (int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
MenuButton *panel = m_pMenuButtons[i];
|
||||
if (panel->IsVisible())
|
||||
{
|
||||
Panel *hot = panel->HasHotkey(unichar);
|
||||
if (hot)
|
||||
{
|
||||
// post a message to the menuitem telling it it's hotkey was pressed
|
||||
PostMessage(hot, new KeyValues("Hotkey"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't chain back
|
||||
}
|
||||
|
||||
void MenuBar::Paint()
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
if (!m_pMenuButtons[i]->IsArmed())
|
||||
m_pMenuButtons[i]->SetDefaultBorder(NULL);
|
||||
else
|
||||
{
|
||||
m_pMenuButtons[i]->SetDefaultBorder(pScheme->GetBorder( "ButtonBorder"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
// get the borders we need
|
||||
SetBorder(pScheme->GetBorder("ButtonBorder"));
|
||||
|
||||
// get the background color
|
||||
SetBgColor(pScheme->GetColor( "MenuBar.BgColor", GetBgColor() ));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reformat according to the new layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::PerformLayout()
|
||||
{
|
||||
int nBarWidth, nBarHeight;
|
||||
GetSize( nBarWidth, nBarHeight );
|
||||
|
||||
// Now position + resize all buttons
|
||||
int x = MENUBARINDENT;
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); ++i )
|
||||
{
|
||||
int nWide, nTall;
|
||||
|
||||
m_pMenuButtons[i]->GetContentSize(nWide, nTall);
|
||||
m_pMenuButtons[i]->SetPos( x, MENUBARINDENT );
|
||||
m_pMenuButtons[i]->SetSize( nWide + Label::Content, nBarHeight - 2 * MENUBARINDENT );
|
||||
|
||||
x += nWide + MENUBARINDENT;
|
||||
}
|
||||
|
||||
m_nRightEdge = x;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the size of the menus in the bar (so other children can be added to menu bar)
|
||||
// Input : w -
|
||||
// int&h -
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::GetContentSize( int& w, int&h )
|
||||
{
|
||||
w = m_nRightEdge + 2;
|
||||
h = GetTall();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnMenuClose()
|
||||
{
|
||||
RequestFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuBar::OnCursorEnteredMenuButton(int VPanel)
|
||||
{
|
||||
VPANEL menuButton = (VPANEL)VPanel;
|
||||
// see if we had a menu open
|
||||
for ( int i = 0; i < m_pMenuButtons.Count(); i++)
|
||||
{
|
||||
// one of our buttons was pressed.
|
||||
if (m_pMenuButtons[i]->IsDepressed())
|
||||
{
|
||||
int oldbutton = i;
|
||||
// now see if menuButton is one of ours.
|
||||
for ( int j = 0; j < m_pMenuButtons.Count(); j++)
|
||||
{
|
||||
MenuButton *button = static_cast<MenuButton *>(ipanel()->GetPanel(menuButton, GetModuleName()));
|
||||
// it is one of ours.
|
||||
if ( button == m_pMenuButtons[j])
|
||||
{
|
||||
// if its a different button than the one we already had open,
|
||||
if (j != oldbutton)
|
||||
{
|
||||
// close this menu and open the one we just entered
|
||||
m_pMenuButtons[oldbutton]->DoClick();
|
||||
button->DoClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,351 +1,351 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/IVGui.h>
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/MenuButton.h>
|
||||
#include <vgui_controls/Menu.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( MenuButton, MenuButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuButton::MenuButton(Panel *parent, const char *panelName, const char *text) : Button(parent, panelName, text)
|
||||
{
|
||||
m_pMenu = NULL;
|
||||
m_iDirection = Menu::DOWN;
|
||||
m_pDropMenuImage = NULL;
|
||||
m_nImageIndex = -1;
|
||||
_openOffsetY = 0;
|
||||
m_bDropMenuButtonStyle = true; // set to true so SetDropMenuButtonStyle() forces real init.
|
||||
|
||||
SetDropMenuButtonStyle( false );
|
||||
SetUseCaptureMouse( false );
|
||||
SetButtonActivationType( ACTIVATE_ONPRESSED );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuButton::~MenuButton()
|
||||
{
|
||||
delete m_pDropMenuImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: attaches a menu to the menu button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetMenu(Menu *menu)
|
||||
{
|
||||
m_pMenu = menu;
|
||||
|
||||
if (menu)
|
||||
{
|
||||
m_pMenu->SetVisible(false);
|
||||
m_pMenu->AddActionSignalTarget(this);
|
||||
m_pMenu->SetParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Never draw a focus border
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::DrawFocusBorder(int tx0, int ty0, int tx1, int ty1)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the direction from the menu button the menu should open
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetOpenDirection(Menu::MenuDirection_e direction)
|
||||
{
|
||||
m_iDirection = direction;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: hides the menu
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::HideMenu(void)
|
||||
{
|
||||
if (!m_pMenu)
|
||||
return;
|
||||
|
||||
// hide the menu
|
||||
m_pMenu->SetVisible(false);
|
||||
|
||||
// unstick the button
|
||||
BaseClass::ForceDepressed(false);
|
||||
Repaint();
|
||||
|
||||
OnHideMenu(m_pMenu);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the menu button loses focus; hides the menu
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnKillFocus( KeyValues *pParams )
|
||||
{
|
||||
VPANEL hPanel = (VPANEL)pParams->GetPtr( "newPanel" );
|
||||
if ( m_pMenu && !m_pMenu->HasFocus() && hPanel != m_pMenu->GetVPanel() )
|
||||
{
|
||||
HideMenu();
|
||||
}
|
||||
BaseClass::OnKillFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the menu is closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnMenuClose()
|
||||
{
|
||||
HideMenu();
|
||||
PostActionSignal(new KeyValues("MenuClose"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the offset from where menu would normally be placed
|
||||
// Only is used if menu is ALIGN_WITH_PARENT
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetOpenOffsetY(int yOffset)
|
||||
{
|
||||
_openOffsetY = yOffset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool MenuButton::CanBeDefaultButton(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles hotkey accesses
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::DoClick()
|
||||
{
|
||||
if ( IsDropMenuButtonStyle() &&
|
||||
m_pDropMenuImage )
|
||||
{
|
||||
int mx, my;
|
||||
// force the menu to appear where the mouse button was pressed
|
||||
input()->GetCursorPos( mx, my );
|
||||
ScreenToLocal( mx, my );
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
if ( mx <= drawX || !OnCheckMenuItemCount() )
|
||||
{
|
||||
// Treat it like a "regular" button click
|
||||
BaseClass::DoClick();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_pMenu )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// menu is already visible, hide the menu
|
||||
if (m_pMenu->IsVisible())
|
||||
{
|
||||
HideMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
// do nothing if menu is not enabled
|
||||
if (!m_pMenu->IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// force the menu to compute required width/height
|
||||
m_pMenu->PerformLayout();
|
||||
|
||||
// Now position it so it can fit in the workspace
|
||||
m_pMenu->PositionRelativeToPanel(this, m_iDirection, _openOffsetY );
|
||||
|
||||
// make sure we're at the top of the draw order (and therefore our children as well)
|
||||
MoveToFront();
|
||||
|
||||
// notify
|
||||
OnShowMenu(m_pMenu);
|
||||
|
||||
// keep the button depressed
|
||||
BaseClass::ForceDepressed(true);
|
||||
|
||||
// show the menu
|
||||
m_pMenu->SetVisible(true);
|
||||
|
||||
// bring to focus
|
||||
m_pMenu->RequestFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
bool shift = (input()->IsKeyDown(KEY_LSHIFT) || input()->IsKeyDown(KEY_RSHIFT));
|
||||
bool ctrl = (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL));
|
||||
bool alt = (input()->IsKeyDown(KEY_LALT) || input()->IsKeyDown(KEY_RALT));
|
||||
|
||||
if (!shift && !ctrl && !alt)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
{
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
{
|
||||
DoClick();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnCursorEntered()
|
||||
{
|
||||
Button::OnCursorEntered();
|
||||
// post a message to the parent menu.
|
||||
// forward the message on to the parent of this menu.
|
||||
KeyValues *msg = new KeyValues ("CursorEnteredMenuButton");
|
||||
// tell the parent this menuitem is the one that was entered so it can open the menu if it wants
|
||||
msg->SetInt("VPanel", GetVPanel());
|
||||
ivgui()->PostMessage(GetVParent(), msg, NULL);
|
||||
}
|
||||
|
||||
// This style is like the IE "back" button where the left side acts like a regular button, the the right side has a little
|
||||
// combo box dropdown indicator and presents and submenu
|
||||
void MenuButton::SetDropMenuButtonStyle( bool state )
|
||||
{
|
||||
bool changed = m_bDropMenuButtonStyle != state;
|
||||
m_bDropMenuButtonStyle = state;
|
||||
if ( !changed )
|
||||
return;
|
||||
|
||||
if ( state )
|
||||
{
|
||||
m_pDropMenuImage = new TextImage( "u" );
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_pDropMenuImage->SetFont(pScheme->GetFont("Marlett", IsProportional()));
|
||||
// m_pDropMenuImage->SetContentAlignment(Label::a_west);
|
||||
// m_pDropMenuImage->SetTextInset(3, 0);
|
||||
m_nImageIndex = AddImage( m_pDropMenuImage, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetToSimpleTextImage();
|
||||
delete m_pDropMenuImage;
|
||||
m_pDropMenuImage = NULL;
|
||||
m_nImageIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuButton::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
|
||||
if ( m_pDropMenuImage )
|
||||
{
|
||||
SetImageAtIndex( 1, m_pDropMenuImage, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MenuButton::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
Assert( m_nImageIndex >= 0 );
|
||||
if ( m_nImageIndex < 0 || !m_pDropMenuImage )
|
||||
return;
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->ResizeImageToContent();
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
|
||||
SetImageBounds( m_nImageIndex, w - contentW - 2, contentW );
|
||||
}
|
||||
|
||||
bool MenuButton::IsDropMenuButtonStyle() const
|
||||
{
|
||||
return m_bDropMenuButtonStyle;
|
||||
}
|
||||
|
||||
void MenuButton::Paint(void)
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
m_pDropMenuImage->SetColor( IsEnabled() ? GetButtonFgColor() : GetDisabledFgColor1() );
|
||||
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
|
||||
surface()->DrawSetColor( IsEnabled() ? GetButtonFgColor() : GetDisabledFgColor1() );
|
||||
surface()->DrawFilledRect( drawX, 3, drawX + 1, GetTall() - 3 );
|
||||
}
|
||||
|
||||
void MenuButton::OnCursorMoved( int x, int y )
|
||||
{
|
||||
BaseClass::OnCursorMoved( x, y );
|
||||
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
if ( x <= drawX || !OnCheckMenuItemCount() )
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSEDANDRELEASED);
|
||||
SetUseCaptureMouse(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
SetUseCaptureMouse(false);
|
||||
}
|
||||
}
|
||||
|
||||
Menu *MenuButton::GetMenu()
|
||||
{
|
||||
Assert( m_pMenu );
|
||||
return m_pMenu;
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/IVGui.h>
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/MenuButton.h>
|
||||
#include <vgui_controls/Menu.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( MenuButton, MenuButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuButton::MenuButton(Panel *parent, const char *panelName, const char *text) : Button(parent, panelName, text)
|
||||
{
|
||||
m_pMenu = NULL;
|
||||
m_iDirection = Menu::DOWN;
|
||||
m_pDropMenuImage = NULL;
|
||||
m_nImageIndex = -1;
|
||||
_openOffsetY = 0;
|
||||
m_bDropMenuButtonStyle = true; // set to true so SetDropMenuButtonStyle() forces real init.
|
||||
|
||||
SetDropMenuButtonStyle( false );
|
||||
SetUseCaptureMouse( false );
|
||||
SetButtonActivationType( ACTIVATE_ONPRESSED );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MenuButton::~MenuButton()
|
||||
{
|
||||
delete m_pDropMenuImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: attaches a menu to the menu button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetMenu(Menu *menu)
|
||||
{
|
||||
m_pMenu = menu;
|
||||
|
||||
if (menu)
|
||||
{
|
||||
m_pMenu->SetVisible(false);
|
||||
m_pMenu->AddActionSignalTarget(this);
|
||||
m_pMenu->SetParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Never draw a focus border
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::DrawFocusBorder(int tx0, int ty0, int tx1, int ty1)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the direction from the menu button the menu should open
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetOpenDirection(Menu::MenuDirection_e direction)
|
||||
{
|
||||
m_iDirection = direction;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: hides the menu
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::HideMenu(void)
|
||||
{
|
||||
if (!m_pMenu)
|
||||
return;
|
||||
|
||||
// hide the menu
|
||||
m_pMenu->SetVisible(false);
|
||||
|
||||
// unstick the button
|
||||
BaseClass::ForceDepressed(false);
|
||||
Repaint();
|
||||
|
||||
OnHideMenu(m_pMenu);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the menu button loses focus; hides the menu
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnKillFocus( KeyValues *pParams )
|
||||
{
|
||||
VPANEL hPanel = (VPANEL)pParams->GetPtr( "newPanel" );
|
||||
if ( m_pMenu && !m_pMenu->HasFocus() && hPanel != m_pMenu->GetVPanel() )
|
||||
{
|
||||
HideMenu();
|
||||
}
|
||||
BaseClass::OnKillFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the menu is closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnMenuClose()
|
||||
{
|
||||
HideMenu();
|
||||
PostActionSignal(new KeyValues("MenuClose"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the offset from where menu would normally be placed
|
||||
// Only is used if menu is ALIGN_WITH_PARENT
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::SetOpenOffsetY(int yOffset)
|
||||
{
|
||||
_openOffsetY = yOffset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool MenuButton::CanBeDefaultButton(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles hotkey accesses
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::DoClick()
|
||||
{
|
||||
if ( IsDropMenuButtonStyle() &&
|
||||
m_pDropMenuImage )
|
||||
{
|
||||
int mx, my;
|
||||
// force the menu to appear where the mouse button was pressed
|
||||
input()->GetCursorPos( mx, my );
|
||||
ScreenToLocal( mx, my );
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
if ( mx <= drawX || !OnCheckMenuItemCount() )
|
||||
{
|
||||
// Treat it like a "regular" button click
|
||||
BaseClass::DoClick();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_pMenu )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// menu is already visible, hide the menu
|
||||
if (m_pMenu->IsVisible())
|
||||
{
|
||||
HideMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
// do nothing if menu is not enabled
|
||||
if (!m_pMenu->IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// force the menu to compute required width/height
|
||||
m_pMenu->PerformLayout();
|
||||
|
||||
// Now position it so it can fit in the workspace
|
||||
m_pMenu->PositionRelativeToPanel(this, m_iDirection, _openOffsetY );
|
||||
|
||||
// make sure we're at the top of the draw order (and therefore our children as well)
|
||||
MoveToFront();
|
||||
|
||||
// notify
|
||||
OnShowMenu(m_pMenu);
|
||||
|
||||
// keep the button depressed
|
||||
BaseClass::ForceDepressed(true);
|
||||
|
||||
// show the menu
|
||||
m_pMenu->SetVisible(true);
|
||||
|
||||
// bring to focus
|
||||
m_pMenu->RequestFocus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
bool shift = (input()->IsKeyDown(KEY_LSHIFT) || input()->IsKeyDown(KEY_RSHIFT));
|
||||
bool ctrl = (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL));
|
||||
bool alt = (input()->IsKeyDown(KEY_LALT) || input()->IsKeyDown(KEY_RALT));
|
||||
|
||||
if (!shift && !ctrl && !alt)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
{
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
{
|
||||
DoClick();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MenuButton::OnCursorEntered()
|
||||
{
|
||||
Button::OnCursorEntered();
|
||||
// post a message to the parent menu.
|
||||
// forward the message on to the parent of this menu.
|
||||
KeyValues *msg = new KeyValues ("CursorEnteredMenuButton");
|
||||
// tell the parent this menuitem is the one that was entered so it can open the menu if it wants
|
||||
msg->SetInt("VPanel", GetVPanel());
|
||||
ivgui()->PostMessage(GetVParent(), msg, NULL);
|
||||
}
|
||||
|
||||
// This style is like the IE "back" button where the left side acts like a regular button, the the right side has a little
|
||||
// combo box dropdown indicator and presents and submenu
|
||||
void MenuButton::SetDropMenuButtonStyle( bool state )
|
||||
{
|
||||
bool changed = m_bDropMenuButtonStyle != state;
|
||||
m_bDropMenuButtonStyle = state;
|
||||
if ( !changed )
|
||||
return;
|
||||
|
||||
if ( state )
|
||||
{
|
||||
m_pDropMenuImage = new TextImage( "u" );
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_pDropMenuImage->SetFont(pScheme->GetFont("Marlett", IsProportional()));
|
||||
// m_pDropMenuImage->SetContentAlignment(Label::a_west);
|
||||
// m_pDropMenuImage->SetTextInset(3, 0);
|
||||
m_nImageIndex = AddImage( m_pDropMenuImage, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetToSimpleTextImage();
|
||||
delete m_pDropMenuImage;
|
||||
m_pDropMenuImage = NULL;
|
||||
m_nImageIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuButton::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
|
||||
if ( m_pDropMenuImage )
|
||||
{
|
||||
SetImageAtIndex( 1, m_pDropMenuImage, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MenuButton::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
Assert( m_nImageIndex >= 0 );
|
||||
if ( m_nImageIndex < 0 || !m_pDropMenuImage )
|
||||
return;
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->ResizeImageToContent();
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
|
||||
SetImageBounds( m_nImageIndex, w - contentW - 2, contentW );
|
||||
}
|
||||
|
||||
bool MenuButton::IsDropMenuButtonStyle() const
|
||||
{
|
||||
return m_bDropMenuButtonStyle;
|
||||
}
|
||||
|
||||
void MenuButton::Paint(void)
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
m_pDropMenuImage->SetColor( IsEnabled() ? GetButtonFgColor() : GetDisabledFgColor1() );
|
||||
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
|
||||
surface()->DrawSetColor( IsEnabled() ? GetButtonFgColor() : GetDisabledFgColor1() );
|
||||
surface()->DrawFilledRect( drawX, 3, drawX + 1, GetTall() - 3 );
|
||||
}
|
||||
|
||||
void MenuButton::OnCursorMoved( int x, int y )
|
||||
{
|
||||
BaseClass::OnCursorMoved( x, y );
|
||||
|
||||
if ( !IsDropMenuButtonStyle() )
|
||||
return;
|
||||
|
||||
int contentW, contentH;
|
||||
m_pDropMenuImage->GetContentSize( contentW, contentH );
|
||||
int drawX = GetWide() - contentW - 2;
|
||||
if ( x <= drawX || !OnCheckMenuItemCount() )
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSEDANDRELEASED);
|
||||
SetUseCaptureMouse(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
SetUseCaptureMouse(false);
|
||||
}
|
||||
}
|
||||
|
||||
Menu *MenuButton::GetMenu()
|
||||
{
|
||||
Assert( m_pMenu );
|
||||
return m_pMenu;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,395 +1,395 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/IInput.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/MessageBox.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
vgui::Panel *MessageBox_Factory()
|
||||
{
|
||||
return new MessageBox("MessageBox", "MessageBoxText");
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM( MessageBox, MessageBox_Factory );
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::MessageBox(const char *title, const char *text, Panel *parent) : Frame(parent, NULL, false)
|
||||
{
|
||||
SetTitle(title, true);
|
||||
m_pMessageLabel = new Label(this, NULL, text);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::MessageBox(const wchar_t *wszTitle, const wchar_t *wszText, Panel *parent) : Frame(parent, NULL, false)
|
||||
{
|
||||
SetTitle(wszTitle, true);
|
||||
m_pMessageLabel = new Label(this, NULL, wszText);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor Helper
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::Init()
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pFrameOver = NULL;
|
||||
m_bShowMessageBoxOverCursor = false;
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
|
||||
m_pOkButton = new Button(this, NULL, "#MessageBox_OK");
|
||||
m_pOkButton->SetCommand( "OnOk" );
|
||||
m_pOkButton->AddActionSignalTarget(this);
|
||||
|
||||
m_pCancelButton = new Button(this, NULL, "#MessageBox_Cancel");
|
||||
m_pCancelButton->SetCommand( "OnCancel" );
|
||||
m_pCancelButton->AddActionSignalTarget(this);
|
||||
m_pCancelButton->SetVisible( false );
|
||||
|
||||
m_OkCommand = m_CancelCommand = NULL;
|
||||
m_bNoAutoClose = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::~MessageBox()
|
||||
{
|
||||
if ( m_OkCommand )
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
if ( m_CancelCommand )
|
||||
{
|
||||
m_CancelCommand->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the message box over the cursor
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::ShowMessageBoxOverCursor( bool bEnable )
|
||||
{
|
||||
m_bShowMessageBoxOverCursor = bEnable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size the message label properly
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::OnCommand( const char *pCommand )
|
||||
{
|
||||
if ( vgui::input()->GetAppModalSurface() == GetVPanel() )
|
||||
{
|
||||
vgui::input()->ReleaseAppModalSurface();
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "OnOk" ) )
|
||||
{
|
||||
if ( m_OkCommand )
|
||||
{
|
||||
PostActionSignal(m_OkCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
else if ( !Q_stricmp( pCommand, "OnCancel" ) )
|
||||
{
|
||||
if ( m_CancelCommand )
|
||||
{
|
||||
PostActionSignal(m_CancelCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_bNoAutoClose )
|
||||
{
|
||||
OnShutdownRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size the message label properly
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
m_pMessageLabel->GetContentSize(wide, tall);
|
||||
m_pMessageLabel->SetSize(wide, tall);
|
||||
|
||||
wide += 100;
|
||||
tall += 100;
|
||||
SetSize(wide, tall);
|
||||
|
||||
if ( m_bShowMessageBoxOverCursor )
|
||||
{
|
||||
PlaceUnderCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
// move to the middle of the screen
|
||||
if ( m_pFrameOver )
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
m_pFrameOver->GetPos(frameX, frameY);
|
||||
m_pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the message box into a modal state
|
||||
// Does not suspend execution - use addActionSignal to get return value
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::DoModal(Frame* pFrameOver)
|
||||
{
|
||||
ShowWindow(pFrameOver);
|
||||
/*
|
||||
// move to the middle of the screen
|
||||
// get the screen size
|
||||
int wide, tall;
|
||||
// get our dialog size
|
||||
GetSize(wide, tall);
|
||||
|
||||
if (pFrameOver)
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
pFrameOver->GetPos(frameX, frameY);
|
||||
pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
if (m_pOkButton->IsVisible())
|
||||
m_pOkButton->RequestFocus();
|
||||
else // handle message boxes with no button
|
||||
RequestFocus();
|
||||
*/
|
||||
input()->SetAppModalSurface(GetVPanel());
|
||||
}
|
||||
|
||||
void MessageBox::ShowWindow(Frame *pFrameOver)
|
||||
{
|
||||
m_pFrameOver = pFrameOver;
|
||||
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
if ( m_pOkButton->IsVisible() )
|
||||
{
|
||||
m_pOkButton->RequestFocus();
|
||||
}
|
||||
else // handle message boxes with no button
|
||||
{
|
||||
RequestFocus();
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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;
|
||||
tall += y;
|
||||
|
||||
int boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
int oldWide, oldTall;
|
||||
m_pOkButton->GetSize(oldWide, oldTall);
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pOkButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
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);
|
||||
}
|
||||
|
||||
boxWidth = max(boxWidth, m_pMessageLabel->GetWide() + 100);
|
||||
boxWidth = max(boxWidth, (btnWide + btnWide2) * 2 + 30);
|
||||
SetSize(boxWidth, boxTall);
|
||||
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
m_pMessageLabel->SetPos((wide/2)-(m_pMessageLabel->GetWide()/2) + x, y + 5 );
|
||||
if ( !m_pCancelButton->IsVisible() )
|
||||
{
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
GetSize(boxWidth, boxTall);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a string command to be sent when the OK button is pressed.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCommand(const char *command)
|
||||
{
|
||||
if (m_OkCommand)
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
m_OkCommand = new KeyValues("Command", "command", command);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the command
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCommand(KeyValues *command)
|
||||
{
|
||||
if (m_OkCommand)
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
m_OkCommand = command;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::OnShutdownRequest()
|
||||
{
|
||||
// Shutdown the dialog
|
||||
PostMessage(this, new KeyValues("Close"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the visibility of the OK button.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonVisible(bool state)
|
||||
{
|
||||
m_pOkButton->SetVisible(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the Text on the OK button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonText(const char *buttonText)
|
||||
{
|
||||
m_pOkButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the Text on the OK button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonText(const wchar_t *wszButtonText)
|
||||
{
|
||||
m_pOkButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cancel button (off by default)
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
m_pCancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelButtonText(const char *buttonText)
|
||||
{
|
||||
m_pCancelButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelButtonText(const wchar_t *wszButtonText)
|
||||
{
|
||||
m_pCancelButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelCommand( KeyValues *command )
|
||||
{
|
||||
if (m_CancelCommand)
|
||||
{
|
||||
m_CancelCommand->deleteThis();
|
||||
}
|
||||
m_CancelCommand = command;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles visibility of the close box.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::DisableCloseButton(bool state)
|
||||
{
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
m_bNoAutoClose = true;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/IInput.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/MessageBox.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
vgui::Panel *MessageBox_Factory()
|
||||
{
|
||||
return new MessageBox("MessageBox", "MessageBoxText");
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM( MessageBox, MessageBox_Factory );
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::MessageBox(const char *title, const char *text, Panel *parent) : Frame(parent, NULL, false)
|
||||
{
|
||||
SetTitle(title, true);
|
||||
m_pMessageLabel = new Label(this, NULL, text);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::MessageBox(const wchar_t *wszTitle, const wchar_t *wszText, Panel *parent) : Frame(parent, NULL, false)
|
||||
{
|
||||
SetTitle(wszTitle, true);
|
||||
m_pMessageLabel = new Label(this, NULL, wszText);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor Helper
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::Init()
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pFrameOver = NULL;
|
||||
m_bShowMessageBoxOverCursor = false;
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
|
||||
m_pOkButton = new Button(this, NULL, "#MessageBox_OK");
|
||||
m_pOkButton->SetCommand( "OnOk" );
|
||||
m_pOkButton->AddActionSignalTarget(this);
|
||||
|
||||
m_pCancelButton = new Button(this, NULL, "#MessageBox_Cancel");
|
||||
m_pCancelButton->SetCommand( "OnCancel" );
|
||||
m_pCancelButton->AddActionSignalTarget(this);
|
||||
m_pCancelButton->SetVisible( false );
|
||||
|
||||
m_OkCommand = m_CancelCommand = NULL;
|
||||
m_bNoAutoClose = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MessageBox::~MessageBox()
|
||||
{
|
||||
if ( m_OkCommand )
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
if ( m_CancelCommand )
|
||||
{
|
||||
m_CancelCommand->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shows the message box over the cursor
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::ShowMessageBoxOverCursor( bool bEnable )
|
||||
{
|
||||
m_bShowMessageBoxOverCursor = bEnable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size the message label properly
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::OnCommand( const char *pCommand )
|
||||
{
|
||||
if ( vgui::input()->GetAppModalSurface() == GetVPanel() )
|
||||
{
|
||||
vgui::input()->ReleaseAppModalSurface();
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "OnOk" ) )
|
||||
{
|
||||
if ( m_OkCommand )
|
||||
{
|
||||
PostActionSignal(m_OkCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
else if ( !Q_stricmp( pCommand, "OnCancel" ) )
|
||||
{
|
||||
if ( m_CancelCommand )
|
||||
{
|
||||
PostActionSignal(m_CancelCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_bNoAutoClose )
|
||||
{
|
||||
OnShutdownRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size the message label properly
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
m_pMessageLabel->GetContentSize(wide, tall);
|
||||
m_pMessageLabel->SetSize(wide, tall);
|
||||
|
||||
wide += 100;
|
||||
tall += 100;
|
||||
SetSize(wide, tall);
|
||||
|
||||
if ( m_bShowMessageBoxOverCursor )
|
||||
{
|
||||
PlaceUnderCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
// move to the middle of the screen
|
||||
if ( m_pFrameOver )
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
m_pFrameOver->GetPos(frameX, frameY);
|
||||
m_pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the message box into a modal state
|
||||
// Does not suspend execution - use addActionSignal to get return value
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::DoModal(Frame* pFrameOver)
|
||||
{
|
||||
ShowWindow(pFrameOver);
|
||||
/*
|
||||
// move to the middle of the screen
|
||||
// get the screen size
|
||||
int wide, tall;
|
||||
// get our dialog size
|
||||
GetSize(wide, tall);
|
||||
|
||||
if (pFrameOver)
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
pFrameOver->GetPos(frameX, frameY);
|
||||
pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
if (m_pOkButton->IsVisible())
|
||||
m_pOkButton->RequestFocus();
|
||||
else // handle message boxes with no button
|
||||
RequestFocus();
|
||||
*/
|
||||
input()->SetAppModalSurface(GetVPanel());
|
||||
}
|
||||
|
||||
void MessageBox::ShowWindow(Frame *pFrameOver)
|
||||
{
|
||||
m_pFrameOver = pFrameOver;
|
||||
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
if ( m_pOkButton->IsVisible() )
|
||||
{
|
||||
m_pOkButton->RequestFocus();
|
||||
}
|
||||
else // handle message boxes with no button
|
||||
{
|
||||
RequestFocus();
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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;
|
||||
tall += y;
|
||||
|
||||
int boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
int oldWide, oldTall;
|
||||
m_pOkButton->GetSize(oldWide, oldTall);
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pOkButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
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);
|
||||
}
|
||||
|
||||
boxWidth = max(boxWidth, m_pMessageLabel->GetWide() + 100);
|
||||
boxWidth = max(boxWidth, (btnWide + btnWide2) * 2 + 30);
|
||||
SetSize(boxWidth, boxTall);
|
||||
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
m_pMessageLabel->SetPos((wide/2)-(m_pMessageLabel->GetWide()/2) + x, y + 5 );
|
||||
if ( !m_pCancelButton->IsVisible() )
|
||||
{
|
||||
m_pOkButton->SetPos((wide/2)-(m_pOkButton->GetWide()/2) + x, tall - m_pOkButton->GetTall() - 15);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
GetSize(boxWidth, boxTall);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a string command to be sent when the OK button is pressed.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCommand(const char *command)
|
||||
{
|
||||
if (m_OkCommand)
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
m_OkCommand = new KeyValues("Command", "command", command);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the command
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCommand(KeyValues *command)
|
||||
{
|
||||
if (m_OkCommand)
|
||||
{
|
||||
m_OkCommand->deleteThis();
|
||||
}
|
||||
m_OkCommand = command;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::OnShutdownRequest()
|
||||
{
|
||||
// Shutdown the dialog
|
||||
PostMessage(this, new KeyValues("Close"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the visibility of the OK button.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonVisible(bool state)
|
||||
{
|
||||
m_pOkButton->SetVisible(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the Text on the OK button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonText(const char *buttonText)
|
||||
{
|
||||
m_pOkButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the Text on the OK button
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetOKButtonText(const wchar_t *wszButtonText)
|
||||
{
|
||||
m_pOkButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cancel button (off by default)
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
m_pCancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelButtonText(const char *buttonText)
|
||||
{
|
||||
m_pCancelButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelButtonText(const wchar_t *wszButtonText)
|
||||
{
|
||||
m_pCancelButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void MessageBox::SetCancelCommand( KeyValues *command )
|
||||
{
|
||||
if (m_CancelCommand)
|
||||
{
|
||||
m_CancelCommand->deleteThis();
|
||||
}
|
||||
m_CancelCommand = command;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles visibility of the close box.
|
||||
//-----------------------------------------------------------------------------
|
||||
void MessageBox::DisableCloseButton(bool state)
|
||||
{
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
m_bNoAutoClose = true;
|
||||
}
|
||||
|
||||
@@ -1,359 +1,359 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/MessageDialog.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CMessageDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
CMessageDialog::CMessageDialog( vgui::Panel *pParent, const uint nType, const char *pTitle, const char *pMsg, const char *pCmdA, const char *pCmdB, vgui::Panel *pCreator, bool bShowActivity )
|
||||
: BaseClass( pParent, "MessageDialog" )
|
||||
{
|
||||
SetSize( 500, 200 );
|
||||
SetDeleteSelfOnClose( true );
|
||||
SetTitleBarVisible( false );
|
||||
SetCloseButtonVisible( false );
|
||||
SetSizeable( false );
|
||||
|
||||
m_pControlSettings = NULL;
|
||||
m_pCreator = pCreator ? pCreator : pParent;
|
||||
|
||||
m_nType = nType;
|
||||
m_pTitle = new vgui::Label( this, "TitleLabel", pTitle );
|
||||
m_pMsg = new vgui::Label( this, "MessageLabel", pMsg );
|
||||
m_pAnimatingPanel = new vgui::AnimatingImagePanel( this, "AnimatingPanel" );
|
||||
|
||||
m_bShowActivity = bShowActivity;
|
||||
|
||||
if ( nType & MD_SIMPLEFRAME )
|
||||
{
|
||||
SetPaintBackgroundEnabled( true );
|
||||
m_pBackground = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBackground = new vgui::ImagePanel( this, "Background" );
|
||||
if ( nType & MD_WARNING )
|
||||
{
|
||||
m_pBackground->SetName( "WarningBackground" );
|
||||
}
|
||||
else if ( nType & MD_ERROR )
|
||||
{
|
||||
m_pBackground->SetName( "ErrorBackground" );
|
||||
}
|
||||
}
|
||||
|
||||
Q_memset( m_pCommands, 0, sizeof( m_pCommands ) );
|
||||
Q_memset( m_Buttons, 0, sizeof( m_Buttons ) );
|
||||
|
||||
if ( pCmdA )
|
||||
{
|
||||
const int len = Q_strlen( pCmdA ) + 1;
|
||||
m_pCommands[BTN_A] = (char*)malloc( len );
|
||||
Q_strncpy( m_pCommands[BTN_A], pCmdA, len );
|
||||
}
|
||||
|
||||
if ( pCmdB )
|
||||
{
|
||||
const int len = Q_strlen( pCmdB ) + 1;
|
||||
m_pCommands[BTN_B] = (char*)malloc( len );
|
||||
Q_strncpy( m_pCommands[BTN_B], pCmdB, len );
|
||||
}
|
||||
|
||||
// invalid until pressed
|
||||
m_ButtonPressed = BTN_INVALID;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CMessageDialog::~CMessageDialog()
|
||||
{
|
||||
if ( m_ButtonPressed != BTN_INVALID && ( m_nType & MD_COMMANDAFTERCLOSE ) )
|
||||
{
|
||||
// caller wants the command sent after closure
|
||||
m_pCreator->OnCommand( m_pCommands[m_ButtonPressed] );
|
||||
}
|
||||
else if ( m_nType & MD_COMMANDONFORCECLOSE )
|
||||
{
|
||||
// caller wants the command sent after closure
|
||||
m_pCreator->OnCommand( m_pCommands[BTN_A] );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
free( m_pCommands[i] );
|
||||
m_pCommands[i] = NULL;
|
||||
|
||||
delete m_Buttons[i].pIcon;
|
||||
delete m_Buttons[i].pText;
|
||||
}
|
||||
|
||||
delete m_pTitle;
|
||||
m_pTitle = NULL;
|
||||
|
||||
delete m_pMsg;
|
||||
m_pMsg = NULL;
|
||||
|
||||
delete m_pBackground;
|
||||
m_pBackground = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to pass to LoadControlSettings()
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::SetControlSettingsKeys( KeyValues *pKeys )
|
||||
{
|
||||
m_pControlSettings = pKeys;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create a new button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::CreateButtonLabel( ButtonLabel_s *pButton, const char *pIcon, const char *pText )
|
||||
{
|
||||
pButton->nWide = m_ButtonIconLabelSpace;
|
||||
pButton->bCreated = true;
|
||||
|
||||
pButton->pIcon = new vgui::Label( this, "icon", pIcon );
|
||||
SETUP_PANEL( pButton->pIcon );
|
||||
pButton->pIcon->SetFont( m_hButtonFont );
|
||||
pButton->pIcon->SizeToContents();
|
||||
pButton->nWide += pButton->pIcon->GetWide();
|
||||
|
||||
pButton->pText = new vgui::Label( this, "text", pText );
|
||||
SETUP_PANEL( pButton->pText );
|
||||
pButton->pText->SetFont( m_hTextFont );
|
||||
pButton->pText->SizeToContents();
|
||||
pButton->pText->SetFgColor( m_ButtonTextColor );
|
||||
pButton->nWide += pButton->pText->GetWide();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create and arrange the panel button labels according to the dialog type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
|
||||
LoadControlSettings( "resource/UI/MessageDialog.res", "GAME", m_pControlSettings );
|
||||
|
||||
m_hButtonFont = pScheme->GetFont( "GameUIButtons" );
|
||||
m_hTextFont = pScheme->GetFont( "MenuLarge" );
|
||||
|
||||
if ( m_nType & MD_OK )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_OK" );
|
||||
}
|
||||
else if ( m_nType & MD_CANCEL )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_Cancel" );
|
||||
}
|
||||
else if ( m_nType & MD_OKCANCEL )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_OK" );
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_Cancel" );
|
||||
}
|
||||
else if ( m_nType & MD_YESNO )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_Yes" );
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_No" );
|
||||
}
|
||||
|
||||
// count the buttons and add up their widths
|
||||
int cButtons = 0;
|
||||
int nTotalWide = 0;
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
if ( m_Buttons[i].bCreated )
|
||||
{
|
||||
++cButtons;
|
||||
nTotalWide += m_Buttons[i].nWide;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure text and icons are center-aligned vertically with each other
|
||||
int nButtonTall = vgui::surface()->GetFontTall( m_hButtonFont );
|
||||
int nTextTall = vgui::surface()->GetFontTall( m_hTextFont );
|
||||
int nVerticalAdjust = ( nButtonTall - nTextTall ) / 2;
|
||||
|
||||
// position the buttons with even horizontal spacing
|
||||
int xpos = 0;
|
||||
int ypos = GetTall() - max( nButtonTall, nTextTall ) - m_ButtonMargin;
|
||||
int nSpacing = ( GetWide() - nTotalWide ) / ( cButtons + 1 );
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
if ( m_Buttons[i].bCreated )
|
||||
{
|
||||
xpos += nSpacing;
|
||||
m_Buttons[i].pIcon->SetPos( xpos, ypos );
|
||||
xpos += m_Buttons[i].pIcon->GetWide() + m_ButtonIconLabelSpace;
|
||||
m_Buttons[i].pText->SetPos( xpos, ypos + nVerticalAdjust );
|
||||
xpos += m_Buttons[i].pText->GetWide();
|
||||
}
|
||||
}
|
||||
|
||||
m_clrNotSimpleBG = pScheme->GetColor( "MessageDialog.MatchmakingBG", Color( 200, 184, 151, 255 ) );
|
||||
m_clrNotSimpleBGBlack = pScheme->GetColor( "MessageDialog.MatchmakingBGBlack", Color( 52, 48, 55, 255 ) );
|
||||
|
||||
if ( !m_bShowActivity )
|
||||
{
|
||||
if ( m_pAnimatingPanel )
|
||||
{
|
||||
if ( m_pAnimatingPanel->IsVisible() )
|
||||
{
|
||||
|
||||
m_pAnimatingPanel->SetVisible( false );
|
||||
}
|
||||
|
||||
m_pAnimatingPanel->StopAnimation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_pAnimatingPanel )
|
||||
{
|
||||
if ( !m_pAnimatingPanel->IsVisible() )
|
||||
{
|
||||
m_pAnimatingPanel->SetVisible( true );
|
||||
}
|
||||
|
||||
m_pAnimatingPanel->StartAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
MoveToCenterOfScreen();
|
||||
|
||||
if ( m_bShowActivity && m_ActivityIndent )
|
||||
{
|
||||
// If we're animating, we push our text label in, and reduce its width
|
||||
int iX,iY,iW,iH;
|
||||
m_pMsg->GetBounds( iX, iY, iW, iH );
|
||||
m_pMsg->SetBounds( iX + m_ActivityIndent, iY, max(0,iW-m_ActivityIndent), iH );
|
||||
}
|
||||
|
||||
// Invalidate the scheme on our message label so that it recalculates
|
||||
// its line breaks in case it was resized when we loaded our .res file.
|
||||
m_pMsg->InvalidateLayout( false, true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create and arrange the panel button labels according to the dialog type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::ApplySettings( KeyValues *inResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
|
||||
m_pTitle->SetFgColor( inResourceData->GetColor( "titlecolor" ) );
|
||||
|
||||
m_pMsg->SetFgColor( inResourceData->GetColor( "messagecolor" ) );
|
||||
|
||||
m_ButtonTextColor = inResourceData->GetColor( "buttontextcolor" );
|
||||
|
||||
m_FooterTall = inResourceData->GetInt( "footer_tall", 0 );
|
||||
m_ButtonMargin = inResourceData->GetInt( "button_margin", 25 );
|
||||
m_ButtonIconLabelSpace = inResourceData->GetInt( "button_separator", 10 );
|
||||
m_ActivityIndent = inResourceData->GetInt( "activity_indent", 0 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
uint CMessageDialog::GetType( void )
|
||||
{
|
||||
return m_nType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::DoCommand( int button )
|
||||
{
|
||||
if ( button == BTN_INVALID || ( m_nType & MD_COMMANDONFORCECLOSE ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_pCommands[button] )
|
||||
{
|
||||
m_ButtonPressed = button;
|
||||
if ( !( m_nType & MD_COMMANDAFTERCLOSE ) )
|
||||
{
|
||||
// caller wants the command sent before closure
|
||||
m_pCreator->OnCommand( m_pCommands[m_ButtonPressed] );
|
||||
}
|
||||
m_pCreator->OnCommand( "ReleaseModalWindow" );
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::OnKeyCodePressed( vgui::KeyCode code )
|
||||
{
|
||||
if ( m_ButtonPressed != BTN_INVALID || GetAlpha() != 255 )
|
||||
{
|
||||
// inhibit any further key activity or during transitions
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( GetBaseButtonCode( code ) )
|
||||
{
|
||||
case KEY_XBUTTON_A:
|
||||
DoCommand( BTN_A );
|
||||
break;
|
||||
|
||||
case KEY_XBUTTON_B:
|
||||
DoCommand( BTN_B );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::PaintBackground( void )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
if ( !( m_nType & MD_SIMPLEFRAME ) )
|
||||
{
|
||||
int nAlpha = GetAlpha();
|
||||
|
||||
m_clrNotSimpleBG[3] = nAlpha;
|
||||
m_clrNotSimpleBGBlack[3] = nAlpha;
|
||||
|
||||
DrawBox( 0, 0, wide, tall, m_clrNotSimpleBGBlack, 1.0f );
|
||||
DrawBox( 0, 0, wide, tall - m_FooterTall, m_clrNotSimpleBG, 1.0f );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Color col = GetBgColor();
|
||||
DrawBox( 0, 0, wide, tall, col, 1.0f );
|
||||
|
||||
// offset the inset by title
|
||||
int titleX, titleY, titleWide, titleTall;
|
||||
m_pTitle->GetBounds( titleX, titleY, titleWide, titleTall );
|
||||
int y = titleY + titleTall;
|
||||
|
||||
// draw an inset
|
||||
Color darkColor;
|
||||
darkColor.SetColor( 0.70f * (float)col.r(), 0.70f * (float)col.g(), 0.70f * (float)col.b(), col.a() );
|
||||
vgui::surface()->DrawSetColor( darkColor );
|
||||
vgui::surface()->DrawFilledRect( 8, y, wide - 8, tall - 8 );
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/MessageDialog.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CMessageDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
CMessageDialog::CMessageDialog( vgui::Panel *pParent, const uint nType, const char *pTitle, const char *pMsg, const char *pCmdA, const char *pCmdB, vgui::Panel *pCreator, bool bShowActivity )
|
||||
: BaseClass( pParent, "MessageDialog" )
|
||||
{
|
||||
SetSize( 500, 200 );
|
||||
SetDeleteSelfOnClose( true );
|
||||
SetTitleBarVisible( false );
|
||||
SetCloseButtonVisible( false );
|
||||
SetSizeable( false );
|
||||
|
||||
m_pControlSettings = NULL;
|
||||
m_pCreator = pCreator ? pCreator : pParent;
|
||||
|
||||
m_nType = nType;
|
||||
m_pTitle = new vgui::Label( this, "TitleLabel", pTitle );
|
||||
m_pMsg = new vgui::Label( this, "MessageLabel", pMsg );
|
||||
m_pAnimatingPanel = new vgui::AnimatingImagePanel( this, "AnimatingPanel" );
|
||||
|
||||
m_bShowActivity = bShowActivity;
|
||||
|
||||
if ( nType & MD_SIMPLEFRAME )
|
||||
{
|
||||
SetPaintBackgroundEnabled( true );
|
||||
m_pBackground = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBackground = new vgui::ImagePanel( this, "Background" );
|
||||
if ( nType & MD_WARNING )
|
||||
{
|
||||
m_pBackground->SetName( "WarningBackground" );
|
||||
}
|
||||
else if ( nType & MD_ERROR )
|
||||
{
|
||||
m_pBackground->SetName( "ErrorBackground" );
|
||||
}
|
||||
}
|
||||
|
||||
Q_memset( m_pCommands, 0, sizeof( m_pCommands ) );
|
||||
Q_memset( m_Buttons, 0, sizeof( m_Buttons ) );
|
||||
|
||||
if ( pCmdA )
|
||||
{
|
||||
const int len = Q_strlen( pCmdA ) + 1;
|
||||
m_pCommands[BTN_A] = (char*)malloc( len );
|
||||
Q_strncpy( m_pCommands[BTN_A], pCmdA, len );
|
||||
}
|
||||
|
||||
if ( pCmdB )
|
||||
{
|
||||
const int len = Q_strlen( pCmdB ) + 1;
|
||||
m_pCommands[BTN_B] = (char*)malloc( len );
|
||||
Q_strncpy( m_pCommands[BTN_B], pCmdB, len );
|
||||
}
|
||||
|
||||
// invalid until pressed
|
||||
m_ButtonPressed = BTN_INVALID;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CMessageDialog::~CMessageDialog()
|
||||
{
|
||||
if ( m_ButtonPressed != BTN_INVALID && ( m_nType & MD_COMMANDAFTERCLOSE ) )
|
||||
{
|
||||
// caller wants the command sent after closure
|
||||
m_pCreator->OnCommand( m_pCommands[m_ButtonPressed] );
|
||||
}
|
||||
else if ( m_nType & MD_COMMANDONFORCECLOSE )
|
||||
{
|
||||
// caller wants the command sent after closure
|
||||
m_pCreator->OnCommand( m_pCommands[BTN_A] );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
free( m_pCommands[i] );
|
||||
m_pCommands[i] = NULL;
|
||||
|
||||
delete m_Buttons[i].pIcon;
|
||||
delete m_Buttons[i].pText;
|
||||
}
|
||||
|
||||
delete m_pTitle;
|
||||
m_pTitle = NULL;
|
||||
|
||||
delete m_pMsg;
|
||||
m_pMsg = NULL;
|
||||
|
||||
delete m_pBackground;
|
||||
m_pBackground = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to pass to LoadControlSettings()
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::SetControlSettingsKeys( KeyValues *pKeys )
|
||||
{
|
||||
m_pControlSettings = pKeys;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create a new button
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::CreateButtonLabel( ButtonLabel_s *pButton, const char *pIcon, const char *pText )
|
||||
{
|
||||
pButton->nWide = m_ButtonIconLabelSpace;
|
||||
pButton->bCreated = true;
|
||||
|
||||
pButton->pIcon = new vgui::Label( this, "icon", pIcon );
|
||||
SETUP_PANEL( pButton->pIcon );
|
||||
pButton->pIcon->SetFont( m_hButtonFont );
|
||||
pButton->pIcon->SizeToContents();
|
||||
pButton->nWide += pButton->pIcon->GetWide();
|
||||
|
||||
pButton->pText = new vgui::Label( this, "text", pText );
|
||||
SETUP_PANEL( pButton->pText );
|
||||
pButton->pText->SetFont( m_hTextFont );
|
||||
pButton->pText->SizeToContents();
|
||||
pButton->pText->SetFgColor( m_ButtonTextColor );
|
||||
pButton->nWide += pButton->pText->GetWide();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create and arrange the panel button labels according to the dialog type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
|
||||
LoadControlSettings( "resource/UI/MessageDialog.res", "GAME", m_pControlSettings );
|
||||
|
||||
m_hButtonFont = pScheme->GetFont( "GameUIButtons" );
|
||||
m_hTextFont = pScheme->GetFont( "MenuLarge" );
|
||||
|
||||
if ( m_nType & MD_OK )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_OK" );
|
||||
}
|
||||
else if ( m_nType & MD_CANCEL )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_Cancel" );
|
||||
}
|
||||
else if ( m_nType & MD_OKCANCEL )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_OK" );
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_Cancel" );
|
||||
}
|
||||
else if ( m_nType & MD_YESNO )
|
||||
{
|
||||
CreateButtonLabel( &m_Buttons[BTN_A], "#GameUI_Icons_A_BUTTON", "#GameUI_Yes" );
|
||||
CreateButtonLabel( &m_Buttons[BTN_B], "#GameUI_Icons_B_BUTTON", "#GameUI_No" );
|
||||
}
|
||||
|
||||
// count the buttons and add up their widths
|
||||
int cButtons = 0;
|
||||
int nTotalWide = 0;
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
if ( m_Buttons[i].bCreated )
|
||||
{
|
||||
++cButtons;
|
||||
nTotalWide += m_Buttons[i].nWide;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure text and icons are center-aligned vertically with each other
|
||||
int nButtonTall = vgui::surface()->GetFontTall( m_hButtonFont );
|
||||
int nTextTall = vgui::surface()->GetFontTall( m_hTextFont );
|
||||
int nVerticalAdjust = ( nButtonTall - nTextTall ) / 2;
|
||||
|
||||
// position the buttons with even horizontal spacing
|
||||
int xpos = 0;
|
||||
int ypos = GetTall() - max( nButtonTall, nTextTall ) - m_ButtonMargin;
|
||||
int nSpacing = ( GetWide() - nTotalWide ) / ( cButtons + 1 );
|
||||
for ( int i = 0; i < MAX_BUTTONS; ++i )
|
||||
{
|
||||
if ( m_Buttons[i].bCreated )
|
||||
{
|
||||
xpos += nSpacing;
|
||||
m_Buttons[i].pIcon->SetPos( xpos, ypos );
|
||||
xpos += m_Buttons[i].pIcon->GetWide() + m_ButtonIconLabelSpace;
|
||||
m_Buttons[i].pText->SetPos( xpos, ypos + nVerticalAdjust );
|
||||
xpos += m_Buttons[i].pText->GetWide();
|
||||
}
|
||||
}
|
||||
|
||||
m_clrNotSimpleBG = pScheme->GetColor( "MessageDialog.MatchmakingBG", Color( 200, 184, 151, 255 ) );
|
||||
m_clrNotSimpleBGBlack = pScheme->GetColor( "MessageDialog.MatchmakingBGBlack", Color( 52, 48, 55, 255 ) );
|
||||
|
||||
if ( !m_bShowActivity )
|
||||
{
|
||||
if ( m_pAnimatingPanel )
|
||||
{
|
||||
if ( m_pAnimatingPanel->IsVisible() )
|
||||
{
|
||||
|
||||
m_pAnimatingPanel->SetVisible( false );
|
||||
}
|
||||
|
||||
m_pAnimatingPanel->StopAnimation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_pAnimatingPanel )
|
||||
{
|
||||
if ( !m_pAnimatingPanel->IsVisible() )
|
||||
{
|
||||
m_pAnimatingPanel->SetVisible( true );
|
||||
}
|
||||
|
||||
m_pAnimatingPanel->StartAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
MoveToCenterOfScreen();
|
||||
|
||||
if ( m_bShowActivity && m_ActivityIndent )
|
||||
{
|
||||
// If we're animating, we push our text label in, and reduce its width
|
||||
int iX,iY,iW,iH;
|
||||
m_pMsg->GetBounds( iX, iY, iW, iH );
|
||||
m_pMsg->SetBounds( iX + m_ActivityIndent, iY, max(0,iW-m_ActivityIndent), iH );
|
||||
}
|
||||
|
||||
// Invalidate the scheme on our message label so that it recalculates
|
||||
// its line breaks in case it was resized when we loaded our .res file.
|
||||
m_pMsg->InvalidateLayout( false, true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create and arrange the panel button labels according to the dialog type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::ApplySettings( KeyValues *inResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
|
||||
m_pTitle->SetFgColor( inResourceData->GetColor( "titlecolor" ) );
|
||||
|
||||
m_pMsg->SetFgColor( inResourceData->GetColor( "messagecolor" ) );
|
||||
|
||||
m_ButtonTextColor = inResourceData->GetColor( "buttontextcolor" );
|
||||
|
||||
m_FooterTall = inResourceData->GetInt( "footer_tall", 0 );
|
||||
m_ButtonMargin = inResourceData->GetInt( "button_margin", 25 );
|
||||
m_ButtonIconLabelSpace = inResourceData->GetInt( "button_separator", 10 );
|
||||
m_ActivityIndent = inResourceData->GetInt( "activity_indent", 0 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
uint CMessageDialog::GetType( void )
|
||||
{
|
||||
return m_nType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::DoCommand( int button )
|
||||
{
|
||||
if ( button == BTN_INVALID || ( m_nType & MD_COMMANDONFORCECLOSE ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_pCommands[button] )
|
||||
{
|
||||
m_ButtonPressed = button;
|
||||
if ( !( m_nType & MD_COMMANDAFTERCLOSE ) )
|
||||
{
|
||||
// caller wants the command sent before closure
|
||||
m_pCreator->OnCommand( m_pCommands[m_ButtonPressed] );
|
||||
}
|
||||
m_pCreator->OnCommand( "ReleaseModalWindow" );
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::OnKeyCodePressed( vgui::KeyCode code )
|
||||
{
|
||||
if ( m_ButtonPressed != BTN_INVALID || GetAlpha() != 255 )
|
||||
{
|
||||
// inhibit any further key activity or during transitions
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( GetBaseButtonCode( code ) )
|
||||
{
|
||||
case KEY_XBUTTON_A:
|
||||
DoCommand( BTN_A );
|
||||
break;
|
||||
|
||||
case KEY_XBUTTON_B:
|
||||
DoCommand( BTN_B );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMessageDialog::PaintBackground( void )
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
if ( !( m_nType & MD_SIMPLEFRAME ) )
|
||||
{
|
||||
int nAlpha = GetAlpha();
|
||||
|
||||
m_clrNotSimpleBG[3] = nAlpha;
|
||||
m_clrNotSimpleBGBlack[3] = nAlpha;
|
||||
|
||||
DrawBox( 0, 0, wide, tall, m_clrNotSimpleBGBlack, 1.0f );
|
||||
DrawBox( 0, 0, wide, tall - m_FooterTall, m_clrNotSimpleBG, 1.0f );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Color col = GetBgColor();
|
||||
DrawBox( 0, 0, wide, tall, col, 1.0f );
|
||||
|
||||
// offset the inset by title
|
||||
int titleX, titleY, titleWide, titleTall;
|
||||
m_pTitle->GetBounds( titleX, titleY, titleWide, titleTall );
|
||||
int y = titleY + titleTall;
|
||||
|
||||
// draw an inset
|
||||
Color darkColor;
|
||||
darkColor.SetColor( 0.70f * (float)col.r(), 0.70f * (float)col.g(), 0.70f * (float)col.b(), col.a() );
|
||||
vgui::surface()->DrawSetColor( darkColor );
|
||||
vgui::surface()->DrawFilledRect( 8, y, wide - 8, tall - 8 );
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,473 +1,473 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include "vgui_controls/EditablePanel.h"
|
||||
#include "vgui_controls/ScrollBar.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
#include "vgui_controls/PanelListPanel.h"
|
||||
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PanelListPanel::PanelListPanel( vgui::Panel *parent, char const *panelName ) : EditablePanel( parent, panelName )
|
||||
{
|
||||
SetBounds( 0, 0, 100, 100 );
|
||||
|
||||
m_vbar = new ScrollBar(this, "PanelListPanelVScroll", true);
|
||||
m_vbar->SetVisible(false);
|
||||
m_vbar->AddActionSignalTarget( this );
|
||||
|
||||
m_pPanelEmbedded = new EditablePanel(this, "PanelListEmbedded");
|
||||
m_pPanelEmbedded->SetBounds(0, 0, 20, 20);
|
||||
m_pPanelEmbedded->SetPaintBackgroundEnabled( false );
|
||||
m_pPanelEmbedded->SetPaintBorderEnabled(false);
|
||||
|
||||
m_iFirstColumnWidth = 100; // default width
|
||||
m_iNumColumns = 1; // 1 column by default
|
||||
|
||||
if ( IsProportional() )
|
||||
{
|
||||
m_iDefaultHeight = scheme()->GetProportionalScaledValueEx( GetScheme(), DEFAULT_HEIGHT );
|
||||
m_iPanelBuffer = scheme()->GetProportionalScaledValueEx( GetScheme(), PANELBUFFER );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iDefaultHeight = DEFAULT_HEIGHT;
|
||||
m_iPanelBuffer = PANELBUFFER;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PanelListPanel::~PanelListPanel()
|
||||
{
|
||||
// free data from table
|
||||
DeleteAllItems();
|
||||
}
|
||||
|
||||
void PanelListPanel::SetVerticalBufferPixels( int buffer )
|
||||
{
|
||||
m_iPanelBuffer = buffer;
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: counts the total vertical pixels
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::ComputeVPixelsNeeded()
|
||||
{
|
||||
int iCurrentItem = 0;
|
||||
int iLargestH = 0;
|
||||
|
||||
int pixels = 0;
|
||||
for ( int i = 0; i < m_SortedItems.Count(); i++ )
|
||||
{
|
||||
Panel *panel = m_DataItems[ m_SortedItems[i] ].panel;
|
||||
if ( !panel )
|
||||
continue;
|
||||
|
||||
if ( panel->IsLayoutInvalid() )
|
||||
{
|
||||
panel->InvalidateLayout( true );
|
||||
}
|
||||
|
||||
int iCurrentColumn = iCurrentItem % m_iNumColumns;
|
||||
|
||||
int w, h;
|
||||
panel->GetSize( w, h );
|
||||
|
||||
if ( iLargestH < h )
|
||||
iLargestH = h;
|
||||
|
||||
if ( iCurrentColumn == 0 )
|
||||
pixels += m_iPanelBuffer; // add in buffer. between rows.
|
||||
|
||||
if ( iCurrentColumn >= m_iNumColumns - 1 )
|
||||
{
|
||||
pixels += iLargestH;
|
||||
iLargestH = 0;
|
||||
}
|
||||
|
||||
iCurrentItem++;
|
||||
}
|
||||
|
||||
// Add in remaining largest height
|
||||
pixels += iLargestH;
|
||||
|
||||
pixels += m_iPanelBuffer; // add in buffer below last item
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns the panel to use to render a cell
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetCellRenderer( int row )
|
||||
{
|
||||
if ( !m_SortedItems.IsValidIndex(row) )
|
||||
return NULL;
|
||||
|
||||
Panel *panel = m_DataItems[ m_SortedItems[row] ].panel;
|
||||
return panel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds an item to the view
|
||||
// data->GetName() is used to uniquely identify an item
|
||||
// data sub items are matched against column header name to be used in the table
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::AddItem( Panel *labelPanel, Panel *panel)
|
||||
{
|
||||
Assert(panel);
|
||||
|
||||
if ( labelPanel )
|
||||
{
|
||||
labelPanel->SetParent( m_pPanelEmbedded );
|
||||
}
|
||||
|
||||
panel->SetParent( m_pPanelEmbedded );
|
||||
|
||||
int itemID = m_DataItems.AddToTail();
|
||||
DATAITEM &newitem = m_DataItems[itemID];
|
||||
newitem.labelPanel = labelPanel;
|
||||
newitem.panel = panel;
|
||||
m_SortedItems.AddToTail(itemID);
|
||||
|
||||
InvalidateLayout();
|
||||
return itemID;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::GetItemCount() const
|
||||
{
|
||||
return m_DataItems.Count();
|
||||
}
|
||||
|
||||
int PanelListPanel::GetItemIDFromRow( int nRow ) const
|
||||
{
|
||||
if ( nRow < 0 || nRow >= GetItemCount() )
|
||||
return m_DataItems.InvalidIndex();
|
||||
return m_SortedItems[ nRow ];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iteration. Use these until they return InvalidItemID to iterate all the items.
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::FirstItem() const
|
||||
{
|
||||
return m_DataItems.Head();
|
||||
}
|
||||
|
||||
int PanelListPanel::NextItem( int nItemID ) const
|
||||
{
|
||||
return m_DataItems.Next( nItemID );
|
||||
}
|
||||
|
||||
int PanelListPanel::InvalidItemID() const
|
||||
{
|
||||
return m_DataItems.InvalidIndex( );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns label panel for this itemID
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetItemLabel(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return NULL;
|
||||
|
||||
return m_DataItems[itemID].labelPanel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns label panel for this itemID
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetItemPanel(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return NULL;
|
||||
|
||||
return m_DataItems[itemID].panel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::RemoveItem(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return;
|
||||
|
||||
DATAITEM &item = m_DataItems[itemID];
|
||||
if ( item.panel )
|
||||
{
|
||||
item.panel->MarkForDeletion();
|
||||
}
|
||||
if ( item.labelPanel )
|
||||
{
|
||||
item.labelPanel->MarkForDeletion();
|
||||
}
|
||||
|
||||
m_DataItems.Remove(itemID);
|
||||
m_SortedItems.FindAndRemove(itemID);
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears and deletes all the memory used by the data items
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::DeleteAllItems()
|
||||
{
|
||||
FOR_EACH_LL( m_DataItems, i )
|
||||
{
|
||||
if ( m_DataItems[i].panel )
|
||||
{
|
||||
delete m_DataItems[i].panel;
|
||||
}
|
||||
}
|
||||
|
||||
m_DataItems.RemoveAll();
|
||||
m_SortedItems.RemoveAll();
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears and deletes all the memory used by the data items
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::RemoveAll()
|
||||
{
|
||||
m_DataItems.RemoveAll();
|
||||
m_SortedItems.RemoveAll();
|
||||
|
||||
// move the scrollbar to the top of the list
|
||||
m_vbar->SetValue(0);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnSizeChanged(int wide, int tall)
|
||||
{
|
||||
BaseClass::OnSizeChanged(wide, tall);
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: relayouts out the panel after any internal changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::PerformLayout()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
int vpixels = ComputeVPixelsNeeded();
|
||||
|
||||
m_vbar->SetRange( 0, vpixels );
|
||||
m_vbar->SetRangeWindow( tall );
|
||||
m_vbar->SetButtonPressedScrollValue( tall / 4 ); // standard height of labels/buttons etc.
|
||||
|
||||
m_vbar->SetPos( wide - m_vbar->GetWide() - 2, 0 );
|
||||
m_vbar->SetSize( m_vbar->GetWide(), tall - 2 );
|
||||
|
||||
int top = m_vbar->GetValue();
|
||||
|
||||
m_pPanelEmbedded->SetPos( 0, -top );
|
||||
m_pPanelEmbedded->SetSize( wide - m_vbar->GetWide(), vpixels ); // scrollbar will sit on top (zpos set explicitly)
|
||||
|
||||
bool bScrollbarVisible = true;
|
||||
// If we're supposed to automatically hide the scrollbar when unnecessary, check it now
|
||||
if ( m_bAutoHideScrollbar )
|
||||
{
|
||||
bScrollbarVisible = (m_pPanelEmbedded->GetTall() > tall);
|
||||
}
|
||||
m_vbar->SetVisible( bScrollbarVisible );
|
||||
|
||||
// Now lay out the controls on the embedded panel
|
||||
int y = 0;
|
||||
int h = 0;
|
||||
int totalh = 0;
|
||||
|
||||
int xpos = m_iFirstColumnWidth + m_iPanelBuffer;
|
||||
int iColumnWidth = ( wide - xpos - m_vbar->GetWide() - 12 ) / m_iNumColumns;
|
||||
|
||||
for ( int i = 0; i < m_SortedItems.Count(); i++ )
|
||||
{
|
||||
int iCurrentColumn = i % m_iNumColumns;
|
||||
|
||||
// add in a little buffer between panels
|
||||
if ( iCurrentColumn == 0 )
|
||||
y += m_iPanelBuffer;
|
||||
|
||||
DATAITEM &item = m_DataItems[ m_SortedItems[i] ];
|
||||
|
||||
if ( h < item.panel->GetTall() )
|
||||
h = item.panel->GetTall();
|
||||
|
||||
if ( item.labelPanel )
|
||||
{
|
||||
item.labelPanel->SetBounds( 0, y, m_iFirstColumnWidth, item.panel->GetTall() );
|
||||
}
|
||||
|
||||
item.panel->SetBounds( xpos + iCurrentColumn * iColumnWidth, y, iColumnWidth, item.panel->GetTall() );
|
||||
|
||||
if ( iCurrentColumn >= m_iNumColumns - 1 )
|
||||
{
|
||||
y += h;
|
||||
totalh += h;
|
||||
|
||||
h = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: scheme settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
SetBgColor(GetSchemeColor("ListPanel.BgColor", GetBgColor(), pScheme));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnSliderMoved( int position )
|
||||
{
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::MoveScrollBarToTop()
|
||||
{
|
||||
m_vbar->SetValue(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::SetFirstColumnWidth( int width )
|
||||
{
|
||||
m_iFirstColumnWidth = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::GetFirstColumnWidth()
|
||||
{
|
||||
return m_iFirstColumnWidth;
|
||||
}
|
||||
|
||||
void PanelListPanel::SetNumColumns( int iNumColumns )
|
||||
{
|
||||
m_iNumColumns = iNumColumns;
|
||||
}
|
||||
|
||||
int PanelListPanel::GetNumColumns( void )
|
||||
{
|
||||
return m_iNumColumns;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: moves the scrollbar with the mousewheel
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_vbar->GetValue();
|
||||
val -= (delta * DEFAULT_HEIGHT);
|
||||
m_vbar->SetValue(val);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: selection handler
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::SetSelectedPanel( Panel *panel )
|
||||
{
|
||||
if ( panel != m_hSelectedItem )
|
||||
{
|
||||
// notify the panels of the selection change
|
||||
if ( m_hSelectedItem )
|
||||
{
|
||||
PostMessage( m_hSelectedItem.Get(), new KeyValues("PanelSelected", "state", 0) );
|
||||
}
|
||||
if ( panel )
|
||||
{
|
||||
PostMessage( panel, new KeyValues("PanelSelected", "state", 1) );
|
||||
}
|
||||
m_hSelectedItem = panel;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetSelectedPanel()
|
||||
{
|
||||
return m_hSelectedItem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::ScrollToItem( int itemNumber )
|
||||
{
|
||||
if (!m_vbar->IsVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DATAITEM& item = m_DataItems[ m_SortedItems[ itemNumber ] ];
|
||||
if ( !item.panel )
|
||||
return;
|
||||
|
||||
int x, y;
|
||||
item.panel->GetPos( x, y );
|
||||
int lx, ly;
|
||||
lx = x;
|
||||
ly = y;
|
||||
m_pPanelEmbedded->LocalToScreen( lx, ly );
|
||||
ScreenToLocal( lx, ly );
|
||||
|
||||
int h = item.panel->GetTall();
|
||||
|
||||
if ( ly >= 0 && ly + h < GetTall() )
|
||||
return;
|
||||
|
||||
m_vbar->SetValue( y );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include "vgui_controls/EditablePanel.h"
|
||||
#include "vgui_controls/ScrollBar.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
#include "vgui_controls/PanelListPanel.h"
|
||||
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PanelListPanel::PanelListPanel( vgui::Panel *parent, char const *panelName ) : EditablePanel( parent, panelName )
|
||||
{
|
||||
SetBounds( 0, 0, 100, 100 );
|
||||
|
||||
m_vbar = new ScrollBar(this, "PanelListPanelVScroll", true);
|
||||
m_vbar->SetVisible(false);
|
||||
m_vbar->AddActionSignalTarget( this );
|
||||
|
||||
m_pPanelEmbedded = new EditablePanel(this, "PanelListEmbedded");
|
||||
m_pPanelEmbedded->SetBounds(0, 0, 20, 20);
|
||||
m_pPanelEmbedded->SetPaintBackgroundEnabled( false );
|
||||
m_pPanelEmbedded->SetPaintBorderEnabled(false);
|
||||
|
||||
m_iFirstColumnWidth = 100; // default width
|
||||
m_iNumColumns = 1; // 1 column by default
|
||||
|
||||
if ( IsProportional() )
|
||||
{
|
||||
m_iDefaultHeight = scheme()->GetProportionalScaledValueEx( GetScheme(), DEFAULT_HEIGHT );
|
||||
m_iPanelBuffer = scheme()->GetProportionalScaledValueEx( GetScheme(), PANELBUFFER );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iDefaultHeight = DEFAULT_HEIGHT;
|
||||
m_iPanelBuffer = PANELBUFFER;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PanelListPanel::~PanelListPanel()
|
||||
{
|
||||
// free data from table
|
||||
DeleteAllItems();
|
||||
}
|
||||
|
||||
void PanelListPanel::SetVerticalBufferPixels( int buffer )
|
||||
{
|
||||
m_iPanelBuffer = buffer;
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: counts the total vertical pixels
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::ComputeVPixelsNeeded()
|
||||
{
|
||||
int iCurrentItem = 0;
|
||||
int iLargestH = 0;
|
||||
|
||||
int pixels = 0;
|
||||
for ( int i = 0; i < m_SortedItems.Count(); i++ )
|
||||
{
|
||||
Panel *panel = m_DataItems[ m_SortedItems[i] ].panel;
|
||||
if ( !panel )
|
||||
continue;
|
||||
|
||||
if ( panel->IsLayoutInvalid() )
|
||||
{
|
||||
panel->InvalidateLayout( true );
|
||||
}
|
||||
|
||||
int iCurrentColumn = iCurrentItem % m_iNumColumns;
|
||||
|
||||
int w, h;
|
||||
panel->GetSize( w, h );
|
||||
|
||||
if ( iLargestH < h )
|
||||
iLargestH = h;
|
||||
|
||||
if ( iCurrentColumn == 0 )
|
||||
pixels += m_iPanelBuffer; // add in buffer. between rows.
|
||||
|
||||
if ( iCurrentColumn >= m_iNumColumns - 1 )
|
||||
{
|
||||
pixels += iLargestH;
|
||||
iLargestH = 0;
|
||||
}
|
||||
|
||||
iCurrentItem++;
|
||||
}
|
||||
|
||||
// Add in remaining largest height
|
||||
pixels += iLargestH;
|
||||
|
||||
pixels += m_iPanelBuffer; // add in buffer below last item
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns the panel to use to render a cell
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetCellRenderer( int row )
|
||||
{
|
||||
if ( !m_SortedItems.IsValidIndex(row) )
|
||||
return NULL;
|
||||
|
||||
Panel *panel = m_DataItems[ m_SortedItems[row] ].panel;
|
||||
return panel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds an item to the view
|
||||
// data->GetName() is used to uniquely identify an item
|
||||
// data sub items are matched against column header name to be used in the table
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::AddItem( Panel *labelPanel, Panel *panel)
|
||||
{
|
||||
Assert(panel);
|
||||
|
||||
if ( labelPanel )
|
||||
{
|
||||
labelPanel->SetParent( m_pPanelEmbedded );
|
||||
}
|
||||
|
||||
panel->SetParent( m_pPanelEmbedded );
|
||||
|
||||
int itemID = m_DataItems.AddToTail();
|
||||
DATAITEM &newitem = m_DataItems[itemID];
|
||||
newitem.labelPanel = labelPanel;
|
||||
newitem.panel = panel;
|
||||
m_SortedItems.AddToTail(itemID);
|
||||
|
||||
InvalidateLayout();
|
||||
return itemID;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: iteration accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::GetItemCount() const
|
||||
{
|
||||
return m_DataItems.Count();
|
||||
}
|
||||
|
||||
int PanelListPanel::GetItemIDFromRow( int nRow ) const
|
||||
{
|
||||
if ( nRow < 0 || nRow >= GetItemCount() )
|
||||
return m_DataItems.InvalidIndex();
|
||||
return m_SortedItems[ nRow ];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iteration. Use these until they return InvalidItemID to iterate all the items.
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::FirstItem() const
|
||||
{
|
||||
return m_DataItems.Head();
|
||||
}
|
||||
|
||||
int PanelListPanel::NextItem( int nItemID ) const
|
||||
{
|
||||
return m_DataItems.Next( nItemID );
|
||||
}
|
||||
|
||||
int PanelListPanel::InvalidItemID() const
|
||||
{
|
||||
return m_DataItems.InvalidIndex( );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns label panel for this itemID
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetItemLabel(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return NULL;
|
||||
|
||||
return m_DataItems[itemID].labelPanel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns label panel for this itemID
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetItemPanel(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return NULL;
|
||||
|
||||
return m_DataItems[itemID].panel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::RemoveItem(int itemID)
|
||||
{
|
||||
if ( !m_DataItems.IsValidIndex(itemID) )
|
||||
return;
|
||||
|
||||
DATAITEM &item = m_DataItems[itemID];
|
||||
if ( item.panel )
|
||||
{
|
||||
item.panel->MarkForDeletion();
|
||||
}
|
||||
if ( item.labelPanel )
|
||||
{
|
||||
item.labelPanel->MarkForDeletion();
|
||||
}
|
||||
|
||||
m_DataItems.Remove(itemID);
|
||||
m_SortedItems.FindAndRemove(itemID);
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears and deletes all the memory used by the data items
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::DeleteAllItems()
|
||||
{
|
||||
FOR_EACH_LL( m_DataItems, i )
|
||||
{
|
||||
if ( m_DataItems[i].panel )
|
||||
{
|
||||
delete m_DataItems[i].panel;
|
||||
}
|
||||
}
|
||||
|
||||
m_DataItems.RemoveAll();
|
||||
m_SortedItems.RemoveAll();
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: clears and deletes all the memory used by the data items
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::RemoveAll()
|
||||
{
|
||||
m_DataItems.RemoveAll();
|
||||
m_SortedItems.RemoveAll();
|
||||
|
||||
// move the scrollbar to the top of the list
|
||||
m_vbar->SetValue(0);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnSizeChanged(int wide, int tall)
|
||||
{
|
||||
BaseClass::OnSizeChanged(wide, tall);
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: relayouts out the panel after any internal changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::PerformLayout()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
int vpixels = ComputeVPixelsNeeded();
|
||||
|
||||
m_vbar->SetRange( 0, vpixels );
|
||||
m_vbar->SetRangeWindow( tall );
|
||||
m_vbar->SetButtonPressedScrollValue( tall / 4 ); // standard height of labels/buttons etc.
|
||||
|
||||
m_vbar->SetPos( wide - m_vbar->GetWide() - 2, 0 );
|
||||
m_vbar->SetSize( m_vbar->GetWide(), tall - 2 );
|
||||
|
||||
int top = m_vbar->GetValue();
|
||||
|
||||
m_pPanelEmbedded->SetPos( 0, -top );
|
||||
m_pPanelEmbedded->SetSize( wide - m_vbar->GetWide(), vpixels ); // scrollbar will sit on top (zpos set explicitly)
|
||||
|
||||
bool bScrollbarVisible = true;
|
||||
// If we're supposed to automatically hide the scrollbar when unnecessary, check it now
|
||||
if ( m_bAutoHideScrollbar )
|
||||
{
|
||||
bScrollbarVisible = (m_pPanelEmbedded->GetTall() > tall);
|
||||
}
|
||||
m_vbar->SetVisible( bScrollbarVisible );
|
||||
|
||||
// Now lay out the controls on the embedded panel
|
||||
int y = 0;
|
||||
int h = 0;
|
||||
int totalh = 0;
|
||||
|
||||
int xpos = m_iFirstColumnWidth + m_iPanelBuffer;
|
||||
int iColumnWidth = ( wide - xpos - m_vbar->GetWide() - 12 ) / m_iNumColumns;
|
||||
|
||||
for ( int i = 0; i < m_SortedItems.Count(); i++ )
|
||||
{
|
||||
int iCurrentColumn = i % m_iNumColumns;
|
||||
|
||||
// add in a little buffer between panels
|
||||
if ( iCurrentColumn == 0 )
|
||||
y += m_iPanelBuffer;
|
||||
|
||||
DATAITEM &item = m_DataItems[ m_SortedItems[i] ];
|
||||
|
||||
if ( h < item.panel->GetTall() )
|
||||
h = item.panel->GetTall();
|
||||
|
||||
if ( item.labelPanel )
|
||||
{
|
||||
item.labelPanel->SetBounds( 0, y, m_iFirstColumnWidth, item.panel->GetTall() );
|
||||
}
|
||||
|
||||
item.panel->SetBounds( xpos + iCurrentColumn * iColumnWidth, y, iColumnWidth, item.panel->GetTall() );
|
||||
|
||||
if ( iCurrentColumn >= m_iNumColumns - 1 )
|
||||
{
|
||||
y += h;
|
||||
totalh += h;
|
||||
|
||||
h = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: scheme settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
SetBgColor(GetSchemeColor("ListPanel.BgColor", GetBgColor(), pScheme));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnSliderMoved( int position )
|
||||
{
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::MoveScrollBarToTop()
|
||||
{
|
||||
m_vbar->SetValue(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::SetFirstColumnWidth( int width )
|
||||
{
|
||||
m_iFirstColumnWidth = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int PanelListPanel::GetFirstColumnWidth()
|
||||
{
|
||||
return m_iFirstColumnWidth;
|
||||
}
|
||||
|
||||
void PanelListPanel::SetNumColumns( int iNumColumns )
|
||||
{
|
||||
m_iNumColumns = iNumColumns;
|
||||
}
|
||||
|
||||
int PanelListPanel::GetNumColumns( void )
|
||||
{
|
||||
return m_iNumColumns;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: moves the scrollbar with the mousewheel
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_vbar->GetValue();
|
||||
val -= (delta * DEFAULT_HEIGHT);
|
||||
m_vbar->SetValue(val);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: selection handler
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::SetSelectedPanel( Panel *panel )
|
||||
{
|
||||
if ( panel != m_hSelectedItem )
|
||||
{
|
||||
// notify the panels of the selection change
|
||||
if ( m_hSelectedItem )
|
||||
{
|
||||
PostMessage( m_hSelectedItem.Get(), new KeyValues("PanelSelected", "state", 0) );
|
||||
}
|
||||
if ( panel )
|
||||
{
|
||||
PostMessage( panel, new KeyValues("PanelSelected", "state", 1) );
|
||||
}
|
||||
m_hSelectedItem = panel;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PanelListPanel::GetSelectedPanel()
|
||||
{
|
||||
return m_hSelectedItem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PanelListPanel::ScrollToItem( int itemNumber )
|
||||
{
|
||||
if (!m_vbar->IsVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DATAITEM& item = m_DataItems[ m_SortedItems[ itemNumber ] ];
|
||||
if ( !item.panel )
|
||||
return;
|
||||
|
||||
int x, y;
|
||||
item.panel->GetPos( x, y );
|
||||
int lx, ly;
|
||||
lx = x;
|
||||
ly = y;
|
||||
m_pPanelEmbedded->LocalToScreen( lx, ly );
|
||||
ScreenToLocal( lx, ly );
|
||||
|
||||
int h = item.panel->GetTall();
|
||||
|
||||
if ( ly >= 0 && ly + h < GetTall() )
|
||||
return;
|
||||
|
||||
m_vbar->SetValue( y );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,278 +1,278 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Contains a list of files, determines their perforce status
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <vgui_controls/PerforceFileExplorer.h>
|
||||
#include <vgui_controls/PerforceFileList.h>
|
||||
#include <vgui_controls/ComboBox.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "filesystem.h"
|
||||
#include <ctype.h>
|
||||
#include "p4lib/ip4.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PerforceFileExplorer::PerforceFileExplorer( Panel *pParent, const char *pPanelName ) :
|
||||
BaseClass( pParent, pPanelName )
|
||||
{
|
||||
m_pFileList = new PerforceFileList( this, "PerforceFileList" );
|
||||
|
||||
// Get the list of available drives and put them in a menu here.
|
||||
// Start with the directory we are in.
|
||||
m_pFullPathCombo = new ComboBox( this, "FullPathCombo", 8, false );
|
||||
m_pFullPathCombo->GetTooltip()->SetTooltipFormatToSingleLine();
|
||||
|
||||
char pFullPath[MAX_PATH];
|
||||
g_pFullFileSystem->GetCurrentDirectory( pFullPath, sizeof(pFullPath) );
|
||||
SetCurrentDirectory( pFullPath );
|
||||
|
||||
m_pFullPathCombo->AddActionSignalTarget( this );
|
||||
|
||||
m_pFolderUpButton = new Button(this, "FolderUpButton", "", this);
|
||||
m_pFolderUpButton->GetTooltip()->SetText( "#FileOpenDialog_ToolTip_Up" );
|
||||
m_pFolderUpButton->SetCommand( new KeyValues( "FolderUp" ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PerforceFileExplorer::~PerforceFileExplorer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from Frame
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
m_pFolderUpButton->AddImage( scheme()->GetImage( "resource/icon_folderup", false), -3 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from Frame
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int x, y, w, h;
|
||||
GetClientArea( x, y, w, h );
|
||||
|
||||
m_pFullPathCombo->SetBounds( x, y + 6, w - 30, 24 );
|
||||
m_pFolderUpButton->SetBounds( x + w - 24, y + 6, 24, 24 );
|
||||
|
||||
m_pFileList->SetBounds( x, y + 36, w, h - 36 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the current directory
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::SetCurrentDirectory( const char *pFullPath )
|
||||
{
|
||||
if ( !pFullPath )
|
||||
return;
|
||||
|
||||
while ( isspace( *pFullPath ) )
|
||||
{
|
||||
++pFullPath;
|
||||
}
|
||||
|
||||
if ( !pFullPath[0] )
|
||||
return;
|
||||
|
||||
m_CurrentDirectory = pFullPath;
|
||||
m_CurrentDirectory.StripTrailingSlash();
|
||||
Q_FixSlashes( m_CurrentDirectory.Get() );
|
||||
|
||||
PopulateFileList();
|
||||
PopulateDriveList();
|
||||
|
||||
char pCurrentDirectory[ MAX_PATH ];
|
||||
m_pFullPathCombo->GetText( pCurrentDirectory, sizeof(pCurrentDirectory) );
|
||||
if ( Q_stricmp( m_CurrentDirectory.Get(), pCurrentDirectory ) )
|
||||
{
|
||||
char pNewDirectory[ MAX_PATH ];
|
||||
Q_snprintf( pNewDirectory, sizeof(pNewDirectory), "%s\\", m_CurrentDirectory.Get() );
|
||||
m_pFullPathCombo->SetText( pNewDirectory );
|
||||
m_pFullPathCombo->GetTooltip()->SetText( pNewDirectory );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PopulateDriveList()
|
||||
{
|
||||
char pFullPath[MAX_PATH * 4];
|
||||
char pSubDirPath[MAX_PATH * 4];
|
||||
Q_strncpy( pFullPath, m_CurrentDirectory.Get(), sizeof( pFullPath ) );
|
||||
Q_strncpy( pSubDirPath, m_CurrentDirectory.Get(), sizeof( pSubDirPath ) );
|
||||
|
||||
m_pFullPathCombo->DeleteAllItems();
|
||||
|
||||
// populate the drive list
|
||||
char buf[512];
|
||||
int len = system()->GetAvailableDrives(buf, 512);
|
||||
char *pBuf = buf;
|
||||
for (int i=0; i < len / 4; i++)
|
||||
{
|
||||
m_pFullPathCombo->AddItem(pBuf, NULL);
|
||||
|
||||
// is this our drive - add all subdirectories
|
||||
if ( !_strnicmp( pBuf, pFullPath, 2 ) )
|
||||
{
|
||||
int indent = 0;
|
||||
char *pData = pFullPath;
|
||||
while (*pData)
|
||||
{
|
||||
if (*pData == '\\')
|
||||
{
|
||||
if (indent > 0)
|
||||
{
|
||||
memset(pSubDirPath, ' ', indent);
|
||||
memcpy(pSubDirPath+indent, pFullPath, pData-pFullPath+1);
|
||||
pSubDirPath[indent+pData-pFullPath+1] = 0;
|
||||
|
||||
m_pFullPathCombo->AddItem( pSubDirPath, NULL );
|
||||
}
|
||||
indent += 2;
|
||||
}
|
||||
pData++;
|
||||
}
|
||||
}
|
||||
pBuf += 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Fill the filelist with the names of all the files in the current directory
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PopulateFileList()
|
||||
{
|
||||
// clear the current list
|
||||
m_pFileList->RemoveAllFiles();
|
||||
|
||||
// Create filter string
|
||||
char pFullFoundPath[MAX_PATH];
|
||||
char pFilter[MAX_PATH+3];
|
||||
Q_snprintf( pFilter, sizeof(pFilter), "%s\\*.*", m_CurrentDirectory.Get() );
|
||||
|
||||
// Find all files on disk
|
||||
FileFindHandle_t h;
|
||||
const char *pFileName = g_pFullFileSystem->FindFirstEx( pFilter, NULL, &h );
|
||||
for ( ; pFileName; pFileName = g_pFullFileSystem->FindNext( h ) )
|
||||
{
|
||||
if ( !Q_stricmp( pFileName, ".." ) || !Q_stricmp( pFileName, "." ) )
|
||||
continue;
|
||||
|
||||
if ( !Q_IsAbsolutePath( pFileName ) )
|
||||
{
|
||||
Q_snprintf( pFullFoundPath, sizeof(pFullFoundPath), "%s\\%s", m_CurrentDirectory.Get(), pFileName );
|
||||
pFileName = pFullFoundPath;
|
||||
}
|
||||
|
||||
int nItemID = m_pFileList->AddFile( pFileName, true );
|
||||
m_pFileList->RefreshPerforceState( nItemID, true, NULL );
|
||||
}
|
||||
g_pFullFileSystem->FindClose( h );
|
||||
|
||||
// Now find all files in perforce
|
||||
CUtlVector<P4File_t> &fileList = p4->GetFileList( m_CurrentDirectory );
|
||||
int nCount = fileList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
const char *pFileName = p4->String( fileList[i].m_sLocalFile );
|
||||
if ( !pFileName[0] )
|
||||
continue;
|
||||
|
||||
int nItemID = m_pFileList->FindFile( pFileName );
|
||||
bool bFileExists = true;
|
||||
if ( nItemID == m_pFileList->InvalidItemID() )
|
||||
{
|
||||
// If it didn't find it, the file must not exist
|
||||
// since it already would have added it above
|
||||
bFileExists = false;
|
||||
nItemID = m_pFileList->AddFile( pFileName, false, fileList[i].m_bDir );
|
||||
}
|
||||
m_pFileList->RefreshPerforceState( nItemID, bFileExists, &fileList[i] );
|
||||
}
|
||||
|
||||
m_pFileList->SortList();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle an item in the Drive combo box being selected
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnTextChanged( KeyValues *kv )
|
||||
{
|
||||
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
|
||||
|
||||
// first check which control had its text changed!
|
||||
if ( pPanel == m_pFullPathCombo )
|
||||
{
|
||||
char pCurrentDirectory[ MAX_PATH ];
|
||||
m_pFullPathCombo->GetText( pCurrentDirectory, sizeof(pCurrentDirectory) );
|
||||
SetCurrentDirectory( pCurrentDirectory );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the file list was doubleclicked
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnItemDoubleClicked()
|
||||
{
|
||||
if ( m_pFileList->GetSelectedItemsCount() != 1 )
|
||||
return;
|
||||
|
||||
int nItemID = m_pFileList->GetSelectedItem( 0 );
|
||||
if ( m_pFileList->IsDirectoryItem( nItemID ) )
|
||||
{
|
||||
const char *pDirectoryName = m_pFileList->GetFile( nItemID );
|
||||
SetCurrentDirectory( pDirectoryName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the folder up button was hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnFolderUp()
|
||||
{
|
||||
char pUpDirectory[MAX_PATH];
|
||||
Q_strncpy( pUpDirectory, m_CurrentDirectory.Get(), sizeof(pUpDirectory) );
|
||||
Q_StripLastDir( pUpDirectory, sizeof(pUpDirectory) );
|
||||
Q_StripTrailingSlash( pUpDirectory );
|
||||
|
||||
// This occurs at the root directory
|
||||
if ( !Q_stricmp( pUpDirectory, "." ) )
|
||||
return;
|
||||
SetCurrentDirectory( pUpDirectory );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Contains a list of files, determines their perforce status
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <vgui_controls/PerforceFileExplorer.h>
|
||||
#include <vgui_controls/PerforceFileList.h>
|
||||
#include <vgui_controls/ComboBox.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "filesystem.h"
|
||||
#include <ctype.h>
|
||||
#include "p4lib/ip4.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PerforceFileExplorer::PerforceFileExplorer( Panel *pParent, const char *pPanelName ) :
|
||||
BaseClass( pParent, pPanelName )
|
||||
{
|
||||
m_pFileList = new PerforceFileList( this, "PerforceFileList" );
|
||||
|
||||
// Get the list of available drives and put them in a menu here.
|
||||
// Start with the directory we are in.
|
||||
m_pFullPathCombo = new ComboBox( this, "FullPathCombo", 8, false );
|
||||
m_pFullPathCombo->GetTooltip()->SetTooltipFormatToSingleLine();
|
||||
|
||||
char pFullPath[MAX_PATH];
|
||||
g_pFullFileSystem->GetCurrentDirectory( pFullPath, sizeof(pFullPath) );
|
||||
SetCurrentDirectory( pFullPath );
|
||||
|
||||
m_pFullPathCombo->AddActionSignalTarget( this );
|
||||
|
||||
m_pFolderUpButton = new Button(this, "FolderUpButton", "", this);
|
||||
m_pFolderUpButton->GetTooltip()->SetText( "#FileOpenDialog_ToolTip_Up" );
|
||||
m_pFolderUpButton->SetCommand( new KeyValues( "FolderUp" ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PerforceFileExplorer::~PerforceFileExplorer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from Frame
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
m_pFolderUpButton->AddImage( scheme()->GetImage( "resource/icon_folderup", false), -3 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from Frame
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int x, y, w, h;
|
||||
GetClientArea( x, y, w, h );
|
||||
|
||||
m_pFullPathCombo->SetBounds( x, y + 6, w - 30, 24 );
|
||||
m_pFolderUpButton->SetBounds( x + w - 24, y + 6, 24, 24 );
|
||||
|
||||
m_pFileList->SetBounds( x, y + 36, w, h - 36 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the current directory
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::SetCurrentDirectory( const char *pFullPath )
|
||||
{
|
||||
if ( !pFullPath )
|
||||
return;
|
||||
|
||||
while ( isspace( *pFullPath ) )
|
||||
{
|
||||
++pFullPath;
|
||||
}
|
||||
|
||||
if ( !pFullPath[0] )
|
||||
return;
|
||||
|
||||
m_CurrentDirectory = pFullPath;
|
||||
m_CurrentDirectory.StripTrailingSlash();
|
||||
Q_FixSlashes( m_CurrentDirectory.Get() );
|
||||
|
||||
PopulateFileList();
|
||||
PopulateDriveList();
|
||||
|
||||
char pCurrentDirectory[ MAX_PATH ];
|
||||
m_pFullPathCombo->GetText( pCurrentDirectory, sizeof(pCurrentDirectory) );
|
||||
if ( Q_stricmp( m_CurrentDirectory.Get(), pCurrentDirectory ) )
|
||||
{
|
||||
char pNewDirectory[ MAX_PATH ];
|
||||
Q_snprintf( pNewDirectory, sizeof(pNewDirectory), "%s\\", m_CurrentDirectory.Get() );
|
||||
m_pFullPathCombo->SetText( pNewDirectory );
|
||||
m_pFullPathCombo->GetTooltip()->SetText( pNewDirectory );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PopulateDriveList()
|
||||
{
|
||||
char pFullPath[MAX_PATH * 4];
|
||||
char pSubDirPath[MAX_PATH * 4];
|
||||
Q_strncpy( pFullPath, m_CurrentDirectory.Get(), sizeof( pFullPath ) );
|
||||
Q_strncpy( pSubDirPath, m_CurrentDirectory.Get(), sizeof( pSubDirPath ) );
|
||||
|
||||
m_pFullPathCombo->DeleteAllItems();
|
||||
|
||||
// populate the drive list
|
||||
char buf[512];
|
||||
int len = system()->GetAvailableDrives(buf, 512);
|
||||
char *pBuf = buf;
|
||||
for (int i=0; i < len / 4; i++)
|
||||
{
|
||||
m_pFullPathCombo->AddItem(pBuf, NULL);
|
||||
|
||||
// is this our drive - add all subdirectories
|
||||
if ( !_strnicmp( pBuf, pFullPath, 2 ) )
|
||||
{
|
||||
int indent = 0;
|
||||
char *pData = pFullPath;
|
||||
while (*pData)
|
||||
{
|
||||
if (*pData == '\\')
|
||||
{
|
||||
if (indent > 0)
|
||||
{
|
||||
memset(pSubDirPath, ' ', indent);
|
||||
memcpy(pSubDirPath+indent, pFullPath, pData-pFullPath+1);
|
||||
pSubDirPath[indent+pData-pFullPath+1] = 0;
|
||||
|
||||
m_pFullPathCombo->AddItem( pSubDirPath, NULL );
|
||||
}
|
||||
indent += 2;
|
||||
}
|
||||
pData++;
|
||||
}
|
||||
}
|
||||
pBuf += 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Fill the filelist with the names of all the files in the current directory
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::PopulateFileList()
|
||||
{
|
||||
// clear the current list
|
||||
m_pFileList->RemoveAllFiles();
|
||||
|
||||
// Create filter string
|
||||
char pFullFoundPath[MAX_PATH];
|
||||
char pFilter[MAX_PATH+3];
|
||||
Q_snprintf( pFilter, sizeof(pFilter), "%s\\*.*", m_CurrentDirectory.Get() );
|
||||
|
||||
// Find all files on disk
|
||||
FileFindHandle_t h;
|
||||
const char *pFileName = g_pFullFileSystem->FindFirstEx( pFilter, NULL, &h );
|
||||
for ( ; pFileName; pFileName = g_pFullFileSystem->FindNext( h ) )
|
||||
{
|
||||
if ( !Q_stricmp( pFileName, ".." ) || !Q_stricmp( pFileName, "." ) )
|
||||
continue;
|
||||
|
||||
if ( !Q_IsAbsolutePath( pFileName ) )
|
||||
{
|
||||
Q_snprintf( pFullFoundPath, sizeof(pFullFoundPath), "%s\\%s", m_CurrentDirectory.Get(), pFileName );
|
||||
pFileName = pFullFoundPath;
|
||||
}
|
||||
|
||||
int nItemID = m_pFileList->AddFile( pFileName, true );
|
||||
m_pFileList->RefreshPerforceState( nItemID, true, NULL );
|
||||
}
|
||||
g_pFullFileSystem->FindClose( h );
|
||||
|
||||
// Now find all files in perforce
|
||||
CUtlVector<P4File_t> &fileList = p4->GetFileList( m_CurrentDirectory );
|
||||
int nCount = fileList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
const char *pFileName = p4->String( fileList[i].m_sLocalFile );
|
||||
if ( !pFileName[0] )
|
||||
continue;
|
||||
|
||||
int nItemID = m_pFileList->FindFile( pFileName );
|
||||
bool bFileExists = true;
|
||||
if ( nItemID == m_pFileList->InvalidItemID() )
|
||||
{
|
||||
// If it didn't find it, the file must not exist
|
||||
// since it already would have added it above
|
||||
bFileExists = false;
|
||||
nItemID = m_pFileList->AddFile( pFileName, false, fileList[i].m_bDir );
|
||||
}
|
||||
m_pFileList->RefreshPerforceState( nItemID, bFileExists, &fileList[i] );
|
||||
}
|
||||
|
||||
m_pFileList->SortList();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle an item in the Drive combo box being selected
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnTextChanged( KeyValues *kv )
|
||||
{
|
||||
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
|
||||
|
||||
// first check which control had its text changed!
|
||||
if ( pPanel == m_pFullPathCombo )
|
||||
{
|
||||
char pCurrentDirectory[ MAX_PATH ];
|
||||
m_pFullPathCombo->GetText( pCurrentDirectory, sizeof(pCurrentDirectory) );
|
||||
SetCurrentDirectory( pCurrentDirectory );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the file list was doubleclicked
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnItemDoubleClicked()
|
||||
{
|
||||
if ( m_pFileList->GetSelectedItemsCount() != 1 )
|
||||
return;
|
||||
|
||||
int nItemID = m_pFileList->GetSelectedItem( 0 );
|
||||
if ( m_pFileList->IsDirectoryItem( nItemID ) )
|
||||
{
|
||||
const char *pDirectoryName = m_pFileList->GetFile( nItemID );
|
||||
SetCurrentDirectory( pDirectoryName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the folder up button was hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void PerforceFileExplorer::OnFolderUp()
|
||||
{
|
||||
char pUpDirectory[MAX_PATH];
|
||||
Q_strncpy( pUpDirectory, m_CurrentDirectory.Get(), sizeof(pUpDirectory) );
|
||||
Q_StripLastDir( pUpDirectory, sizeof(pUpDirectory) );
|
||||
Q_StripTrailingSlash( pUpDirectory );
|
||||
|
||||
// This occurs at the root directory
|
||||
if ( !Q_stricmp( pUpDirectory, "." ) )
|
||||
return;
|
||||
SetCurrentDirectory( pUpDirectory );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,427 +1,427 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/ProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBar::ProgressBar(Panel *parent, const char *panelName) : Panel(parent, panelName)
|
||||
{
|
||||
_progress = 0.0f;
|
||||
m_pszDialogVar = NULL;
|
||||
SetSegmentInfo( 4, 8 );
|
||||
SetBarInset( 4 );
|
||||
SetMargin( 0 );
|
||||
m_iProgressDirection = PROGRESS_EAST;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBar::~ProgressBar()
|
||||
{
|
||||
delete [] m_pszDialogVar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetSegmentInfo( int gap, int width )
|
||||
{
|
||||
_segmentGap = gap;
|
||||
_segmentWide = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of segment blocks drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetDrawnSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return (int)(segmentTotal * _progress);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::PaintBackground()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetBgColor());
|
||||
surface()->DrawFilledRect(0, 0, wide, tall);
|
||||
}
|
||||
|
||||
void ProgressBar::PaintSegment( int &x, int &y, int tall, int wide )
|
||||
{
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
x += _segmentGap;
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + tall - (y * 2));
|
||||
x += _segmentWide;
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
x -= _segmentGap + _segmentWide;
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + tall - (y * 2));
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
y -= _segmentGap + _segmentWide;
|
||||
surface()->DrawFilledRect(x, y, x + wide - (x * 2), y + _segmentWide );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
y += _segmentGap;
|
||||
surface()->DrawFilledRect(x, y, x + wide - (x * 2), y + _segmentWide );
|
||||
y += _segmentWide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::Paint()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
// gaps
|
||||
int segmentTotal = 0, segmentsDrawn = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_WEST:
|
||||
wide -= 2 * m_iBarMargin;
|
||||
x = wide - m_iBarMargin;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_EAST:
|
||||
wide -= 2 * m_iBarMargin;
|
||||
x = m_iBarMargin;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
tall -= 2 * m_iBarMargin;
|
||||
x = m_iBarInset;
|
||||
y = tall - m_iBarMargin;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
tall -= 2 * m_iBarMargin;
|
||||
x = m_iBarInset;
|
||||
y = m_iBarMargin;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
}
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
for (int i = 0; i < segmentsDrawn; i++)
|
||||
{
|
||||
PaintSegment( x, y, tall, wide );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetProgress(float progress)
|
||||
{
|
||||
if (progress != _progress)
|
||||
{
|
||||
// clamp the progress value within the range
|
||||
if (progress < 0.0f)
|
||||
{
|
||||
progress = 0.0f;
|
||||
}
|
||||
else if (progress > 1.0f)
|
||||
{
|
||||
progress = 1.0f;
|
||||
}
|
||||
|
||||
_progress = progress;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
float ProgressBar::GetProgress()
|
||||
{
|
||||
return _progress;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
Panel::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("ProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("ProgressBar.BgColor", pScheme));
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: utility function for calculating a time remaining string
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ProgressBar::ConstructTimeRemainingString(wchar_t *output, int outputBufferSizeInBytes, float startTime, float currentTime, float currentProgress, float lastProgressUpdateTime, bool addRemainingSuffix)
|
||||
{
|
||||
Assert(lastProgressUpdateTime <= currentTime);
|
||||
output[0] = 0;
|
||||
|
||||
// calculate pre-extrapolation values
|
||||
float timeElapsed = lastProgressUpdateTime - startTime;
|
||||
float totalTime = timeElapsed / currentProgress;
|
||||
|
||||
// calculate seconds
|
||||
int secondsRemaining = (int)(totalTime - timeElapsed);
|
||||
if (lastProgressUpdateTime < currentTime)
|
||||
{
|
||||
// old update, extrapolate
|
||||
float progressRate = currentProgress / timeElapsed;
|
||||
float extrapolatedProgress = progressRate * (currentTime - startTime);
|
||||
float extrapolatedTotalTime = (currentTime - startTime) / extrapolatedProgress;
|
||||
secondsRemaining = (int)(extrapolatedTotalTime - timeElapsed);
|
||||
}
|
||||
// if there's some time, make sure it's at least one second left
|
||||
if ( secondsRemaining == 0 && ( ( totalTime - timeElapsed ) > 0 ) )
|
||||
{
|
||||
secondsRemaining = 1;
|
||||
}
|
||||
|
||||
// calculate minutes
|
||||
int minutesRemaining = 0;
|
||||
while (secondsRemaining >= 60)
|
||||
{
|
||||
minutesRemaining++;
|
||||
secondsRemaining -= 60;
|
||||
}
|
||||
|
||||
char minutesBuf[16];
|
||||
Q_snprintf(minutesBuf, sizeof( minutesBuf ), "%d", minutesRemaining);
|
||||
char secondsBuf[16];
|
||||
Q_snprintf(secondsBuf, sizeof( secondsBuf ), "%d", secondsRemaining);
|
||||
|
||||
if (minutesRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeMinutes[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(minutesBuf, unicodeMinutes, sizeof( unicodeMinutes ));
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftMinutesSeconds";
|
||||
if (minutesRemaining == 1 && secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSecond";
|
||||
}
|
||||
else if (minutesRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSeconds";
|
||||
}
|
||||
else if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinutesSecond";
|
||||
}
|
||||
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof( unlocString ));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining", sizeof(unlocString ), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 2, unicodeMinutes, unicodeSeconds);
|
||||
|
||||
}
|
||||
else if (secondsRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftSeconds";
|
||||
if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftSecond";
|
||||
}
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof(unlocString));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining",sizeof(unlocString), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 1, unicodeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetBarInset( int pixels )
|
||||
{
|
||||
m_iBarInset = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetBarInset( void )
|
||||
{
|
||||
return m_iBarInset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetMargin( int pixels )
|
||||
{
|
||||
m_iBarMargin = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetMargin()
|
||||
{
|
||||
return m_iBarMargin;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
_progress = inResourceData->GetFloat("progress", 0.0f);
|
||||
|
||||
const char *dialogVar = inResourceData->GetString("variable", "");
|
||||
if (dialogVar && *dialogVar)
|
||||
{
|
||||
m_pszDialogVar = new char[strlen(dialogVar) + 1];
|
||||
strcpy(m_pszDialogVar, dialogVar);
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
outResourceData->SetFloat("progress", _progress );
|
||||
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
outResourceData->SetString("variable", m_pszDialogVar);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a string description of the panel fields for use in the UI
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ProgressBar::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string progress, string variable", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates progress bar bases on values
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::OnDialogVariablesChanged(KeyValues *dialogVariables)
|
||||
{
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
int val = dialogVariables->GetInt(m_pszDialogVar, -1);
|
||||
if (val >= 0.0f)
|
||||
{
|
||||
SetProgress(val / 100.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DECLARE_BUILD_FACTORY( ContinuousProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ContinuousProgressBar::ContinuousProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ContinuousProgressBar::Paint()
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
surface()->DrawFilledRect( x, y, x + (int)( wide * _progress ), y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
surface()->DrawFilledRect( x + (int)( wide * ( 1.0f - _progress ) ), y, x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
surface()->DrawFilledRect( x, y + (int)( tall * ( 1.0f - _progress ) ), x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
surface()->DrawFilledRect( x, y, x + wide, y + (int)( tall * _progress ) );
|
||||
break;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/ProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBar::ProgressBar(Panel *parent, const char *panelName) : Panel(parent, panelName)
|
||||
{
|
||||
_progress = 0.0f;
|
||||
m_pszDialogVar = NULL;
|
||||
SetSegmentInfo( 4, 8 );
|
||||
SetBarInset( 4 );
|
||||
SetMargin( 0 );
|
||||
m_iProgressDirection = PROGRESS_EAST;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBar::~ProgressBar()
|
||||
{
|
||||
delete [] m_pszDialogVar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetSegmentInfo( int gap, int width )
|
||||
{
|
||||
_segmentGap = gap;
|
||||
_segmentWide = width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the number of segment blocks drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetDrawnSegmentCount()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
int segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
return (int)(segmentTotal * _progress);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::PaintBackground()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetBgColor());
|
||||
surface()->DrawFilledRect(0, 0, wide, tall);
|
||||
}
|
||||
|
||||
void ProgressBar::PaintSegment( int &x, int &y, int tall, int wide )
|
||||
{
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
x += _segmentGap;
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + tall - (y * 2));
|
||||
x += _segmentWide;
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
x -= _segmentGap + _segmentWide;
|
||||
surface()->DrawFilledRect(x, y, x + _segmentWide, y + tall - (y * 2));
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
y -= _segmentGap + _segmentWide;
|
||||
surface()->DrawFilledRect(x, y, x + wide - (x * 2), y + _segmentWide );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
y += _segmentGap;
|
||||
surface()->DrawFilledRect(x, y, x + wide - (x * 2), y + _segmentWide );
|
||||
y += _segmentWide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::Paint()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
// gaps
|
||||
int segmentTotal = 0, segmentsDrawn = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_WEST:
|
||||
wide -= 2 * m_iBarMargin;
|
||||
x = wide - m_iBarMargin;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_EAST:
|
||||
wide -= 2 * m_iBarMargin;
|
||||
x = m_iBarMargin;
|
||||
y = m_iBarInset;
|
||||
segmentTotal = wide / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
tall -= 2 * m_iBarMargin;
|
||||
x = m_iBarInset;
|
||||
y = tall - m_iBarMargin;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
tall -= 2 * m_iBarMargin;
|
||||
x = m_iBarInset;
|
||||
y = m_iBarMargin;
|
||||
segmentTotal = tall / (_segmentGap + _segmentWide);
|
||||
segmentsDrawn = (int)(segmentTotal * _progress);
|
||||
break;
|
||||
}
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
for (int i = 0; i < segmentsDrawn; i++)
|
||||
{
|
||||
PaintSegment( x, y, tall, wide );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetProgress(float progress)
|
||||
{
|
||||
if (progress != _progress)
|
||||
{
|
||||
// clamp the progress value within the range
|
||||
if (progress < 0.0f)
|
||||
{
|
||||
progress = 0.0f;
|
||||
}
|
||||
else if (progress > 1.0f)
|
||||
{
|
||||
progress = 1.0f;
|
||||
}
|
||||
|
||||
_progress = progress;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
float ProgressBar::GetProgress()
|
||||
{
|
||||
return _progress;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
Panel::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("ProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("ProgressBar.BgColor", pScheme));
|
||||
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: utility function for calculating a time remaining string
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ProgressBar::ConstructTimeRemainingString(wchar_t *output, int outputBufferSizeInBytes, float startTime, float currentTime, float currentProgress, float lastProgressUpdateTime, bool addRemainingSuffix)
|
||||
{
|
||||
Assert(lastProgressUpdateTime <= currentTime);
|
||||
output[0] = 0;
|
||||
|
||||
// calculate pre-extrapolation values
|
||||
float timeElapsed = lastProgressUpdateTime - startTime;
|
||||
float totalTime = timeElapsed / currentProgress;
|
||||
|
||||
// calculate seconds
|
||||
int secondsRemaining = (int)(totalTime - timeElapsed);
|
||||
if (lastProgressUpdateTime < currentTime)
|
||||
{
|
||||
// old update, extrapolate
|
||||
float progressRate = currentProgress / timeElapsed;
|
||||
float extrapolatedProgress = progressRate * (currentTime - startTime);
|
||||
float extrapolatedTotalTime = (currentTime - startTime) / extrapolatedProgress;
|
||||
secondsRemaining = (int)(extrapolatedTotalTime - timeElapsed);
|
||||
}
|
||||
// if there's some time, make sure it's at least one second left
|
||||
if ( secondsRemaining == 0 && ( ( totalTime - timeElapsed ) > 0 ) )
|
||||
{
|
||||
secondsRemaining = 1;
|
||||
}
|
||||
|
||||
// calculate minutes
|
||||
int minutesRemaining = 0;
|
||||
while (secondsRemaining >= 60)
|
||||
{
|
||||
minutesRemaining++;
|
||||
secondsRemaining -= 60;
|
||||
}
|
||||
|
||||
char minutesBuf[16];
|
||||
Q_snprintf(minutesBuf, sizeof( minutesBuf ), "%d", minutesRemaining);
|
||||
char secondsBuf[16];
|
||||
Q_snprintf(secondsBuf, sizeof( secondsBuf ), "%d", secondsRemaining);
|
||||
|
||||
if (minutesRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeMinutes[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(minutesBuf, unicodeMinutes, sizeof( unicodeMinutes ));
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftMinutesSeconds";
|
||||
if (minutesRemaining == 1 && secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSecond";
|
||||
}
|
||||
else if (minutesRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinuteSeconds";
|
||||
}
|
||||
else if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftMinutesSecond";
|
||||
}
|
||||
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof( unlocString ));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining", sizeof(unlocString ), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 2, unicodeMinutes, unicodeSeconds);
|
||||
|
||||
}
|
||||
else if (secondsRemaining > 0)
|
||||
{
|
||||
wchar_t unicodeSeconds[16];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(secondsBuf, unicodeSeconds, sizeof( unicodeSeconds ));
|
||||
|
||||
const char *unlocalizedString = "#vgui_TimeLeftSeconds";
|
||||
if (secondsRemaining == 1)
|
||||
{
|
||||
unlocalizedString = "#vgui_TimeLeftSecond";
|
||||
}
|
||||
char unlocString[64];
|
||||
Q_strncpy(unlocString, unlocalizedString,sizeof(unlocString));
|
||||
if (addRemainingSuffix)
|
||||
{
|
||||
Q_strncat(unlocString, "Remaining",sizeof(unlocString), COPY_ALL_CHARACTERS);
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(output, outputBufferSizeInBytes, g_pVGuiLocalize->Find(unlocString), 1, unicodeSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetBarInset( int pixels )
|
||||
{
|
||||
m_iBarInset = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetBarInset( void )
|
||||
{
|
||||
return m_iBarInset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::SetMargin( int pixels )
|
||||
{
|
||||
m_iBarMargin = pixels;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
int ProgressBar::GetMargin()
|
||||
{
|
||||
return m_iBarMargin;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
_progress = inResourceData->GetFloat("progress", 0.0f);
|
||||
|
||||
const char *dialogVar = inResourceData->GetString("variable", "");
|
||||
if (dialogVar && *dialogVar)
|
||||
{
|
||||
m_pszDialogVar = new char[strlen(dialogVar) + 1];
|
||||
strcpy(m_pszDialogVar, dialogVar);
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
outResourceData->SetFloat("progress", _progress );
|
||||
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
outResourceData->SetString("variable", m_pszDialogVar);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a string description of the panel fields for use in the UI
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ProgressBar::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string progress, string variable", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates progress bar bases on values
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBar::OnDialogVariablesChanged(KeyValues *dialogVariables)
|
||||
{
|
||||
if (m_pszDialogVar)
|
||||
{
|
||||
int val = dialogVariables->GetInt(m_pszDialogVar, -1);
|
||||
if (val >= 0.0f)
|
||||
{
|
||||
SetProgress(val / 100.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DECLARE_BUILD_FACTORY( ContinuousProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ContinuousProgressBar::ContinuousProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ContinuousProgressBar::Paint()
|
||||
{
|
||||
int x = 0, y = 0;
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor(GetFgColor());
|
||||
|
||||
switch( m_iProgressDirection )
|
||||
{
|
||||
case PROGRESS_EAST:
|
||||
surface()->DrawFilledRect( x, y, x + (int)( wide * _progress ), y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_WEST:
|
||||
surface()->DrawFilledRect( x + (int)( wide * ( 1.0f - _progress ) ), y, x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_NORTH:
|
||||
surface()->DrawFilledRect( x, y + (int)( tall * ( 1.0f - _progress ) ), x + wide, y + tall );
|
||||
break;
|
||||
|
||||
case PROGRESS_SOUTH:
|
||||
surface()->DrawFilledRect( x, y, x + wide, y + (int)( tall * _progress ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,360 +1,360 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/ProgressBar.h>
|
||||
#include <vgui_controls/ProgressBox.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::ProgressBox(const char *title, const char *text, const char *pszUnknownTimeString, Panel *parent) : Frame(parent, NULL, parent ? false : true)
|
||||
{
|
||||
// save off the non-localized title, since we may need to dynamically localize it (on progress updates)
|
||||
const wchar_t *ws = g_pVGuiLocalize->Find(title);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wszTitleString, ws, sizeof(m_wszTitleString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(title, m_wszTitleString, sizeof(m_wszTitleString));
|
||||
}
|
||||
|
||||
m_pMessageLabel = new Label(this, NULL, pszUnknownTimeString);
|
||||
|
||||
ws = g_pVGuiLocalize->Find(text);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wcsInfoString, ws, sizeof(m_wcsInfoString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_wcsInfoString[0] = 0;
|
||||
}
|
||||
|
||||
ws = g_pVGuiLocalize->Find(pszUnknownTimeString);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wszUnknownTimeString, ws, sizeof(m_wszUnknownTimeString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_wszUnknownTimeString[0] = 0;
|
||||
}
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::ProgressBox(const wchar_t *wszTitle, const wchar_t *wszText, const wchar_t *wszUnknownTimeString, Panel *parent) : Frame(parent, NULL, parent ? false : true)
|
||||
{
|
||||
wcsncpy(m_wszTitleString, wszTitle, sizeof(m_wszTitleString) / sizeof(wchar_t));
|
||||
m_pMessageLabel = new Label(this, NULL, wszUnknownTimeString);
|
||||
wcsncpy(m_wcsInfoString, wszText, sizeof(m_wcsInfoString) / sizeof(wchar_t));
|
||||
wcsncpy(m_wszUnknownTimeString, wszUnknownTimeString, sizeof(m_wszUnknownTimeString) / sizeof(wchar_t));
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor Helper
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::Init()
|
||||
{
|
||||
m_pProgressBar = new ProgressBar(this, NULL);
|
||||
m_pProgressBar->SetVisible(false);
|
||||
|
||||
m_pCancelButton = new Button(this, NULL, "#VGui_Cancel");
|
||||
m_pCancelButton->SetSize(72, 24);
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCancelButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
SetSize(384, 128);
|
||||
m_flCurrentProgress = 0.0f;
|
||||
m_flFirstProgressUpdate = -0.1f;
|
||||
m_flLastProgressUpdate = 0.0f;
|
||||
|
||||
// mark ourselves as needed ticked once a second, to force us to repaint
|
||||
ivgui()->AddTickSignal(GetVPanel(), 1000);
|
||||
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::~ProgressBox()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: resize the message label
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
m_pMessageLabel->GetContentSize(wide, tall);
|
||||
SetSize(384, tall + 92);
|
||||
m_pMessageLabel->SetSize(344, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the message box into a modal state
|
||||
// Does not suspend execution - use addActionSignal to get return value
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::DoModal(Frame *pFrameOver)
|
||||
{
|
||||
ShowWindow(pFrameOver);
|
||||
input()->SetAppModalSurface(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Activates the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::ShowWindow(Frame *pFrameOver)
|
||||
{
|
||||
// move to the middle of the screen
|
||||
// get the screen size
|
||||
int wide, tall;
|
||||
// get our dialog size
|
||||
GetSize(wide, tall);
|
||||
|
||||
if (pFrameOver)
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
pFrameOver->GetPos(frameX, frameY);
|
||||
pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
BaseClass::Activate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the text and OK buttons in correct place
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::PerformLayout()
|
||||
{
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
wide += x;
|
||||
tall += y;
|
||||
|
||||
int leftEdge = x + 16;
|
||||
m_pMessageLabel->SetPos(leftEdge, y + 12);
|
||||
m_pProgressBar->SetPos(leftEdge, y + 14 + m_pMessageLabel->GetTall() + 2);
|
||||
m_pProgressBar->SetSize(wide - 44, 24);
|
||||
|
||||
if (m_pCancelButton->IsVisible())
|
||||
{
|
||||
// make room for cancel
|
||||
int px, py, pw, pt;
|
||||
int offs = m_pCancelButton->GetWide();
|
||||
m_pProgressBar->GetBounds(px, py, pw, pt);
|
||||
m_pCancelButton->SetPos(px + pw - offs, py);
|
||||
m_pProgressBar->SetSize(pw - offs - 10, pt);
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates progress bar, range [0, 1]
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetProgress(float progress)
|
||||
{
|
||||
Assert(progress >= 0.0f && progress <= 1.0f);
|
||||
m_pProgressBar->SetProgress(progress);
|
||||
m_pProgressBar->SetVisible(true);
|
||||
|
||||
// only update progress timings if the progress has actually changed
|
||||
if (progress != m_flCurrentProgress)
|
||||
{
|
||||
// store off timings for calculating time remaining
|
||||
if (m_flFirstProgressUpdate < 0.0f)
|
||||
{
|
||||
m_flFirstProgressUpdate = (float)system()->GetFrameTime();
|
||||
}
|
||||
m_flCurrentProgress = progress;
|
||||
m_flLastProgressUpdate = (float)system()->GetFrameTime();
|
||||
|
||||
UpdateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the info text
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetText(const char *text)
|
||||
{
|
||||
m_pMessageLabel->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Updates the dialog title text
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::UpdateTitle()
|
||||
{
|
||||
// update progress text
|
||||
wchar_t unicode[256];
|
||||
wchar_t completion[64];
|
||||
if ((int)(m_flCurrentProgress * 100.0f) > 0)
|
||||
{
|
||||
_snwprintf(completion, sizeof(completion) / sizeof(wchar_t), L"- %d%% complete", (int)(m_flCurrentProgress * 100.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
completion[0] = 0;
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(unicode, sizeof(unicode), m_wszTitleString, 1, completion);
|
||||
SetTitle(unicode, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: called every render
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnThink()
|
||||
{
|
||||
// calculate the progress made
|
||||
if (m_flFirstProgressUpdate >= 0.0f && m_wcsInfoString[0])
|
||||
{
|
||||
wchar_t timeRemaining[128];
|
||||
if (ProgressBar::ConstructTimeRemainingString(timeRemaining, sizeof(timeRemaining), m_flFirstProgressUpdate, (float)system()->GetFrameTime(), m_flCurrentProgress, m_flLastProgressUpdate, true))
|
||||
{
|
||||
wchar_t unicode[256];
|
||||
g_pVGuiLocalize->ConstructString(unicode, sizeof(unicode), m_wcsInfoString, 1, timeRemaining);
|
||||
m_pMessageLabel->SetText(unicode);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMessageLabel->SetText(m_wszUnknownTimeString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Forces us to repaint once per second
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnTick()
|
||||
{
|
||||
if (m_flFirstProgressUpdate >= 0.0f)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
|
||||
BaseClass::OnTick();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles ESC closing dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: close button pressed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCloseFrameButtonPressed()
|
||||
{
|
||||
OnCancel();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Deletes self when closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnClose()
|
||||
{
|
||||
BaseClass::OnClose();
|
||||
// modal surface is released on deletion
|
||||
MarkForDeletion();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnShutdownRequest()
|
||||
{
|
||||
// Shutdown the dialog
|
||||
PostMessage(this, new KeyValues("Command", "command", "Cancel"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: On update cancelled
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCancel()
|
||||
{
|
||||
// post a message that we've been cancelled
|
||||
PostActionSignal(new KeyValues("ProgressBoxCancelled"));
|
||||
|
||||
// close this dialog
|
||||
Close();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles visibility of the close box.
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
m_pCancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetCancelButtonEnabled(bool state)
|
||||
{
|
||||
m_pCancelButton->SetEnabled(state);
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/ProgressBar.h>
|
||||
#include <vgui_controls/ProgressBox.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::ProgressBox(const char *title, const char *text, const char *pszUnknownTimeString, Panel *parent) : Frame(parent, NULL, parent ? false : true)
|
||||
{
|
||||
// save off the non-localized title, since we may need to dynamically localize it (on progress updates)
|
||||
const wchar_t *ws = g_pVGuiLocalize->Find(title);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wszTitleString, ws, sizeof(m_wszTitleString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode(title, m_wszTitleString, sizeof(m_wszTitleString));
|
||||
}
|
||||
|
||||
m_pMessageLabel = new Label(this, NULL, pszUnknownTimeString);
|
||||
|
||||
ws = g_pVGuiLocalize->Find(text);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wcsInfoString, ws, sizeof(m_wcsInfoString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_wcsInfoString[0] = 0;
|
||||
}
|
||||
|
||||
ws = g_pVGuiLocalize->Find(pszUnknownTimeString);
|
||||
if (ws)
|
||||
{
|
||||
wcsncpy(m_wszUnknownTimeString, ws, sizeof(m_wszUnknownTimeString) / sizeof(wchar_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_wszUnknownTimeString[0] = 0;
|
||||
}
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::ProgressBox(const wchar_t *wszTitle, const wchar_t *wszText, const wchar_t *wszUnknownTimeString, Panel *parent) : Frame(parent, NULL, parent ? false : true)
|
||||
{
|
||||
wcsncpy(m_wszTitleString, wszTitle, sizeof(m_wszTitleString) / sizeof(wchar_t));
|
||||
m_pMessageLabel = new Label(this, NULL, wszUnknownTimeString);
|
||||
wcsncpy(m_wcsInfoString, wszText, sizeof(m_wcsInfoString) / sizeof(wchar_t));
|
||||
wcsncpy(m_wszUnknownTimeString, wszUnknownTimeString, sizeof(m_wszUnknownTimeString) / sizeof(wchar_t));
|
||||
Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor Helper
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::Init()
|
||||
{
|
||||
m_pProgressBar = new ProgressBar(this, NULL);
|
||||
m_pProgressBar->SetVisible(false);
|
||||
|
||||
m_pCancelButton = new Button(this, NULL, "#VGui_Cancel");
|
||||
m_pCancelButton->SetSize(72, 24);
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCancelButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
SetSize(384, 128);
|
||||
m_flCurrentProgress = 0.0f;
|
||||
m_flFirstProgressUpdate = -0.1f;
|
||||
m_flLastProgressUpdate = 0.0f;
|
||||
|
||||
// mark ourselves as needed ticked once a second, to force us to repaint
|
||||
ivgui()->AddTickSignal(GetVPanel(), 1000);
|
||||
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ProgressBox::~ProgressBox()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: resize the message label
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
m_pMessageLabel->GetContentSize(wide, tall);
|
||||
SetSize(384, tall + 92);
|
||||
m_pMessageLabel->SetSize(344, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the message box into a modal state
|
||||
// Does not suspend execution - use addActionSignal to get return value
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::DoModal(Frame *pFrameOver)
|
||||
{
|
||||
ShowWindow(pFrameOver);
|
||||
input()->SetAppModalSurface(GetVPanel());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Activates the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::ShowWindow(Frame *pFrameOver)
|
||||
{
|
||||
// move to the middle of the screen
|
||||
// get the screen size
|
||||
int wide, tall;
|
||||
// get our dialog size
|
||||
GetSize(wide, tall);
|
||||
|
||||
if (pFrameOver)
|
||||
{
|
||||
int frameX, frameY;
|
||||
int frameWide, frameTall;
|
||||
pFrameOver->GetPos(frameX, frameY);
|
||||
pFrameOver->GetSize(frameWide, frameTall);
|
||||
|
||||
SetPos((frameWide - wide) / 2 + frameX, (frameTall - tall) / 2 + frameY);
|
||||
}
|
||||
else
|
||||
{
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
BaseClass::Activate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Put the text and OK buttons in correct place
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::PerformLayout()
|
||||
{
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
wide += x;
|
||||
tall += y;
|
||||
|
||||
int leftEdge = x + 16;
|
||||
m_pMessageLabel->SetPos(leftEdge, y + 12);
|
||||
m_pProgressBar->SetPos(leftEdge, y + 14 + m_pMessageLabel->GetTall() + 2);
|
||||
m_pProgressBar->SetSize(wide - 44, 24);
|
||||
|
||||
if (m_pCancelButton->IsVisible())
|
||||
{
|
||||
// make room for cancel
|
||||
int px, py, pw, pt;
|
||||
int offs = m_pCancelButton->GetWide();
|
||||
m_pProgressBar->GetBounds(px, py, pw, pt);
|
||||
m_pCancelButton->SetPos(px + pw - offs, py);
|
||||
m_pProgressBar->SetSize(pw - offs - 10, pt);
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: updates progress bar, range [0, 1]
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetProgress(float progress)
|
||||
{
|
||||
Assert(progress >= 0.0f && progress <= 1.0f);
|
||||
m_pProgressBar->SetProgress(progress);
|
||||
m_pProgressBar->SetVisible(true);
|
||||
|
||||
// only update progress timings if the progress has actually changed
|
||||
if (progress != m_flCurrentProgress)
|
||||
{
|
||||
// store off timings for calculating time remaining
|
||||
if (m_flFirstProgressUpdate < 0.0f)
|
||||
{
|
||||
m_flFirstProgressUpdate = (float)system()->GetFrameTime();
|
||||
}
|
||||
m_flCurrentProgress = progress;
|
||||
m_flLastProgressUpdate = (float)system()->GetFrameTime();
|
||||
|
||||
UpdateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the info text
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetText(const char *text)
|
||||
{
|
||||
m_pMessageLabel->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Updates the dialog title text
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::UpdateTitle()
|
||||
{
|
||||
// update progress text
|
||||
wchar_t unicode[256];
|
||||
wchar_t completion[64];
|
||||
if ((int)(m_flCurrentProgress * 100.0f) > 0)
|
||||
{
|
||||
_snwprintf(completion, sizeof(completion) / sizeof(wchar_t), L"- %d%% complete", (int)(m_flCurrentProgress * 100.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
completion[0] = 0;
|
||||
}
|
||||
g_pVGuiLocalize->ConstructString(unicode, sizeof(unicode), m_wszTitleString, 1, completion);
|
||||
SetTitle(unicode, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: called every render
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnThink()
|
||||
{
|
||||
// calculate the progress made
|
||||
if (m_flFirstProgressUpdate >= 0.0f && m_wcsInfoString[0])
|
||||
{
|
||||
wchar_t timeRemaining[128];
|
||||
if (ProgressBar::ConstructTimeRemainingString(timeRemaining, sizeof(timeRemaining), m_flFirstProgressUpdate, (float)system()->GetFrameTime(), m_flCurrentProgress, m_flLastProgressUpdate, true))
|
||||
{
|
||||
wchar_t unicode[256];
|
||||
g_pVGuiLocalize->ConstructString(unicode, sizeof(unicode), m_wcsInfoString, 1, timeRemaining);
|
||||
m_pMessageLabel->SetText(unicode);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMessageLabel->SetText(m_wszUnknownTimeString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Forces us to repaint once per second
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnTick()
|
||||
{
|
||||
if (m_flFirstProgressUpdate >= 0.0f)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
|
||||
BaseClass::OnTick();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles ESC closing dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: close button pressed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCloseFrameButtonPressed()
|
||||
{
|
||||
OnCancel();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Deletes self when closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnClose()
|
||||
{
|
||||
BaseClass::OnClose();
|
||||
// modal surface is released on deletion
|
||||
MarkForDeletion();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnShutdownRequest()
|
||||
{
|
||||
// Shutdown the dialog
|
||||
PostMessage(this, new KeyValues("Command", "command", "Cancel"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: On update cancelled
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::OnCancel()
|
||||
{
|
||||
// post a message that we've been cancelled
|
||||
PostActionSignal(new KeyValues("ProgressBoxCancelled"));
|
||||
|
||||
// close this dialog
|
||||
Close();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles visibility of the close box.
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
m_pCancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ProgressBox::SetCancelButtonEnabled(bool state)
|
||||
{
|
||||
m_pCancelButton->SetEnabled(state);
|
||||
BaseClass::SetCloseButtonVisible(state);
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
@@ -1,303 +1,303 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/PropertyDialog.h>
|
||||
#include <vgui_controls/PropertySheet.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyDialog::PropertyDialog(Panel *parent, const char *panelName) : Frame(parent, panelName)
|
||||
{
|
||||
// create the property sheet
|
||||
_propertySheet = new PropertySheet(this, "Sheet");
|
||||
_propertySheet->AddActionSignalTarget(this);
|
||||
_propertySheet->SetTabPosition(1);
|
||||
|
||||
// add the buttons
|
||||
_okButton = new Button(this, "OKButton", "#PropertyDialog_OK");
|
||||
_okButton->AddActionSignalTarget(this);
|
||||
_okButton->SetTabPosition(2);
|
||||
_okButton->SetCommand("OK");
|
||||
GetFocusNavGroup().SetDefaultButton(_okButton);
|
||||
|
||||
_cancelButton = new Button(this, "CancelButton", "#PropertyDialog_Cancel");
|
||||
_cancelButton->AddActionSignalTarget(this);
|
||||
_cancelButton->SetTabPosition(3);
|
||||
_cancelButton->SetCommand("Cancel");
|
||||
|
||||
_applyButton = new Button(this, "ApplyButton", "#PropertyDialog_Apply");
|
||||
_applyButton->AddActionSignalTarget(this);
|
||||
_applyButton->SetTabPosition(4);
|
||||
_applyButton->SetVisible(false); // default to not visible
|
||||
_applyButton->SetEnabled(false); // default to not enabled
|
||||
_applyButton->SetCommand("Apply");
|
||||
|
||||
SetSizeable(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyDialog::~PropertyDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a pointer to the PropertySheet this dialog encapsulates
|
||||
// Output : PropertySheet *
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertySheet *PropertyDialog::GetPropertySheet()
|
||||
{
|
||||
return _propertySheet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a pointer to the currently active page.
|
||||
// Output : Panel
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PropertyDialog::GetActivePage()
|
||||
{
|
||||
return _propertySheet->GetActivePage();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Wrapped function
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::AddPage(Panel *page, const char *title)
|
||||
{
|
||||
_propertySheet->AddPage(page, title);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: reloads the data in all the property page
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ResetAllData()
|
||||
{
|
||||
_propertySheet->ResetAllData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies any changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ApplyChanges()
|
||||
{
|
||||
OnCommand("Apply");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets up the sheet
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int iBottom = m_iSheetInsetBottom;
|
||||
if ( IsProportional() )
|
||||
{
|
||||
iBottom = scheme()->GetProportionalScaledValueEx( GetScheme(), iBottom );
|
||||
}
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
_propertySheet->SetBounds(x, y, wide, tall - iBottom);
|
||||
|
||||
|
||||
// move the buttons to the bottom-right corner
|
||||
int xpos = x + wide - 80;
|
||||
int ypos = tall + y - 28;
|
||||
|
||||
if (_applyButton->IsVisible())
|
||||
{
|
||||
_applyButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
}
|
||||
|
||||
if (_cancelButton->IsVisible())
|
||||
{
|
||||
_cancelButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
}
|
||||
|
||||
_okButton->SetBounds(xpos, ypos, 72, 24);
|
||||
|
||||
_propertySheet->InvalidateLayout(); // tell the propertysheet to redraw!
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles command text from the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
if ( OnOK(false) )
|
||||
{
|
||||
OnCommand("Close");
|
||||
}
|
||||
_applyButton->SetEnabled(false);
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCancel();
|
||||
Close();
|
||||
}
|
||||
else if (!stricmp(command, "Apply"))
|
||||
{
|
||||
OnOK(true);
|
||||
_applyButton->SetEnabled(false);
|
||||
InvalidateLayout();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: called when the Cancel button is pressed
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnCancel()
|
||||
{
|
||||
// designed to be overridden
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : code -
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
// this has been removed, since it conflicts with how we use the escape key in the game
|
||||
// if (code == KEY_ESCAPE)
|
||||
// {
|
||||
// OnCommand("Cancel");
|
||||
// }
|
||||
// else
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Command handler
|
||||
//-----------------------------------------------------------------------------
|
||||
bool PropertyDialog::OnOK(bool applyOnly)
|
||||
{
|
||||
// the sheet should have the pages apply changes before we tell the world
|
||||
_propertySheet->ApplyChanges();
|
||||
|
||||
// this should tell anybody who's watching us that we're done
|
||||
PostActionSignal(new KeyValues("ApplyChanges"));
|
||||
|
||||
// default to closing
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Overrides build mode so it edits the sub panel
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ActivateBuildMode()
|
||||
{
|
||||
// no subpanel, no build mode
|
||||
EditablePanel *panel = dynamic_cast<EditablePanel *>(GetActivePage());
|
||||
if (!panel)
|
||||
return;
|
||||
|
||||
panel->ActivateBuildMode();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the OK/Cancel buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetOKButtonText(const char *text)
|
||||
{
|
||||
_okButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the OK/Cancel buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetCancelButtonText(const char *text)
|
||||
{
|
||||
_cancelButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the apply buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetApplyButtonText(const char *text)
|
||||
{
|
||||
_applyButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetOKButtonVisible(bool state)
|
||||
{
|
||||
_okButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
_cancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetApplyButtonVisible(bool state)
|
||||
{
|
||||
_applyButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: when a sheet changes, enable the apply button
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnApplyButtonEnable()
|
||||
{
|
||||
if (_applyButton->IsEnabled())
|
||||
return;
|
||||
|
||||
EnableApplyButton(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: enable/disable the apply button
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::EnableApplyButton(bool bEnable)
|
||||
{
|
||||
_applyButton->SetEnabled(bEnable);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::RequestFocus(int direction)
|
||||
{
|
||||
_propertySheet->RequestFocus(direction);
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/PropertyDialog.h>
|
||||
#include <vgui_controls/PropertySheet.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyDialog::PropertyDialog(Panel *parent, const char *panelName) : Frame(parent, panelName)
|
||||
{
|
||||
// create the property sheet
|
||||
_propertySheet = new PropertySheet(this, "Sheet");
|
||||
_propertySheet->AddActionSignalTarget(this);
|
||||
_propertySheet->SetTabPosition(1);
|
||||
|
||||
// add the buttons
|
||||
_okButton = new Button(this, "OKButton", "#PropertyDialog_OK");
|
||||
_okButton->AddActionSignalTarget(this);
|
||||
_okButton->SetTabPosition(2);
|
||||
_okButton->SetCommand("OK");
|
||||
GetFocusNavGroup().SetDefaultButton(_okButton);
|
||||
|
||||
_cancelButton = new Button(this, "CancelButton", "#PropertyDialog_Cancel");
|
||||
_cancelButton->AddActionSignalTarget(this);
|
||||
_cancelButton->SetTabPosition(3);
|
||||
_cancelButton->SetCommand("Cancel");
|
||||
|
||||
_applyButton = new Button(this, "ApplyButton", "#PropertyDialog_Apply");
|
||||
_applyButton->AddActionSignalTarget(this);
|
||||
_applyButton->SetTabPosition(4);
|
||||
_applyButton->SetVisible(false); // default to not visible
|
||||
_applyButton->SetEnabled(false); // default to not enabled
|
||||
_applyButton->SetCommand("Apply");
|
||||
|
||||
SetSizeable(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyDialog::~PropertyDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a pointer to the PropertySheet this dialog encapsulates
|
||||
// Output : PropertySheet *
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertySheet *PropertyDialog::GetPropertySheet()
|
||||
{
|
||||
return _propertySheet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a pointer to the currently active page.
|
||||
// Output : Panel
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *PropertyDialog::GetActivePage()
|
||||
{
|
||||
return _propertySheet->GetActivePage();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Wrapped function
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::AddPage(Panel *page, const char *title)
|
||||
{
|
||||
_propertySheet->AddPage(page, title);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: reloads the data in all the property page
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ResetAllData()
|
||||
{
|
||||
_propertySheet->ResetAllData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies any changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ApplyChanges()
|
||||
{
|
||||
OnCommand("Apply");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets up the sheet
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int iBottom = m_iSheetInsetBottom;
|
||||
if ( IsProportional() )
|
||||
{
|
||||
iBottom = scheme()->GetProportionalScaledValueEx( GetScheme(), iBottom );
|
||||
}
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
_propertySheet->SetBounds(x, y, wide, tall - iBottom);
|
||||
|
||||
|
||||
// move the buttons to the bottom-right corner
|
||||
int xpos = x + wide - 80;
|
||||
int ypos = tall + y - 28;
|
||||
|
||||
if (_applyButton->IsVisible())
|
||||
{
|
||||
_applyButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
}
|
||||
|
||||
if (_cancelButton->IsVisible())
|
||||
{
|
||||
_cancelButton->SetBounds(xpos, ypos, 72, 24);
|
||||
xpos -= 80;
|
||||
}
|
||||
|
||||
_okButton->SetBounds(xpos, ypos, 72, 24);
|
||||
|
||||
_propertySheet->InvalidateLayout(); // tell the propertysheet to redraw!
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles command text from the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
if ( OnOK(false) )
|
||||
{
|
||||
OnCommand("Close");
|
||||
}
|
||||
_applyButton->SetEnabled(false);
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCancel();
|
||||
Close();
|
||||
}
|
||||
else if (!stricmp(command, "Apply"))
|
||||
{
|
||||
OnOK(true);
|
||||
_applyButton->SetEnabled(false);
|
||||
InvalidateLayout();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: called when the Cancel button is pressed
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnCancel()
|
||||
{
|
||||
// designed to be overridden
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : code -
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
// this has been removed, since it conflicts with how we use the escape key in the game
|
||||
// if (code == KEY_ESCAPE)
|
||||
// {
|
||||
// OnCommand("Cancel");
|
||||
// }
|
||||
// else
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Command handler
|
||||
//-----------------------------------------------------------------------------
|
||||
bool PropertyDialog::OnOK(bool applyOnly)
|
||||
{
|
||||
// the sheet should have the pages apply changes before we tell the world
|
||||
_propertySheet->ApplyChanges();
|
||||
|
||||
// this should tell anybody who's watching us that we're done
|
||||
PostActionSignal(new KeyValues("ApplyChanges"));
|
||||
|
||||
// default to closing
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Overrides build mode so it edits the sub panel
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::ActivateBuildMode()
|
||||
{
|
||||
// no subpanel, no build mode
|
||||
EditablePanel *panel = dynamic_cast<EditablePanel *>(GetActivePage());
|
||||
if (!panel)
|
||||
return;
|
||||
|
||||
panel->ActivateBuildMode();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the OK/Cancel buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetOKButtonText(const char *text)
|
||||
{
|
||||
_okButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the OK/Cancel buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetCancelButtonText(const char *text)
|
||||
{
|
||||
_cancelButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the text on the apply buttons, overriding the default
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetApplyButtonText(const char *text)
|
||||
{
|
||||
_applyButton->SetText(text);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetOKButtonVisible(bool state)
|
||||
{
|
||||
_okButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetCancelButtonVisible(bool state)
|
||||
{
|
||||
_cancelButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: changes the visibility of the buttons
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::SetApplyButtonVisible(bool state)
|
||||
{
|
||||
_applyButton->SetVisible(state);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: when a sheet changes, enable the apply button
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::OnApplyButtonEnable()
|
||||
{
|
||||
if (_applyButton->IsEnabled())
|
||||
return;
|
||||
|
||||
EnableApplyButton(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: enable/disable the apply button
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::EnableApplyButton(bool bEnable)
|
||||
{
|
||||
_applyButton->SetEnabled(bEnable);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyDialog::RequestFocus(int direction)
|
||||
{
|
||||
_propertySheet->RequestFocus(direction);
|
||||
}
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
#include "vgui_controls/PropertyPage.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyPage::PropertyPage(Panel *parent, const char *panelName) : EditablePanel(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyPage::~PropertyPage()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when page is loaded. Data should be reloaded from document into controls.
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnResetData()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the OK / Apply button is pressed. Changed data should be written into document.
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnApplyChanges()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Designed to be overriden
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageShow()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Designed to be overriden
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageHide()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *pageTab -
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageTabActivated(Panel *pageTab)
|
||||
{
|
||||
_pageTab = pageTab;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
// left and right only get propogated to parents if our tab has focus
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
if (_pageTab != 0 && _pageTab->HasFocus())
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
{
|
||||
if (_pageTab != 0 && _pageTab->HasFocus())
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::SetVisible(bool state)
|
||||
{
|
||||
if (IsVisible() && !state)
|
||||
{
|
||||
// if we're going away and we have a current button, get rid of it
|
||||
if (GetFocusNavGroup().GetCurrentDefaultButton())
|
||||
{
|
||||
GetFocusNavGroup().SetCurrentDefaultButton(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::SetVisible(state);
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
#include "vgui_controls/PropertyPage.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyPage::PropertyPage(Panel *parent, const char *panelName) : EditablePanel(parent, panelName)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertyPage::~PropertyPage()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when page is loaded. Data should be reloaded from document into controls.
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnResetData()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Called when the OK / Apply button is pressed. Changed data should be written into document.
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnApplyChanges()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Designed to be overriden
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageShow()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Designed to be overriden
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageHide()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *pageTab -
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnPageTabActivated(Panel *pageTab)
|
||||
{
|
||||
_pageTab = pageTab;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
// left and right only get propogated to parents if our tab has focus
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
if (_pageTab != 0 && _pageTab->HasFocus())
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
{
|
||||
if (_pageTab != 0 && _pageTab->HasFocus())
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void PropertyPage::SetVisible(bool state)
|
||||
{
|
||||
if (IsVisible() && !state)
|
||||
{
|
||||
// if we're going away and we have a current button, get rid of it
|
||||
if (GetFocusNavGroup().GetCurrentDefaultButton())
|
||||
{
|
||||
GetFocusNavGroup().SetCurrentDefaultButton(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::SetVisible(state);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,222 +1,222 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
#include <vgui_controls/QueryBox.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::QueryBox(const char *title, const char *queryText, vgui::Panel *parent) : MessageBox(title, queryText,parent)
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#QueryBox_Cancel");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOkButton->SetCommand("OK");
|
||||
m_pCancelCommand = NULL;
|
||||
m_pOkCommand = NULL;
|
||||
|
||||
m_pOkButton->SetTabPosition(1);
|
||||
m_pCancelButton->SetTabPosition(2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::QueryBox(const wchar_t *wszTitle, const wchar_t *wszQueryText,vgui::Panel *parent) : MessageBox(wszTitle, wszQueryText,parent)
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#QueryBox_Cancel");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOkButton->SetCommand("OK");
|
||||
m_pCancelCommand = NULL;
|
||||
m_pOkCommand = NULL;
|
||||
|
||||
m_pOkButton->SetTabPosition(1);
|
||||
m_pCancelButton->SetTabPosition(2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::~QueryBox()
|
||||
{
|
||||
delete m_pCancelButton;
|
||||
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand->deleteThis();
|
||||
}
|
||||
if ( m_pCancelCommand )
|
||||
{
|
||||
m_pCancelCommand->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Layout the window for drawing
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
wide += x;
|
||||
tall += y;
|
||||
|
||||
int oldWide, oldTall;
|
||||
m_pCancelButton->GetSize(oldWide, oldTall);
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pCancelButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
m_pCancelButton->SetSize(btnWide, btnTall);
|
||||
|
||||
//nt boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles command text from the buttons
|
||||
// Deletes self when closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
OnCommand("Close");
|
||||
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
PostActionSignal(m_pOkCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCommand("Close");
|
||||
|
||||
if (m_pCancelCommand)
|
||||
{
|
||||
PostActionSignal(m_pCancelCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::OnCommand(command);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to send when ok button is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetOKCommand(KeyValues *keyValues)
|
||||
{
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand->deleteThis();
|
||||
}
|
||||
|
||||
m_pOkCommand = keyValues;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a value of the ok command
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetOKCommandValue(const char *keyName, int value)
|
||||
{
|
||||
if ( !m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand = new KeyValues("Command");
|
||||
}
|
||||
|
||||
m_pOkCommand->SetInt(keyName, value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to send when the cancel button is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelCommand(KeyValues *keyValues)
|
||||
{
|
||||
if ( m_pCancelCommand )
|
||||
{
|
||||
m_pCancelCommand->deleteThis();
|
||||
}
|
||||
|
||||
m_pCancelCommand = keyValues;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the cancel button text
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelButtonText(const char* buttonText)
|
||||
{
|
||||
m_pCancelButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the cancel button text
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelButtonText(const wchar_t* wszButtonText)
|
||||
{
|
||||
m_pCancelButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void QueryBox::OnKeyCodeTyped( KeyCode code )
|
||||
{
|
||||
if ( code == KEY_ESCAPE )
|
||||
{
|
||||
OnCommand("Cancel");
|
||||
}
|
||||
else
|
||||
{
|
||||
Frame::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::OnKeyCodePressed( KeyCode code )
|
||||
{
|
||||
if ( code == KEY_XBUTTON_B )
|
||||
{
|
||||
OnCommand("Cancel");
|
||||
}
|
||||
else
|
||||
{
|
||||
Frame::OnKeyCodePressed(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
#include <vgui_controls/QueryBox.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::QueryBox(const char *title, const char *queryText, vgui::Panel *parent) : MessageBox(title, queryText,parent)
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#QueryBox_Cancel");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOkButton->SetCommand("OK");
|
||||
m_pCancelCommand = NULL;
|
||||
m_pOkCommand = NULL;
|
||||
|
||||
m_pOkButton->SetTabPosition(1);
|
||||
m_pCancelButton->SetTabPosition(2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::QueryBox(const wchar_t *wszTitle, const wchar_t *wszQueryText,vgui::Panel *parent) : MessageBox(wszTitle, wszQueryText,parent)
|
||||
{
|
||||
SetDeleteSelfOnClose(true);
|
||||
m_pCancelButton = new Button(this, "CancelButton", "#QueryBox_Cancel");
|
||||
m_pCancelButton->SetCommand("Cancel");
|
||||
m_pOkButton->SetCommand("OK");
|
||||
m_pCancelCommand = NULL;
|
||||
m_pOkCommand = NULL;
|
||||
|
||||
m_pOkButton->SetTabPosition(1);
|
||||
m_pCancelButton->SetTabPosition(2);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
QueryBox::~QueryBox()
|
||||
{
|
||||
delete m_pCancelButton;
|
||||
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand->deleteThis();
|
||||
}
|
||||
if ( m_pCancelCommand )
|
||||
{
|
||||
m_pCancelCommand->deleteThis();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Layout the window for drawing
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
wide += x;
|
||||
tall += y;
|
||||
|
||||
int oldWide, oldTall;
|
||||
m_pCancelButton->GetSize(oldWide, oldTall);
|
||||
|
||||
int btnWide, btnTall;
|
||||
m_pCancelButton->GetContentSize(btnWide, btnTall);
|
||||
btnWide = max(oldWide, btnWide + 10);
|
||||
btnTall = max(oldTall, btnTall + 10);
|
||||
m_pCancelButton->SetSize(btnWide, btnTall);
|
||||
|
||||
//nt boxWidth, boxTall;
|
||||
GetSize(boxWidth, boxTall);
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles command text from the buttons
|
||||
// Deletes self when closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::OnCommand(const char *command)
|
||||
{
|
||||
if (!stricmp(command, "OK"))
|
||||
{
|
||||
OnCommand("Close");
|
||||
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
PostActionSignal(m_pOkCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
else if (!stricmp(command, "Cancel"))
|
||||
{
|
||||
OnCommand("Close");
|
||||
|
||||
if (m_pCancelCommand)
|
||||
{
|
||||
PostActionSignal(m_pCancelCommand->MakeCopy());
|
||||
}
|
||||
}
|
||||
|
||||
BaseClass::OnCommand(command);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to send when ok button is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetOKCommand(KeyValues *keyValues)
|
||||
{
|
||||
if ( m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand->deleteThis();
|
||||
}
|
||||
|
||||
m_pOkCommand = keyValues;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set a value of the ok command
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetOKCommandValue(const char *keyName, int value)
|
||||
{
|
||||
if ( !m_pOkCommand )
|
||||
{
|
||||
m_pOkCommand = new KeyValues("Command");
|
||||
}
|
||||
|
||||
m_pOkCommand->SetInt(keyName, value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the keyvalues to send when the cancel button is hit
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelCommand(KeyValues *keyValues)
|
||||
{
|
||||
if ( m_pCancelCommand )
|
||||
{
|
||||
m_pCancelCommand->deleteThis();
|
||||
}
|
||||
|
||||
m_pCancelCommand = keyValues;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the cancel button text
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelButtonText(const char* buttonText)
|
||||
{
|
||||
m_pCancelButton->SetText(buttonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the cancel button text
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::SetCancelButtonText(const wchar_t* wszButtonText)
|
||||
{
|
||||
m_pCancelButton->SetText(wszButtonText);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void QueryBox::OnKeyCodeTyped( KeyCode code )
|
||||
{
|
||||
if ( code == KEY_ESCAPE )
|
||||
{
|
||||
OnCommand("Cancel");
|
||||
}
|
||||
else
|
||||
{
|
||||
Frame::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void QueryBox::OnKeyCodePressed( KeyCode code )
|
||||
{
|
||||
if ( code == KEY_XBUTTON_B )
|
||||
{
|
||||
OnCommand("Cancel");
|
||||
}
|
||||
else
|
||||
{
|
||||
Frame::OnKeyCodePressed(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,419 +1,419 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/FocusNavGroup.h>
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/RadioButton.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
enum direction
|
||||
{
|
||||
UP = -1,
|
||||
DOWN = 1,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Check box image
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioImage::Paint()
|
||||
{
|
||||
DrawSetTextFont(GetFont());
|
||||
|
||||
// draw background
|
||||
if (_radioButton->IsEnabled())
|
||||
{
|
||||
DrawSetTextColor(_bgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_radioButton->GetBgColor());
|
||||
}
|
||||
DrawPrintChar(0, 1, 'n');
|
||||
|
||||
// draw border circl
|
||||
DrawSetTextColor(_borderColor1);
|
||||
DrawPrintChar(0, 1, 'j');
|
||||
DrawSetTextColor(_borderColor2);
|
||||
DrawPrintChar(0, 1, 'k');
|
||||
|
||||
// draw selected check
|
||||
if (_radioButton->IsSelected())
|
||||
{
|
||||
DrawSetTextColor(_checkColor);
|
||||
DrawPrintChar(0, 1, 'h');
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( RadioButton, RadioButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create a radio button.
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton::RadioButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
|
||||
{
|
||||
SetContentAlignment(a_west);
|
||||
|
||||
// create the image
|
||||
_radioBoxImage = new RadioImage(this);
|
||||
|
||||
_oldTabPosition = 0;
|
||||
_subTabPosition = 0;
|
||||
|
||||
SetTextImageIndex(1);
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton::~RadioButton()
|
||||
{
|
||||
delete _radioBoxImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Apply resource file scheme.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
_radioBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(150, 150, 150, 0), pScheme);
|
||||
_radioBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 0), pScheme);
|
||||
_radioBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 0), pScheme);
|
||||
_radioBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 0), pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("RadioButton.TextColor", pScheme));
|
||||
_selectedFgColor = GetSchemeColor("RadioButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
|
||||
|
||||
SetDefaultColor( GetFgColor(), GetBgColor() );
|
||||
|
||||
SetArmedColor( GetSchemeColor("RadioButton.ArmedTextColor", pScheme), GetButtonArmedBgColor() );
|
||||
|
||||
SetContentAlignment(a_west);
|
||||
|
||||
// reloading the scheme wipes out lists of images
|
||||
_radioBoxImage->SetFont( pScheme->GetFont("Marlett", IsProportional()) );
|
||||
_radioBoxImage->ResizeImageToContent();
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the border style of the button, Radio buttons have no border
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *RadioButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tab position of the radio button with the set of radio buttons
|
||||
// A group of RadioButtons must have the same TabPosition, with [1, n] subtabpositions
|
||||
//-----------------------------------------------------------------------------
|
||||
int RadioButton::GetSubTabPosition()
|
||||
{
|
||||
return _subTabPosition;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tab position of the radio button with the set of radio buttons
|
||||
// A group of RadioButtons must have the same TabPosition, with [1, n] subtabpositions
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SetSubTabPosition(int position)
|
||||
{
|
||||
_subTabPosition = position;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return the RadioButton's real tab position (its Panel one changes)
|
||||
//-----------------------------------------------------------------------------
|
||||
int RadioButton::GetRadioTabPosition()
|
||||
{
|
||||
return _oldTabPosition;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the radio button checked. When a radio button is checked, a
|
||||
// message is sent to all other radio buttons in the same group so
|
||||
// they will become unchecked.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SetSelected(bool state)
|
||||
{
|
||||
InternalSetSelected( state, true );
|
||||
}
|
||||
|
||||
void RadioButton::InternalSetSelected(bool state, bool bFireEvents)
|
||||
{
|
||||
if (state == true)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
return;
|
||||
|
||||
// restore our tab position
|
||||
SetTabPosition(_oldTabPosition);
|
||||
|
||||
// Should we send notifications?
|
||||
if ( bFireEvents )
|
||||
{
|
||||
// send a message
|
||||
KeyValues *msg = new KeyValues("RadioButtonChecked");
|
||||
msg->SetPtr("panel", this);
|
||||
msg->SetInt("tabposition", _oldTabPosition);
|
||||
|
||||
// send a message to all other panels on the same level as heirarchy,
|
||||
// so that other radio buttons know to shut off
|
||||
VPANEL radioParent = GetVParent();
|
||||
if (radioParent)
|
||||
{
|
||||
for (int i = 0; i < ipanel()->GetChildCount(radioParent); i++)
|
||||
{
|
||||
VPANEL child = ipanel()->GetChild(radioParent, i);
|
||||
if (child != GetVPanel())
|
||||
{
|
||||
ivgui()->PostMessage(child, msg->MakeCopy(), GetVPanel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RequestFocus();
|
||||
PostActionSignal(msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove ourselves from the tab order
|
||||
if (GetTabPosition())
|
||||
{
|
||||
_oldTabPosition = GetTabPosition();
|
||||
}
|
||||
SetTabPosition(0);
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
|
||||
ToggleButton::SetSelected(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the selection state without firing any events
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SilentSetSelected(bool state)
|
||||
{
|
||||
InternalSetSelected( state, false );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set up the text color before doing normal layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::PerformLayout()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
SetFgColor(_selectedFgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFgColor(GetButtonFgColor());
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Apply resource settings including button state and text color.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
ToggleButton::ApplySettings(inResourceData);
|
||||
SetTextColorState(CS_NORMAL);
|
||||
|
||||
_subTabPosition = inResourceData->GetInt("SubTabPosition");
|
||||
_oldTabPosition = inResourceData->GetInt("TabPosition");
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get resource settings including button state, text color, and subTabPosition
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
ToggleButton::GetSettings(outResourceData);
|
||||
outResourceData->SetInt("SubTabPosition", _subTabPosition);
|
||||
outResourceData->SetInt("TabPosition", GetRadioTabPosition());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describe editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *RadioButton::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
Q_snprintf(buf, sizeof(buf), "%s, int SubTabPosition", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: When a radio button is checked, all other radio buttons
|
||||
// in the same group become unchecked.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::OnRadioButtonChecked(int tabPosition)
|
||||
{
|
||||
// make sure we're in the same tab group
|
||||
if (tabPosition != _oldTabPosition)
|
||||
return;
|
||||
|
||||
// wouldn't be sent to us from ourselves, so another radio button has taken over
|
||||
SetSelected(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draws the selection rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::Paint()
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
/*
|
||||
if (HasFocus())
|
||||
{
|
||||
int tx0, ty0, tx1, ty1;
|
||||
_textImage->GetPos(tx0, ty0);
|
||||
_textImage->GetSize(tx1, ty1);
|
||||
DrawFocusBorder(tx0, ty0, tx0 + tx1, ty0 + ty1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::DoClick()
|
||||
{
|
||||
SetSelected(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle arrow key movement
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
case KEY_SPACE:
|
||||
{
|
||||
if (!IsSelected())
|
||||
{
|
||||
SetSelected(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Panel::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
RadioButton *bestRadio = FindBestRadioButton( DOWN );
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->SetSelected(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
{
|
||||
RadioButton *bestRadio = FindBestRadioButton( UP );
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->SetSelected(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Find the correct radio button to move to.
|
||||
// Input : direction - the direction we are moving, up or down.
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton *RadioButton::FindBestRadioButton(int direction)
|
||||
{
|
||||
RadioButton *bestRadio = NULL;
|
||||
int highestRadio = 0;
|
||||
Panel *pr = GetParent();
|
||||
if (pr)
|
||||
{
|
||||
// find the radio button to go to next
|
||||
for (int i = 0; i < pr->GetChildCount(); i++)
|
||||
{
|
||||
RadioButton *child = dynamic_cast<RadioButton *>(pr->GetChild(i));
|
||||
if (child && child->GetRadioTabPosition() == _oldTabPosition)
|
||||
{
|
||||
if (child->GetSubTabPosition() == _subTabPosition + direction)
|
||||
{
|
||||
bestRadio = child;
|
||||
break;
|
||||
}
|
||||
if ( (child->GetSubTabPosition() == 0) && (direction == DOWN) )
|
||||
{
|
||||
bestRadio = child;
|
||||
continue;
|
||||
}
|
||||
else if ( (child->GetSubTabPosition() > highestRadio) && (direction == UP) )
|
||||
{
|
||||
bestRadio = child;
|
||||
highestRadio = bestRadio->GetSubTabPosition();
|
||||
continue;
|
||||
}
|
||||
if (!bestRadio)
|
||||
{
|
||||
bestRadio = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->RequestFocus();
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
return bestRadio;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/FocusNavGroup.h>
|
||||
#include <vgui_controls/Image.h>
|
||||
#include <vgui_controls/RadioButton.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
enum direction
|
||||
{
|
||||
UP = -1,
|
||||
DOWN = 1,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Check box image
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioImage::Paint()
|
||||
{
|
||||
DrawSetTextFont(GetFont());
|
||||
|
||||
// draw background
|
||||
if (_radioButton->IsEnabled())
|
||||
{
|
||||
DrawSetTextColor(_bgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSetTextColor(_radioButton->GetBgColor());
|
||||
}
|
||||
DrawPrintChar(0, 1, 'n');
|
||||
|
||||
// draw border circl
|
||||
DrawSetTextColor(_borderColor1);
|
||||
DrawPrintChar(0, 1, 'j');
|
||||
DrawSetTextColor(_borderColor2);
|
||||
DrawPrintChar(0, 1, 'k');
|
||||
|
||||
// draw selected check
|
||||
if (_radioButton->IsSelected())
|
||||
{
|
||||
DrawSetTextColor(_checkColor);
|
||||
DrawPrintChar(0, 1, 'h');
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( RadioButton, RadioButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Create a radio button.
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton::RadioButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
|
||||
{
|
||||
SetContentAlignment(a_west);
|
||||
|
||||
// create the image
|
||||
_radioBoxImage = new RadioImage(this);
|
||||
|
||||
_oldTabPosition = 0;
|
||||
_subTabPosition = 0;
|
||||
|
||||
SetTextImageIndex(1);
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton::~RadioButton()
|
||||
{
|
||||
delete _radioBoxImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Apply resource file scheme.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
_radioBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(150, 150, 150, 0), pScheme);
|
||||
_radioBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 0), pScheme);
|
||||
_radioBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 0), pScheme);
|
||||
_radioBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 0), pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("RadioButton.TextColor", pScheme));
|
||||
_selectedFgColor = GetSchemeColor("RadioButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
|
||||
|
||||
SetDefaultColor( GetFgColor(), GetBgColor() );
|
||||
|
||||
SetArmedColor( GetSchemeColor("RadioButton.ArmedTextColor", pScheme), GetButtonArmedBgColor() );
|
||||
|
||||
SetContentAlignment(a_west);
|
||||
|
||||
// reloading the scheme wipes out lists of images
|
||||
_radioBoxImage->SetFont( pScheme->GetFont("Marlett", IsProportional()) );
|
||||
_radioBoxImage->ResizeImageToContent();
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
|
||||
// don't draw a background
|
||||
SetPaintBackgroundEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the border style of the button, Radio buttons have no border
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder *RadioButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tab position of the radio button with the set of radio buttons
|
||||
// A group of RadioButtons must have the same TabPosition, with [1, n] subtabpositions
|
||||
//-----------------------------------------------------------------------------
|
||||
int RadioButton::GetSubTabPosition()
|
||||
{
|
||||
return _subTabPosition;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tab position of the radio button with the set of radio buttons
|
||||
// A group of RadioButtons must have the same TabPosition, with [1, n] subtabpositions
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SetSubTabPosition(int position)
|
||||
{
|
||||
_subTabPosition = position;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return the RadioButton's real tab position (its Panel one changes)
|
||||
//-----------------------------------------------------------------------------
|
||||
int RadioButton::GetRadioTabPosition()
|
||||
{
|
||||
return _oldTabPosition;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the radio button checked. When a radio button is checked, a
|
||||
// message is sent to all other radio buttons in the same group so
|
||||
// they will become unchecked.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SetSelected(bool state)
|
||||
{
|
||||
InternalSetSelected( state, true );
|
||||
}
|
||||
|
||||
void RadioButton::InternalSetSelected(bool state, bool bFireEvents)
|
||||
{
|
||||
if (state == true)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
return;
|
||||
|
||||
// restore our tab position
|
||||
SetTabPosition(_oldTabPosition);
|
||||
|
||||
// Should we send notifications?
|
||||
if ( bFireEvents )
|
||||
{
|
||||
// send a message
|
||||
KeyValues *msg = new KeyValues("RadioButtonChecked");
|
||||
msg->SetPtr("panel", this);
|
||||
msg->SetInt("tabposition", _oldTabPosition);
|
||||
|
||||
// send a message to all other panels on the same level as heirarchy,
|
||||
// so that other radio buttons know to shut off
|
||||
VPANEL radioParent = GetVParent();
|
||||
if (radioParent)
|
||||
{
|
||||
for (int i = 0; i < ipanel()->GetChildCount(radioParent); i++)
|
||||
{
|
||||
VPANEL child = ipanel()->GetChild(radioParent, i);
|
||||
if (child != GetVPanel())
|
||||
{
|
||||
ivgui()->PostMessage(child, msg->MakeCopy(), GetVPanel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RequestFocus();
|
||||
PostActionSignal(msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove ourselves from the tab order
|
||||
if (GetTabPosition())
|
||||
{
|
||||
_oldTabPosition = GetTabPosition();
|
||||
}
|
||||
SetTabPosition(0);
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
|
||||
ToggleButton::SetSelected(state);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the selection state without firing any events
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::SilentSetSelected(bool state)
|
||||
{
|
||||
InternalSetSelected( state, false );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set up the text color before doing normal layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::PerformLayout()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
SetFgColor(_selectedFgColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFgColor(GetButtonFgColor());
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Apply resource settings including button state and text color.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
ToggleButton::ApplySettings(inResourceData);
|
||||
SetTextColorState(CS_NORMAL);
|
||||
|
||||
_subTabPosition = inResourceData->GetInt("SubTabPosition");
|
||||
_oldTabPosition = inResourceData->GetInt("TabPosition");
|
||||
SetImageAtIndex(0, _radioBoxImage, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get resource settings including button state, text color, and subTabPosition
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
ToggleButton::GetSettings(outResourceData);
|
||||
outResourceData->SetInt("SubTabPosition", _subTabPosition);
|
||||
outResourceData->SetInt("TabPosition", GetRadioTabPosition());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describe editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *RadioButton::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
Q_snprintf(buf, sizeof(buf), "%s, int SubTabPosition", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: When a radio button is checked, all other radio buttons
|
||||
// in the same group become unchecked.
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::OnRadioButtonChecked(int tabPosition)
|
||||
{
|
||||
// make sure we're in the same tab group
|
||||
if (tabPosition != _oldTabPosition)
|
||||
return;
|
||||
|
||||
// wouldn't be sent to us from ourselves, so another radio button has taken over
|
||||
SetSelected(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draws the selection rectangle
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::Paint()
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
/*
|
||||
if (HasFocus())
|
||||
{
|
||||
int tx0, ty0, tx1, ty1;
|
||||
_textImage->GetPos(tx0, ty0);
|
||||
_textImage->GetSize(tx1, ty1);
|
||||
DrawFocusBorder(tx0, ty0, tx0 + tx1, ty0 + ty1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::DoClick()
|
||||
{
|
||||
SetSelected(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handle arrow key movement
|
||||
//-----------------------------------------------------------------------------
|
||||
void RadioButton::OnKeyCodeTyped(KeyCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
case KEY_SPACE:
|
||||
{
|
||||
if (!IsSelected())
|
||||
{
|
||||
SetSelected(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Panel::OnKeyCodeTyped(code);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
RadioButton *bestRadio = FindBestRadioButton( DOWN );
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->SetSelected(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_LEFT:
|
||||
{
|
||||
RadioButton *bestRadio = FindBestRadioButton( UP );
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->SetSelected(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BaseClass::OnKeyCodeTyped(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Find the correct radio button to move to.
|
||||
// Input : direction - the direction we are moving, up or down.
|
||||
//-----------------------------------------------------------------------------
|
||||
RadioButton *RadioButton::FindBestRadioButton(int direction)
|
||||
{
|
||||
RadioButton *bestRadio = NULL;
|
||||
int highestRadio = 0;
|
||||
Panel *pr = GetParent();
|
||||
if (pr)
|
||||
{
|
||||
// find the radio button to go to next
|
||||
for (int i = 0; i < pr->GetChildCount(); i++)
|
||||
{
|
||||
RadioButton *child = dynamic_cast<RadioButton *>(pr->GetChild(i));
|
||||
if (child && child->GetRadioTabPosition() == _oldTabPosition)
|
||||
{
|
||||
if (child->GetSubTabPosition() == _subTabPosition + direction)
|
||||
{
|
||||
bestRadio = child;
|
||||
break;
|
||||
}
|
||||
if ( (child->GetSubTabPosition() == 0) && (direction == DOWN) )
|
||||
{
|
||||
bestRadio = child;
|
||||
continue;
|
||||
}
|
||||
else if ( (child->GetSubTabPosition() > highestRadio) && (direction == UP) )
|
||||
{
|
||||
bestRadio = child;
|
||||
highestRadio = bestRadio->GetSubTabPosition();
|
||||
continue;
|
||||
}
|
||||
if (!bestRadio)
|
||||
{
|
||||
bestRadio = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestRadio)
|
||||
{
|
||||
bestRadio->RequestFocus();
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
return bestRadio;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,200 +1,200 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/RotatingProgressBar.h>
|
||||
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( RotatingProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RotatingProgressBar::RotatingProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_flStartRadians = 0;
|
||||
m_flEndRadians = 0;
|
||||
m_flLastAngle = 0;
|
||||
|
||||
m_nTextureId = -1;
|
||||
m_pszImageName = NULL;
|
||||
|
||||
m_flTickDelay = 30;
|
||||
|
||||
ivgui()->AddTickSignal(GetVPanel(), m_flTickDelay );
|
||||
|
||||
SetPaintBorderEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RotatingProgressBar::~RotatingProgressBar()
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId );
|
||||
m_nTextureId = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetImage( imageName );
|
||||
}
|
||||
|
||||
// Find min and max rotations in radians
|
||||
m_flStartRadians = DEG2RAD(inResourceData->GetFloat( "start_degrees", 0 ) );
|
||||
m_flEndRadians = DEG2RAD( inResourceData->GetFloat( "end_degrees", 0 ) );
|
||||
|
||||
// Start at 0 progress
|
||||
m_flLastAngle = m_flStartRadians;
|
||||
|
||||
// approach speed is specified in degrees per second.
|
||||
// convert to radians per 1/30th of a second
|
||||
float flDegressPerSecond = DEG2RAD( inResourceData->GetFloat( "approach_speed", 360.0 ) ); // default is super fast
|
||||
m_flApproachSpeed = flDegressPerSecond * ( m_flTickDelay / 1000.0f ); // divide by number of frames in a second
|
||||
|
||||
m_flRotOriginX = inResourceData->GetFloat( "rot_origin_x_percent", 0.5f );
|
||||
m_flRotOriginY = inResourceData->GetFloat( "rot_origin_y_percent", 0.5f );
|
||||
|
||||
m_flRotatingX = inResourceData->GetFloat( "rotating_x", 0 );
|
||||
m_flRotatingY = inResourceData->GetFloat( "rotating_y", 0 );
|
||||
m_flRotatingWide = inResourceData->GetFloat( "rotating_wide", 0 );
|
||||
m_flRotatingTall = inResourceData->GetFloat( "rotating_tall", 0 );
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
if ( m_pszImageName && strlen( m_pszImageName ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId == -1 )
|
||||
{
|
||||
m_nTextureId = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId, m_pszImageName, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::SetImage(const char *imageName)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_snprintf( m_pszImageName, len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::PaintBackground()
|
||||
{
|
||||
// No background
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Update event when we aren't drawing so we don't get huge sweeps
|
||||
// when we start drawing it
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::OnTick( void )
|
||||
{
|
||||
float flDesiredAngle = RemapVal( GetProgress(), 0.0, 1.0, m_flStartRadians, m_flEndRadians );
|
||||
m_flLastAngle = Approach( flDesiredAngle, m_flLastAngle, m_flApproachSpeed );
|
||||
|
||||
BaseClass::OnTick();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::Paint()
|
||||
{
|
||||
// we have an image that we rotate based on the progress,
|
||||
// where '0' is not rotated,'90' is rotated 90 degrees to the right.
|
||||
// Image is rotated around its center.
|
||||
|
||||
// desired rotation is GetProgress() ( 0.0 -> 1.0 ) mapped into
|
||||
// ( m_flStartDegrees -> m_flEndDegrees )
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId );
|
||||
vgui::surface()->DrawSetColor( Color(255,255,255,255) );
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
float mid_x = m_flRotatingX + m_flRotOriginX * m_flRotatingWide;
|
||||
float mid_y = m_flRotatingY + m_flRotOriginY * m_flRotatingTall;
|
||||
|
||||
Vertex_t vert[4];
|
||||
|
||||
vert[0].Init( Vector2D( m_flRotatingX, m_flRotatingY ), Vector2D(0,0) );
|
||||
vert[1].Init( Vector2D( m_flRotatingX+m_flRotatingWide, m_flRotatingY ), Vector2D(1,0) );
|
||||
vert[2].Init( Vector2D( m_flRotatingX+m_flRotatingWide, m_flRotatingY+m_flRotatingTall ), Vector2D(1,1) );
|
||||
vert[3].Init( Vector2D( m_flRotatingX, m_flRotatingY+m_flRotatingTall ), Vector2D(0,1) );
|
||||
|
||||
float flCosA = cos(m_flLastAngle);
|
||||
float flSinA = sin(m_flLastAngle);
|
||||
|
||||
// rotate each point around (mid_x, mid_y) by flAngle radians
|
||||
for ( int i=0;i<4;i++ )
|
||||
{
|
||||
Vector2D result;
|
||||
|
||||
// subtract the (x,y) we're rotating around, we'll add it on at the end.
|
||||
vert[i].m_Position.x -= mid_x;
|
||||
vert[i].m_Position.y -= mid_y;
|
||||
|
||||
result.x = ( vert[i].m_Position.x * flCosA - vert[i].m_Position.y * flSinA ) + mid_x;
|
||||
result.y = ( vert[i].m_Position.x * flSinA + vert[i].m_Position.y * flCosA ) + mid_y;
|
||||
|
||||
vert[i].m_Position = result;
|
||||
}
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 4, vert );
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/RotatingProgressBar.h>
|
||||
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( RotatingProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RotatingProgressBar::RotatingProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_flStartRadians = 0;
|
||||
m_flEndRadians = 0;
|
||||
m_flLastAngle = 0;
|
||||
|
||||
m_nTextureId = -1;
|
||||
m_pszImageName = NULL;
|
||||
|
||||
m_flTickDelay = 30;
|
||||
|
||||
ivgui()->AddTickSignal(GetVPanel(), m_flTickDelay );
|
||||
|
||||
SetPaintBorderEnabled(false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
RotatingProgressBar::~RotatingProgressBar()
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId );
|
||||
m_nTextureId = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetImage( imageName );
|
||||
}
|
||||
|
||||
// Find min and max rotations in radians
|
||||
m_flStartRadians = DEG2RAD(inResourceData->GetFloat( "start_degrees", 0 ) );
|
||||
m_flEndRadians = DEG2RAD( inResourceData->GetFloat( "end_degrees", 0 ) );
|
||||
|
||||
// Start at 0 progress
|
||||
m_flLastAngle = m_flStartRadians;
|
||||
|
||||
// approach speed is specified in degrees per second.
|
||||
// convert to radians per 1/30th of a second
|
||||
float flDegressPerSecond = DEG2RAD( inResourceData->GetFloat( "approach_speed", 360.0 ) ); // default is super fast
|
||||
m_flApproachSpeed = flDegressPerSecond * ( m_flTickDelay / 1000.0f ); // divide by number of frames in a second
|
||||
|
||||
m_flRotOriginX = inResourceData->GetFloat( "rot_origin_x_percent", 0.5f );
|
||||
m_flRotOriginY = inResourceData->GetFloat( "rot_origin_y_percent", 0.5f );
|
||||
|
||||
m_flRotatingX = inResourceData->GetFloat( "rotating_x", 0 );
|
||||
m_flRotatingY = inResourceData->GetFloat( "rotating_y", 0 );
|
||||
m_flRotatingWide = inResourceData->GetFloat( "rotating_wide", 0 );
|
||||
m_flRotatingTall = inResourceData->GetFloat( "rotating_tall", 0 );
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
if ( m_pszImageName && strlen( m_pszImageName ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId == -1 )
|
||||
{
|
||||
m_nTextureId = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId, m_pszImageName, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::SetImage(const char *imageName)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_snprintf( m_pszImageName, len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::PaintBackground()
|
||||
{
|
||||
// No background
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Update event when we aren't drawing so we don't get huge sweeps
|
||||
// when we start drawing it
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::OnTick( void )
|
||||
{
|
||||
float flDesiredAngle = RemapVal( GetProgress(), 0.0, 1.0, m_flStartRadians, m_flEndRadians );
|
||||
m_flLastAngle = Approach( flDesiredAngle, m_flLastAngle, m_flApproachSpeed );
|
||||
|
||||
BaseClass::OnTick();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void RotatingProgressBar::Paint()
|
||||
{
|
||||
// we have an image that we rotate based on the progress,
|
||||
// where '0' is not rotated,'90' is rotated 90 degrees to the right.
|
||||
// Image is rotated around its center.
|
||||
|
||||
// desired rotation is GetProgress() ( 0.0 -> 1.0 ) mapped into
|
||||
// ( m_flStartDegrees -> m_flEndDegrees )
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId );
|
||||
vgui::surface()->DrawSetColor( Color(255,255,255,255) );
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
float mid_x = m_flRotatingX + m_flRotOriginX * m_flRotatingWide;
|
||||
float mid_y = m_flRotatingY + m_flRotOriginY * m_flRotatingTall;
|
||||
|
||||
Vertex_t vert[4];
|
||||
|
||||
vert[0].Init( Vector2D( m_flRotatingX, m_flRotatingY ), Vector2D(0,0) );
|
||||
vert[1].Init( Vector2D( m_flRotatingX+m_flRotatingWide, m_flRotatingY ), Vector2D(1,0) );
|
||||
vert[2].Init( Vector2D( m_flRotatingX+m_flRotatingWide, m_flRotatingY+m_flRotatingTall ), Vector2D(1,1) );
|
||||
vert[3].Init( Vector2D( m_flRotatingX, m_flRotatingY+m_flRotatingTall ), Vector2D(0,1) );
|
||||
|
||||
float flCosA = cos(m_flLastAngle);
|
||||
float flSinA = sin(m_flLastAngle);
|
||||
|
||||
// rotate each point around (mid_x, mid_y) by flAngle radians
|
||||
for ( int i=0;i<4;i++ )
|
||||
{
|
||||
Vector2D result;
|
||||
|
||||
// subtract the (x,y) we're rotating around, we'll add it on at the end.
|
||||
vert[i].m_Position.x -= mid_x;
|
||||
vert[i].m_Position.y -= mid_y;
|
||||
|
||||
result.x = ( vert[i].m_Position.x * flCosA - vert[i].m_Position.y * flSinA ) + mid_x;
|
||||
result.y = ( vert[i].m_Position.x * flSinA + vert[i].m_Position.y * flCosA ) + mid_y;
|
||||
|
||||
vert[i].m_Position = result;
|
||||
}
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 4, vert );
|
||||
}
|
||||
@@ -1,266 +1,266 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/ScalableImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ScalableImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImagePanel::ScalableImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_iSrcCornerHeight = 0;
|
||||
m_iSrcCornerWidth = 0;
|
||||
|
||||
m_iCornerHeight = 0;
|
||||
m_iCornerWidth = 0;
|
||||
|
||||
m_pszImageName = NULL;
|
||||
m_pszDrawColorName = NULL;
|
||||
|
||||
m_DrawColor = Color(255,255,255,255);
|
||||
|
||||
m_flCornerWidthPercent = 0;
|
||||
m_flCornerHeightPercent = 0;
|
||||
|
||||
m_iTextureID = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImagePanel::~ScalableImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszDrawColorName;
|
||||
|
||||
if ( vgui::surface() && m_iTextureID != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_iTextureID );
|
||||
m_iTextureID = -1;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::SetImage(const char *imageName)
|
||||
{
|
||||
if ( *imageName )
|
||||
{
|
||||
char szImage[MAX_PATH];
|
||||
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
Q_snprintf( szImage, len, "%s%s", pszDir, imageName );
|
||||
|
||||
if ( m_pszImageName && V_stricmp( szImage, m_pszImageName ) == 0 )
|
||||
return;
|
||||
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_strncpy(m_pszImageName, szImage, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::PaintBackground()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor( m_DrawColor.r(), m_DrawColor.g(), m_DrawColor.b(), GetAlpha() );
|
||||
surface()->DrawSetTexture( m_iTextureID );
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
float uvx = 0;
|
||||
float uvy = 0;
|
||||
float uvw = 0, uvh = 0;
|
||||
|
||||
float drawW, drawH;
|
||||
|
||||
int row, col;
|
||||
for ( row=0;row<3;row++ )
|
||||
{
|
||||
x = 0;
|
||||
uvx = 0;
|
||||
|
||||
if ( row == 0 || row == 2 )
|
||||
{
|
||||
//uvh - row 0 or 2, is src_corner_height
|
||||
uvh = m_flCornerHeightPercent;
|
||||
drawH = m_iCornerHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvh - row 1, is tall - ( 2 * src_corner_height ) ( min 0 )
|
||||
uvh = max( 1.0 - 2 * m_flCornerHeightPercent, 0.0f );
|
||||
drawH = max( 0, ( tall - 2 * m_iCornerHeight ) );
|
||||
}
|
||||
|
||||
for ( col=0;col<3;col++ )
|
||||
{
|
||||
if ( col == 0 || col == 2 )
|
||||
{
|
||||
//uvw - col 0 or 2, is src_corner_width
|
||||
uvw = m_flCornerWidthPercent;
|
||||
drawW = m_iCornerWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvw - col 1, is wide - ( 2 * src_corner_width ) ( min 0 )
|
||||
uvw = max( 1.0 - 2 * m_flCornerWidthPercent, 0.0f );
|
||||
drawW = max( 0, ( wide - 2 * m_iCornerWidth ) );
|
||||
}
|
||||
|
||||
Vector2D uv11( uvx, uvy );
|
||||
Vector2D uv21( uvx+uvw, uvy );
|
||||
Vector2D uv22( uvx+uvw, uvy+uvh );
|
||||
Vector2D uv12( uvx, uvy+uvh );
|
||||
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].Init( Vector2D( x, y ), uv11 );
|
||||
verts[1].Init( Vector2D( x+drawW, y ), uv21 );
|
||||
verts[2].Init( Vector2D( x+drawW, y+drawH ), uv22 );
|
||||
verts[3].Init( Vector2D( x, y+drawH ), uv12 );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 4, verts );
|
||||
|
||||
x += drawW;
|
||||
uvx += uvw;
|
||||
}
|
||||
|
||||
y += drawH;
|
||||
uvy += uvh;
|
||||
}
|
||||
|
||||
vgui::surface()->DrawSetTexture(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
if (m_pszDrawColorName)
|
||||
{
|
||||
outResourceData->SetString("drawcolor", m_pszDrawColorName);
|
||||
}
|
||||
|
||||
outResourceData->SetInt("src_corner_height", m_iSrcCornerHeight);
|
||||
outResourceData->SetInt("src_corner_width", m_iSrcCornerWidth);
|
||||
|
||||
outResourceData->SetInt("draw_corner_height", m_iCornerHeight);
|
||||
outResourceData->SetInt("draw_corner_width", m_iCornerWidth);
|
||||
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
delete [] m_pszDrawColorName;
|
||||
m_pszDrawColorName = NULL;
|
||||
|
||||
const char *pszDrawColor = inResourceData->GetString("drawcolor", "");
|
||||
if (*pszDrawColor)
|
||||
{
|
||||
int r = 0, g = 0, b = 0, a = 255;
|
||||
int len = Q_strlen(pszDrawColor) + 1;
|
||||
m_pszDrawColorName = new char[ len ];
|
||||
Q_strncpy( m_pszDrawColorName, pszDrawColor, len );
|
||||
|
||||
if (sscanf(pszDrawColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_DrawColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_DrawColor = pScheme->GetColor(pszDrawColor, Color(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
m_iSrcCornerHeight = inResourceData->GetInt( "src_corner_height" );
|
||||
m_iSrcCornerWidth = inResourceData->GetInt( "src_corner_width" );
|
||||
|
||||
m_iCornerHeight = inResourceData->GetInt( "draw_corner_height" );
|
||||
m_iCornerWidth = inResourceData->GetInt( "draw_corner_width" );
|
||||
|
||||
if ( IsProportional() )
|
||||
{
|
||||
// scale the x and y up to our screen co-ords
|
||||
m_iCornerHeight = scheme()->GetProportionalScaledValueEx(GetScheme(), m_iCornerHeight);
|
||||
m_iCornerWidth = scheme()->GetProportionalScaledValueEx(GetScheme(), m_iCornerWidth);
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
SetImage( imageName );
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void ScalableImagePanel::PerformLayout( void )
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
surface()->DrawSetTextureFile( m_iTextureID, m_pszImageName, true, false);
|
||||
}
|
||||
|
||||
// get image dimensions, compare to m_iSrcCornerHeight, m_iSrcCornerWidth
|
||||
int wide,tall;
|
||||
surface()->DrawGetTextureSize( m_iTextureID, wide, tall );
|
||||
|
||||
m_flCornerWidthPercent = ( wide > 0 ) ? ( (float)m_iSrcCornerWidth / (float)wide ) : 0;
|
||||
m_flCornerHeightPercent = ( tall > 0 ) ? ( (float)m_iSrcCornerHeight / (float)tall ) : 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ScalableImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s string image, int src_corner_height, int src_corner_width, int draw_corner_height, int draw_corner_width", BaseClass::GetDescription());
|
||||
return buf;
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include <vgui_controls/ScalableImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( ScalableImagePanel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImagePanel::ScalableImagePanel(Panel *parent, const char *name) : Panel(parent, name)
|
||||
{
|
||||
m_iSrcCornerHeight = 0;
|
||||
m_iSrcCornerWidth = 0;
|
||||
|
||||
m_iCornerHeight = 0;
|
||||
m_iCornerWidth = 0;
|
||||
|
||||
m_pszImageName = NULL;
|
||||
m_pszDrawColorName = NULL;
|
||||
|
||||
m_DrawColor = Color(255,255,255,255);
|
||||
|
||||
m_flCornerWidthPercent = 0;
|
||||
m_flCornerHeightPercent = 0;
|
||||
|
||||
m_iTextureID = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImagePanel::~ScalableImagePanel()
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
delete [] m_pszDrawColorName;
|
||||
|
||||
if ( vgui::surface() && m_iTextureID != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_iTextureID );
|
||||
m_iTextureID = -1;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::SetImage(const char *imageName)
|
||||
{
|
||||
if ( *imageName )
|
||||
{
|
||||
char szImage[MAX_PATH];
|
||||
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
Q_snprintf( szImage, len, "%s%s", pszDir, imageName );
|
||||
|
||||
if ( m_pszImageName && V_stricmp( szImage, m_pszImageName ) == 0 )
|
||||
return;
|
||||
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_strncpy(m_pszImageName, szImage, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::PaintBackground()
|
||||
{
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
surface()->DrawSetColor( m_DrawColor.r(), m_DrawColor.g(), m_DrawColor.b(), GetAlpha() );
|
||||
surface()->DrawSetTexture( m_iTextureID );
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
float uvx = 0;
|
||||
float uvy = 0;
|
||||
float uvw = 0, uvh = 0;
|
||||
|
||||
float drawW, drawH;
|
||||
|
||||
int row, col;
|
||||
for ( row=0;row<3;row++ )
|
||||
{
|
||||
x = 0;
|
||||
uvx = 0;
|
||||
|
||||
if ( row == 0 || row == 2 )
|
||||
{
|
||||
//uvh - row 0 or 2, is src_corner_height
|
||||
uvh = m_flCornerHeightPercent;
|
||||
drawH = m_iCornerHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvh - row 1, is tall - ( 2 * src_corner_height ) ( min 0 )
|
||||
uvh = max( 1.0 - 2 * m_flCornerHeightPercent, 0.0f );
|
||||
drawH = max( 0, ( tall - 2 * m_iCornerHeight ) );
|
||||
}
|
||||
|
||||
for ( col=0;col<3;col++ )
|
||||
{
|
||||
if ( col == 0 || col == 2 )
|
||||
{
|
||||
//uvw - col 0 or 2, is src_corner_width
|
||||
uvw = m_flCornerWidthPercent;
|
||||
drawW = m_iCornerWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvw - col 1, is wide - ( 2 * src_corner_width ) ( min 0 )
|
||||
uvw = max( 1.0 - 2 * m_flCornerWidthPercent, 0.0f );
|
||||
drawW = max( 0, ( wide - 2 * m_iCornerWidth ) );
|
||||
}
|
||||
|
||||
Vector2D uv11( uvx, uvy );
|
||||
Vector2D uv21( uvx+uvw, uvy );
|
||||
Vector2D uv22( uvx+uvw, uvy+uvh );
|
||||
Vector2D uv12( uvx, uvy+uvh );
|
||||
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].Init( Vector2D( x, y ), uv11 );
|
||||
verts[1].Init( Vector2D( x+drawW, y ), uv21 );
|
||||
verts[2].Init( Vector2D( x+drawW, y+drawH ), uv22 );
|
||||
verts[3].Init( Vector2D( x, y+drawH ), uv12 );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 4, verts );
|
||||
|
||||
x += drawW;
|
||||
uvx += uvw;
|
||||
}
|
||||
|
||||
y += drawH;
|
||||
uvy += uvh;
|
||||
}
|
||||
|
||||
vgui::surface()->DrawSetTexture(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets control settings for editing
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::GetSettings(KeyValues *outResourceData)
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
if (m_pszDrawColorName)
|
||||
{
|
||||
outResourceData->SetString("drawcolor", m_pszDrawColorName);
|
||||
}
|
||||
|
||||
outResourceData->SetInt("src_corner_height", m_iSrcCornerHeight);
|
||||
outResourceData->SetInt("src_corner_width", m_iSrcCornerWidth);
|
||||
|
||||
outResourceData->SetInt("draw_corner_height", m_iCornerHeight);
|
||||
outResourceData->SetInt("draw_corner_width", m_iCornerWidth);
|
||||
|
||||
if (m_pszImageName)
|
||||
{
|
||||
outResourceData->SetString("image", m_pszImageName);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies designer settings from res file
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImagePanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
delete [] m_pszDrawColorName;
|
||||
m_pszDrawColorName = NULL;
|
||||
|
||||
const char *pszDrawColor = inResourceData->GetString("drawcolor", "");
|
||||
if (*pszDrawColor)
|
||||
{
|
||||
int r = 0, g = 0, b = 0, a = 255;
|
||||
int len = Q_strlen(pszDrawColor) + 1;
|
||||
m_pszDrawColorName = new char[ len ];
|
||||
Q_strncpy( m_pszDrawColorName, pszDrawColor, len );
|
||||
|
||||
if (sscanf(pszDrawColor, "%d %d %d %d", &r, &g, &b, &a) >= 3)
|
||||
{
|
||||
// it's a direct color
|
||||
m_DrawColor = Color(r, g, b, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
|
||||
m_DrawColor = pScheme->GetColor(pszDrawColor, Color(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
m_iSrcCornerHeight = inResourceData->GetInt( "src_corner_height" );
|
||||
m_iSrcCornerWidth = inResourceData->GetInt( "src_corner_width" );
|
||||
|
||||
m_iCornerHeight = inResourceData->GetInt( "draw_corner_height" );
|
||||
m_iCornerWidth = inResourceData->GetInt( "draw_corner_width" );
|
||||
|
||||
if ( IsProportional() )
|
||||
{
|
||||
// scale the x and y up to our screen co-ords
|
||||
m_iCornerHeight = scheme()->GetProportionalScaledValueEx(GetScheme(), m_iCornerHeight);
|
||||
m_iCornerWidth = scheme()->GetProportionalScaledValueEx(GetScheme(), m_iCornerWidth);
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
SetImage( imageName );
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void ScalableImagePanel::PerformLayout( void )
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
surface()->DrawSetTextureFile( m_iTextureID, m_pszImageName, true, false);
|
||||
}
|
||||
|
||||
// get image dimensions, compare to m_iSrcCornerHeight, m_iSrcCornerWidth
|
||||
int wide,tall;
|
||||
surface()->DrawGetTextureSize( m_iTextureID, wide, tall );
|
||||
|
||||
m_flCornerWidthPercent = ( wide > 0 ) ? ( (float)m_iSrcCornerWidth / (float)wide ) : 0;
|
||||
m_flCornerHeightPercent = ( tall > 0 ) ? ( (float)m_iSrcCornerHeight / (float)tall ) : 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Describes editing details
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ScalableImagePanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s string image, int src_corner_height, int src_corner_width, int draw_corner_height, int draw_corner_width", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,86 +1,86 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/ScrollableEditablePanel.h"
|
||||
#include "vgui_controls/ScrollBar.h"
|
||||
#include "vgui_controls/ScrollBarSlider.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
ScrollableEditablePanel::ScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
|
||||
BaseClass( pParent, pName )
|
||||
{
|
||||
m_pChild = pChild;
|
||||
m_pChild->SetParent( this );
|
||||
|
||||
m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
|
||||
m_pScrollBar->SetWide( 16 );
|
||||
m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
|
||||
m_pScrollBar->AddActionSignalTarget( this );
|
||||
}
|
||||
|
||||
void ScrollableEditablePanel::ApplySettings( KeyValues *pInResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( pInResourceData );
|
||||
|
||||
KeyValues *pScrollbarKV = pInResourceData->FindKey( "Scrollbar" );
|
||||
if ( pScrollbarKV )
|
||||
{
|
||||
m_pScrollBar->ApplySettings( pScrollbarKV );
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollableEditablePanel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
m_pChild->SetWide( GetWide() - m_pScrollBar->GetWide() );
|
||||
m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
|
||||
m_pScrollBar->SetRangeWindow( GetTall() );
|
||||
|
||||
if ( m_pScrollBar->GetSlider() )
|
||||
{
|
||||
m_pScrollBar->GetSlider()->SetFgColor( GetFgColor() );
|
||||
}
|
||||
if ( m_pScrollBar->GetButton(0) )
|
||||
{
|
||||
m_pScrollBar->GetButton(0)->SetFgColor( GetFgColor() );
|
||||
}
|
||||
if ( m_pScrollBar->GetButton(1) )
|
||||
{
|
||||
m_pScrollBar->GetButton(1)->SetFgColor( GetFgColor() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the scroll bar moves
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScrollableEditablePanel::OnScrollBarSliderMoved()
|
||||
{
|
||||
InvalidateLayout();
|
||||
|
||||
int nScrollAmount = m_pScrollBar->GetValue();
|
||||
m_pChild->SetPos( 0, -nScrollAmount );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// respond to mouse wheel events
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScrollableEditablePanel::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_pScrollBar->GetValue();
|
||||
val -= (delta * 50);
|
||||
m_pScrollBar->SetValue( val );
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/ScrollableEditablePanel.h"
|
||||
#include "vgui_controls/ScrollBar.h"
|
||||
#include "vgui_controls/ScrollBarSlider.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
ScrollableEditablePanel::ScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
|
||||
BaseClass( pParent, pName )
|
||||
{
|
||||
m_pChild = pChild;
|
||||
m_pChild->SetParent( this );
|
||||
|
||||
m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
|
||||
m_pScrollBar->SetWide( 16 );
|
||||
m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
|
||||
m_pScrollBar->AddActionSignalTarget( this );
|
||||
}
|
||||
|
||||
void ScrollableEditablePanel::ApplySettings( KeyValues *pInResourceData )
|
||||
{
|
||||
BaseClass::ApplySettings( pInResourceData );
|
||||
|
||||
KeyValues *pScrollbarKV = pInResourceData->FindKey( "Scrollbar" );
|
||||
if ( pScrollbarKV )
|
||||
{
|
||||
m_pScrollBar->ApplySettings( pScrollbarKV );
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollableEditablePanel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
m_pChild->SetWide( GetWide() - m_pScrollBar->GetWide() );
|
||||
m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
|
||||
m_pScrollBar->SetRangeWindow( GetTall() );
|
||||
|
||||
if ( m_pScrollBar->GetSlider() )
|
||||
{
|
||||
m_pScrollBar->GetSlider()->SetFgColor( GetFgColor() );
|
||||
}
|
||||
if ( m_pScrollBar->GetButton(0) )
|
||||
{
|
||||
m_pScrollBar->GetButton(0)->SetFgColor( GetFgColor() );
|
||||
}
|
||||
if ( m_pScrollBar->GetButton(1) )
|
||||
{
|
||||
m_pScrollBar->GetButton(1)->SetFgColor( GetFgColor() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the scroll bar moves
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScrollableEditablePanel::OnScrollBarSliderMoved()
|
||||
{
|
||||
InvalidateLayout();
|
||||
|
||||
int nScrollAmount = m_pScrollBar->GetValue();
|
||||
m_pChild->SetPos( 0, -nScrollAmount );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// respond to mouse wheel events
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScrollableEditablePanel::OnMouseWheeled(int delta)
|
||||
{
|
||||
int val = m_pScrollBar->GetValue();
|
||||
val -= (delta * 50);
|
||||
m_pScrollBar->SetValue( val );
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,102 +1,102 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
#include <vgui_controls/ToggleButton.h>
|
||||
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( ToggleButton, ToggleButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToggleButton::ToggleButton(Panel *parent, const char *panelName, const char* text) : Button(parent, panelName, text)
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Turns double-click into normal click
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::OnMouseDoublePressed(MouseCode code)
|
||||
{
|
||||
OnMousePressed(code);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ToggleButton::GetButtonFgColor()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
// highlight the text when depressed
|
||||
return _selectedColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ToggleButton::CanBeDefaultButton(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles the state of the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::DoClick()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
ForceDepressed(false);
|
||||
}
|
||||
else if (!IsSelected())
|
||||
{
|
||||
ForceDepressed(true);
|
||||
}
|
||||
|
||||
SetSelected(!IsSelected());
|
||||
FireActionSignal();
|
||||
|
||||
// post a button toggled message
|
||||
KeyValues *msg = new KeyValues("ButtonToggled");
|
||||
msg->SetInt("state", (int)IsSelected());
|
||||
PostActionSignal(msg);
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
_selectedColor = GetSchemeColor("ToggleButton.SelectedTextColor", pScheme);
|
||||
}
|
||||
|
||||
void ToggleButton::OnKeyCodePressed(KeyCode code)
|
||||
{
|
||||
if (code != KEY_ENTER)
|
||||
{
|
||||
BaseClass::OnKeyCodePressed(code);
|
||||
}
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
#include <vgui_controls/ToggleButton.h>
|
||||
|
||||
#include <KeyValues.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY_DEFAULT_TEXT( ToggleButton, ToggleButton );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToggleButton::ToggleButton(Panel *parent, const char *panelName, const char* text) : Button(parent, panelName, text)
|
||||
{
|
||||
SetButtonActivationType(ACTIVATE_ONPRESSED);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Turns double-click into normal click
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::OnMouseDoublePressed(MouseCode code)
|
||||
{
|
||||
OnMousePressed(code);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
Color ToggleButton::GetButtonFgColor()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
// highlight the text when depressed
|
||||
return _selectedColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BaseClass::GetButtonFgColor();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ToggleButton::CanBeDefaultButton(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Toggles the state of the button
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::DoClick()
|
||||
{
|
||||
if (IsSelected())
|
||||
{
|
||||
ForceDepressed(false);
|
||||
}
|
||||
else if (!IsSelected())
|
||||
{
|
||||
ForceDepressed(true);
|
||||
}
|
||||
|
||||
SetSelected(!IsSelected());
|
||||
FireActionSignal();
|
||||
|
||||
// post a button toggled message
|
||||
KeyValues *msg = new KeyValues("ButtonToggled");
|
||||
msg->SetInt("state", (int)IsSelected());
|
||||
PostActionSignal(msg);
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToggleButton::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
_selectedColor = GetSchemeColor("ToggleButton.SelectedTextColor", pScheme);
|
||||
}
|
||||
|
||||
void ToggleButton::OnKeyCodePressed(KeyCode code)
|
||||
{
|
||||
if (code != KEY_ENTER)
|
||||
{
|
||||
BaseClass::OnKeyCodePressed(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,478 +1,478 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include <vgui_controls/ToolWindow.h>
|
||||
#include <vgui_controls/PropertySheet.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
CUtlVector< ToolWindow * > ToolWindow::s_ToolWindows;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
int ToolWindow::GetToolWindowCount()
|
||||
{
|
||||
return s_ToolWindows.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : index -
|
||||
// Output : PropertySheet
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow *ToolWindow::GetToolWindow( int index )
|
||||
{
|
||||
return s_ToolWindows[ index ];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow::ToolWindow(
|
||||
Panel *parent,
|
||||
bool contextlabel,
|
||||
IToolWindowFactory *factory /*= 0*/,
|
||||
Panel *page /*= NULL*/,
|
||||
char const *title /*= NULL */,
|
||||
bool contextMenu /*=false*/,
|
||||
bool inGlobalList /*= true*/ ) : BaseClass( parent, "ToolWindow" ),
|
||||
m_pFactory( factory )
|
||||
{
|
||||
if ( inGlobalList )
|
||||
{
|
||||
s_ToolWindows.AddToTail( this );
|
||||
}
|
||||
|
||||
// create the property sheet
|
||||
m_pPropertySheet = new PropertySheet(this, "ToolWindowSheet", true );
|
||||
m_pPropertySheet->ShowContextButtons( contextlabel );
|
||||
m_pPropertySheet->AddPage( page, title, 0, contextMenu );
|
||||
m_pPropertySheet->AddActionSignalTarget(this);
|
||||
m_pPropertySheet->SetSmallTabs( true );
|
||||
m_pPropertySheet->SetKBNavigationEnabled( false );
|
||||
|
||||
SetSmallCaption( true );
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(true);
|
||||
SetMoveable( true );
|
||||
SetSizeable(true);
|
||||
|
||||
SetClipToParent( false );
|
||||
SetVisible( true );
|
||||
|
||||
SetDeleteSelfOnClose( true );
|
||||
|
||||
SetTitle( "", false );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow::~ToolWindow()
|
||||
{
|
||||
// These don't actually kill the children of the property sheet
|
||||
m_pPropertySheet->RemoveAllPages();
|
||||
|
||||
s_ToolWindows.FindAndRemove( this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Pass through to sheet
|
||||
// Input : -
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ToolWindow::IsDraggableTabContainer() const
|
||||
{
|
||||
return m_pPropertySheet->IsDraggableTab();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a pointer to the PropertySheet this dialog encapsulates
|
||||
// Output : PropertySheet *
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertySheet *ToolWindow::GetPropertySheet()
|
||||
{
|
||||
return m_pPropertySheet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a pointer to the currently active page.
|
||||
// Output : Panel
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *ToolWindow::GetActivePage()
|
||||
{
|
||||
return m_pPropertySheet->GetActivePage();
|
||||
}
|
||||
|
||||
void ToolWindow::SetActivePage( Panel *page )
|
||||
{
|
||||
m_pPropertySheet->SetActivePage( page );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Wrapped function
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::AddPage(Panel *page, const char *title, bool contextMenu)
|
||||
{
|
||||
m_pPropertySheet->AddPage(page, title, 0, contextMenu );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *page -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::RemovePage( Panel *page )
|
||||
{
|
||||
m_pPropertySheet->RemovePage( page );
|
||||
if ( m_pPropertySheet->GetNumPages() == 0 )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets up the sheet
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
m_pPropertySheet->SetBounds(x, y, wide, tall);
|
||||
m_pPropertySheet->InvalidateLayout(); // tell the propertysheet to redraw!
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Overrides build mode so it edits the sub panel
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::ActivateBuildMode()
|
||||
{
|
||||
// no subpanel, no build mode
|
||||
EditablePanel *panel = dynamic_cast<EditablePanel *>(GetActivePage());
|
||||
if (!panel)
|
||||
return;
|
||||
|
||||
panel->ActivateBuildMode();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::RequestFocus(int direction)
|
||||
{
|
||||
m_pPropertySheet->RequestFocus(direction);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *factory -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::SetToolWindowFactory( IToolWindowFactory *factory )
|
||||
{
|
||||
m_pFactory = factory;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output : IToolWindowFactory
|
||||
//-----------------------------------------------------------------------------
|
||||
IToolWindowFactory *ToolWindow::GetToolWindowFactory()
|
||||
{
|
||||
return m_pFactory;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: To fill the space left by other tool windows
|
||||
// Input : edge: 0=all, 1=top, 2=right, 3=bottom, 4=left
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::Grow( int edge, int from_x, int from_y )
|
||||
{
|
||||
int status_h = 24;
|
||||
int menubar_h = 27;
|
||||
|
||||
int sw, sh;
|
||||
surface()->GetScreenSize( sw, sh );
|
||||
|
||||
int old_x, old_y, old_w, old_h;
|
||||
GetBounds( old_x, old_y, old_w, old_h );
|
||||
|
||||
int new_x, new_y, new_w, new_h;
|
||||
new_x = old_x;
|
||||
new_y = old_y;
|
||||
new_w = old_w;
|
||||
new_h = old_h;
|
||||
|
||||
int c = GetToolWindowCount();
|
||||
|
||||
// grow up
|
||||
if ( ( edge == 0 ) || ( edge == 1 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_y >= 0 )
|
||||
{
|
||||
old_h = old_h - ( from_y - old_y );
|
||||
old_y = from_y;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_h = old_h + ( old_y - menubar_h );
|
||||
new_y = menubar_h;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_x > x ) && ( old_x < x + w ) )
|
||||
|| ( ( old_x + old_w > x ) && ( old_x + old_w < x + w ) )
|
||||
|| ( ( old_x <= x ) && old_x + old_w >= x + w ))
|
||||
&& ( ( old_y >= y + h ) && ( new_y < y + h ) ) )
|
||||
{
|
||||
new_h = old_h + ( old_y - ( y + h ) );
|
||||
new_y = y + h;
|
||||
}
|
||||
}
|
||||
old_h = new_h;
|
||||
old_y = new_y;
|
||||
}
|
||||
|
||||
// grow right
|
||||
if ( ( edge == 0 ) || ( edge == 2 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_x >= 0 )
|
||||
{
|
||||
old_w = from_x - old_x;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_w = sw - old_x;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_y > y ) && ( old_y < y + h ) )
|
||||
|| ( ( old_y + old_h > y ) && ( old_y + old_h < y + h ) )
|
||||
|| ( ( old_y <= y ) && old_y + old_h >= y + h ))
|
||||
&& ( ( old_x + old_w <= x ) && ( new_w > x - old_x ) ) )
|
||||
{
|
||||
new_w = x - old_x;
|
||||
}
|
||||
}
|
||||
old_w = new_w;
|
||||
}
|
||||
|
||||
// grow down
|
||||
if ( ( edge == 0 ) || ( edge == 3 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_y >= 0 )
|
||||
{
|
||||
old_h = from_y - old_y;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_h = sh - old_y - status_h;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_x > x ) && ( old_x < x + w ) )
|
||||
|| ( ( old_x + old_w > x ) && ( old_x + old_w < x + w ) )
|
||||
|| ( ( old_x <= x ) && old_x + old_w >= x + w ))
|
||||
&& ( ( old_y + old_h <= y ) && ( new_h > y - old_y ) ) )
|
||||
{
|
||||
new_h = y - old_y;
|
||||
}
|
||||
}
|
||||
old_h = new_h;
|
||||
}
|
||||
|
||||
// grow left
|
||||
if ( ( edge == 0 ) || ( edge == 4 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_x >= 0 )
|
||||
{
|
||||
old_w = old_w - ( from_x - old_x );
|
||||
old_x = from_x;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_w = old_w + old_x;
|
||||
new_x = 0;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_y > y ) && ( old_y < y + h ) )
|
||||
|| ( ( old_y + old_h > y ) && ( old_y + old_h < y + h ) )
|
||||
|| ( ( old_y <= y ) && old_y + old_h >= y + h ))
|
||||
&& ( ( old_x >= x + w ) && ( new_x < x + w ) ) )
|
||||
{
|
||||
new_w = old_w + ( old_x - ( x + w ) );
|
||||
new_x = x + w;
|
||||
}
|
||||
}
|
||||
old_w = new_w;
|
||||
old_x = new_x;
|
||||
}
|
||||
|
||||
// Set panel bounds
|
||||
SetBounds( new_x, new_y, new_w, new_h );
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Calls Grow based on where the mouse is.
|
||||
// over titlebar: grows all edges ( from mouse pos )
|
||||
// over edge grab area: grows just that edge
|
||||
// over corner grab area: grows the two adjacent edges
|
||||
// Input :
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::GrowFromClick()
|
||||
{
|
||||
int mx, my;
|
||||
input()->GetCursorPos( mx, my );
|
||||
|
||||
int esz, csz, brsz, ch;
|
||||
esz = GetDraggerSize();
|
||||
csz = GetCornerSize();
|
||||
brsz = GetBottomRightSize();
|
||||
ch = GetCaptionHeight();
|
||||
|
||||
int x, y, w, h;
|
||||
GetBounds( x, y, w, h );
|
||||
|
||||
// upper right
|
||||
if ( ( mx > x+w-csz-1 ) && ( my < y+csz ) )
|
||||
{
|
||||
Grow(1);
|
||||
Grow(2);
|
||||
}
|
||||
// lower right (the big one)
|
||||
else if ( ( mx > x+w-brsz-1 ) && ( my > y+h-brsz-1 ) )
|
||||
{
|
||||
Grow(2);
|
||||
Grow(3);
|
||||
}
|
||||
// lower left
|
||||
else if ( ( mx < x+csz ) && ( my > y+h-csz-1 ) )
|
||||
{
|
||||
Grow(3);
|
||||
Grow(4);
|
||||
}
|
||||
// upper left
|
||||
else if ( ( mx < x+csz ) && ( my < y+csz ) )
|
||||
{
|
||||
Grow(4);
|
||||
Grow(1);
|
||||
}
|
||||
// top edge
|
||||
else if ( my < y+esz )
|
||||
{
|
||||
Grow(1);
|
||||
}
|
||||
// right edge
|
||||
else if ( mx > x+w-esz-1 )
|
||||
{
|
||||
Grow(2);
|
||||
}
|
||||
// bottom edge
|
||||
else if ( my > y+h-esz-1 )
|
||||
{
|
||||
Grow(3);
|
||||
}
|
||||
// left edge
|
||||
else if ( mx < x+esz )
|
||||
{
|
||||
Grow(4);
|
||||
}
|
||||
// otherwise (if over the grab bar), grow all edges (from the clicked point)
|
||||
else if ( my < y + ch )
|
||||
{
|
||||
Grow(0, mx, my);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::OnMouseDoublePressed( MouseCode code )
|
||||
{
|
||||
GrowFromClick();
|
||||
}
|
||||
|
||||
void ToolWindow::OnMousePressed( MouseCode code )
|
||||
{
|
||||
switch ( code )
|
||||
{
|
||||
case MOUSE_MIDDLE:
|
||||
GrowFromClick();
|
||||
break;
|
||||
default:
|
||||
BaseClass::OnMousePressed( code );
|
||||
}
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include <vgui_controls/ToolWindow.h>
|
||||
#include <vgui_controls/PropertySheet.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
CUtlVector< ToolWindow * > ToolWindow::s_ToolWindows;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
int ToolWindow::GetToolWindowCount()
|
||||
{
|
||||
return s_ToolWindows.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : index -
|
||||
// Output : PropertySheet
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow *ToolWindow::GetToolWindow( int index )
|
||||
{
|
||||
return s_ToolWindows[ index ];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow::ToolWindow(
|
||||
Panel *parent,
|
||||
bool contextlabel,
|
||||
IToolWindowFactory *factory /*= 0*/,
|
||||
Panel *page /*= NULL*/,
|
||||
char const *title /*= NULL */,
|
||||
bool contextMenu /*=false*/,
|
||||
bool inGlobalList /*= true*/ ) : BaseClass( parent, "ToolWindow" ),
|
||||
m_pFactory( factory )
|
||||
{
|
||||
if ( inGlobalList )
|
||||
{
|
||||
s_ToolWindows.AddToTail( this );
|
||||
}
|
||||
|
||||
// create the property sheet
|
||||
m_pPropertySheet = new PropertySheet(this, "ToolWindowSheet", true );
|
||||
m_pPropertySheet->ShowContextButtons( contextlabel );
|
||||
m_pPropertySheet->AddPage( page, title, 0, contextMenu );
|
||||
m_pPropertySheet->AddActionSignalTarget(this);
|
||||
m_pPropertySheet->SetSmallTabs( true );
|
||||
m_pPropertySheet->SetKBNavigationEnabled( false );
|
||||
|
||||
SetSmallCaption( true );
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(true);
|
||||
SetMoveable( true );
|
||||
SetSizeable(true);
|
||||
|
||||
SetClipToParent( false );
|
||||
SetVisible( true );
|
||||
|
||||
SetDeleteSelfOnClose( true );
|
||||
|
||||
SetTitle( "", false );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ToolWindow::~ToolWindow()
|
||||
{
|
||||
// These don't actually kill the children of the property sheet
|
||||
m_pPropertySheet->RemoveAllPages();
|
||||
|
||||
s_ToolWindows.FindAndRemove( this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Pass through to sheet
|
||||
// Input : -
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ToolWindow::IsDraggableTabContainer() const
|
||||
{
|
||||
return m_pPropertySheet->IsDraggableTab();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a pointer to the PropertySheet this dialog encapsulates
|
||||
// Output : PropertySheet *
|
||||
//-----------------------------------------------------------------------------
|
||||
PropertySheet *ToolWindow::GetPropertySheet()
|
||||
{
|
||||
return m_pPropertySheet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets a pointer to the currently active page.
|
||||
// Output : Panel
|
||||
//-----------------------------------------------------------------------------
|
||||
Panel *ToolWindow::GetActivePage()
|
||||
{
|
||||
return m_pPropertySheet->GetActivePage();
|
||||
}
|
||||
|
||||
void ToolWindow::SetActivePage( Panel *page )
|
||||
{
|
||||
m_pPropertySheet->SetActivePage( page );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Wrapped function
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::AddPage(Panel *page, const char *title, bool contextMenu)
|
||||
{
|
||||
m_pPropertySheet->AddPage(page, title, 0, contextMenu );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *page -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::RemovePage( Panel *page )
|
||||
{
|
||||
m_pPropertySheet->RemovePage( page );
|
||||
if ( m_pPropertySheet->GetNumPages() == 0 )
|
||||
{
|
||||
MarkForDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets up the sheet
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int x, y, wide, tall;
|
||||
GetClientArea(x, y, wide, tall);
|
||||
m_pPropertySheet->SetBounds(x, y, wide, tall);
|
||||
m_pPropertySheet->InvalidateLayout(); // tell the propertysheet to redraw!
|
||||
Repaint();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Overrides build mode so it edits the sub panel
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::ActivateBuildMode()
|
||||
{
|
||||
// no subpanel, no build mode
|
||||
EditablePanel *panel = dynamic_cast<EditablePanel *>(GetActivePage());
|
||||
if (!panel)
|
||||
return;
|
||||
|
||||
panel->ActivateBuildMode();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::RequestFocus(int direction)
|
||||
{
|
||||
m_pPropertySheet->RequestFocus(direction);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *factory -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ToolWindow::SetToolWindowFactory( IToolWindowFactory *factory )
|
||||
{
|
||||
m_pFactory = factory;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output : IToolWindowFactory
|
||||
//-----------------------------------------------------------------------------
|
||||
IToolWindowFactory *ToolWindow::GetToolWindowFactory()
|
||||
{
|
||||
return m_pFactory;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: To fill the space left by other tool windows
|
||||
// Input : edge: 0=all, 1=top, 2=right, 3=bottom, 4=left
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::Grow( int edge, int from_x, int from_y )
|
||||
{
|
||||
int status_h = 24;
|
||||
int menubar_h = 27;
|
||||
|
||||
int sw, sh;
|
||||
surface()->GetScreenSize( sw, sh );
|
||||
|
||||
int old_x, old_y, old_w, old_h;
|
||||
GetBounds( old_x, old_y, old_w, old_h );
|
||||
|
||||
int new_x, new_y, new_w, new_h;
|
||||
new_x = old_x;
|
||||
new_y = old_y;
|
||||
new_w = old_w;
|
||||
new_h = old_h;
|
||||
|
||||
int c = GetToolWindowCount();
|
||||
|
||||
// grow up
|
||||
if ( ( edge == 0 ) || ( edge == 1 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_y >= 0 )
|
||||
{
|
||||
old_h = old_h - ( from_y - old_y );
|
||||
old_y = from_y;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_h = old_h + ( old_y - menubar_h );
|
||||
new_y = menubar_h;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_x > x ) && ( old_x < x + w ) )
|
||||
|| ( ( old_x + old_w > x ) && ( old_x + old_w < x + w ) )
|
||||
|| ( ( old_x <= x ) && old_x + old_w >= x + w ))
|
||||
&& ( ( old_y >= y + h ) && ( new_y < y + h ) ) )
|
||||
{
|
||||
new_h = old_h + ( old_y - ( y + h ) );
|
||||
new_y = y + h;
|
||||
}
|
||||
}
|
||||
old_h = new_h;
|
||||
old_y = new_y;
|
||||
}
|
||||
|
||||
// grow right
|
||||
if ( ( edge == 0 ) || ( edge == 2 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_x >= 0 )
|
||||
{
|
||||
old_w = from_x - old_x;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_w = sw - old_x;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_y > y ) && ( old_y < y + h ) )
|
||||
|| ( ( old_y + old_h > y ) && ( old_y + old_h < y + h ) )
|
||||
|| ( ( old_y <= y ) && old_y + old_h >= y + h ))
|
||||
&& ( ( old_x + old_w <= x ) && ( new_w > x - old_x ) ) )
|
||||
{
|
||||
new_w = x - old_x;
|
||||
}
|
||||
}
|
||||
old_w = new_w;
|
||||
}
|
||||
|
||||
// grow down
|
||||
if ( ( edge == 0 ) || ( edge == 3 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_y >= 0 )
|
||||
{
|
||||
old_h = from_y - old_y;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_h = sh - old_y - status_h;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_x > x ) && ( old_x < x + w ) )
|
||||
|| ( ( old_x + old_w > x ) && ( old_x + old_w < x + w ) )
|
||||
|| ( ( old_x <= x ) && old_x + old_w >= x + w ))
|
||||
&& ( ( old_y + old_h <= y ) && ( new_h > y - old_y ) ) )
|
||||
{
|
||||
new_h = y - old_y;
|
||||
}
|
||||
}
|
||||
old_h = new_h;
|
||||
}
|
||||
|
||||
// grow left
|
||||
if ( ( edge == 0 ) || ( edge == 4 ) )
|
||||
{
|
||||
// first shrink the edge back to the grow point
|
||||
if ( from_x >= 0 )
|
||||
{
|
||||
old_w = old_w - ( from_x - old_x );
|
||||
old_x = from_x;
|
||||
}
|
||||
|
||||
// now grow the edge as far as it can go
|
||||
new_w = old_w + old_x;
|
||||
new_x = 0;
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( ( !tw ) || ( tw == this ) )
|
||||
continue;
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
// grow it
|
||||
if ( ( ( ( old_y > y ) && ( old_y < y + h ) )
|
||||
|| ( ( old_y + old_h > y ) && ( old_y + old_h < y + h ) )
|
||||
|| ( ( old_y <= y ) && old_y + old_h >= y + h ))
|
||||
&& ( ( old_x >= x + w ) && ( new_x < x + w ) ) )
|
||||
{
|
||||
new_w = old_w + ( old_x - ( x + w ) );
|
||||
new_x = x + w;
|
||||
}
|
||||
}
|
||||
old_w = new_w;
|
||||
old_x = new_x;
|
||||
}
|
||||
|
||||
// Set panel bounds
|
||||
SetBounds( new_x, new_y, new_w, new_h );
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Calls Grow based on where the mouse is.
|
||||
// over titlebar: grows all edges ( from mouse pos )
|
||||
// over edge grab area: grows just that edge
|
||||
// over corner grab area: grows the two adjacent edges
|
||||
// Input :
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::GrowFromClick()
|
||||
{
|
||||
int mx, my;
|
||||
input()->GetCursorPos( mx, my );
|
||||
|
||||
int esz, csz, brsz, ch;
|
||||
esz = GetDraggerSize();
|
||||
csz = GetCornerSize();
|
||||
brsz = GetBottomRightSize();
|
||||
ch = GetCaptionHeight();
|
||||
|
||||
int x, y, w, h;
|
||||
GetBounds( x, y, w, h );
|
||||
|
||||
// upper right
|
||||
if ( ( mx > x+w-csz-1 ) && ( my < y+csz ) )
|
||||
{
|
||||
Grow(1);
|
||||
Grow(2);
|
||||
}
|
||||
// lower right (the big one)
|
||||
else if ( ( mx > x+w-brsz-1 ) && ( my > y+h-brsz-1 ) )
|
||||
{
|
||||
Grow(2);
|
||||
Grow(3);
|
||||
}
|
||||
// lower left
|
||||
else if ( ( mx < x+csz ) && ( my > y+h-csz-1 ) )
|
||||
{
|
||||
Grow(3);
|
||||
Grow(4);
|
||||
}
|
||||
// upper left
|
||||
else if ( ( mx < x+csz ) && ( my < y+csz ) )
|
||||
{
|
||||
Grow(4);
|
||||
Grow(1);
|
||||
}
|
||||
// top edge
|
||||
else if ( my < y+esz )
|
||||
{
|
||||
Grow(1);
|
||||
}
|
||||
// right edge
|
||||
else if ( mx > x+w-esz-1 )
|
||||
{
|
||||
Grow(2);
|
||||
}
|
||||
// bottom edge
|
||||
else if ( my > y+h-esz-1 )
|
||||
{
|
||||
Grow(3);
|
||||
}
|
||||
// left edge
|
||||
else if ( mx < x+esz )
|
||||
{
|
||||
Grow(4);
|
||||
}
|
||||
// otherwise (if over the grab bar), grow all edges (from the clicked point)
|
||||
else if ( my < y + ch )
|
||||
{
|
||||
Grow(0, mx, my);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ToolWindow::OnMouseDoublePressed( MouseCode code )
|
||||
{
|
||||
GrowFromClick();
|
||||
}
|
||||
|
||||
void ToolWindow::OnMousePressed( MouseCode code )
|
||||
{
|
||||
switch ( code )
|
||||
{
|
||||
case MOUSE_MIDDLE:
|
||||
GrowFromClick();
|
||||
break;
|
||||
default:
|
||||
BaseClass::OnMousePressed( code );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,406 +1,406 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//=============================================================================//
|
||||
|
||||
#include <math.h>
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
static vgui::DHANDLE< TextEntry > s_TooltipWindow;
|
||||
static int s_iTooltipWindowCount = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseTooltip::BaseTooltip(Panel *parent, const char *text)
|
||||
{
|
||||
SetText(text);
|
||||
|
||||
_displayOnOneLine = false;
|
||||
_makeVisible = false;
|
||||
_isDirty = false;
|
||||
_enabled = true;
|
||||
|
||||
_tooltipDelay = 500; // default delay for opening tooltips
|
||||
_delay = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reset the tooltip delay timer
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ResetDelay()
|
||||
{
|
||||
_isDirty = true;
|
||||
_delay = system()->GetTimeMillis() + _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipDelay( int tooltipDelay )
|
||||
{
|
||||
_tooltipDelay = tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
int BaseTooltip::GetTooltipDelay()
|
||||
{
|
||||
return _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on one line only
|
||||
// Default is multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToSingleLine()
|
||||
{
|
||||
_displayOnOneLine = true;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToMultiLine()
|
||||
{
|
||||
_displayOnOneLine = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
_makeVisible = true;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
void BaseTooltip::SetEnabled( bool bState )
|
||||
{
|
||||
_enabled = bState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BaseTooltip::ShouldLayout( void )
|
||||
{
|
||||
if (!_makeVisible)
|
||||
return false;
|
||||
|
||||
if (_delay > system()->GetTimeMillis())
|
||||
return false;
|
||||
|
||||
// We only need to layout when we first become visible
|
||||
if ( !_isDirty )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::HideTooltip()
|
||||
{
|
||||
_makeVisible = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetText(const char *text)
|
||||
{
|
||||
_isDirty = true;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
|
||||
if (m_Text.Size() > 0)
|
||||
{
|
||||
m_Text.RemoveAll();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < strlen(text); i++)
|
||||
{
|
||||
m_Text.AddToTail(text[i]);
|
||||
}
|
||||
m_Text.AddToTail('\0');
|
||||
|
||||
if (s_TooltipWindow.Get() && m_pParent == s_TooltipWindow.Get()->GetParent())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *BaseTooltip::GetText()
|
||||
{
|
||||
return m_Text.Base();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Position the tool tip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::PositionWindow( Panel *pTipPanel )
|
||||
{
|
||||
int iTipW, iTipH;
|
||||
pTipPanel->GetSize( iTipW, iTipH );
|
||||
|
||||
int cursorX, cursorY;
|
||||
input()->GetCursorPos(cursorX, cursorY);
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetScreenSize(wide, tall);
|
||||
|
||||
if (wide - iTipW > cursorX)
|
||||
{
|
||||
cursorY += 20;
|
||||
// menu hanging right
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX, cursorY - iTipH - 20);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging left
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY - iTipH - 20 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::TextTooltip(Panel *parent, const char *text) : BaseTooltip( parent, text )
|
||||
{
|
||||
if (!s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow = new TextEntry(NULL, "tooltip");
|
||||
|
||||
s_TooltipWindow->InvalidateLayout(false, true);
|
||||
|
||||
// this bit of hackery is necessary because tooltips don't get ApplySchemeSettings called from their parents
|
||||
IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() );
|
||||
s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme));
|
||||
s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme));
|
||||
s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder"));
|
||||
s_TooltipWindow->SetFont( pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
s_iTooltipWindowCount++;
|
||||
|
||||
// this line prevents the main window from losing focus
|
||||
// when a tooltip pops up
|
||||
s_TooltipWindow->MakePopup(false, true);
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
SetText(text);
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
s_TooltipWindow->SetEditable(false);
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::~TextTooltip()
|
||||
{
|
||||
if (--s_iTooltipWindowCount < 1)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->MarkForDeletion();
|
||||
}
|
||||
s_TooltipWindow = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SetText(const char *text)
|
||||
{
|
||||
BaseTooltip::SetText( text );
|
||||
|
||||
if (s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the font from the scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
if ( s_TooltipWindow )
|
||||
{
|
||||
s_TooltipWindow->SetFont(pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
int nLen = s_TooltipWindow->GetTextLength();
|
||||
|
||||
if ( nLen <= 0 )
|
||||
{
|
||||
// Empty tool tip, no need to show it
|
||||
_makeVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
s_TooltipWindow->GetText( pBuf, nLen+1 );
|
||||
Panel *pCurrentParent = s_TooltipWindow->GetParent();
|
||||
|
||||
_isDirty = _isDirty || ( pCurrentParent != currentPanel );
|
||||
s_TooltipWindow->SetText( m_Text.Base() );
|
||||
s_TooltipWindow->SetParent(currentPanel);
|
||||
}
|
||||
BaseTooltip::ShowTooltip( currentPanel );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::PerformLayout()
|
||||
{
|
||||
if ( !ShouldLayout() )
|
||||
return;
|
||||
// we're ready, just make us visible
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
_isDirty = false;
|
||||
|
||||
s_TooltipWindow->SetVisible(true);
|
||||
s_TooltipWindow->MakePopup( false, true );
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
// relayout the textwindow immediately so that we know it's size
|
||||
//m_pTextEntry->InvalidateLayout(true);
|
||||
|
||||
SizeTextWindow();
|
||||
PositionWindow( s_TooltipWindow );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Size the text window so all the text fits inside it.
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SizeTextWindow()
|
||||
{
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
if (_displayOnOneLine)
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
int wide, tall;
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
double newWide = sqrt( (2.0/1) * wide * tall );
|
||||
double newTall = (1/2) * newWide;
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetSize((int)newWide, (int)newTall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
|
||||
if (( wide < 100 ) && ( s_TooltipWindow->GetNumLines() == 2) )
|
||||
{
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
while ( (float)wide/(float)tall < 2 )
|
||||
{
|
||||
s_TooltipWindow->SetSize( wide + 1, tall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
}
|
||||
}
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
// ivgui()->DPrintf("End Ratio: %f\n", (float)wide/(float)tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::HideTooltip()
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
BaseTooltip::HideTooltip();
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//=============================================================================//
|
||||
|
||||
#include <math.h>
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
static vgui::DHANDLE< TextEntry > s_TooltipWindow;
|
||||
static int s_iTooltipWindowCount = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseTooltip::BaseTooltip(Panel *parent, const char *text)
|
||||
{
|
||||
SetText(text);
|
||||
|
||||
_displayOnOneLine = false;
|
||||
_makeVisible = false;
|
||||
_isDirty = false;
|
||||
_enabled = true;
|
||||
|
||||
_tooltipDelay = 500; // default delay for opening tooltips
|
||||
_delay = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reset the tooltip delay timer
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ResetDelay()
|
||||
{
|
||||
_isDirty = true;
|
||||
_delay = system()->GetTimeMillis() + _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipDelay( int tooltipDelay )
|
||||
{
|
||||
_tooltipDelay = tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
int BaseTooltip::GetTooltipDelay()
|
||||
{
|
||||
return _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on one line only
|
||||
// Default is multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToSingleLine()
|
||||
{
|
||||
_displayOnOneLine = true;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToMultiLine()
|
||||
{
|
||||
_displayOnOneLine = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
_makeVisible = true;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
void BaseTooltip::SetEnabled( bool bState )
|
||||
{
|
||||
_enabled = bState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BaseTooltip::ShouldLayout( void )
|
||||
{
|
||||
if (!_makeVisible)
|
||||
return false;
|
||||
|
||||
if (_delay > system()->GetTimeMillis())
|
||||
return false;
|
||||
|
||||
// We only need to layout when we first become visible
|
||||
if ( !_isDirty )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::HideTooltip()
|
||||
{
|
||||
_makeVisible = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetText(const char *text)
|
||||
{
|
||||
_isDirty = true;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
|
||||
if (m_Text.Size() > 0)
|
||||
{
|
||||
m_Text.RemoveAll();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < strlen(text); i++)
|
||||
{
|
||||
m_Text.AddToTail(text[i]);
|
||||
}
|
||||
m_Text.AddToTail('\0');
|
||||
|
||||
if (s_TooltipWindow.Get() && m_pParent == s_TooltipWindow.Get()->GetParent())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *BaseTooltip::GetText()
|
||||
{
|
||||
return m_Text.Base();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Position the tool tip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::PositionWindow( Panel *pTipPanel )
|
||||
{
|
||||
int iTipW, iTipH;
|
||||
pTipPanel->GetSize( iTipW, iTipH );
|
||||
|
||||
int cursorX, cursorY;
|
||||
input()->GetCursorPos(cursorX, cursorY);
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetScreenSize(wide, tall);
|
||||
|
||||
if (wide - iTipW > cursorX)
|
||||
{
|
||||
cursorY += 20;
|
||||
// menu hanging right
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX, cursorY - iTipH - 20);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging left
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY - iTipH - 20 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::TextTooltip(Panel *parent, const char *text) : BaseTooltip( parent, text )
|
||||
{
|
||||
if (!s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow = new TextEntry(NULL, "tooltip");
|
||||
|
||||
s_TooltipWindow->InvalidateLayout(false, true);
|
||||
|
||||
// this bit of hackery is necessary because tooltips don't get ApplySchemeSettings called from their parents
|
||||
IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() );
|
||||
s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme));
|
||||
s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme));
|
||||
s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder"));
|
||||
s_TooltipWindow->SetFont( pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
s_iTooltipWindowCount++;
|
||||
|
||||
// this line prevents the main window from losing focus
|
||||
// when a tooltip pops up
|
||||
s_TooltipWindow->MakePopup(false, true);
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
SetText(text);
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
s_TooltipWindow->SetEditable(false);
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::~TextTooltip()
|
||||
{
|
||||
if (--s_iTooltipWindowCount < 1)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->MarkForDeletion();
|
||||
}
|
||||
s_TooltipWindow = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SetText(const char *text)
|
||||
{
|
||||
BaseTooltip::SetText( text );
|
||||
|
||||
if (s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the font from the scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
if ( s_TooltipWindow )
|
||||
{
|
||||
s_TooltipWindow->SetFont(pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
int nLen = s_TooltipWindow->GetTextLength();
|
||||
|
||||
if ( nLen <= 0 )
|
||||
{
|
||||
// Empty tool tip, no need to show it
|
||||
_makeVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
s_TooltipWindow->GetText( pBuf, nLen+1 );
|
||||
Panel *pCurrentParent = s_TooltipWindow->GetParent();
|
||||
|
||||
_isDirty = _isDirty || ( pCurrentParent != currentPanel );
|
||||
s_TooltipWindow->SetText( m_Text.Base() );
|
||||
s_TooltipWindow->SetParent(currentPanel);
|
||||
}
|
||||
BaseTooltip::ShowTooltip( currentPanel );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::PerformLayout()
|
||||
{
|
||||
if ( !ShouldLayout() )
|
||||
return;
|
||||
// we're ready, just make us visible
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
_isDirty = false;
|
||||
|
||||
s_TooltipWindow->SetVisible(true);
|
||||
s_TooltipWindow->MakePopup( false, true );
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
// relayout the textwindow immediately so that we know it's size
|
||||
//m_pTextEntry->InvalidateLayout(true);
|
||||
|
||||
SizeTextWindow();
|
||||
PositionWindow( s_TooltipWindow );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Size the text window so all the text fits inside it.
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SizeTextWindow()
|
||||
{
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
if (_displayOnOneLine)
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
int wide, tall;
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
double newWide = sqrt( (2.0/1) * wide * tall );
|
||||
double newTall = (1/2) * newWide;
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetSize((int)newWide, (int)newTall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
|
||||
if (( wide < 100 ) && ( s_TooltipWindow->GetNumLines() == 2) )
|
||||
{
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
while ( (float)wide/(float)tall < 2 )
|
||||
{
|
||||
s_TooltipWindow->SetSize( wide + 1, tall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
}
|
||||
}
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
// ivgui()->DPrintf("End Ratio: %f\n", (float)wide/(float)tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::HideTooltip()
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
BaseTooltip::HideTooltip();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,315 +1,315 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#include <assert.h>
|
||||
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/Cursor.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/MouseCode.h>
|
||||
#include <vgui/IBorder.h>
|
||||
|
||||
#include <vgui_controls/TreeViewListControl.h>
|
||||
#include <vgui_controls/ScrollBar.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/TreeView.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
#include <vgui_controls/ImageList.h>
|
||||
#include <vgui_controls/ImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CTreeViewListControl );
|
||||
|
||||
CTreeViewListControl::CTreeViewListControl( vgui::Panel *pParent, const char *pName ) :
|
||||
BaseClass( pParent, pName )
|
||||
{
|
||||
m_pTree = NULL;
|
||||
m_BorderColor.SetColor( 255, 255, 255, 255 );
|
||||
m_TitleBarFont = NULL;
|
||||
m_TitleBarHeight = 20;
|
||||
SetPostChildPaintEnabled( true );
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetTreeView( vgui::TreeView *pTree )
|
||||
{
|
||||
m_pTree = pTree;
|
||||
if ( m_pTree )
|
||||
{
|
||||
m_pTree->SetParent( this );
|
||||
m_pTree->SetPaintBackgroundEnabled( false );
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
vgui::TreeView *CTreeViewListControl::GetTree()
|
||||
{
|
||||
return m_pTree;
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetTitleBarHeight()
|
||||
{
|
||||
return m_TitleBarHeight;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetTitleBarInfo( vgui::HFont hFont, int titleBarHeight )
|
||||
{
|
||||
m_TitleBarFont = hFont;
|
||||
m_TitleBarHeight = titleBarHeight;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetBorderColor( Color clr )
|
||||
{
|
||||
m_BorderColor = clr;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetNumColumns( int nColumns )
|
||||
{
|
||||
m_Columns.Purge();
|
||||
m_Columns.SetSize( nColumns );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetNumColumns() const
|
||||
{
|
||||
return m_Columns.Count();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetColumnInfo( int iColumn, const char *pTitle, int width, int ciFlags )
|
||||
{
|
||||
if ( iColumn < 0 || iColumn >= m_Columns.Count() )
|
||||
{
|
||||
Assert( false );
|
||||
return;
|
||||
}
|
||||
CColumnInfo *pInfo = &m_Columns[iColumn];
|
||||
pInfo->m_Title = pTitle;
|
||||
pInfo->m_Width = width;
|
||||
pInfo->m_ciFlags = ciFlags;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetNumRows()
|
||||
{
|
||||
return m_Rows.Count();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetTreeItemAtRow( int iRow )
|
||||
{
|
||||
if ( iRow < 0 || iRow >= m_Rows.Count() )
|
||||
return -1;
|
||||
else
|
||||
return m_Rows[iRow];
|
||||
}
|
||||
|
||||
void CTreeViewListControl::GetGridElementBounds( int iColumn, int iRow, int &left, int &top, int &right, int &bottom )
|
||||
{
|
||||
left = m_Columns[iColumn].m_Left;
|
||||
right = m_Columns[iColumn].m_Right;
|
||||
|
||||
// vgui doesn't seem to be drawing things exactly right. Like it you draw a line at (0,0) to (100,0),
|
||||
// then a rectangle from (1,1) to (100,100), it'll overwrite the line at the top.
|
||||
int treeTopBorder = 0;
|
||||
IBorder *treeBorder = m_pTree->GetBorder();
|
||||
if ( treeBorder )
|
||||
{
|
||||
int l, t, r, b;
|
||||
treeBorder->GetInset( l, t, r, b );
|
||||
treeTopBorder = t;
|
||||
}
|
||||
if ( iRow == -1 )
|
||||
{
|
||||
top = 1;
|
||||
bottom = m_TitleBarHeight - 2;
|
||||
}
|
||||
else if ( m_pTree )
|
||||
{
|
||||
int x, y;
|
||||
m_pTree->GetPos( x, y );
|
||||
|
||||
top = treeTopBorder + m_TitleBarHeight + ( iRow * m_pTree->GetRowHeight() );
|
||||
bottom = top + m_pTree->GetRowHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
left = top = right = bottom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CTreeViewListControl::PerformLayout()
|
||||
{
|
||||
RecalculateRows();
|
||||
RecalculateColumns();
|
||||
|
||||
// Reposition the tree view.
|
||||
if ( m_pTree && m_Columns.Count() > 0 )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( 0, -1, left, top, right, bottom );
|
||||
|
||||
top = m_TitleBarHeight;
|
||||
|
||||
m_pTree->SetBounds( left, top, right - left, GetTall() - top );
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
|
||||
void CTreeViewListControl::RecalculateRows()
|
||||
{
|
||||
m_Rows.Purge();
|
||||
|
||||
if ( !m_pTree || m_pTree->GetRootItemIndex() == -1 )
|
||||
return;
|
||||
|
||||
int iRoot = m_pTree->GetRootItemIndex();
|
||||
RecalculateRows_R( iRoot );
|
||||
}
|
||||
|
||||
|
||||
void CTreeViewListControl::RecalculateRows_R( int index )
|
||||
{
|
||||
m_Rows.AddToTail( index );
|
||||
if ( !m_pTree->IsItemExpanded( index ) )
|
||||
return;
|
||||
|
||||
int nChildren = m_pTree->GetNumChildren( index );
|
||||
for ( int i=0; i < nChildren; i++ )
|
||||
{
|
||||
int iChild = m_pTree->GetChild( index, i );
|
||||
RecalculateRows_R( iChild );
|
||||
}
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetScrollBarSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::RecalculateColumns()
|
||||
{
|
||||
int rightEdge = GetWide()-1 - GetScrollBarSize();
|
||||
|
||||
int x = 0;
|
||||
int c = m_Columns.Count();
|
||||
for ( int i=0; i < c; i++ )
|
||||
{
|
||||
m_Columns[i].m_Left = x + 1;
|
||||
int cw = m_Columns[i].m_Width;
|
||||
if ( i == c - 1 )
|
||||
{
|
||||
cw = rightEdge - x - 2;
|
||||
}
|
||||
m_Columns[i].m_Right = x + cw - 2;
|
||||
x += cw;
|
||||
}
|
||||
}
|
||||
|
||||
void CTreeViewListControl::PostChildPaint()
|
||||
{
|
||||
BaseClass::PostChildPaint();
|
||||
|
||||
// Draw the grid lines.
|
||||
vgui::surface()->DrawSetColor( m_BorderColor );
|
||||
|
||||
if ( m_Columns.Count() <= 0 )
|
||||
return;
|
||||
|
||||
// Draw the horizontal lines.
|
||||
int endX = 0;
|
||||
endX = m_Columns[m_Columns.Count()-1].m_Right + 1;
|
||||
|
||||
int bottomY = 0;
|
||||
for ( int i=0; i < m_Rows.Count(); i++ )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( 0, i, left, top, right, bottom );
|
||||
|
||||
bottomY = bottom;
|
||||
vgui::surface()->DrawLine( 0, bottomY, endX, bottomY );
|
||||
}
|
||||
|
||||
// Draw the vertical lines.
|
||||
int curX = 0;
|
||||
for ( int i=0; i < m_Columns.Count(); i++ )
|
||||
{
|
||||
vgui::surface()->DrawLine( curX, 0, curX, bottomY );
|
||||
curX += m_Columns[i].m_Width;
|
||||
}
|
||||
vgui::surface()->DrawLine( curX, 0, curX, bottomY );
|
||||
}
|
||||
|
||||
void CTreeViewListControl::Paint()
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
// Draw the title bars.
|
||||
DrawTitleBars();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::DrawTitleBars()
|
||||
{
|
||||
int rightEdge = GetWide();
|
||||
|
||||
for ( int i=0; i < m_Columns.Count(); i++ )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( i, -1, left, top, right, bottom );
|
||||
|
||||
if ( left >= rightEdge )
|
||||
continue;
|
||||
|
||||
vgui::surface()->DrawSetColor( 0, 0, 0, 255 );
|
||||
vgui::surface()->DrawFilledRect( left, top, right, bottom );
|
||||
|
||||
vgui::surface()->DrawSetTextColor( 255, 255, 255, 255 );
|
||||
|
||||
const char *pTitleString = m_Columns[i].m_Title.String();
|
||||
|
||||
wchar_t unicodeString[1024];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( pTitleString, unicodeString, sizeof(unicodeString) );
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetTextSize( m_TitleBarFont, unicodeString, wide, tall );
|
||||
|
||||
surface()->DrawSetTextFont( m_TitleBarFont );
|
||||
|
||||
if ( m_Columns[i].m_ciFlags & CTreeViewListControl::CI_HEADER_LEFTALIGN )
|
||||
{
|
||||
int midy = (top+bottom)/2;
|
||||
surface()->DrawSetTextPos( left, midy );
|
||||
}
|
||||
else
|
||||
{
|
||||
int textRight = min( right, rightEdge );
|
||||
|
||||
int midx = (left+textRight)/2;
|
||||
int midy = (top+bottom)/2;
|
||||
|
||||
surface()->DrawSetTextPos( midx - wide/2, midy - tall/2 );
|
||||
}
|
||||
|
||||
surface()->DrawPrintText( unicodeString, strlen( pTitleString ) );
|
||||
}
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
#include <assert.h>
|
||||
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/Cursor.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/KeyCode.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/MouseCode.h>
|
||||
#include <vgui/IBorder.h>
|
||||
|
||||
#include <vgui_controls/TreeViewListControl.h>
|
||||
#include <vgui_controls/ScrollBar.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/TreeView.h>
|
||||
#include <vgui_controls/Label.h>
|
||||
#include <vgui_controls/Button.h>
|
||||
#include <vgui_controls/TextImage.h>
|
||||
#include <vgui_controls/ImageList.h>
|
||||
#include <vgui_controls/ImagePanel.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CTreeViewListControl );
|
||||
|
||||
CTreeViewListControl::CTreeViewListControl( vgui::Panel *pParent, const char *pName ) :
|
||||
BaseClass( pParent, pName )
|
||||
{
|
||||
m_pTree = NULL;
|
||||
m_BorderColor.SetColor( 255, 255, 255, 255 );
|
||||
m_TitleBarFont = NULL;
|
||||
m_TitleBarHeight = 20;
|
||||
SetPostChildPaintEnabled( true );
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetTreeView( vgui::TreeView *pTree )
|
||||
{
|
||||
m_pTree = pTree;
|
||||
if ( m_pTree )
|
||||
{
|
||||
m_pTree->SetParent( this );
|
||||
m_pTree->SetPaintBackgroundEnabled( false );
|
||||
}
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
vgui::TreeView *CTreeViewListControl::GetTree()
|
||||
{
|
||||
return m_pTree;
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetTitleBarHeight()
|
||||
{
|
||||
return m_TitleBarHeight;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetTitleBarInfo( vgui::HFont hFont, int titleBarHeight )
|
||||
{
|
||||
m_TitleBarFont = hFont;
|
||||
m_TitleBarHeight = titleBarHeight;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetBorderColor( Color clr )
|
||||
{
|
||||
m_BorderColor = clr;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetNumColumns( int nColumns )
|
||||
{
|
||||
m_Columns.Purge();
|
||||
m_Columns.SetSize( nColumns );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetNumColumns() const
|
||||
{
|
||||
return m_Columns.Count();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::SetColumnInfo( int iColumn, const char *pTitle, int width, int ciFlags )
|
||||
{
|
||||
if ( iColumn < 0 || iColumn >= m_Columns.Count() )
|
||||
{
|
||||
Assert( false );
|
||||
return;
|
||||
}
|
||||
CColumnInfo *pInfo = &m_Columns[iColumn];
|
||||
pInfo->m_Title = pTitle;
|
||||
pInfo->m_Width = width;
|
||||
pInfo->m_ciFlags = ciFlags;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetNumRows()
|
||||
{
|
||||
return m_Rows.Count();
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetTreeItemAtRow( int iRow )
|
||||
{
|
||||
if ( iRow < 0 || iRow >= m_Rows.Count() )
|
||||
return -1;
|
||||
else
|
||||
return m_Rows[iRow];
|
||||
}
|
||||
|
||||
void CTreeViewListControl::GetGridElementBounds( int iColumn, int iRow, int &left, int &top, int &right, int &bottom )
|
||||
{
|
||||
left = m_Columns[iColumn].m_Left;
|
||||
right = m_Columns[iColumn].m_Right;
|
||||
|
||||
// vgui doesn't seem to be drawing things exactly right. Like it you draw a line at (0,0) to (100,0),
|
||||
// then a rectangle from (1,1) to (100,100), it'll overwrite the line at the top.
|
||||
int treeTopBorder = 0;
|
||||
IBorder *treeBorder = m_pTree->GetBorder();
|
||||
if ( treeBorder )
|
||||
{
|
||||
int l, t, r, b;
|
||||
treeBorder->GetInset( l, t, r, b );
|
||||
treeTopBorder = t;
|
||||
}
|
||||
if ( iRow == -1 )
|
||||
{
|
||||
top = 1;
|
||||
bottom = m_TitleBarHeight - 2;
|
||||
}
|
||||
else if ( m_pTree )
|
||||
{
|
||||
int x, y;
|
||||
m_pTree->GetPos( x, y );
|
||||
|
||||
top = treeTopBorder + m_TitleBarHeight + ( iRow * m_pTree->GetRowHeight() );
|
||||
bottom = top + m_pTree->GetRowHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
left = top = right = bottom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CTreeViewListControl::PerformLayout()
|
||||
{
|
||||
RecalculateRows();
|
||||
RecalculateColumns();
|
||||
|
||||
// Reposition the tree view.
|
||||
if ( m_pTree && m_Columns.Count() > 0 )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( 0, -1, left, top, right, bottom );
|
||||
|
||||
top = m_TitleBarHeight;
|
||||
|
||||
m_pTree->SetBounds( left, top, right - left, GetTall() - top );
|
||||
}
|
||||
|
||||
BaseClass::PerformLayout();
|
||||
}
|
||||
|
||||
|
||||
void CTreeViewListControl::RecalculateRows()
|
||||
{
|
||||
m_Rows.Purge();
|
||||
|
||||
if ( !m_pTree || m_pTree->GetRootItemIndex() == -1 )
|
||||
return;
|
||||
|
||||
int iRoot = m_pTree->GetRootItemIndex();
|
||||
RecalculateRows_R( iRoot );
|
||||
}
|
||||
|
||||
|
||||
void CTreeViewListControl::RecalculateRows_R( int index )
|
||||
{
|
||||
m_Rows.AddToTail( index );
|
||||
if ( !m_pTree->IsItemExpanded( index ) )
|
||||
return;
|
||||
|
||||
int nChildren = m_pTree->GetNumChildren( index );
|
||||
for ( int i=0; i < nChildren; i++ )
|
||||
{
|
||||
int iChild = m_pTree->GetChild( index, i );
|
||||
RecalculateRows_R( iChild );
|
||||
}
|
||||
}
|
||||
|
||||
int CTreeViewListControl::GetScrollBarSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CTreeViewListControl::RecalculateColumns()
|
||||
{
|
||||
int rightEdge = GetWide()-1 - GetScrollBarSize();
|
||||
|
||||
int x = 0;
|
||||
int c = m_Columns.Count();
|
||||
for ( int i=0; i < c; i++ )
|
||||
{
|
||||
m_Columns[i].m_Left = x + 1;
|
||||
int cw = m_Columns[i].m_Width;
|
||||
if ( i == c - 1 )
|
||||
{
|
||||
cw = rightEdge - x - 2;
|
||||
}
|
||||
m_Columns[i].m_Right = x + cw - 2;
|
||||
x += cw;
|
||||
}
|
||||
}
|
||||
|
||||
void CTreeViewListControl::PostChildPaint()
|
||||
{
|
||||
BaseClass::PostChildPaint();
|
||||
|
||||
// Draw the grid lines.
|
||||
vgui::surface()->DrawSetColor( m_BorderColor );
|
||||
|
||||
if ( m_Columns.Count() <= 0 )
|
||||
return;
|
||||
|
||||
// Draw the horizontal lines.
|
||||
int endX = 0;
|
||||
endX = m_Columns[m_Columns.Count()-1].m_Right + 1;
|
||||
|
||||
int bottomY = 0;
|
||||
for ( int i=0; i < m_Rows.Count(); i++ )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( 0, i, left, top, right, bottom );
|
||||
|
||||
bottomY = bottom;
|
||||
vgui::surface()->DrawLine( 0, bottomY, endX, bottomY );
|
||||
}
|
||||
|
||||
// Draw the vertical lines.
|
||||
int curX = 0;
|
||||
for ( int i=0; i < m_Columns.Count(); i++ )
|
||||
{
|
||||
vgui::surface()->DrawLine( curX, 0, curX, bottomY );
|
||||
curX += m_Columns[i].m_Width;
|
||||
}
|
||||
vgui::surface()->DrawLine( curX, 0, curX, bottomY );
|
||||
}
|
||||
|
||||
void CTreeViewListControl::Paint()
|
||||
{
|
||||
BaseClass::Paint();
|
||||
|
||||
// Draw the title bars.
|
||||
DrawTitleBars();
|
||||
}
|
||||
|
||||
void CTreeViewListControl::DrawTitleBars()
|
||||
{
|
||||
int rightEdge = GetWide();
|
||||
|
||||
for ( int i=0; i < m_Columns.Count(); i++ )
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
GetGridElementBounds( i, -1, left, top, right, bottom );
|
||||
|
||||
if ( left >= rightEdge )
|
||||
continue;
|
||||
|
||||
vgui::surface()->DrawSetColor( 0, 0, 0, 255 );
|
||||
vgui::surface()->DrawFilledRect( left, top, right, bottom );
|
||||
|
||||
vgui::surface()->DrawSetTextColor( 255, 255, 255, 255 );
|
||||
|
||||
const char *pTitleString = m_Columns[i].m_Title.String();
|
||||
|
||||
wchar_t unicodeString[1024];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( pTitleString, unicodeString, sizeof(unicodeString) );
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetTextSize( m_TitleBarFont, unicodeString, wide, tall );
|
||||
|
||||
surface()->DrawSetTextFont( m_TitleBarFont );
|
||||
|
||||
if ( m_Columns[i].m_ciFlags & CTreeViewListControl::CI_HEADER_LEFTALIGN )
|
||||
{
|
||||
int midy = (top+bottom)/2;
|
||||
surface()->DrawSetTextPos( left, midy );
|
||||
}
|
||||
else
|
||||
{
|
||||
int textRight = min( right, rightEdge );
|
||||
|
||||
int midx = (left+textRight)/2;
|
||||
int midy = (top+bottom)/2;
|
||||
|
||||
surface()->DrawSetTextPos( midx - wide/2, midy - tall/2 );
|
||||
}
|
||||
|
||||
surface()->DrawPrintText( unicodeString, strlen( pTitleString ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,158 +1,158 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/Cursor.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
#include "vgui_controls/URLLabel.h"
|
||||
#include "vgui_controls/TextImage.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::Panel *URLLabel_Factory()
|
||||
{
|
||||
return new URLLabel(NULL, NULL, "URLLabel", NULL);
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM( URLLabel, URLLabel_Factory );
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::URLLabel(Panel *parent, const char *panelName, const char *text, const char *pszURL) : Label(parent, panelName, text)
|
||||
{
|
||||
m_pszURL = NULL;
|
||||
m_bUnderline = false;
|
||||
m_iURLSize = 0;
|
||||
if (pszURL && strlen(pszURL) > 0)
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: unicode constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::URLLabel(Panel *parent, const char *panelName, const wchar_t *wszText, const char *pszURL) : Label(parent, panelName, wszText)
|
||||
{
|
||||
m_pszURL = NULL;
|
||||
m_bUnderline = false;
|
||||
m_iURLSize = 0;
|
||||
if (pszURL && strlen(pszURL) > 0)
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::~URLLabel()
|
||||
{
|
||||
if (m_pszURL)
|
||||
delete [] m_pszURL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the URL
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::SetURL(const char *pszURL)
|
||||
{
|
||||
int iNewURLSize = strlen(pszURL);
|
||||
if (iNewURLSize > m_iURLSize || !m_pszURL)
|
||||
{
|
||||
delete [] m_pszURL;
|
||||
m_pszURL = new char [iNewURLSize + 1];
|
||||
}
|
||||
strcpy(m_pszURL, pszURL);
|
||||
m_iURLSize = iNewURLSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: If we were left clicked on, launch the URL
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::OnMousePressed(MouseCode code)
|
||||
{
|
||||
if (code == MOUSE_LEFT)
|
||||
{
|
||||
if (m_pszURL)
|
||||
{
|
||||
system()->ShellExecute("open", m_pszURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies resouce settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
const char *pszURL = inResourceData->GetString("URLText", NULL);
|
||||
if (pszURL)
|
||||
{
|
||||
if (pszURL[0] == '#')
|
||||
{
|
||||
// it's a localized url, look it up
|
||||
const wchar_t *ws = g_pVGuiLocalize->Find(pszURL + 1);
|
||||
if (ws)
|
||||
{
|
||||
char localizedUrl[512];
|
||||
g_pVGuiLocalize->ConvertUnicodeToANSI(ws, localizedUrl, sizeof(localizedUrl));
|
||||
SetURL(localizedUrl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: saves them to disk
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::GetSettings( KeyValues *outResourceData )
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
if (m_pszURL)
|
||||
{
|
||||
outResourceData->SetString("URLText", m_pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a description of the label string
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *URLLabel::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string URLText", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: scheme settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
// set our font to be underlined by default
|
||||
// the Label::ApplySchemeSettings() will override it if override set in scheme file
|
||||
SetFont( pScheme->GetFont( "DefaultUnderline", IsProportional() ) );
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetCursor(dc_hand);
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/ISystem.h"
|
||||
#include "vgui/MouseCode.h"
|
||||
#include "vgui/Cursor.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
#include "vgui_controls/URLLabel.h"
|
||||
#include "vgui_controls/TextImage.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::Panel *URLLabel_Factory()
|
||||
{
|
||||
return new URLLabel(NULL, NULL, "URLLabel", NULL);
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM( URLLabel, URLLabel_Factory );
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::URLLabel(Panel *parent, const char *panelName, const char *text, const char *pszURL) : Label(parent, panelName, text)
|
||||
{
|
||||
m_pszURL = NULL;
|
||||
m_bUnderline = false;
|
||||
m_iURLSize = 0;
|
||||
if (pszURL && strlen(pszURL) > 0)
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: unicode constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::URLLabel(Panel *parent, const char *panelName, const wchar_t *wszText, const char *pszURL) : Label(parent, panelName, wszText)
|
||||
{
|
||||
m_pszURL = NULL;
|
||||
m_bUnderline = false;
|
||||
m_iURLSize = 0;
|
||||
if (pszURL && strlen(pszURL) > 0)
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
URLLabel::~URLLabel()
|
||||
{
|
||||
if (m_pszURL)
|
||||
delete [] m_pszURL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the URL
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::SetURL(const char *pszURL)
|
||||
{
|
||||
int iNewURLSize = strlen(pszURL);
|
||||
if (iNewURLSize > m_iURLSize || !m_pszURL)
|
||||
{
|
||||
delete [] m_pszURL;
|
||||
m_pszURL = new char [iNewURLSize + 1];
|
||||
}
|
||||
strcpy(m_pszURL, pszURL);
|
||||
m_iURLSize = iNewURLSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: If we were left clicked on, launch the URL
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::OnMousePressed(MouseCode code)
|
||||
{
|
||||
if (code == MOUSE_LEFT)
|
||||
{
|
||||
if (m_pszURL)
|
||||
{
|
||||
system()->ShellExecute("open", m_pszURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Applies resouce settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
const char *pszURL = inResourceData->GetString("URLText", NULL);
|
||||
if (pszURL)
|
||||
{
|
||||
if (pszURL[0] == '#')
|
||||
{
|
||||
// it's a localized url, look it up
|
||||
const wchar_t *ws = g_pVGuiLocalize->Find(pszURL + 1);
|
||||
if (ws)
|
||||
{
|
||||
char localizedUrl[512];
|
||||
g_pVGuiLocalize->ConvertUnicodeToANSI(ws, localizedUrl, sizeof(localizedUrl));
|
||||
SetURL(localizedUrl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetURL(pszURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: saves them to disk
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::GetSettings( KeyValues *outResourceData )
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
if (m_pszURL)
|
||||
{
|
||||
outResourceData->SetString("URLText", m_pszURL);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns a description of the label string
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *URLLabel::GetDescription( void )
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, string URLText", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: scheme settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void URLLabel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
// set our font to be underlined by default
|
||||
// the Label::ApplySchemeSettings() will override it if override set in scheme file
|
||||
SetFont( pScheme->GetFont( "DefaultUnderline", IsProportional() ) );
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetCursor(dc_hand);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,114 +1,114 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/WizardPanel.h"
|
||||
#include "vgui_controls/WizardSubPanel.h"
|
||||
#include "vgui_controls/BuildGroup.h"
|
||||
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
#include <stdio.h>
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel::WizardSubPanel(Panel *parent, const char *panelName) : EditablePanel(parent, panelName), _wizardPanel(NULL)
|
||||
{
|
||||
SetVisible(false);
|
||||
m_iDesiredWide = 0;
|
||||
m_iDesiredTall = 0;
|
||||
SetBuildGroup(GetBuildGroup());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel::~WizardSubPanel()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetBgColor(GetSchemeColor("WizardSubPanel.BgColor",pScheme));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::GetSettings( KeyValues *outResourceData )
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
outResourceData->SetInt("WizardWide", m_iDesiredWide);
|
||||
outResourceData->SetInt("WizardTall", m_iDesiredTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
// don't adjust visiblity during settings application (since it's our parent who really controls it)
|
||||
bool bVisible = IsVisible();
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
m_iDesiredWide = inResourceData->GetInt("WizardWide", 0);
|
||||
m_iDesiredTall = inResourceData->GetInt("WizardTall", 0);
|
||||
|
||||
if (GetWizardPanel() && m_iDesiredWide && m_iDesiredTall)
|
||||
{
|
||||
GetWizardPanel()->SetSize(m_iDesiredWide, m_iDesiredTall);
|
||||
}
|
||||
|
||||
SetVisible(bVisible);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: build mode description
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *WizardSubPanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, int WizardWide, int WizardTall", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the size this subpanel would like the wizard to be
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WizardSubPanel::GetDesiredSize(int &wide, int &tall)
|
||||
{
|
||||
wide = m_iDesiredWide;
|
||||
tall = m_iDesiredTall;
|
||||
|
||||
return (m_iDesiredWide && m_iDesiredTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues *WizardSubPanel::GetWizardData()
|
||||
{
|
||||
return GetWizardPanel()->GetWizardData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel *WizardSubPanel::GetSiblingSubPanelByName(const char *pageName)
|
||||
{
|
||||
return GetWizardPanel()->GetSubPanelByName(pageName);
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_controls/WizardPanel.h"
|
||||
#include "vgui_controls/WizardSubPanel.h"
|
||||
#include "vgui_controls/BuildGroup.h"
|
||||
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
#include <stdio.h>
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel::WizardSubPanel(Panel *parent, const char *panelName) : EditablePanel(parent, panelName), _wizardPanel(NULL)
|
||||
{
|
||||
SetVisible(false);
|
||||
m_iDesiredWide = 0;
|
||||
m_iDesiredTall = 0;
|
||||
SetBuildGroup(GetBuildGroup());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel::~WizardSubPanel()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
SetBgColor(GetSchemeColor("WizardSubPanel.BgColor",pScheme));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::GetSettings( KeyValues *outResourceData )
|
||||
{
|
||||
BaseClass::GetSettings(outResourceData);
|
||||
|
||||
outResourceData->SetInt("WizardWide", m_iDesiredWide);
|
||||
outResourceData->SetInt("WizardTall", m_iDesiredTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void WizardSubPanel::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
// don't adjust visiblity during settings application (since it's our parent who really controls it)
|
||||
bool bVisible = IsVisible();
|
||||
|
||||
BaseClass::ApplySettings(inResourceData);
|
||||
|
||||
m_iDesiredWide = inResourceData->GetInt("WizardWide", 0);
|
||||
m_iDesiredTall = inResourceData->GetInt("WizardTall", 0);
|
||||
|
||||
if (GetWizardPanel() && m_iDesiredWide && m_iDesiredTall)
|
||||
{
|
||||
GetWizardPanel()->SetSize(m_iDesiredWide, m_iDesiredTall);
|
||||
}
|
||||
|
||||
SetVisible(bVisible);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: build mode description
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *WizardSubPanel::GetDescription()
|
||||
{
|
||||
static char buf[1024];
|
||||
_snprintf(buf, sizeof(buf), "%s, int WizardWide, int WizardTall", BaseClass::GetDescription());
|
||||
return buf;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the size this subpanel would like the wizard to be
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WizardSubPanel::GetDesiredSize(int &wide, int &tall)
|
||||
{
|
||||
wide = m_iDesiredWide;
|
||||
tall = m_iDesiredTall;
|
||||
|
||||
return (m_iDesiredWide && m_iDesiredTall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues *WizardSubPanel::GetWizardData()
|
||||
{
|
||||
return GetWizardPanel()->GetWizardData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
WizardSubPanel *WizardSubPanel::GetSiblingSubPanelByName(const char *pageName)
|
||||
{
|
||||
return GetWizardPanel()->GetSubPanelByName(pageName);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,72 +1,72 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <locale.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
extern int g_nYou_Must_Add_Public_Vgui_Controls_Vgui_ControlsCpp_To_Your_Project;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
static char g_szControlsModuleName[256];
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Initializes the controls
|
||||
//-----------------------------------------------------------------------------
|
||||
extern "C" { extern int _heapmin(); }
|
||||
|
||||
bool VGui_InitInterfacesList( const char *moduleName, CreateInterfaceFn *factoryList, int numFactories )
|
||||
{
|
||||
g_nYou_Must_Add_Public_Vgui_Controls_Vgui_ControlsCpp_To_Your_Project = 1;
|
||||
|
||||
// If you hit this error, then you need to include memoverride.cpp in the project somewhere or else
|
||||
// you'll get crashes later when vgui_controls allocates KeyValues and vgui tries to delete them.
|
||||
#if !defined(NO_MALLOC_OVERRIDE) && defined( WIN32 )
|
||||
if ( _heapmin() != 1 )
|
||||
{
|
||||
Assert( false );
|
||||
Error( "Must include memoverride.cpp in your project." );
|
||||
}
|
||||
#endif
|
||||
// keep a record of this module name
|
||||
strncpy(g_szControlsModuleName, moduleName, sizeof(g_szControlsModuleName));
|
||||
g_szControlsModuleName[sizeof(g_szControlsModuleName) - 1] = 0;
|
||||
|
||||
// initialize our locale (must be done for every vgui dll/exe)
|
||||
// "" makes it use the default locale, required to make iswprint() work correctly in different languages
|
||||
setlocale(LC_CTYPE, "");
|
||||
setlocale(LC_TIME, "");
|
||||
setlocale(LC_COLLATE, "");
|
||||
setlocale(LC_MONETARY, "");
|
||||
|
||||
// NOTE: Vgui expects to use these interfaces which are defined in tier3.lib
|
||||
if ( !g_pVGui || !g_pVGuiInput || !g_pVGuiPanel ||
|
||||
!g_pVGuiSurface || !g_pVGuiSchemeManager || !g_pVGuiSystem )
|
||||
{
|
||||
Warning( "vgui_controls is missing a required interface!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the name of the module this has been compiled into
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *GetControlsModuleName()
|
||||
{
|
||||
return g_szControlsModuleName;
|
||||
}
|
||||
|
||||
} // namespace vgui
|
||||
|
||||
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include <vgui_controls/Controls.h>
|
||||
#include <locale.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
extern int g_nYou_Must_Add_Public_Vgui_Controls_Vgui_ControlsCpp_To_Your_Project;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
static char g_szControlsModuleName[256];
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Initializes the controls
|
||||
//-----------------------------------------------------------------------------
|
||||
extern "C" { extern int _heapmin(); }
|
||||
|
||||
bool VGui_InitInterfacesList( const char *moduleName, CreateInterfaceFn *factoryList, int numFactories )
|
||||
{
|
||||
g_nYou_Must_Add_Public_Vgui_Controls_Vgui_ControlsCpp_To_Your_Project = 1;
|
||||
|
||||
// If you hit this error, then you need to include memoverride.cpp in the project somewhere or else
|
||||
// you'll get crashes later when vgui_controls allocates KeyValues and vgui tries to delete them.
|
||||
#if !defined(NO_MALLOC_OVERRIDE) && defined( WIN32 )
|
||||
if ( _heapmin() != 1 )
|
||||
{
|
||||
Assert( false );
|
||||
Error( "Must include memoverride.cpp in your project." );
|
||||
}
|
||||
#endif
|
||||
// keep a record of this module name
|
||||
strncpy(g_szControlsModuleName, moduleName, sizeof(g_szControlsModuleName));
|
||||
g_szControlsModuleName[sizeof(g_szControlsModuleName) - 1] = 0;
|
||||
|
||||
// initialize our locale (must be done for every vgui dll/exe)
|
||||
// "" makes it use the default locale, required to make iswprint() work correctly in different languages
|
||||
setlocale(LC_CTYPE, "");
|
||||
setlocale(LC_TIME, "");
|
||||
setlocale(LC_COLLATE, "");
|
||||
setlocale(LC_MONETARY, "");
|
||||
|
||||
// NOTE: Vgui expects to use these interfaces which are defined in tier3.lib
|
||||
if ( !g_pVGui || !g_pVGuiInput || !g_pVGuiPanel ||
|
||||
!g_pVGuiSurface || !g_pVGuiSchemeManager || !g_pVGuiSystem )
|
||||
{
|
||||
Warning( "vgui_controls is missing a required interface!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the name of the module this has been compiled into
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *GetControlsModuleName()
|
||||
{
|
||||
return g_szControlsModuleName;
|
||||
}
|
||||
|
||||
} // namespace vgui
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui_controls/cvartogglecheckbutton.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::Panel *Create_CvarToggleCheckButton()
|
||||
{
|
||||
return new CvarToggleCheckButton< ConVarRef >( NULL, NULL );
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( CvarToggleCheckButton<ConVarRef>, CvarToggleCheckButton, Create_CvarToggleCheckButton );
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui_controls/cvartogglecheckbutton.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::Panel *Create_CvarToggleCheckButton()
|
||||
{
|
||||
return new CvarToggleCheckButton< ConVarRef >( NULL, NULL );
|
||||
}
|
||||
|
||||
DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( CvarToggleCheckButton<ConVarRef>, CvarToggleCheckButton, Create_CvarToggleCheckButton );
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,195 +1,195 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/savedocumentquery.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
#include "vgui_controls/Frame.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IVGui.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This dialog asks if you want to save your work
|
||||
//-----------------------------------------------------------------------------
|
||||
class CSaveDocumentQuery : public vgui::Frame
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CSaveDocumentQuery, vgui::Frame );
|
||||
|
||||
public:
|
||||
CSaveDocumentQuery( vgui::Panel *pParent, const char *filename, const char *pFileType, int nContext,
|
||||
vgui::Panel *pActionSignalTarget = 0, KeyValues *pKeyValues = 0 );
|
||||
~CSaveDocumentQuery();
|
||||
|
||||
// Inherited from vgui::Frame
|
||||
virtual void OnCommand( char const *cmd );
|
||||
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
|
||||
|
||||
// Put the message box into a modal state
|
||||
void DoModal();
|
||||
|
||||
private:
|
||||
// Posts commands to the action signal target
|
||||
void PostCommand( const char *pCommand );
|
||||
|
||||
vgui::Label *m_pMessageLabel;
|
||||
vgui::Button *m_pYesButton;
|
||||
vgui::Button *m_pNoButton;
|
||||
vgui::Button *m_pCancelButton;
|
||||
vgui::Panel *m_pActionSignalTarget;
|
||||
|
||||
char m_szFileName[ 256 ];
|
||||
char m_szFileType[ 256 ];
|
||||
int m_nContext;
|
||||
KeyValues* m_pPostSaveKeyValues;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void ShowSaveDocumentQuery( vgui::Panel *pParent, const char *pFileName, const char *pFileType, int nContext, vgui::Panel *pActionSignalTarget, KeyValues *pPostSaveCommand )
|
||||
{
|
||||
CSaveDocumentQuery *query = new CSaveDocumentQuery( pParent, pFileName, pFileType, nContext, pActionSignalTarget, pPostSaveCommand );
|
||||
query->SetSmallCaption( true );
|
||||
query->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSaveDocumentQuery::CSaveDocumentQuery( vgui::Panel *pParent, char const *pFileName, const char *pFileType, int nContext, vgui::Panel *pActionSignalTarget, KeyValues *pPostSaveCommand ) :
|
||||
BaseClass( pParent, "SaveDocumentQuery" ),
|
||||
m_nContext( nContext ),
|
||||
m_pActionSignalTarget( pActionSignalTarget )
|
||||
{
|
||||
if ( !pFileName || !pFileName[0] )
|
||||
{
|
||||
pFileName = "<untitled>";
|
||||
}
|
||||
Q_strncpy( m_szFileName, pFileName, sizeof( m_szFileName ) );
|
||||
Q_strncpy( m_szFileType, pFileType, sizeof( m_szFileType ) );
|
||||
m_pPostSaveKeyValues = pPostSaveCommand;
|
||||
|
||||
SetDeleteSelfOnClose(true);
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
|
||||
SetTitle( "Save Changes", true );
|
||||
|
||||
m_pMessageLabel = new Label( this, "FileNameLabel", "" );
|
||||
|
||||
m_pYesButton = new Button( this, "Yes", "Yes", this, "yes" );
|
||||
m_pNoButton = new Button( this, "No", "No", this, "no" );
|
||||
m_pCancelButton = new Button( this, "Cancel", "Cancel", this, "cancel" );
|
||||
|
||||
LoadControlSettings( "resource/ToolSaveDocumentQuery.res" );
|
||||
|
||||
m_pMessageLabel->SetText( m_szFileName );
|
||||
}
|
||||
|
||||
CSaveDocumentQuery::~CSaveDocumentQuery()
|
||||
{
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
m_pPostSaveKeyValues->deleteThis();
|
||||
m_pPostSaveKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Posts commands to the action signal target
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::PostCommand( const char *pCommand )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( pCommand );
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), kv, 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Process commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::OnCommand( char const *cmd )
|
||||
{
|
||||
if ( !Q_stricmp( cmd, "yes" ) )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "OnSaveFile" );
|
||||
kv->SetString( "filename", m_szFileName );
|
||||
kv->SetString( "filetype", m_szFileType );
|
||||
kv->SetInt( "context", m_nContext );
|
||||
kv->SetPtr( "actionTarget", m_pActionSignalTarget );
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pPostSaveKeyValues->MakeCopy() );
|
||||
}
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), kv, 0 );
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "no" ) )
|
||||
{
|
||||
PostCommand( "OnMarkNotDirty" );
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), m_pPostSaveKeyValues->MakeCopy(), 0 );
|
||||
}
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "cancel" ) )
|
||||
{
|
||||
PostCommand( "OnCancelSaveDocument" );
|
||||
MarkForDeletion();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deal with scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Put the message box into a modal state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::DoModal()
|
||||
{
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
RequestFocus();
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/savedocumentquery.h"
|
||||
#include "vgui_controls/Button.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
#include "vgui_controls/Frame.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui/IVGui.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This dialog asks if you want to save your work
|
||||
//-----------------------------------------------------------------------------
|
||||
class CSaveDocumentQuery : public vgui::Frame
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CSaveDocumentQuery, vgui::Frame );
|
||||
|
||||
public:
|
||||
CSaveDocumentQuery( vgui::Panel *pParent, const char *filename, const char *pFileType, int nContext,
|
||||
vgui::Panel *pActionSignalTarget = 0, KeyValues *pKeyValues = 0 );
|
||||
~CSaveDocumentQuery();
|
||||
|
||||
// Inherited from vgui::Frame
|
||||
virtual void OnCommand( char const *cmd );
|
||||
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
|
||||
|
||||
// Put the message box into a modal state
|
||||
void DoModal();
|
||||
|
||||
private:
|
||||
// Posts commands to the action signal target
|
||||
void PostCommand( const char *pCommand );
|
||||
|
||||
vgui::Label *m_pMessageLabel;
|
||||
vgui::Button *m_pYesButton;
|
||||
vgui::Button *m_pNoButton;
|
||||
vgui::Button *m_pCancelButton;
|
||||
vgui::Panel *m_pActionSignalTarget;
|
||||
|
||||
char m_szFileName[ 256 ];
|
||||
char m_szFileType[ 256 ];
|
||||
int m_nContext;
|
||||
KeyValues* m_pPostSaveKeyValues;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void ShowSaveDocumentQuery( vgui::Panel *pParent, const char *pFileName, const char *pFileType, int nContext, vgui::Panel *pActionSignalTarget, KeyValues *pPostSaveCommand )
|
||||
{
|
||||
CSaveDocumentQuery *query = new CSaveDocumentQuery( pParent, pFileName, pFileType, nContext, pActionSignalTarget, pPostSaveCommand );
|
||||
query->SetSmallCaption( true );
|
||||
query->DoModal();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSaveDocumentQuery::CSaveDocumentQuery( vgui::Panel *pParent, char const *pFileName, const char *pFileType, int nContext, vgui::Panel *pActionSignalTarget, KeyValues *pPostSaveCommand ) :
|
||||
BaseClass( pParent, "SaveDocumentQuery" ),
|
||||
m_nContext( nContext ),
|
||||
m_pActionSignalTarget( pActionSignalTarget )
|
||||
{
|
||||
if ( !pFileName || !pFileName[0] )
|
||||
{
|
||||
pFileName = "<untitled>";
|
||||
}
|
||||
Q_strncpy( m_szFileName, pFileName, sizeof( m_szFileName ) );
|
||||
Q_strncpy( m_szFileType, pFileType, sizeof( m_szFileType ) );
|
||||
m_pPostSaveKeyValues = pPostSaveCommand;
|
||||
|
||||
SetDeleteSelfOnClose(true);
|
||||
|
||||
SetMenuButtonResponsive(false);
|
||||
SetMinimizeButtonVisible(false);
|
||||
SetCloseButtonVisible(false);
|
||||
SetSizeable(false);
|
||||
|
||||
SetTitle( "Save Changes", true );
|
||||
|
||||
m_pMessageLabel = new Label( this, "FileNameLabel", "" );
|
||||
|
||||
m_pYesButton = new Button( this, "Yes", "Yes", this, "yes" );
|
||||
m_pNoButton = new Button( this, "No", "No", this, "no" );
|
||||
m_pCancelButton = new Button( this, "Cancel", "Cancel", this, "cancel" );
|
||||
|
||||
LoadControlSettings( "resource/ToolSaveDocumentQuery.res" );
|
||||
|
||||
m_pMessageLabel->SetText( m_szFileName );
|
||||
}
|
||||
|
||||
CSaveDocumentQuery::~CSaveDocumentQuery()
|
||||
{
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
m_pPostSaveKeyValues->deleteThis();
|
||||
m_pPostSaveKeyValues = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Posts commands to the action signal target
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::PostCommand( const char *pCommand )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( pCommand );
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), kv, 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Process commands
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::OnCommand( char const *cmd )
|
||||
{
|
||||
if ( !Q_stricmp( cmd, "yes" ) )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( "OnSaveFile" );
|
||||
kv->SetString( "filename", m_szFileName );
|
||||
kv->SetString( "filetype", m_szFileType );
|
||||
kv->SetInt( "context", m_nContext );
|
||||
kv->SetPtr( "actionTarget", m_pActionSignalTarget );
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
kv->AddSubKey( m_pPostSaveKeyValues->MakeCopy() );
|
||||
}
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), kv, 0 );
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "no" ) )
|
||||
{
|
||||
PostCommand( "OnMarkNotDirty" );
|
||||
if ( m_pPostSaveKeyValues )
|
||||
{
|
||||
vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), m_pPostSaveKeyValues->MakeCopy(), 0 );
|
||||
}
|
||||
MarkForDeletion();
|
||||
}
|
||||
else if ( !Q_stricmp( cmd, "cancel" ) )
|
||||
{
|
||||
PostCommand( "OnCancelSaveDocument" );
|
||||
MarkForDeletion();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deal with scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
int wide, tall;
|
||||
GetSize( wide, tall );
|
||||
|
||||
int swide, stall;
|
||||
surface()->GetScreenSize(swide, stall);
|
||||
|
||||
// put the dialog in the middle of the screen
|
||||
SetPos((swide - wide) / 2, (stall - tall) / 2);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Put the message box into a modal state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSaveDocumentQuery::DoModal()
|
||||
{
|
||||
SetVisible( true );
|
||||
SetEnabled( true );
|
||||
MoveToFront();
|
||||
|
||||
RequestFocus();
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
@@ -1,212 +1,212 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/subrectimage.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// Officially the invalid texture ID is zero, but -1 is used in many
|
||||
// places, and changing it carries some risk. Adding a named constant
|
||||
// for this file avoids warnings and makes future changes easier.
|
||||
const HTexture SUBRECT_INVALID_TEXTURE = (HTexture)-1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSubRectImage::CSubRectImage( const char *filename, bool hardwareFiltered, int subx, int suby, int subw, int subh )
|
||||
{
|
||||
SetSize( subw, subh );
|
||||
sub[ 0 ] = subx;
|
||||
sub[ 1 ] = suby;
|
||||
sub[ 2 ] = subw;
|
||||
sub[ 3 ] = subh;
|
||||
|
||||
_filtered = hardwareFiltered;
|
||||
// HACKHACK - force VGUI materials to be in the vgui/ directory
|
||||
// This needs to be revisited once GoldSRC is grandfathered off.
|
||||
//!! need to make this work with goldsrc
|
||||
int size = strlen(filename) + 1 + strlen("vgui/");
|
||||
_filename = (char *)malloc( size );
|
||||
Assert( _filename );
|
||||
|
||||
Q_snprintf( _filename, size, "vgui/%s", filename );
|
||||
|
||||
_id = SUBRECT_INVALID_TEXTURE;
|
||||
_uploaded = false;
|
||||
_color = Color(255, 255, 255, 255);
|
||||
_pos[0] = _pos[1] = 0;
|
||||
_valid = true;
|
||||
_wide = subw;
|
||||
_tall = subh;
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
CSubRectImage::~CSubRectImage()
|
||||
{
|
||||
if ( vgui::surface() && _id != SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( _id );
|
||||
_id = SUBRECT_INVALID_TEXTURE;
|
||||
}
|
||||
|
||||
if ( _filename )
|
||||
{
|
||||
free( _filename );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = _wide;
|
||||
tall = _tall;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
wide = 0;
|
||||
tall = 0;
|
||||
|
||||
if (!_valid)
|
||||
return;
|
||||
|
||||
if ( _id != SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
surface()->DrawGetTextureSize(_id, wide, tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ignored
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetSize(int x, int y)
|
||||
{
|
||||
_wide = x;
|
||||
_tall = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetPos(int x, int y)
|
||||
{
|
||||
_pos[0] = x;
|
||||
_pos[1] = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetColor(Color col)
|
||||
{
|
||||
_color = col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the file name of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSubRectImage::GetName()
|
||||
{
|
||||
return _filename;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Renders the loaded image, uploading it if necessary
|
||||
// Assumes a valid image is always returned from uploading
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::Paint()
|
||||
{
|
||||
if ( !_valid )
|
||||
return;
|
||||
|
||||
// if we don't have an _id then lets make one
|
||||
if ( _id == SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
_id = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
// if we have not uploaded yet, lets go ahead and do so
|
||||
if ( !_uploaded )
|
||||
{
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
// set the texture current, set the color, and draw the biatch
|
||||
surface()->DrawSetColor( _color[0], _color[1], _color[2], _color[3] );
|
||||
surface()->DrawSetTexture( _id );
|
||||
|
||||
if ( _wide == 0 || _tall == 0 )
|
||||
return;
|
||||
|
||||
int cw, ch;
|
||||
GetContentSize( cw, ch );
|
||||
if ( cw == 0 || ch == 0 )
|
||||
return;
|
||||
|
||||
float s[ 2 ];
|
||||
float t[ 2 ];
|
||||
|
||||
s[ 0 ] = (float)sub[ 0 ] / (float)cw;
|
||||
s[ 1 ] = (float)(sub[ 0 ]+sub[ 2 ]) / (float)cw;
|
||||
t[ 0 ] = (float)sub[ 1 ] / (float)ch;
|
||||
t[ 1 ] = (float)(sub[ 1 ]+sub[ 3 ]) / (float)ch;
|
||||
surface()->DrawTexturedSubRect(
|
||||
_pos[0],
|
||||
_pos[1],
|
||||
_pos[0] + _wide,
|
||||
_pos[1] + _tall,
|
||||
s[ 0 ],
|
||||
t[ 0 ],
|
||||
s[ 1 ],
|
||||
t[ 1 ] );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ensures the bitmap has been uploaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::ForceUpload()
|
||||
{
|
||||
if ( !_valid || _uploaded )
|
||||
return;
|
||||
|
||||
if ( _id == SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
_id = surface()->CreateNewTextureID( false );
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( _id, _filename, _filtered, false );
|
||||
|
||||
_uploaded = true;
|
||||
|
||||
_valid = surface()->IsTextureIDValid( _id );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
HTexture CSubRectImage::GetID()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
bool CSubRectImage::IsValid()
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "vgui_controls/subrectimage.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui_controls/Controls.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
// Officially the invalid texture ID is zero, but -1 is used in many
|
||||
// places, and changing it carries some risk. Adding a named constant
|
||||
// for this file avoids warnings and makes future changes easier.
|
||||
const HTexture SUBRECT_INVALID_TEXTURE = (HTexture)-1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSubRectImage::CSubRectImage( const char *filename, bool hardwareFiltered, int subx, int suby, int subw, int subh )
|
||||
{
|
||||
SetSize( subw, subh );
|
||||
sub[ 0 ] = subx;
|
||||
sub[ 1 ] = suby;
|
||||
sub[ 2 ] = subw;
|
||||
sub[ 3 ] = subh;
|
||||
|
||||
_filtered = hardwareFiltered;
|
||||
// HACKHACK - force VGUI materials to be in the vgui/ directory
|
||||
// This needs to be revisited once GoldSRC is grandfathered off.
|
||||
//!! need to make this work with goldsrc
|
||||
int size = strlen(filename) + 1 + strlen("vgui/");
|
||||
_filename = (char *)malloc( size );
|
||||
Assert( _filename );
|
||||
|
||||
Q_snprintf( _filename, size, "vgui/%s", filename );
|
||||
|
||||
_id = SUBRECT_INVALID_TEXTURE;
|
||||
_uploaded = false;
|
||||
_color = Color(255, 255, 255, 255);
|
||||
_pos[0] = _pos[1] = 0;
|
||||
_valid = true;
|
||||
_wide = subw;
|
||||
_tall = subh;
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
CSubRectImage::~CSubRectImage()
|
||||
{
|
||||
if ( vgui::surface() && _id != SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( _id );
|
||||
_id = SUBRECT_INVALID_TEXTURE;
|
||||
}
|
||||
|
||||
if ( _filename )
|
||||
{
|
||||
free( _filename );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = _wide;
|
||||
tall = _tall;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
wide = 0;
|
||||
tall = 0;
|
||||
|
||||
if (!_valid)
|
||||
return;
|
||||
|
||||
if ( _id != SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
surface()->DrawGetTextureSize(_id, wide, tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ignored
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetSize(int x, int y)
|
||||
{
|
||||
_wide = x;
|
||||
_tall = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetPos(int x, int y)
|
||||
{
|
||||
_pos[0] = x;
|
||||
_pos[1] = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::SetColor(Color col)
|
||||
{
|
||||
_color = col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the file name of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSubRectImage::GetName()
|
||||
{
|
||||
return _filename;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Renders the loaded image, uploading it if necessary
|
||||
// Assumes a valid image is always returned from uploading
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::Paint()
|
||||
{
|
||||
if ( !_valid )
|
||||
return;
|
||||
|
||||
// if we don't have an _id then lets make one
|
||||
if ( _id == SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
_id = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
// if we have not uploaded yet, lets go ahead and do so
|
||||
if ( !_uploaded )
|
||||
{
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
// set the texture current, set the color, and draw the biatch
|
||||
surface()->DrawSetColor( _color[0], _color[1], _color[2], _color[3] );
|
||||
surface()->DrawSetTexture( _id );
|
||||
|
||||
if ( _wide == 0 || _tall == 0 )
|
||||
return;
|
||||
|
||||
int cw, ch;
|
||||
GetContentSize( cw, ch );
|
||||
if ( cw == 0 || ch == 0 )
|
||||
return;
|
||||
|
||||
float s[ 2 ];
|
||||
float t[ 2 ];
|
||||
|
||||
s[ 0 ] = (float)sub[ 0 ] / (float)cw;
|
||||
s[ 1 ] = (float)(sub[ 0 ]+sub[ 2 ]) / (float)cw;
|
||||
t[ 0 ] = (float)sub[ 1 ] / (float)ch;
|
||||
t[ 1 ] = (float)(sub[ 1 ]+sub[ 3 ]) / (float)ch;
|
||||
surface()->DrawTexturedSubRect(
|
||||
_pos[0],
|
||||
_pos[1],
|
||||
_pos[0] + _wide,
|
||||
_pos[1] + _tall,
|
||||
s[ 0 ],
|
||||
t[ 0 ],
|
||||
s[ 1 ],
|
||||
t[ 1 ] );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ensures the bitmap has been uploaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSubRectImage::ForceUpload()
|
||||
{
|
||||
if ( !_valid || _uploaded )
|
||||
return;
|
||||
|
||||
if ( _id == SUBRECT_INVALID_TEXTURE )
|
||||
{
|
||||
_id = surface()->CreateNewTextureID( false );
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( _id, _filename, _filtered, false );
|
||||
|
||||
_uploaded = true;
|
||||
|
||||
_valid = surface()->IsTextureIDValid( _id );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
HTexture CSubRectImage::GetID()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
bool CSubRectImage::IsValid()
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,216 +1,216 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// VGUI_CONTROLS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$macro SRCDIR "..\.."
|
||||
$Macro GENERATED_PROTO_DIR "generated_proto"
|
||||
$macro PROTOBUF_LITE 0
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
$include "$SRCDIR\vpc_scripts\protobuf_builder.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\thirdparty;$SRCDIR\thirdparty\cef;$GENERATED_PROTO_DIR"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "vgui_controls"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "AnalogBar.cpp"
|
||||
$File "AnimatingImagePanel.cpp"
|
||||
$File "AnimationController.cpp"
|
||||
$File "BitmapImagePanel.cpp"
|
||||
$File "BuildFactoryHelper.cpp"
|
||||
$File "BuildGroup.cpp"
|
||||
$File "BuildModeDialog.cpp"
|
||||
$File "Button.cpp"
|
||||
$File "CheckButton.cpp"
|
||||
$File "CheckButtonList.cpp"
|
||||
$File "CircularProgressBar.cpp"
|
||||
$File "ComboBox.cpp"
|
||||
$File "consoledialog.cpp"
|
||||
$File "ControllerMap.cpp"
|
||||
$File "controls.cpp"
|
||||
$File "CvarToggleCheckButton.cpp"
|
||||
$File "DirectorySelectDialog.cpp"
|
||||
$File "Divider.cpp"
|
||||
$File "EditablePanel.cpp"
|
||||
$File "ExpandButton.cpp"
|
||||
$File "FileOpenDialog.cpp"
|
||||
$File "FileOpenStateMachine.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp"
|
||||
$File "FocusNavGroup.cpp"
|
||||
$File "Frame.cpp"
|
||||
$File "GraphPanel.cpp"
|
||||
$File "HTML.cpp"
|
||||
$File "Image.cpp"
|
||||
$File "ImageList.cpp"
|
||||
$File "ImagePanel.cpp"
|
||||
$File "InputDialog.cpp"
|
||||
$File "KeyBindingHelpDialog.cpp"
|
||||
$File "KeyBoardEditorDialog.cpp"
|
||||
$File "KeyRepeat.cpp"
|
||||
$File "Label.cpp"
|
||||
$File "ListPanel.cpp"
|
||||
$File "ListViewPanel.cpp"
|
||||
$File "Menu.cpp"
|
||||
$File "MenuBar.cpp"
|
||||
$File "MenuButton.cpp"
|
||||
$File "MenuItem.cpp"
|
||||
$File "MessageBox.cpp"
|
||||
$File "MessageDialog.cpp"
|
||||
$File "Panel.cpp"
|
||||
$File "PanelListPanel.cpp"
|
||||
$File "PerforceFileExplorer.cpp"
|
||||
$File "PerforceFileList.cpp"
|
||||
$File "perforcefilelistframe.cpp"
|
||||
$File "ProgressBar.cpp"
|
||||
$File "ProgressBox.cpp"
|
||||
$File "PropertyDialog.cpp"
|
||||
$File "PropertyPage.cpp"
|
||||
$File "PropertySheet.cpp"
|
||||
$File "QueryBox.cpp"
|
||||
$File "RadioButton.cpp"
|
||||
$File "RichText.cpp"
|
||||
$File "RotatingProgressBar.cpp"
|
||||
$File "savedocumentquery.cpp"
|
||||
$File "ScalableImagePanel.cpp"
|
||||
$File "ScrollableEditablePanel.cpp"
|
||||
$File "ScrollBar.cpp"
|
||||
$File "ScrollBarSlider.cpp"
|
||||
$File "SectionedListPanel.cpp"
|
||||
$File "Slider.cpp"
|
||||
$File "Splitter.cpp"
|
||||
$File "subrectimage.cpp"
|
||||
$File "TextEntry.cpp"
|
||||
$File "TextImage.cpp"
|
||||
$File "ToggleButton.cpp"
|
||||
$File "Tooltip.cpp"
|
||||
$File "ToolWindow.cpp"
|
||||
$File "TreeView.cpp"
|
||||
$File "TreeViewListControl.cpp"
|
||||
$File "URLLabel.cpp"
|
||||
$File "WizardPanel.cpp"
|
||||
$File "WizardSubPanel.cpp"
|
||||
$File "$SRCDIR\public\html\htmlprotobuf.cpp"
|
||||
$File "$SRCDIR/vgui2/src/vgui_key_translation.cpp"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\vgui_controls\AnalogBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\AnimatingImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\AnimationController.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BitmapImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BuildGroup.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BuildModeDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Button.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CheckButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CheckButtonList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CircularProgressBar.h"
|
||||
$File "$SRCDIR\public\Color.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ComboBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\consoledialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ControllerMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Controls.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CvarToggleCheckButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\DialogManager.h"
|
||||
$File "$SRCDIR\public\vgui_controls\DirectorySelectDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Divider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\EditablePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ExpandButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FileOpenDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FileOpenStateMachine.h"
|
||||
$File "$SRCDIR\public\filesystem.h"
|
||||
$File "$SRCDIR\public\filesystem_helpers.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FocusNavGroup.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Frame.h"
|
||||
$File "$SRCDIR\public\vgui_controls\GraphPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\HTML.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Image.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ImageList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\InputDialog.h"
|
||||
$File "$SRCDIR\public\tier1\interface.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBindingHelpDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBindingMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBoardEditorDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyRepeat.h"
|
||||
$File "$SRCDIR\public\tier1\KeyValues.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Label.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ListViewPanel.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgoff.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgon.h"
|
||||
$File "$SRCDIR\public\tier1\mempool.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Menu.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuItem.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Panel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PanelAnimationVar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PanelListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PerforceFileExplorer.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PerforceFileList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\perforcefilelistframe.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PHandle.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ProgressBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ProgressBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertyDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertyPage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertySheet.h"
|
||||
$File "$SRCDIR\public\vgui_controls\QueryBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RadioButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RichText.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RotatingProgressBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\savedocumentquery.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScalableImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollableEditablePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollBarSlider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\SectionedListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Slider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Splitter.h"
|
||||
$File "$SRCDIR\public\vgui_controls\subrectimage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TextEntry.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TextImage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ToggleButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Tooltip.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ToolWindow.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TreeView.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TreeViewListControl.h"
|
||||
$File "$SRCDIR\public\vgui_controls\URLLabel.h"
|
||||
$File "$SRCDIR\public\tier1\utlmemory.h"
|
||||
$File "$SRCDIR\public\tier1\utlrbtree.h"
|
||||
$File "$SRCDIR\public\tier1\utlvector.h"
|
||||
$File "$SRCDIR\public\vgui_controls\WizardPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\WizardSubPanel.h"
|
||||
}
|
||||
|
||||
$Folder "Protobuf Files"
|
||||
{
|
||||
$File "$SRCDIR\vgui2\chromehtml\htmlmessages.proto"
|
||||
$DynamicFile "$GENERATED_PROTO_DIR\htmlmessages.pb.h"
|
||||
$DynamicFile "$GENERATED_PROTO_DIR\htmlmessages.pb.cc"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$Create/UsePrecompiledHeader "Not Using Precompiled Headers" [$WINDOWS]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// VGUI_CONTROLS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$macro SRCDIR "..\.."
|
||||
$Macro GENERATED_PROTO_DIR "generated_proto"
|
||||
$macro PROTOBUF_LITE 0
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
$include "$SRCDIR\vpc_scripts\protobuf_builder.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\thirdparty;$SRCDIR\thirdparty\cef;$GENERATED_PROTO_DIR"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "vgui_controls"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "AnalogBar.cpp"
|
||||
$File "AnimatingImagePanel.cpp"
|
||||
$File "AnimationController.cpp"
|
||||
$File "BitmapImagePanel.cpp"
|
||||
$File "BuildFactoryHelper.cpp"
|
||||
$File "BuildGroup.cpp"
|
||||
$File "BuildModeDialog.cpp"
|
||||
$File "Button.cpp"
|
||||
$File "CheckButton.cpp"
|
||||
$File "CheckButtonList.cpp"
|
||||
$File "CircularProgressBar.cpp"
|
||||
$File "ComboBox.cpp"
|
||||
$File "consoledialog.cpp"
|
||||
$File "ControllerMap.cpp"
|
||||
$File "controls.cpp"
|
||||
$File "CvarToggleCheckButton.cpp"
|
||||
$File "DirectorySelectDialog.cpp"
|
||||
$File "Divider.cpp"
|
||||
$File "EditablePanel.cpp"
|
||||
$File "ExpandButton.cpp"
|
||||
$File "FileOpenDialog.cpp"
|
||||
$File "FileOpenStateMachine.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp"
|
||||
$File "FocusNavGroup.cpp"
|
||||
$File "Frame.cpp"
|
||||
$File "GraphPanel.cpp"
|
||||
$File "HTML.cpp"
|
||||
$File "Image.cpp"
|
||||
$File "ImageList.cpp"
|
||||
$File "ImagePanel.cpp"
|
||||
$File "InputDialog.cpp"
|
||||
$File "KeyBindingHelpDialog.cpp"
|
||||
$File "KeyBoardEditorDialog.cpp"
|
||||
$File "KeyRepeat.cpp"
|
||||
$File "Label.cpp"
|
||||
$File "ListPanel.cpp"
|
||||
$File "ListViewPanel.cpp"
|
||||
$File "Menu.cpp"
|
||||
$File "MenuBar.cpp"
|
||||
$File "MenuButton.cpp"
|
||||
$File "MenuItem.cpp"
|
||||
$File "MessageBox.cpp"
|
||||
$File "MessageDialog.cpp"
|
||||
$File "Panel.cpp"
|
||||
$File "PanelListPanel.cpp"
|
||||
$File "PerforceFileExplorer.cpp"
|
||||
$File "PerforceFileList.cpp"
|
||||
$File "perforcefilelistframe.cpp"
|
||||
$File "ProgressBar.cpp"
|
||||
$File "ProgressBox.cpp"
|
||||
$File "PropertyDialog.cpp"
|
||||
$File "PropertyPage.cpp"
|
||||
$File "PropertySheet.cpp"
|
||||
$File "QueryBox.cpp"
|
||||
$File "RadioButton.cpp"
|
||||
$File "RichText.cpp"
|
||||
$File "RotatingProgressBar.cpp"
|
||||
$File "savedocumentquery.cpp"
|
||||
$File "ScalableImagePanel.cpp"
|
||||
$File "ScrollableEditablePanel.cpp"
|
||||
$File "ScrollBar.cpp"
|
||||
$File "ScrollBarSlider.cpp"
|
||||
$File "SectionedListPanel.cpp"
|
||||
$File "Slider.cpp"
|
||||
$File "Splitter.cpp"
|
||||
$File "subrectimage.cpp"
|
||||
$File "TextEntry.cpp"
|
||||
$File "TextImage.cpp"
|
||||
$File "ToggleButton.cpp"
|
||||
$File "Tooltip.cpp"
|
||||
$File "ToolWindow.cpp"
|
||||
$File "TreeView.cpp"
|
||||
$File "TreeViewListControl.cpp"
|
||||
$File "URLLabel.cpp"
|
||||
$File "WizardPanel.cpp"
|
||||
$File "WizardSubPanel.cpp"
|
||||
$File "$SRCDIR\public\html\htmlprotobuf.cpp"
|
||||
$File "$SRCDIR/vgui2/src/vgui_key_translation.cpp"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\vgui_controls\AnalogBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\AnimatingImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\AnimationController.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BitmapImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BuildGroup.h"
|
||||
$File "$SRCDIR\public\vgui_controls\BuildModeDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Button.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CheckButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CheckButtonList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CircularProgressBar.h"
|
||||
$File "$SRCDIR\public\Color.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ComboBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\consoledialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ControllerMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Controls.h"
|
||||
$File "$SRCDIR\public\vgui_controls\CvarToggleCheckButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\DialogManager.h"
|
||||
$File "$SRCDIR\public\vgui_controls\DirectorySelectDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Divider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\EditablePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ExpandButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FileOpenDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FileOpenStateMachine.h"
|
||||
$File "$SRCDIR\public\filesystem.h"
|
||||
$File "$SRCDIR\public\filesystem_helpers.h"
|
||||
$File "$SRCDIR\public\vgui_controls\FocusNavGroup.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Frame.h"
|
||||
$File "$SRCDIR\public\vgui_controls\GraphPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\HTML.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Image.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ImageList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\InputDialog.h"
|
||||
$File "$SRCDIR\public\tier1\interface.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBindingHelpDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBindingMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyBoardEditorDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\KeyRepeat.h"
|
||||
$File "$SRCDIR\public\tier1\KeyValues.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Label.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ListViewPanel.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgoff.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgon.h"
|
||||
$File "$SRCDIR\public\tier1\mempool.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Menu.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MenuItem.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\MessageMap.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Panel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PanelAnimationVar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PanelListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PerforceFileExplorer.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PerforceFileList.h"
|
||||
$File "$SRCDIR\public\vgui_controls\perforcefilelistframe.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PHandle.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ProgressBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ProgressBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertyDialog.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertyPage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\PropertySheet.h"
|
||||
$File "$SRCDIR\public\vgui_controls\QueryBox.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RadioButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RichText.h"
|
||||
$File "$SRCDIR\public\vgui_controls\RotatingProgressBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\savedocumentquery.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScalableImagePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollableEditablePanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollBar.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ScrollBarSlider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\SectionedListPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Slider.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Splitter.h"
|
||||
$File "$SRCDIR\public\vgui_controls\subrectimage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TextEntry.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TextImage.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ToggleButton.h"
|
||||
$File "$SRCDIR\public\vgui_controls\Tooltip.h"
|
||||
$File "$SRCDIR\public\vgui_controls\ToolWindow.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TreeView.h"
|
||||
$File "$SRCDIR\public\vgui_controls\TreeViewListControl.h"
|
||||
$File "$SRCDIR\public\vgui_controls\URLLabel.h"
|
||||
$File "$SRCDIR\public\tier1\utlmemory.h"
|
||||
$File "$SRCDIR\public\tier1\utlrbtree.h"
|
||||
$File "$SRCDIR\public\tier1\utlvector.h"
|
||||
$File "$SRCDIR\public\vgui_controls\WizardPanel.h"
|
||||
$File "$SRCDIR\public\vgui_controls\WizardSubPanel.h"
|
||||
}
|
||||
|
||||
$Folder "Protobuf Files"
|
||||
{
|
||||
$File "$SRCDIR\vgui2\chromehtml\htmlmessages.proto"
|
||||
$DynamicFile "$GENERATED_PROTO_DIR\htmlmessages.pb.h"
|
||||
$DynamicFile "$GENERATED_PROTO_DIR\htmlmessages.pb.cc"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$Create/UsePrecompiledHeader "Not Using Precompiled Headers" [$WINDOWS]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user