Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "stdafx.h"
  3. #include "hammer.h"
  4. #include "hammervgui.h"
  5. #include <vgui/IVGui.h>
  6. #include <vgui/ISurface.h>
  7. #include <vgui/ISystem.h>
  8. #include "vgui/IInput.h"
  9. #include <VGuiMatSurface/IMatSystemSurface.h>
  10. #include <matsys_controls/matsyscontrols.h>
  11. #include "material.h"
  12. #include "vgui_controls/AnimationController.h"
  13. #include "inputsystem/iinputsystem.h"
  14. #include "VGuiWnd.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: singleton accessor
  17. //-----------------------------------------------------------------------------
  18. static CHammerVGui s_HammerVGui;
  19. CHammerVGui *HammerVGui()
  20. {
  21. return &s_HammerVGui;
  22. }
  23. CHammerVGui::CHammerVGui(void)
  24. {
  25. m_pActiveWindow = NULL;
  26. m_hMainWindow = NULL;
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Setup the base vgui panels
  30. //-----------------------------------------------------------------------------
  31. bool CHammerVGui::Init( HWND hWindow )
  32. {
  33. // initialize vgui_control interfaces
  34. if (!vgui::VGui_InitInterfacesList( "HAMMER", &g_Factory, 1 ))
  35. return false;
  36. if ( !vgui::VGui_InitMatSysInterfacesList( "HAMMER", &g_Factory, 1 ) )
  37. return false;
  38. if ( !g_pMatSystemSurface )
  39. return false;
  40. // configuration settings
  41. vgui::system()->SetUserConfigFile("hammer.vdf", "EXECUTABLE_PATH");
  42. // Are we trapping input?
  43. g_pMatSystemSurface->EnableWindowsMessages( true );
  44. // Need to be able to play sounds through vgui
  45. // g_pMatSystemSurface->InstallPlaySoundFunc( VGui_PlaySound );
  46. // load scheme
  47. if (!vgui::scheme()->LoadSchemeFromFile("Resource/SourceScheme.res", "Hammer"))
  48. {
  49. return false;
  50. }
  51. m_hMainWindow = hWindow;
  52. // Start the App running
  53. vgui::ivgui()->Start();
  54. vgui::ivgui()->SetSleep(false);
  55. return true;
  56. }
  57. void CHammerVGui::SetFocus( CVGuiWnd *pVGuiWnd )
  58. {
  59. if ( pVGuiWnd == m_pActiveWindow )
  60. return;
  61. g_pInputSystem->PollInputState();
  62. vgui::ivgui()->RunFrame();
  63. g_pMatSystemSurface->AttachToWindow( NULL, false );
  64. g_pInputSystem->DetachFromWindow( );
  65. if ( pVGuiWnd )
  66. {
  67. m_pActiveWindow = pVGuiWnd;
  68. g_pInputSystem->AttachToWindow( pVGuiWnd->GetParentWnd()->GetSafeHwnd() );
  69. g_pMatSystemSurface->AttachToWindow( pVGuiWnd->GetParentWnd()->GetSafeHwnd(), false );
  70. vgui::ivgui()->ActivateContext( pVGuiWnd->GetVGuiContext() );
  71. }
  72. else
  73. {
  74. m_pActiveWindow = NULL;
  75. vgui::ivgui()->ActivateContext( vgui::DEFAULT_VGUI_CONTEXT );
  76. }
  77. }
  78. bool CHammerVGui::HasFocus( CVGuiWnd *pWnd )
  79. {
  80. return m_pActiveWindow == pWnd;
  81. }
  82. void CHammerVGui::Simulate()
  83. {
  84. // VPROF( "CHammerVGui::Simulate" );
  85. if ( !IsInitialized() )
  86. return;
  87. g_pInputSystem->PollInputState();
  88. vgui::ivgui()->RunFrame();
  89. // run vgui animations
  90. vgui::GetAnimationController()->UpdateAnimations( vgui::system()->GetCurrentTime() );
  91. }
  92. void CHammerVGui::Shutdown()
  93. {
  94. // Give panels a chance to settle so things
  95. // Marked for deletion will actually get deleted
  96. if ( !IsInitialized() )
  97. return;
  98. g_pInputSystem->PollInputState();
  99. vgui::ivgui()->RunFrame();
  100. // stop the App running
  101. vgui::ivgui()->Stop();
  102. }
  103. CHammerVGui::~CHammerVGui(void)
  104. {
  105. }