polygon_2d_editor_plugin.h 6.1 KB

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