guiParticleGraphInspector.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _GUIPARTICLEGRAPHINSPECTOR_H_
  23. #define _GUIPARTICLEGRAPHINSPECTOR_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/guiControl.h"
  26. #endif
  27. class GuiParticleGraphInspector : public GuiControl
  28. {
  29. private:
  30. typedef GuiControl Parent;
  31. StringTableEntry mTargetField;
  32. ParticleAsset* mTargetAsset;
  33. U32 mEmitterIndex;
  34. F32 mMinX, mMinY, mMaxX, mMaxY; //Display settings
  35. StringTableEntry mLabelX, mLabelY;
  36. StringTableEntry mMaxYLabel, mMinYLabel, mMaxXLabel, mMinXLabel;
  37. const F32 mRadius = 7; //size of a point
  38. RectI mGridRect;
  39. Point2I mCalculationOffset;
  40. public:
  41. struct GraphPoint
  42. {
  43. GraphPoint() {}
  44. GraphPoint(Point2I p, F32 time, F32 value, U32 index) { mTime = time; mValue = value; mPoint = p; mIndex = index; }
  45. F32 mTime;
  46. F32 mValue;
  47. Point2I mPoint;
  48. U32 mIndex;
  49. };
  50. S32 mSelectedIndex;
  51. bool mDirty;
  52. Vector<GraphPoint> mPointList;
  53. //creation methods
  54. DECLARE_CONOBJECT(GuiParticleGraphInspector);
  55. GuiParticleGraphInspector();
  56. static void initPersistFields();
  57. virtual void inspectObject(ParticleAsset* object);
  58. virtual void setDisplayField(const char* fieldName);
  59. virtual void setDisplayField(const char* fieldName, U16 index);
  60. virtual void setDisplayArea(StringTableEntry minX, StringTableEntry minY, StringTableEntry maxX, StringTableEntry maxY);
  61. virtual void setDisplayLabels(const char* labelX, const char* labelY);
  62. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  63. virtual void setControlProfile(GuiControlProfile *prof);
  64. virtual void onTouchUp(const GuiEvent &event);
  65. virtual void onTouchDown(const GuiEvent &event);
  66. virtual void onTouchDragged(const GuiEvent &event);
  67. void onRender(Point2I offset, const RectI &updateRect);
  68. protected:
  69. U32 findHitGraphPoint(const Point2I &point);
  70. F32 getGraphValue(const F32 y);
  71. F32 getGraphTime(const F32 x);
  72. void calculatePoints(const RectI &contentRect);
  73. void renderLabels(const RectI &contentRect, const ColorI &labelColor);
  74. void renderGrid(const RectI &contentRect, const ColorI &gridColor);
  75. void renderPoints(const RectI &contentRect, const ColorI &lineColor);
  76. void renderDot(const RectI &contentRect, const Point2I &point, const Point2I &cursorPt, bool isSelected);
  77. void renderLine(const RectI &contentRect, const Point2I &point1, const Point2I &point2, const ColorI &lineColor);
  78. ParticleAssetField* getTargetField();
  79. };
  80. #endif