gradient_texture_2d_editor_plugin.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************/
  2. /* gradient_texture_2d_editor_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H
  31. #define GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/editor_spin_slider.h"
  34. class GradientTexture2DEditorRect : public Control {
  35. GDCLASS(GradientTexture2DEditorRect, Control);
  36. enum Handle {
  37. HANDLE_NONE,
  38. HANDLE_FILL_FROM,
  39. HANDLE_FILL_TO
  40. };
  41. Ref<GradientTexture2D> texture;
  42. UndoRedo *undo_redo = nullptr;
  43. bool snap_enabled = false;
  44. float snap_size = 0;
  45. TextureRect *checkerboard = nullptr;
  46. Handle handle = HANDLE_NONE;
  47. Size2 handle_size;
  48. Point2 offset;
  49. Size2 size;
  50. Point2 _get_handle_position(const Handle p_handle);
  51. void _update_fill_position();
  52. void _gui_input(const Ref<InputEvent> &p_event);
  53. protected:
  54. void _notification(int p_what);
  55. static void _bind_methods();
  56. public:
  57. void set_texture(Ref<GradientTexture2D> &p_texture);
  58. void set_snap_enabled(bool p_snap_enabled);
  59. void set_snap_size(float p_snap_size);
  60. GradientTexture2DEditorRect();
  61. };
  62. class GradientTexture2DEditor : public VBoxContainer {
  63. GDCLASS(GradientTexture2DEditor, VBoxContainer);
  64. Ref<GradientTexture2D> texture;
  65. UndoRedo *undo_redo = nullptr;
  66. Button *reverse_button = nullptr;
  67. Button *snap_button = nullptr;
  68. EditorSpinSlider *snap_size_edit = nullptr;
  69. GradientTexture2DEditorRect *texture_editor_rect = nullptr;
  70. void _reverse_button_pressed();
  71. void _set_snap_enabled(bool p_enabled);
  72. void _set_snap_size(float p_snap_size);
  73. protected:
  74. void _notification(int p_what);
  75. static void _bind_methods();
  76. public:
  77. void set_texture(Ref<GradientTexture2D> &p_texture);
  78. GradientTexture2DEditor();
  79. };
  80. class EditorInspectorPluginGradientTexture2D : public EditorInspectorPlugin {
  81. GDCLASS(EditorInspectorPluginGradientTexture2D, EditorInspectorPlugin);
  82. public:
  83. virtual bool can_handle(Object *p_object);
  84. virtual void parse_begin(Object *p_object);
  85. };
  86. class GradientTexture2DEditorPlugin : public EditorPlugin {
  87. GDCLASS(GradientTexture2DEditorPlugin, EditorPlugin);
  88. public:
  89. GradientTexture2DEditorPlugin(EditorNode *p_node);
  90. };
  91. #endif // GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H