shader_graph_editor_plugin.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*************************************************************************/
  2. /* shader_graph_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SHADER_GRAPH_EDITOR_PLUGIN_H
  31. #define SHADER_GRAPH_EDITOR_PLUGIN_H
  32. // FIXME: Godot 3.0 broke compatibility with ShaderGraphEditorPlugin,
  33. // it needs to be ported to the new shader language.
  34. #if 0
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_plugin.h"
  37. #include "editor/property_editor.h"
  38. #include "scene/gui/button.h"
  39. #include "scene/gui/graph_edit.h"
  40. #include "scene/gui/popup.h"
  41. #include "scene/gui/tree.h"
  42. #include "scene/resources/shader.h"
  43. #include "scene/resources/shader_graph.h"
  44. /**
  45. @author Juan Linietsky <reduzio@gmail.com>
  46. */
  47. class GraphColorRampEdit : public Control {
  48. GDCLASS(GraphColorRampEdit,Control);
  49. struct Point {
  50. float offset;
  51. Color color;
  52. bool operator<(const Point& p_ponit) const {
  53. return offset<p_ponit.offset;
  54. }
  55. };
  56. PopupPanel *popup;
  57. ColorPicker *picker;
  58. bool grabbing;
  59. int grabbed;
  60. float grabbed_at;
  61. Vector<Point> points;
  62. void _color_changed(const Color& p_color);
  63. protected:
  64. void _gui_input(const InputEvent& p_event);
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. void set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors);
  69. Vector<float> get_offsets() const;
  70. Vector<Color> get_colors() const;
  71. virtual Size2 get_minimum_size() const;
  72. GraphColorRampEdit();
  73. };
  74. class GraphCurveMapEdit : public Control {
  75. GDCLASS(GraphCurveMapEdit,Control);
  76. struct Point {
  77. float offset;
  78. float height;
  79. bool operator<(const Point& p_ponit) const {
  80. return offset<p_ponit.offset;
  81. }
  82. };
  83. bool grabbing;
  84. int grabbed;
  85. Vector<Point> points;
  86. void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d);
  87. protected:
  88. void _gui_input(const InputEvent& p_event);
  89. void _notification(int p_what);
  90. static void _bind_methods();
  91. public:
  92. void set_points(const Vector<Vector2>& p_points);
  93. Vector<Vector2> get_points() const;
  94. virtual Size2 get_minimum_size() const;
  95. GraphCurveMapEdit();
  96. };
  97. class ShaderGraphView : public Control {
  98. GDCLASS(ShaderGraphView,Control);
  99. CustomPropertyEditor *ped_popup;
  100. bool block_update;
  101. Label *status;
  102. GraphEdit *graph_edit;
  103. Ref<ShaderGraph> graph;
  104. int edited_id;
  105. int edited_def;
  106. ShaderGraph::ShaderType type;
  107. void _update_graph();
  108. void _create_node(int p_id);
  109. ToolButton *make_label(String text, Variant::Type v_type = Variant::NIL);
  110. ToolButton *make_editor(String text, GraphNode* gn, int p_id, int param, Variant::Type type, String p_hint="");
  111. void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot);
  112. void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot);
  113. void _node_removed(int p_id);
  114. void _begin_node_move();
  115. void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id);
  116. void _end_node_move();
  117. void _move_node(int p_id,const Vector2& p_to);
  118. void _duplicate_nodes_request();
  119. void _duplicate_nodes(const Array &p_nodes);
  120. void _delete_nodes_request();
  121. void _default_changed(int p_id, Node* p_button, int p_param, int v_type, String p_hint);
  122. void _scalar_const_changed(double p_value,int p_id);
  123. void _vec_const_changed(double p_value, int p_id, Array p_arr);
  124. void _rgb_const_changed(const Color& p_color, int p_id);
  125. void _xform_const_changed(int p_id,Node* p_button);
  126. void _scalar_op_changed(int p_op, int p_id);
  127. void _vec_op_changed(int p_op, int p_id);
  128. void _vec_scalar_op_changed(int p_op, int p_id);
  129. void _rgb_op_changed(int p_op, int p_id);
  130. void _xform_inv_rev_changed(bool p_enabled, int p_id);
  131. void _scalar_func_changed(int p_func, int p_id);
  132. void _vec_func_changed(int p_func, int p_id);
  133. void _scalar_input_changed(double p_value,int p_id);
  134. void _vec_input_changed(double p_value, int p_id, Array p_arr);
  135. void _xform_input_changed(int p_id,Node* p_button);
  136. void _rgb_input_changed(const Color& p_color, int p_id);
  137. void _tex_input_change(int p_id,Node* p_button);
  138. void _cube_input_change(int p_id);
  139. void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit);
  140. void _tex_edited(int p_id,Node* p_button);
  141. void _cube_edited(int p_id,Node* p_button);
  142. void _variant_edited();
  143. void _comment_edited(int p_id,Node* p_button);
  144. void _color_ramp_changed(int p_id,Node* p_ramp);
  145. void _curve_changed(int p_id,Node* p_curve);
  146. void _sg_updated();
  147. Map<int,GraphNode*> node_map;
  148. Variant get_drag_data_fw(const Point2& p_point,Control* p_from);
  149. bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const;
  150. void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from);
  151. protected:
  152. void _notification(int p_what);
  153. static void _bind_methods();
  154. public:
  155. void add_node(int p_type, const Vector2 &location);
  156. GraphEdit *get_graph_edit() { return graph_edit; }
  157. void set_graph(Ref<ShaderGraph> p_graph);
  158. ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT);
  159. };
  160. class ShaderGraphEditor : public VBoxContainer {
  161. GDCLASS(ShaderGraphEditor,VBoxContainer);
  162. PopupMenu *popup;
  163. TabContainer *tabs;
  164. ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX];
  165. static const char* node_names[ShaderGraph::NODE_TYPE_MAX];
  166. Vector2 next_location;
  167. bool _2d;
  168. void _add_node(int p_type);
  169. void _popup_requested(const Vector2 &p_position);
  170. protected:
  171. void _notification(int p_what);
  172. static void _bind_methods();
  173. public:
  174. void edit(Ref<ShaderGraph> p_shader);
  175. ShaderGraphEditor(bool p_2d);
  176. };
  177. class ShaderGraphEditorPlugin : public EditorPlugin {
  178. GDCLASS( ShaderGraphEditorPlugin, EditorPlugin );
  179. bool _2d;
  180. ShaderGraphEditor *shader_editor;
  181. EditorNode *editor;
  182. public:
  183. virtual String get_name() const { return "ShaderGraph"; }
  184. bool has_main_screen() const { return false; }
  185. virtual void edit(Object *p_node);
  186. virtual bool handles(Object *p_node) const;
  187. virtual void make_visible(bool p_visible);
  188. ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d);
  189. ~ShaderGraphEditorPlugin();
  190. };
  191. #endif
  192. #endif // SHADER_GRAPH_EDITOR_PLUGIN_H