polygon_2d_editor_plugin.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* polygon_2d_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. /**
  34. @author Juan Linietsky <reduzio@gmail.com>
  35. */
  36. class Polygon2DEditor : public AbstractPolygon2DEditor {
  37. GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
  38. enum Mode {
  39. MODE_EDIT_UV = MODE_CONT,
  40. UVEDIT_POLYGON_TO_UV,
  41. UVEDIT_UV_TO_POLYGON,
  42. UVEDIT_UV_CLEAR
  43. };
  44. enum UVMode {
  45. UV_MODE_EDIT_POINT,
  46. UV_MODE_MOVE,
  47. UV_MODE_ROTATE,
  48. UV_MODE_SCALE,
  49. UV_MODE_MAX
  50. };
  51. Polygon2D *node;
  52. UVMode uv_mode;
  53. AcceptDialog *uv_edit;
  54. ToolButton *uv_button[4];
  55. ToolButton *b_snap_enable;
  56. ToolButton *b_snap_grid;
  57. Control *uv_edit_draw;
  58. HSlider *uv_zoom;
  59. SpinBox *uv_zoom_value;
  60. HScrollBar *uv_hscroll;
  61. VScrollBar *uv_vscroll;
  62. MenuButton *uv_menu;
  63. TextureRect *uv_icon_zoom;
  64. Vector2 uv_draw_ofs;
  65. float uv_draw_zoom;
  66. PoolVector<Vector2> uv_prev;
  67. int uv_drag_index;
  68. bool uv_drag;
  69. UVMode uv_move_current;
  70. Vector2 uv_drag_from;
  71. bool updating_uv_scroll;
  72. AcceptDialog *error;
  73. ToolButton *button_uv;
  74. bool use_snap;
  75. bool snap_show_grid;
  76. Vector2 snap_offset;
  77. Vector2 snap_step;
  78. virtual void _menu_option(int p_option);
  79. void _uv_scroll_changed(float);
  80. void _uv_input(const Ref<InputEvent> &p_input);
  81. void _uv_draw();
  82. void _uv_mode(int p_mode);
  83. void _set_use_snap(bool p_use);
  84. void _set_show_grid(bool p_show);
  85. void _set_snap_off_x(float p_val);
  86. void _set_snap_off_y(float p_val);
  87. void _set_snap_step_x(float p_val);
  88. void _set_snap_step_y(float p_val);
  89. protected:
  90. virtual Node2D *_get_node() const;
  91. virtual void _set_node(Node *p_polygon);
  92. virtual Vector2 _get_offset(int p_idx) const;
  93. void _notification(int p_what);
  94. static void _bind_methods();
  95. Vector2 snap_point(Vector2 p_target) const;
  96. public:
  97. Polygon2DEditor(EditorNode *p_editor);
  98. };
  99. class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
  100. GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
  101. public:
  102. Polygon2DEditorPlugin(EditorNode *p_node);
  103. };
  104. #endif // POLYGON_2D_EDITOR_PLUGIN_H