forestBrushTool.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 _FOREST_EDITOR_BRUSH_H_
  23. #define _FOREST_EDITOR_BRUSH_H_
  24. #ifndef _FOREST_EDITOR_TOOL_H_
  25. #include "forest/editor/forestTool.h"
  26. #endif
  27. #ifndef _FORESTITEM_H_
  28. #include "forest/forestItem.h"
  29. #endif
  30. #ifndef _FOREST_EDITOR_BRUSHELEMENT_H_
  31. #include "forest/editor/forestBrushElement.h"
  32. #endif
  33. #ifndef _COLOR_H_
  34. #include "core/color.h"
  35. #endif
  36. class Forest;
  37. class ForestUndoAction;
  38. class ForestBrushTool : public ForestTool
  39. {
  40. typedef ForestTool Parent;
  41. friend class ForestBrushToolEvent;
  42. public:
  43. enum BrushMode
  44. {
  45. Paint = 0,
  46. Erase,
  47. EraseSelected
  48. };
  49. ForestBrushTool();
  50. virtual ~ForestBrushTool();
  51. // SimObject
  52. DECLARE_CONOBJECT( ForestBrushTool );
  53. static void initPersistFields();
  54. virtual bool onAdd();
  55. virtual void onRemove();
  56. // ForestTool
  57. virtual void on3DMouseDown( const Gui3DMouseEvent &evt );
  58. virtual void on3DMouseUp( const Gui3DMouseEvent &evt );
  59. virtual void on3DMouseMove( const Gui3DMouseEvent &evt );
  60. virtual void on3DMouseDragged( const Gui3DMouseEvent &evt );
  61. virtual bool onMouseWheel(const GuiEvent &evt );
  62. virtual void onRender3D();
  63. virtual void onRender2D();
  64. virtual void onActivated( const Gui3DMouseEvent &lastEvent );
  65. virtual void onDeactivated();
  66. virtual bool updateGuiInfo();
  67. // ForestBrushTool
  68. void setSize( F32 val );
  69. void setPressure( F32 val );
  70. void setHardness( F32 val );
  71. void collectElements() { _collectElements(); }
  72. bool getGroundAt( const Point3F &worldPt, F32 *zValueOut, VectorF *normalOut );
  73. protected:
  74. void _onStroke();
  75. virtual void _action( const Point3F &point );
  76. virtual void _paint( const Point3F &point );
  77. virtual void _erase( const Point3F &point );
  78. bool _updateBrushPoint( const Gui3DMouseEvent &event_ );
  79. virtual void _collectElements();
  80. static bool protectedSetSize( void *object, const char *index, const char *data );
  81. static bool protectedSetPressure( void *object, const char *index, const char *data );
  82. static bool protectedSetHardness( void *object, const char *index, const char *data );
  83. protected:
  84. MRandom mRandom;
  85. /// We treat this as a radius.
  86. F32 mSize;
  87. F32 mPressure;
  88. F32 mHardness;
  89. U32 mMode;
  90. ColorI mColor;
  91. Vector<ForestBrushElement*> mElements;
  92. Vector<ForestItemData*> mDatablocks;
  93. ///
  94. bool mBrushDown;
  95. ///
  96. bool mDrawBrush;
  97. ///
  98. U32 mStrokeEvent;
  99. ///
  100. Point3F mLastBrushPoint;
  101. Point3F mLastBrushNormal;
  102. /// The creation action we're actively filling.
  103. ForestUndoAction *mCurrAction;
  104. };
  105. typedef ForestBrushTool::BrushMode ForestBrushMode;
  106. DefineEnumType( ForestBrushMode );
  107. class ForestBrushToolEvent : public SimEvent
  108. {
  109. public:
  110. void process( SimObject *object )
  111. {
  112. ((ForestBrushTool*)object)->_onStroke();
  113. }
  114. };
  115. #endif // _FOREST_EDITOR_BRUSH_H_