guiParticleGraphCtrl.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIPARTICLEGRAPHCTRL_H_
  23. #define _GUIPARTICLEGRAPHCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. #ifndef _STRINGTABLE_H_
  28. #include "core/stringTable.h"
  29. #endif
  30. class GuiParticleGraphCtrl : public GuiControl
  31. {
  32. private:
  33. typedef GuiControl Parent;
  34. protected:
  35. /// The color of the nuts.
  36. ColorI mNutColor;
  37. /// The outline color of the nuts.
  38. ColorI mOutlineColor;
  39. /// The rectangle size to check for clicks on nuts (default 8) which is RectI( pointClick - 4, pointClick - 4, 8, 8 )
  40. S32 mVertexClickSize;
  41. Point2I findHitNut( Point2I hitPoint );
  42. public:
  43. enum Constants {
  44. MaxPlots = 32,
  45. MaxDataPoints = 200
  46. };
  47. enum GraphType {
  48. Point,
  49. Polyline,
  50. Filled,
  51. Bar
  52. };
  53. struct PlotInfo
  54. {
  55. LinearColorF mGraphColor;
  56. Vector<Point2F> mGraphData;
  57. Vector<Point2F> mNutList;
  58. Point2F mGraphMax;
  59. Point2F mGraphMin;
  60. GraphType mGraphType;
  61. StringTableEntry mGraphName;
  62. bool mHidden;
  63. F32 mGraphScale;
  64. };
  65. S32 mSelectedPlot;
  66. S32 mSelectedPoint;
  67. S32 mOriginalSelectedPoint;
  68. S32 mLastSelectedPoint;
  69. S32 mTooltipSelectedPlot;
  70. S32 mAddedPointIndex;
  71. bool mAutoMax;
  72. bool mAutoRemove;
  73. bool mRenderAllPoints;
  74. bool mPointWasAdded;
  75. bool mRenderGraphTooltip;
  76. bool mRenderNextGraphTooltip;
  77. bool mPointXMovementClamped;
  78. Point2F mAddedPoint;
  79. Point2F mLastMousePos;
  80. Point2I mCursorPos;
  81. PlotInfo mPlots[MaxPlots];
  82. //creation methods
  83. DECLARE_CONOBJECT(GuiParticleGraphCtrl);
  84. DECLARE_CATEGORY( "Gui Editor" );
  85. GuiParticleGraphCtrl();
  86. virtual ~GuiParticleGraphCtrl() { };
  87. void onMouseMove(const GuiEvent &event);
  88. void onMouseDown( const GuiEvent &event );
  89. void onMouseUp( const GuiEvent &event );
  90. void onMouseDragged( const GuiEvent &event );
  91. void onRightMouseDown( const GuiEvent &event );
  92. void onRightMouseUp( const GuiEvent &event );
  93. void onRightMouseDragged( const GuiEvent &event );
  94. //Parental methods
  95. bool onWake();
  96. void onRender(Point2I offset, const RectI &updateRect);
  97. bool renderGraphTooltip(Point2I cursorPos, StringTableEntry tooltip);
  98. // Graph interface
  99. S32 addPlotPoint(S32 plotID, Point2F v, bool setAdded = true);
  100. void insertPlotPoint(S32 plotID, S32 i, Point2F v);
  101. S32 changePlotPoint(S32 plotID, S32 i, Point2F v);
  102. S32 removePlotPoint(S32 plotID, S32 i);
  103. Point2F convertToGraphCoord(S32 plotID, Point2I v);
  104. // Set Graph specific functions
  105. void setGraphType(S32 plotID, const char *graphType);
  106. void setSelectedPlot(S32 plotID);
  107. void setSelectedPoint(S32 point);
  108. void resetSelectedPoint();
  109. void setGraphHidden(S32 plotID, bool isHidden);
  110. // Set Global Options
  111. void setAutoGraphMax(bool autoMax);
  112. void setAutoRemove(bool autoRemove);
  113. void setRenderAll(bool renderAll);
  114. void setRenderGraphTooltip(bool renderGraphTooltip);
  115. void setPointXMovementClamped(bool clamped);
  116. // Get Functions
  117. Point2F getGraphExtent(S32 plotID);
  118. LinearColorF getGraphColor(S32 plotID);
  119. S32 getSelectedPlot();
  120. S32 getSelectedPoint();
  121. Point2F getPlotPoint(S32 plotID, S32 samples);
  122. S32 getPlotIndex(S32 plotID, F32 x, F32 y);
  123. Point2F getGraphMax(S32 plotID);
  124. Point2F getGraphMin(S32 plotID);
  125. bool isExistingPoint(S32 plotID, S32 point);
  126. StringTableEntry getGraphName(S32 plotID);
  127. // Set Graph Min and MaxFunctions
  128. void setGraphMin(S32 plotID, Point2F graphMin);
  129. void setGraphMinX(S32 plotID, F32 graphMinX);
  130. void setGraphMinY(S32 plotID, F32 graphMinY);
  131. void setGraphMax(S32 plotID, Point2F graphMax);
  132. void setGraphMaxX(S32 plotID, F32 graphMaxX);
  133. void setGraphMaxY(S32 plotID, F32 graphMaxY);
  134. // Other set functions for graphs
  135. void setGraphName(S32 plotID, StringTableEntry graphName);
  136. // Clear Functions
  137. void clearGraph(S32 plotID);
  138. void clearAllGraphs();
  139. // Selection nuts.
  140. bool inNut( const Point2I &pt, S32 x, S32 y );
  141. void drawNut( const Point2I &nut, S32 size, ColorI &outlineColor, ColorI &nutColor );
  142. };
  143. typedef GuiParticleGraphCtrl::GraphType GuiParticleGraphType;
  144. DefineEnumType( GuiParticleGraphType );
  145. #endif