sprite_2d.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**************************************************************************/
  2. /* sprite_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 SPRITE_2D_H
  31. #define SPRITE_2D_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/texture.h"
  34. class Sprite2D : public Node2D {
  35. GDCLASS(Sprite2D, Node2D);
  36. Ref<Texture2D> texture;
  37. Color specular_color;
  38. real_t shininess = 0.0;
  39. bool centered = true;
  40. Point2 offset;
  41. bool hflip = false;
  42. bool vflip = false;
  43. bool region_enabled = false;
  44. Rect2 region_rect;
  45. bool region_filter_clip_enabled = false;
  46. int frame = 0;
  47. int vframes = 1;
  48. int hframes = 1;
  49. void _get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip_enabled) const;
  50. void _texture_changed();
  51. protected:
  52. void _notification(int p_what);
  53. static void _bind_methods();
  54. void _validate_property(PropertyInfo &p_property) const;
  55. public:
  56. #ifdef TOOLS_ENABLED
  57. virtual Dictionary _edit_get_state() const override;
  58. virtual void _edit_set_state(const Dictionary &p_state) override;
  59. virtual void _edit_set_pivot(const Point2 &p_pivot) override;
  60. virtual Point2 _edit_get_pivot() const override;
  61. virtual bool _edit_use_pivot() const override;
  62. #endif // TOOLS_ENABLED
  63. #ifdef DEBUG_ENABLED
  64. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  65. virtual Rect2 _edit_get_rect() const override;
  66. virtual bool _edit_use_rect() const override;
  67. #endif // DEBUG_ENABLED
  68. bool is_pixel_opaque(const Point2 &p_point) const;
  69. void set_texture(const Ref<Texture2D> &p_texture);
  70. Ref<Texture2D> get_texture() const;
  71. void set_centered(bool p_center);
  72. bool is_centered() const;
  73. void set_offset(const Point2 &p_offset);
  74. Point2 get_offset() const;
  75. void set_flip_h(bool p_flip);
  76. bool is_flipped_h() const;
  77. void set_flip_v(bool p_flip);
  78. bool is_flipped_v() const;
  79. void set_region_enabled(bool p_enabled);
  80. bool is_region_enabled() const;
  81. void set_region_filter_clip_enabled(bool p_enabled);
  82. bool is_region_filter_clip_enabled() const;
  83. void set_region_rect(const Rect2 &p_region_rect);
  84. Rect2 get_region_rect() const;
  85. void set_frame(int p_frame);
  86. int get_frame() const;
  87. void set_frame_coords(const Vector2i &p_coord);
  88. Vector2i get_frame_coords() const;
  89. void set_vframes(int p_amount);
  90. int get_vframes() const;
  91. void set_hframes(int p_amount);
  92. int get_hframes() const;
  93. Rect2 get_rect() const;
  94. virtual Rect2 get_anchorable_rect() const override;
  95. Sprite2D();
  96. ~Sprite2D();
  97. };
  98. #endif // SPRITE_2D_H