canvas_layer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**************************************************************************/
  2. /* canvas_layer.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. #pragma once
  31. #include "scene/main/node.h"
  32. class Viewport;
  33. class CanvasLayer : public Node {
  34. GDCLASS(CanvasLayer, Node);
  35. mutable bool locrotscale_dirty = false;
  36. mutable Vector2 ofs;
  37. mutable Size2 scale = Vector2(1, 1);
  38. mutable real_t rot = 0.0;
  39. int layer = 1;
  40. Transform2D transform;
  41. RID canvas;
  42. ObjectID custom_viewport_id; // to check validity
  43. Viewport *custom_viewport = nullptr;
  44. RID viewport;
  45. Viewport *vp = nullptr;
  46. int sort_index = 0;
  47. bool visible = true;
  48. bool follow_viewport = false;
  49. float follow_viewport_scale = 1.0;
  50. void _update_xform();
  51. void _update_locrotscale() const;
  52. void _update_follow_viewport(bool p_force_exit = false);
  53. protected:
  54. void _notification(int p_what);
  55. static void _bind_methods();
  56. void _validate_property(PropertyInfo &p_property) const;
  57. public:
  58. void update_draw_order();
  59. void set_layer(int p_xform);
  60. int get_layer() const;
  61. void set_visible(bool p_visible);
  62. bool is_visible() const;
  63. void show();
  64. void hide();
  65. void set_transform(const Transform2D &p_xform);
  66. Transform2D get_transform() const;
  67. Transform2D get_final_transform() const;
  68. void set_offset(const Vector2 &p_offset);
  69. Vector2 get_offset() const;
  70. void set_rotation(real_t p_radians);
  71. real_t get_rotation() const;
  72. void set_scale(const Size2 &p_scale);
  73. Size2 get_scale() const;
  74. Size2 get_viewport_size() const;
  75. RID get_viewport() const;
  76. void set_custom_viewport(Node *p_viewport);
  77. Node *get_custom_viewport() const;
  78. void reset_sort_index();
  79. int get_sort_index();
  80. void set_follow_viewport(bool p_enable);
  81. bool is_following_viewport() const;
  82. void set_follow_viewport_scale(float p_ratio);
  83. float get_follow_viewport_scale() const;
  84. RID get_canvas() const;
  85. CanvasLayer();
  86. ~CanvasLayer();
  87. };