Debian Codegraph @

editor/scene/gradient_editor_plugin.h

raw symbols SCIP
1 /**************************************************************************/
2 /* gradient_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 #pragma once
32
33 #include "editor/inspector/editor_inspector.h"
34 #include "editor/plugins/editor_plugin.h"
35 #include "scene/resources/gradient.h"
36
37 class EditorSpinSlider;
38 class ColorPicker;
39 class PopupPanel;
40 class GradientTexture1D;
41
42 class GradientEdit : public Control {
43 GDCLASS(GradientEdit, Control);
44
45 Ref<Gradient> gradient;
46 Ref<GradientTexture1D> preview_texture;
47
48 PopupPanel *popup = nullptr;
49 ColorPicker *picker = nullptr;
50
51 bool snap_enabled = false;
52 int snap_count = 10;
53
54 enum GrabMode {
55 GRAB_NONE,
56 GRAB_ADD,
57 GRAB_MOVE
58 };
59
60 GrabMode grabbing = GRAB_NONE;
61 float pre_grab_offset = 0.5;
62 int pre_grab_index = -1;
63 int selected_index = -1;
64 int hovered_index = -1;
65
66 // Make sure to use the scaled values below.
67 const int BASE_SPACING = 4;
68 const int BASE_HANDLE_WIDTH = 8;
69
70 int draw_spacing = BASE_SPACING;
71 int handle_width = BASE_HANDLE_WIDTH;
72
73 int _get_gradient_rect_width() const;
74
75 void _color_changed(const Color &p_color);
76 void _redraw();
77
78 int _get_point_at(int p_xpos) const;
79 int _predict_insertion_index(float p_offset);
80 void _show_color_picker();
81
82 protected:
83 virtual void gui_input(const Ref<InputEvent> &p_event) override;
84 void _notification(int p_what);
85 static void _bind_methods();
86
87 public:
88 void set_gradient(const Ref<Gradient> &p_gradient);
89 const Ref<Gradient> &get_gradient() const;
90
91 ColorPicker *get_picker() const;
92 PopupPanel *get_popup() const;
93
94 void set_selected_index(int p_index);
95
96 void add_point(float p_offset, const Color &p_color);
97 void remove_point(int p_index);
98 void set_offset(int p_index, float p_offset);
99 void set_color(int p_index, const Color &p_color);
100 void reverse_gradient();
101
102 void set_snap_enabled(bool p_enabled);
103 void set_snap_count(int p_count);
104
105 GradientEdit();
106 };
107
108 class GradientEditor : public VBoxContainer {
109 GDCLASS(GradientEditor, VBoxContainer);
110
111 Button *reverse_button = nullptr;
112 Button *snap_button = nullptr;
113 EditorSpinSlider *snap_count_edit = nullptr;
114 GradientEdit *gradient_editor_rect = nullptr;
115
116 void _set_snap_enabled(bool p_enabled);
117 void _set_snap_count(int p_count);
118
119 protected:
120 void _notification(int p_what);
121
122 public:
123 static const int DEFAULT_SNAP;
124 void set_gradient(const Ref<Gradient> &p_gradient);
125
126 GradientEditor();
127 };
128
129 class EditorInspectorPluginGradient : public EditorInspectorPlugin {
130 GDCLASS(EditorInspectorPluginGradient, EditorInspectorPlugin);
131
132 public:
133 virtual bool can_handle(Object *p_object) override;
134 virtual void parse_begin(Object *p_object) override;
135 };
136
137 class GradientEditorPlugin : public EditorPlugin {
138 GDCLASS(GradientEditorPlugin, EditorPlugin);
139
140 public:
141 virtual String get_plugin_name() const override { return "Gradient"; }
142
143 GradientEditorPlugin();
144 };