| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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 |
}; |