| 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 | |
| 31 | #ifndef GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H |
| 32 | #define GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H |
| 33 | |
| 34 | #include "editor/editor_inspector.h" |
| 35 | #include "editor/editor_plugin.h" |
| 36 | |
| 37 | class Button; |
| 38 | class EditorSpinSlider; |
| 39 | class GradientTexture2D; |
| 40 | |
| 41 | class GradientTexture2DEdit : public Control { |
| 42 | GDCLASS(GradientTexture2DEdit, Control); |
| 43 | |
| 44 | enum Handle { |
| 45 | HANDLE_NONE, |
| 46 | HANDLE_FROM, |
| 47 | HANDLE_TO |
| 48 | }; |
| 49 | |
| 50 | Ref<GradientTexture2D> texture; |
| 51 | bool snap_enabled = false; |
| 52 | int snap_count = 0; |
| 53 | |
| 54 | TextureRect *checkerboard = nullptr; |
| 55 | |
| 56 | Handle hovered = HANDLE_NONE; |
| 57 | Handle grabbed = HANDLE_NONE; |
| 58 | Point2 initial_grab_pos; |
| 59 | |
| 60 | Size2 handle_size; |
| 61 | Point2 offset; |
| 62 | Size2 size; |
| 63 | |
| 64 | Point2 _get_handle_pos(const Handle p_handle); |
| 65 | Handle get_handle_at(const Vector2 &p_pos); |
| 66 | void set_fill_pos(const Vector2 &p_pos); |
| 67 | |
| 68 | virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 69 | |
| 70 | void _draw(); |
| 71 | |
| 72 | protected: |
| 73 | void _notification(int p_what); |
| 74 | |
| 75 | public: |
| 76 | void set_texture(Ref<GradientTexture2D> &p_texture); |
| 77 | void set_snap_enabled(bool p_snap_enabled); |
| 78 | void set_snap_count(int p_snap_count); |
| 79 | |
| 80 | GradientTexture2DEdit(); |
| 81 | }; |
| 82 | |
| 83 | class GradientTexture2DEditor : public VBoxContainer { |
| 84 | GDCLASS(GradientTexture2DEditor, VBoxContainer); |
| 85 | |
| 86 | Ref<GradientTexture2D> texture; |
| 87 | |
| 88 | Button *reverse_button = nullptr; |
| 89 | Button *snap_button = nullptr; |
| 90 | EditorSpinSlider *snap_count_edit = nullptr; |
| 91 | GradientTexture2DEdit *texture_editor_rect = nullptr; |
| 92 | |
| 93 | void _reverse_button_pressed(); |
| 94 | void _set_snap_enabled(bool p_enabled); |
| 95 | void _set_snap_count(int p_snap_count); |
| 96 | |
| 97 | protected: |
| 98 | void _notification(int p_what); |
| 99 | |
| 100 | public: |
| 101 | static const int DEFAULT_SNAP; |
| 102 | void set_texture(Ref<GradientTexture2D> &p_texture); |
| 103 | |
| 104 | GradientTexture2DEditor(); |
| 105 | }; |
| 106 | |
| 107 | class EditorInspectorPluginGradientTexture2D : public EditorInspectorPlugin { |
| 108 | GDCLASS(EditorInspectorPluginGradientTexture2D, EditorInspectorPlugin); |
| 109 | |
| 110 | public: |
| 111 | virtual bool can_handle(Object *p_object) override; |
| 112 | virtual void parse_begin(Object *p_object) override; |
| 113 | }; |
| 114 | |
| 115 | class GradientTexture2DEditorPlugin : public EditorPlugin { |
| 116 | GDCLASS(GradientTexture2DEditorPlugin, EditorPlugin); |
| 117 | |
| 118 | public: |
| 119 | GradientTexture2DEditorPlugin(); |
| 120 | }; |
| 121 | |
| 122 | #endif // GRADIENT_TEXTURE_2D_EDITOR_PLUGIN_H |
| 123 | |