polygon_2d_editor_plugin.h 5.2 KB

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