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