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.

162 lines
5.0 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMEDEMO3_H
  7. #define DMEDEMO3_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "datamodel/dmattributevar.h"
  13. //-----------------------------------------------------------------------------
  14. // Demo 3: Creating an in-game editor for the editable versions
  15. //-----------------------------------------------------------------------------
  16. //-----------------------------------------------------------------------------
  17. // No changes here from demo 2
  18. //-----------------------------------------------------------------------------
  19. class CDmeQuadV3 : public CDmElement
  20. {
  21. DEFINE_ELEMENT( CDmeQuadV3, CDmElement );
  22. // NEW METHODS IN VERSION 3, needed by renderer
  23. public:
  24. int MinX() const { return MIN( m_X0, m_X1 ); }
  25. int MinY() const { return MIN( m_Y0, m_Y1 ); }
  26. int MaxX() const { return MAX( m_X0, m_X1 ); }
  27. int MaxY() const { return MAX( m_Y0, m_Y1 ); }
  28. // OLD METHODS FROM VERSION 3
  29. public:
  30. CDmaVar< int > m_X0;
  31. CDmaVar< int > m_Y0;
  32. CDmaVar< int > m_X1;
  33. CDmaVar< int > m_Y1;
  34. CDmaColor m_Color;
  35. };
  36. //-----------------------------------------------------------------------------
  37. // No changes here from demo 2
  38. //-----------------------------------------------------------------------------
  39. class CDmeQuadListV3 : public CDmElement
  40. {
  41. DEFINE_ELEMENT( CDmeQuadListV3, CDmElement );
  42. // NEW STUFF FOR DEMO 3
  43. public:
  44. // Iteration necessary to render
  45. int GetQuadCount() const;
  46. CDmeQuadV3 *GetQuad( int i );
  47. // OLD STUFF FROM DEMO 2
  48. public:
  49. // List management
  50. void AddQuad( CDmeQuadV3 *pQuad );
  51. CDmeQuadV3 *FindQuadByName( const char *pName );
  52. void RemoveQuad( CDmeQuadV3 *pQuad );
  53. void RemoveAllQuads();
  54. // Render order management
  55. void MoveToFront( CDmeQuadV3 *pQuad );
  56. void MoveToBack( CDmeQuadV3 *pQuad );
  57. private:
  58. CDmaElementArray< CDmeQuadV3 > m_Quads;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // Dme version of a the editor 'document'
  62. //
  63. // The interface here is designed to be able to be used directly from
  64. // python. I'm currently hiding direct access to CDmeQuadV3 to here to
  65. // make python usage easier, but python can handle it if we pass CDmeQuadV3s
  66. // in the interface. We may well want to start passing them around once
  67. // we get to the VGUI-based editor.
  68. //
  69. // Early editors we wrote didn't clearly separate data from UI at the doc
  70. // level which resulted in a bunch of complexity as our tools got bigger.
  71. // Actually making a Dm element which contains a notion of selection in it
  72. // I believe will reduce this problem in the future (this is still an untested
  73. // theory in-house, although other 3rd party editors use this technique also).
  74. //
  75. // Remember that only attributes can be saved and have undo support.
  76. // If you want to add members to a Dme element which are not saved and
  77. // never need undo, you can either use normal non-CDma members,
  78. // or mark attributes to not be saved. In this case, I make the
  79. // selection state be an attribute to get undo but mark the selection
  80. // attribute to not save it to the file.
  81. //-----------------------------------------------------------------------------
  82. class CDmeQuadDocV3 : public CDmElement
  83. {
  84. DEFINE_ELEMENT( CDmeQuadDocV3, CDmElement );
  85. // NEW STUFF FOR DEMO 3
  86. public:
  87. // Iteration necessary to render
  88. int GetQuadCount() const;
  89. CDmeQuadV3 *GetQuad( int i );
  90. // Iteration necessary to render
  91. int GetSelectedQuadCount() const;
  92. CDmeQuadV3 *GetSelectedQuad( int i );
  93. // Add quads in rect to selection
  94. void AddQuadsInRectToSelection( int x0, int y0, int x1, int y1 );
  95. // Is point in selected quad?
  96. bool IsPointInSelectedQuad( int x, int y ) const;
  97. // OLD STUFF FROM DEMO 2
  98. public:
  99. // Adds quad, resets selection to new quad
  100. void AddQuad( const char *pName, int x0, int y0, int x1, int y1 );
  101. // Clears selection
  102. void ClearSelection();
  103. // Adds quad to selection
  104. void AddQuadToSelection( const char *pName );
  105. // Deletes selected quads
  106. void DeleteSelectedQuads();
  107. // Changes quad color
  108. void SetSelectedQuadColor( int r, int g, int b, int a );
  109. // Moves quads
  110. void MoveSelectedQuads( int dx, int dy );
  111. // Resizes selected quad (works only when 1 quad is selected)
  112. void ResizeSelectedQuad( int nWidth, int nHeight );
  113. // Moves selected quad to front/back (works only when 1 quad is selected)
  114. void MoveSelectedToFront();
  115. void MoveSelectedToBack();
  116. private:
  117. CDmaElement< CDmeQuadListV3 > m_QuadList;
  118. CDmaElementArray< CDmeQuadV3 > m_SelectedQuads;
  119. };
  120. //-----------------------------------------------------------------------------
  121. // Usage in python (works from the debugger!)
  122. //-----------------------------------------------------------------------------
  123. // 1) Python at commandline
  124. // 2) import vs
  125. // 3) vs.dm.SetUndoEnabled( 0 )
  126. // 4) doc = vs.CreateElement( �DmeQuadDocV3�, �root�, -1 )
  127. // 5) � doc stuff, e.g. doc.AddQuad( 'quad1', 5, 5, 30, 40 )
  128. // 6) vs.dm.SaveToFile( �file name�, ��, �keyvalues2�, �dmx�, doc )
  129. #endif // DMEDEMO3_H