| 1 | /**************************************************************************/ |
| 2 | /* polygon_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 POLYGON_2D_EDITOR_PLUGIN_H |
| 32 | #define POLYGON_2D_EDITOR_PLUGIN_H |
| 33 | |
| 34 | #include "editor/plugins/abstract_polygon_2d_editor.h" |
| 35 | |
| 36 | class AcceptDialog; |
| 37 | class ButtonGroup; |
| 38 | class HScrollBar; |
| 39 | class HSlider; |
| 40 | class Label; |
| 41 | class ; |
| 42 | class Panel; |
| 43 | class ScrollContainer; |
| 44 | class SpinBox; |
| 45 | class TextureRect; |
| 46 | class ViewPanner; |
| 47 | class VScrollBar; |
| 48 | |
| 49 | class Polygon2DEditor : public AbstractPolygon2DEditor { |
| 50 | GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); |
| 51 | |
| 52 | enum Mode { |
| 53 | MODE_EDIT_UV = MODE_CONT, |
| 54 | UVEDIT_POLYGON_TO_UV, |
| 55 | UVEDIT_UV_TO_POLYGON, |
| 56 | UVEDIT_UV_CLEAR, |
| 57 | UVEDIT_GRID_SETTINGS |
| 58 | }; |
| 59 | |
| 60 | enum UVMode { |
| 61 | UV_MODE_CREATE, |
| 62 | UV_MODE_CREATE_INTERNAL, |
| 63 | UV_MODE_REMOVE_INTERNAL, |
| 64 | UV_MODE_EDIT_POINT, |
| 65 | UV_MODE_MOVE, |
| 66 | UV_MODE_ROTATE, |
| 67 | UV_MODE_SCALE, |
| 68 | UV_MODE_ADD_POLYGON, |
| 69 | UV_MODE_REMOVE_POLYGON, |
| 70 | UV_MODE_PAINT_WEIGHT, |
| 71 | UV_MODE_CLEAR_WEIGHT, |
| 72 | UV_MODE_MAX |
| 73 | }; |
| 74 | |
| 75 | Button *uv_edit_mode[4]; |
| 76 | Ref<ButtonGroup> uv_edit_group; |
| 77 | |
| 78 | Polygon2D *node = nullptr; |
| 79 | |
| 80 | UVMode uv_mode; |
| 81 | AcceptDialog *uv_edit = nullptr; |
| 82 | Button *uv_button[UV_MODE_MAX]; |
| 83 | Button *b_snap_enable = nullptr; |
| 84 | Button *b_snap_grid = nullptr; |
| 85 | Panel *uv_edit_draw = nullptr; |
| 86 | HSlider *uv_zoom = nullptr; |
| 87 | SpinBox *uv_zoom_value = nullptr; |
| 88 | HScrollBar *uv_hscroll = nullptr; |
| 89 | VScrollBar *uv_vscroll = nullptr; |
| 90 | MenuButton * = nullptr; |
| 91 | TextureRect *uv_icon_zoom = nullptr; |
| 92 | |
| 93 | Ref<ViewPanner> uv_panner; |
| 94 | void _uv_pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event); |
| 95 | void _uv_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event); |
| 96 | |
| 97 | VBoxContainer *bone_scroll_main_vb = nullptr; |
| 98 | ScrollContainer *bone_scroll = nullptr; |
| 99 | VBoxContainer *bone_scroll_vb = nullptr; |
| 100 | Button *sync_bones = nullptr; |
| 101 | HSlider *bone_paint_strength = nullptr; |
| 102 | SpinBox *bone_paint_radius = nullptr; |
| 103 | Label *bone_paint_radius_label = nullptr; |
| 104 | bool bone_painting; |
| 105 | int bone_painting_bone = 0; |
| 106 | Vector<float> prev_weights; |
| 107 | Vector2 bone_paint_pos; |
| 108 | AcceptDialog *grid_settings = nullptr; |
| 109 | |
| 110 | void _sync_bones(); |
| 111 | void _update_bone_list(); |
| 112 | |
| 113 | Vector2 uv_draw_ofs; |
| 114 | real_t uv_draw_zoom; |
| 115 | Vector<Vector2> points_prev; |
| 116 | Vector<Vector2> uv_create_uv_prev; |
| 117 | Vector<Vector2> uv_create_poly_prev; |
| 118 | Vector<Color> uv_create_colors_prev; |
| 119 | int uv_create_prev_internal_vertices = 0; |
| 120 | Array uv_create_bones_prev; |
| 121 | Array polygons_prev; |
| 122 | |
| 123 | Vector2 uv_create_to; |
| 124 | int point_drag_index; |
| 125 | bool uv_drag; |
| 126 | bool uv_create; |
| 127 | Vector<int> polygon_create; |
| 128 | UVMode uv_move_current; |
| 129 | Vector2 uv_drag_from; |
| 130 | bool updating_uv_scroll; |
| 131 | |
| 132 | AcceptDialog *error = nullptr; |
| 133 | |
| 134 | Button *button_uv = nullptr; |
| 135 | |
| 136 | bool use_snap; |
| 137 | bool snap_show_grid; |
| 138 | Vector2 snap_offset; |
| 139 | Vector2 snap_step; |
| 140 | |
| 141 | virtual void (int p_option) override; |
| 142 | |
| 143 | void _cancel_editing(); |
| 144 | void _update_polygon_editing_state(); |
| 145 | |
| 146 | void _uv_scroll_changed(real_t); |
| 147 | void _uv_input(const Ref<InputEvent> &p_input); |
| 148 | void _uv_draw(); |
| 149 | void _uv_mode(int p_mode); |
| 150 | |
| 151 | void _set_use_snap(bool p_use); |
| 152 | void _set_show_grid(bool p_show); |
| 153 | void _set_snap_off_x(real_t p_val); |
| 154 | void _set_snap_off_y(real_t p_val); |
| 155 | void _set_snap_step_x(real_t p_val); |
| 156 | void _set_snap_step_y(real_t p_val); |
| 157 | |
| 158 | void _uv_edit_mode_select(int p_mode); |
| 159 | void (); |
| 160 | void _bone_paint_selected(int p_index); |
| 161 | |
| 162 | int _get_polygon_count() const override; |
| 163 | |
| 164 | protected: |
| 165 | virtual Node2D *_get_node() const override; |
| 166 | virtual void _set_node(Node *p_polygon) override; |
| 167 | |
| 168 | virtual Vector2 _get_offset(int p_idx) const override; |
| 169 | |
| 170 | virtual bool _has_uv() const override { return true; }; |
| 171 | virtual void _commit_action() override; |
| 172 | |
| 173 | void _notification(int p_what); |
| 174 | static void _bind_methods(); |
| 175 | |
| 176 | Vector2 snap_point(Vector2 p_target) const; |
| 177 | |
| 178 | public: |
| 179 | Polygon2DEditor(); |
| 180 | }; |
| 181 | |
| 182 | class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin { |
| 183 | GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin); |
| 184 | |
| 185 | public: |
| 186 | Polygon2DEditorPlugin(); |
| 187 | }; |
| 188 | |
| 189 | #endif // POLYGON_2D_EDITOR_PLUGIN_H |
| 190 | |