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.

140 lines
3.4 KiB

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