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.

877 lines
30 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if !defined( __SCALEFFORMUIIMPL_H__ )
  8. #define __SCALEFFORMUIIMPL_H__
  9. #include "scaleformuiintegration.h"
  10. #include "movieslot.h"
  11. #include "sfuiavatarimage.h"
  12. #include "sfuiinventoryimage.h"
  13. #include "sfuichromehtmlimage.h"
  14. #include "tier1/utlmap.h"
  15. #include "igameevents.h"
  16. #include "cdll_int.h"
  17. #if defined( USE_SDL ) || defined( OSX )
  18. #include "appframework/ilaunchermgr.h"
  19. #endif
  20. #if defined( SF_ENABLE_IME ) && defined( SF_ENABLE_IME_WIN32 )
  21. #include "GFx/IME/GFx_IMEManager.h"
  22. #include "GFxIME/GFx_IMEManagerWin32.h"
  23. #endif
  24. #if ( defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION ) ) || defined( _X360 )
  25. #include <d3d9.h>
  26. #endif
  27. class DeviceCallbacks;
  28. class ScaleformUIAvatarImage;
  29. class IShaderAPI;
  30. #define MAX_VALUES_IN_ARRAY 20
  31. #define NUM_VALUEARRAY_SLOTS ( MAX_VALUES_IN_ARRAY-1 )
  32. #define MAX_BOUND_COMMAND_LENGTH 64
  33. #define TEMPORARY_BUFFER_SIZE 4086
  34. #define MAX_AXIS_PER_JOYSTICK 2
  35. #define MAX_JOYSTICKS_PER_SLOT 2
  36. #define MAX_SLOTS_WITH_JOYSTICKS 2
  37. #define JOY_VALUE_INDEX( slot, stick, axis ) ( ( slot * MAX_JOYSTICKS_PER_SLOT + stick ) * MAX_AXIS_PER_JOYSTICK + axis )
  38. // [HPE] Removing the extra splitscreen slot - we no longer support local multiplayer on CS:GO
  39. #define MAX_SLOTS ( SF_SS_SLOT( 0 ) + 1 )
  40. #if defined( _WIN32 )
  41. #define ALLOCA _alloca
  42. #elif defined( _PS3 )
  43. #define ALLOCA alloca
  44. #endif
  45. #if defined( _PS3 )
  46. struct IDirect3DDevice9;
  47. struct D3DPRESENT_PARAMETERS;
  48. #endif
  49. enum CURSOR_IMAGE_TYPE
  50. {
  51. CURSOR_IMAGE_NONE,
  52. CURSOR_IMAGE_MOVE_CROSSHAIR,
  53. CURSOR_IMAGE_MOUSE,
  54. };
  55. inline SFPARAMS ToSFPARAMS( SF::GFx::FunctionHandler::Params* ptr )
  56. {
  57. return reinterpret_cast<SFPARAMS>( ptr );
  58. }
  59. inline SF::GFx::FunctionHandler::Params* FromSFPARAMS( SFPARAMS ptr )
  60. {
  61. return reinterpret_cast< SF::GFx::FunctionHandler::Params* >( ptr );
  62. }
  63. inline SFVALUE ToSFVALUE( SF::GFx::Value* ptr )
  64. {
  65. return reinterpret_cast<SFVALUE>( ptr );
  66. }
  67. inline SF::GFx::Value* FromSFVALUE( SFVALUE ptr )
  68. {
  69. return reinterpret_cast<SF::GFx::Value*>( ptr );
  70. }
  71. inline SFMOVIE ToSFMOVIE( Scaleform::GFx::Movie *ptr )
  72. {
  73. return reinterpret_cast< SFMOVIE >( ptr );
  74. }
  75. inline SF::GFx::Movie* FromSFMOVIE( SFMOVIE ptr )
  76. {
  77. return reinterpret_cast< SF::GFx::Movie* >( ptr );
  78. }
  79. inline SFMOVIEDEF ToSFMOVIEDEF( Scaleform::GFx::MovieDef *ptr )
  80. {
  81. return reinterpret_cast< SFMOVIEDEF >( ptr );
  82. }
  83. inline SF::GFx::MovieDef* FromSFMOVIEDEF( SFMOVIEDEF ptr )
  84. {
  85. return reinterpret_cast< SF::GFx::MovieDef* >( ptr );
  86. }
  87. class CScaleFormThreadCommandQueue: public SF::Render::ThreadCommandQueue
  88. {
  89. public:
  90. virtual void GetRenderInterfaces( SF::Render::Interfaces* p )
  91. {
  92. p->pHAL = pHAL;
  93. p->pRenderer2D = pR2D;
  94. p->pTextureManager = pHAL->GetTextureManager();
  95. p->RenderThreadID = 0;
  96. }
  97. virtual void PushThreadCommand( SF::Render::ThreadCommand* command )
  98. {
  99. if (command) {
  100. MaterialLock_t hMaterialLock = materials->Lock();
  101. command->Execute();
  102. materials->Unlock( hMaterialLock );
  103. }
  104. }
  105. SF::Render::HAL* pHAL;
  106. SF::Render::Renderer2D* pR2D;
  107. };
  108. #if defined( SF_ENABLE_IME ) && defined( SF_ENABLE_IME_WIN32 )
  109. class ScaleformeUIIMEManager : public SF::GFx::IME::GFxIMEManagerWin32
  110. {
  111. public:
  112. ScaleformeUIIMEManager( HWND hwnd, IGameEventManager2* pGameEventManager )
  113. : SF::GFx::IME::GFxIMEManagerWin32( hwnd ), m_pGameEventManager( pGameEventManager ) {}
  114. virtual void FinalizeComposition( const wchar_t* pstr, SF::UPInt len = SF_MAX_UPINT )
  115. {
  116. IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
  117. if ( pEvent )
  118. {
  119. pEvent->SetString( "eventtype", "addchars" );
  120. pEvent->SetWString( "eventdata", pstr );
  121. m_pGameEventManager->FireEventClientSide( pEvent );
  122. }
  123. }
  124. virtual void SetCompositionText( const wchar_t* pstr, SF::UPInt len = SF_MAX_UPINT )
  125. {
  126. IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
  127. if ( pEvent )
  128. {
  129. pEvent->SetString( "eventtype", "setcomposition" );
  130. pEvent->SetWString( "eventdata", pstr );
  131. m_pGameEventManager->FireEventClientSide( pEvent );
  132. }
  133. }
  134. virtual void HighlightText( SF::UPInt pos, SF::UPInt len, TextHighlightStyle style, bool clause )
  135. {}
  136. virtual void ClearComposition()
  137. {
  138. IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
  139. if ( pEvent )
  140. {
  141. pEvent->SetString( "eventtype", "cancelcomposition" );
  142. pEvent->SetWString( "eventdata", L"" );
  143. m_pGameEventManager->FireEventClientSide( pEvent );
  144. }
  145. }
  146. private:
  147. IGameEventManager2* m_pGameEventManager;
  148. };
  149. #endif
  150. class ScaleformUIImpl: public CTier3AppSystem<IScaleformUI>
  151. {
  152. typedef CTier3AppSystem<IScaleformUI> BaseClass;
  153. /**********************
  154. * These are the basic singleton support functions
  155. * the are in ScaleformUIInitImpl.cpp
  156. */
  157. /* singleton support */
  158. public:
  159. static ScaleformUIImpl m_Instance;
  160. /* normal class */
  161. protected:
  162. SF::GFx::System* m_pSystem;
  163. SF::GFx::Loader* m_pLoader;
  164. #if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
  165. SF::Ptr<SF::Render::D3D9::HAL> m_pRenderHAL;
  166. #else
  167. SF::Ptr<SF::Render::GL::HAL> m_pRenderHAL;
  168. #endif
  169. SF::Ptr<SF::Render::Renderer2D> m_pRenderer2D;
  170. CScaleFormThreadCommandQueue *m_pThreadCommandQueue;
  171. IDirect3DDevice9* m_pDevice;
  172. #if defined( _WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
  173. IDirect3DStateBlock9* m_pD3D9Stateblock;
  174. DWORD m_srgbRenderState;
  175. DWORD m_pSavedSrgbSamplerStates[16];
  176. #endif
  177. #if defined( _WIN32 )
  178. SF::Ptr<ScaleformeUIIMEManager> m_pIMEManager;
  179. #endif
  180. SF::Ptr<ScaleformTranslatorAdapter> m_pTranslatorAdapter;
  181. SF::Ptr<ScaleformFunctionHandlerAdapter> m_pFunctionAdapter;
  182. SF::SysAlloc* m_pAllocator;
  183. #if defined( USE_SDL ) || defined( OSX )
  184. ILauncherMgr *m_pLauncherMgr;
  185. #endif
  186. IShaderDeviceMgr* m_pShaderDeviceMgr;
  187. DeviceCallbacks* m_pDeviceCallbacks;
  188. IShaderAPI* m_pShaderAPI;
  189. IGameUIFuncs* m_pGameUIFuncs;
  190. IVEngineClient* m_pEngine;
  191. IGameEventManager2* m_pGameEventManager;
  192. wchar_t m_wcControllerButtonToBindingTable[BUTTON_CODE_COUNT][MAX_BOUND_COMMAND_LENGTH];
  193. BaseSlot* m_SlotPtrs[MAX_SLOTS];
  194. // gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
  195. // CThreadMutex m_SlotMutexes[MAX_SLOTS];
  196. int m_SlotDeniesInputRefCount[MAX_SLOTS];
  197. CUtlVector<SF::GFx::Movie*> m_MovieViews;
  198. CUtlVector<const wchar_t*> m_LocalizableCommandNames;
  199. CUtlVector<const char*> m_LocalizableCommandKeys;
  200. CUtlVector<const char*> m_MovieDefNameCache;
  201. CUtlVector<SF::GFx::MovieDef*> m_MovieDefCache;
  202. CUtlVector<SF::GFx::Value*> m_ValueCache;
  203. CUtlVector<SF::GFx::Value*> m_ValueArrayCaches[NUM_VALUEARRAY_SLOTS];
  204. #ifdef _DEBUG
  205. CUtlVector<SF::GFx::Value*> m_ValuesInUse;
  206. CUtlVector<SF::GFx::Value*> m_ValueArraysInUse[NUM_VALUEARRAY_SLOTS];
  207. #endif
  208. float m_fJoyValues[MAX_AXIS_PER_JOYSTICK * MAX_JOYSTICKS_PER_SLOT * MAX_SLOTS_WITH_JOYSTICKS];
  209. int m_iJoyAxisButtonsDown[MAX_SLOTS_WITH_JOYSTICKS];
  210. int m_iScreenWidth;
  211. int m_iScreenHeight;
  212. int m_iLastMouseX;
  213. int m_iLastMouseY;
  214. float m_fCursorTimeUntilHide;
  215. char m_cTemporaryBuffer[TEMPORARY_BUFFER_SIZE];
  216. bool m_bTrySWFFirst;
  217. bool m_bPumpScaleformStats;
  218. bool m_bForcePS3;
  219. bool m_bDenyAllInputToGame;
  220. bool m_bShowActionNameIfUnbound;
  221. bool m_bEatPS3MouseEvent;
  222. int m_iWantCursorShown;
  223. bool m_bIMEEnabled;
  224. int m_iIMEFocusSlot;
  225. CUtlMap< XUID, ScaleformUIAvatarImage * > m_mapUserXuidToAvatar;
  226. IVTFTexture* m_pDefaultAvatarTexture;
  227. ScaleformUIAvatarImage* m_pDefaultAvatarImage;
  228. #if !defined( NO_STEAM )
  229. bool m_bSteamCallbacksConfigured;
  230. void EnsureSteamCallbacksConfigured();
  231. STEAM_CALLBACK_MANUAL( ScaleformUIImpl, Steam_OnPersonaStateChanged, PersonaStateChange_t, m_CallbackPersonaStateChanged );
  232. STEAM_CALLBACK_MANUAL( ScaleformUIImpl, Steam_OnAvatarImageLoaded, AvatarImageLoaded_t, m_CallbackAvatarImageLoaded );
  233. #endif // NO_STEAM
  234. CUtlMap< uint64, ScaleformUIInventoryImage * > m_mapItemIdToImage;
  235. IVTFTexture* m_pDefaultInventoryTexture;
  236. ScaleformUIInventoryImage* m_pDefaultInventoryImage;
  237. struct DefaultInventoryIcon_t
  238. {
  239. IVTFTexture* m_pTexture;
  240. ScaleformUIInventoryImage* m_pImage;
  241. };
  242. #ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
  243. CUtlHashFast< DefaultInventoryIcon_t > m_defaultInventoryIcons;
  244. #endif
  245. CUtlMap< uint64, ScaleformUIChromeHTMLImage* > m_mapImageIdToChromeImage;
  246. ScaleformUIChromeHTMLImage* m_pDefaultChromeHTMLImage;
  247. int m_iKeyboardSlot;
  248. CURSOR_IMAGE_TYPE m_loadedCursorImage;
  249. bool m_isCursorForced;
  250. // Time updated in RunFrame and used in AdvanceSlot
  251. float m_fTime;
  252. #if defined( _PS3 )
  253. InputDevice_t m_preForcedInputType;
  254. #endif
  255. // Set to true if advance and render are running on the same thread
  256. bool m_bSingleThreaded;
  257. // ScaleformUI::ClearCache will queue the call to clear the scaleform mesh cache
  258. // to ensure the mesh cache being cleared on the render thread
  259. bool m_bClearMeshCacheQueued;
  260. protected:
  261. ScaleformUIImpl( void );
  262. void ClearMembers( void );
  263. void InitMovieImpl( void );
  264. void ShutdownMovieImpl( void );
  265. void InitRendererImpl( void );
  266. void ShutdownRendererImpl( void );
  267. void InitValueImpl( void );
  268. void ShutdownValueImpl( void );
  269. void InitHighLevelImpl( void );
  270. void ShutdownHighLevelImpl( void );
  271. void InitMovieSlotImpl( void );
  272. void ShutdownMovieSlotImpl( void );
  273. void InitCursorImpl( void );
  274. void ShutdownCursorImpl( void );
  275. void InitTranslationImpl( void );
  276. void ShutdownTranslationImpl( void );
  277. void InitFonts( void );
  278. bool DistributeEvent( SF::GFx::Event& event, int slotNumber, bool toAllSlots, bool clearControllerUI = true );
  279. bool DistributeKeyEvent( bool keyDown, bool fromController, const char* binding, ButtonCode_t code, ButtonCode_t vkey, int slotNumber, bool toAllSlots );
  280. bool DistributeCharTyped( wchar_t code );
  281. bool TallyAxisButtonEvent( int slot, int code, bool down );
  282. bool HitTest( int x, int y );
  283. BaseSlot* LockSlotPtr( int slot );
  284. void UnlockSlotPtr( int slot );
  285. bool AnalogStickNavigationDisabled( int slot );
  286. void UpdateUIAvatarImages( void );
  287. void SetJoyValue( int slot, int stick, int axis, int value );
  288. #if defined( _PS3 )
  289. void InitCursorPS3( bool usingMoveCrosshair );
  290. #endif
  291. public:
  292. // the following are for the system callbacks from flash
  293. void AddAPIFunctionToObject( SFVALUE pAPI, SFMOVIE pMovie, ScaleformUIFunctionHandlerObject* object, const ScaleformUIFunctionHandlerDefinition* pFunctionDef );
  294. int GetScreenWidth( void )
  295. {
  296. return m_iScreenWidth;
  297. }
  298. int GetScreenHeight( void )
  299. {
  300. return m_iScreenHeight;
  301. }
  302. bool OwnsAtLeastOneMutex( void );
  303. void DebugBreakIfNotLocked( void );
  304. bool GetVerbose( void );
  305. void SetVerbose( bool bVerbose );
  306. // IAppSystem implementation
  307. public:
  308. virtual bool Connect( CreateInterfaceFn factory );
  309. virtual void Disconnect( void );
  310. // Here's where systems can access other interfaces implemented by this m_pObject
  311. // Returns NULL if it doesn't implement the requested interface
  312. virtual void *QueryInterface( const char *pInterfaceName );
  313. // Init, shutdown
  314. virtual InitReturnVal_t Init( void );
  315. virtual void Shutdown( void );
  316. // Returns all dependent libraries
  317. virtual const AppSystemInfo_t* GetDependencies( void );
  318. // Returns the tier
  319. virtual AppSystemTier_t GetTier( void )
  320. {
  321. return APP_SYSTEM_TIER3;
  322. }
  323. // Reconnect to a particular interface
  324. virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName )
  325. {
  326. BaseClass::Reconnect( factory, pInterfaceName );
  327. }
  328. void LogPrintf( const char *format, ... );
  329. IVEngineClient* GetEnginePtr()
  330. {
  331. return m_pEngine;
  332. }
  333. // IScaleformUI implementation
  334. /**************************
  335. * common, high-level functions and are implemented in ScaleformUIHighLevelImpl.cpp
  336. */
  337. bool GetForcePS3( void ) { return m_bForcePS3; }
  338. #if defined( _PS3 )
  339. void PS3UseMoveCursor( void );
  340. void PS3UseStandardCursor( void );
  341. void PS3ForceCursorStart( void );
  342. void PS3ForceCursorEnd( void );
  343. #endif
  344. public:
  345. // called when the safezone convar is changed
  346. // tells all the slots to change their safe zone
  347. void UpdateSafeZone( void );
  348. // called when the UI tint convar is changed - applies the new tint to all slots
  349. void UpdateTint( void );
  350. // virtual void Render();
  351. virtual void SetSingleThreadedMode( bool bSingleThreded );
  352. virtual void RunFrame( float time );
  353. void AdvanceSlot( int slot );
  354. virtual bool HandleInputEvent( const InputEvent_t &event );
  355. virtual bool HandleIMEEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam );
  356. virtual bool PreProcessKeyboardEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam );
  357. virtual void SetIMEEnabled( bool bEnabled );
  358. virtual void SetIMEFocus( int slot );
  359. virtual void ShutdownIME();
  360. virtual float GetJoyValue( int slot, int stickIndex, int axis );
  361. void SetScreenSize( int x, int y );
  362. const char* CorrectFlashFileName( const char * name );
  363. ScaleformUIAvatarImage* GetAvatarImage( XUID playerID );
  364. void UpdateAvatarImages( void );
  365. virtual bool AvatarImageAddRef( XUID playerID );
  366. virtual void AvatarImageRelease( XUID playerID );
  367. virtual void AvatarImageReload( XUID playerID, IScaleformAvatarImageProvider *pProvider );
  368. virtual void AddDeviceDependentObject( IShaderDeviceDependentObject * pObject );
  369. virtual void RemoveDeviceDependentObject( IShaderDeviceDependentObject * pObject );
  370. ScaleformUIInventoryImage* GetInventoryImage( uint64 iItemId );
  371. virtual bool InventoryImageAddRef( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider );
  372. virtual void InventoryImageUpdate( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider );
  373. virtual void InventoryImageRelease( uint64 iItemId );
  374. #ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
  375. virtual void InitInventoryDefaultIcons( CUtlVector< const char * > *vecIconDefaultNames );
  376. #endif
  377. ScaleformUIChromeHTMLImage* GetChromeHTMLImage( uint64 imageID );
  378. virtual bool ChromeHTMLImageAddRef( uint64 imageID );
  379. virtual void ChromeHTMLImageUpdate( uint64 imageID, const byte* rgba, int width, int height, ::ImageFormat format );
  380. virtual void ChromeHTMLImageRelease( uint64 imageID );
  381. virtual void ForceUpdateImages();
  382. SF::Render::Image* CreateImageFromFile( const char *pszFileName, const SF::GFx::ImageCreateInfo& info, int width, int height );
  383. /**********************************
  384. * slot stuff. This is all in ScaleformUIImplMovieSlot.cpp
  385. */
  386. virtual void SetSlotViewport( int slot, int x, int y, int width, int height );
  387. virtual void RenderSlot( int slot );
  388. virtual void ForkRenderSlot( int slot );
  389. virtual void JoinRenderSlot( int slot );
  390. virtual void InitSlot( int slotID, const char* rootMovie, IScaleformSlotInitController *pController );
  391. virtual void SlotAddRef( int slot );
  392. virtual void SlotRelease( int slotID );
  393. virtual void LockSlot( int slot );
  394. virtual void UnlockSlot( int slot );
  395. virtual void RequestElement( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject );
  396. virtual void RemoveElement( int slot, SFVALUE element );
  397. virtual void InstallGlobalObject( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SFVALUE *pInstalledGlobalObjectResult );
  398. virtual void RemoveGlobalObject( int slot, SFVALUE element );
  399. virtual bool SlotConsumesInputEvents( int slot );
  400. virtual bool ConsumesInputEvents( void );
  401. virtual bool SlotDeniesInputToGame( int slot );
  402. virtual void DenyInputToGame( bool value );
  403. virtual void DenyInputToGameFromFlash( int slot, bool value );
  404. virtual void SendUIEvent( const char* action, const char* eventData, int slot = 0 );
  405. virtual void LockInputToSlot( int slot );
  406. virtual void UnlockInput( void );
  407. virtual void ForceCollectGarbage( int slot );
  408. virtual void ClearCache( void );
  409. virtual void LockMostRecentInputDevice( int slot );
  410. /************************************
  411. * Cursor stuff. in ScaleformUIImplCursor.cpp
  412. */
  413. protected:
  414. void UpdateCursorLazyHide( float time );
  415. void UpdateCursorWaitTime( float newTime );
  416. void InnerShowCursor( void );
  417. void InnerHideCursor( void );
  418. void CursorMoved( void );
  419. void ControllerMoved( void );
  420. bool IsSetToControllerUI( int slot );
  421. void SetToControllerUI( int slot, bool value );
  422. public:
  423. void MaybeShowCursor( void );
  424. bool IsSlotKeyboardAccessible( int slot );
  425. virtual void InitCursor( const char* cursorMovie );
  426. virtual void ReleaseCursor( void );
  427. virtual bool IsCursorVisible( void );
  428. virtual void RenderCursor( void );
  429. virtual void AdvanceCursor( void );
  430. virtual void SetCursorViewport( int x, int y, int width, int height );
  431. virtual void ShowCursor( void );
  432. virtual void HideCursor( void );
  433. virtual void SetCursorShape( int shapeIndex );
  434. /*******
  435. * Renderer stuff
  436. * These are in ScaleformUIRendererImpl.cpp
  437. */
  438. void FinishInitializingRenderer( void );
  439. void SetRenderingDevice( IDirect3DDevice9 *pDevice, D3DPRESENT_PARAMETERS *pPresentParameters, HWND hWnd );
  440. void NotifyRenderingDeviceLost();
  441. void SaveRenderingState( void );
  442. void RestoreRenderingState( void );
  443. void SetRenderTargets( void );
  444. void DumpMeshCacheStats( void );
  445. /*********
  446. * Movie Def related stuff
  447. * These are in ScaleformMovieImpl.cpp
  448. */
  449. virtual SFMOVIEDEF CreateMovieDef( const char* pfilename, unsigned int loadConstants = 0, size_t memoryArena = 0 );
  450. virtual void ReleaseMovieDef( SFMOVIEDEF movieDef );
  451. virtual SFMOVIE MovieDef_CreateInstance( SFMOVIEDEF movieDef, bool initFirstFrame = true, size_t memoryArena = 0 );
  452. virtual void ReleaseMovieView( SFMOVIE movieView );
  453. virtual void MovieView_Advance( SFMOVIE movieView, float time, unsigned int frameCatchUpCount = 2 );
  454. virtual void MovieView_SetBackgroundAlpha( SFMOVIE movieView, float alpha );
  455. virtual void MovieView_SetViewport( SFMOVIE movieView, int bufw, int bufh, int left, int top, int w, int h, unsigned int flags = 0 );
  456. virtual void MovieView_Display( SFMOVIE movieView );
  457. virtual void MovieView_SetViewScaleMode( SFMOVIE movieView, IScaleformUI::_ScaleModeType type );
  458. virtual IScaleformUI::_ScaleModeType MovieView_GetViewScaleMode( SFMOVIE movieView );
  459. virtual void MovieView_SetViewAlignment( SFMOVIE movieView, IScaleformUI::_AlignType type );
  460. virtual IScaleformUI::_AlignType MovieView_GetViewAlignment( SFMOVIE movieView );
  461. virtual SFVALUE MovieView_CreateObject( SFMOVIE movieView, const char* className = NULL, SFVALUEARRAY args = SFVALUEARRAY(0, NULL), int numArgs = 0 );
  462. virtual SFVALUE MovieView_GetVariable( SFMOVIE movieView, const char* variablePath );
  463. virtual SFVALUE MovieView_CreateString( SFMOVIE movieView, const char *str );
  464. virtual SFVALUE MovieView_CreateStringW( SFMOVIE movieView, const wchar_t *str );
  465. virtual SFVALUE MovieView_CreateArray( SFMOVIE movieView, int size = -1 );
  466. virtual bool MovieView_HitTest( SFMOVIE movieView, float x, float y, IScaleformUI::_HitTestType testCond = IScaleformUI::HitTest_Shapes, unsigned int controllerIdx = 0 );
  467. /*************************
  468. * keycode stuff.
  469. * these are in ScaleformUIKeymapImpl.cpp
  470. */
  471. void DecodeButtonandSlotFromButtonCode( ButtonCode_t inCode, ButtonCode_t &outcode, int &outSlot );
  472. /***************************
  473. * translation and button glyph functionality.
  474. * These are in ScaleformUITranslationImpl.cpp
  475. */
  476. protected:
  477. void RemoveKeyBindings( void );
  478. const wchar_t* LocalizeCommand( const wchar_t* command );
  479. ButtonCode_t LookupButtonFromBinding( const wchar_t* binding, bool bForceControllerLookup = false );
  480. void BindCommandToControllerButton( ButtonCode_t code, const char* binding );
  481. IScaleformUI::ControllerButton::Enum ValveButtonToControllerButton( ButtonCode_t b );
  482. public:
  483. virtual void RefreshKeyBindings( void );
  484. virtual void ShowActionNameWhenActionIsNotBound( bool value );
  485. virtual void UpdateBindingForButton( ButtonCode_t bt, const char* pbinding );
  486. virtual const wchar_t* Translate( const char *key, bool* pIsHTML );
  487. virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const wchar_t* pin, int fontSize, bool bForceControllerGlyph = false );
  488. virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const char* text, int fontSize, bool bForceControllerGlyph = false );
  489. virtual void MakeStringSafe( const wchar_t* stringin, wchar_t* stringout, int outlength );
  490. /*************************
  491. * value stuff
  492. * these are in ScaleformUIValueImpl.cpp
  493. */
  494. protected:
  495. SFVALUE CreateGFxValue( SFVALUE pValue = NULL );
  496. void ReleaseGFxValue( SFVALUE pValue );
  497. public:
  498. virtual SFVALUE CreateValue( SFVALUE value );
  499. virtual SFVALUE CreateValue( const char* value );
  500. virtual SFVALUE CreateValue( const wchar_t* value );
  501. virtual SFVALUE CreateValue( int value );
  502. virtual SFVALUE CreateValue( float value );
  503. virtual SFVALUE CreateValue( bool value );
  504. virtual SFVALUE CreateNewObject( int slot );
  505. virtual SFVALUE CreateNewString( int slot, const char* value );
  506. virtual SFVALUE CreateNewString( int slot, const wchar_t* value );
  507. virtual SFVALUE CreateNewArray( int slot, int size = -1 );
  508. virtual void Value_SetValue( SFVALUE obj, SFVALUE value );
  509. virtual void Value_SetValue( SFVALUE obj, int value );
  510. virtual void Value_SetValue( SFVALUE obj, float value );
  511. virtual void Value_SetValue( SFVALUE obj, bool value );
  512. virtual void Value_SetValue( SFVALUE obj, const char* value );
  513. virtual void Value_SetValue( SFVALUE obj, const wchar_t* value );
  514. virtual void Value_SetColor( SFVALUE obj, int color );
  515. virtual void Value_SetColor( SFVALUE obj, float r, float g, float b, float a );
  516. virtual void Value_SetTint( SFVALUE obj, int color );
  517. virtual void Value_SetTint( SFVALUE obj, float r, float g, float b, float a );
  518. virtual void Value_SetColorTransform( SFVALUE obj, int colorMultiply, int colorAdd );
  519. virtual void Value_SetColorTransform( SFVALUE obj, float r, float g, float b, float a, int colorAdd );
  520. virtual void Value_SetText( SFVALUE obj, const char* value );
  521. virtual void Value_SetText( SFVALUE obj, const wchar_t* value );
  522. virtual void Value_SetTextHTML( SFVALUE obj, const char* value );
  523. virtual void Value_SetTextHTML( SFVALUE obj, const wchar_t* value );
  524. virtual int Value_SetFormattedText( SFVALUE obj, const char* pFormat, ... );
  525. virtual void Value_SetArraySize( SFVALUE obj, int size );
  526. virtual int Value_GetArraySize( SFVALUE obj );
  527. virtual void Value_ClearArrayElements( SFVALUE obj );
  528. virtual void Value_RemoveArrayElement( SFVALUE obj, int index );
  529. virtual void Value_RemoveArrayElements( SFVALUE obj, int index, int count );
  530. virtual SFVALUE Value_GetArrayElement( SFVALUE obj, int index );
  531. virtual void Value_SetArrayElement( SFVALUE obj, int index, SFVALUE value );
  532. virtual void Value_SetArrayElement( SFVALUE obj, int index, int value );
  533. virtual void Value_SetArrayElement( SFVALUE obj, int index, float value );
  534. virtual void Value_SetArrayElement( SFVALUE obj, int index, bool value );
  535. virtual void Value_SetArrayElement( SFVALUE obj, int index, const char* value );
  536. virtual void Value_SetArrayElement( SFVALUE obj, int index, const wchar_t* value );
  537. void SetVisible( SFVALUE pgfx, bool visible );
  538. virtual void Value_SetVisible( SFVALUE obj, bool visible );
  539. virtual void Value_GetDisplayInfo( SFVALUE obj, ScaleformDisplayInfo* dinfo );
  540. virtual void Value_SetDisplayInfo( SFVALUE obj, const ScaleformDisplayInfo* dinfo );
  541. virtual void ReleaseValue( SFVALUE value );
  542. virtual void CreateValueArray( SFVALUEARRAY& valueArray, int length );
  543. virtual SFVALUEARRAY CreateValueArray( int length );
  544. virtual void ReleaseValueArray( SFVALUEARRAY& valueArray );
  545. virtual void ReleaseValueArray( SFVALUEARRAY& valueArray, int count ); // DEPRECATED
  546. virtual SFVALUE ValueArray_GetElement( SFVALUEARRAY, int index );
  547. virtual IScaleformUI::_ValueType ValueArray_GetType( SFVALUEARRAY array, int index );
  548. virtual double ValueArray_GetNumber( SFVALUEARRAY array, int index );
  549. virtual bool ValueArray_GetBool( SFVALUEARRAY array, int index );
  550. virtual const char* ValueArray_GetString( SFVALUEARRAY array, int index );
  551. virtual const wchar_t* ValueArray_GetStringW( SFVALUEARRAY array, int index );
  552. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, SFVALUE value );
  553. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, int value );
  554. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, float value );
  555. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, bool value );
  556. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const char* value );
  557. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const wchar_t* value );
  558. virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const char* value );
  559. virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const wchar_t* value );
  560. virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const char* value );
  561. virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const wchar_t* value );
  562. virtual bool Value_HasMember( SFVALUE value, const char* name );
  563. virtual SFVALUE Value_GetMember( SFVALUE value, const char* name );
  564. virtual bool Value_SetMember( SFVALUE obj, const char *name, SFVALUE value );
  565. virtual bool Value_SetMember( SFVALUE obj, const char *name, int value );
  566. virtual bool Value_SetMember( SFVALUE obj, const char *name, float value );
  567. virtual bool Value_SetMember( SFVALUE obj, const char *name, bool value );
  568. virtual bool Value_SetMember( SFVALUE obj, const char *name, const char* value );
  569. virtual bool Value_SetMember( SFVALUE obj, const char *name, const wchar_t* value );
  570. virtual ISFTextObject* TextObject_MakeTextObject( SFVALUE value );
  571. virtual ISFTextObject* TextObject_MakeTextObjectFromMember( SFVALUE value, const char* pName );
  572. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args );
  573. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args );
  574. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs );
  575. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs );
  576. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ); // DEPRECATED
  577. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ); // DEPRECATED
  578. virtual IScaleformUI::_ValueType Value_GetType( SFVALUE obj );
  579. virtual double Value_GetNumber( SFVALUE obj );
  580. virtual bool Value_GetBool( SFVALUE obj );
  581. virtual const char* Value_GetString( SFVALUE obj );
  582. virtual const wchar_t* Value_GetStringW( SFVALUE obj );
  583. virtual SFVALUE Value_GetText( SFVALUE obj );
  584. virtual SFVALUE Value_GetTextHTML( SFVALUE obj );
  585. /************************************
  586. * m_Callback parameter stuff
  587. * These are in ScaleformUIParamsImpl.cpp
  588. */
  589. virtual SFVALUEARRAY Params_GetArgs( SFPARAMS params );
  590. virtual unsigned int Params_GetNumArgs( SFPARAMS params );
  591. virtual bool Params_ArgIs( SFPARAMS params, unsigned int index, IScaleformUI::_ValueType v );
  592. virtual SFVALUE Params_GetArg( SFPARAMS params, int index = 0 );
  593. virtual IScaleformUI::_ValueType Params_GetArgType( SFPARAMS params, int index = 0 );
  594. virtual double Params_GetArgAsNumber( SFPARAMS params, int index = 0 );
  595. virtual bool Params_GetArgAsBool( SFPARAMS params, int index = 0 );
  596. virtual const char* Params_GetArgAsString( SFPARAMS params, int index = 0 );
  597. virtual const wchar_t* Params_GetArgAsStringW( SFPARAMS params, int index = 0 );
  598. virtual void Params_DebugSpew( SFPARAMS params );
  599. virtual void Params_SetResult( SFPARAMS params, SFVALUE value );
  600. virtual void Params_SetResult( SFPARAMS params, int value );
  601. virtual void Params_SetResult( SFPARAMS params, float value );
  602. virtual void Params_SetResult( SFPARAMS params, bool value );
  603. virtual void Params_SetResult( SFPARAMS params, const char* value, bool bMakeNewValue = true );
  604. virtual void Params_SetResult( SFPARAMS params, const wchar_t* value, bool bMakeNewValue = true );
  605. virtual SFVALUE Params_CreateNewObject( SFPARAMS params );
  606. virtual SFVALUE Params_CreateNewString( SFPARAMS params, const char* value );
  607. virtual SFVALUE Params_CreateNewString( SFPARAMS params, const wchar_t* value );
  608. virtual SFVALUE Params_CreateNewArray( SFPARAMS params, int size = -1 );
  609. ButtonCode_t GetCurrentKey() { return m_CurrentKey; }
  610. protected:
  611. ButtonCode_t m_CurrentKey;
  612. protected:
  613. /************************************
  614. * helper functions to map to and from SFUI and SDK enums
  615. */
  616. SF::GFx::Movie::ScaleModeType ScaleModeType_SFUI_to_SDK( IScaleformUI::_ScaleModeType scaleModeType );
  617. IScaleformUI::_ScaleModeType ScaleModeType_SDK_to_SFUI( SF::GFx::Movie::ScaleModeType scaleModeType );
  618. SF::GFx::Value::ValueType ValueType_SFUI_to_SDK( IScaleformUI::_ValueType valueType );
  619. IScaleformUI::_ValueType ValueType_SDK_to_SFUI( SF::GFx::Value::ValueType ValueType );
  620. SF::GFx::Movie::AlignType AlignType_SFUI_to_SDK( IScaleformUI::_AlignType alignType );
  621. IScaleformUI::_AlignType AlignType_SDK_to_SFUI( SF::GFx::Movie::AlignType alignType );
  622. SF::GFx::Movie::HitTestType HitTestType_SFUI_to_SDK( IScaleformUI::_HitTestType hitTestType );
  623. IScaleformUI::_HitTestType HitTestType_SDK_to_SFUI( SF::GFx::Movie::HitTestType hitTestType );
  624. };
  625. #define SFINST ( ScaleformUIImpl::m_Instance )
  626. class DeviceCallbacks: public IShaderDeviceDependentObject
  627. {
  628. public:
  629. int m_iRefCount;
  630. ScaleformUIImpl* m_pScaleform;
  631. DeviceCallbacks( void ) :
  632. m_iRefCount( 1 ), m_pScaleform( NULL )
  633. {
  634. }
  635. virtual void DeviceLost( void )
  636. {
  637. m_pScaleform->NotifyRenderingDeviceLost();
  638. }
  639. virtual void DeviceReset( void *pDevice, void *pPresentParameters, void *pHWnd )
  640. {
  641. m_pScaleform->SetRenderingDevice( ( IDirect3DDevice9* )pDevice, ( D3DPRESENT_PARAMETERS* )pPresentParameters, ( HWND )pHWnd );
  642. }
  643. virtual void ScreenSizeChanged( int width, int height )
  644. {
  645. m_pScaleform->SetScreenSize( width, height );
  646. }
  647. };
  648. class ScaleformCallbackHolder: public SF::GFx::ASUserData
  649. {
  650. public:
  651. ScaleformUIFunctionHandlerObject* m_pObject;
  652. ScaleformUIFunctionHandler m_Callback;
  653. inline ScaleformCallbackHolder( ScaleformUIFunctionHandlerObject* object, ScaleformUIFunctionHandler callback ) :
  654. SF::GFx::ASUserData(), m_pObject( object ), m_Callback( callback )
  655. {
  656. }
  657. inline void Execute( SF::GFx::FunctionHandler::Params *params )
  658. {
  659. ( m_pObject->*m_Callback )( &SFINST, ToSFPARAMS( params ) );
  660. }
  661. virtual void OnDestroy( SF::GFx::Movie* pmovie, void* pobject );
  662. };
  663. #endif