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