mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-04 18:09:53 +03:00
1
This commit is contained in:
1156
tools/toolutils/BaseToolSystem.cpp
Normal file
1156
tools/toolutils/BaseToolSystem.cpp
Normal file
File diff suppressed because it is too large
Load Diff
45
tools/toolutils/ConsolePage.cpp
Normal file
45
tools/toolutils/ConsolePage.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#include "toolutils/ConsolePage.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CConsolePage::CConsolePage( Panel *parent, bool bStatusVersion ) : BaseClass( parent, "ToolsConsole", bStatusVersion )
|
||||
{
|
||||
AddActionSignalTarget( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Submits a command
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsolePage::OnCommandSubmitted( const char *pCommand )
|
||||
{
|
||||
enginetools->Command( pCommand );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets up colors
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsolePage::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
m_PrintColor = GetSchemeColor("IFMConsole.TextColor", pScheme);
|
||||
m_DPrintColor = GetSchemeColor("IFMConsole.DevTextColor", pScheme);
|
||||
}
|
||||
251
tools/toolutils/ToolFileMenuButton.cpp
Normal file
251
tools/toolutils/ToolFileMenuButton.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Standard file menu
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/toolfilemenubutton.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "vgui_controls/frame.h"
|
||||
#include "vgui_controls/button.h"
|
||||
#include "vgui_controls/listpanel.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "p4lib/ip4.h"
|
||||
#include "vgui_controls/perforcefilelistframe.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global function to create the file menu
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton* CreateToolFileMenuButton( vgui::Panel *parent, const char *panelName,
|
||||
const char *text, vgui::Panel *pActionTarget, IFileMenuCallbacks *pCallbacks )
|
||||
{
|
||||
return new CToolFileMenuButton( parent, panelName, text, pActionTarget, pCallbacks );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolFileMenuButton::CToolFileMenuButton( vgui::Panel *pParent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget, IFileMenuCallbacks *pFileMenuCallback ) :
|
||||
BaseClass( pParent, panelName, text, pActionSignalTarget ), m_pFileMenuCallback( pFileMenuCallback )
|
||||
{
|
||||
Assert( pFileMenuCallback );
|
||||
|
||||
AddMenuItem( "new", "#ToolFileNew", new KeyValues( "OnNew" ), pActionSignalTarget, NULL, "file_new" );
|
||||
AddMenuItem( "open", "#ToolFileOpen", new KeyValues( "OnOpen" ), pActionSignalTarget, NULL, "file_open" );
|
||||
AddMenuItem( "save", "#ToolFileSave", new KeyValues( "OnSave" ), pActionSignalTarget, NULL, "file_save" );
|
||||
AddMenuItem( "saveas", "#ToolFileSaveAs", new KeyValues( "OnSaveAs" ), pActionSignalTarget );
|
||||
AddMenuItem( "close", "#ToolFileClose", new KeyValues( "OnClose" ), pActionSignalTarget );
|
||||
AddSeparator();
|
||||
|
||||
// Add the Perforce menu options only if there is a valid P4 interface (SDK users won't have this)
|
||||
if ( p4 )
|
||||
{
|
||||
m_pPerforce = new vgui::Menu( this, "Perforce" );
|
||||
m_pMenu->AddCascadingMenuItem( "#ToolPerforce", this, m_pPerforce );
|
||||
m_nPerforceAdd = m_pPerforce->AddMenuItem( "perforce_add", "#ToolPerforceAdd", new KeyValues( "OnPerforceAdd" ), this );
|
||||
m_nPerforceOpen = m_pPerforce->AddMenuItem( "perforce_open", "#ToolPerforceOpen", new KeyValues( "OnPerforceOpen" ), this );
|
||||
m_nPerforceRevert = m_pPerforce->AddMenuItem( "perforce_revert", "#ToolPerforceRevert", new KeyValues( "OnPerforceRevert" ), this );
|
||||
m_nPerforceSubmit = m_pPerforce->AddMenuItem( "perforce_submit", "#ToolPerforceSubmit", new KeyValues( "OnPerforceSubmit" ), this );
|
||||
m_pPerforce->AddSeparator();
|
||||
m_nPerforceP4Win = m_pPerforce->AddMenuItem( "perforce_p4win", "#ToolPerforceP4Win", new KeyValues( "OnPerforceP4Win" ), this );
|
||||
m_nPerforceListOpenFiles = m_pPerforce->AddMenuItem( "perforce_listopenfiles", "#ToolPerforceListOpenFiles", new KeyValues( "OnPerforceListOpenFiles" ), this );
|
||||
}
|
||||
|
||||
m_pRecentFiles = new vgui::Menu( this, "RecentFiles" );
|
||||
m_nRecentFiles = m_pMenu->AddCascadingMenuItem( "#ToolFileRecent", pActionSignalTarget, m_pRecentFiles );
|
||||
|
||||
AddMenuItem( "clearrecent", "#ToolFileClearRecent", new KeyValues ( "OnClearRecent" ), pActionSignalTarget );
|
||||
AddSeparator();
|
||||
AddMenuItem( "exit", "#ToolFileExit", new KeyValues ( "OnExit" ), pActionSignalTarget );
|
||||
|
||||
SetMenu( m_pMenu );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets called when the menu is shown
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnShowMenu( vgui::Menu *menu )
|
||||
{
|
||||
BaseClass::OnShowMenu( menu );
|
||||
|
||||
// Update the menu
|
||||
int nEnableMask = m_pFileMenuCallback->GetFileMenuItemsEnabled();
|
||||
|
||||
int id = m_Items.Find( "new" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_NEW) != 0 );
|
||||
id = m_Items.Find( "open" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_OPEN) != 0 );
|
||||
id = m_Items.Find( "save" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_SAVE) != 0 );
|
||||
id = m_Items.Find( "saveas" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_SAVEAS) != 0 );
|
||||
id = m_Items.Find( "close" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_CLOSE) != 0 );
|
||||
id = m_Items.Find( "clearrecent" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_CLEAR_RECENT) != 0 );
|
||||
|
||||
m_pRecentFiles->DeleteAllItems();
|
||||
|
||||
if ( (nEnableMask & IFileMenuCallbacks::FILE_RECENT) == 0 )
|
||||
{
|
||||
m_pMenu->SetItemEnabled( m_nRecentFiles, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->SetItemEnabled( m_nRecentFiles, true );
|
||||
m_pFileMenuCallback->AddRecentFilesToMenu( m_pRecentFiles );
|
||||
}
|
||||
|
||||
// We only have the Perforce menu items if we have valid p4 interface
|
||||
if ( p4 )
|
||||
{
|
||||
bool bP4Connected = p4->IsConnectedToServer();
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( bP4Connected && m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
bool bIsUnnamed = !Q_IsAbsolutePath( pPerforceFile );
|
||||
bool bOpenedForEdit = p4->GetFileState( pPerforceFile ) != P4FILE_UNOPENED;
|
||||
bool bFileInPerforce = p4->IsFileInPerforce( pPerforceFile );
|
||||
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceAdd, !bIsUnnamed && !bFileInPerforce && !bOpenedForEdit );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceOpen, !bIsUnnamed && bFileInPerforce && !bOpenedForEdit );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceRevert, !bIsUnnamed && bOpenedForEdit );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceSubmit, !bIsUnnamed && bOpenedForEdit );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceP4Win, !bIsUnnamed && bFileInPerforce || bOpenedForEdit );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceListOpenFiles, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceAdd, false );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceOpen, false );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceRevert, false );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceSubmit, false );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceP4Win, false );
|
||||
m_pPerforce->SetItemEnabled( m_nPerforceListOpenFiles, bP4Connected );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Perforce functions
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceAdd( )
|
||||
{
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Add Movie File to Perforce?", "Movie File", PERFORCE_ACTION_FILE_ADD );
|
||||
pPerforceFrame->AddFile( pPerforceFile );
|
||||
pPerforceFrame->DoModal( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Check out a file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceOpen( )
|
||||
{
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Check Out Movie File from Perforce?", "Movie File", PERFORCE_ACTION_FILE_EDIT );
|
||||
pPerforceFrame->AddFile( pPerforceFile );
|
||||
pPerforceFrame->DoModal( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Revert a file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceRevert( )
|
||||
{
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Revert Movie File Changes from Perforce?", "Movie File", PERFORCE_ACTION_FILE_REVERT );
|
||||
pPerforceFrame->AddFile( pPerforceFile );
|
||||
pPerforceFrame->DoModal( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Submit a file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceSubmit( )
|
||||
{
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Submit Movie File Changes to Perforce?", "Movie File", PERFORCE_ACTION_FILE_SUBMIT );
|
||||
pPerforceFrame->AddFile( pPerforceFile );
|
||||
pPerforceFrame->DoModal( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Open a file in p4win
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceP4Win( )
|
||||
{
|
||||
char pPerforceFile[MAX_PATH];
|
||||
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
|
||||
{
|
||||
if ( p4->IsFileInPerforce( pPerforceFile ) )
|
||||
{
|
||||
p4->OpenFileInP4Win( pPerforceFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show a file in p4win
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuButton::OnPerforceListOpenFiles( )
|
||||
{
|
||||
CUtlVector<P4File_t> openedFiles;
|
||||
p4->GetOpenedFileListInPath( "GAME", openedFiles );
|
||||
COperationFileListFrame *pOpenedFiles = new COperationFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Opened Files In Perforce", "File Name", false, true );
|
||||
|
||||
int nCount = openedFiles.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
const char *pOpenType = NULL;
|
||||
switch( openedFiles[i].m_eOpenState )
|
||||
{
|
||||
case P4FILE_OPENED_FOR_ADD:
|
||||
pOpenType = "Add";
|
||||
break;
|
||||
case P4FILE_OPENED_FOR_EDIT:
|
||||
pOpenType = "Edit";
|
||||
break;
|
||||
case P4FILE_OPENED_FOR_DELETE:
|
||||
pOpenType = "Delete";
|
||||
break;
|
||||
case P4FILE_OPENED_FOR_INTEGRATE:
|
||||
pOpenType = "Integrate";
|
||||
break;
|
||||
}
|
||||
|
||||
if ( pOpenType )
|
||||
{
|
||||
pOpenedFiles->AddOperation( pOpenType, p4->String( openedFiles[i].m_sLocalFile ) );
|
||||
}
|
||||
}
|
||||
|
||||
pOpenedFiles->DoModal( );
|
||||
}
|
||||
60
tools/toolutils/ToolHelpMenuButton.cpp
Normal file
60
tools/toolutils/ToolHelpMenuButton.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/toolswitchmenubutton.h"
|
||||
#include "vgui_controls/panel.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Menu to switch between tools
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolHelpMenuButton : public CToolMenuButton
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CToolHelpMenuButton, CToolMenuButton );
|
||||
|
||||
public:
|
||||
CToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget );
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global function to create the help menu
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton* CreateToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
|
||||
{
|
||||
return new CToolHelpMenuButton( toolName, helpBinding, parent, panelName, text, pActionTarget );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolHelpMenuButton::CToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) :
|
||||
BaseClass( parent, panelName, text, pActionTarget )
|
||||
{
|
||||
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolHelpShowHelp" );
|
||||
if ( fmt )
|
||||
{
|
||||
wchar_t desc[ 256 ];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( toolName, desc, sizeof( desc ) );
|
||||
|
||||
wchar_t buf[ 512 ];
|
||||
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
|
||||
|
||||
AddMenuItem( "help", buf, new KeyValues( "OnHelp" ), pActionTarget, NULL, helpBinding );
|
||||
}
|
||||
|
||||
SetMenu(m_pMenu);
|
||||
}
|
||||
185
tools/toolutils/ToolMenuButton.cpp
Normal file
185
tools/toolutils/ToolMenuButton.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "toolutils/toolmenubar.h"
|
||||
#include "toolutils/basetoolsystem.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "vgui_controls/KeyBindingMap.h"
|
||||
#include "vgui/ILocalize.h"
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton::CToolMenuButton( Panel *parent, const char *panelName, const char *text, Panel *actionTarget ) :
|
||||
BaseClass( parent, panelName, text ),
|
||||
m_pActionTarget( actionTarget )
|
||||
{
|
||||
m_pMenu = new Menu( this, "Menu" );
|
||||
}
|
||||
|
||||
void CToolMenuButton::Reset()
|
||||
{
|
||||
m_Items.RemoveAll();
|
||||
m_pMenu->DeleteAllItems();
|
||||
}
|
||||
|
||||
int CToolMenuButton::AddMenuItem( char const *itemName, const char *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
|
||||
{
|
||||
int id = m_pMenu->AddMenuItem(itemText, message, target, userData);
|
||||
MenuItem_t item;
|
||||
item.m_ItemID = id;
|
||||
if ( kbcommandname )
|
||||
{
|
||||
item.m_KeyBinding = kbcommandname;
|
||||
}
|
||||
m_Items.Insert( itemName, item );
|
||||
return id;
|
||||
}
|
||||
|
||||
int CToolMenuButton::AddCheckableMenuItem( char const *itemName, const char *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
|
||||
{
|
||||
int id = m_pMenu->AddCheckableMenuItem(itemText, message, target, userData);
|
||||
MenuItem_t item;
|
||||
item.m_ItemID = id;
|
||||
if ( kbcommandname )
|
||||
{
|
||||
item.m_KeyBinding = kbcommandname;
|
||||
}
|
||||
m_Items.Insert( itemName, item );
|
||||
return id;
|
||||
}
|
||||
|
||||
int CToolMenuButton::AddMenuItem( char const *itemName, const wchar_t *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
|
||||
{
|
||||
int id = m_pMenu->AddMenuItem(itemName, itemText, message, target, userData);
|
||||
MenuItem_t item;
|
||||
item.m_ItemID = id;
|
||||
if ( kbcommandname )
|
||||
{
|
||||
item.m_KeyBinding = kbcommandname;
|
||||
}
|
||||
m_Items.Insert( itemName, item );
|
||||
return id;
|
||||
}
|
||||
|
||||
int CToolMenuButton::AddCheckableMenuItem( char const *itemName, const wchar_t *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
|
||||
{
|
||||
int id = m_pMenu->AddCheckableMenuItem(itemName, itemText, message, target, userData);
|
||||
MenuItem_t item;
|
||||
item.m_ItemID = id;
|
||||
if ( kbcommandname )
|
||||
{
|
||||
item.m_KeyBinding = kbcommandname;
|
||||
}
|
||||
m_Items.Insert( itemName, item );
|
||||
return id;
|
||||
}
|
||||
|
||||
void CToolMenuButton::AddSeparator()
|
||||
{
|
||||
m_pMenu->AddSeparator();
|
||||
}
|
||||
|
||||
void CToolMenuButton::SetItemEnabled( int itemID, bool state )
|
||||
{
|
||||
m_pMenu->SetItemEnabled( m_Items[ itemID ].m_ItemID, state );
|
||||
}
|
||||
|
||||
int CToolMenuButton::FindMenuItem( char const *itemName )
|
||||
{
|
||||
int id = m_Items.Find( itemName );
|
||||
if ( id == m_Items.InvalidIndex() )
|
||||
return -1;
|
||||
return m_Items[ id ].m_ItemID;
|
||||
}
|
||||
|
||||
void CToolMenuButton::AddSeparatorAfterItem( char const *itemName )
|
||||
{
|
||||
int id = FindMenuItem( itemName );
|
||||
if ( id != -1 )
|
||||
{
|
||||
m_pMenu->AddSeparatorAfterItem( id );
|
||||
}
|
||||
}
|
||||
|
||||
void CToolMenuButton::MoveMenuItem( int itemID, int moveBeforeThisItemID )
|
||||
{
|
||||
m_pMenu->MoveMenuItem( itemID, moveBeforeThisItemID );
|
||||
}
|
||||
|
||||
void CToolMenuButton::SetCurrentKeyBindingLabel( char const *itemName, char const *binding )
|
||||
{
|
||||
int id = FindMenuItem( itemName );
|
||||
if ( id != -1 )
|
||||
{
|
||||
m_pMenu->SetCurrentKeyBinding( id, binding );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CToolMenuButton::UpdateMenuItemKeyBindings()
|
||||
{
|
||||
if ( !m_pActionTarget )
|
||||
return;
|
||||
|
||||
int c = m_Items.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
if ( !m_Items[ i ].m_KeyBinding.IsValid() )
|
||||
continue;
|
||||
|
||||
char const *bindingName = m_Items[ i ].m_KeyBinding.String();
|
||||
|
||||
CUtlVector< BoundKey_t * > list;
|
||||
m_pActionTarget->LookupBoundKeys( bindingName, list );
|
||||
if ( list.Count() <= 0 )
|
||||
continue;
|
||||
|
||||
BoundKey_t *kb = list[ 0 ];
|
||||
Assert( kb );
|
||||
|
||||
// Found it, now convert to binding string
|
||||
// First do modifiers
|
||||
wchar_t sz[ 256 ];
|
||||
wcsncpy( sz, Panel::KeyCodeModifiersToDisplayString( (KeyCode)kb->keycode, kb->modifiers ), 256 );
|
||||
sz[ 255 ] = L'\0';
|
||||
|
||||
char ansi[ 512 ];
|
||||
g_pVGuiLocalize->ConvertUnicodeToANSI( sz, ansi, sizeof( ansi ) );
|
||||
m_pMenu->SetCurrentKeyBinding( m_Items[ i ].m_ItemID, ansi );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CToolMenuButton::OnShowMenu( Menu *menu )
|
||||
{
|
||||
CToolMenuBar *bar = dynamic_cast< CToolMenuBar * >( GetParent() );
|
||||
if ( bar )
|
||||
{
|
||||
CBaseToolSystem *sys = bar->GetToolSystem();
|
||||
if ( sys )
|
||||
{
|
||||
sys->UpdateMenu( menu );
|
||||
}
|
||||
}
|
||||
|
||||
UpdateMenuItemKeyBindings();
|
||||
|
||||
m_pMenu->ForceCalculateWidth();
|
||||
}
|
||||
|
||||
vgui::Menu *CToolMenuButton::GetMenu()
|
||||
{
|
||||
return m_pMenu;
|
||||
}
|
||||
|
||||
|
||||
72
tools/toolutils/ToolSwitchMenuButton.cpp
Normal file
72
tools/toolutils/ToolSwitchMenuButton.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/toolswitchmenubutton.h"
|
||||
#include "vgui_controls/panel.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Menu to switch between tools
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolSwitchMenuButton : public CToolMenuButton
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CToolSwitchMenuButton, CToolMenuButton );
|
||||
|
||||
public:
|
||||
CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget );
|
||||
virtual void OnShowMenu(vgui::Menu *menu);
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global function to create the switch menu
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton* CreateToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
|
||||
{
|
||||
return new CToolSwitchMenuButton( parent, panelName, text, pActionTarget );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolSwitchMenuButton::CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) :
|
||||
BaseClass( parent, panelName, text, pActionTarget )
|
||||
{
|
||||
SetMenu(m_pMenu);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is called when the menu is made visible
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolSwitchMenuButton::OnShowMenu(vgui::Menu *menu)
|
||||
{
|
||||
BaseClass::OnShowMenu( menu );
|
||||
|
||||
Reset();
|
||||
|
||||
int c = enginetools->GetToolCount();
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
char const *toolname = enginetools->GetToolName( i );
|
||||
|
||||
char toolcmd[ 32 ];
|
||||
Q_snprintf( toolcmd, sizeof( toolcmd ), "OnTool%i", i );
|
||||
|
||||
int id = AddCheckableMenuItem( toolname, toolname, new KeyValues ( "Command", "command", toolcmd ), m_pActionTarget );
|
||||
m_pMenu->SetItemEnabled( id, true );
|
||||
m_pMenu->SetMenuItemChecked( id, enginetools->IsTopmostTool( enginetools->GetToolSystem( i ) ) );
|
||||
}
|
||||
}
|
||||
118
tools/toolutils/ToolUI.cpp
Normal file
118
tools/toolutils/ToolUI.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// The tool UI has 4 purposes:
|
||||
// 1) Create the menu bar and client area (lies under the menu bar)
|
||||
// 2) Forward all mouse messages to the tool workspace so action menus work
|
||||
// 3) Forward all commands to the tool system so all smarts can reside there
|
||||
// 4) Control the size of the menu bar + the working area
|
||||
//=============================================================================
|
||||
|
||||
#include "ToolUI.h"
|
||||
#include "toolutils/toolmenubar.h"
|
||||
#include "toolutils/basetoolsystem.h"
|
||||
#include "vgui/Cursor.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "toolutils/toolmenubar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
#define MENU_HEIGHT 28
|
||||
// Height of the status bar, if the tool installs one
|
||||
#define STATUS_HEIGHT 24
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolUI::CToolUI( vgui::Panel *pParent, const char *panelName, CBaseToolSystem *pBaseToolSystem ) :
|
||||
BaseClass( pParent, panelName ), m_pClientArea( 0 ), m_pBaseToolSystem( pBaseToolSystem )
|
||||
{
|
||||
SetPaintEnabled(false);
|
||||
SetPaintBackgroundEnabled(false);
|
||||
SetPaintBorderEnabled(false);
|
||||
|
||||
int w, h;
|
||||
pParent->GetSize( w, h );
|
||||
SetBounds( 0, 0, w, h );
|
||||
|
||||
m_pMenuBar = m_pBaseToolSystem->CreateMenuBar( m_pBaseToolSystem );
|
||||
m_pMenuBar->SetParent( this );
|
||||
m_pMenuBar->SetSize( w, MENU_HEIGHT );
|
||||
// This can be NULL if no status bar should be included
|
||||
m_pStatusBar = m_pBaseToolSystem->CreateStatusBar( this );
|
||||
m_pStatusBar->SetParent( this );
|
||||
|
||||
m_pClientArea = new vgui::Panel( this, "ClientArea" );
|
||||
m_pClientArea->SetMouseInputEnabled( false );
|
||||
m_pClientArea->SetCursor( vgui::dc_none );
|
||||
m_pClientArea->SetBounds( 0, MENU_HEIGHT, w, h - MENU_HEIGHT );
|
||||
}
|
||||
|
||||
vgui::Panel *CToolUI::GetClientArea()
|
||||
{
|
||||
return m_pClientArea;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The tool UI panel should always fill the space...
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolUI::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
// Make the editor panel fill the space
|
||||
int iWidth, iHeight;
|
||||
vgui::VPANEL parent = GetParent() ? GetParent()->GetVPanel() : vgui::surface()->GetEmbeddedPanel();
|
||||
vgui::ipanel()->GetSize( parent, iWidth, iHeight );
|
||||
SetSize( iWidth, iHeight );
|
||||
int insettop = MENU_HEIGHT;
|
||||
int insetbottom = 0;
|
||||
m_pMenuBar->SetSize( iWidth, insettop );
|
||||
if ( m_pStatusBar )
|
||||
{
|
||||
insetbottom = STATUS_HEIGHT;
|
||||
m_pStatusBar->SetBounds( 0, iHeight - insetbottom, iWidth, insetbottom );
|
||||
}
|
||||
m_pClientArea->SetBounds( 0, insettop, iWidth, iHeight - insettop - insetbottom );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::MenuBar *CToolUI::GetMenuBar()
|
||||
{
|
||||
return m_pMenuBar;
|
||||
}
|
||||
|
||||
vgui::Panel *CToolUI::GetStatusBar()
|
||||
{
|
||||
return m_pStatusBar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward commands to systems that have more smarts than I do!
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolUI::OnMousePressed( vgui::MouseCode code )
|
||||
{
|
||||
// Chain mouse pressed calls to the parent tool workspace
|
||||
CallParentFunction( new KeyValues( "MousePressed", "code", code ) );
|
||||
}
|
||||
|
||||
void CToolUI::OnCommand( const char *cmd )
|
||||
{
|
||||
m_pBaseToolSystem->OnCommand( cmd );
|
||||
}
|
||||
|
||||
void CToolUI::UpdateMenuBarTitle()
|
||||
{
|
||||
CToolFileMenuBar *mb = dynamic_cast< CToolFileMenuBar * >( GetMenuBar() );
|
||||
if ( mb )
|
||||
{
|
||||
char title[ 64 ];
|
||||
m_pBaseToolSystem->ComputeMenuBarTitle( title, sizeof( title ) );
|
||||
mb->SetInfo( title );
|
||||
}
|
||||
}
|
||||
66
tools/toolutils/ToolUI.h
Normal file
66
tools/toolutils/ToolUI.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// The tool UI has 4 purposes:
|
||||
// 1) Create the menu bar and client area (lies under the menu bar)
|
||||
// 2) Forward all mouse messages to the tool workspace so action menus work
|
||||
// 3) Forward all commands to the tool system so all smarts can reside there
|
||||
// 4) Control the size of the menu bar + the working area
|
||||
//=============================================================================
|
||||
|
||||
#ifndef TOOLUI_H
|
||||
#define TOOLUI_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vgui_controls/panel.h"
|
||||
#include "vgui/mousecode.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseToolSystem;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class MenuBar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The tool UI has 4 purposes:
|
||||
// 1) Create the menu bar and client area (lies under the menu bar)
|
||||
// 2) Forward all mouse messages to the tool workspace so action menus work
|
||||
// 3) Forward all commands to the tool system so all smarts can reside there
|
||||
// 4) Control the size of the menu bar + the working area
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolUI : public vgui::Panel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CToolUI, vgui::Panel );
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
CToolUI( vgui::Panel *pParent, const char *pPanelName, CBaseToolSystem *pBaseToolSystem );
|
||||
|
||||
// Overrides of panel methods
|
||||
virtual void PerformLayout();
|
||||
virtual void OnCommand( const char *cmd );
|
||||
virtual void OnMousePressed( vgui::MouseCode code );
|
||||
|
||||
virtual void UpdateMenuBarTitle();
|
||||
|
||||
// Other public methods
|
||||
vgui::MenuBar *GetMenuBar();
|
||||
vgui::Panel *GetClientArea();
|
||||
vgui::Panel *GetStatusBar();
|
||||
|
||||
private:
|
||||
vgui::MenuBar *m_pMenuBar;
|
||||
vgui::Panel *m_pStatusBar;
|
||||
vgui::Panel *m_pClientArea;
|
||||
CBaseToolSystem *m_pBaseToolSystem;
|
||||
};
|
||||
|
||||
|
||||
#endif // TOOLUI_H
|
||||
137
tools/toolutils/attributeelementchoicelist.cpp
Normal file
137
tools/toolutils/attributeelementchoicelist.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "toolutils/attributeelementchoicelist.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
|
||||
|
||||
typedef CUtlRBTree< CDmElement *, int > ElementDict_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns the choice string that AddElementsRecursively would have returned
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *GetChoiceString( CDmElement *pElement )
|
||||
{
|
||||
return pElement->GetName();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recursively adds all elements referred to this element into the list of elements
|
||||
//-----------------------------------------------------------------------------
|
||||
void AddElementsRecursively_R( CDmElement *pElement, ElementChoiceList_t &list, ElementDict_t &dict, const char *pElementType )
|
||||
{
|
||||
if ( !pElement )
|
||||
return;
|
||||
|
||||
if ( dict.Find( pElement ) != dict.InvalidIndex() )
|
||||
return;
|
||||
|
||||
dict.Insert( pElement );
|
||||
|
||||
if ( pElement->IsA( pElementType ) )
|
||||
{
|
||||
int nIndex = list.AddToTail( );
|
||||
ElementChoice_t &entry = list[nIndex];
|
||||
entry.m_pValue = pElement;
|
||||
entry.m_pChoiceString = GetChoiceString( pElement );
|
||||
}
|
||||
|
||||
for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
char const *attributeName = pAttribute->GetName( );
|
||||
DmAttributeType_t attrType = pAttribute->GetType( );
|
||||
if ( attrType == AT_ELEMENT )
|
||||
{
|
||||
CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
|
||||
AddElementsRecursively_R( pChild, list, dict, pElementType );
|
||||
}
|
||||
else if ( attrType == AT_ELEMENT_ARRAY )
|
||||
{
|
||||
const CDmrElementArray<CDmElement> children( pElement, attributeName );
|
||||
uint n = children.Count();
|
||||
for ( uint i = 0; i < n; ++i )
|
||||
{
|
||||
CDmElement *pChild = children[ i ];
|
||||
AddElementsRecursively_R( pChild, list, dict, pElementType );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recursively adds all elements referred to this element into the list of elements
|
||||
//-----------------------------------------------------------------------------
|
||||
void AddElementsRecursively_R( CDmElement *pElement, DmeHandleVec_t &list, ElementDict_t &dict, const char *pElementType )
|
||||
{
|
||||
if ( !pElement )
|
||||
return;
|
||||
|
||||
if ( dict.Find( pElement ) != dict.InvalidIndex() )
|
||||
return;
|
||||
|
||||
dict.Insert( pElement );
|
||||
|
||||
if ( pElement->IsA( pElementType ) )
|
||||
{
|
||||
int nIndex = list.AddToTail( );
|
||||
list[nIndex] = pElement;
|
||||
}
|
||||
|
||||
for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
char const *attributeName = pAttribute->GetName( );
|
||||
DmAttributeType_t attrType = pAttribute->GetType( );
|
||||
if ( attrType == AT_ELEMENT )
|
||||
{
|
||||
CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
|
||||
AddElementsRecursively_R( pChild, list, dict, pElementType );
|
||||
}
|
||||
else if ( attrType == AT_ELEMENT_ARRAY )
|
||||
{
|
||||
const CDmrElementArray<CDmElement> children( pElement, attributeName );
|
||||
uint n = children.Count();
|
||||
for ( uint i = 0; i < n; ++i )
|
||||
{
|
||||
CDmElement *pChild = children[ i ];
|
||||
AddElementsRecursively_R( pChild, list, dict, pElementType );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recursively adds all elements referred to this element into the list of elements
|
||||
//-----------------------------------------------------------------------------
|
||||
void AddElementsRecursively( CDmElement *obj, ElementChoiceList_t &list, const char *pElementType )
|
||||
{
|
||||
if ( !pElementType )
|
||||
{
|
||||
pElementType = g_pDataModel->GetString( CDmElement::GetStaticTypeSymbol() );
|
||||
}
|
||||
|
||||
ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
|
||||
AddElementsRecursively_R( obj, list, dict, pElementType );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recursively adds all elements of the specified type under pElement into the vector
|
||||
//-----------------------------------------------------------------------------
|
||||
void AddElementsRecursively( CDmElement *pElement, DmeHandleVec_t &list, const char *pElementType )
|
||||
{
|
||||
if ( !pElementType )
|
||||
{
|
||||
pElementType = g_pDataModel->GetString( CDmElement::GetStaticTypeSymbol() );
|
||||
}
|
||||
|
||||
ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
|
||||
AddElementsRecursively_R( pElement, list, dict, pElementType );
|
||||
}
|
||||
47
tools/toolutils/basepropertiescontainer.cpp
Normal file
47
tools/toolutils/basepropertiescontainer.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/basepropertiescontainer.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
CBasePropertiesContainer::CBasePropertiesContainer( vgui::Panel *parent, IDmNotify *pNotify, CDmeEditorTypeDictionary *pDict /*=NULL*/ )
|
||||
: BaseClass( parent, pNotify, NULL, true, pDict )
|
||||
{
|
||||
SetDropEnabled( true );
|
||||
}
|
||||
|
||||
bool CBasePropertiesContainer::IsDroppable( CUtlVector< KeyValues * >& msglist )
|
||||
{
|
||||
if ( msglist.Count() != 1 )
|
||||
return false;
|
||||
|
||||
KeyValues *data = msglist[ 0 ];
|
||||
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( data->GetInt( "dmeelement", DMELEMENT_HANDLE_INVALID ) ) ) );
|
||||
if ( !ptr )
|
||||
return false;
|
||||
|
||||
if ( ptr == GetObject() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CBasePropertiesContainer::OnPanelDropped( CUtlVector< KeyValues * >& msglist )
|
||||
{
|
||||
if ( msglist.Count() != 1 )
|
||||
return;
|
||||
|
||||
KeyValues *data = msglist[ 0 ];
|
||||
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( data->GetInt( "dmeelement", DMELEMENT_HANDLE_INVALID ) ) ) );
|
||||
if ( !ptr )
|
||||
return;
|
||||
|
||||
// Already browsing
|
||||
if ( ptr == GetObject() )
|
||||
return;
|
||||
|
||||
SetObject( ptr );
|
||||
}
|
||||
151
tools/toolutils/basestatusbar.cpp
Normal file
151
tools/toolutils/basestatusbar.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/basestatusbar.h"
|
||||
#include "toolutils/ConsolePage.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "vgui/IVGui.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
CBaseStatusBar::CBaseStatusBar( vgui::Panel *parent, char const *panelName )
|
||||
: BaseClass( parent, panelName ),
|
||||
m_flLastFPSSnapShot( -1.0f )
|
||||
{
|
||||
SetVisible( true );
|
||||
m_pConsole = new CConsolePage( this, true );
|
||||
m_pLabel = new Label( this, "Console", "#BxConsole" );
|
||||
m_pMemory = new Label( this, "Memory", "" );
|
||||
m_pFPS = new Label( this, "FPS", "" );
|
||||
m_pGameTime = new Label( this, "GameTime", "" );
|
||||
|
||||
MakePopup( false );
|
||||
|
||||
UpdateMemoryUsage( 9.999 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Forces console to take up full area except right edge
|
||||
// Input : -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseStatusBar::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
int oldw = w;
|
||||
|
||||
w *= 0.45f;
|
||||
|
||||
int x = 8;
|
||||
|
||||
int cw, ch;
|
||||
m_pLabel->GetContentSize( cw, ch );
|
||||
m_pLabel->SetBounds( x, 4, cw, h - 8 );
|
||||
|
||||
x += cw + 4;
|
||||
|
||||
int consoleWide = w - x - 8;
|
||||
|
||||
m_pConsole->SetBounds( x, 2, consoleWide, h - 4 );
|
||||
|
||||
x += consoleWide + 4;
|
||||
|
||||
int infoW = 85;
|
||||
|
||||
int rightx = oldw - infoW - 10;
|
||||
m_pFPS->SetBounds( rightx, 2, infoW - 2 - 10, h - 8 );
|
||||
rightx -= infoW;
|
||||
m_pGameTime->SetBounds( rightx, 2, infoW - 2, h - 8 );
|
||||
rightx -= infoW;
|
||||
m_pMemory->SetBounds( rightx, 2, infoW - 2, h - 8 );
|
||||
}
|
||||
|
||||
void CBaseStatusBar::UpdateMemoryUsage( float mbUsed )
|
||||
{
|
||||
char mem[ 256 ];
|
||||
Q_snprintf( mem, sizeof( mem ), "[mem: %.2f Mb]", mbUsed );
|
||||
m_pMemory->SetText( mem );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Message map
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseStatusBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
// get the borders we need
|
||||
SetBorder(pScheme->GetBorder("ButtonBorder"));
|
||||
|
||||
// get the background color
|
||||
SetBgColor(pScheme->GetColor( "StatusBar.BgColor", GetBgColor() ));
|
||||
|
||||
m_pLabel->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
|
||||
m_pMemory->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
|
||||
m_pFPS->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
|
||||
m_pGameTime->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
|
||||
}
|
||||
|
||||
static float GetMemoryUsage();
|
||||
|
||||
void CBaseStatusBar::OnThink()
|
||||
{
|
||||
BaseClass::OnThink();
|
||||
|
||||
float curtime = enginetools->GetRealTime();
|
||||
|
||||
char gt[ 32 ];
|
||||
Q_snprintf( gt, sizeof( gt ), "[game: %.3f]", enginetools->ServerTime() );
|
||||
m_pGameTime->SetText( gt );
|
||||
|
||||
float elapsed = curtime - m_flLastFPSSnapShot;
|
||||
if ( elapsed < 0.4f )
|
||||
return;
|
||||
|
||||
m_flLastFPSSnapShot = curtime;
|
||||
|
||||
float ft = enginetools->GetRealFrameTime();
|
||||
if ( ft <= 0.0f )
|
||||
{
|
||||
m_pFPS->SetText( "[fps: ??]" );
|
||||
}
|
||||
else
|
||||
{
|
||||
char fps[ 32 ];
|
||||
Q_snprintf( fps, sizeof( fps ), "[fps: %.1f]", 1.0f / ft );
|
||||
m_pFPS->SetText( fps );
|
||||
}
|
||||
|
||||
UpdateMemoryUsage( GetMemoryUsage() );
|
||||
}
|
||||
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
static float GetMemoryUsage()
|
||||
{
|
||||
PROCESS_MEMORY_COUNTERS counters;
|
||||
counters.cb = sizeof( counters );
|
||||
|
||||
if ( GetProcessMemoryInfo( GetCurrentProcess(), &counters, sizeof( counters ) ) )
|
||||
{
|
||||
return (float)counters.WorkingSetSize / ( 1024.0f * 1024.0f );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
457
tools/toolutils/miniviewport.cpp
Normal file
457
tools/toolutils/miniviewport.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/miniviewport.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/MaterialSystemUtil.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "materialsystem/itexture.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "VGuiMatSurface/IMatSystemSurface.h"
|
||||
#include "view_shared.h"
|
||||
#include "texture_group_names.h"
|
||||
#include "vgui_controls/PropertySheet.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include <windows.h> // for MultiByteToWideChar
|
||||
#include "cdll_int.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
class CMiniViewportEngineRenderArea;
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
extern IMatSystemSurface *g_pMatSystemSurface;
|
||||
|
||||
#define DEFAULT_PREVIEW_WIDTH 1280
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: This is a "frame" which is used to position the engine
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMiniViewportPropertyPage : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CMiniViewportPropertyPage, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CMiniViewportPropertyPage( Panel *parent, const char *panelName );
|
||||
|
||||
virtual Color GetBgColor();
|
||||
|
||||
void GetEngineBounds( int& x, int& y, int& w, int& h );
|
||||
|
||||
void RenderFrameBegin();
|
||||
|
||||
CMiniViewportEngineRenderArea *GetViewportArea() { return m_pViewportArea; }
|
||||
|
||||
private:
|
||||
virtual void PerformLayout();
|
||||
|
||||
Color m_bgColor;
|
||||
|
||||
CMiniViewportEngineRenderArea *m_pViewportArea;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// the actual renderable area
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMiniViewportEngineRenderArea : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CMiniViewportEngineRenderArea, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CMiniViewportEngineRenderArea( Panel *parent, const char *panelName );
|
||||
~CMiniViewportEngineRenderArea();
|
||||
|
||||
virtual void PaintBackground();
|
||||
virtual void GetEngineBounds( int& x, int& y, int& w, int& h );
|
||||
virtual void ApplySchemeSettings( IScheme *pScheme );
|
||||
|
||||
void RenderFrameBegin();
|
||||
void SetOverlayText( const char *pText );
|
||||
|
||||
// Called when the layoff texture needs to be released
|
||||
void ReleaseLayoffTexture();
|
||||
|
||||
protected:
|
||||
void InitSceneMaterials();
|
||||
void ShutdownSceneMaterials();
|
||||
|
||||
// Paints the black borders around the engine window
|
||||
void PaintEngineBorders( int x, int y, int w, int h );
|
||||
|
||||
// Paints the engine window itself
|
||||
void PaintEngineWindow( int x, int y, int w, int h );
|
||||
|
||||
// Paints the overlay text
|
||||
void PaintOverlayText( );
|
||||
|
||||
int m_nEngineOutputTexture;
|
||||
vgui::HFont m_OverlayTextFont;
|
||||
CUtlString m_OverlayText;
|
||||
|
||||
CTextureReference m_ScreenBuffer;
|
||||
CMaterialReference m_ScreenMaterial;
|
||||
};
|
||||
|
||||
|
||||
CMiniViewportEngineRenderArea::CMiniViewportEngineRenderArea( Panel *parent, const char *panelName )
|
||||
: BaseClass( parent, panelName )
|
||||
{
|
||||
SetPaintEnabled( false );
|
||||
SetPaintBorderEnabled( false );
|
||||
SetPaintBackgroundEnabled( true );
|
||||
|
||||
m_nEngineOutputTexture = vgui::surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
CMiniViewportEngineRenderArea::~CMiniViewportEngineRenderArea()
|
||||
{
|
||||
ShutdownSceneMaterials();
|
||||
}
|
||||
|
||||
void CMiniViewportEngineRenderArea::RenderFrameBegin()
|
||||
{
|
||||
if ( !enginetools->IsInGame() )
|
||||
return;
|
||||
|
||||
InitSceneMaterials();
|
||||
|
||||
CViewSetup playerViewSetup;
|
||||
int x, y, w, h;
|
||||
GetEngineBounds( x, y, w, h );
|
||||
enginetools->GetPlayerView( playerViewSetup, 0, 0, w, h );
|
||||
|
||||
// NOTE: This is a workaround to a nasty problem. Vgui uses stencil
|
||||
// to determing if the panels should occlude each other. The engine
|
||||
// has now started to use stencil for various random effects.
|
||||
// To prevent these different stencil uses from clashing, we will
|
||||
// render the engine prior to vgui painting + cache the result off in
|
||||
//
|
||||
// Make the engine draw the scene
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->PushRenderTargetAndViewport( m_ScreenBuffer, 0, 0, w, h );
|
||||
|
||||
// Tell the engine to tell the client to render the view (sans viewmodel)
|
||||
enginetools->SetMainView( playerViewSetup.origin, playerViewSetup.angles );
|
||||
enginetools->RenderView( playerViewSetup, VIEW_CLEAR_COLOR | VIEW_CLEAR_DEPTH, RENDERVIEW_DRAWHUD | RENDERVIEW_DRAWVIEWMODEL );
|
||||
|
||||
// Pop the target
|
||||
pRenderContext->PopRenderTargetAndViewport();
|
||||
}
|
||||
|
||||
void CMiniViewportEngineRenderArea::InitSceneMaterials()
|
||||
{
|
||||
if ( m_ScreenBuffer )
|
||||
return;
|
||||
|
||||
if ( g_pMaterialSystem->IsTextureLoaded( "_rt_LayoffResult" ) )
|
||||
{
|
||||
ITexture *pTexture = g_pMaterialSystem->FindTexture( "_rt_LayoffResult", TEXTURE_GROUP_RENDER_TARGET );
|
||||
m_ScreenBuffer.Init( pTexture );
|
||||
}
|
||||
else
|
||||
{
|
||||
// For now, layoff dimensions match aspect of back buffer
|
||||
int nBackBufferWidth, nBackBufferHeight;
|
||||
g_pMaterialSystem->GetBackBufferDimensions( nBackBufferWidth, nBackBufferHeight );
|
||||
float flAspect = nBackBufferWidth / (float)nBackBufferHeight;
|
||||
int nPreviewWidth = min( DEFAULT_PREVIEW_WIDTH, nBackBufferWidth );
|
||||
int nPreviewHeight = ( int )( nPreviewWidth / flAspect + 0.5f );
|
||||
|
||||
g_pMaterialSystem->BeginRenderTargetAllocation(); // Begin allocating RTs which IFM can scribble into
|
||||
|
||||
// LDR final result of either HDR or LDR rendering
|
||||
m_ScreenBuffer.Init( g_pMaterialSystem->CreateNamedRenderTargetTextureEx2(
|
||||
"_rt_LayoffResult", nPreviewWidth, nPreviewHeight, RT_SIZE_OFFSCREEN,
|
||||
g_pMaterialSystem->GetBackBufferFormat(), MATERIAL_RT_DEPTH_SHARED, TEXTUREFLAGS_BORDER ) );
|
||||
|
||||
g_pMaterialSystem->EndRenderTargetAllocation(); // End allocating RTs which IFM can scribble into
|
||||
}
|
||||
|
||||
KeyValues *pVMTKeyValues = NULL;
|
||||
pVMTKeyValues= new KeyValues( "UnlitGeneric" );
|
||||
pVMTKeyValues->SetString( "$basetexture", m_ScreenBuffer->GetName() );
|
||||
pVMTKeyValues->SetInt( "$nofog", 1 );
|
||||
m_ScreenMaterial.Init( "MiniViewportEngineRenderAreaSceneMaterial", pVMTKeyValues );
|
||||
m_ScreenMaterial->Refresh();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the layoff texture needs to be released
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::ReleaseLayoffTexture()
|
||||
{
|
||||
m_ScreenBuffer.Shutdown();
|
||||
m_ScreenMaterial.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Apply scheme settings
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::ApplySchemeSettings( IScheme *pScheme )
|
||||
{
|
||||
BaseClass::ApplySchemeSettings( pScheme );
|
||||
m_OverlayTextFont = pScheme->GetFont( "DefaultLargeOutline" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::ShutdownSceneMaterials()
|
||||
{
|
||||
m_ScreenBuffer.Shutdown();
|
||||
m_ScreenMaterial.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets text to draw over the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::SetOverlayText( const char *pText )
|
||||
{
|
||||
m_OverlayText = pText;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Paints the black borders around the engine window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::PaintEngineBorders( int x, int y, int w, int h )
|
||||
{
|
||||
// Draws black borders around the engine window
|
||||
surface()->DrawSetColor( Color( 0, 0, 0, 255 ) );
|
||||
if ( x != 0 )
|
||||
{
|
||||
surface()->DrawFilledRect( 0, 0, x, h );
|
||||
surface()->DrawFilledRect( x + w, 0, w + 2 * x, h );
|
||||
}
|
||||
else if ( y != 0 )
|
||||
{
|
||||
surface()->DrawFilledRect( 0, 0, w, y );
|
||||
surface()->DrawFilledRect( 0, y + h, w, h + 2 * y );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Paints the overlay text
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::PaintOverlayText( )
|
||||
{
|
||||
if ( !m_OverlayText.Length() )
|
||||
return;
|
||||
|
||||
int cw, ch;
|
||||
GetSize( cw, ch );
|
||||
|
||||
int nTextWidth, nTextHeight;
|
||||
int nBufLen = m_OverlayText.Length()+1;
|
||||
wchar_t *pTemp = (wchar_t*)_alloca( nBufLen * sizeof(wchar_t) );
|
||||
::MultiByteToWideChar( CP_UTF8, 0, m_OverlayText.Get(), -1, pTemp, nBufLen );
|
||||
|
||||
g_pMatSystemSurface->GetTextSize( m_OverlayTextFont, pTemp, nTextWidth, nTextHeight );
|
||||
int lx = (cw - nTextWidth) / 2;
|
||||
if ( lx < 10 )
|
||||
{
|
||||
lx = 10;
|
||||
}
|
||||
int ly = ch - 10 - nTextHeight;
|
||||
g_pMatSystemSurface->DrawColoredTextRect( m_OverlayTextFont,
|
||||
lx, ly, cw - lx, ch - ly,
|
||||
255, 255, 255, 255, "%s", m_OverlayText.Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Paints the engine window itself
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::PaintEngineWindow( int x, int y, int w, int h )
|
||||
{
|
||||
if ( !enginetools->IsInGame() )
|
||||
{
|
||||
surface()->DrawSetColor( Color( 127, 127, 200, 63 ) );
|
||||
surface()->DrawFilledRect( x, y, x + w, y + h );
|
||||
}
|
||||
else
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
g_pMatSystemSurface->DrawSetTextureMaterial( m_nEngineOutputTexture, m_ScreenMaterial );
|
||||
surface()->DrawSetColor( Color( 0, 0, 0, 255 ) );
|
||||
|
||||
int nTexWidth = m_ScreenBuffer->GetActualWidth();
|
||||
int nTexHeight = m_ScreenBuffer->GetActualHeight();
|
||||
float flOOWidth = 1.0f / nTexWidth;
|
||||
float flOOHeight = 1.0f / nTexHeight;
|
||||
|
||||
float s0, s1, t0, t1;
|
||||
|
||||
s0 = ( 0.5f ) * flOOWidth;
|
||||
t0 = ( 0.5f ) * flOOHeight;
|
||||
s1 = ( (float)w - 0.5f ) * flOOWidth;
|
||||
t1 = ( (float)h - 0.5f ) * flOOHeight;
|
||||
|
||||
vgui::surface()->DrawTexturedSubRect( x, y, x+w, y+h, s0, t0, s1, t1 );
|
||||
|
||||
PaintOverlayText();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Paints the background
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::PaintBackground()
|
||||
{
|
||||
int x, y, w, h;
|
||||
GetEngineBounds( x, y, w, h );
|
||||
PaintEngineBorders( x, y, w, h );
|
||||
PaintEngineWindow( x, y, w, h );
|
||||
}
|
||||
|
||||
void CMiniViewportEngineRenderArea::GetEngineBounds( int& x, int& y, int& w, int& h )
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
GetSize( w, h );
|
||||
|
||||
// Check aspect ratio
|
||||
int sx, sy;
|
||||
surface()->GetScreenSize( sx, sy );
|
||||
|
||||
if ( sy > 0 &&
|
||||
h > 0 )
|
||||
{
|
||||
float screenaspect = (float)sx / (float)sy;
|
||||
float aspect = (float)w / (float)h;
|
||||
|
||||
float ratio = screenaspect / aspect;
|
||||
|
||||
// Screen is wider, need bars at top and bottom
|
||||
if ( ratio > 1.0f )
|
||||
{
|
||||
int usetall = (float)w / screenaspect;
|
||||
y = ( h - usetall ) / 2;
|
||||
h = usetall;
|
||||
}
|
||||
// Screen is narrower, need bars at left/right
|
||||
else
|
||||
{
|
||||
int usewide = (float)h * screenaspect;
|
||||
x = ( w - usewide ) / 2;
|
||||
w = usewide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CMiniViewportPropertyPage::CMiniViewportPropertyPage(Panel *parent, const char *panelName ) :
|
||||
BaseClass( parent, panelName )
|
||||
{
|
||||
m_bgColor = Color( 0, 0, 0, 0 );
|
||||
|
||||
m_pViewportArea = new CMiniViewportEngineRenderArea( this, "Engine" );
|
||||
}
|
||||
|
||||
void CMiniViewportPropertyPage::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
m_pViewportArea->SetBounds( 0, 0, w, h );
|
||||
}
|
||||
|
||||
Color CMiniViewportPropertyPage::GetBgColor()
|
||||
{
|
||||
return m_bgColor;
|
||||
}
|
||||
|
||||
|
||||
void CMiniViewportPropertyPage::GetEngineBounds( int& x, int& y, int& w, int& h )
|
||||
{
|
||||
m_pViewportArea->GetEngineBounds( x, y, w, h );
|
||||
m_pViewportArea->LocalToScreen( x, y );
|
||||
}
|
||||
|
||||
void CMiniViewportPropertyPage::RenderFrameBegin()
|
||||
{
|
||||
m_pViewportArea->RenderFrameBegin();
|
||||
}
|
||||
|
||||
CMiniViewport::CMiniViewport( vgui::Panel *parent, bool contextLabel, vgui::IToolWindowFactory *factory /*= 0*/,
|
||||
vgui::Panel *page /*= NULL*/, char const *title /*= NULL*/, bool contextMenu /*= false*/ ) :
|
||||
BaseClass( parent, contextLabel, factory, page, title, contextMenu, false )
|
||||
{
|
||||
SetCloseButtonVisible( false );
|
||||
|
||||
GetPropertySheet()->SetDraggableTabs( false );
|
||||
|
||||
// Add the viewport panel
|
||||
m_hPage = new CMiniViewportPropertyPage( this, "ViewportPage" );
|
||||
|
||||
AddPage( m_hPage.Get(), "#ToolMiniViewport", false );
|
||||
}
|
||||
|
||||
void CMiniViewport::GetViewport( bool& enabled, int& x, int& y, int& w, int& h )
|
||||
{
|
||||
enabled = false;
|
||||
x = y = w = h = 0;
|
||||
|
||||
int screenw, screenh;
|
||||
surface()->GetScreenSize( screenw, screenh );
|
||||
|
||||
m_hPage->GetEngineBounds( x, y, w, h );
|
||||
|
||||
y = screenh - ( y + h );
|
||||
}
|
||||
|
||||
void CMiniViewport::GetEngineBounds( int& x, int& y, int& w, int& h )
|
||||
{
|
||||
m_hPage->GetEngineBounds( x, y, w, h );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the layoff texture needs to be released
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewport::ReleaseLayoffTexture()
|
||||
{
|
||||
if ( m_hPage.Get() )
|
||||
{
|
||||
m_hPage->GetViewportArea()->ReleaseLayoffTexture();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets text to draw over the window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewport::SetOverlayText( const char *pText )
|
||||
{
|
||||
if ( m_hPage.Get() )
|
||||
{
|
||||
m_hPage->GetViewportArea()->SetOverlayText( pText );
|
||||
}
|
||||
}
|
||||
|
||||
void CMiniViewport::RenderFrameBegin()
|
||||
{
|
||||
if ( m_hPage.Get() )
|
||||
{
|
||||
m_hPage->RenderFrameBegin();
|
||||
}
|
||||
}
|
||||
157
tools/toolutils/recentfilelist.cpp
Normal file
157
tools/toolutils/recentfilelist.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/recentfilelist.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "iregistry.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds a file to the list of recent files
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRecentFileList::Add( const char *pFileName, const char *pFileFormat )
|
||||
{
|
||||
RecentFileInfo_t info;
|
||||
info.m_pFileName = pFileName;
|
||||
int idx = m_RecentFiles.Find( info );
|
||||
if ( idx != m_RecentFiles.InvalidIndex() )
|
||||
{
|
||||
// Remove from current slot so it gets added to head (most recent) below...
|
||||
m_RecentFiles.Remove( idx );
|
||||
}
|
||||
|
||||
while ( m_RecentFiles.Count() >= MAX_RECENT_FILES )
|
||||
{
|
||||
// Oldest is at last slot
|
||||
m_RecentFiles.Remove( m_RecentFiles.Count() - 1 );
|
||||
}
|
||||
|
||||
int i = m_RecentFiles.AddToHead( );
|
||||
m_RecentFiles[i].m_pFileName = pFileName;
|
||||
m_RecentFiles[i].m_pFileFormat = pFileFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes all files from the list
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRecentFileList::Clear()
|
||||
{
|
||||
m_RecentFiles.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if there's no files in the file list
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CRecentFileList::IsEmpty() const
|
||||
{
|
||||
return m_RecentFiles.Count() == 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file in a particular slot
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CRecentFileList::GetFile( int slot ) const
|
||||
{
|
||||
if ( slot < 0 || slot >= m_RecentFiles.Count() )
|
||||
return NULL;
|
||||
|
||||
return m_RecentFiles[slot].m_pFileName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file in a particular slot
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CRecentFileList::GetFileFormat( int slot ) const
|
||||
{
|
||||
if ( slot < 0 || slot >= m_RecentFiles.Count() )
|
||||
return NULL;
|
||||
|
||||
return m_RecentFiles[slot].m_pFileFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads the file list from the registry
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRecentFileList::LoadFromRegistry( const char *pToolKeyName )
|
||||
{
|
||||
Clear();
|
||||
|
||||
// Iterate in reverse order so most recent files goes to top
|
||||
for ( int i = MAX_RECENT_FILES; i >= 0; --i )
|
||||
{
|
||||
char sz[ 128 ];
|
||||
char szType[ 128 ];
|
||||
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
|
||||
Q_snprintf( szType, sizeof( szType ), "%s\\history_fileformat%02i", pToolKeyName, i );
|
||||
|
||||
// NOTE: Can't call registry->ReadString twice in a row!
|
||||
char pFileName[MAX_PATH];
|
||||
Q_strncpy( pFileName, registry->ReadString( sz, "" ), sizeof(pFileName) );
|
||||
if ( pFileName && pFileName[ 0 ] )
|
||||
{
|
||||
const char *valType = registry->ReadString( szType, "" );
|
||||
const char *pFormat = (valType && valType[0]) ? valType : "dmx";
|
||||
Add( pFileName, pFormat );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Saves file list into the registry
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRecentFileList::SaveToRegistry( const char *pToolKeyName ) const
|
||||
{
|
||||
char sz[ 128 ];
|
||||
|
||||
int i, c;
|
||||
c = m_RecentFiles.Count();
|
||||
for ( i = 0 ; i < c; ++i )
|
||||
{
|
||||
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
|
||||
registry->WriteString( sz, m_RecentFiles[i].m_pFileName );
|
||||
|
||||
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
|
||||
registry->WriteString( sz, m_RecentFiles[i].m_pFileFormat );
|
||||
}
|
||||
|
||||
// Clear out all other registry settings
|
||||
for ( ; i < MAX_RECENT_FILES; ++i )
|
||||
{
|
||||
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
|
||||
registry->WriteString( sz, "" );
|
||||
|
||||
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
|
||||
registry->WriteString( sz, "" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds the list of files to a particular menu
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRecentFileList::AddToMenu( vgui::Menu *menu, vgui::Panel *pActionTarget, const char *pCommandName ) const
|
||||
{
|
||||
int i, c;
|
||||
c = m_RecentFiles.Count();
|
||||
for ( i = 0 ; i < c; ++i )
|
||||
{
|
||||
char sz[ 32 ];
|
||||
Q_snprintf( sz, sizeof( sz ), "%s%02i", pCommandName, i );
|
||||
char const *fn = m_RecentFiles[i].m_pFileName;
|
||||
menu->AddMenuItem( fn, new KeyValues( "Command", "command", sz ), pActionTarget );
|
||||
}
|
||||
}
|
||||
286
tools/toolutils/savewindowpositions.cpp
Normal file
286
tools/toolutils/savewindowpositions.cpp
Normal file
@@ -0,0 +1,286 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/savewindowpositions.h"
|
||||
#include "iregistry.h"
|
||||
#include "vgui_controls/Panel.h"
|
||||
#include "vgui_controls/PHandle.h"
|
||||
#include "vgui_controls/ToolWindow.h"
|
||||
#include "vgui/ISurface.h"
|
||||
#include "vgui_controls/PropertySheet.h"
|
||||
#include "tier1/utlsymbol.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: This will save the bounds and the visibility state of UI elements registered during startup
|
||||
// FIXME: Preserve Z order?
|
||||
//-----------------------------------------------------------------------------
|
||||
class CWindowPositionMgr : public IWindowPositionMgr
|
||||
{
|
||||
public:
|
||||
// Inherited from IWindowPositionMgr
|
||||
virtual void SavePositions( char const *filename, char const *key );
|
||||
virtual bool LoadPositions( char const *filename, Panel *parent, vgui::IToolWindowFactory *factory, char const *key, bool force = false );
|
||||
virtual void RegisterPanel( char const *saveName, Panel *panel, bool contextMenu );
|
||||
virtual void UnregisterPanel( vgui::Panel *panel );
|
||||
|
||||
private:
|
||||
struct LoadInfo_t
|
||||
{
|
||||
CUtlSymbol m_Name;
|
||||
PHandle m_hPanel;
|
||||
bool m_bLoaded;
|
||||
bool m_bContextMenu;
|
||||
};
|
||||
|
||||
LoadInfo_t *Find( Panel *panel );
|
||||
LoadInfo_t *Find( char const *panelName );
|
||||
|
||||
CUtlVector< LoadInfo_t > m_Panels;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton instance
|
||||
//-----------------------------------------------------------------------------
|
||||
static CWindowPositionMgr g_WindowPositionMgr;
|
||||
IWindowPositionMgr *windowposmgr = &g_WindowPositionMgr;
|
||||
|
||||
CWindowPositionMgr::LoadInfo_t *CWindowPositionMgr::Find( Panel *panel )
|
||||
{
|
||||
if ( !panel )
|
||||
return NULL;
|
||||
|
||||
int c = m_Panels.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
LoadInfo_t *info = &m_Panels[ i ];
|
||||
if ( info->m_hPanel.Get() == panel )
|
||||
return info;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CWindowPositionMgr::LoadInfo_t *CWindowPositionMgr::Find( char const *panelName )
|
||||
{
|
||||
if ( !panelName )
|
||||
return NULL;
|
||||
|
||||
int c = m_Panels.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
LoadInfo_t *info = &m_Panels[ i ];
|
||||
if ( !Q_stricmp( info->m_Name.String(), panelName ) )
|
||||
return info;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void BufPrint( CUtlBuffer& buf, int level, char const *fmt, ... )
|
||||
{
|
||||
char string[ 2048 ];
|
||||
va_list argptr;
|
||||
va_start( argptr, fmt );
|
||||
_vsnprintf( string, sizeof( string ) - 1, fmt, argptr );
|
||||
va_end( argptr );
|
||||
string[ sizeof( string ) - 1 ] = 0;
|
||||
|
||||
while ( --level >= 0 )
|
||||
{
|
||||
buf.Printf( " " );
|
||||
}
|
||||
buf.Printf( "%s", string );
|
||||
}
|
||||
|
||||
void CWindowPositionMgr::SavePositions( char const *filename, char const *key )
|
||||
{
|
||||
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
|
||||
buf.Printf( "%s\n", key );
|
||||
buf.Printf( "{\n" );
|
||||
|
||||
int sw, sh;
|
||||
vgui::surface()->GetScreenSize( sw, sh );
|
||||
float flOOW = (sw != 0.0f) ? 1.0f / (float)sw : 1.0f;
|
||||
float flOOH = (sh != 0.0f) ? 1.0f / (float)sh : 1.0f;
|
||||
|
||||
int c = ToolWindow::GetToolWindowCount();
|
||||
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
ToolWindow *tw = ToolWindow::GetToolWindow( i );
|
||||
Assert( tw );
|
||||
if ( !tw )
|
||||
continue;
|
||||
|
||||
BufPrint( buf, 1, "toolwindow\n" );
|
||||
BufPrint( buf, 1, "{\n" );
|
||||
|
||||
// Get panel bounds
|
||||
int x, y, w, h;
|
||||
tw->GetBounds( x, y, w, h );
|
||||
|
||||
float fx = (float)x * flOOW;
|
||||
float fy = (float)y * flOOH;
|
||||
float fw = (float)w * flOOW;
|
||||
float fh = (float)h * flOOH;
|
||||
BufPrint( buf, 2, "bounds \"%.10f %.10f %.10f %.10f\"\n", fx, fy, fw, fh );
|
||||
|
||||
// Now iterate the actual contained panels
|
||||
PropertySheet *sheet = tw->GetPropertySheet();
|
||||
Assert( sheet );
|
||||
if ( sheet )
|
||||
{
|
||||
int subCount = sheet->GetNumPages();
|
||||
Assert( subCount > 0 );
|
||||
if ( subCount > 0 )
|
||||
{
|
||||
BufPrint( buf, 2, "windows\n" );
|
||||
BufPrint( buf, 2, "{\n" );
|
||||
|
||||
for ( int s = 0 ; s < subCount; ++s )
|
||||
{
|
||||
Panel *subPanel = sheet->GetPage( s );
|
||||
if ( !subPanel )
|
||||
continue;
|
||||
|
||||
LoadInfo_t *info = Find( subPanel );
|
||||
if ( !info )
|
||||
continue;
|
||||
|
||||
BufPrint( buf, 3, "panel \"%s\"\n", info->m_Name.String() );
|
||||
}
|
||||
|
||||
BufPrint( buf, 2, "}\n" );
|
||||
}
|
||||
}
|
||||
|
||||
BufPrint( buf, 1, "}\n" );
|
||||
}
|
||||
|
||||
buf.Printf( "}\n" );
|
||||
|
||||
if ( g_pFullFileSystem->FileExists( filename, "DEFAULT_WRITE_PATH" ) &&
|
||||
!g_pFullFileSystem->IsFileWritable( filename, "DEFAULT_WRITE_PATH" ) )
|
||||
{
|
||||
Warning( "IFM window layout file '%s' is read-only!!!\n", filename );
|
||||
}
|
||||
|
||||
FileHandle_t h = g_pFullFileSystem->Open( filename, "wb", "DEFAULT_WRITE_PATH" );
|
||||
if ( FILESYSTEM_INVALID_HANDLE != h )
|
||||
{
|
||||
g_pFullFileSystem->Write( buf.Base(), buf.TellPut(), h );
|
||||
g_pFullFileSystem->Close( h );
|
||||
}
|
||||
}
|
||||
|
||||
bool CWindowPositionMgr::LoadPositions( char const *filename, vgui::Panel *parent, vgui::IToolWindowFactory *factory, char const *key, bool force /*=false*/ )
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
int sw, sh;
|
||||
vgui::surface()->GetScreenSize( sw, sh );
|
||||
|
||||
KeyValues *kv = new KeyValues( key );
|
||||
if ( kv->LoadFromFile( g_pFullFileSystem, filename, "GAME" ) )
|
||||
{
|
||||
// Walk through tools
|
||||
for ( KeyValues *tw = kv->GetFirstSubKey(); tw != NULL; tw = tw->GetNextKey() )
|
||||
{
|
||||
if ( Q_stricmp( tw->GetName(), "toolwindow" ) )
|
||||
continue;
|
||||
|
||||
// read bounds
|
||||
float fx, fy, fw, fh;
|
||||
int x, y, w, h;
|
||||
char const *bounds = tw->GetString( "bounds", "" );
|
||||
if ( !bounds || !bounds[ 0 ] )
|
||||
continue;
|
||||
|
||||
if ( 4 != sscanf( bounds, "%f %f %f %f", &fx, &fy, &fw, &fh ) )
|
||||
continue;
|
||||
|
||||
x = (int)( sw * fx + 0.5f );
|
||||
y = (int)( sh * fy + 0.5f );
|
||||
w = (int)( sw * fw + 0.5f );
|
||||
h = (int)( sh * fh + 0.5f );
|
||||
|
||||
w = clamp( w, 0, sw );
|
||||
h = clamp( h, 0, sh );
|
||||
|
||||
// Now load pages
|
||||
KeyValues *pages = tw->FindKey( "windows", false );
|
||||
if ( !pages )
|
||||
continue;
|
||||
|
||||
ToolWindow *newTool = factory->InstanceToolWindow( parent, true, NULL, NULL, false );
|
||||
newTool->SetBounds( x, y, w, h );
|
||||
|
||||
for ( KeyValues *page = pages->GetFirstSubKey(); page != NULL; page = page->GetNextKey() )
|
||||
{
|
||||
if ( Q_stricmp( page->GetName(), "panel" ) )
|
||||
continue;
|
||||
|
||||
char const *pageName = page->GetString();
|
||||
if ( !pageName || !pageName[ 0 ] )
|
||||
continue;
|
||||
|
||||
LoadInfo_t *info = Find( pageName );
|
||||
if ( !info )
|
||||
continue;
|
||||
|
||||
newTool->AddPage( info->m_hPanel.Get(), info->m_Name.String(), info->m_bContextMenu );
|
||||
success = true;
|
||||
}
|
||||
|
||||
// If we didn't successfully create something, delete the tool
|
||||
if ( !success )
|
||||
{
|
||||
delete newTool;
|
||||
}
|
||||
}
|
||||
}
|
||||
kv->deleteThis();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void CWindowPositionMgr::RegisterPanel( char const *saveName, Panel *panel, bool contextMenu )
|
||||
{
|
||||
char const *panelName = panel->GetName();
|
||||
if ( !panelName || !panelName[ 0 ] )
|
||||
{
|
||||
Warning( "CWindowPositionMgr::RegisterPanel: Panel has NULL or blank name!!!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
LoadInfo_t info;
|
||||
info.m_hPanel = panel;
|
||||
info.m_Name = saveName;
|
||||
info.m_bLoaded = false;
|
||||
info.m_bContextMenu = contextMenu;
|
||||
|
||||
m_Panels.AddToTail( info );
|
||||
}
|
||||
|
||||
void CWindowPositionMgr::UnregisterPanel( vgui::Panel *panel )
|
||||
{
|
||||
int c = m_Panels.Count();
|
||||
for ( int i = c - 1; i >= 0; --i )
|
||||
{
|
||||
if ( m_Panels[ i ].m_hPanel.Get() != panel )
|
||||
continue;
|
||||
|
||||
m_Panels.Remove( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
233
tools/toolutils/tool_main.cpp
Normal file
233
tools/toolutils/tool_main.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/convar.h"
|
||||
#include "icvar.h"
|
||||
#include "toolframework/itoolsystem.h"
|
||||
#include "toolframework/itooldictionary.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "ienginevgui.h"
|
||||
#include "icvar.h"
|
||||
#include "toolutils/vgui_tools.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include "iregistry.h"
|
||||
#include "datamodel/idatamodel.h"
|
||||
#include "filesystem.h"
|
||||
#include "p4lib/ip4.h"
|
||||
#include "engine/ivdebugoverlay.h"
|
||||
#include "tier3/tier3dm.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "dmserializers/idmserializers.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
IEngineTool *enginetools = NULL;
|
||||
IEngineVGui *enginevgui = NULL;
|
||||
IFileSystem *g_pFileSystem = NULL;
|
||||
IVDebugOverlay *debugoverlay = NULL;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Assumed to be implemented within the specific tool DLL
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConnectTools( CreateInterfaceFn factory );
|
||||
void CreateTools( );
|
||||
void DisconnectTools( );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VGUI_CreateToolRootPanel( void )
|
||||
{
|
||||
// Just using PANEL_GAMEDLL in HL2 right now
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VGUI_DestroyToolRootPanel( void )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global accessors for root tool panels
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::VPANEL VGui_GetToolRootPanel( void )
|
||||
{
|
||||
vgui::VPANEL root = enginevgui->GetPanel( PANEL_GAMEDLL );
|
||||
return root;
|
||||
}
|
||||
|
||||
vgui::VPANEL VGui_GetRootPanel( void )
|
||||
{
|
||||
vgui::VPANEL root = enginevgui->GetPanel( PANEL_ROOT );
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of IToolDictionary
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolDictionary : public CTier3DmAppSystem< IToolDictionary >
|
||||
{
|
||||
typedef CTier3DmAppSystem< IToolDictionary > BaseClass;
|
||||
|
||||
public:
|
||||
CToolDictionary();
|
||||
|
||||
// Inherited from IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual void *QueryInterface( const char *pInterfaceName );
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
// Inherited from IToolDictionary
|
||||
virtual void CreateTools();
|
||||
virtual int GetToolCount() const;
|
||||
virtual IToolSystem *GetTool( int index );
|
||||
|
||||
public:
|
||||
void RegisterTool( IToolSystem *tool );
|
||||
|
||||
private:
|
||||
CUtlVector< IToolSystem * > m_Tools;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface for tools
|
||||
//-----------------------------------------------------------------------------
|
||||
static CToolDictionary g_ToolDictionary;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CToolDictionary, IToolDictionary, VTOOLDICTIONARY_INTERFACE_VERSION, g_ToolDictionary );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolDictionary::CToolDictionary()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from IAppSystem
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CToolDictionary::Connect( CreateInterfaceFn factory )
|
||||
{
|
||||
if ( !BaseClass::Connect( factory ) )
|
||||
return false;
|
||||
|
||||
// FIXME: This interface pointer is taken care of in tier2 + tier1
|
||||
g_pFileSystem = g_pFullFileSystem;
|
||||
|
||||
enginevgui = ( IEngineVGui * )factory( VENGINE_VGUI_VERSION, NULL );
|
||||
enginetools = ( IEngineTool * )factory( VENGINETOOL_INTERFACE_VERSION, NULL );
|
||||
debugoverlay = ( IVDebugOverlay * )factory( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL );
|
||||
|
||||
if ( !enginevgui || !debugoverlay || !g_pCVar || !enginetools || !g_pFileSystem )
|
||||
return false;
|
||||
|
||||
if ( !VGui_Startup( factory ) )
|
||||
return false;
|
||||
|
||||
return ConnectTools( factory );
|
||||
}
|
||||
|
||||
void CToolDictionary::Disconnect()
|
||||
{
|
||||
DisconnectTools();
|
||||
enginevgui = NULL;
|
||||
enginetools = NULL;
|
||||
debugoverlay = NULL;
|
||||
g_pFileSystem = NULL;
|
||||
|
||||
BaseClass::Disconnect( );
|
||||
}
|
||||
|
||||
void *CToolDictionary::QueryInterface( const char *pInterfaceName )
|
||||
{
|
||||
if ( !V_strcmp( pInterfaceName, VTOOLDICTIONARY_INTERFACE_VERSION ) )
|
||||
return (IToolDictionary*)this;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InitReturnVal_t CToolDictionary::Init()
|
||||
{
|
||||
InitReturnVal_t nRetVal = BaseClass::Init();
|
||||
if ( nRetVal != INIT_OK )
|
||||
return nRetVal;
|
||||
|
||||
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
|
||||
|
||||
// Init registry
|
||||
if ( !registry->Init( "Source\\Tools" ) )
|
||||
{
|
||||
Warning( "registry->Init failed\n" );
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
// Re-enable this and VGui_Shutdown if we create root tool panels
|
||||
// VGui_PostInit();
|
||||
|
||||
return INIT_OK;
|
||||
}
|
||||
|
||||
void CToolDictionary::Shutdown()
|
||||
{
|
||||
// Re-enable this and VGui_PostInit if we create root tool panels
|
||||
VGui_Shutdown();
|
||||
|
||||
registry->Shutdown();
|
||||
|
||||
BaseClass::Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of IToolDictionary methods
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolDictionary::CreateTools()
|
||||
{
|
||||
::CreateTools( );
|
||||
}
|
||||
|
||||
int CToolDictionary::GetToolCount() const
|
||||
{
|
||||
return m_Tools.Count();
|
||||
}
|
||||
|
||||
IToolSystem *CToolDictionary::GetTool( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Tools.Count() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return m_Tools[ index ];
|
||||
}
|
||||
|
||||
void CToolDictionary::RegisterTool( IToolSystem *tool )
|
||||
{
|
||||
m_Tools.AddToTail( tool );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allows tools to install themselves into the dictionary
|
||||
//-----------------------------------------------------------------------------
|
||||
void RegisterTool( IToolSystem *tool )
|
||||
{
|
||||
g_ToolDictionary.RegisterTool( tool );
|
||||
}
|
||||
|
||||
|
||||
131
tools/toolutils/tooleditmenubutton.cpp
Normal file
131
tools/toolutils/tooleditmenubutton.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Standard edit menu for tools
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/tooleditmenubutton.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "datamodel/idatamodel.h"
|
||||
#include "vgui_controls/menu.h"
|
||||
#include "vgui/ilocalize.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The Edit menu
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolEditMenuButton : public CToolMenuButton
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CToolEditMenuButton, CToolMenuButton );
|
||||
public:
|
||||
CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
|
||||
virtual void OnShowMenu( vgui::Menu *menu );
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global function to create the file menu
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton* CreateToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
|
||||
{
|
||||
return new CToolEditMenuButton( parent, panelName, text, pActionTarget );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolEditMenuButton::CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
|
||||
: BaseClass( parent, panelName, text, pActionSignalTarget )
|
||||
{
|
||||
AddMenuItem( "undo", "#ToolEditUndo", new KeyValues ( "Command", "command", "OnUndo" ), pActionSignalTarget, NULL, "undo" );
|
||||
AddMenuItem( "redo", "#ToolEditRedo", new KeyValues ( "Command", "command", "OnRedo" ), pActionSignalTarget, NULL, "redo" );
|
||||
AddSeparator();
|
||||
AddMenuItem( "describe", "#ToolEditDescribeUndo", new KeyValues ( "Command", "command", "OnDescribeUndo" ), pActionSignalTarget);
|
||||
AddMenuItem( "wipeundo", "#ToolEditWipeUndo", new KeyValues ( "Command", "command", "OnWipeUndo" ), pActionSignalTarget);
|
||||
AddSeparator();
|
||||
AddMenuItem( "editkeybindings", "#BxEditKeyBindings", new KeyValues( "OnEditKeyBindings" ), pActionSignalTarget, NULL, "editkeybindings" );
|
||||
|
||||
SetMenu(m_pMenu);
|
||||
}
|
||||
|
||||
void CToolEditMenuButton::OnShowMenu( vgui::Menu *menu )
|
||||
{
|
||||
BaseClass::OnShowMenu( menu );
|
||||
|
||||
// Update the menu
|
||||
char sz[ 512 ];
|
||||
|
||||
int id;
|
||||
id = m_Items.Find( "undo" );
|
||||
if ( g_pDataModel->CanUndo() )
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, true );
|
||||
|
||||
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditUndoStr" );
|
||||
if ( fmt )
|
||||
{
|
||||
wchar_t desc[ 256 ];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetUndoDesc(), desc, sizeof( desc ) );
|
||||
|
||||
wchar_t buf[ 512 ];
|
||||
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
|
||||
|
||||
m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnUndo" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, false );
|
||||
m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
|
||||
}
|
||||
|
||||
id = m_Items.Find( "redo" );
|
||||
if ( g_pDataModel->CanRedo() )
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, true );
|
||||
|
||||
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditRedoStr" );
|
||||
if ( fmt )
|
||||
{
|
||||
wchar_t desc[ 256 ];
|
||||
g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetRedoDesc(), desc, sizeof( desc ) );
|
||||
|
||||
wchar_t buf[ 512 ];
|
||||
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
|
||||
|
||||
m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnRedo" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->UpdateMenuItem( id, sz, new KeyValues( "Command", "command", "OnRedo" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, false );
|
||||
m_pMenu->UpdateMenuItem( id, "#ToolEditRedo", new KeyValues( "Command", "command", "OnRedo" ) );
|
||||
}
|
||||
|
||||
id = m_Items.Find( "describe" );
|
||||
if ( g_pDataModel->CanUndo() )
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenu->SetItemEnabled( id, false );
|
||||
}
|
||||
}
|
||||
132
tools/toolutils/toolmenubar.cpp
Normal file
132
tools/toolutils/toolmenubar.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/toolmenubar.h"
|
||||
#include "vgui_controls/Label.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Version that only has tool name and info
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuBar::CToolMenuBar( CBaseToolSystem *pParent, const char *pPanelName ) :
|
||||
BaseClass( (Panel *)pParent, pPanelName ),
|
||||
m_pToolSystem( pParent )
|
||||
{
|
||||
m_pInfo = new Label( this, "Info", "" );
|
||||
m_pToolName = new Label( this, "ToolName", "" );
|
||||
}
|
||||
|
||||
CBaseToolSystem *CToolMenuBar::GetToolSystem()
|
||||
{
|
||||
return m_pToolSystem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the tool bar's name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolMenuBar::SetToolName( const char *pName )
|
||||
{
|
||||
m_pToolName->SetText( pName );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the tool bar info
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolMenuBar::SetInfo( const char *pInfo )
|
||||
{
|
||||
m_pInfo->SetText( pInfo );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lays out the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolMenuBar::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
int cw, ch;
|
||||
m_pInfo->GetContentSize( cw, ch );
|
||||
|
||||
int right = w - cw - 20;
|
||||
m_pInfo->SetBounds( right, 0, cw, h );
|
||||
|
||||
m_pToolName->GetContentSize( cw, ch );
|
||||
m_pToolName->SetBounds( right - cw - 5, 0, cw, h );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Version that only has tool name, info, and file name
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolFileMenuBar::CToolFileMenuBar( CBaseToolSystem *parent, const char *panelName ) :
|
||||
BaseClass( parent, panelName )
|
||||
{
|
||||
m_pFileName = new Label( this, "FileName", "" );
|
||||
}
|
||||
|
||||
|
||||
void CToolFileMenuBar::SetFileName( char const *name )
|
||||
{
|
||||
m_pFileName->SetText( name );
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Performs layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolFileMenuBar::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
int w, h;
|
||||
GetSize( w, h );
|
||||
|
||||
int cw, ch;
|
||||
m_pInfo->GetContentSize( cw, ch );
|
||||
|
||||
int right = w - cw - 20;
|
||||
|
||||
m_pToolName->GetContentSize( cw, ch );
|
||||
|
||||
int barx, bary;
|
||||
GetContentSize( barx, bary );
|
||||
|
||||
int faredge = right - cw - 5- 2;
|
||||
int nearedge = barx + 2;
|
||||
|
||||
int mid = ( nearedge + faredge ) * 0.5f;
|
||||
|
||||
m_pFileName->GetContentSize( cw, ch );
|
||||
m_pFileName->SetBounds( mid - cw * 0.5f, 0, cw, h );
|
||||
}
|
||||
54
tools/toolutils/toolutils.vpc
Normal file
54
tools/toolutils/toolutils.vpc
Normal file
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// TOOLUTILS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
|
||||
$Project "Toolutils"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "attributeelementchoicelist.cpp"
|
||||
$File "basepropertiescontainer.cpp"
|
||||
$File "basestatusbar.cpp"
|
||||
$File "BaseToolSystem.cpp"
|
||||
$File "ConsolePage.cpp"
|
||||
$File "miniviewport.cpp"
|
||||
$File "recentfilelist.cpp"
|
||||
$File "savewindowpositions.cpp"
|
||||
$File "tool_main.cpp"
|
||||
$File "tooleditmenubutton.cpp"
|
||||
$File "ToolFileMenuButton.cpp"
|
||||
$File "ToolHelpMenuButton.cpp"
|
||||
$File "toolmenubar.cpp"
|
||||
$File "ToolMenuButton.cpp"
|
||||
$File "ToolSwitchMenuButton.cpp"
|
||||
$File "ToolUI.cpp"
|
||||
$File "vgui_tools.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\toolutils\AttributeElementChoiceList.h"
|
||||
$File "$SRCDIR\public\toolutils\basepropertiescontainer.h"
|
||||
$File "$SRCDIR\public\toolutils\basestatusbar.h"
|
||||
$File "$SRCDIR\public\toolutils\BaseToolSystem.h"
|
||||
$File "$SRCDIR\public\toolutils\DmeMdlRenderable.h"
|
||||
$File "$SRCDIR\public\toolutils\DmeRenderable.h"
|
||||
$File "$SRCDIR\public\toolutils\enginetools_int.h"
|
||||
$File "$SRCDIR\public\toolutils\miniviewport.h"
|
||||
$File "$SRCDIR\public\toolutils\recentfilelist.h"
|
||||
$File "$SRCDIR\public\toolutils\savewindowpositions.h"
|
||||
$File "$SRCDIR\public\toolutils\ToolEditMenuButton.h"
|
||||
$File "$SRCDIR\public\toolutils\ToolFileMenuButton.h"
|
||||
$File "$SRCDIR\public\toolutils\ToolHelpMenuButton.h"
|
||||
$File "$SRCDIR\public\toolutils\toolmenubar.h"
|
||||
$File "$SRCDIR\public\toolutils\ToolMenuButton.h"
|
||||
$File "$SRCDIR\public\toolutils\ToolSwitchMenuButton.h"
|
||||
$File "ToolUI.h"
|
||||
$File "$SRCDIR\public\toolutils\vgui_tools.h"
|
||||
}
|
||||
}
|
||||
67
tools/toolutils/vgui_tools.cpp
Normal file
67
tools/toolutils/vgui_tools.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/vgui_tools.h"
|
||||
#include "ienginevgui.h"
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IInput.h>
|
||||
#include "tier0/vprof.h"
|
||||
#include <vgui_controls/Panel.h>
|
||||
#include <KeyValues.h>
|
||||
#include <dme_controls/dmeControls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : appSystemFactory -
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VGui_Startup( CreateInterfaceFn appSystemFactory )
|
||||
{
|
||||
// All of the various tools .dlls expose GetVGuiControlsModuleName() to us to make sure we don't have communication across .dlls
|
||||
if ( !vgui::VGui_InitDmeInterfacesList( GetVGuiControlsModuleName(), &appSystemFactory, 1 ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VGui_PostInit()
|
||||
{
|
||||
// Create any root panels for .dll
|
||||
VGUI_CreateToolRootPanel();
|
||||
|
||||
// Make sure we have a panel
|
||||
VPANEL root = VGui_GetToolRootPanel();
|
||||
if ( !root )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
//-----------------------------------------------------------------------------
|
||||
void VGui_Shutdown()
|
||||
{
|
||||
VGUI_DestroyToolRootPanel();
|
||||
|
||||
// Make sure anything "marked for deletion"
|
||||
// actually gets deleted before this dll goes away
|
||||
vgui::ivgui()->RunFrame();
|
||||
}
|
||||
Reference in New Issue
Block a user