summaryrefslogtreecommitdiff
path: root/tools/sampletool
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /tools/sampletool
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'tools/sampletool')
-rw-r--r--tools/sampletool/cbase.cpp9
-rw-r--r--tools/sampletool/cbase.h46
-rw-r--r--tools/sampletool/sampletool.cpp342
-rw-r--r--tools/sampletool/sampletool.vpc79
4 files changed, 476 insertions, 0 deletions
diff --git a/tools/sampletool/cbase.cpp b/tools/sampletool/cbase.cpp
new file mode 100644
index 0000000..5ddb045
--- /dev/null
+++ b/tools/sampletool/cbase.cpp
@@ -0,0 +1,9 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================
+
+#include "cbase.h"
+
+// This file causes the .pch to be built \ No newline at end of file
diff --git a/tools/sampletool/cbase.h b/tools/sampletool/cbase.h
new file mode 100644
index 0000000..a21b327
--- /dev/null
+++ b/tools/sampletool/cbase.h
@@ -0,0 +1,46 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================
+
+#ifndef CBASE_H
+#define CBASE_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#ifdef _WIN32
+// Silence certain warnings
+#pragma warning(disable : 4244) // int or float down-conversion
+#pragma warning(disable : 4305) // int or float data truncation
+#pragma warning(disable : 4201) // nameless struct/union
+#pragma warning(disable : 4511) // copy constructor could not be generated
+#pragma warning(disable : 4675) // resolved overload was found by argument dependent lookup
+#pragma warning(disable : 4706) // assignment within conditional expression
+#endif
+
+#ifdef _DEBUG
+#define DEBUG 1
+#endif
+
+// Misc C-runtime library headers
+#include <math.h>
+#include <stdio.h>
+#include "minmax.h"
+
+// tier 0
+#include "tier0/dbg.h"
+#include "tier0/platform.h"
+#include "basetypes.h"
+
+// tier 1
+#include "tier1/strtools.h"
+#include "utlvector.h"
+#include "mathlib/vmatrix.h"
+#include "filesystem.h"
+
+#include "tier1/ConVar.h"
+#include "icvar.h"
+
+#endif // CBASE_H
diff --git a/tools/sampletool/sampletool.cpp b/tools/sampletool/sampletool.cpp
new file mode 100644
index 0000000..f29a83e
--- /dev/null
+++ b/tools/sampletool/sampletool.cpp
@@ -0,0 +1,342 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Core Movie Maker UI API
+//
+//=============================================================================
+#include "cbase.h"
+
+#include "toolutils/basetoolsystem.h"
+#include "toolutils/recentfilelist.h"
+#include "toolutils/toolmenubar.h"
+#include "toolutils/toolswitchmenubutton.h"
+#include "toolutils/toolfilemenubutton.h"
+#include "toolutils/toolmenubutton.h"
+#include "vgui_controls/Menu.h"
+#include "tier1/KeyValues.h"
+#include "toolutils/enginetools_int.h"
+#include "toolframework/ienginetool.h"
+#include "vgui/IInput.h"
+#include "vgui/KeyCode.h"
+#include "vgui_controls/FileOpenDialog.h"
+#include "filesystem.h"
+#include "vgui/ilocalize.h"
+#include "dme_controls/elementpropertiestree.h"
+#include "tier0/icommandline.h"
+#include "materialsystem/imaterialsystem.h"
+#include "VGuiMatSurface/IMatSystemSurface.h"
+#include "tier3/tier3.h"
+#include "tier2/fileutils.h"
+
+using namespace vgui;
+
+
+const char *GetVGuiControlsModuleName()
+{
+ return "SampleTool";
+}
+
+//-----------------------------------------------------------------------------
+// Connect, disconnect
+//-----------------------------------------------------------------------------
+bool ConnectTools( CreateInterfaceFn factory )
+{
+ return (materials != NULL) && (g_pMatSystemSurface != NULL);
+}
+
+void DisconnectTools( )
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Implementation of the sample tool
+//-----------------------------------------------------------------------------
+class CSampleTool : public CBaseToolSystem, public IFileMenuCallbacks
+{
+ DECLARE_CLASS_SIMPLE( CSampleTool, CBaseToolSystem );
+
+public:
+ CSampleTool();
+
+ // Inherited from IToolSystem
+ virtual const char *GetToolName() { return "Sample Tool"; }
+ virtual const char *GetBindingsContextFile() { return "cfg/SampleTool.kb"; }
+ virtual bool Init( );
+ virtual void Shutdown();
+
+ // Inherited from IFileMenuCallbacks
+ virtual int GetFileMenuItemsEnabled( );
+ virtual void AddRecentFilesToMenu( vgui::Menu *menu );
+ virtual bool GetPerforceFileName( char *pFileName, int nMaxLen ) { return false; }
+ virtual vgui::Panel* GetRootPanel() { return this; }
+
+ // Inherited from CBaseToolSystem
+ virtual vgui::HScheme GetToolScheme();
+ virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
+ virtual void OnCommand( const char *cmd );
+ virtual const char *GetRegistryName() { return "SampleTool"; }
+ virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
+
+public:
+ MESSAGE_FUNC( OnNew, "OnNew" );
+ MESSAGE_FUNC( OnOpen, "OnOpen" );
+ MESSAGE_FUNC( OnSave, "OnSave" );
+ MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
+ MESSAGE_FUNC( OnClose, "OnClose" );
+ MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
+ MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
+ MESSAGE_FUNC( OnExit, "OnExit" );
+
+ void OpenFileFromHistory( int slot );
+ virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
+ virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
+ virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
+ virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
+
+private:
+ // Loads up a new document
+ void LoadDocument( const char *pDocName );
+
+ // Updates the menu bar based on the current file
+ void UpdateMenuBar( );
+
+ // Shows element properties
+ void ShowElementProperties( );
+
+ virtual const char *GetLogoTextureName();
+
+};
+
+
+//-----------------------------------------------------------------------------
+// Singleton
+//-----------------------------------------------------------------------------
+CSampleTool *g_pSampleTool = NULL;
+
+void CreateTools()
+{
+ g_pSampleTool = new CSampleTool();
+}
+
+
+//-----------------------------------------------------------------------------
+// Constructor
+//-----------------------------------------------------------------------------
+CSampleTool::CSampleTool()
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Init, shutdown
+//-----------------------------------------------------------------------------
+bool CSampleTool::Init( )
+{
+ m_RecentFiles.LoadFromRegistry( GetRegistryName() );
+
+ // NOTE: This has to happen before BaseClass::Init
+// g_pVGuiLocalize->AddFile( "resource/toolsample_%language%.txt" );
+
+ if ( !BaseClass::Init( ) )
+ return false;
+
+ return true;
+}
+
+void CSampleTool::Shutdown()
+{
+ m_RecentFiles.SaveToRegistry( GetRegistryName() );
+ BaseClass::Shutdown();
+}
+
+
+//-----------------------------------------------------------------------------
+// Derived classes can implement this to get a new scheme to be applied to this tool
+//-----------------------------------------------------------------------------
+vgui::HScheme CSampleTool::GetToolScheme()
+{
+ return vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "SampleTool" );
+}
+
+
+//-----------------------------------------------------------------------------
+// Initializes the menu bar
+//-----------------------------------------------------------------------------
+vgui::MenuBar *CSampleTool::CreateMenuBar( CBaseToolSystem *pParent )
+{
+ CToolMenuBar *pMenuBar = new CToolMenuBar( pParent, "Main Menu Bar" );
+
+ // Sets info in the menu bar
+ char title[ 64 ];
+ ComputeMenuBarTitle( title, sizeof( title ) );
+ pMenuBar->SetInfo( title );
+ pMenuBar->SetToolName( GetToolName() );
+
+ // Add menu buttons
+ CToolMenuButton *pFileButton = CreateToolFileMenuButton( pMenuBar, "File", "&File", GetActionTarget(), this );
+ CToolMenuButton *pSwitchButton = CreateToolSwitchMenuButton( pMenuBar, "Switcher", "&Tools", GetActionTarget() );
+
+ pMenuBar->AddButton( pFileButton );
+ pMenuBar->AddButton( pSwitchButton );
+
+ return pMenuBar;
+}
+
+
+//-----------------------------------------------------------------------------
+// Creates the action menu
+//-----------------------------------------------------------------------------
+vgui::Menu *CSampleTool::CreateActionMenu( vgui::Panel *pParent )
+{
+ vgui::Menu *pActionMenu = new Menu( pParent, "ActionMenu" );
+ pActionMenu->AddMenuItem( "#ToolHide", new KeyValues( "Command", "command", "HideActionMenu" ), GetActionTarget() );
+ return pActionMenu;
+}
+
+//-----------------------------------------------------------------------------
+// Inherited from IFileMenuCallbacks
+//-----------------------------------------------------------------------------
+int CSampleTool::GetFileMenuItemsEnabled( )
+{
+ int nFlags = FILE_ALL;
+ if ( m_RecentFiles.IsEmpty() )
+ {
+ nFlags &= ~(FILE_RECENT | FILE_CLEAR_RECENT);
+ }
+ return nFlags;
+}
+
+void CSampleTool::AddRecentFilesToMenu( vgui::Menu *pMenu )
+{
+ m_RecentFiles.AddToMenu( pMenu, GetActionTarget(), "OnRecent" );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : -
+//-----------------------------------------------------------------------------
+void CSampleTool::OnExit()
+{
+ enginetools->Command( "quit\n" );
+}
+
+//-----------------------------------------------------------------------------
+// Handle commands from the action menu and other menus
+//-----------------------------------------------------------------------------
+void CSampleTool::OnCommand( const char *cmd )
+{
+ if ( !V_stricmp( cmd, "HideActionMenu" ) )
+ {
+ if ( GetActionMenu() )
+ {
+ GetActionMenu()->SetVisible( false );
+ }
+ }
+ else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnRecent" ) )
+ {
+ int idx = Q_atoi( pSuffix );
+ OpenFileFromHistory( idx );
+ }
+ else if( const char *pSuffix = StringAfterPrefix( cmd, "OnTool" ) )
+ {
+ int idx = Q_atoi( pSuffix );
+ enginetools->SwitchToTool( idx );
+ }
+ else
+ {
+ BaseClass::OnCommand( cmd );
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Command handlers
+//-----------------------------------------------------------------------------
+void CSampleTool::OnNew()
+{
+ // FIXME: Implement
+}
+
+void CSampleTool::OnOpen()
+{
+ OpenFile( "txt" );
+}
+
+bool CSampleTool::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
+{
+ // FIXME: Implement
+
+ m_RecentFiles.Add( pFileName, pFileFormat );
+ return true;
+}
+
+void CSampleTool::OnSave()
+{
+ // FIXME: Implement
+}
+
+void CSampleTool::OnSaveAs()
+{
+ SaveFile( NULL, NULL, 0 );
+}
+
+bool CSampleTool::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
+{
+ // FIXME: Implement
+
+ m_RecentFiles.Add( pFileName, pFileFormat );
+ return true;
+}
+
+void CSampleTool::OnClose()
+{
+ // FIXME: Implement
+}
+
+void CSampleTool::OnCloseNoSave()
+{
+ // FIXME: Implement
+}
+
+void CSampleTool::OnMarkNotDirty()
+{
+ // FIXME: Implement
+}
+
+
+//-----------------------------------------------------------------------------
+// Show the save document query dialog
+//-----------------------------------------------------------------------------
+void CSampleTool::OpenFileFromHistory( int slot )
+{
+ const char *pFileName = m_RecentFiles.GetFile( slot );
+ OnReadFileFromDisk( pFileName, NULL, 0 );
+}
+
+
+//-----------------------------------------------------------------------------
+// Called when file operations complete
+//-----------------------------------------------------------------------------
+void CSampleTool::OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues )
+{
+ // FIXME: Implement
+}
+
+
+//-----------------------------------------------------------------------------
+// Show the File browser dialog
+//-----------------------------------------------------------------------------
+void CSampleTool::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
+{
+ char pStartingDir[ MAX_PATH ];
+ GetModSubdirectory( NULL, pStartingDir, sizeof(pStartingDir) );
+
+ pDialog->SetTitle( "Choose SampleTool .txt file", true );
+ pDialog->SetStartDirectoryContext( "sample_session", pStartingDir );
+ pDialog->AddFilter( "*.txt", "SampleTool (*.txt)", true );
+}
+
+const char *CSampleTool::GetLogoTextureName()
+{
+ return "vgui/tools/sampletool/sampletool_logo";
+} \ No newline at end of file
diff --git a/tools/sampletool/sampletool.vpc b/tools/sampletool/sampletool.vpc
new file mode 100644
index 0000000..d81f2b1
--- /dev/null
+++ b/tools/sampletool/sampletool.vpc
@@ -0,0 +1,79 @@
+//-----------------------------------------------------------------------------
+// SAMPLETOOL.VPC
+//
+// Project Script
+//-----------------------------------------------------------------------------
+
+$Macro SRCDIR "..\.."
+$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
+
+$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
+
+$Configuration
+{
+ $Compiler
+ {
+ $AdditionalIncludeDirectories "$BASE,.\,..\common,$SRCDIR\game\shared"
+ $PreprocessorDefinitions "$BASE;SAMPLETOOL_EXPORTS"
+ $Create/UsePrecompiledHeader "Use Precompiled Header (/Yu)"
+ $Create/UsePCHThroughFile "cbase.h"
+ }
+
+ $Linker
+ {
+ $AdditionalDependencies "$BASE Psapi.lib"
+ }
+}
+
+$Project "Sampletool"
+{
+ $Folder "Source Files"
+ {
+ $File "sampletool.cpp"
+ $File "cbase.cpp"
+ {
+ $Configuration
+ {
+ $Compiler
+ {
+ $Create/UsePrecompiledHeader "Create Precompiled Header (/Yc)"
+ }
+ }
+ }
+
+ $File "$SRCDIR\public\interpolatortypes.cpp" \
+ "$SRCDIR\public\registry.cpp" \
+ "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
+ {
+ $Configuration
+ {
+ $Compiler
+ {
+ $Create/UsePrecompiledHeader "Not Using Precompiled Headers"
+ }
+ }
+ }
+ }
+
+ $Folder "Header Files"
+ {
+ $File "cbase.h"
+ $File "$SRCDIR\public\interpolatortypes.h"
+ $File "$SRCDIR\public\mathlib\mathlib.h"
+ }
+
+ $Folder "Link Libraries"
+ {
+ $Lib datamodel
+ $Lib dme_controls
+ $Lib dmserializers
+ $Lib mathlib
+ $Lib matsys_controls
+ $Lib movieobjects
+ $Lib sfmobjects
+ $Lib tier2
+ $Lib tier3
+ $Lib toolutils
+ $Lib vgui_controls
+ }
+}