Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/main/canvas_item.h
9896 views
1
/**************************************************************************/
2
/* canvas_item.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
#pragma once
32
33
#include "scene/main/node.h"
34
#include "scene/resources/font.h"
35
36
class CanvasLayer;
37
class MultiMesh;
38
class StyleBox;
39
class Window;
40
class World2D;
41
42
class CanvasItem : public Node {
43
GDCLASS(CanvasItem, Node);
44
45
friend class CanvasLayer;
46
47
public:
48
enum TextureFilter {
49
TEXTURE_FILTER_PARENT_NODE,
50
TEXTURE_FILTER_NEAREST,
51
TEXTURE_FILTER_LINEAR,
52
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS,
53
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
54
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC,
55
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC,
56
TEXTURE_FILTER_MAX
57
};
58
59
enum TextureRepeat {
60
TEXTURE_REPEAT_PARENT_NODE,
61
TEXTURE_REPEAT_DISABLED,
62
TEXTURE_REPEAT_ENABLED,
63
TEXTURE_REPEAT_MIRROR,
64
TEXTURE_REPEAT_MAX,
65
};
66
67
enum ClipChildrenMode {
68
CLIP_CHILDREN_DISABLED,
69
CLIP_CHILDREN_ONLY,
70
CLIP_CHILDREN_AND_DRAW,
71
CLIP_CHILDREN_MAX,
72
};
73
74
private:
75
mutable SelfList<Node>
76
xform_change;
77
78
RID canvas_item;
79
StringName canvas_group;
80
81
CanvasLayer *canvas_layer = nullptr;
82
83
Color modulate = Color(1, 1, 1, 1);
84
Color self_modulate = Color(1, 1, 1, 1);
85
86
List<CanvasItem *> children_items;
87
List<CanvasItem *>::Element *C = nullptr;
88
89
int light_mask = 1;
90
uint32_t visibility_layer = 1;
91
92
int z_index = 0;
93
bool z_relative = true;
94
bool y_sort_enabled = false;
95
96
Window *window = nullptr;
97
bool visible = true;
98
bool parent_visible_in_tree = false;
99
bool pending_update = false;
100
bool top_level = false;
101
bool drawing = false;
102
bool block_transform_notify = false;
103
bool behind = false;
104
bool use_parent_material = false;
105
bool notify_local_transform = false;
106
bool notify_transform = false;
107
bool hide_clip_children = false;
108
109
ClipChildrenMode clip_children_mode = CLIP_CHILDREN_DISABLED;
110
111
mutable RS::CanvasItemTextureFilter texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
112
mutable RS::CanvasItemTextureRepeat texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
113
TextureFilter texture_filter = TEXTURE_FILTER_PARENT_NODE;
114
TextureRepeat texture_repeat = TEXTURE_REPEAT_PARENT_NODE;
115
116
Ref<Material> material;
117
mutable HashMap<StringName, Variant> instance_shader_parameters;
118
mutable HashMap<StringName, StringName> instance_shader_parameter_property_remap;
119
120
mutable Transform2D global_transform;
121
mutable MTFlag global_invalid;
122
123
_FORCE_INLINE_ bool _is_global_invalid() const { return is_group_processing() ? global_invalid.mt.is_set() : global_invalid.st; }
124
void _set_global_invalid(bool p_invalid) const;
125
126
void _top_level_raise_self();
127
128
void _propagate_visibility_changed(bool p_parent_visible_in_tree);
129
void _handle_visibility_change(bool p_visible);
130
131
virtual void _top_level_changed();
132
virtual void _top_level_changed_on_parent();
133
134
void _redraw_callback();
135
136
void _enter_canvas();
137
void _exit_canvas();
138
139
void _window_visibility_changed();
140
141
void _notify_transform(CanvasItem *p_node);
142
143
virtual void _physics_interpolated_changed() override;
144
145
static CanvasItem *current_item_drawn;
146
friend class Viewport;
147
void _refresh_texture_repeat_cache() const;
148
void _update_texture_repeat_changed(bool p_propagate);
149
void _refresh_texture_filter_cache() const;
150
void _update_texture_filter_changed(bool p_propagate);
151
152
void _notify_transform_deferred();
153
const StringName *_instance_shader_parameter_get_remap(const StringName &p_name) const;
154
155
protected:
156
bool _set(const StringName &p_name, const Variant &p_value);
157
bool _get(const StringName &p_name, Variant &r_ret) const;
158
void _get_property_list(List<PropertyInfo> *p_list) const;
159
160
virtual void _update_self_texture_repeat(RS::CanvasItemTextureRepeat p_texture_repeat);
161
virtual void _update_self_texture_filter(RS::CanvasItemTextureFilter p_texture_filter);
162
163
_FORCE_INLINE_ void _notify_transform() {
164
_notify_transform(this);
165
if (is_inside_tree() && !block_transform_notify && notify_local_transform) {
166
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
167
}
168
}
169
170
void item_rect_changed(bool p_size_changed = true);
171
172
void set_canvas_item_use_identity_transform(bool p_enable);
173
174
void _notification(int p_what);
175
static void _bind_methods();
176
177
#ifndef DISABLE_DEPRECATED
178
void _draw_string_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
179
void _draw_multiline_string_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
180
void _draw_string_outline_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
181
void _draw_multiline_string_outline_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
182
void _draw_char_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
183
void _draw_char_outline_bind_compat_104872(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
184
void _draw_circle_bind_compat_84472(const Point2 &p_pos, real_t p_radius, const Color &p_color);
185
void _draw_rect_bind_compat_84523(const Rect2 &p_rect, const Color &p_color, bool p_filled, real_t p_width);
186
void _draw_dashed_line_bind_compat_84523(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, real_t p_dash, bool p_aligned);
187
void _draw_multiline_bind_compat_84523(const Vector<Point2> &p_points, const Color &p_color, real_t p_width);
188
void _draw_multiline_colors_bind_compat_84523(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width);
189
static void _bind_compatibility_methods();
190
#endif // DISABLE_DEPRECATED
191
192
void _validate_property(PropertyInfo &p_property) const;
193
194
_FORCE_INLINE_ void set_hide_clip_children(bool p_value) { hide_clip_children = p_value; }
195
196
GDVIRTUAL0(_draw)
197
198
public:
199
enum {
200
NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
201
NOTIFICATION_DRAW = 30,
202
NOTIFICATION_VISIBILITY_CHANGED = 31,
203
NOTIFICATION_ENTER_CANVAS = 32,
204
NOTIFICATION_EXIT_CANVAS = 33,
205
NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 35,
206
NOTIFICATION_WORLD_2D_CHANGED = 36,
207
};
208
209
/* EDITOR AND DEBUGGING */
210
211
#ifdef TOOLS_ENABLED
212
// Save and restore a CanvasItem state
213
virtual void _edit_set_state(const Dictionary &p_state) {}
214
virtual Dictionary _edit_get_state() const { return Dictionary(); }
215
216
// Used to move the node
217
virtual void _edit_set_position(const Point2 &p_position) = 0;
218
virtual Point2 _edit_get_position() const = 0;
219
220
// Used to scale the node
221
virtual void _edit_set_scale(const Size2 &p_scale) = 0;
222
virtual Size2 _edit_get_scale() const = 0;
223
224
// Used to rotate the node
225
virtual bool _edit_use_rotation() const { return false; }
226
virtual void _edit_set_rotation(real_t p_rotation) {}
227
virtual real_t _edit_get_rotation() const { return 0.0; }
228
229
// Used to resize/move the node
230
virtual void _edit_set_rect(const Rect2 &p_rect) {}
231
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); } // LOOKS WEIRD
232
233
// Used to set a pivot
234
virtual bool _edit_use_pivot() const { return false; }
235
virtual void _edit_set_pivot(const Point2 &p_pivot) {}
236
virtual Point2 _edit_get_pivot() const { return Point2(); }
237
238
virtual Transform2D _edit_get_transform() const;
239
#endif // TOOLS_ENABLED
240
241
#ifdef DEBUG_ENABLED
242
// Those need to be available in debug runtime, to allow for node selection.
243
244
// Select the node.
245
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
246
247
// Used to resize/move the node.
248
virtual bool _edit_use_rect() const { return false; } // Maybe replace with _edit_get_editmode().
249
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); }
250
#endif // DEBUG_ENABLED
251
252
void update_draw_order();
253
254
/* VISIBILITY */
255
256
void set_visible(bool p_visible);
257
bool is_visible() const;
258
bool is_visible_in_tree() const;
259
void show();
260
void hide();
261
262
void queue_redraw();
263
void move_to_front();
264
265
void set_clip_children_mode(ClipChildrenMode p_clip_mode);
266
ClipChildrenMode get_clip_children_mode() const;
267
268
virtual void set_light_mask(int p_light_mask);
269
int get_light_mask() const;
270
271
void set_modulate(const Color &p_modulate);
272
Color get_modulate() const;
273
Color get_modulate_in_tree() const;
274
275
virtual void set_self_modulate(const Color &p_self_modulate);
276
Color get_self_modulate() const;
277
278
void set_visibility_layer(uint32_t p_visibility_layer);
279
uint32_t get_visibility_layer() const;
280
281
void set_visibility_layer_bit(uint32_t p_visibility_layer, bool p_enable);
282
bool get_visibility_layer_bit(uint32_t p_visibility_layer) const;
283
284
/* ORDERING */
285
286
virtual void set_z_index(int p_z);
287
int get_z_index() const;
288
int get_effective_z_index() const;
289
290
void set_z_as_relative(bool p_enabled);
291
bool is_z_relative() const;
292
293
virtual void set_y_sort_enabled(bool p_enabled);
294
virtual bool is_y_sort_enabled() const;
295
296
/* DRAWING API */
297
298
void draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, real_t p_dash = 2.0, bool p_aligned = true, bool p_antialiased = false);
299
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
300
void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
301
void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
302
void draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
303
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
304
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
305
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
306
void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
307
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
308
void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
309
void draw_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false);
310
void draw_msdf_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), double p_outline = 0.0, double p_pixel_range = 4.0, double p_scale = 1.0);
311
void draw_lcd_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1));
312
void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
313
void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture = Ref<Texture2D>());
314
void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>());
315
void draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>());
316
317
void draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1));
318
void draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture);
319
320
void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
321
void draw_multiline_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
322
323
void draw_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
324
void draw_multiline_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
325
326
void draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), float p_oversampling = 0.0) const;
327
void draw_char_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), float p_oversampling = 0.0) const;
328
329
void draw_set_transform(const Point2 &p_offset, real_t p_rot = 0.0, const Size2 &p_scale = Size2(1.0, 1.0));
330
void draw_set_transform_matrix(const Transform2D &p_matrix);
331
void draw_animation_slice(double p_animation_length, double p_slice_begin, double p_slice_end, double p_offset = 0);
332
void draw_end_animation();
333
334
static CanvasItem *get_current_item_drawn();
335
336
/* RECT / TRANSFORM */
337
338
void set_as_top_level(bool p_top_level);
339
bool is_set_as_top_level() const;
340
341
void set_draw_behind_parent(bool p_enable);
342
bool is_draw_behind_parent_enabled() const;
343
344
CanvasItem *get_parent_item() const;
345
346
virtual Transform2D get_transform() const = 0;
347
348
virtual Transform2D get_global_transform() const;
349
virtual Transform2D get_global_transform_const() const;
350
virtual Transform2D get_global_transform_with_canvas() const;
351
virtual Transform2D get_screen_transform() const;
352
353
CanvasItem *get_top_level() const;
354
_FORCE_INLINE_ RID get_canvas_item() const {
355
return canvas_item;
356
}
357
358
void set_block_transform_notify(bool p_enable);
359
bool is_block_transform_notify_enabled() const;
360
361
Transform2D get_canvas_transform() const;
362
Transform2D get_viewport_transform() const;
363
Rect2 get_viewport_rect() const;
364
RID get_viewport_rid() const;
365
RID get_canvas() const;
366
ObjectID get_canvas_layer_instance_id() const;
367
Ref<World2D> get_world_2d() const;
368
369
virtual void set_material(const Ref<Material> &p_material);
370
Ref<Material> get_material() const;
371
372
void set_instance_shader_parameter(const StringName &p_name, const Variant &p_value);
373
Variant get_instance_shader_parameter(const StringName &p_name) const;
374
375
virtual void set_use_parent_material(bool p_use_parent_material);
376
bool get_use_parent_material() const;
377
378
Ref<InputEvent> make_input_local(const Ref<InputEvent> &p_event) const;
379
Vector2 make_canvas_position_local(const Vector2 &screen_point) const;
380
381
Vector2 get_global_mouse_position() const;
382
Vector2 get_local_mouse_position() const;
383
384
void set_notify_local_transform(bool p_enable);
385
bool is_local_transform_notification_enabled() const;
386
387
void set_notify_transform(bool p_enable);
388
bool is_transform_notification_enabled() const;
389
390
void force_update_transform();
391
392
virtual void set_texture_filter(TextureFilter p_texture_filter);
393
TextureFilter get_texture_filter() const;
394
395
virtual void set_texture_repeat(TextureRepeat p_texture_repeat);
396
TextureRepeat get_texture_repeat() const;
397
398
TextureFilter get_texture_filter_in_tree() const;
399
TextureRepeat get_texture_repeat_in_tree() const;
400
401
// Used by control nodes to retrieve the parent's anchorable area
402
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); }
403
404
int get_canvas_layer() const;
405
CanvasLayer *get_canvas_layer_node() const;
406
407
virtual PackedStringArray get_configuration_warnings() const override;
408
409
CanvasItem();
410
~CanvasItem();
411
};
412
413
VARIANT_ENUM_CAST(CanvasItem::TextureFilter)
414
VARIANT_ENUM_CAST(CanvasItem::TextureRepeat)
415
VARIANT_ENUM_CAST(CanvasItem::ClipChildrenMode)
416
417
class CanvasTexture : public Texture2D {
418
GDCLASS(CanvasTexture, Texture2D);
419
OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged.
420
421
Ref<Texture2D> diffuse_texture;
422
Ref<Texture2D> normal_texture;
423
Ref<Texture2D> specular_texture;
424
Color specular = Color(1, 1, 1, 1);
425
real_t shininess = 1.0;
426
427
RID canvas_texture;
428
429
CanvasItem::TextureFilter texture_filter = CanvasItem::TEXTURE_FILTER_PARENT_NODE;
430
CanvasItem::TextureRepeat texture_repeat = CanvasItem::TEXTURE_REPEAT_PARENT_NODE;
431
432
protected:
433
static void _bind_methods();
434
435
public:
436
void set_diffuse_texture(const Ref<Texture2D> &p_diffuse);
437
Ref<Texture2D> get_diffuse_texture() const;
438
439
void set_normal_texture(const Ref<Texture2D> &p_normal);
440
Ref<Texture2D> get_normal_texture() const;
441
442
void set_specular_texture(const Ref<Texture2D> &p_specular);
443
Ref<Texture2D> get_specular_texture() const;
444
445
void set_specular_color(const Color &p_color);
446
Color get_specular_color() const;
447
448
void set_specular_shininess(real_t p_shininess);
449
real_t get_specular_shininess() const;
450
451
void set_texture_filter(CanvasItem::TextureFilter p_filter);
452
CanvasItem::TextureFilter get_texture_filter() const;
453
454
void set_texture_repeat(CanvasItem::TextureRepeat p_repeat);
455
CanvasItem::TextureRepeat get_texture_repeat() const;
456
457
virtual int get_width() const override;
458
virtual int get_height() const override;
459
460
virtual bool is_pixel_opaque(int p_x, int p_y) const override;
461
virtual bool has_alpha() const override;
462
463
virtual Ref<Image> get_image() const override;
464
465
virtual RID get_rid() const override;
466
467
CanvasTexture();
468
~CanvasTexture();
469
};
470
471