Counter Strike : Global Offensive Source Code
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.

120 lines
3.3 KiB

  1. //=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. //=============================================================================
  9. #ifdef _WIN32
  10. #include "appframework/vguimaterialsystem2app.h"
  11. #include "vgui/IVGui.h"
  12. #include "vgui/ISurface.h"
  13. #include "vgui_controls/controls.h"
  14. #include "vgui/IScheme.h"
  15. #include "vgui/ILocalize.h"
  16. #include "tier0/dbg.h"
  17. #include "vguirendersurface/ivguirendersurface.h"
  18. #include "tier3/tier3.h"
  19. #include "interfaces/interfaces.h"
  20. #include "inputsystem/iinputstacksystem.h"
  21. //-----------------------------------------------------------------------------
  22. // Constructor
  23. //-----------------------------------------------------------------------------
  24. CVGuiMaterialSystem2App::CVGuiMaterialSystem2App()
  25. {
  26. m_hAppInputContext = INPUT_CONTEXT_HANDLE_INVALID;
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Create all singleton systems
  30. //-----------------------------------------------------------------------------
  31. bool CVGuiMaterialSystem2App::Create()
  32. {
  33. if ( !BaseClass::Create() )
  34. return false;
  35. AppSystemInfo_t appSystems[] =
  36. {
  37. { "inputsystem.dll", INPUTSTACKSYSTEM_INTERFACE_VERSION },
  38. // NOTE: This has to occur before vgui2.dll so it replaces vgui2's surface implementation
  39. { "vguirendersurface.dll", VGUI_SURFACE_INTERFACE_VERSION },
  40. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  41. // Required to terminate the list
  42. { "", "" }
  43. };
  44. return AddSystems( appSystems );
  45. }
  46. void CVGuiMaterialSystem2App::Destroy()
  47. {
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Init, shutdown
  51. //-----------------------------------------------------------------------------
  52. bool CVGuiMaterialSystem2App::PreInit( )
  53. {
  54. if ( !BaseClass::PreInit() )
  55. return false;
  56. CreateInterfaceFn factory = GetFactory();
  57. ConnectTier3Libraries( &factory, 1 );
  58. if ( !vgui::VGui_InitInterfacesList( "CVGuiMaterialSystem2App", &factory, 1 ) )
  59. return false;
  60. if ( !g_pVGuiRenderSurface )
  61. {
  62. Warning( "CVGuiMaterialSystem2App::PreInit: Unable to connect to necessary interface!\n" );
  63. return false;
  64. }
  65. return true;
  66. }
  67. bool CVGuiMaterialSystem2App::PostInit()
  68. {
  69. if ( !BaseClass::PostInit() )
  70. return false;
  71. m_hAppInputContext = g_pInputStackSystem->PushInputContext();
  72. InputContextHandle_t hVGuiInputContext = g_pInputStackSystem->PushInputContext();
  73. g_pVGuiRenderSurface->SetInputContext( hVGuiInputContext );
  74. g_pVGuiRenderSurface->EnableWindowsMessages( true );
  75. return true;
  76. }
  77. void CVGuiMaterialSystem2App::PreShutdown()
  78. {
  79. g_pVGuiRenderSurface->EnableWindowsMessages( false );
  80. g_pVGuiRenderSurface->SetInputContext( NULL );
  81. if ( m_hAppInputContext != INPUT_CONTEXT_HANDLE_INVALID )
  82. {
  83. g_pInputStackSystem->PopInputContext(); // Vgui
  84. g_pInputStackSystem->PopInputContext(); // App
  85. }
  86. BaseClass::PreShutdown();
  87. }
  88. void CVGuiMaterialSystem2App::PostShutdown()
  89. {
  90. DisconnectTier3Libraries();
  91. BaseClass::PostShutdown();
  92. }
  93. InputContextHandle_t CVGuiMaterialSystem2App::GetAppInputContext()
  94. {
  95. return m_hAppInputContext;
  96. }
  97. #endif // _WIN32