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.

215 lines
7.0 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. // NOTE: This must be the last file included!!!
  9. #include "tier0/memdbgon.h"
  10. using namespace Scaleform::GFx;
  11. // Uncomment this to check you are not trying to access an invalid params and the
  12. // type is correct
  13. // Comment in pc-beta
  14. //#define SF_CHECK_PARAMS_VALID
  15. #if defined( SF_CHECK_PARAMS_VALID )
  16. #define SF_PARAMS_ASSERT( _exp, _msg ) AssertMsgAlways( _exp, _msg )
  17. #else
  18. #define SF_PARAMS_ASSERT( _exp, _msg ) ((void)0)
  19. #endif
  20. SFVALUEARRAY ScaleformUIImpl::Params_GetArgs( SFPARAMS sfparams )
  21. {
  22. FunctionHandler::Params* pParams = FromSFPARAMS(sfparams);
  23. return SFVALUEARRAY( pParams->ArgCount, ToSFVALUE( pParams->pArgs ) );
  24. }
  25. unsigned int ScaleformUIImpl::Params_GetNumArgs( SFPARAMS params )
  26. {
  27. return FromSFPARAMS(params)->ArgCount;
  28. }
  29. SFVALUE ScaleformUIImpl::Params_GetArg( SFPARAMS params, int index )
  30. {
  31. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  32. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  33. return ToSFVALUE( &( pParams->pArgs[index] ) );
  34. }
  35. IScaleformUI::_ValueType ScaleformUIImpl::Params_GetArgType( SFPARAMS params, int index )
  36. {
  37. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  38. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  39. return ((uint)index < pParams->ArgCount) ? ValueType_SDK_to_SFUI( pParams->pArgs[index].GetType() ) : IScaleformUI::VT_Undefined;
  40. }
  41. bool ScaleformUIImpl::Params_ArgIs( SFPARAMS params, unsigned int index, IScaleformUI::_ValueType v )
  42. {
  43. if ( index < ( FromSFPARAMS(params) )->ArgCount )
  44. {
  45. return ( ValueType_SDK_to_SFUI( FromSFPARAMS(params)->pArgs[index].GetType() ) == v );
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. double ScaleformUIImpl::Params_GetArgAsNumber( SFPARAMS params, int index )
  53. {
  54. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  55. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  56. SF_PARAMS_ASSERT( pParams->pArgs[index].IsNumber(), "SF param is not a number!" );
  57. return ( double ) pParams->pArgs[index].GetNumber();
  58. }
  59. bool ScaleformUIImpl::Params_GetArgAsBool( SFPARAMS params, int index )
  60. {
  61. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  62. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  63. SF_PARAMS_ASSERT( pParams->pArgs[index].IsBool(), "SF param is not a boolean!" );
  64. return pParams->pArgs[index].GetBool();
  65. }
  66. const char* ScaleformUIImpl::Params_GetArgAsString( SFPARAMS params, int index )
  67. {
  68. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  69. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  70. SF_PARAMS_ASSERT( pParams->pArgs[index].IsString(), "SF param is not a string!" );
  71. return pParams->pArgs[index].GetString();
  72. }
  73. const wchar_t* ScaleformUIImpl::Params_GetArgAsStringW( SFPARAMS params, int index )
  74. {
  75. FunctionHandler::Params* pParams = FromSFPARAMS(params);
  76. SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
  77. SF_PARAMS_ASSERT( pParams->pArgs[index].IsStringW(), "SF param is not a StringW!" );
  78. return pParams->pArgs[index].GetStringW();
  79. }
  80. const char* Helper_SFTypeToCString( Value::ValueType type )
  81. {
  82. switch ( type )
  83. {
  84. case Value::VT_Undefined: return "undefined";
  85. case Value::VT_Null: return "null";
  86. case Value::VT_Boolean: return "boolean";
  87. case Value::VT_Int: return "int";
  88. case Value::VT_UInt: return "uint";
  89. case Value::VT_Number: return "number";
  90. case Value::VT_String: return "string";
  91. case Value::VT_StringW: return "stringw";
  92. case Value::VT_Object: return "object";
  93. case Value::VT_Array: return "array";
  94. case Value::VT_DisplayObject: return "displayobject";
  95. case Value::VT_Closure: return "closure";
  96. case Value::VT_ConvertBoolean: return "convertboolean";
  97. case Value::VT_ConvertInt: return "convertint";
  98. case Value::VT_ConvertUInt: return "convertuint";
  99. case Value::VT_ConvertNumber: return "convertnumber";
  100. case Value::VT_ConvertString: return "convertstring";
  101. case Value::VT_ConvertStringW: return "convertstringw";
  102. default:
  103. AssertMsg( 0, "Unknown ValueType\n" );
  104. return "undefined";
  105. }
  106. }
  107. void ScaleformUIImpl::Params_DebugSpew( SFPARAMS params )
  108. {
  109. FunctionHandler::Params* pParams = FromSFPARAMS( params );
  110. for ( unsigned i = 0; i < pParams->ArgCount; ++i )
  111. {
  112. Msg( "Param %d: %s (%s) \n", i, pParams->pArgs[ i ].ToString().ToCStr(), Helper_SFTypeToCString( pParams->pArgs[ i ].GetType() ) );
  113. }
  114. }
  115. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, SFVALUE value )
  116. {
  117. *FromSFPARAMS( params )->pRetVal = *FromSFVALUE( value );
  118. }
  119. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, int value )
  120. {
  121. FromSFPARAMS(params)->pRetVal->SetNumber( ( SF::Double ) value );
  122. }
  123. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, float value )
  124. {
  125. FromSFPARAMS(params)->pRetVal->SetNumber( ( SF::Double ) value );
  126. }
  127. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, bool value )
  128. {
  129. FromSFPARAMS(params)->pRetVal->SetBoolean( value );
  130. }
  131. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, const char* value, bool bMakeNewValue /* = true */ )
  132. {
  133. char dummy_value;
  134. const char* stack_addr = &dummy_value;
  135. const intp diff = value - stack_addr;
  136. if ( ( diff > -128*1024 && diff < 128*1024 ) || bMakeNewValue )
  137. {
  138. // This string looks like it is on the stack. Make a Scaleform-managed string
  139. // to duplicate it into.
  140. SFVALUE managed_value = Params_CreateNewString( params, value );
  141. Params_SetResult( params, managed_value );
  142. ReleaseValue( managed_value );
  143. }
  144. else
  145. {
  146. ( reinterpret_cast<FunctionHandler::Params*>(params)->pRetVal )->SetString( value );
  147. }
  148. }
  149. void ScaleformUIImpl::Params_SetResult( SFPARAMS params, const wchar_t* value, bool bMakeNewValue /* = true */ )
  150. {
  151. wchar_t dummy_value;
  152. const wchar_t* stack_addr = &dummy_value;
  153. const intp diff = value - stack_addr;
  154. if ( ( diff > -128*1024 && diff < 128*1024 ) || bMakeNewValue )
  155. {
  156. // This string looks like it is on the stack. Make a Scaleform-managed string
  157. // to duplicate it into.
  158. SFVALUE managed_value = Params_CreateNewString( params, value );
  159. Params_SetResult( params, managed_value );
  160. ReleaseValue( managed_value );
  161. }
  162. else
  163. {
  164. ( ( ( FunctionHandler::Params* ) params )->pRetVal )->SetStringW( value );
  165. }
  166. }
  167. SFVALUE ScaleformUIImpl::Params_CreateNewObject( SFPARAMS params )
  168. {
  169. return MovieView_CreateObject( ToSFMOVIE( FromSFPARAMS(params)->pMovie ) );
  170. }
  171. SFVALUE ScaleformUIImpl::Params_CreateNewArray( SFPARAMS params, int size )
  172. {
  173. return MovieView_CreateArray( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), size );
  174. }
  175. SFVALUE ScaleformUIImpl::Params_CreateNewString( SFPARAMS params, const char* value )
  176. {
  177. return MovieView_CreateString( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), value );
  178. }
  179. SFVALUE ScaleformUIImpl::Params_CreateNewString( SFPARAMS params, const wchar_t* value )
  180. {
  181. return MovieView_CreateStringW( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), value );
  182. }