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.

234 lines
6.2 KiB

  1. //===== Copyright � 2005-2006, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: build a sheet data file and a large image out of multiple images
  4. //
  5. //===========================================================================//
  6. #include "materialobjects/dmedemo2.h"
  7. #include "tier1/strtools.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. #include "tier0/dbg.h"
  10. //-----------------------------------------------------------------------------
  11. // Dme version of a quad
  12. //-----------------------------------------------------------------------------
  13. IMPLEMENT_ELEMENT_FACTORY( DmeQuadV2, CDmeQuadV2 );
  14. void CDmeQuadV2::OnConstruction()
  15. {
  16. m_X0.Init( this, "x0" );
  17. m_Y0.Init( this, "y0" );
  18. m_X1.Init( this, "x1" );
  19. m_Y1.Init( this, "y1" );
  20. m_Color.InitAndSet( this, "color", Color( 255, 255, 255, 255 ) );
  21. }
  22. void CDmeQuadV2::OnDestruction()
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Dme version of a list of quads
  27. //-----------------------------------------------------------------------------
  28. IMPLEMENT_ELEMENT_FACTORY( DmeQuadListV2, CDmeQuadListV2 );
  29. void CDmeQuadListV2::OnConstruction()
  30. {
  31. m_Quads.Init( this, "quads" );
  32. }
  33. void CDmeQuadListV2::OnDestruction()
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // List management
  38. //-----------------------------------------------------------------------------
  39. void CDmeQuadListV2::AddQuad( CDmeQuadV2 *pQuad )
  40. {
  41. m_Quads.InsertBefore( 0, pQuad );
  42. }
  43. CDmeQuadV2 *CDmeQuadListV2::FindQuadByName( const char *pName )
  44. {
  45. for ( int i = 0; i < m_Quads.Count(); ++i )
  46. {
  47. if ( !Q_stricmp( pName, m_Quads[i]->GetName() ) )
  48. return m_Quads[i];
  49. }
  50. return NULL;
  51. }
  52. void CDmeQuadListV2::RemoveQuad( CDmeQuadV2 *pQuad )
  53. {
  54. int nIndex = m_Quads.Find( pQuad );
  55. if ( nIndex != m_Quads.InvalidIndex() )
  56. {
  57. m_Quads.Remove( nIndex );
  58. }
  59. }
  60. void CDmeQuadListV2::RemoveAllQuads()
  61. {
  62. m_Quads.RemoveAll();
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Render order management
  66. //-----------------------------------------------------------------------------
  67. void CDmeQuadListV2::MoveToFront( CDmeQuadV2 *pQuad )
  68. {
  69. int nIndex = m_Quads.Find( pQuad );
  70. if ( nIndex != m_Quads.InvalidIndex() )
  71. {
  72. m_Quads.Remove( nIndex );
  73. m_Quads.AddToTail( pQuad );
  74. }
  75. }
  76. void CDmeQuadListV2::MoveToBack( CDmeQuadV2 *pQuad )
  77. {
  78. int nIndex = m_Quads.Find( pQuad );
  79. if ( nIndex != m_Quads.InvalidIndex() )
  80. {
  81. m_Quads.Remove( nIndex );
  82. m_Quads.InsertBefore( 0, pQuad );
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Dme version of a the editor 'document'
  87. //-----------------------------------------------------------------------------
  88. IMPLEMENT_ELEMENT_FACTORY( DmeQuadDocV2, CDmeQuadDocV2 );
  89. void CDmeQuadDocV2::OnConstruction()
  90. {
  91. m_Quads.InitAndCreate( this, "quadList" );
  92. m_SelectedQuads.Init( this, "selectedQuads", FATTRIB_DONTSAVE );
  93. }
  94. void CDmeQuadDocV2::OnDestruction()
  95. {
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Adds quad, resets selection to new quad
  99. //-----------------------------------------------------------------------------
  100. void CDmeQuadDocV2::AddQuad( const char *pName, int x0, int y0, int x1, int y1 )
  101. {
  102. CDmeQuadV2 *pQuadV2 = CreateElement< CDmeQuadV2 >( pName, GetFileId() );
  103. pQuadV2->m_X0 = x0;
  104. pQuadV2->m_X1 = x1;
  105. pQuadV2->m_Y0 = y0;
  106. pQuadV2->m_Y1 = y1;
  107. m_Quads->AddQuad( pQuadV2 );
  108. ClearSelection();
  109. AddQuadToSelection( pName );
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Clears selection
  113. //-----------------------------------------------------------------------------
  114. void CDmeQuadDocV2::ClearSelection()
  115. {
  116. m_SelectedQuads.RemoveAll();
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Adds quad to selection
  120. //-----------------------------------------------------------------------------
  121. void CDmeQuadDocV2::AddQuadToSelection( const char *pName )
  122. {
  123. CDmeQuadV2 *pQuad = m_Quads->FindQuadByName( pName );
  124. if ( pQuad )
  125. {
  126. m_SelectedQuads.AddToTail( pQuad );
  127. }
  128. }
  129. //-----------------------------------------------------------------------------
  130. // Deletes selected quads
  131. //-----------------------------------------------------------------------------
  132. void CDmeQuadDocV2::DeleteSelectedQuads()
  133. {
  134. int nCount = m_SelectedQuads.Count();
  135. for ( int i = 0; i < nCount; ++i )
  136. {
  137. DestroyElement( m_SelectedQuads[i] );
  138. }
  139. ClearSelection();
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Changes quad color
  143. //-----------------------------------------------------------------------------
  144. void CDmeQuadDocV2::SetSelectedQuadColor( int r, int g, int b, int a )
  145. {
  146. Color c( r, g, b, a );
  147. int nCount = m_SelectedQuads.Count();
  148. for ( int i = 0; i < nCount; ++i )
  149. {
  150. CDmeQuadV2 *pQuad = m_SelectedQuads[i];
  151. pQuad->m_Color.Set( c );
  152. }
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Moves quads
  156. //-----------------------------------------------------------------------------
  157. void CDmeQuadDocV2::MoveSelectedQuads( int dx, int dy )
  158. {
  159. int nCount = m_SelectedQuads.Count();
  160. for ( int i = 0; i < nCount; ++i )
  161. {
  162. CDmeQuadV2 *pQuad = m_SelectedQuads[i];
  163. pQuad->m_X0 += dx;
  164. pQuad->m_X1 += dx;
  165. pQuad->m_Y0 += dy;
  166. pQuad->m_Y1 += dy;
  167. }
  168. }
  169. //-----------------------------------------------------------------------------
  170. // Resizes selected quad (works only when 1 quad is selected)
  171. //-----------------------------------------------------------------------------
  172. void CDmeQuadDocV2::ResizeSelectedQuad( int nWidth, int nHeight )
  173. {
  174. if ( m_SelectedQuads.Count() != 1 )
  175. return;
  176. CDmeQuadV2 *pQuad = m_SelectedQuads[0];
  177. pQuad->m_X1 = pQuad->m_X0 + nWidth;
  178. pQuad->m_Y1 = pQuad->m_Y0 + nHeight;
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Moves selected quad to front/back (works only when 1 quad is selected)
  182. //-----------------------------------------------------------------------------
  183. void CDmeQuadDocV2::MoveSelectedToFront()
  184. {
  185. if ( m_SelectedQuads.Count() != 1 )
  186. return;
  187. m_Quads->MoveToFront( m_SelectedQuads[0] );
  188. }
  189. void CDmeQuadDocV2::MoveSelectedToBack()
  190. {
  191. if ( m_SelectedQuads.Count() != 1 )
  192. return;
  193. m_Quads->MoveToBack( m_SelectedQuads[0] );
  194. }