polygon_2d_editor_plugin.h 5.8 KB

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