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.

1476 lines
43 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if !defined( __SCALEFORMUI_H__ )
  8. #define __SCALEFORMUI_H__
  9. // this is needed so that pointers to members match with those in CStrike15
  10. #pragma pointers_to_members( full_generality, virtual_inheritance )
  11. #include "appframework/iappsystem.h"
  12. #include "inputsystem/InputEnums.h"
  13. #include "inputsystem/ButtonCode.h"
  14. #include "refcount.h"
  15. #include "shaderapi/IShaderDevice.h"
  16. #ifdef CLIENT_DLL
  17. #include "cs_workshop_manager.h"
  18. #endif
  19. #if ( defined( _OSX ) || defined ( _LINUX ) ) && ( defined( _DEBUG ) || defined( USE_MEM_DEBUG ) )
  20. #include <typeinfo>
  21. #endif
  22. #ifndef NO_STEAM
  23. #include "steam/steam_api.h"
  24. extern CSteamAPIContext *steamapicontext;
  25. #endif
  26. #define USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
  27. enum
  28. {
  29. SF_RESERVED_CURSOR_SLOT,
  30. SF_RESERVED_BEGINFRAME_SLOT = 0xFFFFFFFE, // These two reserved slots are used with SF4 to put a single BeginFrame/EndFrame call pair into the render context
  31. SF_RESERVED_ENDFRAME_SLOT = 0xFFFFFFFF
  32. };
  33. // SF4 TODO
  34. // Using a set of void * for now because we need to keep both SF4 and SF3 working
  35. //namespace Scaleform
  36. //{
  37. // namespace GFx
  38. // {
  39. // class Value;
  40. // class MovieDef;
  41. // class Movie;
  42. // }
  43. //}
  44. //
  45. //typedef SFVALUE SFVALUE;
  46. // typedef Scaleform::GFx::MovieDef* SFMOVIEDEF;
  47. //typedef Scaleform::GFx::Movie* SFMOVIE;
  48. /* SFPARAMS
  49. *
  50. * SF4 TODO
  51. * This should actually be declared as
  52. * typedef Scaleform::GFx::FunctionHandler::Params* SFPARAMS
  53. * Unfortunately this is not possible without including SF SDK header files, because Params
  54. * is internal to FunctionHandler which is a class and not a namespace.
  55. *
  56. * SFPARAMS is passed by SF to callbacks in game code, which extract info from it by passing it
  57. * on to ScaleformUI helper functions.
  58. *
  59. * Declaring it as a void* is nasty but seems the only way out, without dragging in SF SDK into
  60. * other projects such as Client
  61. */
  62. struct SFPARAMS_opaque_tag;
  63. typedef SFPARAMS_opaque_tag *SFPARAMS;
  64. struct SFMOVIE_opaque_tag;
  65. typedef SFMOVIE_opaque_tag * SFMOVIE;
  66. struct SFMOVIEDEF_opaque_tag;
  67. typedef SFMOVIEDEF_opaque_tag* SFMOVIEDEF;
  68. struct SFVALUE_opaque_tag;
  69. typedef SFVALUE_opaque_tag* SFVALUE;
  70. /*
  71. This class is a wrapper for a tuple of SFVALUEs (actually Scaleform::GFx::Value objects) that is use for passing parameters to
  72. flash functions. It exists primarily to do bounds checking for indices and verify count parity when calling Invoke.
  73. */
  74. class SFVALUEARRAY
  75. {
  76. public:
  77. SFVALUEARRAY() :
  78. m_count(0),
  79. m_pValues(NULL)
  80. {}
  81. SFVALUEARRAY( int count, SFVALUE pValues ) :
  82. m_count(count),
  83. m_pValues(pValues)
  84. {}
  85. ~SFVALUEARRAY() {}
  86. SFVALUE GetValues() const { return m_pValues; }
  87. int Count() const { return m_count; }
  88. SFVALUE operator[] (int index ); // only usable from within the materialsystem.dll
  89. void SetValues( int count, SFVALUE pValues )
  90. {
  91. m_count = count;
  92. m_pValues = pValues;
  93. }
  94. private:
  95. SFVALUE m_pValues;
  96. int m_count;
  97. };
  98. enum
  99. {
  100. SF_FIRST_UNRESERVED_SLOT = 1, SF_FULL_SCREEN_SLOT = SF_FIRST_UNRESERVED_SLOT, SF_FIRST_SS_SLOT, SF_SLOT_IDS_COUNT
  101. };
  102. #define SF_SS_SLOT( x ) ( SF_FIRST_SS_SLOT + ( x ) )
  103. #define SF_ENGINE_UI_SLOT_MASK 3
  104. #define SF_GAME_UI_SLOT_MASK ( ~3 )
  105. // Custom virtual keys the scaleform implementation uses for the right thumbstick.
  106. // We're using the values below for these VK's because according to WinUser.h ( where the VKs are defined )
  107. // the range 0x88 - 0x8F is unassigned.
  108. #define VK_XSTICK2_UP 0x88
  109. #define VK_XSTICK2_RIGHT 0x89
  110. #define VK_XSTICK2_DOWN 0x8A
  111. #define VK_XSTICK2_LEFT 0x8B
  112. #define VK_MWHEEL_UP 0x8C
  113. #define VK_MWHEEL_DOWN 0x8D
  114. /* REI: This is a pretty unsafe function, and doesn't seem to be used. Commenting out for now.
  115. template<class C, class T>
  116. inline C MakeSFHandle( T* ptr )
  117. {
  118. return ( C ) ptr;
  119. }
  120. */
  121. class IScaleformUI;
  122. class IUIMarshalHelper;
  123. /******************************************************
  124. * callback handling machinery
  125. */
  126. class ScaleformUIFunctionHandlerObject
  127. {
  128. };
  129. #define SCALEFORM_CALLBACK_ARGS_DECL IUIMarshalHelper* pui, SFPARAMS obj
  130. typedef void ( ScaleformUIFunctionHandlerObject::*ScaleformUIFunctionHandler )( SCALEFORM_CALLBACK_ARGS_DECL );
  131. struct ScaleformUIFunctionHandlerDefinition
  132. {
  133. const char *m_pName;
  134. union{
  135. // Doing this lame union to force the compiler to properly align the
  136. // member function pointer to at least 16-bytes for warning control.
  137. ScaleformUIFunctionHandler m_pHandler;
  138. char __dont_use_me_pad[16];
  139. };
  140. };
  141. class IScaleformUIFunctionHandlerDefinitionTable
  142. {
  143. public:
  144. virtual const ScaleformUIFunctionHandlerDefinition* GetTable( void ) const = 0;
  145. };
  146. /***************************************************************************
  147. * The following should be used as follows:
  148. * define some methods in a class that you want to serve as function callbacks, and use
  149. * the method signature shown here:
  150. class GFxTutorial
  151. {
  152. public:
  153. // GameAPI stuff
  154. void ToggleFullScreen( SCALEFORM_CALLBACK_ARGS_DECL );
  155. void SetNewBackground( SCALEFORM_CALLBACK_ARGS_DECL );
  156. void NewLight( SCALEFORM_CALLBACK_ARGS_DECL );
  157. void NewScene( SCALEFORM_CALLBACK_ARGS_DECL );
  158. void SetLuminance( SCALEFORM_CALLBACK_ARGS_DECL );
  159. void SFGrabFocus( SCALEFORM_CALLBACK_ARGS_DECL );
  160. void SetMeshPath( SCALEFORM_CALLBACK_ARGS_DECL );
  161. };
  162. * in the same file, add an API_DEF block to expose the methods:
  163. * make sure you put a comma after each SFUI_DECL_METHOD function!
  164. SFUI_BEGIN_GAME_API_DEF
  165. SFUI_DECL_METHOD( ToggleFullScreen ),
  166. SFUI_DECL_METHOD( SetNewBackground ),
  167. SFUI_DECL_METHOD( NewLight ),
  168. SFUI_DECL_METHOD( NewScene ),
  169. SFUI_DECL_METHOD( SetLuminance ),
  170. SFUI_DECL_METHOD( SFGrabFocus ),
  171. SFUI_DECL_METHOD( SetMeshPath ),
  172. SFUI_END_GAME_API_DEF( GFxTutorial );
  173. * install the methods into flash like this:
  174. SFUI_INSTALL_GAME_API( pScaleformUI, sfMovieView, "GameAPI" );
  175. * after this, flash can call _root.GameAPI.ToggleFullScreen() etc.
  176. *
  177. * To make the API_DEF available outside of the file it's defined in,
  178. * add the following after you end the API_DEF block:
  179. *
  180. SFUI_MAKE_GAME_API_PUBLIC( ExternalName );
  181. * and install it like this:
  182. SFUI_INSTALL_EXTERNAL_GAME_API( ExternalName, pScaleformUI, sfMovieView, "GameAPI" );
  183. *
  184. */
  185. #define SFUI_OBJ_NAME( classname, uiname ) ScaleformFunctionHandler_##classname##_##uiname
  186. #define SFUI_OBJ_PTR_NAME( classname, uiname ) pScaleformFunctionHandler_##classname##_##uiname
  187. #define SFUI_BEGIN_GAME_API_DEF \
  188. template<class T>\
  189. class FunctionCallbackDefTable : public IScaleformUIFunctionHandlerDefinitionTable\
  190. {\
  191. static const ScaleformUIFunctionHandlerDefinition m_FunctionTable[];\
  192. public: const ScaleformUIFunctionHandlerDefinition* GetTable( void ) const {return m_FunctionTable;}\
  193. };\
  194. template<class T>\
  195. const ScaleformUIFunctionHandlerDefinition FunctionCallbackDefTable<T>::m_FunctionTable[] = {\
  196. SFUI_DECL_METHOD( OnLoadFinished ),\
  197. SFUI_DECL_METHOD( OnReady ),\
  198. SFUI_DECL_METHOD( OnLoadProgress ),\
  199. SFUI_DECL_METHOD( OnLoadError ),\
  200. SFUI_DECL_METHOD( OnUnload ),\
  201. // Verify that the method has the right arguments before converting it
  202. template <typename T>
  203. inline ScaleformUIFunctionHandler ToScaleformUIFunctionHandler(void (T::*method)(IUIMarshalHelper*, SFPARAMS))
  204. {
  205. return reinterpret_cast< ScaleformUIFunctionHandler >( method );
  206. }
  207. #define SFUI_DECL_METHOD( method ) {#method, ToScaleformUIFunctionHandler( &T::method )}
  208. #define SFUI_DECL_METHOD_AS( method, asname ) {asname, ToScaleformUIFunctionHandler( &T::method )}
  209. #define SFUI_END_GAME_API_DEF( classname, uiname )\
  210. {NULL, NULL}\
  211. };\
  212. static FunctionCallbackDefTable<classname> SFUI_OBJ_NAME( classname, uiname );\
  213. IScaleformUIFunctionHandlerDefinitionTable* SFUI_OBJ_PTR_NAME( classname, uiname ) = &SFUI_OBJ_NAME( classname, uiname )
  214. #define SFUI_REQUEST_ELEMENT( slot, pScaleformUI, classname, pinstance, uiname )\
  215. extern IScaleformUIFunctionHandlerDefinitionTable* SFUI_OBJ_PTR_NAME( classname, uiname );\
  216. pScaleformUI->RequestElement( slot, #uiname, reinterpret_cast<ScaleformUIFunctionHandlerObject*>( pinstance ), SFUI_OBJ_PTR_NAME( classname, uiname ) );
  217. /***************************************************************
  218. * This is a helper class that helps us effeciently set SFText
  219. * elements in flash
  220. */
  221. class ISFTextObject
  222. {
  223. public:
  224. virtual void SetText( int value ) = 0;
  225. virtual void SetText( float value ) = 0;
  226. virtual void SetText( const char* pszText ) = 0;
  227. virtual void SetTextHTML( const char* pszText ) = 0;
  228. virtual void SetText( const wchar_t* pwszText ) = 0;
  229. virtual void SetTextHTML( const wchar_t* pwszText ) = 0;
  230. virtual bool IsValid( void ) = 0;
  231. virtual void Release( void ) = 0;
  232. virtual void SetVisible( bool visible ) = 0;
  233. };
  234. /*******************************************************************
  235. * This is used to pass state information back and forth to flash
  236. * MovieClip objects
  237. */
  238. class ScaleformDisplayInfo
  239. {
  240. protected:
  241. enum SET_FLAGS
  242. {
  243. X_SET = 0x01,
  244. Y_SET = 0x02,
  245. ROTATION_SET = 0x04,
  246. ALPHA_SET = 0x08,
  247. VISIBILITY_SET = 0x10,
  248. XSCALE_SET = 0x20,
  249. YSCALE_SET = 0x40,
  250. };
  251. double m_fX;
  252. double m_fY;
  253. double m_fRotation;
  254. double m_fAlpha;
  255. double m_fXScale;
  256. double m_fYScale;
  257. int m_iSetFlags;
  258. bool m_bVisibility;
  259. public:
  260. ScaleformDisplayInfo() : m_iSetFlags( 0 ) {}
  261. void Clear( void ) {m_iSetFlags = 0;}
  262. inline bool IsXSet( void ) const {return ( m_iSetFlags & X_SET ) != 0;}
  263. inline bool IsYSet( void ) const {return ( m_iSetFlags & Y_SET ) != 0;}
  264. inline bool IsRotationSet( void ) const {return ( m_iSetFlags & ROTATION_SET ) != 0;}
  265. inline bool IsAlphaSet( void ) const {return ( m_iSetFlags & ALPHA_SET ) != 0;}
  266. inline bool IsVisibilitySet( void ) const {return ( m_iSetFlags & VISIBILITY_SET ) != 0;}
  267. inline bool IsXScaleSet( void ) const {return ( m_iSetFlags & XSCALE_SET ) != 0;}
  268. inline bool IsYScaleSet( void ) const {return ( m_iSetFlags & YSCALE_SET ) != 0;}
  269. inline void SetX( double value ) {m_iSetFlags |= X_SET ; m_fX = value;}
  270. inline void SetY( double value ) {m_iSetFlags |= Y_SET ; m_fY = value;}
  271. inline void SetRotation( double value ) {m_iSetFlags |= ROTATION_SET ; m_fRotation = value;}
  272. inline void SetAlpha( double value ) {m_iSetFlags |= ALPHA_SET ; m_fAlpha = value;}
  273. inline void SetVisibility( bool value ) {m_iSetFlags |= VISIBILITY_SET ; m_bVisibility = value;}
  274. inline void SetXScale( double value ) {m_iSetFlags |= XSCALE_SET ; m_fXScale = value;}
  275. inline void SetYScale( double value ) {m_iSetFlags |= YSCALE_SET ; m_fYScale = value;}
  276. inline double GetX( void ) const {return m_fX;}
  277. inline double GetY( void ) const {return m_fY;}
  278. inline double GetRotation( void ) const {return m_fRotation;}
  279. inline double GetAlpha( void ) const {return m_fAlpha;}
  280. inline bool GetVisibility( void ) const {return m_bVisibility;}
  281. inline double GetXScale( void ) const {return m_fXScale;}
  282. inline double GetYScale( void ) const {return m_fYScale;}
  283. };
  284. /***************************************************************
  285. * This is the interface used to initialize slot
  286. */
  287. class IScaleformSlotInitController
  288. {
  289. public:
  290. // A new slot has been created and InitSlot almost finished, perform final configuration
  291. virtual void ConfigureNewSlotPostInit( int slot ) = 0;
  292. // Notification to external systems that a file was loaded by Scaleform libraries
  293. virtual bool OnFileLoadedByScaleform( char const *pszFilename, void *pvBuffer, int numBytesLoaded ) = 0;
  294. virtual const void * GetStringUserData( const char * pchStringTableName, const char * pchKeyName, int * pLength ) = 0;
  295. virtual void PassSignaturesArray( void *pvArray ) = 0;
  296. };
  297. /***************************************************************
  298. * This is the interface used to initialize avatar image data
  299. */
  300. class IScaleformAvatarImageProvider
  301. {
  302. public:
  303. struct ImageInfo_t
  304. {
  305. void const *m_pvImageData;
  306. uint32 m_cbImageData;
  307. };
  308. public:
  309. // Scaleform low-level image needs rgba bits of the inventory image (if it's ready)
  310. virtual bool GetImageInfo( uint64 xuid, ImageInfo_t *pImageInfo ) = 0;
  311. };
  312. /***************************************************************
  313. * This is the interface used to initialize inventory image data
  314. */
  315. class IScaleformInventoryImageProvider
  316. {
  317. public:
  318. struct ImageInfo_t
  319. {
  320. void *m_pvEconItemView;
  321. const char *m_pDefaultIconName;
  322. const CUtlBuffer* m_bufImageDataRGBA;
  323. int m_nWidth;
  324. int m_nHeight;
  325. };
  326. public:
  327. // Scaleform low-level image needs rgba bits of the inventory image (if it's ready)
  328. virtual bool GetInventoryImageInfo( uint64 uiItemId, ImageInfo_t *pImageInfo ) = 0;
  329. };
  330. /***************************************************************
  331. * This is the main interface which is used to interact with scaleform
  332. */
  333. class IUIMarshalHelper
  334. {
  335. public:
  336. // SF4 TODO - REMOVE
  337. enum _ValueType {
  338. VT_Undefined,
  339. VT_Null,
  340. VT_Boolean,
  341. VT_Int,
  342. VT_UInt,
  343. VT_Number,
  344. VT_String,
  345. VT_StringW,
  346. VT_Object,
  347. VT_Array,
  348. VT_DisplayObject,
  349. VT_Closure,
  350. VT_ConvertBoolean,
  351. VT_ConvertInt,
  352. VT_ConvertUInt,
  353. VT_ConvertNumber,
  354. VT_ConvertString,
  355. VT_ConvertStringW
  356. };
  357. /***********************************************
  358. * callback parameter handling
  359. */
  360. virtual SFVALUEARRAY Params_GetArgs( SFPARAMS params ) = 0;
  361. virtual unsigned int Params_GetNumArgs( SFPARAMS params ) = 0;
  362. virtual bool Params_ArgIs( SFPARAMS params, unsigned int index, _ValueType v ) = 0;
  363. virtual SFVALUE Params_GetArg( SFPARAMS params, int index = 0 ) = 0;
  364. virtual _ValueType Params_GetArgType( SFPARAMS params, int index = 0 ) = 0;
  365. virtual double Params_GetArgAsNumber( SFPARAMS params, int index = 0 ) = 0;
  366. virtual bool Params_GetArgAsBool( SFPARAMS params, int index = 0 ) = 0;
  367. virtual const char* Params_GetArgAsString( SFPARAMS params, int index = 0 ) = 0;
  368. virtual const wchar_t* Params_GetArgAsStringW( SFPARAMS params, int index = 0 ) = 0;
  369. virtual void Params_DebugSpew( SFPARAMS params ) = 0;
  370. virtual void Params_SetResult( SFPARAMS params, SFVALUE value ) = 0;
  371. virtual void Params_SetResult( SFPARAMS params, int value ) = 0;
  372. virtual void Params_SetResult( SFPARAMS params, float value ) = 0;
  373. virtual void Params_SetResult( SFPARAMS params, bool value ) = 0;
  374. virtual void Params_SetResult( SFPARAMS params, const char* value, bool bMakeNewValue = true) = 0;
  375. virtual void Params_SetResult( SFPARAMS params, const wchar_t* value, bool bMakeNewValue = true ) = 0;
  376. virtual SFVALUE Params_CreateNewObject( SFPARAMS params ) = 0;
  377. virtual SFVALUE Params_CreateNewString( SFPARAMS params, const char* value ) = 0;
  378. virtual SFVALUE Params_CreateNewString( SFPARAMS params, const wchar_t* value ) = 0;
  379. virtual SFVALUE Params_CreateNewArray( SFPARAMS params, int size = -1 ) = 0;
  380. };
  381. #define SCALEFORMUI_INTERFACE_VERSION "ScaleformUI002"
  382. class IScaleformUI: public IAppSystem, public IUIMarshalHelper
  383. {
  384. /*******************************
  385. * high level functions. These are the bread and butter
  386. * of the interface. They deal mostly with controlling / updating slots
  387. */
  388. public:
  389. virtual void DumpMeshCacheStats() = 0;
  390. virtual void SetSingleThreadedMode( bool bSingleThreded ) = 0;
  391. virtual void RunFrame( float time ) = 0;
  392. virtual void AdvanceSlot( int slot ) = 0;
  393. virtual bool HandleInputEvent( const InputEvent_t &event ) = 0;
  394. virtual bool HandleIMEEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam ) = 0;
  395. virtual bool PreProcessKeyboardEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam ) = 0;
  396. virtual void SetIMEEnabled( bool bEnabled ) = 0;
  397. virtual void SetIMEFocus( int slot ) = 0;
  398. virtual void ShutdownIME() = 0;
  399. virtual float GetJoyValue( int slot, int stickIndex, int axis ) = 0;
  400. virtual void SetSlotViewport( int slot, int x, int y, int width, int height ) = 0;
  401. virtual void RenderSlot( int slot ) = 0;
  402. virtual void ForkRenderSlot( int slot ) = 0;
  403. virtual void JoinRenderSlot( int slot ) = 0;
  404. virtual void InitSlot( int slotID, const char* rootMovie, IScaleformSlotInitController *pController ) = 0;
  405. virtual void SlotRelease( int slotID ) = 0;
  406. virtual void SlotAddRef( int slot ) = 0;
  407. virtual void LockSlot( int slot ) = 0;
  408. virtual void UnlockSlot( int slot ) = 0;
  409. virtual void RequestElement( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject ) = 0;
  410. virtual void RemoveElement( int slot, SFVALUE element ) = 0;
  411. virtual void InstallGlobalObject( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SFVALUE *pInstalledGlobalObjectResult ) = 0;
  412. virtual void RemoveGlobalObject( int slot, SFVALUE element ) = 0;
  413. virtual bool SlotConsumesInputEvents( int slot ) = 0;
  414. virtual bool ConsumesInputEvents( void ) = 0;
  415. virtual bool SlotDeniesInputToGame( int slot ) = 0;
  416. virtual void DenyInputToGame( bool value ) = 0;
  417. // Called from the movieslot to inform Scaleform singleton that we do/don't want our slot to deny input to game
  418. virtual void DenyInputToGameFromFlash( int slot, bool value ) = 0;
  419. virtual void LockInputToSlot( int slot ) = 0;
  420. virtual void UnlockInput( void ) = 0;
  421. virtual bool AvatarImageAddRef( uint64 playerID ) = 0;
  422. virtual void AvatarImageRelease( uint64 playerID ) = 0;
  423. virtual void AvatarImageReload( uint64 playerID, IScaleformAvatarImageProvider *pProvider = NULL ) = 0;
  424. virtual void AddDeviceDependentObject( IShaderDeviceDependentObject * pObject ) = 0;
  425. virtual void RemoveDeviceDependentObject( IShaderDeviceDependentObject * pObject ) = 0;
  426. virtual bool InventoryImageAddRef( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider ) = 0;
  427. virtual void InventoryImageUpdate( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider ) = 0;
  428. virtual void InventoryImageRelease( uint64 iItemId ) = 0;
  429. #ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
  430. virtual void InitInventoryDefaultIcons( CUtlVector< const char * > *vecIconDefaultNames ) = 0;
  431. #endif
  432. virtual bool ChromeHTMLImageAddRef( uint64 imageID ) = 0;
  433. virtual void ChromeHTMLImageUpdate( uint64 imageID, const byte* rgba, int width, int height, ::ImageFormat format ) = 0;
  434. virtual void ChromeHTMLImageRelease( uint64 imageID ) = 0;
  435. virtual void ForceUpdateImages() = 0;
  436. virtual ButtonCode_t GetCurrentKey() = 0;
  437. virtual void SendUIEvent( const char* action, const char* eventData, int slot = 0 ) = 0;
  438. /*********
  439. * Code to deal with the scaleform cursor
  440. */
  441. public:
  442. virtual void InitCursor( const char* cursorMovie ) = 0;
  443. virtual void ReleaseCursor( void ) = 0;
  444. virtual bool IsCursorVisible( void ) = 0;
  445. virtual void RenderCursor( void ) = 0;
  446. virtual void AdvanceCursor( void ) = 0;
  447. virtual void SetCursorViewport( int x, int y, int width, int height ) = 0;
  448. virtual void ShowCursor( void ) = 0;
  449. virtual void HideCursor( void ) = 0;
  450. #if defined( _PS3 )
  451. virtual void PS3UseMoveCursor( void ) = 0;
  452. virtual void PS3UseStandardCursor( void ) = 0;
  453. virtual void PS3ForceCursorStart( void ) = 0;
  454. virtual void PS3ForceCursorEnd( void ) = 0;
  455. #endif
  456. virtual void SetCursorShape( int shapeIndex ) = 0;
  457. virtual void ForceCollectGarbage( int slot ) = 0;
  458. virtual bool IsSetToControllerUI( int slot ) = 0;
  459. virtual void LockMostRecentInputDevice( int slot ) = 0;
  460. virtual void ClearCache( void ) = 0;
  461. /*********
  462. * MovieDef and MovieView related stuff
  463. */
  464. public:
  465. /*****************
  466. * There are many more methods in GFxMovieView. If you need something that's not here,
  467. * check the doucmention at www.scaleform.com or look in the GFxMovieView.h include file
  468. * and add the functionality to this interface and then to ScaleformUIImpl
  469. */
  470. virtual SFMOVIEDEF CreateMovieDef( const char* pfilename, unsigned int loadConstants = 0, size_t memoryArena = 0 ) = 0;
  471. virtual void ReleaseMovieDef( SFMOVIEDEF movieDef ) = 0;
  472. virtual SFMOVIE MovieDef_CreateInstance( SFMOVIEDEF movieDef, bool initFirstFrame = true, size_t memoryArena = 0 ) = 0;
  473. virtual void ReleaseMovieView( SFMOVIE movieView ) = 0;
  474. virtual void MovieView_Advance( SFMOVIE movieView, float time, unsigned int frameCatchUpCount = 2 ) = 0;
  475. virtual void MovieView_SetBackgroundAlpha( SFMOVIE movieView, float alpha ) = 0;
  476. virtual void MovieView_SetViewport( SFMOVIE movieView, int bufw, int bufh, int left, int top, int w, int h, unsigned int flags = 0 ) = 0;
  477. virtual void MovieView_Display( SFMOVIE movieView ) = 0;
  478. /**************************
  479. * movie alignment
  480. */
  481. // these come from gfxplayer.h
  482. // SF4 TODO - Remove
  483. enum _ScaleModeType
  484. {
  485. SM_NoScale, SM_ShowAll, SM_ExactFit, SM_NoBorder
  486. };
  487. enum _AlignType
  488. {
  489. Align_Center, Align_TopCenter, Align_BottomCenter, Align_CenterLeft, Align_CenterRight, Align_TopLeft, Align_TopRight, Align_BottomLeft, Align_BottomRight
  490. };
  491. virtual void MovieView_SetViewScaleMode( SFMOVIE movieView, _ScaleModeType type ) = 0;
  492. virtual _ScaleModeType MovieView_GetViewScaleMode( SFMOVIE movieView ) = 0;
  493. virtual void MovieView_SetViewAlignment( SFMOVIE movieView, _AlignType type ) = 0;
  494. virtual _AlignType MovieView_GetViewAlignment( SFMOVIE movieView ) = 0;
  495. /******************************
  496. * create / access values
  497. */
  498. virtual SFVALUE MovieView_CreateObject( SFMOVIE movieView, const char* className = NULL, SFVALUEARRAY args = SFVALUEARRAY(0, NULL), int numArgs = 0 ) = 0;
  499. virtual SFVALUE MovieView_GetVariable( SFMOVIE movieView, const char* variablePath ) = 0;
  500. virtual SFVALUE MovieView_CreateString( SFMOVIE movieView, const char *str ) = 0;
  501. virtual SFVALUE MovieView_CreateStringW( SFMOVIE movieView, const wchar_t *str ) = 0;
  502. virtual SFVALUE MovieView_CreateArray( SFMOVIE movieView, int size = -1 ) = 0;
  503. /*************************************
  504. * movie input events
  505. */
  506. /********************************************
  507. * Methods to handle translation of strings and
  508. * replacing ${glyph} type constructs in strings
  509. */
  510. // if key does not start with '#' this function returns NULL
  511. virtual const wchar_t* Translate( const char *key, bool* pIsHTML ) = 0;
  512. // escape the '$' in strings to avoid glyph replacment '\\${not a glyph}'
  513. virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const wchar_t* pin, int fontSize = 0, bool bForceControllerGlyph = false ) = 0;
  514. virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const char* text, int fontSize = 0, bool bForceControllerGlyph = false ) = 0;
  515. // these convert html codes to &lt; style codes and escape the $ and @
  516. virtual void MakeStringSafe( const wchar_t* stringin, OUT_Z_BYTECAP(outlength) wchar_t* stringout, int outlength ) = 0;
  517. /********************************************
  518. * keyboard codes
  519. */
  520. enum KeyCode
  521. {
  522. VoidSymbol = 0,
  523. // A through Z and numbers 0 through 9.
  524. A = 65,
  525. B,
  526. C,
  527. D,
  528. E,
  529. F,
  530. G,
  531. H,
  532. I,
  533. J,
  534. K,
  535. L,
  536. M,
  537. N,
  538. O,
  539. P,
  540. Q,
  541. R,
  542. S,
  543. T,
  544. U,
  545. V,
  546. W,
  547. X,
  548. Y,
  549. Z,
  550. Num0 = 48,
  551. Num1,
  552. Num2,
  553. Num3,
  554. Num4,
  555. Num5,
  556. Num6,
  557. Num7,
  558. Num8,
  559. Num9,
  560. // Numeric keypad.
  561. KP_0 = 96,
  562. KP_1,
  563. KP_2,
  564. KP_3,
  565. KP_4,
  566. KP_5,
  567. KP_6,
  568. KP_7,
  569. KP_8,
  570. KP_9,
  571. KP_Multiply,
  572. KP_Add,
  573. KP_Enter,
  574. KP_Subtract,
  575. KP_Decimal,
  576. KP_Divide,
  577. // Function keys.
  578. F1 = 112,
  579. F2,
  580. F3,
  581. F4,
  582. F5,
  583. F6,
  584. F7,
  585. F8,
  586. F9,
  587. F10,
  588. F11,
  589. F12,
  590. F13,
  591. F14,
  592. F15,
  593. // Other keys.
  594. Backspace = 8,
  595. Tab,
  596. Clear = 12,
  597. Return,
  598. Shift = 16,
  599. Control,
  600. Alt,
  601. Pause,
  602. CapsLock = 20, // Toggle
  603. Escape = 27,
  604. Space = 32,
  605. PageUp,
  606. PageDown,
  607. End = 35,
  608. Home,
  609. Left,
  610. Up,
  611. Right,
  612. Down,
  613. Insert = 45,
  614. Delete,
  615. Help,
  616. XStick2Up = 0x88, // These 4 are custom key codes for the right thumbstick.
  617. XStick2Left = 0x89,
  618. XStick2Right = 0x8A,
  619. XStick2Down = 0x8B,
  620. MWHEEL_UP,
  621. MWHEEL_DOWN,
  622. NumLock = 144, // Toggle
  623. ScrollLock = 145, // Toggle
  624. Semicolon = 186,
  625. Equal = 187,
  626. Comma = 188, // Platform specific?
  627. Minus = 189,
  628. Period = 190, // Platform specific?
  629. Slash = 191,
  630. Bar = 192,
  631. BracketLeft = 219,
  632. Backslash = 220,
  633. BracketRight = 221,
  634. Quote = 222,
  635. OEM_AX = 0xE1, // 'AX' key on Japanese AX kbd
  636. OEM_102 = 0xE2, // "<>" or "\|" on RT 102-key kbd.
  637. ICO_HELP = 0xE3, // Help key on ICO
  638. ICO_00 = 0xE4, // 00 key on ICO
  639. // Total number of keys.
  640. KeyCount
  641. };
  642. // these are for strings that use $@x where x is a code for the controller button function
  643. // the function x refers to ( Select ) gets mapped to a controller button ( PS3_Square ), and
  644. // the PS3_Square gets mapped to an image to show in the UI.
  645. // these are the buttons that we have glyphs for
  646. class ControllerButton
  647. {
  648. public:
  649. enum Enum
  650. {
  651. // ** Important **
  652. // if you add or remove functions from this enum, be sure to reflect the changes in the
  653. // following arrays in ScaleformUITranslationsImpl.cpp:
  654. // g_buttonFunctionKeywords
  655. // g_controllerButtonToButtonCodeLookup
  656. // g_controllerButtonImageNames
  657. // generic enums
  658. Confirm,
  659. Cancel,
  660. West,
  661. North,
  662. LShoulder,
  663. RShoulder,
  664. LTrigger,
  665. RTrigger,
  666. DPadUp,
  667. DPadDown,
  668. DPadLeft,
  669. DPadRight,
  670. DPad,
  671. LStickUp,
  672. LStickDown,
  673. LStickLeft,
  674. LStickRight,
  675. LStickButton,
  676. LStick,
  677. RStickUp,
  678. RStickDown,
  679. RStickLeft,
  680. RStickRight,
  681. RStickButton,
  682. RStick,
  683. Start,
  684. AltStart,
  685. NumButtons,
  686. Undefined = NumButtons,
  687. // xbox enums ( these have the same ordinal values as the generics above )
  688. XBoxA = Confirm,
  689. XBoxB,
  690. XBoxX,
  691. XBoxY,
  692. XBoxLB,
  693. XBoxRB,
  694. XBoxLT,
  695. XBoxRT,
  696. XBoxStart = Start,
  697. XBoxBack,
  698. // ps3 enums ( these have the same ordinal values as the generics above )
  699. PS3X = Confirm,
  700. PS3Circle,
  701. PS3Square,
  702. PS3Triangle,
  703. PS3L1,
  704. PS3R1,
  705. PS3L2,
  706. PS3R2,
  707. PS3L3 = LStickButton,
  708. PS3R3 = RStickButton,
  709. PS3Start = Start,
  710. PS3Select,
  711. };
  712. };
  713. virtual void RefreshKeyBindings( void ) = 0;
  714. virtual void ShowActionNameWhenActionIsNotBound( bool value ) = 0;
  715. virtual void UpdateBindingForButton( ButtonCode_t bt, const char* pbinding ) = 0;
  716. /********************************************
  717. * Hit Testing
  718. */
  719. // this comes from GFxPlayer.h
  720. // SF4 TODO - Remove
  721. enum _HitTestType
  722. {
  723. HitTest_Bounds = 0, HitTest_Shapes = 1, HitTest_ButtonEvents = 2, HitTest_ShapesNoInvisible = 3
  724. };
  725. virtual bool MovieView_HitTest( SFMOVIE movieView, float x, float y, _HitTestType testCond = HitTest_Shapes, unsigned int controllerIdx = 0 ) = 0;
  726. /**********************************************
  727. * Scaleform::GFx::Value stuff
  728. */
  729. protected:
  730. public:
  731. // This comes from GFxPlayer.h
  732. virtual SFVALUE CreateValue( SFVALUE value ) = 0;
  733. virtual SFVALUE CreateValue( int value ) = 0;
  734. virtual SFVALUE CreateValue( float value ) = 0;
  735. virtual SFVALUE CreateValue( bool value ) = 0;
  736. virtual SFVALUE CreateValue( const char* value ) = 0;
  737. virtual SFVALUE CreateValue( const wchar_t* value ) = 0;
  738. virtual SFVALUE CreateNewObject( int slot ) = 0;
  739. virtual SFVALUE CreateNewString( int slot, const char* value ) = 0;
  740. virtual SFVALUE CreateNewString( int slot, const wchar_t* value ) = 0;
  741. virtual SFVALUE CreateNewArray( int slot, int size = -1 ) = 0;
  742. virtual void Value_SetValue( SFVALUE obj, SFVALUE value ) = 0;
  743. virtual void Value_SetValue( SFVALUE obj, int value ) = 0;
  744. virtual void Value_SetValue( SFVALUE obj, float value ) = 0;
  745. virtual void Value_SetValue( SFVALUE obj, bool value ) = 0;
  746. virtual void Value_SetValue( SFVALUE obj, const char* value ) = 0;
  747. virtual void Value_SetValue( SFVALUE obj, const wchar_t* value ) = 0;
  748. virtual void Value_SetColor( SFVALUE obj, int color ) = 0;
  749. virtual void Value_SetColor( SFVALUE obj, float r, float g, float b, float a ) = 0;
  750. virtual void Value_SetTint( SFVALUE obj, int color ) = 0;
  751. virtual void Value_SetTint( SFVALUE obj, float r, float g, float b, float a ) = 0;
  752. virtual void Value_SetColorTransform( SFVALUE obj, int colorMultiply, int colorAdd ) = 0;
  753. virtual void Value_SetColorTransform( SFVALUE obj, float r, float g, float b, float a, int colorAdd ) = 0;
  754. virtual void Value_SetArraySize( SFVALUE obj, int size ) = 0;
  755. virtual int Value_GetArraySize( SFVALUE obj ) = 0;
  756. virtual void Value_ClearArrayElements( SFVALUE obj ) = 0;
  757. virtual void Value_RemoveArrayElement( SFVALUE obj, int index ) = 0;
  758. virtual void Value_RemoveArrayElements( SFVALUE obj, int index, int count ) = 0;
  759. virtual SFVALUE Value_GetArrayElement( SFVALUE obj, int index ) = 0;
  760. virtual void Value_SetArrayElement( SFVALUE obj, int index, SFVALUE value ) = 0;
  761. virtual void Value_SetArrayElement( SFVALUE obj, int index, int value ) = 0;
  762. virtual void Value_SetArrayElement( SFVALUE obj, int index, float value ) = 0;
  763. virtual void Value_SetArrayElement( SFVALUE obj, int index, bool value ) = 0;
  764. virtual void Value_SetArrayElement( SFVALUE obj, int index, const char* value ) = 0;
  765. virtual void Value_SetArrayElement( SFVALUE obj, int index, const wchar_t* value ) = 0;
  766. virtual void Value_SetText( SFVALUE obj, const char* value ) = 0;
  767. virtual void Value_SetText( SFVALUE obj, const wchar_t* value ) = 0;
  768. virtual void Value_SetTextHTML( SFVALUE obj, const char* value ) = 0;
  769. virtual void Value_SetTextHTML( SFVALUE obj, const wchar_t* value ) = 0;
  770. virtual int Value_SetFormattedText( SFVALUE obj, const char* pFormat, ... ) = 0;
  771. virtual void ReleaseValue( SFVALUE value ) = 0;
  772. virtual void CreateValueArray( SFVALUEARRAY& valueArray, int length ) = 0;
  773. virtual SFVALUEARRAY CreateValueArray( int length ) = 0;
  774. virtual void ReleaseValueArray( SFVALUEARRAY& valueArray ) = 0;
  775. virtual void ReleaseValueArray( SFVALUEARRAY& valueArray, int count ) = 0; // DEPRECATED
  776. virtual SFVALUE ValueArray_GetElement( SFVALUEARRAY, int index ) = 0;
  777. virtual _ValueType ValueArray_GetType( SFVALUEARRAY array, int index ) = 0;
  778. virtual double ValueArray_GetNumber( SFVALUEARRAY array, int index ) = 0;
  779. virtual bool ValueArray_GetBool( SFVALUEARRAY array, int index ) = 0;
  780. virtual const char* ValueArray_GetString( SFVALUEARRAY array, int index ) = 0;
  781. virtual const wchar_t* ValueArray_GetStringW( SFVALUEARRAY array, int index ) = 0;
  782. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, SFVALUE value ) = 0;
  783. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, int value ) = 0;
  784. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, float value ) = 0;
  785. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, bool value ) = 0;
  786. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const char* value ) = 0;
  787. virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const wchar_t* value ) = 0;
  788. virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const char* value ) = 0;
  789. virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const wchar_t* value ) = 0;
  790. virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const char* value ) = 0;
  791. virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const wchar_t* value ) = 0;
  792. virtual bool Value_HasMember( SFVALUE value, const char* name ) = 0;
  793. virtual SFVALUE Value_GetMember( SFVALUE value, const char* name ) = 0;
  794. virtual bool Value_SetMember( SFVALUE obj, const char *name, SFVALUE value ) = 0;
  795. virtual bool Value_SetMember( SFVALUE obj, const char *name, int value ) = 0;
  796. virtual bool Value_SetMember( SFVALUE obj, const char *name, float value ) = 0;
  797. virtual bool Value_SetMember( SFVALUE obj, const char *name, bool value ) = 0;
  798. virtual bool Value_SetMember( SFVALUE obj, const char *name, const char* value ) = 0;
  799. virtual bool Value_SetMember( SFVALUE obj, const char *name, const wchar_t* value ) = 0;
  800. virtual ISFTextObject* TextObject_MakeTextObject( SFVALUE value ) = 0;
  801. virtual ISFTextObject* TextObject_MakeTextObjectFromMember( SFVALUE value, const char* pName ) = 0;
  802. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args ) = 0;
  803. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args ) = 0;
  804. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs ) = 0;
  805. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs ) = 0;
  806. virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ) = 0; // DEPRECATED
  807. virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ) = 0; // DEPRECATED
  808. virtual void Value_SetVisible( SFVALUE obj, bool visible ) = 0;
  809. virtual void Value_GetDisplayInfo( SFVALUE obj, ScaleformDisplayInfo* dinfo ) = 0;
  810. virtual void Value_SetDisplayInfo( SFVALUE obj, const ScaleformDisplayInfo* dinfo ) = 0;
  811. virtual _ValueType Value_GetType( SFVALUE obj ) = 0;
  812. virtual double Value_GetNumber( SFVALUE obj ) = 0;
  813. virtual bool Value_GetBool( SFVALUE obj ) = 0;
  814. virtual const char* Value_GetString( SFVALUE obj ) = 0;
  815. virtual const wchar_t* Value_GetStringW( SFVALUE obj ) = 0;
  816. virtual SFVALUE Value_GetText( SFVALUE obj ) = 0;
  817. virtual SFVALUE Value_GetTextHTML( SFVALUE obj ) = 0;
  818. };
  819. inline void ScaleformInitFullScreenAndCursor( IScaleformUI* pui, const char* fullScreenName, const char* cursorName, IScaleformSlotInitController *pInitController )
  820. {
  821. pui->InitSlot( SF_FULL_SCREEN_SLOT, fullScreenName, pInitController );
  822. if ( !IsX360() )
  823. pui->InitCursor( cursorName );
  824. }
  825. inline void ScaleformReleaseFullScreenAndCursor( IScaleformUI* pui )
  826. {
  827. pui->SlotRelease( SF_FULL_SCREEN_SLOT );
  828. pui->ReleaseCursor();
  829. }
  830. inline void SFDevMsg( const char *pMsgFormat, ... )
  831. {
  832. #if !defined( DBGFLAG_STRINGS_STRIP )
  833. ConVarRef dev_scaleform_debug("dev_scaleform_debug");
  834. if ( dev_scaleform_debug.GetBool() )
  835. {
  836. char str[4096] = "SF: ";
  837. char startIdx = strlen(str);
  838. va_list marker;
  839. va_start( marker, pMsgFormat );
  840. V_vsnprintf( str + startIdx, sizeof( str ) - startIdx, pMsgFormat, marker );
  841. va_end( marker );
  842. DevMsg( "%s", str );
  843. }
  844. #endif
  845. }
  846. template<class T>
  847. class ScaleformFlashInterfaceMixin : public T
  848. {
  849. public:
  850. // the fancy for statement below is so we can use this macro like
  851. // so:
  852. //
  853. // WITH_SLOT_LOCKED
  854. // {
  855. // //code requiring lock
  856. // }
  857. class ForLoopOnce
  858. {
  859. public:
  860. ForLoopOnce() : m_bDone(false) {}
  861. bool Looping() { return !m_bDone; }
  862. void SetDone() { m_bDone = true; }
  863. private:
  864. bool m_bDone;
  865. };
  866. class AutoScaleformSlotLocker : public ForLoopOnce
  867. {
  868. public:
  869. explicit AutoScaleformSlotLocker( ScaleformFlashInterfaceMixin<T>& parent ) : m_parent(parent)
  870. {
  871. m_parent.LockScaleformSlot();
  872. }
  873. ~AutoScaleformSlotLocker()
  874. {
  875. m_parent.UnlockScaleformSlot();
  876. }
  877. private:
  878. AutoScaleformSlotLocker();
  879. ScaleformFlashInterfaceMixin<T>& m_parent;
  880. };
  881. #define WITH_SLOT_LOCKED for ( AutoScaleformSlotLocker __locker__(*this); __locker__.Looping(); __locker__.SetDone() )
  882. class AutoScaleformValueArray : public SFVALUEARRAY, public ForLoopOnce
  883. {
  884. public:
  885. AutoScaleformValueArray( ScaleformFlashInterfaceMixin<T>& parent, int count ) :
  886. m_parent(parent)
  887. {
  888. m_parent.m_pScaleformUI->CreateValueArray(*this, count);
  889. }
  890. ~AutoScaleformValueArray()
  891. {
  892. m_parent.m_pScaleformUI->ReleaseValueArray(*this);
  893. }
  894. private:
  895. AutoScaleformValueArray();
  896. ScaleformFlashInterfaceMixin<T>& m_parent;
  897. };
  898. #define WITH_SFVALUEARRAY( name, count ) for ( AutoScaleformValueArray name(*this, count); name.Looping(); name.SetDone() )
  899. class AutoScaleformValueArraySlotLocker : public SFVALUEARRAY, public ForLoopOnce
  900. {
  901. public:
  902. explicit AutoScaleformValueArraySlotLocker( class ScaleformFlashInterfaceMixin& parent, int count ) :
  903. m_parent(parent)
  904. {
  905. m_parent.LockScaleformSlot();
  906. m_parent.m_pScaleformUI->CreateValueArray(*this, count);
  907. }
  908. ~AutoScaleformValueArraySlotLocker()
  909. {
  910. m_parent.m_pScaleformUI->ReleaseValueArray(*this);
  911. m_parent.UnlockScaleformSlot();
  912. }
  913. private:
  914. AutoScaleformValueArraySlotLocker();
  915. ScaleformFlashInterfaceMixin& m_parent;
  916. };
  917. #define WITH_SFVALUEARRAY_SLOT_LOCKED( name, count ) for ( AutoScaleformValueArraySlotLocker name(*this, count); name.Looping(); name.SetDone() )
  918. #define SF_SPLITSCREEN_PLAYER_GUARD() ACTIVE_SPLITSCREEN_PLAYER_GUARD( m_iFlashSlot - SF_FIRST_SS_SLOT ); GAMEUI_ACTIVE_SPLITSCREEN_PLAYER_GUARD( m_iFlashSlot - SF_FIRST_SS_SLOT )
  919. #define SF_FORCE_SPLITSCREEN_PLAYER_GUARD(x) ACTIVE_SPLITSCREEN_PLAYER_GUARD( (x) ); GAMEUI_ACTIVE_SPLITSCREEN_PLAYER_GUARD( (x) )
  920. // enum to distinguish the desired joystick. Passed into the GetJoyX and GetJoyY methods )
  921. enum
  922. {
  923. LEFT_STICK,
  924. RIGHT_STICK
  925. };
  926. //scaleform callbacks
  927. // GameAPI stuff
  928. IScaleformUI* m_pScaleformUI;
  929. SFVALUE m_FlashAPI;
  930. int m_iFlashSlot;
  931. bool m_bFlashAPIIsValid;
  932. ScaleformFlashInterfaceMixin()
  933. {
  934. InitScaleformMixinAfterConstruction();
  935. }
  936. void InitScaleformMixinAfterConstruction( void )
  937. {
  938. m_bFlashAPIIsValid = false;
  939. m_iFlashSlot = -1;
  940. m_pScaleformUI = NULL;
  941. m_FlashAPI = NULL;
  942. }
  943. virtual ~ScaleformFlashInterfaceMixin()
  944. {
  945. RemoveFlashElement();
  946. }
  947. /***********************
  948. * required callback handlers
  949. */
  950. void OnLoadFinished( IUIMarshalHelper* puiHelper, SFPARAMS params )
  951. {
  952. // $$$REI TODO: This callback needs access to Scaleform directly; figure out how to avoid this callback in Panorama
  953. IScaleformUI* pui = static_cast< IScaleformUI* >( puiHelper );
  954. m_pScaleformUI = pui;
  955. m_FlashAPI = m_pScaleformUI->CreateValue( pui->Params_GetArg( params, 0 ) );
  956. m_iFlashSlot = ( int ) m_pScaleformUI->Params_GetArgAsNumber( params, 1 );
  957. m_pScaleformUI->SlotAddRef( m_iFlashSlot );
  958. m_bFlashAPIIsValid = true;
  959. #if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
  960. char szName[128];
  961. V_snprintf( szName, ARRAYSIZE(szName), "ScaleformUI::OnLoadFinished_%s", typeid( *this ).name() );
  962. MEM_ALLOC_CREDIT_( szName );
  963. #endif
  964. FlashLoaded();
  965. #if defined(_DEBUG)
  966. SFDevMsg("ScaleformUI::OnLoadFinished_%s slot=%d\n", typeid( *this ).name(), m_iFlashSlot);
  967. #else
  968. SFDevMsg("ScaleformUI::OnLoadFinished slot=%d\n", m_iFlashSlot);
  969. #endif
  970. }
  971. void OnReady( IUIMarshalHelper* pui, SFPARAMS params )
  972. {
  973. #if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
  974. char szName[128];
  975. V_snprintf( szName, ARRAYSIZE(szName), "ScaleformUI::OnReady_%s", typeid( *this ).name() );
  976. MEM_ALLOC_CREDIT_( szName );
  977. #endif
  978. FlashReady();
  979. SFDevMsg("ScaleformUI::OnReady\n");
  980. }
  981. void OnLoadProgress( IUIMarshalHelper* pui, SFPARAMS params )
  982. {
  983. int loadedBytes;
  984. int totalBytes;
  985. loadedBytes = ( int ) pui->Params_GetArgAsNumber( params, 1 );
  986. totalBytes = ( int ) pui->Params_GetArgAsNumber( params, 2 );
  987. FlashLoadProgress( loadedBytes, totalBytes );
  988. }
  989. void OnLoadError( IUIMarshalHelper* puiHelper, SFPARAMS params )
  990. {
  991. // $$$REI TODO: This callback needs access to Scaleform directly; figure out how to avoid this callback in Panorama
  992. IScaleformUI* pui = static_cast< IScaleformUI* >( puiHelper );
  993. FlashLoadError( pui, params );
  994. }
  995. void OnUnload( IUIMarshalHelper* puiHelper, SFPARAMS params )
  996. {
  997. #if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
  998. char szName[128];
  999. V_snprintf( szName, ARRAYSIZE(szName), "ScaleformUI::OnUnload_%s", typeid( *this ).name() );
  1000. #endif
  1001. if ( PreUnloadFlash() )
  1002. {
  1003. SFDevMsg("ScaleformUI::OnUnload slot=%d\n", m_iFlashSlot);
  1004. m_pScaleformUI->Params_SetResult( params, true );
  1005. m_bFlashAPIIsValid = false;
  1006. m_pScaleformUI->ReleaseValue( m_FlashAPI );
  1007. m_FlashAPI = NULL;
  1008. m_pScaleformUI->SlotRelease( m_iFlashSlot );
  1009. m_pScaleformUI = NULL;
  1010. PostUnloadFlash();
  1011. }
  1012. else
  1013. {
  1014. SFDevMsg("ScaleformUI::OnUnload slot=%d FAILED\n", m_iFlashSlot);
  1015. m_pScaleformUI->Params_SetResult( params, false );
  1016. }
  1017. }
  1018. /**************************
  1019. * useful functions
  1020. */
  1021. void RemoveFlashElement( void )
  1022. {
  1023. #if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
  1024. char szName[128];
  1025. V_snprintf( szName, ARRAYSIZE(szName), "ScaleformUI::RemoveFlashElement_%s", typeid( *this ).name() );
  1026. #endif
  1027. if ( FlashAPIIsValid() )
  1028. {
  1029. // the RemoveElement call takes care of locking for us
  1030. m_pScaleformUI->RemoveElement( m_iFlashSlot, m_FlashAPI );
  1031. }
  1032. }
  1033. bool FlashAPIIsValid( void )
  1034. {
  1035. return m_bFlashAPIIsValid;
  1036. }
  1037. // override these functions for you own use
  1038. virtual void FlashLoaded( void )
  1039. {
  1040. }
  1041. virtual void FlashReady( void )
  1042. {
  1043. }
  1044. virtual bool PreUnloadFlash( void )
  1045. {
  1046. // return false if you don't want to unload now
  1047. return true;
  1048. }
  1049. virtual void PostUnloadFlash( void )
  1050. {
  1051. }
  1052. virtual void FlashLoadProgress( int loadedBytes, int totalBytes )
  1053. {
  1054. }
  1055. virtual void FlashLoadError( IScaleformUI* pui, SFPARAMS params )
  1056. {
  1057. // Failed to load a movie clip (dependency swf file corrupt)
  1058. Error( "Error loading swf file!" );
  1059. }
  1060. float GetJoyX( int stick )
  1061. {
  1062. if ( FlashAPIIsValid() )
  1063. {
  1064. return m_pScaleformUI->GetJoyValue( m_iFlashSlot - SF_FIRST_SS_SLOT, stick, 0 );
  1065. }
  1066. else
  1067. return 0.0f;
  1068. }
  1069. float GetJoyY( int stick )
  1070. {
  1071. if ( FlashAPIIsValid() )
  1072. {
  1073. return m_pScaleformUI->GetJoyValue( m_iFlashSlot - SF_FIRST_SS_SLOT, stick, 1 );
  1074. }
  1075. else
  1076. return 0.0f;
  1077. }
  1078. SFVALUE CreateFlashObject()
  1079. {
  1080. SFVALUE result = NULL;
  1081. if ( FlashAPIIsValid() )
  1082. {
  1083. WITH_SLOT_LOCKED
  1084. {
  1085. result = m_pScaleformUI->CreateNewObject( m_iFlashSlot );
  1086. }
  1087. }
  1088. return result;
  1089. }
  1090. SFVALUE CreateFlashArray( int length = -1 )
  1091. {
  1092. SFVALUE result = NULL;
  1093. if ( FlashAPIIsValid() )
  1094. {
  1095. WITH_SLOT_LOCKED
  1096. {
  1097. result = m_pScaleformUI->CreateNewArray( m_iFlashSlot, length );
  1098. }
  1099. }
  1100. return result;
  1101. }
  1102. SFVALUE CreateFlashString( const char *value )
  1103. {
  1104. SFVALUE result = NULL;
  1105. if ( FlashAPIIsValid() )
  1106. {
  1107. WITH_SLOT_LOCKED
  1108. {
  1109. result = m_pScaleformUI->CreateNewString( m_iFlashSlot, value );
  1110. }
  1111. }
  1112. return result;
  1113. }
  1114. SFVALUE CreateFlashString( const wchar_t* value )
  1115. {
  1116. SFVALUE result = NULL;
  1117. if ( FlashAPIIsValid() )
  1118. {
  1119. WITH_SLOT_LOCKED
  1120. {
  1121. result = m_pScaleformUI->CreateNewString( m_iFlashSlot, value );
  1122. }
  1123. }
  1124. return result;
  1125. }
  1126. void LockInputToSlot( int slot = -1 )
  1127. {
  1128. AssertMsg( m_pScaleformUI, "Called LockInputToSlot with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1129. if ( m_pScaleformUI )
  1130. {
  1131. if ( slot == -1 )
  1132. slot = m_iFlashSlot - SF_FIRST_SS_SLOT;
  1133. m_pScaleformUI->LockInputToSlot( slot );
  1134. }
  1135. }
  1136. void UnlockInput()
  1137. {
  1138. AssertMsg( m_pScaleformUI, "Called UnlockInput with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1139. if ( m_pScaleformUI )
  1140. {
  1141. m_pScaleformUI->UnlockInput();
  1142. }
  1143. }
  1144. void LockScaleformSlot( void )
  1145. {
  1146. AssertMsg( m_pScaleformUI, "Called LockScaleformSlot with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1147. if ( m_pScaleformUI )
  1148. {
  1149. m_pScaleformUI->LockSlot( m_iFlashSlot );
  1150. }
  1151. }
  1152. void UnlockScaleformSlot( void )
  1153. {
  1154. AssertMsg( m_pScaleformUI, "Called UnlockScaleformSlot with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1155. if ( m_pScaleformUI )
  1156. {
  1157. m_pScaleformUI->UnlockSlot( m_iFlashSlot );
  1158. }
  1159. }
  1160. void SafeReleaseSFVALUE( SFVALUE& value )
  1161. {
  1162. AssertMsg( m_pScaleformUI, "Called SafeReleaseSFVALUE with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1163. if ( m_pScaleformUI && value )
  1164. {
  1165. m_pScaleformUI->ReleaseValue( value );
  1166. value = NULL;
  1167. }
  1168. }
  1169. void SafeReleaseSFTextObject( ISFTextObject*& value )
  1170. {
  1171. if ( value )
  1172. {
  1173. WITH_SLOT_LOCKED
  1174. {
  1175. value->Release();
  1176. }
  1177. value = NULL;
  1178. }
  1179. }
  1180. void SendUIEvent( const char* action, const char* eventData )
  1181. {
  1182. AssertMsg( m_pScaleformUI, "Called SendUIEvent with NULL m_pScaleformUI pointer (probably from PostUnloadFlash" );
  1183. if ( m_pScaleformUI )
  1184. m_pScaleformUI->SendUIEvent( action, eventData, m_iFlashSlot );
  1185. }
  1186. };
  1187. class ScaleformEmptyClass{};
  1188. typedef ScaleformFlashInterfaceMixin<ScaleformEmptyClass> ScaleformFlashInterface;
  1189. #endif