summaryrefslogtreecommitdiff
path: root/tools/toolutils/basestatusbar.cpp
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/toolutils/basestatusbar.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'tools/toolutils/basestatusbar.cpp')
-rw-r--r--tools/toolutils/basestatusbar.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/tools/toolutils/basestatusbar.cpp b/tools/toolutils/basestatusbar.cpp
new file mode 100644
index 0000000..1fe8add
--- /dev/null
+++ b/tools/toolutils/basestatusbar.cpp
@@ -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;
+} \ No newline at end of file