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.

746 lines
30 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef IUIENGINE_H
  6. #define IUIENGINE_H
  7. #pragma once
  8. #include "tier0/platform.h"
  9. #if defined( SOURCE2_PANORAMA )
  10. #include "tier0/platwindow.h"
  11. #endif
  12. #include "tier1/convar.h"
  13. #include "panorama.h"
  14. #include "./iuipanel.h"
  15. #include "utlsymbol.h"
  16. #include "panoramatypes.h"
  17. #include "iuilayoutmanager.h"
  18. #include "controls/panelhandle.h"
  19. #include "tier1/utllinkedlist.h"
  20. #include "tier1/utlstring.h"
  21. #include "tier1/utldelegate.h"
  22. #include "tier0/validator.h"
  23. #ifdef SOURCE_PANORAMA_FIXME
  24. #include "tier1/UtlSortVector.h"
  25. #else
  26. #include "tier1/utlsortvector.h"
  27. #endif
  28. #include "language.h"
  29. #include "panorama/layout/panel2dfactory.h"
  30. #include "iuistylefactory.h"
  31. #include "interface.h"
  32. #include "steam/isteamhttp.h"
  33. #include "iuifilesystem.h"
  34. #if !defined( SOURCE2_PANORAMA )
  35. #include "audio/iaudiointerface.h"
  36. #include <openvr.h>
  37. #endif
  38. #if _GNUC
  39. #pragma GCC diagnostic push
  40. #pragma GCC diagnostic ignored "-Wshadow"
  41. #endif
  42. #if defined( SOURCE2_PANORAMA )
  43. #include "../thirdparty/v8/include/v8.h"
  44. #else
  45. #include "tier0/memdbgoff.h"
  46. #include "../external/v8/include/v8.h"
  47. #include "tier0/memdbgon.h"
  48. #endif
  49. #if _GNUC
  50. #pragma GCC diagnostic pop
  51. #endif
  52. #ifdef SUPPORTS_AUDIO
  53. class IAudioOutputStream;
  54. #endif
  55. typedef uint64 GID_t;
  56. class KeyValues;
  57. #if !defined( SOURCE2_PANORAMA )
  58. class IHTMLChromeController;
  59. #endif
  60. typedef CUtlDelegate< void( GID_t, KeyValues *, void * ) > JSONWebAPIDelegate_t;
  61. #if defined( SOURCE2_PANORAMA )
  62. DECLARE_LOGGING_CHANNEL( LOG_PANORAMA );
  63. DECLARE_LOGGING_CHANNEL( LOG_PANORAMA_SCRIPT );
  64. #endif
  65. namespace v8
  66. {
  67. class Isolate;
  68. }
  69. namespace panorama
  70. {
  71. // forward decl for engine components
  72. class CUIProtoBufMsgMemoryPoolMgr;
  73. class CUIRenderEngine;
  74. class IUIInput;
  75. class IUIEvent;
  76. class IUILocalization;
  77. class IUISoundSystem;
  78. class IUILayoutManager;
  79. class CMovieManager;
  80. class IUITextLayout;
  81. class IUISettings;
  82. class IUIWindow;
  83. class CPanelStyle;
  84. class IUIJSObject;
  85. typedef void * HAUDIOSAMPLE;
  86. class IUIEngineFrameListener
  87. {
  88. public:
  89. virtual void OnPreFrame() = 0;
  90. virtual void OnPostFrame() = 0;
  91. virtual void OnEngineShutdown() = 0;
  92. };
  93. class CJSONWebAPIParams
  94. {
  95. public:
  96. struct WebAPIParam_t
  97. {
  98. CUtlString strParamName;
  99. CUtlString strParamValue;
  100. };
  101. CJSONWebAPIParams() { }
  102. void AddParam( const char *pchParamName, const char *pchParamValue )
  103. {
  104. int iVec = m_vecParams.AddToTail();
  105. WebAPIParam_t &param = m_vecParams[iVec];
  106. param.strParamName = pchParamName;
  107. param.strParamValue = pchParamValue;
  108. }
  109. CUtlVector<WebAPIParam_t> *AccessParams() { return &m_vecParams; }
  110. private:
  111. CCopyableUtlVector< WebAPIParam_t > m_vecParams;
  112. };
  113. typedef void (*PanoramaFrameFunc_t)();
  114. typedef int JSGenericCallbackHandle_t;
  115. const JSGenericCallbackHandle_t JS_GENERIC_CALLBACK_HANDLE_INVALID = -1;
  116. struct RegisterJSScopeInfo_t
  117. {
  118. const char *pName;
  119. const char *pDescription;
  120. int nEntries;
  121. };
  122. enum RegisterJSType_t : uint8
  123. {
  124. k_ERegisterJSTypeUnknown,
  125. k_ERegisterJSTypeInvalid,
  126. k_ERegisterJSTypeVoid,
  127. k_ERegisterJSTypeBool,
  128. k_ERegisterJSTypeInt8,
  129. k_ERegisterJSTypeUint8,
  130. k_ERegisterJSTypeInt16,
  131. k_ERegisterJSTypeUint16,
  132. k_ERegisterJSTypeInt32,
  133. k_ERegisterJSTypeUint32,
  134. k_ERegisterJSTypeInt64,
  135. k_ERegisterJSTypeUint64,
  136. k_ERegisterJSTypeFloat,
  137. k_ERegisterJSTypeDouble,
  138. k_ERegisterJSTypeConstString,
  139. k_ERegisterJSTypePanoramaSymbol,
  140. k_ERegisterJSTypeRawV8Args,
  141. };
  142. struct RegisterJSEntryInfo_t
  143. {
  144. enum
  145. {
  146. k_EGlobalFunction = 0x00000000,
  147. k_EMethod = 0x00000001,
  148. k_EAccessor = 0x00000002,
  149. k_EAccessorReadOnly = 0x00000003,
  150. k_EConstantValue = 0x00000004,
  151. k_EEntryTypeMask = 0x0000000f,
  152. };
  153. const char *pName;
  154. const char *pDescription;
  155. uint32 unFlags;
  156. // Return or value type.
  157. RegisterJSType_t eDataType;
  158. // Prototype information may not be known.
  159. static const uint8 k_unNumParamsUnknown = 0xff;
  160. uint8 unNumParams;
  161. static const uint8 k_unMaxParams = 10;
  162. RegisterJSType_t pParamTypes[k_unMaxParams];
  163. uint32 GetEntryType() const
  164. {
  165. return unFlags & k_EEntryTypeMask;
  166. }
  167. };
  168. //
  169. // Interface that needs to be implemented for game engines on all platforms
  170. //
  171. class IUIEngine
  172. {
  173. public:
  174. enum ERenderTarget
  175. {
  176. // these assignments are important because they are cross-cast at the protobuf layer
  177. k_ERenderToWindow = 1,
  178. k_ERenderFullScreen = 2,
  179. k_ERenderBorderlessFullScreenWindow = 3,
  180. k_ERenderToOverlayTexture = 4,
  181. k_ERenderToOverlaySharedTexture = 5,
  182. k_ERenderToOverlaySteamWM = 6,
  183. k_ERenderToLegacyVR = 7, // This one is used for the Steam Client's main interface and will die eventually
  184. k_ERenderToOpenVROverlay = 8,
  185. k_ERenderTargetUnset = 0,
  186. };
  187. enum EHapticFeedbackPosition
  188. {
  189. k_EHapticFeedbackPosition_Left,
  190. k_EHapticFeedbackPosition_Right,
  191. };
  192. enum EHapticFeedbackStrength
  193. {
  194. k_EHapticFeedbackStrength_VeryLow,
  195. k_EHapticFeedbackStrength_Low,
  196. k_EHapticFeedbackStrength_Medium,
  197. k_EHapticFeedbackStrength_High,
  198. };
  199. // return true if the states are different and a valid transition. Used to test fullscreen transition
  200. static bool BValidRenderStateChange( ERenderTarget eCurrentRenderTarget, ERenderTarget eRequestedRenderTarget );
  201. static bool BIsRenderingToTexture( ERenderTarget eTarget ) { return (eTarget == k_ERenderToOverlayTexture || eTarget == k_ERenderToOverlaySharedTexture || eTarget == k_ERenderToOpenVROverlay ); }
  202. static bool BIsOverlayTarget( ERenderTarget eTarget )
  203. {
  204. return (eTarget == IUIEngine::k_ERenderToOverlayTexture ||
  205. eTarget == IUIEngine::k_ERenderToOverlaySharedTexture ||
  206. eTarget == IUIEngine::k_ERenderToOverlaySteamWM);
  207. }
  208. static bool BIsRenderingToLegacyVR( ERenderTarget eTarget ) { return (eTarget == k_ERenderToLegacyVR); }
  209. static bool BIsRenderingToOpenVROverlay( ERenderTarget eTarget ) { return (eTarget == k_ERenderToOpenVROverlay); }
  210. static bool BIsRenderingToFullScreen( ERenderTarget eTarget ) { return (eTarget == k_ERenderFullScreen); }
  211. public:
  212. virtual ~IUIEngine() {}
  213. // Starts up subsystems and makes engine ready for use, you need to call RegisterNamedLocalPath() for at least the <config> path first!
  214. #if defined( SOURCE2_PANORAMA )
  215. virtual bool StartupSubsystems( IUISettings *psettings, PlatWindow_t hWindow ) = 0;
  216. #else
  217. virtual bool StartupSubsystems( IUISettings *psettings, IHTMLChromeController *pHTMLController ) = 0;
  218. #endif
  219. // Hookup convars
  220. virtual void ConCommandInit( IConCommandBaseAccessor *pAccessor ) = 0;
  221. // Shutdown
  222. virtual void Shutdown() = 0;
  223. virtual void RequestShutdown() = 0;
  224. // Run will run frames and block, letting the UI engine control the whole frame loop.
  225. virtual void Run() = 0;
  226. // Run frame will run a single frame, letting you wrap the UI engine in an external frame loop
  227. virtual void RunFrame() = 0;
  228. // Will set the UI engine to aggressively limit frame rate it runs at to avoid resource usage
  229. virtual void SetAggressiveFrameRateLimit( bool bLimit ) = 0;
  230. virtual bool BIsRunning() = 0;
  231. virtual bool BHasFocus() = 0;
  232. virtual double GetCurrentFrameTime() = 0;
  233. #if !defined( SOURCE2_PANORAMA )
  234. virtual IUIWindow *CreateNewWindow( const char *pchWindowTitle, uint32 width, uint32 height, ERenderTarget eRenderType, bool bFixedSurfaceSize, bool bEnforceWindowAspectRatio, bool bUseCustomMouseCursor, const char *pchMonitorName ) = 0;
  235. virtual IUIWindow *CreateNewOverlayWindow( const char *pchWindowTitle, uint32 width, uint32 height, panorama::IUIEngine::ERenderTarget eTarget, bool bFixedSize, bool bDrawCustomMouseCursor ) = 0;
  236. virtual IUIWindow *CreateNewOpenVROverlayWindow( uint32 width, uint32 height, vr::VROverlayHandle_t ulOverlayHandle ) = 0;
  237. #else
  238. virtual IUIWindow *CreateNewUILayerWindow( uint32 xPos, uint32 yPos, uint32 width, uint32 height, bool bFixedSurfaceSize, bool bEnforceWindowAspectRatio, bool bUseCustomMouseCursor, bool bAcceptKBandMouse, const char *pName ) = 0;
  239. #endif
  240. virtual IUITextLayout *CreateTextLayout( const char *pchText, const char *pchFontName, float flSize, float flLineHeight, EFontWeight weight, EFontStyle style, ETextAlign align, bool bWrap, bool bEllipsis, int nLetterSpacing, float flMaxWidth, float flMaxHeight ) = 0;
  241. virtual IUITextLayout *CreateTextLayout( const wchar_t *pwchText, const char *pchFontName, float flSize, float flLineHeight, EFontWeight weight, EFontStyle style, ETextAlign align, bool bWrap, bool bEllipsis, int nLetterSpacing, float flMaxWidth, float flMaxHeight ) = 0;
  242. virtual void FreeTextLayout( IUITextLayout *pLayout ) = 0;
  243. virtual const CUtlSortVector< CUtlString > &GetSortedValidFontNames() = 0;
  244. virtual IUIInput *UIInputEngine() = 0;
  245. virtual IUILocalization *UILocalize() = 0;
  246. virtual IUISoundSystem *UISoundSystem() = 0;
  247. virtual IUISettings *UISettings() = 0;
  248. virtual IUILayoutManager *UILayoutManager() = 0;
  249. virtual IUIFileSystem *UIFileSystem() = 0;
  250. virtual void RegisterFrameFunc( PanoramaFrameFunc_t frameFunc ) = 0;
  251. virtual void ReloadLayoutFile( CPanoramaSymbol symPath ) = 0;
  252. virtual void ToggleDebugMode() = 0;
  253. virtual CUtlLinkedList<CUtlString> &GetConsoleHistory() = 0;
  254. // panel management
  255. virtual IUIPanel * CreatePanel() = 0;
  256. virtual void PanelDestroyed( IUIPanel *pPanel, IUIPanel *pOldParent ) = 0;
  257. virtual bool IsValidPanelPointer( const IUIPanel *pPanel ) = 0;
  258. virtual PanelHandle_t GetPanelHandle( const IUIPanel *pPanel ) = 0;
  259. virtual IUIPanel *GetPanelPtr( const PanelHandle_t &handle ) = 0;
  260. virtual void CallBeforeStyleAndLayout( IUIPanel *pPanel ) = 0;
  261. // registration for panel destroyed
  262. typedef CUtlDelegate< void( const panorama::IUIPanel *, IUIPanel *pOldParent ) > PanelDestroyedDel_t;
  263. virtual void RegisterForPanelDestroyed( PanelDestroyedDel_t del ) = 0;
  264. virtual void UnregisterForPanelDestroyed( PanelDestroyedDel_t del ) = 0;
  265. // Event management
  266. virtual void RegisterEventHandler( CPanoramaSymbol symMsg, IUIPanel *pPanel, CUtlAbstractDelegate pFunc ) = 0;
  267. virtual void UnregisterEventHandler( CPanoramaSymbol symMsg, IUIPanel *pPanel, CUtlAbstractDelegate pFunc ) = 0;
  268. virtual void RegisterEventHandler( CPanoramaSymbol symMsg, IUIPanelClient *pPanel, CUtlAbstractDelegate pFunc ) = 0;
  269. virtual void UnregisterEventHandler( CPanoramaSymbol symMsg, IUIPanelClient *pPanel, CUtlAbstractDelegate pFunc ) = 0;
  270. virtual void UnregisterEventHandlersForPanel( IUIPanel *pPanel ) = 0;
  271. virtual void RegisterForUnhandledEvent( CPanoramaSymbol symMsg, CUtlAbstractDelegate pFunc ) = 0;
  272. virtual void UnregisterForUnhandledEvent( CPanoramaSymbol symMsg, CUtlAbstractDelegate pFunc ) = 0;
  273. virtual bool BHaveEventHandlersRegisteredForType( CPanoramaSymbol symPanelType ) = 0;
  274. virtual void RegisterPanelTypeEventHandler( CPanoramaSymbol symMsg, CPanoramaSymbol symPanelType, CUtlAbstractDelegate pFunc, bool bThisPtrIsUIPanel = false ) = 0;
  275. virtual bool DispatchEvent( IUIEvent *pEvent ) = 0;
  276. virtual void DispatchEventAsync( float flDelay, IUIEvent *pEvent ) = 0;
  277. virtual bool BAnyHandlerRegisteredForEvent( const CPanoramaSymbol &symEvent ) = 0;
  278. virtual CPanoramaSymbol GetLastDispatchedEventSymbol() = 0;
  279. virtual IUIPanel *GetLastDispatchedEventTargetPanel() = 0;
  280. // Event filtering
  281. virtual void RegisterEventFilter( CUtlAbstractDelegate pFunc ) = 0;
  282. virtual void UnregisterEventFilter( CUtlAbstractDelegate pFunc ) = 0;
  283. // Repaints all windows immediately, queuing for animation/render threads
  284. virtual void LayoutAndPaintWindows() = 0;
  285. // Get install path for the application
  286. virtual const char *GetApplicationInstallPath() = 0;
  287. // Get the userdata path for the application
  288. virtual const char *GetApplicationUserDataPath() = 0;
  289. // Register a named local path (executable-relative, readonly on POSIX) for resources, should be something like {images} or {movies}
  290. virtual void RegisterNamedLocalPath( const char *pathName, const char *pchLocalPath, bool bWatchForFileChanges, bool bAddToOverwriteIfExists = false ) = 0;
  291. // Register a named userdata path (userdata-relative, writable on POSIX) for local read/write storage like {config}
  292. virtual void RegisterNamedUserPath( const char *pathName, const char *pchUserPath, bool bWatchForFileChanges, bool bAddToOverwriteIfExists = false ) = 0;
  293. // Register the path to load custom vfont files from
  294. virtual void RegisterCustomFontPath( const char *pchFontPath ) = 0;
  295. // Get the local path for a named path like {images} or {movies}
  296. virtual const char *GetLocalPathForNamedPath( const char *pathName ) = 0;
  297. // Get the local path for a named path like {images} or {movies} combined with the relative pathname
  298. // and also following up the possible overwritten paths
  299. virtual void GetLocalPathForRelativePath( const char *pchLocalPathName, const char *pchRelativePathname, CUtlString &strLocalPath ) = 0;
  300. // Register for a named hostname in http:// paths like {steamcommunity}
  301. virtual void RegisterNamedRemoteHost( const char *hostName, const char*pchRemoteHost ) = 0;
  302. // Get the named host for a named remote host like {steamcommunity}
  303. virtual const char *GetRemoteHostForNamedHost( const char *hostName ) = 0;
  304. // Register an additional X-Header to be sent when requesting layout from the web
  305. virtual void RegisterXHeader( const char *pchHeaderName, const char *pchHeaderValue ) = 0;
  306. // Get the current count of registers X-Headers
  307. virtual int GetXHeaderCount() const = 0;
  308. // Get the name and value for the given indexed X-Header
  309. virtual void GetXHeader( int i, CUtlString &strName, CUtlString &strValue ) const = 0;
  310. // Set the cookie header to use for the named remote host
  311. virtual void SetCookieHeaderForNamedRemoteHost( const char *hostName, const CUtlVector<CUtlString> &vecCookies ) = 0;
  312. // Sets the cookie header to use for the remote host (doesn't require named host use)
  313. virtual void SetCookieHeaderForRemoteHost( const char *hostName, const CUtlVector<CUtlString> &vecCookies ) = 0;
  314. // Get the cookie header string that should be used for the remote host
  315. virtual const CUtlVector<CUtlString> &GetCookieHeadersForNamedRemoteHost( const char *namedRemoteHost ) = 0;
  316. // Get the cookie header string that should be used for the remote host
  317. virtual const CUtlVector<CUtlString> &GetCookieHeadersForRemoteHost( const char *hostName ) = 0;
  318. // Gets the value of a cookie. Returns false if the cookie does not exist.
  319. virtual bool GetCookieValueForRemoteHost( const char *hostName, const char *cookieName, CUtlString *pstrCookieValue ) = 0;
  320. #if defined( SOURCE2_PANORAMA ) || defined( PANORAMA_PUBLIC_STEAM_SDK )
  321. virtual ISteamHTMLSurface *AccessHTMLController() = 0;
  322. #else
  323. virtual IHTMLChromeController *AccessHTMLController() = 0;
  324. #endif
  325. // native message box. Used usually for development.
  326. enum ENativeMessageBoxType_t
  327. {
  328. k_ENativeMessageOk = 1,
  329. k_ENativeMessageYesNo = 2
  330. };
  331. virtual bool ShowNativeTopMostMessageBox( const char *pchMsg, const char *pchTitle, ENativeMessageBoxType_t eType ) = 0;
  332. // Add a listener callback for pre/post frame events
  333. virtual void AddFrameListener( IUIEngineFrameListener *pListener ) = 0;
  334. // Remove a listener callback for pre/post frame events
  335. virtual void RemoveFrameListener( IUIEngineFrameListener *pListener ) = 0;
  336. // storage for mouse can activate info
  337. virtual void RegisterMouseCanActivateParent( IUIPanel *pPanel, const char *pchParent ) = 0;
  338. virtual void UnregisterMouseCanActivateParent( IUIPanel *pPanel ) = 0;
  339. virtual const char *GetMouseCanActivateParent( IUIPanel *pPanel ) = 0;
  340. // See if any window owned by the ui engine has focus
  341. virtual bool BAnyWindowHasFocus() = 0;
  342. // See if any window owned by the ui engine is visible and has focus, sometimes overlay windows have focus but are not visible
  343. // and you generally don't want to consider them as focused then
  344. virtual bool BAnyVisibleWindowHasFocus() = 0;
  345. // See if any overlay window owned by the ui engine has focus
  346. virtual bool BAnyOverlayWindowHasFocus() = 0;
  347. // Get the focused window, there should really be only one, if some bug allows multiple the first found is returned
  348. virtual IUIWindow *GetFocusedWindow() = 0;
  349. // Get the last time any input event happened across any of our windows
  350. virtual double GetLastInputTime() = 0;
  351. // Called internally from input layer to update last input time to current frame
  352. virtual void UpdateLastInputTime() = 0;
  353. // Clipboard access
  354. virtual void CopyToClipboard( const char *pchTextUTF8 ) = 0;
  355. virtual void GetClipboardText( CUtlString &strUTF8 ) = 0;
  356. // Input locale support
  357. virtual ELanguage GetDisplayLanguage() = 0;
  358. virtual ELanguage GetCurrentInputLocale() = 0;
  359. virtual bool BHaveInputLocale( ELanguage language ) = 0;
  360. virtual void SetInputLocale( ELanguage language ) = 0;
  361. // Overlay tracking
  362. virtual bool BHasOverlayForApp( uint64 gameID, uint64 ulPID ) = 0;
  363. virtual void TrackOverlayForApp( uint64 gameID, uint64 ulPID, void * pOverlay ) = 0;
  364. virtual void DeleteOverlayInstanceForApp( uint64 gameID, uint64 dwPID, void * pOverlay ) = 0;
  365. virtual void *OverlayForApp( uint64 gameID, uint64 ulPID ) = 0;
  366. // GPU Information
  367. virtual bool BGetGPUInformation( char *rgchGPUDesc, uint32 unGPUDescBytes, uint64 *pulDedicatedGPUMem, uint64 *pulDedicatedSystemMem, uint64 *pulSharedMem ) = 0;
  368. // Pool allocations for panel styles
  369. virtual IUIPanelStyle *AllocPanelStyle( IUIPanel *pStyle, float flUIScaleFactor ) = 0;
  370. virtual void FreePanelStyle( IUIPanelStyle *pPanel ) = 0;
  371. virtual void SetPanelWaitingAsyncDelete( IUIPanel *pPanel ) = 0;
  372. virtual bool BIsPanelWaitingAsyncDelete( IUIPanel *pPanel ) = 0;
  373. virtual void PulseActiveControllerHaptic( EHapticFeedbackPosition ePosition, EHapticFeedbackStrength eStrength ) = 0;
  374. virtual void MarkLayerToRepaintThreadSafe( uint64 ulCompositionLayerID ) = 0;
  375. virtual void AddDirectoryChangeWatch( const char *pchPath ) = 0;
  376. // Get how many lines to scroll for mouse wheel
  377. virtual uint32 GetWheelScrollLines() = 0;
  378. // Execute some javascript in the given panel context
  379. virtual void RunScript( IUIPanel *pPanelContext, const char *pchScriptString, const char *pchSourceFilename, int nSourceBeginLine, int nSourceBeginCol, bool bPrintRetValue ) = 0;
  380. // Expose a new object type/template to javascript with the given name,
  381. // the function pointer passed should setup member accssors/methods with the functions
  382. // from uijsregistration.h
  383. virtual void ExposeObjectTypeToJavaScript( const char *pchObjectTypeName, CUtlAbstractDelegate &del ) = 0;
  384. // Expose an instance of an object type as a global with specified name to javascript
  385. virtual void ExposeGlobalObjectToJavaScript( const char *pchJSVarName, void *pInstance, const char *pchJsTypeName, bool bTrueGlobal = false ) = 0;
  386. virtual void ClearGlobalObjectForJavaScript( const char *pchJSVarName, void *pInstance ) = 0;
  387. virtual void DeleteJSObjectInstance( IUIJSObject *pInstance ) = 0;
  388. // Get panel that contains the javascript context
  389. virtual panorama::IUIPanel *GetPanelForJavaScriptContext( v8::Context *pContext ) = 0;
  390. // Get javascript context for a panel (may be NULL)
  391. virtual v8::Persistent<v8::Context> *GetJavaScriptContextForPanel( panorama::IUIPanel *pPanel ) = 0;
  392. // Helper to spew exceptions to console
  393. virtual void OutputJSExceptionToConsole( v8::TryCatch &try_catch, IUIPanel *pPanelContext ) = 0;
  394. // Add a function template to global namespace, by default this is really panorama., but you can specify to make it really global as well
  395. virtual void AddGlobalV8FunctionTemplate( const char *pchJSFuncName, v8::Handle< v8::FunctionTemplate > *pFunc, bool bTrueGlobal = false ) = 0;
  396. // Get global v8 context
  397. virtual v8::Persistent<v8::Context> &GetV8GlobalContext() = 0;
  398. // Access the current object template we are setting up
  399. virtual v8::Handle<v8::ObjectTemplate> GetCurrentV8ObjectTemplateToSetup() = 0;
  400. // Allow access to the proto buf msg memory pool
  401. virtual CUIProtoBufMsgMemoryPoolMgr *MsgMemoryPoolMgr() = 0;
  402. // Allow access to style factory interface
  403. virtual IUIStyleFactory *UIStyleFactory() = 0;
  404. // Various code that uses JS needs this
  405. virtual v8::Isolate * GetV8Isolate() = 0;
  406. // Create a V8 object to wrap a panel
  407. virtual v8::Persistent<v8::Object> *CreateV8PanelInstance( IUIPanel *pPanel ) = 0;
  408. // Helper to create a JS object to wrap a given panel style
  409. virtual v8::Persistent<v8::Object> *CreateV8PanelStyleInstance( IUIPanelStyle *pPanelStyle ) = 0;
  410. // Helper to create JS object for given js object type
  411. virtual v8::Persistent<v8::Object> *CreateV8ObjectInstance( const char *pchObjectType, void *pActualObject, IUIJSObject *pJSObject ) = 0;
  412. // Create JSON web api job, use the helpers in uiwebapiclient.h directly instead, this is there for them to use internally
  413. virtual uint32 InitiateAsyncJSONWebAPIRequest( EHTTPMethod eMethod, CUtlString strURL, IUIPanel *pCallbackTargetPanel, void *pContext, CJSONWebAPIParams *pParams = NULL, HTTPCookieContainerHandle hCookieContainer = INVALID_HTTPCOOKIE_HANDLE ) = 0;
  414. // Create JSON web api job, use the helpers in uiwebapiclient.h directly instead, this is there for them to use internally
  415. virtual uint32 InitiateAsyncJSONWebAPIRequest( EHTTPMethod eMethod, CUtlString strURL, JSONWebAPIDelegate_t callback, void *pContext, CJSONWebAPIParams *pParams = NULL, HTTPCookieContainerHandle hCookieContainer = INVALID_HTTPCOOKIE_HANDLE ) = 0;
  416. // Cancel previously created web api request job
  417. virtual void CancelAsyncJSONWebAPIRequest( uint32 requestID ) = 0;
  418. // Resolves a path that may contain named path portions, etc, to a full local path
  419. virtual CUtlString ResolvePath( const char *pchPath ) = 0;
  420. // Used internally by initialization code to register events with framework
  421. virtual void RegisterEventWithEngine( CPanoramaSymbol symEvent, UIEventFactory factory ) = 0;
  422. // Check if a symbol is a valid event name
  423. virtual bool IsValidEventName( const CPanoramaSymbol symEvent ) = 0;
  424. // Check if a symbol is a valid panel event name
  425. virtual bool IsValidPanelEvent( const CPanoramaSymbol symEvent, int *pParams ) = 0;
  426. // Create input event from symbol, internal framework use
  427. virtual IUIEvent *CreateInputEventFromSymbol( CPanoramaSymbol symEvent, IUIPanel *pPanel, EPanelEventSource_t eSource, int nRepeats ) = 0;
  428. // Create an event from a string representation
  429. virtual IUIEvent *CreateEventFromString( IUIPanel *pCreatingPanel, const char *pchEvent, const char **pchEventEnd ) = 0;
  430. // Used internally by initialization code to register panels with framework
  431. virtual void RegisterPanelFactoryWithEngine( CPanoramaSymbol symPanelType, CPanel2DFactory *pFactory ) = 0;
  432. // Is the panel type registered
  433. virtual bool BRegisteredPanelType( CPanoramaSymbol symPanelType ) = 0;
  434. // Factory func for creating panels
  435. virtual IUIPanelClient *CreatePanel( CPanoramaSymbol symName, const char *pchID, panorama::IUIPanel *parent ) = 0;
  436. // Create debugger window
  437. virtual void CreateDebuggerWindow() = 0;
  438. // Close debugger window
  439. virtual void CloseDebuggerWindow() = 0;
  440. // Register any delegate to run at specified time, be sure to use CancelScheduledDelgate if you delete the object the delgate runs on, etc.
  441. virtual int RegisterScheduledDelegate( double flTargetFrameTime, CUtlDelegate< void() > del ) = 0;
  442. // Cancel a scheduled delegate by index returned from RegisterScheduledDelegate
  443. virtual void CancelScheduledDelegate( int iScheduleIndex ) = 0;
  444. // Return the last frame time for which we already ran scheduled delegates
  445. virtual double GetLastScheduledDelegateRunTime() = 0;
  446. // CPanoramaSymbol support for cross DLL symbols
  447. virtual UtlSymId_t MakeSymbol( const char *pchText ) = 0;
  448. // CPanoramaSymbol support for cross DLL symbols
  449. virtual const char * ResolveSymbol( const UtlSymId_t sym ) = 0;
  450. // Interface to allow animation/render threads to queue a decrement of a ref count on an object next frame in the main thread
  451. virtual void QueueDecrementRefNextFrame( CRefCount *pRefCountObj ) = 0;
  452. // Register a V8 callback function associated with a given UI panel
  453. virtual JSGenericCallbackHandle_t RegisterJSGenericCallback( panorama::IUIPanel *pContextPanel, v8::Handle< v8::Function > callbackFunc ) = 0;
  454. // Invoke a callback previously registered with the system. Returns false if the handle has expired (the context panel is gone, or it was explicitly unregistered)
  455. virtual bool InvokeJSGenericCallback( JSGenericCallbackHandle_t nHandle, int nArgs = 0, v8::Handle< v8::Value > *pArgs = NULL, v8::Handle< v8::Value > *pOutRetVal = NULL ) = 0;
  456. // Explicitly remove the callback from the system (future invokes on the handle will do nothing and return false)
  457. virtual void UnregisterJSGenericCallback( JSGenericCallbackHandle_t nHandle ) = 0;
  458. // Return the number of scopes, such as classes, that JS functions
  459. // have been registered in.
  460. virtual int GetNumRegisterJSScopes() = 0;
  461. // Return information on a JS registration scope.
  462. virtual void GetRegisterJSScopeInfo( int nScope, RegisterJSScopeInfo_t *pInfo ) = 0;
  463. // Return information on a specific entry in a JS registration scope,
  464. // such as a method in a class scope.
  465. virtual void GetRegisterJSEntryInfo( int nScope, int nEntry, RegisterJSEntryInfo_t *pInfo ) = 0;
  466. // Open a new scope for JS registrations.
  467. virtual int StartRegisterJSScope( const char *pName, const char *pDesc = NULL ) = 0;
  468. // Close current JS registration scope.
  469. virtual void EndRegisterJSScope() = 0;
  470. // If there is a current JS registration scope allocate a new entry
  471. // and fill it out. If there is no scope, which is possible as
  472. // recording registration info is only enabled in certain places,
  473. // this will return -1.
  474. virtual int NewRegisterJSEntry( const char *pName, uint32 unFlags, const char *pDesc = NULL, RegisterJSType_t eDataType = k_ERegisterJSTypeUnknown ) = 0;
  475. // If there is a current JS registration entry set the parameter
  476. // type information in it. Silently ignores -1 entry indices
  477. // so this can be called safely when there is no scope.
  478. virtual void SetRegisterJSEntryParams( int nEntry, uint8 unNumParams, RegisterJSType_t *pParamTypes ) = 0;
  479. // Invalidate cached copies of all layout/style/script files (used eg. by the game when search paths change)
  480. // (Does NOT rebuild or reload any existing UI, just causes subsequent references to the files to load from scratch.)
  481. virtual void ClearFileCache() = 0;
  482. // Spew the current list of all cached files and their refcounts (for debugging)
  483. virtual void PrintCacheStatus() = 0;
  484. // get a list of all the windows owned by the engine
  485. virtual void GetWindowsForDebugger( CUtlVector<IUIWindow *> &vecWindows ) = 0;
  486. // Turn on paint count tracking for panels
  487. virtual void SetPaintCountTrackingEnabled( bool bEnablePaintCountTracking ) = 0;
  488. // Is paint count tracking on for panels
  489. virtual bool GetPaintCountTrackingEnabled() = 0;
  490. // Increment paint count tracking for panels
  491. virtual void IncrementPaintCountForPanel( uint64 ulPanelPtrValue, bool bRequiredCompositionLayer, double flFrameTime ) = 0;
  492. // Get panel paint info for the panel
  493. virtual void GetPanelPaintInfo( uint64 ulPanelPtrValue, uint32 &unPaintCount, bool &bRequiredCompositionLayer, double &flFrameTimeLastPaint ) = 0;
  494. // Returns whether any windows exist for the UI engine
  495. virtual bool BHasAnyWindows() = 0;
  496. #ifdef DBGFLAG_VALIDATE
  497. // Memory validation related interfaces
  498. virtual bool PrepareForValidate() = 0;
  499. virtual bool ResumeFromValidate() = 0;
  500. virtual void Validate( CValidator &validator, const tchar *pchName ) = 0;
  501. #endif
  502. #if defined( SOURCE2_PANORAMA )
  503. virtual void TextEntryFocusChange( IUIPanel *pPanel ) = 0;
  504. virtual void TextEntryInvalid( IUIPanel *pPanel ) = 0;
  505. #endif
  506. };
  507. //-----------------------------------------------------------------------------
  508. // Purpose: Helper for render state transitions, returns true if a state
  509. // change is being requested, and it is valid. Helper for fullscreen switching.
  510. //-----------------------------------------------------------------------------
  511. inline bool IUIEngine::BValidRenderStateChange( ERenderTarget eCurrentRenderTarget, ERenderTarget eRequestedRenderTarget )
  512. {
  513. if( eCurrentRenderTarget == eRequestedRenderTarget )
  514. return false;
  515. // if we are in a mode that can switch...
  516. if( eCurrentRenderTarget == IUIEngine::k_ERenderFullScreen || eCurrentRenderTarget == IUIEngine::k_ERenderToWindow )
  517. {
  518. switch( eRequestedRenderTarget ) // test if request is for a state that can be switched to
  519. {
  520. case IUIEngine::k_ERenderFullScreen:
  521. case IUIEngine::k_ERenderToWindow:
  522. return true; // we can change
  523. default:
  524. return false; // not so much
  525. }
  526. }
  527. // render to texture toggled shared vs copied texture
  528. if( BIsRenderingToTexture( eCurrentRenderTarget ) &&
  529. BIsRenderingToTexture( eRequestedRenderTarget ) &&
  530. (eCurrentRenderTarget != eRequestedRenderTarget) )
  531. {
  532. return true;
  533. }
  534. return false;
  535. }
  536. #ifndef PANORAMA_EXPORTS
  537. extern IUIEngine *g_pUIEngineSingleton;
  538. extern CSysModule *g_PanoramaModule;
  539. inline IUIEngine *UIEngine() { return g_pUIEngineSingleton; }
  540. inline IUILocalization *UILocalize() { return UIEngine()->UILocalize(); }
  541. inline IUISoundSystem *UISoundSystem() { return UIEngine()->UISoundSystem(); }
  542. inline IUIInput *UIInputEngine() { return UIEngine() ? UIEngine()->UIInputEngine() : NULL; }
  543. #else
  544. IUIEngine *UIEngine();
  545. IUILocalization *UILocalize();
  546. IUIInput *UIInputEngine();
  547. IUISoundSystem *UISoundSystem();
  548. #endif
  549. #ifdef DBGFLAG_VALIDATE
  550. PANORAMA_INTERFACE void ValidateStaticsInternal( CValidator &validator );
  551. #endif
  552. PANORAMA_INTERFACE IUIEngine *CreatePanoramaUIEngineInternal();
  553. extern void RegisterEventTypesWithEngine( IUIEngine *pEngine );
  554. #ifndef PANORAMA_EXPORTS
  555. extern bool LoadPanoramaModule( const char *pchPanoramaModulePath );
  556. extern void UnloadPanoramaModule();
  557. extern IUIEngine *CreatePanoramaUIEngine();
  558. extern void ConnectPanoramaUIEngine( IUIEngine * );
  559. extern void ShutdownPanoramaUIEngine( IUIEngine * );
  560. #ifdef DBGFLAG_VALIDATE
  561. extern void ValidateStatics( CValidator &validator );
  562. #endif
  563. #endif
  564. // To expose a generic object via UIEngine()->ExposeObjectTypeToJavaScript() you should derive from this interface
  565. // the GetTypeName member should return the same type name you register as exposed
  566. class IUIJSObject
  567. {
  568. public:
  569. ~IUIJSObject()
  570. {
  571. UIEngine()->DeleteJSObjectInstance( this );
  572. }
  573. virtual const char *GetJSTypeName() = 0;
  574. };
  575. } // namespace panorama
  576. #endif // IUIENGINE_H