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.

183 lines
5.9 KiB

  1. //================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
  2. //
  3. // ilaunchermgr.h
  4. //
  5. //==================================================================================================
  6. #ifndef ILAUNCHERMGR_H
  7. #define ILAUNCHERMGR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #if defined( USE_SDL ) || defined( OSX ) || defined( LINUX )
  12. // Purpose: The overlay doesn't properly work on OS X 64-bit because a bunch of
  13. // Cocoa functions that we hook were never ported to 64-bit. Until that is fixed,
  14. // we basically have to work around this by making sure the cursor is visible
  15. // and set to something that is reasonable for usage in the overlay.
  16. #if ( defined( OSX ) && defined( PLATFORM_64BITS ) && !defined( NO_STEAM ) )
  17. #define WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND 1
  18. #endif
  19. #include "tier0/threadtools.h"
  20. #include "appframework/iappsystem.h"
  21. #include "inputsystem/iinputsystem.h"
  22. #include "togl/glmgrbasics.h"
  23. #include "togl/glmdisplay.h"
  24. // if you rev this version also update materialsystem/cmaterialsystem.cpp CMaterialSystem::Connect as it defines the string directly
  25. #if defined( USE_SDL )
  26. #define SDLMGR_INTERFACE_VERSION "SDLMgrInterface001"
  27. #elif defined( OSX )
  28. #define COCOAMGR_INTERFACE_VERSION "CocoaMgrInterface006"
  29. #endif
  30. class GLMDisplayDB;
  31. class CCocoaEvent;
  32. class CShowPixelsParams;
  33. class CStackCrawlParams;
  34. #if defined( USE_SDL )
  35. typedef struct SDL_Cursor SDL_Cursor;
  36. #endif
  37. class ILauncherMgr : public IAppSystem
  38. {
  39. public:
  40. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  41. virtual void Disconnect() = 0;
  42. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  43. // Init, shutdown
  44. virtual InitReturnVal_t Init() = 0;
  45. virtual void Shutdown() = 0;
  46. // Create the window.
  47. #ifdef USE_SDL
  48. virtual bool CreateGameWindow( const char *pTitle, bool bWindowed, int width, int height, bool bDesktopFriendlyFullscreen ) = 0;
  49. #else
  50. virtual bool CreateGameWindow( const char *pTitle, bool bWindowed, int width, int height ) = 0;
  51. #endif
  52. virtual void GetDesiredPixelFormatAttribsAndRendererInfo( uint **ptrOut, uint *countOut, GLMRendererInfoFields *rendInfoOut ) = 0;
  53. // Get the NSGLContext for a window's main view - note this is the carbon windowref as an argument
  54. virtual PseudoGLContextPtr GetGLContextForWindow( void* windowref ) = 0;
  55. // Get the next N events. The function returns the number of events that were filled into your array.
  56. virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false ) = 0;
  57. // Set the mouse cursor position.
  58. virtual void SetCursorPosition( int x, int y ) = 0;
  59. virtual void ShowPixels( CShowPixelsParams *params ) = 0;
  60. #ifdef USE_SDL
  61. virtual void SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight, bool bDesktopFriendlyFullscreen ) = 0;
  62. #else
  63. virtual void SetWindowFullScreen( bool bFullScreen, int nWidth, int nHeight ) = 0;
  64. #endif
  65. virtual bool IsWindowFullScreen() = 0;
  66. virtual void MoveWindow( int x, int y ) = 0;
  67. virtual void SizeWindow( int width, int tall ) = 0;
  68. virtual void PumpWindowsMessageLoop() = 0;
  69. virtual void DestroyGameWindow() = 0;
  70. virtual void SetApplicationIcon( const char *pchAppIconFile ) = 0;
  71. virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta = false ) = 0;
  72. virtual void GetNativeDisplayInfo( int nDisplay, uint &nWidth, uint &nHeight, uint &nRefreshHz ) = 0; // Retrieve the size of the monitor (desktop)
  73. virtual void RenderedSize( uint &width, uint &height, bool set ) = 0; // either set or retrieve rendered size value (from dxabstract)
  74. virtual void DisplayedSize( uint &width, uint &height ) = 0; // query backbuffer size (window size whether FS or windowed)
  75. virtual GLMDisplayDB *GetDisplayDB( void ) = 0;
  76. virtual void WaitUntilUserInput( int msSleepTime ) = 0;
  77. virtual PseudoGLContextPtr GetMainContext() = 0;
  78. virtual PseudoGLContextPtr CreateExtraContext() = 0;
  79. virtual void DeleteContext( PseudoGLContextPtr hContext ) = 0;
  80. virtual bool MakeContextCurrent( PseudoGLContextPtr hContext ) = 0;
  81. virtual void GetStackCrawl( CStackCrawlParams *params ) = 0;
  82. virtual void *GetWindowRef() = 0;
  83. virtual void SetMouseVisible( bool bState ) = 0;
  84. #ifdef USE_SDL
  85. virtual int GetActiveDisplayIndex() = 0;
  86. virtual void SetMouseCursor( SDL_Cursor *hCursor ) = 0;
  87. virtual void SetForbidMouseGrab( bool bForbidMouseGrab ) = 0;
  88. virtual void OnFrameRendered() = 0;
  89. #endif
  90. #ifndef OSX
  91. virtual void SetGammaRamp( const uint16 *pRed, const uint16 *pGreen, const uint16 *pBlue ) = 0;
  92. #endif
  93. #if WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND
  94. virtual void ForceSystemCursorVisible() = 0;
  95. virtual void UnforceSystemCursorVisible() = 0;
  96. #endif
  97. virtual double GetPrevGLSwapWindowTime() = 0;
  98. };
  99. extern ILauncherMgr *g_pLauncherMgr;
  100. enum CocoaEventType_t
  101. {
  102. CocoaEvent_KeyDown,
  103. CocoaEvent_KeyUp,
  104. CocoaEvent_MouseButtonDown,
  105. CocoaEvent_MouseMove,
  106. CocoaEvent_MouseButtonUp,
  107. CocoaEvent_AppActivate,
  108. CocoaEvent_MouseScroll,
  109. CocoaEvent_AppQuit,
  110. CocoaEvent_Deleted, // Event was one of the above, but has been handled and should be ignored now.
  111. };
  112. // enum values need to match bit-shifting logic in CInputSystem::UpdateMouseButtonState and
  113. // the codes from NSEvent pressedMouseButtons, turns out the two are in agreement right now
  114. enum CocoaMouseButton_t
  115. {
  116. COCOABUTTON_LEFT = 1 << 0,
  117. COCOABUTTON_RIGHT = 1 << 1,
  118. COCOABUTTON_MIDDLE = 1 << 2,
  119. COCOABUTTON_4 = 1 << 3,
  120. COCOABUTTON_5 = 1 << 4,
  121. };
  122. enum ECocoaKeyModifier
  123. {
  124. eCapsLockKey,
  125. eShiftKey,
  126. eControlKey,
  127. eAltKey, // aka option
  128. eCommandKey
  129. };
  130. class CCocoaEvent
  131. {
  132. public:
  133. CocoaEventType_t m_EventType;
  134. int m_VirtualKeyCode;
  135. wchar_t m_UnicodeKey;
  136. wchar_t m_UnicodeKeyUnmodified;
  137. uint m_ModifierKeyMask; //
  138. int m_MousePos[2];
  139. int m_MouseButtonFlags; // Current state of the mouse buttons. See COCOABUTTON_xxxx.
  140. uint m_nMouseClickCount;
  141. int m_MouseButton; // which of the CocoaMouseButton_t buttons this is for from above
  142. };
  143. #endif // defined( USE_SDL ) || defined( OSX ) || defined( LINUX)
  144. #endif // ILAUNCHERMGR_H