guiShaderEditor.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 _GUISHADEREDITOR_H_
  23. #define _GUISHADEREDITOR_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. #ifndef _UNDO_H_
  28. #include "util/undo.h"
  29. #endif
  30. #ifndef _GFX_GFXDRAWER_H_
  31. #include "gfx/gfxDrawUtil.h"
  32. #endif
  33. #ifndef _SHADERNODE_H_
  34. #include "gui/shaderEditor/nodes/shaderNode.h"
  35. #endif // !_SHADERNODE_H_
  36. class GuiShaderEditor : public GuiControl
  37. {
  38. public:
  39. typedef GuiControl Parent;
  40. enum mouseModes { Selecting, MovingSelection, DragPanning, DragConnection, DragSelecting, DragClone };
  41. protected:
  42. // list
  43. typedef Vector<ShaderNode*> ShaderNodeVector;
  44. // all nodes in this graph.
  45. ShaderNodeVector mCurrNodes;
  46. // Undo
  47. SimGroup* mTrash;
  48. // view controls
  49. Point2I mViewOffset;
  50. F32 mZoomScale;
  51. // mouse interaction
  52. mouseModes mMouseDownMode;
  53. Point2I mLastMousePos;
  54. Point2I mLastDragPos;
  55. Point2I mSelectionAnchor;
  56. Point2I mDragBeginPoint;
  57. Vector<Point2I> mDragBeginPoints;
  58. bool mDragAddSelection;
  59. bool mDragMoveUndo;
  60. bool mFullBoxSelection;
  61. ShaderNodeVector mSelectedNodes;
  62. void renderNodes(Point2I offset, const RectI& updateRect);
  63. // functions for handling mouse events.
  64. ShaderNode* findHitNode(const Point2I& pt);
  65. void findNodesInRect(const RectI& rect, Vector<ShaderNode*>& outResult);
  66. void getDragRect(RectI& box);
  67. void startDragMove(const Point2I& startPoint);
  68. void startDragRectangle(const Point2I& startPoint);
  69. void startDragClone(const Point2I& startPoint);
  70. void setMouseMode(mouseModes mode);
  71. public:
  72. GuiShaderEditor();
  73. DECLARE_CONOBJECT(GuiShaderEditor);
  74. DECLARE_CATEGORY("Shader Editor");
  75. DECLARE_DESCRIPTION("Implements a shader node based editor.");
  76. bool onWake();
  77. void onSleep();
  78. static void initPersistFields();
  79. virtual bool onAdd() override;
  80. virtual void onRemove() override;
  81. virtual void onPreRender() override;
  82. virtual void onRender(Point2I offset, const RectI& updateRect) override;
  83. // interaction
  84. virtual bool onKeyDown(const GuiEvent& event) override;
  85. virtual void onMouseDown(const GuiEvent& event) override;
  86. virtual void onMouseUp(const GuiEvent& event) override;
  87. virtual void onMouseDragged(const GuiEvent& event) override;
  88. virtual void onMiddleMouseDown(const GuiEvent& event) override;
  89. virtual void onMiddleMouseUp(const GuiEvent& event) override;
  90. virtual void onMiddleMouseDragged(const GuiEvent& event) override;
  91. virtual bool onMouseWheelUp(const GuiEvent& event) override;
  92. virtual bool onMouseWheelDown(const GuiEvent& event) override;
  93. RectI getSelectionBounds();
  94. void deleteSelection();
  95. void moveSelection(const Point2I& delta, bool callback = true);
  96. void clearSelection();
  97. void cloneSelection();
  98. void addSelectionAtPoint(const Point2I& pos);
  99. void addSelection(ShaderNode* inNode);
  100. bool selectionContains(ShaderNode* inNode);
  101. void removeSelection(ShaderNode* inNode);
  102. void canHitSelectedNodes(bool state = true);
  103. };
  104. #endif _GUISHADEREDITOR_H_