2
0

polygon_2d_editor_plugin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 <[email protected]>
  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_CREATE_INTERNAL,
  49. UV_MODE_REMOVE_INTERNAL,
  50. UV_MODE_EDIT_POINT,
  51. UV_MODE_MOVE,
  52. UV_MODE_ROTATE,
  53. UV_MODE_SCALE,
  54. UV_MODE_ADD_POLYGON,
  55. UV_MODE_REMOVE_POLYGON,
  56. UV_MODE_PAINT_WEIGHT,
  57. UV_MODE_CLEAR_WEIGHT,
  58. UV_MODE_MAX
  59. };
  60. ToolButton *uv_edit_mode[4];
  61. Ref<ButtonGroup> uv_edit_group;
  62. Polygon2D *node;
  63. UVMode uv_mode;
  64. AcceptDialog *uv_edit;
  65. ToolButton *uv_button[UV_MODE_MAX];
  66. ToolButton *b_snap_enable;
  67. ToolButton *b_snap_grid;
  68. Panel *uv_edit_draw;
  69. HSlider *uv_zoom;
  70. SpinBox *uv_zoom_value;
  71. HScrollBar *uv_hscroll;
  72. VScrollBar *uv_vscroll;
  73. MenuButton *uv_menu;
  74. TextureRect *uv_icon_zoom;
  75. VBoxContainer *bone_scroll_main_vb;
  76. ScrollContainer *bone_scroll;
  77. VBoxContainer *bone_scroll_vb;
  78. Button *sync_bones;
  79. HSlider *bone_paint_strength;
  80. SpinBox *bone_paint_radius;
  81. Label *bone_paint_radius_label;
  82. bool bone_painting;
  83. int bone_painting_bone;
  84. PoolVector<float> prev_weights;
  85. Vector2 bone_paint_pos;
  86. AcceptDialog *grid_settings;
  87. void _sync_bones();
  88. void _update_bone_list();
  89. Vector2 uv_draw_ofs;
  90. float uv_draw_zoom;
  91. PoolVector<Vector2> points_prev;
  92. PoolVector<Vector2> uv_create_uv_prev;
  93. PoolVector<Vector2> uv_create_poly_prev;
  94. PoolVector<Color> uv_create_colors_prev;
  95. int uv_create_prev_internal_vertices;
  96. Array uv_create_bones_prev;
  97. Array polygons_prev;
  98. Vector2 uv_create_to;
  99. int point_drag_index;
  100. bool uv_drag;
  101. bool uv_create;
  102. Vector<int> polygon_create;
  103. UVMode uv_move_current;
  104. Vector2 uv_drag_from;
  105. bool updating_uv_scroll;
  106. AcceptDialog *error;
  107. ToolButton *button_uv;
  108. bool use_snap;
  109. bool snap_show_grid;
  110. Vector2 snap_offset;
  111. Vector2 snap_step;
  112. virtual void _menu_option(int p_option);
  113. void _cancel_editing();
  114. void _update_polygon_editing_state();
  115. void _uv_scroll_changed(float);
  116. void _uv_input(const Ref<InputEvent> &p_input);
  117. void _uv_draw();
  118. void _uv_mode(int p_mode);
  119. void _set_use_snap(bool p_use);
  120. void _set_show_grid(bool p_show);
  121. void _set_snap_off_x(float p_val);
  122. void _set_snap_off_y(float p_val);
  123. void _set_snap_step_x(float p_val);
  124. void _set_snap_step_y(float p_val);
  125. void _uv_edit_mode_select(int p_mode);
  126. void _uv_edit_popup_hide();
  127. void _bone_paint_selected(int p_index);
  128. int _get_polygon_count() const;
  129. protected:
  130. virtual Node2D *_get_node() const;
  131. virtual void _set_node(Node *p_polygon);
  132. virtual Vector2 _get_offset(int p_idx) const;
  133. virtual bool _has_uv() const { return true; };
  134. virtual void _commit_action();
  135. void _notification(int p_what);
  136. static void _bind_methods();
  137. Vector2 snap_point(Vector2 p_target) const;
  138. public:
  139. Polygon2DEditor(EditorNode *p_editor);
  140. };
  141. class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
  142. GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
  143. public:
  144. Polygon2DEditorPlugin(EditorNode *p_node);
  145. };
  146. #endif // POLYGON_2D_EDITOR_PLUGIN_H