gradient_texture_2d_editor_plugin.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 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 EditorUndoRedoManager;
  35. class GradientTexture2DEditorRect : public Control {
  36. GDCLASS(GradientTexture2DEditorRect, Control);
  37. enum Handle {
  38. HANDLE_NONE,
  39. HANDLE_FILL_FROM,
  40. HANDLE_FILL_TO
  41. };
  42. Ref<GradientTexture2D> texture;
  43. Ref<EditorUndoRedoManager> undo_redo;
  44. bool snap_enabled = false;
  45. float snap_size = 0;
  46. TextureRect *checkerboard = nullptr;
  47. Handle handle = HANDLE_NONE;
  48. Size2 handle_size;
  49. Point2 offset;
  50. Size2 size;
  51. Point2 _get_handle_position(const Handle p_handle);
  52. void _update_fill_position();
  53. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  54. protected:
  55. void _notification(int p_what);
  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. Ref<EditorUndoRedoManager> undo_redo;
  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. public:
  76. void set_texture(Ref<GradientTexture2D> &p_texture);
  77. GradientTexture2DEditor();
  78. };
  79. class EditorInspectorPluginGradientTexture2D : public EditorInspectorPlugin {
  80. GDCLASS(EditorInspectorPluginGradientTexture2D, EditorInspectorPlugin);
  81. public:
  82. virtual bool can_handle(Object *p_object) override;
  83. virtual void parse_begin(Object *p_object) override;
  84. };
  85. class GradientTexture2DEditorPlugin : public EditorPlugin {
  86. GDCLASS(GradientTexture2DEditorPlugin, EditorPlugin);
  87. public:
  88. GradientTexture2DEditorPlugin();
  89. };
  90. #endif // GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H