polygon_2d.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*************************************************************************/
  2. /* polygon_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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_H
  31. #define POLYGON_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class Polygon2D : public Node2D {
  34. GDCLASS(Polygon2D, Node2D);
  35. PoolVector<Vector2> polygon;
  36. PoolVector<Vector2> uv;
  37. PoolVector<Color> vertex_colors;
  38. Array polygons;
  39. int internal_vertices;
  40. struct Bone {
  41. NodePath path;
  42. PoolVector<float> weights;
  43. };
  44. Vector<Bone> bone_weights;
  45. Color color;
  46. Ref<Texture> texture;
  47. Size2 tex_scale;
  48. Vector2 tex_ofs;
  49. bool tex_tile;
  50. float tex_rot;
  51. bool invert;
  52. float invert_border;
  53. bool antialiased;
  54. Vector2 offset;
  55. mutable bool rect_cache_dirty;
  56. mutable Rect2 item_rect;
  57. NodePath skeleton;
  58. ObjectID current_skeleton_id;
  59. Array _get_bones() const;
  60. void _set_bones(const Array &p_bones);
  61. void _skeleton_bone_setup_changed();
  62. protected:
  63. void _notification(int p_what);
  64. static void _bind_methods();
  65. public:
  66. #ifdef TOOLS_ENABLED
  67. virtual Dictionary _edit_get_state() const;
  68. virtual void _edit_set_state(const Dictionary &p_state);
  69. virtual void _edit_set_pivot(const Point2 &p_pivot);
  70. virtual Point2 _edit_get_pivot() const;
  71. virtual bool _edit_use_pivot() const;
  72. virtual Rect2 _edit_get_rect() const;
  73. virtual bool _edit_use_rect() const;
  74. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  75. #endif
  76. void set_polygon(const PoolVector<Vector2> &p_polygon);
  77. PoolVector<Vector2> get_polygon() const;
  78. void set_internal_vertex_count(int p_count);
  79. int get_internal_vertex_count() const;
  80. void set_uv(const PoolVector<Vector2> &p_uv);
  81. PoolVector<Vector2> get_uv() const;
  82. void set_polygons(const Array &p_polygons);
  83. Array get_polygons() const;
  84. void set_color(const Color &p_color);
  85. Color get_color() const;
  86. void set_vertex_colors(const PoolVector<Color> &p_colors);
  87. PoolVector<Color> get_vertex_colors() const;
  88. void set_texture(const Ref<Texture> &p_texture);
  89. Ref<Texture> get_texture() const;
  90. void set_texture_offset(const Vector2 &p_offset);
  91. Vector2 get_texture_offset() const;
  92. void set_texture_rotation(float p_rot);
  93. float get_texture_rotation() const;
  94. void set_texture_rotation_degrees(float p_rot);
  95. float get_texture_rotation_degrees() const;
  96. void set_texture_scale(const Size2 &p_scale);
  97. Size2 get_texture_scale() const;
  98. void set_invert(bool p_invert);
  99. bool get_invert() const;
  100. void set_antialiased(bool p_antialiased);
  101. bool get_antialiased() const;
  102. void set_invert_border(float p_invert_border);
  103. float get_invert_border() const;
  104. void set_offset(const Vector2 &p_offset);
  105. Vector2 get_offset() const;
  106. void add_bone(const NodePath &p_path = NodePath(), const PoolVector<float> &p_weights = PoolVector<float>());
  107. int get_bone_count() const;
  108. NodePath get_bone_path(int p_index) const;
  109. PoolVector<float> get_bone_weights(int p_index) const;
  110. void erase_bone(int p_idx);
  111. void clear_bones();
  112. void set_bone_weights(int p_index, const PoolVector<float> &p_weights);
  113. void set_bone_path(int p_index, const NodePath &p_path);
  114. void set_skeleton(const NodePath &p_skeleton);
  115. NodePath get_skeleton() const;
  116. Polygon2D();
  117. };
  118. #endif // POLYGON_2D_H