| 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/plugins/editor_plugin.h" |
| 34 |
#include "scene/2d/path_2d.h" |
| 35 |
#include "scene/gui/box_container.h" |
| 36 |
|
| 37 |
class CanvasItemEditor; |
| 38 |
class ConfirmationDialog; |
| 39 |
class MenuButton; |
| 40 |
|
| 41 |
class Path2DEditor : public HBoxContainer { |
| 42 |
GDCLASS(Path2DEditor, HBoxContainer); |
| 43 |
|
| 44 |
friend class Path2DEditorPlugin; |
| 45 |
|
| 46 |
CanvasItemEditor *canvas_item_editor = nullptr; |
| 47 |
Panel *panel = nullptr; |
| 48 |
Path2D *node = nullptr; |
| 49 |
|
| 50 |
enum Mode { |
| 51 |
MODE_CREATE, |
| 52 |
MODE_EDIT, |
| 53 |
MODE_EDIT_CURVE, |
| 54 |
MODE_DELETE, |
| 55 |
MODE_CLOSE, |
| 56 |
MODE_CLEAR_POINTS, |
| 57 |
}; |
| 58 |
|
| 59 |
Mode mode = MODE_EDIT; |
| 60 |
HBoxContainer *toolbar = nullptr; |
| 61 |
Button *curve_clear_points = nullptr; |
| 62 |
Button *curve_close = nullptr; |
| 63 |
Button *curve_create = nullptr; |
| 64 |
Button *curve_del = nullptr; |
| 65 |
Button *curve_edit = nullptr; |
| 66 |
Button *curve_edit_curve = nullptr; |
| 67 |
MenuButton *handle_menu = nullptr; |
| 68 |
|
| 69 |
Button *create_curve_button = nullptr; |
| 70 |
ConfirmationDialog *clear_points_dialog = nullptr; |
| 71 |
|
| 72 |
bool mirror_handle_angle = true; |
| 73 |
bool mirror_handle_length = true; |
| 74 |
bool on_edge = false; |
| 75 |
|
| 76 |
enum HandleOption { |
| 77 |
HANDLE_OPTION_ANGLE, |
| 78 |
HANDLE_OPTION_LENGTH, |
| 79 |
}; |
| 80 |
|
| 81 |
enum Action { |
| 82 |
ACTION_NONE, |
| 83 |
ACTION_MOVING_POINT, |
| 84 |
ACTION_MOVING_NEW_POINT, |
| 85 |
ACTION_MOVING_NEW_POINT_FROM_SPLIT, |
| 86 |
ACTION_MOVING_IN, |
| 87 |
ACTION_MOVING_OUT, |
| 88 |
}; |
| 89 |
|
| 90 |
Action action = ACTION_NONE; |
| 91 |
int action_point = 0; |
| 92 |
Point2 moving_from; |
| 93 |
Point2 moving_screen_from; |
| 94 |
float orig_in_length = 0.0f; |
| 95 |
float orig_out_length = 0.0f; |
| 96 |
Vector2 edge_point; |
| 97 |
Vector2 original_mouse_pos; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
int control_points_in_range = 0; |
| 102 |
|
| 103 |
void _mode_selected(int p_mode); |
| 104 |
void _handle_option_pressed(int p_option); |
| 105 |
void _cancel_current_action(); |
| 106 |
|
| 107 |
void _node_visibility_changed(); |
| 108 |
void _update_toolbar(); |
| 109 |
|
| 110 |
void _create_curve(); |
| 111 |
void _confirm_clear_points(); |
| 112 |
void _clear_curve_points(Path2D *p_path2d); |
| 113 |
void _restore_curve_points(Path2D *p_path2d, const PackedVector2Array &p_points); |
| 114 |
|
| 115 |
RID debug_mesh_rid; |
| 116 |
RID debug_handle_mesh_rid; |
| 117 |
RID debug_handle_multimesh_rid; |
| 118 |
|
| 119 |
RID debug_handle_curve_multimesh_rid; |
| 120 |
RID debug_handle_sharp_multimesh_rid; |
| 121 |
RID debug_handle_smooth_multimesh_rid; |
| 122 |
|
| 123 |
LocalVector<Vector2> debug_handle_lines; |
| 124 |
LocalVector<Transform2D> debug_handle_curve_transforms; |
| 125 |
LocalVector<Transform2D> debug_handle_sharp_transforms; |
| 126 |
LocalVector<Transform2D> debug_handle_smooth_transforms; |
| 127 |
|
| 128 |
protected: |
| 129 |
void _notification(int p_what); |
| 130 |
void _node_removed(Node *p_node); |
| 131 |
static void _bind_methods(); |
| 132 |
|
| 133 |
public: |
| 134 |
bool forward_gui_input(const Ref<InputEvent> &p_event); |
| 135 |
void forward_canvas_draw_over_viewport(Control *p_overlay); |
| 136 |
void edit(Node *p_path2d); |
| 137 |
Path2DEditor(); |
| 138 |
~Path2DEditor(); |
| 139 |
}; |
| 140 |
|
| 141 |
class Path2DEditorPlugin : public EditorPlugin { |
| 142 |
GDCLASS(Path2DEditorPlugin, EditorPlugin); |
| 143 |
|
| 144 |
Path2DEditor *path2d_editor = nullptr; |
| 145 |
|
| 146 |
public: |
| 147 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return path2d_editor->forward_gui_input(p_event); } |
| 148 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { path2d_editor->forward_canvas_draw_over_viewport(p_overlay); } |
| 149 |
|
| 150 |
virtual String get_plugin_name() const override { return "Path2D"; } |
| 151 |
bool has_main_screen() const override { return false; } |
| 152 |
virtual void edit(Object *p_object) override; |
| 153 |
virtual bool handles(Object *p_object) const override; |
| 154 |
virtual void make_visible(bool p_visible) override; |
| 155 |
|
| 156 |
Path2DEditorPlugin(); |
| 157 |
}; |