guiParticleGraphInspector.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. GuiParticleGraphInspector* mVariationInspector;
  41. public:
  42. struct GraphPoint
  43. {
  44. GraphPoint() {}
  45. GraphPoint(Point2I p, F32 time, F32 value, U32 index) { mTime = time; mValue = value; mPoint = p; mIndex = index; }
  46. F32 mTime;
  47. F32 mValue;
  48. Point2I mPoint;
  49. U32 mIndex;
  50. };
  51. S32 mSelectedIndex;
  52. bool mDirty;
  53. Vector<GraphPoint> mPointList;
  54. //creation methods
  55. DECLARE_CONOBJECT(GuiParticleGraphInspector);
  56. GuiParticleGraphInspector();
  57. static void initPersistFields();
  58. virtual void inspectObject(ParticleAsset* object);
  59. virtual void setDisplayField(const char* fieldName);
  60. virtual void setDisplayField(const char* fieldName, U16 index);
  61. virtual void setDisplayArea(StringTableEntry minX, StringTableEntry minY, StringTableEntry maxX, StringTableEntry maxY);
  62. virtual void setDisplayLabels(const char* labelX, const char* labelY);
  63. virtual void setVariationGraphInspector(GuiParticleGraphInspector* object) { mVariationInspector = object; }
  64. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  65. virtual void setControlProfile(GuiControlProfile *prof);
  66. virtual void onTouchUp(const GuiEvent &event);
  67. virtual void onTouchDown(const GuiEvent &event);
  68. virtual void onTouchDragged(const GuiEvent &event);
  69. void onRender(Point2I offset, const RectI &updateRect);
  70. Vector<GraphPoint>* getRenderPoints();
  71. protected:
  72. U32 findHitGraphPoint(const Point2I &point);
  73. F32 getGraphValue(const F32 y);
  74. F32 getGraphTime(const F32 x);
  75. void calculatePoints(const RectI &contentRect);
  76. Point2I convertToRenderPoint(const RectI& contentRect, F32 time, F32 value);
  77. void renderLabels(const RectI &contentRect, const ColorI &labelColor);
  78. void renderGrid(const RectI &contentRect, const ColorI &gridColor);
  79. void renderPoints(const RectI &contentRect, const ColorI &lineColor);
  80. void renderVariation(const RectI &contentRect, const ColorI& color);
  81. void renderDot(const RectI &contentRect, const Point2I &point, const Point2I &cursorPt, bool isSelected);
  82. void renderLine(const RectI &contentRect, const Point2I &point1, const Point2I &point2, const ColorI &lineColor);
  83. void renderQuad(const RectI& contentRect, const Point2I& point1, const Point2I& point2, const Point2I& point3, const Point2I& point4, const ColorI& quadColor);
  84. ParticleAssetField* getTargetField();
  85. };
  86. #endif