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.

174 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "tier1/fmtstr.h"
  9. // NOTE: This must be the last file included!!!
  10. #include "tier0/memdbgon.h"
  11. using namespace Scaleform::GFx;
  12. #define TEMP_BUFFER_LENGTH 1024
  13. class TextBoxArrayVisitor: public Value::ArrayVisitor
  14. {
  15. public:
  16. CUtlBlockVector<Value> *m_pTextBoxes;
  17. void Visit( unsigned int idx, const Value& val )
  18. {
  19. m_pTextBoxes->AddToTail( val );
  20. }
  21. };
  22. /**********************************************
  23. * Implementation of the text object. It accepts
  24. * an SFText object or a TextBox from flash
  25. * and keeps referenes to all the text boxes so
  26. * that they can be set directly without needing
  27. * to invoke the SetText function.
  28. */
  29. class SFTextObjectImpl: public ISFTextObject
  30. {
  31. protected:
  32. // Using a CUtlBlockVector to avoid realloc (memcpy of Scaleform::Value)
  33. // when the vector grow which would perform a shallow copy
  34. // (Need to use Scaleform::Value copy constructor performing a deep copy)
  35. CUtlBlockVector<Value> m_TextBoxes;
  36. public:
  37. SFTextObjectImpl()
  38. {
  39. }
  40. SFTextObjectImpl( Value &value )
  41. {
  42. Init( value );
  43. }
  44. bool Init( Value &value )
  45. {
  46. m_TextBoxes.RemoveAll();
  47. if ( value.GetType() != Value::VT_DisplayObject )
  48. {
  49. return false;
  50. }
  51. Value boxArray;
  52. if ( value.GetMember( "SFText_TextBoxList", &boxArray ) )
  53. {
  54. TextBoxArrayVisitor vis;
  55. vis.m_pTextBoxes = &m_TextBoxes;
  56. boxArray.VisitElements( &vis );
  57. }
  58. else
  59. {
  60. m_TextBoxes.AddToTail( value );
  61. }
  62. return true;
  63. }
  64. virtual void SetText( int value )
  65. {
  66. SetText( CFmtStr( "%d", value ) );
  67. }
  68. virtual void SetText( float value )
  69. {
  70. SetText( CFmtStr( "%0.f", value ) );
  71. }
  72. virtual void SetText( const char* pszText )
  73. {
  74. FOR_EACH_VEC( m_TextBoxes, i )
  75. {
  76. m_TextBoxes[i].SetText( pszText );
  77. }
  78. }
  79. virtual void SetTextHTML( const char* pszText )
  80. {
  81. FOR_EACH_VEC( m_TextBoxes, i )
  82. {
  83. m_TextBoxes[i].SetTextHTML( pszText );
  84. }
  85. }
  86. virtual void SetText( const wchar_t* pwszText )
  87. {
  88. FOR_EACH_VEC( m_TextBoxes, i )
  89. {
  90. m_TextBoxes[i].SetText( pwszText );
  91. }
  92. }
  93. virtual void SetTextHTML( const wchar_t* pwszText )
  94. {
  95. FOR_EACH_VEC( m_TextBoxes, i )
  96. {
  97. m_TextBoxes[i].SetTextHTML( pwszText );
  98. }
  99. }
  100. virtual void SetVisible( bool visible )
  101. {
  102. FOR_EACH_VEC( m_TextBoxes, i )
  103. {
  104. SFINST.SetVisible( ToSFVALUE( &m_TextBoxes[i] ), visible);
  105. }
  106. }
  107. virtual bool IsValid( void )
  108. {
  109. return m_TextBoxes.Count() > 0;
  110. }
  111. virtual void Release( void )
  112. {
  113. delete this;
  114. }
  115. };
  116. /************************************************
  117. * methods in IScalformUI for creating these objects
  118. */
  119. ISFTextObject* ScaleformUIImpl::TextObject_MakeTextObject( SFVALUE value )
  120. {
  121. SFTextObjectImpl* pResult = new SFTextObjectImpl( *FromSFVALUE( value ) );
  122. if ( !pResult->IsValid() )
  123. {
  124. pResult->Release();
  125. pResult = NULL;
  126. }
  127. return pResult;
  128. }
  129. ISFTextObject* ScaleformUIImpl::TextObject_MakeTextObjectFromMember( SFVALUE value, const char * pName )
  130. {
  131. Value* pValue = FromSFVALUE( value );
  132. Value member;
  133. if ( pValue->GetMember( pName, &member ) )
  134. {
  135. return TextObject_MakeTextObject( ToSFVALUE( &member ) );
  136. }
  137. else
  138. {
  139. return NULL;
  140. }
  141. }