Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/main/canvas_item.cpp
9902 views
1
/**************************************************************************/
2
/* canvas_item.cpp */
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
#include "canvas_item.h"
32
#include "canvas_item.compat.inc"
33
34
#include "scene/2d/canvas_group.h"
35
#include "scene/main/canvas_layer.h"
36
#include "scene/main/window.h"
37
#include "scene/resources/atlas_texture.h"
38
#include "scene/resources/font.h"
39
#include "scene/resources/multimesh.h"
40
#include "scene/resources/style_box.h"
41
#include "scene/resources/world_2d.h"
42
43
#define ERR_DRAW_GUARD \
44
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside this node's `_draw()`, functions connected to its `draw` signal, or when it receives NOTIFICATION_DRAW.")
45
46
#ifdef DEBUG_ENABLED
47
bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
48
if (_edit_use_rect()) {
49
return _edit_get_rect().has_point(p_point);
50
} else {
51
return p_point.length() < p_tolerance;
52
}
53
}
54
#endif // DEBUG_ENABLED
55
56
#ifdef TOOLS_ENABLED
57
Transform2D CanvasItem::_edit_get_transform() const {
58
return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot());
59
}
60
#endif //TOOLS_ENABLED
61
62
bool CanvasItem::is_visible_in_tree() const {
63
ERR_READ_THREAD_GUARD_V(false);
64
return visible && parent_visible_in_tree;
65
}
66
67
void CanvasItem::_propagate_visibility_changed(bool p_parent_visible_in_tree) {
68
parent_visible_in_tree = p_parent_visible_in_tree;
69
if (!visible) {
70
return;
71
}
72
73
_handle_visibility_change(p_parent_visible_in_tree);
74
}
75
76
void CanvasItem::set_visible(bool p_visible) {
77
ERR_MAIN_THREAD_GUARD;
78
if (visible == p_visible) {
79
return;
80
}
81
82
visible = p_visible;
83
84
if (!parent_visible_in_tree) {
85
notification(NOTIFICATION_VISIBILITY_CHANGED);
86
return;
87
}
88
89
_handle_visibility_change(p_visible);
90
}
91
92
void CanvasItem::_handle_visibility_change(bool p_visible) {
93
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible);
94
notification(NOTIFICATION_VISIBILITY_CHANGED);
95
96
if (p_visible) {
97
queue_redraw();
98
} else {
99
emit_signal(SceneStringName(hidden));
100
}
101
102
_block();
103
for (int i = 0; i < get_child_count(); i++) {
104
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
105
106
if (c) { // Should the top_levels stop propagation? I think so, but...
107
c->_propagate_visibility_changed(p_visible);
108
}
109
}
110
_unblock();
111
}
112
113
void CanvasItem::show() {
114
ERR_MAIN_THREAD_GUARD;
115
set_visible(true);
116
}
117
118
void CanvasItem::hide() {
119
ERR_MAIN_THREAD_GUARD;
120
set_visible(false);
121
}
122
123
bool CanvasItem::is_visible() const {
124
ERR_READ_THREAD_GUARD_V(false);
125
return visible;
126
}
127
128
CanvasItem *CanvasItem::current_item_drawn = nullptr;
129
CanvasItem *CanvasItem::get_current_item_drawn() {
130
return current_item_drawn;
131
}
132
133
void CanvasItem::_redraw_callback() {
134
if (!is_inside_tree()) {
135
pending_update = false;
136
return;
137
}
138
139
RID ci = get_canvas_item();
140
RenderingServer::get_singleton()->canvas_item_clear(ci);
141
//todo updating = true - only allow drawing here
142
if (is_visible_in_tree()) {
143
drawing = true;
144
Ref<TextServer> ts = TextServerManager::get_singleton()->get_primary_interface();
145
if (ts.is_valid()) {
146
ts->set_current_drawn_item_oversampling(get_viewport()->get_oversampling());
147
}
148
current_item_drawn = this;
149
notification(NOTIFICATION_DRAW);
150
emit_signal(SceneStringName(draw));
151
GDVIRTUAL_CALL(_draw);
152
current_item_drawn = nullptr;
153
if (ts.is_valid()) {
154
ts->set_current_drawn_item_oversampling(0.0);
155
}
156
drawing = false;
157
}
158
//todo updating = false
159
pending_update = false; // don't change to false until finished drawing (avoid recursive update)
160
}
161
162
Transform2D CanvasItem::get_global_transform_with_canvas() const {
163
ERR_READ_THREAD_GUARD_V(Transform2D());
164
if (canvas_layer) {
165
return canvas_layer->get_final_transform() * get_global_transform();
166
} else if (is_inside_tree()) {
167
return get_viewport()->get_canvas_transform() * get_global_transform();
168
} else {
169
return get_global_transform();
170
}
171
}
172
173
Transform2D CanvasItem::get_screen_transform() const {
174
ERR_READ_THREAD_GUARD_V(Transform2D());
175
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
176
return get_viewport()->get_popup_base_transform() * get_global_transform_with_canvas();
177
}
178
179
Transform2D CanvasItem::get_global_transform() const {
180
ERR_READ_THREAD_GUARD_V(Transform2D());
181
182
if (_is_global_invalid()) {
183
// This code can enter multiple times from threads if dirty, this is expected.
184
const CanvasItem *pi = get_parent_item();
185
Transform2D new_global;
186
if (pi) {
187
new_global = pi->get_global_transform() * get_transform();
188
} else {
189
new_global = get_transform();
190
}
191
192
global_transform = new_global;
193
_set_global_invalid(false);
194
}
195
196
return global_transform;
197
}
198
199
// Same as get_global_transform() but no reset for `global_invalid`.
200
Transform2D CanvasItem::get_global_transform_const() const {
201
if (_is_global_invalid()) {
202
const CanvasItem *pi = get_parent_item();
203
if (pi) {
204
global_transform = pi->get_global_transform_const() * get_transform();
205
} else {
206
global_transform = get_transform();
207
}
208
}
209
210
return global_transform;
211
}
212
213
void CanvasItem::_set_global_invalid(bool p_invalid) const {
214
if (is_group_processing()) {
215
if (p_invalid) {
216
global_invalid.mt.set();
217
} else {
218
global_invalid.mt.clear();
219
}
220
} else {
221
global_invalid.st = p_invalid;
222
}
223
}
224
225
void CanvasItem::_top_level_raise_self() {
226
if (!is_inside_tree()) {
227
return;
228
}
229
230
if (canvas_layer) {
231
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index());
232
} else {
233
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index());
234
}
235
}
236
237
void CanvasItem::_enter_canvas() {
238
// Resolves to nullptr if the node is top_level.
239
CanvasItem *parent_item = get_parent_item();
240
241
if (get_parent()) {
242
get_viewport()->canvas_parent_mark_dirty(get_parent());
243
}
244
245
if (parent_item) {
246
canvas_layer = parent_item->canvas_layer;
247
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, parent_item->get_canvas_item());
248
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, visibility_layer);
249
} else {
250
Node *n = this;
251
252
canvas_layer = nullptr;
253
254
while (n) {
255
canvas_layer = Object::cast_to<CanvasLayer>(n);
256
if (canvas_layer) {
257
break;
258
}
259
if (Object::cast_to<Viewport>(n)) {
260
break;
261
}
262
n = n->get_parent();
263
}
264
265
RID canvas;
266
if (canvas_layer) {
267
canvas = canvas_layer->get_canvas();
268
} else {
269
canvas = get_viewport()->find_world_2d()->get_canvas();
270
}
271
272
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);
273
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, visibility_layer);
274
275
canvas_group = "_root_canvas" + itos(canvas.get_id());
276
277
add_to_group(canvas_group);
278
if (canvas_layer) {
279
canvas_layer->reset_sort_index();
280
} else {
281
get_viewport()->gui_reset_canvas_sort_index();
282
}
283
}
284
285
pending_update = false;
286
queue_redraw();
287
288
notification(NOTIFICATION_ENTER_CANVAS);
289
}
290
291
void CanvasItem::_exit_canvas() {
292
notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
293
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
294
canvas_layer = nullptr;
295
if (canvas_group != StringName()) {
296
remove_from_group(canvas_group);
297
canvas_group = StringName();
298
}
299
}
300
301
void CanvasItem::_notification(int p_what) {
302
switch (p_what) {
303
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
304
RID ae = get_accessibility_element();
305
ERR_FAIL_COND(ae.is_null());
306
307
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, !visible);
308
} break;
309
310
case NOTIFICATION_ENTER_TREE: {
311
ERR_MAIN_THREAD_GUARD;
312
ERR_FAIL_COND(!is_inside_tree());
313
314
Node *parent = get_parent();
315
if (parent) {
316
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
317
318
if (ci) {
319
parent_visible_in_tree = ci->is_visible_in_tree();
320
C = ci->children_items.push_back(this);
321
} else {
322
CanvasLayer *cl = Object::cast_to<CanvasLayer>(parent);
323
324
if (cl) {
325
parent_visible_in_tree = cl->is_visible();
326
} else {
327
// Look for a window.
328
Viewport *viewport = nullptr;
329
330
while (parent) {
331
viewport = Object::cast_to<Viewport>(parent);
332
if (viewport) {
333
break;
334
}
335
parent = parent->get_parent();
336
}
337
338
ERR_FAIL_NULL(viewport);
339
340
window = Object::cast_to<Window>(viewport);
341
if (window) {
342
window->connect(SceneStringName(visibility_changed), callable_mp(this, &CanvasItem::_window_visibility_changed));
343
parent_visible_in_tree = window->is_visible();
344
} else {
345
parent_visible_in_tree = true;
346
}
347
}
348
}
349
}
350
351
_set_global_invalid(true);
352
_enter_canvas();
353
354
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, is_visible_in_tree()); // The visibility of the parent may change.
355
if (is_visible_in_tree()) {
356
notification(NOTIFICATION_VISIBILITY_CHANGED); // Considered invisible until entered.
357
}
358
359
_update_texture_filter_changed(false);
360
_update_texture_repeat_changed(false);
361
362
if (!block_transform_notify && !xform_change.in_list()) {
363
get_tree()->xform_change_list.add(&xform_change);
364
}
365
366
if (get_viewport()) {
367
get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()), CONNECT_REFERENCE_COUNTED);
368
}
369
370
// If using physics interpolation, reset for this node only,
371
// as a helper, as in most cases, users will want items reset when
372
// adding to the tree.
373
// In cases where they move immediately after adding,
374
// there will be little cost in having two resets as these are cheap,
375
// and it is worth it for convenience.
376
// Do not propagate to children, as each child of an added branch
377
// receives its own NOTIFICATION_ENTER_TREE, and this would
378
// cause unnecessary duplicate resets.
379
if (is_physics_interpolated_and_enabled()) {
380
notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
381
}
382
383
} break;
384
case NOTIFICATION_EXIT_TREE: {
385
ERR_MAIN_THREAD_GUARD;
386
387
if (xform_change.in_list()) {
388
get_tree()->xform_change_list.remove(&xform_change);
389
}
390
_exit_canvas();
391
if (C) {
392
Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C);
393
C = nullptr;
394
}
395
if (window) {
396
window->disconnect(SceneStringName(visibility_changed), callable_mp(this, &CanvasItem::_window_visibility_changed));
397
window = nullptr;
398
}
399
_set_global_invalid(true);
400
parent_visible_in_tree = false;
401
402
if (get_viewport()) {
403
get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()));
404
}
405
} break;
406
407
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
408
if (is_visible_in_tree() && is_physics_interpolated_and_enabled()) {
409
RenderingServer::get_singleton()->canvas_item_reset_physics_interpolation(canvas_item);
410
}
411
} break;
412
413
case NOTIFICATION_VISIBILITY_CHANGED: {
414
ERR_MAIN_THREAD_GUARD;
415
416
emit_signal(SceneStringName(visibility_changed));
417
} break;
418
case NOTIFICATION_WORLD_2D_CHANGED: {
419
ERR_MAIN_THREAD_GUARD;
420
421
_exit_canvas();
422
_enter_canvas();
423
} break;
424
case NOTIFICATION_PARENTED: {
425
// The node is not inside the tree during this notification.
426
ERR_MAIN_THREAD_GUARD;
427
428
_notify_transform();
429
} break;
430
}
431
}
432
433
void CanvasItem::update_draw_order() {
434
ERR_MAIN_THREAD_GUARD;
435
436
if (!is_inside_tree()) {
437
return;
438
}
439
440
if (canvas_group != StringName()) {
441
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE | SceneTree::GROUP_CALL_DEFERRED, canvas_group, "_top_level_raise_self");
442
} else {
443
ERR_FAIL_NULL_MSG(get_parent_item(), "Moved child is in incorrect state (no canvas group, no canvas item parent).");
444
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index());
445
}
446
}
447
448
void CanvasItem::_window_visibility_changed() {
449
_propagate_visibility_changed(window->is_visible());
450
}
451
452
void CanvasItem::queue_redraw() {
453
ERR_THREAD_GUARD; // Calling from thread is safe.
454
if (!is_inside_tree()) {
455
return;
456
}
457
if (pending_update) {
458
return;
459
}
460
461
pending_update = true;
462
463
callable_mp(this, &CanvasItem::_redraw_callback).call_deferred();
464
}
465
466
void CanvasItem::move_to_front() {
467
ERR_MAIN_THREAD_GUARD;
468
if (!get_parent()) {
469
return;
470
}
471
get_parent()->move_child(this, -1);
472
}
473
474
void CanvasItem::set_modulate(const Color &p_modulate) {
475
ERR_THREAD_GUARD;
476
if (modulate == p_modulate) {
477
return;
478
}
479
480
modulate = p_modulate;
481
RenderingServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate);
482
}
483
484
Color CanvasItem::get_modulate() const {
485
ERR_READ_THREAD_GUARD_V(Color());
486
return modulate;
487
}
488
489
Color CanvasItem::get_modulate_in_tree() const {
490
ERR_READ_THREAD_GUARD_V(Color());
491
Color final_modulate = modulate;
492
CanvasItem *parent_item = get_parent_item();
493
while (parent_item) {
494
final_modulate *= parent_item->get_modulate();
495
parent_item = parent_item->get_parent_item();
496
}
497
return final_modulate;
498
}
499
500
void CanvasItem::set_as_top_level(bool p_top_level) {
501
ERR_MAIN_THREAD_GUARD;
502
if (top_level == p_top_level) {
503
return;
504
}
505
506
if (!is_inside_tree()) {
507
top_level = p_top_level;
508
_notify_transform();
509
return;
510
}
511
512
_exit_canvas();
513
top_level = p_top_level;
514
_top_level_changed();
515
_enter_canvas();
516
517
_notify_transform();
518
519
if (get_viewport()) {
520
get_viewport()->canvas_item_top_level_changed();
521
}
522
reset_physics_interpolation();
523
}
524
525
void CanvasItem::_top_level_changed() {
526
// Inform children that top_level status has changed on a parent.
527
int children = get_child_count();
528
for (int i = 0; i < children; i++) {
529
CanvasItem *child = Object::cast_to<CanvasItem>(get_child(i));
530
if (child) {
531
child->_top_level_changed_on_parent();
532
}
533
}
534
}
535
536
void CanvasItem::_top_level_changed_on_parent() {
537
// Inform children that top_level status has changed on a parent.
538
_top_level_changed();
539
}
540
541
bool CanvasItem::is_set_as_top_level() const {
542
return top_level;
543
}
544
545
CanvasItem *CanvasItem::get_parent_item() const {
546
ERR_READ_THREAD_GUARD_V(nullptr);
547
if (top_level) {
548
return nullptr;
549
}
550
551
return Object::cast_to<CanvasItem>(get_parent());
552
}
553
554
void CanvasItem::set_self_modulate(const Color &p_self_modulate) {
555
ERR_THREAD_GUARD;
556
if (self_modulate == p_self_modulate) {
557
return;
558
}
559
560
self_modulate = p_self_modulate;
561
RenderingServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate);
562
}
563
564
Color CanvasItem::get_self_modulate() const {
565
ERR_READ_THREAD_GUARD_V(Color());
566
return self_modulate;
567
}
568
569
void CanvasItem::set_light_mask(int p_light_mask) {
570
ERR_THREAD_GUARD;
571
if (light_mask == p_light_mask) {
572
return;
573
}
574
575
light_mask = p_light_mask;
576
RS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask);
577
}
578
579
int CanvasItem::get_light_mask() const {
580
ERR_READ_THREAD_GUARD_V(0);
581
return light_mask;
582
}
583
584
const StringName *CanvasItem::_instance_shader_parameter_get_remap(const StringName &p_name) const {
585
StringName *r = instance_shader_parameter_property_remap.getptr(p_name);
586
if (!r) {
587
String s = p_name;
588
if (s.begins_with("instance_shader_parameters/")) {
589
StringName name = s.trim_prefix("instance_shader_parameters/");
590
instance_shader_parameter_property_remap[p_name] = name;
591
return instance_shader_parameter_property_remap.getptr(p_name);
592
}
593
return nullptr;
594
}
595
return r;
596
}
597
598
bool CanvasItem::_set(const StringName &p_name, const Variant &p_value) {
599
const StringName *r = _instance_shader_parameter_get_remap(p_name);
600
if (r) {
601
set_instance_shader_parameter(*r, p_value);
602
return true;
603
}
604
return false;
605
}
606
607
bool CanvasItem::_get(const StringName &p_name, Variant &r_ret) const {
608
const StringName *r = _instance_shader_parameter_get_remap(p_name);
609
if (r) {
610
r_ret = get_instance_shader_parameter(*r);
611
return true;
612
}
613
614
return false;
615
}
616
617
void CanvasItem::_get_property_list(List<PropertyInfo> *p_list) const {
618
List<PropertyInfo> pinfo;
619
RS::get_singleton()->canvas_item_get_instance_shader_parameter_list(get_canvas_item(), &pinfo);
620
621
for (PropertyInfo &pi : pinfo) {
622
bool has_def_value = false;
623
Variant def_value = RS::get_singleton()->canvas_item_get_instance_shader_parameter_default_value(get_canvas_item(), pi.name);
624
if (def_value.get_type() != Variant::NIL) {
625
has_def_value = true;
626
}
627
if (instance_shader_parameters.has(pi.name)) {
628
pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : PROPERTY_USAGE_NONE);
629
} else {
630
pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE); // Do not save if not changed.
631
}
632
633
pi.name = "instance_shader_parameters/" + pi.name;
634
p_list->push_back(pi);
635
}
636
}
637
638
void CanvasItem::item_rect_changed(bool p_size_changed) {
639
ERR_MAIN_THREAD_GUARD;
640
if (p_size_changed) {
641
queue_redraw();
642
}
643
emit_signal(SceneStringName(item_rect_changed));
644
}
645
646
void CanvasItem::set_z_index(int p_z) {
647
ERR_THREAD_GUARD;
648
ERR_FAIL_COND(p_z < RS::CANVAS_ITEM_Z_MIN);
649
ERR_FAIL_COND(p_z > RS::CANVAS_ITEM_Z_MAX);
650
z_index = p_z;
651
RS::get_singleton()->canvas_item_set_z_index(canvas_item, z_index);
652
update_configuration_warnings();
653
}
654
655
void CanvasItem::set_z_as_relative(bool p_enabled) {
656
ERR_THREAD_GUARD;
657
if (z_relative == p_enabled) {
658
return;
659
}
660
z_relative = p_enabled;
661
RS::get_singleton()->canvas_item_set_z_as_relative_to_parent(canvas_item, p_enabled);
662
}
663
664
bool CanvasItem::is_z_relative() const {
665
ERR_READ_THREAD_GUARD_V(false);
666
return z_relative;
667
}
668
669
int CanvasItem::get_z_index() const {
670
ERR_READ_THREAD_GUARD_V(0);
671
return z_index;
672
}
673
674
int CanvasItem::get_effective_z_index() const {
675
ERR_READ_THREAD_GUARD_V(0);
676
int effective_z_index = z_index;
677
if (is_z_relative()) {
678
CanvasItem *p = get_parent_item();
679
if (p) {
680
effective_z_index += p->get_effective_z_index();
681
}
682
}
683
return effective_z_index;
684
}
685
686
void CanvasItem::set_y_sort_enabled(bool p_enabled) {
687
ERR_THREAD_GUARD;
688
y_sort_enabled = p_enabled;
689
RS::get_singleton()->canvas_item_set_sort_children_by_y(canvas_item, y_sort_enabled);
690
}
691
692
bool CanvasItem::is_y_sort_enabled() const {
693
ERR_READ_THREAD_GUARD_V(false);
694
return y_sort_enabled;
695
}
696
697
void CanvasItem::draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, real_t p_dash, bool p_aligned, bool p_antialiased) {
698
ERR_THREAD_GUARD;
699
ERR_DRAW_GUARD;
700
ERR_FAIL_COND(p_dash <= 0.0);
701
702
float length = (p_to - p_from).length();
703
Vector2 step = p_dash * (p_to - p_from).normalized();
704
705
if (length < p_dash || step == Vector2()) {
706
RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
707
return;
708
}
709
710
int steps = (p_aligned) ? Math::ceil(length / p_dash) : Math::floor(length / p_dash);
711
if (steps % 2 == 0) {
712
steps--;
713
}
714
715
Point2 off = p_from;
716
if (p_aligned) {
717
off += (p_to - p_from).normalized() * (length - steps * p_dash) / 2.0;
718
}
719
720
Vector<Vector2> points;
721
points.resize(steps + 1);
722
for (int i = 0; i < steps; i += 2) {
723
points.write[i] = (i == 0) ? p_from : off;
724
points.write[i + 1] = (p_aligned && i == steps - 1) ? p_to : (off + step);
725
off += step * 2;
726
}
727
728
Vector<Color> colors = { p_color };
729
730
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, points, colors, p_width, p_antialiased);
731
}
732
733
void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, bool p_antialiased) {
734
ERR_THREAD_GUARD;
735
ERR_DRAW_GUARD;
736
737
RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
738
}
739
740
void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width, bool p_antialiased) {
741
ERR_THREAD_GUARD;
742
ERR_DRAW_GUARD;
743
744
Vector<Color> colors = { p_color };
745
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width, p_antialiased);
746
}
747
748
void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width, bool p_antialiased) {
749
ERR_THREAD_GUARD;
750
ERR_DRAW_GUARD;
751
752
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
753
}
754
755
void CanvasItem::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, bool p_antialiased) {
756
ERR_THREAD_GUARD;
757
Vector<Point2> points;
758
points.resize(p_point_count);
759
Point2 *points_ptr = points.ptrw();
760
761
// Clamp angle difference to full circle so arc won't overlap itself.
762
const real_t delta_angle = CLAMP(p_end_angle - p_start_angle, -Math::TAU, Math::TAU);
763
for (int i = 0; i < p_point_count; i++) {
764
real_t theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle;
765
points_ptr[i] = p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius;
766
}
767
768
draw_polyline(points, p_color, p_width, p_antialiased);
769
}
770
771
void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width, bool p_antialiased) {
772
ERR_THREAD_GUARD;
773
ERR_DRAW_GUARD;
774
775
Vector<Color> colors = { p_color };
776
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, colors, p_width, p_antialiased);
777
}
778
779
void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width, bool p_antialiased) {
780
ERR_THREAD_GUARD;
781
ERR_DRAW_GUARD;
782
783
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width, p_antialiased);
784
}
785
786
void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
787
ERR_THREAD_GUARD;
788
ERR_DRAW_GUARD;
789
790
Rect2 rect = p_rect.abs();
791
792
if (p_filled) {
793
if (p_width != -1.0) {
794
WARN_PRINT("The draw_rect() \"width\" argument has no effect when \"filled\" is \"true\".");
795
}
796
797
RenderingServer::get_singleton()->canvas_item_add_rect(canvas_item, rect, p_color, p_antialiased);
798
} else if (p_width >= rect.size.width || p_width >= rect.size.height) {
799
RenderingServer::get_singleton()->canvas_item_add_rect(canvas_item, rect.grow(0.5f * p_width), p_color, p_antialiased);
800
} else {
801
Vector<Vector2> points;
802
points.resize(5);
803
points.write[0] = rect.position;
804
points.write[1] = rect.position + Vector2(rect.size.x, 0);
805
points.write[2] = rect.position + rect.size;
806
points.write[3] = rect.position + Vector2(0, rect.size.y);
807
points.write[4] = rect.position;
808
809
Vector<Color> colors = { p_color };
810
811
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, points, colors, p_width, p_antialiased);
812
}
813
}
814
815
void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
816
ERR_THREAD_GUARD;
817
ERR_DRAW_GUARD;
818
819
if (p_filled) {
820
if (p_width != -1.0) {
821
WARN_PRINT("The draw_circle() \"width\" argument has no effect when \"filled\" is \"true\".");
822
}
823
824
RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color, p_antialiased);
825
} else if (p_width >= 2.0 * p_radius) {
826
RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius + 0.5 * p_width, p_color, p_antialiased);
827
} else {
828
// Tessellation count is hardcoded. Keep in sync with the same variable in `RendererCanvasCull::canvas_item_add_circle()`.
829
const int circle_segments = 64;
830
831
Vector<Vector2> points;
832
points.resize(circle_segments + 1);
833
834
Vector2 *points_ptr = points.ptrw();
835
const real_t circle_point_step = Math::TAU / circle_segments;
836
837
for (int i = 0; i < circle_segments; i++) {
838
float angle = i * circle_point_step;
839
points_ptr[i].x = Math::cos(angle) * p_radius;
840
points_ptr[i].y = Math::sin(angle) * p_radius;
841
points_ptr[i] += p_pos;
842
}
843
points_ptr[circle_segments] = points_ptr[0];
844
845
Vector<Color> colors = { p_color };
846
847
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, points, colors, p_width, p_antialiased);
848
}
849
}
850
851
void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
852
ERR_THREAD_GUARD;
853
ERR_DRAW_GUARD;
854
855
ERR_FAIL_COND(p_texture.is_null());
856
857
p_texture->draw(canvas_item, p_pos, p_modulate, false);
858
}
859
860
void CanvasItem::draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) {
861
ERR_THREAD_GUARD;
862
ERR_DRAW_GUARD;
863
864
ERR_FAIL_COND(p_texture.is_null());
865
p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose);
866
}
867
868
void CanvasItem::draw_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) {
869
ERR_THREAD_GUARD;
870
ERR_DRAW_GUARD;
871
ERR_FAIL_COND(p_texture.is_null());
872
p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_clip_uv);
873
}
874
875
void CanvasItem::draw_msdf_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, double p_outline, double p_pixel_range, double p_scale) {
876
ERR_THREAD_GUARD;
877
ERR_DRAW_GUARD;
878
ERR_FAIL_COND(p_texture.is_null());
879
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(canvas_item, p_rect, p_texture->get_rid(), p_src_rect, p_modulate, p_outline, p_pixel_range, p_scale);
880
}
881
882
void CanvasItem::draw_lcd_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate) {
883
ERR_THREAD_GUARD;
884
ERR_DRAW_GUARD;
885
ERR_FAIL_COND(p_texture.is_null());
886
RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(canvas_item, p_rect, p_texture->get_rid(), p_src_rect, p_modulate);
887
}
888
889
void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) {
890
ERR_THREAD_GUARD;
891
ERR_DRAW_GUARD;
892
893
ERR_FAIL_COND(p_style_box.is_null());
894
895
p_style_box->draw(canvas_item, p_rect);
896
}
897
898
void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
899
ERR_THREAD_GUARD;
900
ERR_DRAW_GUARD;
901
902
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
903
RenderingServer::get_singleton()->canvas_item_add_primitive(canvas_item, p_points, p_colors, p_uvs, rid);
904
}
905
906
void CanvasItem::draw_set_transform(const Point2 &p_offset, real_t p_rot, const Size2 &p_scale) {
907
ERR_THREAD_GUARD;
908
ERR_DRAW_GUARD;
909
910
Transform2D xform(p_rot, p_offset);
911
xform.scale_basis(p_scale);
912
RenderingServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform);
913
}
914
915
void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) {
916
ERR_THREAD_GUARD;
917
ERR_DRAW_GUARD;
918
919
RenderingServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix);
920
}
921
void CanvasItem::draw_animation_slice(double p_animation_length, double p_slice_begin, double p_slice_end, double p_offset) {
922
ERR_THREAD_GUARD;
923
ERR_DRAW_GUARD;
924
925
RenderingServer::get_singleton()->canvas_item_add_animation_slice(canvas_item, p_animation_length, p_slice_begin, p_slice_end, p_offset);
926
}
927
928
void CanvasItem::draw_end_animation() {
929
ERR_THREAD_GUARD;
930
ERR_DRAW_GUARD;
931
932
RenderingServer::get_singleton()->canvas_item_add_animation_slice(canvas_item, 1, 0, 2, 0);
933
}
934
935
void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
936
ERR_THREAD_GUARD;
937
ERR_DRAW_GUARD;
938
939
const Ref<AtlasTexture> atlas = p_texture;
940
if (atlas.is_valid() && atlas->get_atlas().is_valid()) {
941
const Ref<Texture2D> &texture = atlas->get_atlas();
942
const Vector2 atlas_size = texture->get_size();
943
944
const Vector2 remap_min = atlas->get_region().position / atlas_size;
945
const Vector2 remap_max = atlas->get_region().get_end() / atlas_size;
946
947
PackedVector2Array uvs = p_uvs;
948
for (Vector2 &p : uvs) {
949
p.x = Math::remap(p.x, 0, 1, remap_min.x, remap_max.x);
950
p.y = Math::remap(p.y, 0, 1, remap_min.y, remap_max.y);
951
}
952
RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, uvs, texture->get_rid());
953
} else {
954
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
955
RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, texture_rid);
956
}
957
}
958
959
void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
960
draw_polygon(p_points, { p_color }, p_uvs, p_texture);
961
}
962
963
void CanvasItem::draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Transform2D &p_transform, const Color &p_modulate) {
964
ERR_THREAD_GUARD;
965
ERR_FAIL_COND(p_mesh.is_null());
966
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
967
968
RenderingServer::get_singleton()->canvas_item_add_mesh(canvas_item, p_mesh->get_rid(), p_transform, p_modulate, texture_rid);
969
}
970
971
void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture) {
972
ERR_THREAD_GUARD;
973
ERR_FAIL_COND(p_multimesh.is_null());
974
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
975
RenderingServer::get_singleton()->canvas_item_add_multimesh(canvas_item, p_multimesh->get_rid(), texture_rid);
976
}
977
978
void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, const Color &p_modulate, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation, float p_oversampling) const {
979
ERR_THREAD_GUARD;
980
ERR_DRAW_GUARD;
981
ERR_FAIL_COND(p_font.is_null());
982
983
p_font->draw_string(canvas_item, p_pos, p_text, p_alignment, p_width, p_font_size, p_modulate, p_jst_flags, p_direction, p_orientation, p_oversampling);
984
}
985
986
void CanvasItem::draw_multiline_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, int p_max_lines, const Color &p_modulate, BitField<TextServer::LineBreakFlag> p_brk_flags, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation, float p_oversampling) const {
987
ERR_THREAD_GUARD;
988
ERR_DRAW_GUARD;
989
ERR_FAIL_COND(p_font.is_null());
990
991
p_font->draw_multiline_string(canvas_item, p_pos, p_text, p_alignment, p_width, p_font_size, p_max_lines, p_modulate, p_brk_flags, p_jst_flags, p_direction, p_orientation, p_oversampling);
992
}
993
994
void CanvasItem::draw_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, int p_size, const Color &p_modulate, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation, float p_oversampling) const {
995
ERR_THREAD_GUARD;
996
ERR_DRAW_GUARD;
997
ERR_FAIL_COND(p_font.is_null());
998
999
p_font->draw_string_outline(canvas_item, p_pos, p_text, p_alignment, p_width, p_font_size, p_size, p_modulate, p_jst_flags, p_direction, p_orientation, p_oversampling);
1000
}
1001
1002
void CanvasItem::draw_multiline_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, int p_max_lines, int p_size, const Color &p_modulate, BitField<TextServer::LineBreakFlag> p_brk_flags, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation, float p_oversampling) const {
1003
ERR_THREAD_GUARD;
1004
ERR_DRAW_GUARD;
1005
ERR_FAIL_COND(p_font.is_null());
1006
1007
p_font->draw_multiline_string_outline(canvas_item, p_pos, p_text, p_alignment, p_width, p_font_size, p_max_lines, p_size, p_modulate, p_brk_flags, p_jst_flags, p_direction, p_orientation, p_oversampling);
1008
}
1009
1010
void CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size, const Color &p_modulate, float p_oversampling) const {
1011
ERR_THREAD_GUARD;
1012
ERR_DRAW_GUARD;
1013
ERR_FAIL_COND(p_char.length() != 1);
1014
ERR_FAIL_COND(p_font.is_null());
1015
1016
p_font->draw_char(canvas_item, p_pos, p_char[0], p_font_size, p_modulate, p_oversampling);
1017
}
1018
1019
void CanvasItem::draw_char_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size, int p_size, const Color &p_modulate, float p_oversampling) const {
1020
ERR_THREAD_GUARD;
1021
ERR_DRAW_GUARD;
1022
ERR_FAIL_COND(p_char.length() != 1);
1023
ERR_FAIL_COND(p_font.is_null());
1024
1025
p_font->draw_char_outline(canvas_item, p_pos, p_char[0], p_font_size, p_size, p_modulate, p_oversampling);
1026
}
1027
1028
void CanvasItem::_notify_transform_deferred() {
1029
if (is_inside_tree() && notify_transform && !xform_change.in_list()) {
1030
get_tree()->xform_change_list.add(&xform_change);
1031
}
1032
}
1033
1034
void CanvasItem::_notify_transform(CanvasItem *p_node) {
1035
/* This check exists to avoid re-propagating the transform
1036
* notification down the tree on dirty nodes. It provides
1037
* optimization by avoiding redundancy (nodes are dirty, will get the
1038
* notification anyway).
1039
*/
1040
1041
if (/*p_node->xform_change.in_list() &&*/ p_node->_is_global_invalid()) {
1042
return; //nothing to do
1043
}
1044
1045
p_node->_set_global_invalid(true);
1046
1047
if (p_node->notify_transform && !p_node->xform_change.in_list()) {
1048
if (!p_node->block_transform_notify) {
1049
if (p_node->is_inside_tree()) {
1050
if (is_accessible_from_caller_thread()) {
1051
get_tree()->xform_change_list.add(&p_node->xform_change);
1052
} else {
1053
// Should be rare, but still needs to be handled.
1054
callable_mp(p_node, &CanvasItem::_notify_transform_deferred).call_deferred();
1055
}
1056
}
1057
}
1058
}
1059
1060
for (CanvasItem *ci : p_node->children_items) {
1061
if (ci->top_level) {
1062
continue;
1063
}
1064
_notify_transform(ci);
1065
}
1066
}
1067
1068
void CanvasItem::_physics_interpolated_changed() {
1069
RenderingServer::get_singleton()->canvas_item_set_interpolated(canvas_item, is_physics_interpolated());
1070
}
1071
1072
void CanvasItem::set_canvas_item_use_identity_transform(bool p_enable) {
1073
// Prevent sending item transforms to RenderingServer when using global coords.
1074
_set_use_identity_transform(p_enable);
1075
1076
// Let RenderingServer know not to concatenate the parent transform during the render.
1077
RenderingServer::get_singleton()->canvas_item_set_use_identity_transform(get_canvas_item(), p_enable);
1078
1079
if (is_inside_tree()) {
1080
if (p_enable) {
1081
// Make sure item is using identity transform in server.
1082
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), Transform2D());
1083
} else {
1084
// Make sure item transform is up to date in server if switching identity transform off.
1085
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), get_transform());
1086
}
1087
}
1088
}
1089
1090
Rect2 CanvasItem::get_viewport_rect() const {
1091
ERR_READ_THREAD_GUARD_V(Rect2());
1092
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
1093
return get_viewport()->get_visible_rect();
1094
}
1095
1096
RID CanvasItem::get_canvas() const {
1097
ERR_READ_THREAD_GUARD_V(RID());
1098
ERR_FAIL_COND_V(!is_inside_tree(), RID());
1099
1100
if (canvas_layer) {
1101
return canvas_layer->get_canvas();
1102
} else {
1103
return get_viewport()->find_world_2d()->get_canvas();
1104
}
1105
}
1106
1107
ObjectID CanvasItem::get_canvas_layer_instance_id() const {
1108
ERR_READ_THREAD_GUARD_V(ObjectID());
1109
if (canvas_layer) {
1110
return canvas_layer->get_instance_id();
1111
} else {
1112
return ObjectID();
1113
}
1114
}
1115
1116
CanvasItem *CanvasItem::get_top_level() const {
1117
ERR_READ_THREAD_GUARD_V(nullptr);
1118
CanvasItem *ci = const_cast<CanvasItem *>(this);
1119
while (!ci->top_level && Object::cast_to<CanvasItem>(ci->get_parent())) {
1120
ci = Object::cast_to<CanvasItem>(ci->get_parent());
1121
}
1122
1123
return ci;
1124
}
1125
1126
Ref<World2D> CanvasItem::get_world_2d() const {
1127
ERR_READ_THREAD_GUARD_V(Ref<World2D>());
1128
ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>());
1129
1130
CanvasItem *tl = get_top_level();
1131
1132
if (tl->get_viewport()) {
1133
return tl->get_viewport()->find_world_2d();
1134
} else {
1135
return Ref<World2D>();
1136
}
1137
}
1138
1139
RID CanvasItem::get_viewport_rid() const {
1140
ERR_READ_THREAD_GUARD_V(RID());
1141
ERR_FAIL_COND_V(!is_inside_tree(), RID());
1142
return get_viewport()->get_viewport_rid();
1143
}
1144
1145
void CanvasItem::set_block_transform_notify(bool p_enable) {
1146
ERR_THREAD_GUARD;
1147
block_transform_notify = p_enable;
1148
}
1149
1150
bool CanvasItem::is_block_transform_notify_enabled() const {
1151
ERR_READ_THREAD_GUARD_V(false);
1152
return block_transform_notify;
1153
}
1154
1155
void CanvasItem::set_draw_behind_parent(bool p_enable) {
1156
ERR_THREAD_GUARD;
1157
if (behind == p_enable) {
1158
return;
1159
}
1160
behind = p_enable;
1161
RenderingServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind);
1162
}
1163
1164
bool CanvasItem::is_draw_behind_parent_enabled() const {
1165
ERR_READ_THREAD_GUARD_V(false);
1166
return behind;
1167
}
1168
1169
void CanvasItem::set_material(const Ref<Material> &p_material) {
1170
ERR_THREAD_GUARD;
1171
material = p_material;
1172
RID rid;
1173
if (material.is_valid()) {
1174
rid = material->get_rid();
1175
}
1176
RS::get_singleton()->canvas_item_set_material(canvas_item, rid);
1177
notify_property_list_changed(); //properties for material exposed
1178
}
1179
1180
void CanvasItem::set_use_parent_material(bool p_use_parent_material) {
1181
ERR_THREAD_GUARD;
1182
use_parent_material = p_use_parent_material;
1183
RS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material);
1184
}
1185
1186
void CanvasItem::set_instance_shader_parameter(const StringName &p_name, const Variant &p_value) {
1187
if (p_value.get_type() == Variant::NIL) {
1188
Variant def_value = RS::get_singleton()->canvas_item_get_instance_shader_parameter_default_value(get_canvas_item(), p_name);
1189
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, def_value);
1190
instance_shader_parameters.erase(p_value);
1191
} else {
1192
instance_shader_parameters[p_name] = p_value;
1193
if (p_value.get_type() == Variant::OBJECT) {
1194
RID tex_id = p_value;
1195
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, tex_id);
1196
} else {
1197
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, p_value);
1198
}
1199
}
1200
}
1201
1202
Variant CanvasItem::get_instance_shader_parameter(const StringName &p_name) const {
1203
return RS::get_singleton()->canvas_item_get_instance_shader_parameter(get_canvas_item(), p_name);
1204
}
1205
1206
bool CanvasItem::get_use_parent_material() const {
1207
ERR_READ_THREAD_GUARD_V(false);
1208
return use_parent_material;
1209
}
1210
1211
Ref<Material> CanvasItem::get_material() const {
1212
ERR_READ_THREAD_GUARD_V(Ref<Material>());
1213
return material;
1214
}
1215
1216
Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) const {
1217
ERR_READ_THREAD_GUARD_V(Vector2());
1218
ERR_FAIL_COND_V(!is_inside_tree(), screen_point);
1219
1220
Transform2D local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse();
1221
1222
return local_matrix.xform(screen_point);
1223
}
1224
1225
Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const {
1226
ERR_READ_THREAD_GUARD_V(Ref<InputEvent>());
1227
ERR_FAIL_COND_V(p_event.is_null(), p_event);
1228
ERR_FAIL_COND_V(!is_inside_tree(), p_event);
1229
1230
return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse());
1231
}
1232
1233
Vector2 CanvasItem::get_global_mouse_position() const {
1234
ERR_READ_THREAD_GUARD_V(Vector2());
1235
ERR_FAIL_NULL_V(get_viewport(), Vector2());
1236
return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position());
1237
}
1238
1239
Vector2 CanvasItem::get_local_mouse_position() const {
1240
ERR_READ_THREAD_GUARD_V(Vector2());
1241
ERR_FAIL_NULL_V(get_viewport(), Vector2());
1242
1243
return get_global_transform().affine_inverse().xform(get_global_mouse_position());
1244
}
1245
1246
void CanvasItem::force_update_transform() {
1247
ERR_THREAD_GUARD;
1248
ERR_FAIL_COND(!is_inside_tree());
1249
if (!xform_change.in_list()) {
1250
return;
1251
}
1252
1253
get_tree()->xform_change_list.remove(&xform_change);
1254
1255
notification(NOTIFICATION_TRANSFORM_CHANGED);
1256
}
1257
1258
void CanvasItem::_validate_property(PropertyInfo &p_property) const {
1259
if (hide_clip_children && p_property.name == "clip_children") {
1260
p_property.usage = PROPERTY_USAGE_NONE;
1261
}
1262
}
1263
1264
PackedStringArray CanvasItem::get_configuration_warnings() const {
1265
PackedStringArray warnings = Node::get_configuration_warnings();
1266
1267
if (clip_children_mode != CLIP_CHILDREN_DISABLED && is_inside_tree()) {
1268
bool warned_about_ancestor_clipping = false;
1269
bool warned_about_canvasgroup_ancestor = false;
1270
Node *n = get_parent();
1271
while (n) {
1272
CanvasItem *as_canvas_item = Object::cast_to<CanvasItem>(n);
1273
if (!warned_about_ancestor_clipping && as_canvas_item && as_canvas_item->clip_children_mode != CLIP_CHILDREN_DISABLED) {
1274
warnings.push_back(vformat(RTR("Ancestor \"%s\" clips its children, so this node will not be able to clip its children."), as_canvas_item->get_name()));
1275
warned_about_ancestor_clipping = true;
1276
}
1277
1278
CanvasGroup *as_canvas_group = Object::cast_to<CanvasGroup>(n);
1279
if (!warned_about_canvasgroup_ancestor && as_canvas_group) {
1280
warnings.push_back(vformat(RTR("Ancestor \"%s\" is a CanvasGroup, so this node will not be able to clip its children."), as_canvas_group->get_name()));
1281
warned_about_canvasgroup_ancestor = true;
1282
}
1283
1284
// Only break out early once both warnings have been triggered, so
1285
// that the user is aware of both possible reasons for clipping not working.
1286
if (warned_about_ancestor_clipping && warned_about_canvasgroup_ancestor) {
1287
break;
1288
}
1289
n = n->get_parent();
1290
}
1291
}
1292
1293
return warnings;
1294
}
1295
1296
void CanvasItem::_bind_methods() {
1297
ClassDB::bind_method(D_METHOD("_top_level_raise_self"), &CanvasItem::_top_level_raise_self);
1298
1299
#ifdef TOOLS_ENABLED
1300
ClassDB::bind_method(D_METHOD("_edit_set_state", "state"), &CanvasItem::_edit_set_state);
1301
ClassDB::bind_method(D_METHOD("_edit_get_state"), &CanvasItem::_edit_get_state);
1302
ClassDB::bind_method(D_METHOD("_edit_set_position", "position"), &CanvasItem::_edit_set_position);
1303
ClassDB::bind_method(D_METHOD("_edit_get_position"), &CanvasItem::_edit_get_position);
1304
ClassDB::bind_method(D_METHOD("_edit_set_scale", "scale"), &CanvasItem::_edit_set_scale);
1305
ClassDB::bind_method(D_METHOD("_edit_get_scale"), &CanvasItem::_edit_get_scale);
1306
ClassDB::bind_method(D_METHOD("_edit_set_rect", "rect"), &CanvasItem::_edit_set_rect);
1307
ClassDB::bind_method(D_METHOD("_edit_get_rect"), &CanvasItem::_edit_get_rect);
1308
ClassDB::bind_method(D_METHOD("_edit_use_rect"), &CanvasItem::_edit_use_rect);
1309
ClassDB::bind_method(D_METHOD("_edit_set_rotation", "degrees"), &CanvasItem::_edit_set_rotation);
1310
ClassDB::bind_method(D_METHOD("_edit_get_rotation"), &CanvasItem::_edit_get_rotation);
1311
ClassDB::bind_method(D_METHOD("_edit_use_rotation"), &CanvasItem::_edit_use_rotation);
1312
ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
1313
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
1314
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
1315
ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform);
1316
#endif //TOOLS_ENABLED
1317
1318
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
1319
1320
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &CanvasItem::set_visible);
1321
ClassDB::bind_method(D_METHOD("is_visible"), &CanvasItem::is_visible);
1322
ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &CanvasItem::is_visible_in_tree);
1323
ClassDB::bind_method(D_METHOD("show"), &CanvasItem::show);
1324
ClassDB::bind_method(D_METHOD("hide"), &CanvasItem::hide);
1325
1326
ClassDB::bind_method(D_METHOD("queue_redraw"), &CanvasItem::queue_redraw);
1327
ClassDB::bind_method(D_METHOD("move_to_front"), &CanvasItem::move_to_front);
1328
1329
ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &CanvasItem::set_as_top_level);
1330
ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &CanvasItem::is_set_as_top_level);
1331
1332
ClassDB::bind_method(D_METHOD("set_light_mask", "light_mask"), &CanvasItem::set_light_mask);
1333
ClassDB::bind_method(D_METHOD("get_light_mask"), &CanvasItem::get_light_mask);
1334
1335
ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &CanvasItem::set_modulate);
1336
ClassDB::bind_method(D_METHOD("get_modulate"), &CanvasItem::get_modulate);
1337
1338
ClassDB::bind_method(D_METHOD("set_self_modulate", "self_modulate"), &CanvasItem::set_self_modulate);
1339
ClassDB::bind_method(D_METHOD("get_self_modulate"), &CanvasItem::get_self_modulate);
1340
1341
ClassDB::bind_method(D_METHOD("set_z_index", "z_index"), &CanvasItem::set_z_index);
1342
ClassDB::bind_method(D_METHOD("get_z_index"), &CanvasItem::get_z_index);
1343
1344
ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &CanvasItem::set_z_as_relative);
1345
ClassDB::bind_method(D_METHOD("is_z_relative"), &CanvasItem::is_z_relative);
1346
1347
ClassDB::bind_method(D_METHOD("set_y_sort_enabled", "enabled"), &CanvasItem::set_y_sort_enabled);
1348
ClassDB::bind_method(D_METHOD("is_y_sort_enabled"), &CanvasItem::is_y_sort_enabled);
1349
1350
ClassDB::bind_method(D_METHOD("set_draw_behind_parent", "enable"), &CanvasItem::set_draw_behind_parent);
1351
ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"), &CanvasItem::is_draw_behind_parent_enabled);
1352
1353
ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width", "antialiased"), &CanvasItem::draw_line, DEFVAL(-1.0), DEFVAL(false));
1354
ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash", "aligned", "antialiased"), &CanvasItem::draw_dashed_line, DEFVAL(-1.0), DEFVAL(2.0), DEFVAL(true), DEFVAL(false));
1355
ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(-1.0), DEFVAL(false));
1356
ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(-1.0), DEFVAL(false));
1357
ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_arc, DEFVAL(-1.0), DEFVAL(false));
1358
ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width", "antialiased"), &CanvasItem::draw_multiline, DEFVAL(-1.0), DEFVAL(false));
1359
ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0), DEFVAL(false));
1360
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width", "antialiased"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
1361
ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color", "filled", "width", "antialiased"), &CanvasItem::draw_circle, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
1362
ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
1363
ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false));
1364
ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(true));
1365
ClassDB::bind_method(D_METHOD("draw_msdf_texture_rect_region", "texture", "rect", "src_rect", "modulate", "outline", "pixel_range", "scale"), &CanvasItem::draw_msdf_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(0.0), DEFVAL(4.0), DEFVAL(1.0));
1366
ClassDB::bind_method(D_METHOD("draw_lcd_texture_rect_region", "texture", "rect", "src_rect", "modulate"), &CanvasItem::draw_lcd_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)));
1367
ClassDB::bind_method(D_METHOD("draw_style_box", "style_box", "rect"), &CanvasItem::draw_style_box);
1368
ClassDB::bind_method(D_METHOD("draw_primitive", "points", "colors", "uvs", "texture"), &CanvasItem::draw_primitive, DEFVAL(Ref<Texture2D>()));
1369
ClassDB::bind_method(D_METHOD("draw_polygon", "points", "colors", "uvs", "texture"), &CanvasItem::draw_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()));
1370
ClassDB::bind_method(D_METHOD("draw_colored_polygon", "points", "color", "uvs", "texture"), &CanvasItem::draw_colored_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()));
1371
ClassDB::bind_method(D_METHOD("draw_string", "font", "pos", "text", "alignment", "width", "font_size", "modulate", "justification_flags", "direction", "orientation", "oversampling"), &CanvasItem::draw_string, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND), DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(TextServer::ORIENTATION_HORIZONTAL), DEFVAL(0.0));
1372
ClassDB::bind_method(D_METHOD("draw_multiline_string", "font", "pos", "text", "alignment", "width", "font_size", "max_lines", "modulate", "brk_flags", "justification_flags", "direction", "orientation", "oversampling"), &CanvasItem::draw_multiline_string, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(-1), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND), DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(TextServer::ORIENTATION_HORIZONTAL), DEFVAL(0.0));
1373
ClassDB::bind_method(D_METHOD("draw_string_outline", "font", "pos", "text", "alignment", "width", "font_size", "size", "modulate", "justification_flags", "direction", "orientation", "oversampling"), &CanvasItem::draw_string_outline, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(1), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND), DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(TextServer::ORIENTATION_HORIZONTAL), DEFVAL(0.0));
1374
ClassDB::bind_method(D_METHOD("draw_multiline_string_outline", "font", "pos", "text", "alignment", "width", "font_size", "max_lines", "size", "modulate", "brk_flags", "justification_flags", "direction", "orientation", "oversampling"), &CanvasItem::draw_multiline_string_outline, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(-1), DEFVAL(1), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND), DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(TextServer::ORIENTATION_HORIZONTAL), DEFVAL(0.0));
1375
ClassDB::bind_method(D_METHOD("draw_char", "font", "pos", "char", "font_size", "modulate", "oversampling"), &CanvasItem::draw_char, DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(0.0));
1376
ClassDB::bind_method(D_METHOD("draw_char_outline", "font", "pos", "char", "font_size", "size", "modulate", "oversampling"), &CanvasItem::draw_char_outline, DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(-1), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(0.0));
1377
ClassDB::bind_method(D_METHOD("draw_mesh", "mesh", "texture", "transform", "modulate"), &CanvasItem::draw_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1, 1)));
1378
ClassDB::bind_method(D_METHOD("draw_multimesh", "multimesh", "texture"), &CanvasItem::draw_multimesh);
1379
ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform, DEFVAL(0.0), DEFVAL(Size2(1.0, 1.0)));
1380
ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix);
1381
ClassDB::bind_method(D_METHOD("draw_animation_slice", "animation_length", "slice_begin", "slice_end", "offset"), &CanvasItem::draw_animation_slice, DEFVAL(0.0));
1382
ClassDB::bind_method(D_METHOD("draw_end_animation"), &CanvasItem::draw_end_animation);
1383
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasItem::get_transform);
1384
ClassDB::bind_method(D_METHOD("get_global_transform"), &CanvasItem::get_global_transform);
1385
ClassDB::bind_method(D_METHOD("get_global_transform_with_canvas"), &CanvasItem::get_global_transform_with_canvas);
1386
ClassDB::bind_method(D_METHOD("get_viewport_transform"), &CanvasItem::get_viewport_transform);
1387
ClassDB::bind_method(D_METHOD("get_viewport_rect"), &CanvasItem::get_viewport_rect);
1388
ClassDB::bind_method(D_METHOD("get_canvas_transform"), &CanvasItem::get_canvas_transform);
1389
ClassDB::bind_method(D_METHOD("get_screen_transform"), &CanvasItem::get_screen_transform);
1390
ClassDB::bind_method(D_METHOD("get_local_mouse_position"), &CanvasItem::get_local_mouse_position);
1391
ClassDB::bind_method(D_METHOD("get_global_mouse_position"), &CanvasItem::get_global_mouse_position);
1392
ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasItem::get_canvas);
1393
ClassDB::bind_method(D_METHOD("get_canvas_layer_node"), &CanvasItem::get_canvas_layer_node);
1394
ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d);
1395
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport);
1396
1397
ClassDB::bind_method(D_METHOD("set_material", "material"), &CanvasItem::set_material);
1398
ClassDB::bind_method(D_METHOD("get_material"), &CanvasItem::get_material);
1399
1400
ClassDB::bind_method(D_METHOD("set_instance_shader_parameter", "name", "value"), &CanvasItem::set_instance_shader_parameter);
1401
ClassDB::bind_method(D_METHOD("get_instance_shader_parameter", "name"), &CanvasItem::get_instance_shader_parameter);
1402
1403
ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material);
1404
ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material);
1405
1406
ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &CanvasItem::set_notify_local_transform);
1407
ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &CanvasItem::is_local_transform_notification_enabled);
1408
1409
ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &CanvasItem::set_notify_transform);
1410
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &CanvasItem::is_transform_notification_enabled);
1411
1412
ClassDB::bind_method(D_METHOD("force_update_transform"), &CanvasItem::force_update_transform);
1413
1414
ClassDB::bind_method(D_METHOD("make_canvas_position_local", "viewport_point"), &CanvasItem::make_canvas_position_local);
1415
ClassDB::bind_method(D_METHOD("make_input_local", "event"), &CanvasItem::make_input_local);
1416
1417
ClassDB::bind_method(D_METHOD("set_visibility_layer", "layer"), &CanvasItem::set_visibility_layer);
1418
ClassDB::bind_method(D_METHOD("get_visibility_layer"), &CanvasItem::get_visibility_layer);
1419
ClassDB::bind_method(D_METHOD("set_visibility_layer_bit", "layer", "enabled"), &CanvasItem::set_visibility_layer_bit);
1420
ClassDB::bind_method(D_METHOD("get_visibility_layer_bit", "layer"), &CanvasItem::get_visibility_layer_bit);
1421
1422
ClassDB::bind_method(D_METHOD("set_texture_filter", "mode"), &CanvasItem::set_texture_filter);
1423
ClassDB::bind_method(D_METHOD("get_texture_filter"), &CanvasItem::get_texture_filter);
1424
1425
ClassDB::bind_method(D_METHOD("set_texture_repeat", "mode"), &CanvasItem::set_texture_repeat);
1426
ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasItem::get_texture_repeat);
1427
1428
ClassDB::bind_method(D_METHOD("set_clip_children_mode", "mode"), &CanvasItem::set_clip_children_mode);
1429
ClassDB::bind_method(D_METHOD("get_clip_children_mode"), &CanvasItem::get_clip_children_mode);
1430
1431
GDVIRTUAL_BIND(_draw);
1432
1433
ADD_GROUP("Visibility", "");
1434
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
1435
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
1436
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate");
1437
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled");
1438
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
1439
ADD_PROPERTY(PropertyInfo(Variant::INT, "clip_children", PROPERTY_HINT_ENUM, "Disabled,Clip Only,Clip + Draw"), "set_clip_children_mode", "get_clip_children_mode");
1440
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask");
1441
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_layer", PROPERTY_HINT_LAYERS_2D_RENDER), "set_visibility_layer", "get_visibility_layer");
1442
1443
ADD_GROUP("Ordering", "");
1444
ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index");
1445
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative");
1446
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "y_sort_enabled"), "set_y_sort_enabled", "is_y_sort_enabled");
1447
1448
ADD_GROUP("Texture", "texture_");
1449
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Inherit,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
1450
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Inherit,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat");
1451
1452
ADD_GROUP("Material", "");
1453
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial"), "set_material", "get_material");
1454
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material");
1455
// ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled");
1456
1457
ADD_SIGNAL(MethodInfo("draw"));
1458
ADD_SIGNAL(MethodInfo("visibility_changed"));
1459
ADD_SIGNAL(MethodInfo("hidden"));
1460
ADD_SIGNAL(MethodInfo("item_rect_changed"));
1461
1462
BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
1463
BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
1464
BIND_CONSTANT(NOTIFICATION_DRAW);
1465
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
1466
BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS);
1467
BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS);
1468
BIND_CONSTANT(NOTIFICATION_WORLD_2D_CHANGED);
1469
1470
BIND_ENUM_CONSTANT(TEXTURE_FILTER_PARENT_NODE);
1471
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST);
1472
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR);
1473
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS);
1474
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS);
1475
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC);
1476
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC);
1477
BIND_ENUM_CONSTANT(TEXTURE_FILTER_MAX);
1478
1479
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_PARENT_NODE);
1480
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_DISABLED);
1481
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_ENABLED);
1482
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MIRROR);
1483
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MAX);
1484
1485
BIND_ENUM_CONSTANT(CLIP_CHILDREN_DISABLED);
1486
BIND_ENUM_CONSTANT(CLIP_CHILDREN_ONLY);
1487
BIND_ENUM_CONSTANT(CLIP_CHILDREN_AND_DRAW);
1488
BIND_ENUM_CONSTANT(CLIP_CHILDREN_MAX);
1489
}
1490
1491
Transform2D CanvasItem::get_canvas_transform() const {
1492
ERR_READ_THREAD_GUARD_V(Transform2D());
1493
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
1494
1495
if (canvas_layer) {
1496
return canvas_layer->get_final_transform();
1497
} else if (Object::cast_to<CanvasItem>(get_parent())) {
1498
return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform();
1499
} else {
1500
return get_viewport()->get_canvas_transform();
1501
}
1502
}
1503
1504
Transform2D CanvasItem::get_viewport_transform() const {
1505
ERR_READ_THREAD_GUARD_V(Transform2D());
1506
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
1507
1508
if (canvas_layer) {
1509
return get_viewport()->get_final_transform() * canvas_layer->get_final_transform();
1510
} else {
1511
return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform();
1512
}
1513
}
1514
1515
void CanvasItem::set_notify_local_transform(bool p_enable) {
1516
ERR_THREAD_GUARD;
1517
notify_local_transform = p_enable;
1518
}
1519
1520
bool CanvasItem::is_local_transform_notification_enabled() const {
1521
ERR_READ_THREAD_GUARD_V(false);
1522
return notify_local_transform;
1523
}
1524
1525
void CanvasItem::set_notify_transform(bool p_enable) {
1526
ERR_THREAD_GUARD;
1527
if (notify_transform == p_enable) {
1528
return;
1529
}
1530
1531
notify_transform = p_enable;
1532
1533
if (notify_transform && is_inside_tree()) {
1534
// This ensures that invalid globals get resolved, so notifications can be received.
1535
_ALLOW_DISCARD_ get_global_transform();
1536
}
1537
}
1538
1539
bool CanvasItem::is_transform_notification_enabled() const {
1540
ERR_READ_THREAD_GUARD_V(false);
1541
return notify_transform;
1542
}
1543
1544
int CanvasItem::get_canvas_layer() const {
1545
ERR_READ_THREAD_GUARD_V(0);
1546
if (canvas_layer) {
1547
return canvas_layer->get_layer();
1548
} else {
1549
return 0;
1550
}
1551
}
1552
1553
CanvasLayer *CanvasItem::get_canvas_layer_node() const {
1554
ERR_READ_THREAD_GUARD_V(nullptr);
1555
return canvas_layer;
1556
}
1557
1558
void CanvasItem::set_visibility_layer(uint32_t p_visibility_layer) {
1559
ERR_THREAD_GUARD;
1560
visibility_layer = p_visibility_layer;
1561
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, p_visibility_layer);
1562
}
1563
1564
uint32_t CanvasItem::get_visibility_layer() const {
1565
ERR_READ_THREAD_GUARD_V(0);
1566
return visibility_layer;
1567
}
1568
1569
void CanvasItem::set_visibility_layer_bit(uint32_t p_visibility_layer, bool p_enable) {
1570
ERR_THREAD_GUARD;
1571
ERR_FAIL_UNSIGNED_INDEX(p_visibility_layer, 32);
1572
if (p_enable) {
1573
set_visibility_layer(visibility_layer | (1 << p_visibility_layer));
1574
} else {
1575
set_visibility_layer(visibility_layer & (~(1 << p_visibility_layer)));
1576
}
1577
}
1578
1579
bool CanvasItem::get_visibility_layer_bit(uint32_t p_visibility_layer) const {
1580
ERR_READ_THREAD_GUARD_V(false);
1581
ERR_FAIL_UNSIGNED_INDEX_V(p_visibility_layer, 32, false);
1582
return (visibility_layer & (1 << p_visibility_layer));
1583
}
1584
1585
void CanvasItem::_refresh_texture_filter_cache() const {
1586
if (!is_inside_tree()) {
1587
return;
1588
}
1589
1590
if (texture_filter == TEXTURE_FILTER_PARENT_NODE) {
1591
CanvasItem *parent_item = get_parent_item();
1592
if (parent_item) {
1593
texture_filter_cache = parent_item->texture_filter_cache;
1594
} else {
1595
texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
1596
}
1597
} else {
1598
texture_filter_cache = RS::CanvasItemTextureFilter(texture_filter);
1599
}
1600
}
1601
1602
void CanvasItem::_update_self_texture_filter(RS::CanvasItemTextureFilter p_texture_filter) {
1603
RS::get_singleton()->canvas_item_set_default_texture_filter(get_canvas_item(), p_texture_filter);
1604
queue_redraw();
1605
}
1606
1607
void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
1608
if (!is_inside_tree()) {
1609
return;
1610
}
1611
_refresh_texture_filter_cache();
1612
_update_self_texture_filter(texture_filter_cache);
1613
1614
if (p_propagate) {
1615
for (CanvasItem *E : children_items) {
1616
if (!E->top_level && E->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
1617
E->_update_texture_filter_changed(true);
1618
}
1619
}
1620
}
1621
}
1622
1623
void CanvasItem::set_texture_filter(TextureFilter p_texture_filter) {
1624
ERR_MAIN_THREAD_GUARD; // Goes down in the tree, so only main thread can set.
1625
ERR_FAIL_INDEX(p_texture_filter, TEXTURE_FILTER_MAX);
1626
if (texture_filter == p_texture_filter) {
1627
return;
1628
}
1629
texture_filter = p_texture_filter;
1630
_update_texture_filter_changed(true);
1631
notify_property_list_changed();
1632
}
1633
1634
CanvasItem::TextureFilter CanvasItem::get_texture_filter() const {
1635
ERR_READ_THREAD_GUARD_V(TEXTURE_FILTER_NEAREST);
1636
return texture_filter;
1637
}
1638
1639
void CanvasItem::_refresh_texture_repeat_cache() const {
1640
if (!is_inside_tree()) {
1641
return;
1642
}
1643
1644
if (texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
1645
CanvasItem *parent_item = get_parent_item();
1646
if (parent_item) {
1647
texture_repeat_cache = parent_item->texture_repeat_cache;
1648
} else {
1649
texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
1650
}
1651
} else {
1652
texture_repeat_cache = RS::CanvasItemTextureRepeat(texture_repeat);
1653
}
1654
}
1655
1656
void CanvasItem::_update_self_texture_repeat(RS::CanvasItemTextureRepeat p_texture_repeat) {
1657
RS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), p_texture_repeat);
1658
queue_redraw();
1659
}
1660
1661
void CanvasItem::_update_texture_repeat_changed(bool p_propagate) {
1662
if (!is_inside_tree()) {
1663
return;
1664
}
1665
_refresh_texture_repeat_cache();
1666
_update_self_texture_repeat(texture_repeat_cache);
1667
1668
if (p_propagate) {
1669
for (CanvasItem *E : children_items) {
1670
if (!E->top_level && E->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
1671
E->_update_texture_repeat_changed(true);
1672
}
1673
}
1674
}
1675
}
1676
1677
void CanvasItem::set_texture_repeat(TextureRepeat p_texture_repeat) {
1678
ERR_MAIN_THREAD_GUARD; // Goes down in the tree, so only main thread can set.
1679
ERR_FAIL_INDEX(p_texture_repeat, TEXTURE_REPEAT_MAX);
1680
if (texture_repeat == p_texture_repeat) {
1681
return;
1682
}
1683
texture_repeat = p_texture_repeat;
1684
_update_texture_repeat_changed(true);
1685
notify_property_list_changed();
1686
}
1687
1688
void CanvasItem::set_clip_children_mode(ClipChildrenMode p_clip_mode) {
1689
ERR_THREAD_GUARD;
1690
ERR_FAIL_COND(p_clip_mode >= CLIP_CHILDREN_MAX);
1691
1692
if (clip_children_mode == p_clip_mode) {
1693
return;
1694
}
1695
clip_children_mode = p_clip_mode;
1696
1697
update_configuration_warnings();
1698
1699
if (Object::cast_to<CanvasGroup>(this) != nullptr) {
1700
//avoid accidental bugs, make this not work on CanvasGroup
1701
return;
1702
}
1703
1704
RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CanvasGroupMode(clip_children_mode));
1705
}
1706
1707
CanvasItem::ClipChildrenMode CanvasItem::get_clip_children_mode() const {
1708
ERR_READ_THREAD_GUARD_V(CLIP_CHILDREN_DISABLED);
1709
return clip_children_mode;
1710
}
1711
1712
CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const {
1713
ERR_READ_THREAD_GUARD_V(TEXTURE_REPEAT_DISABLED);
1714
return texture_repeat;
1715
}
1716
1717
CanvasItem::TextureFilter CanvasItem::get_texture_filter_in_tree() const {
1718
ERR_READ_THREAD_GUARD_V(TEXTURE_FILTER_NEAREST);
1719
_refresh_texture_filter_cache();
1720
return (TextureFilter)texture_filter_cache;
1721
}
1722
1723
CanvasItem::TextureRepeat CanvasItem::get_texture_repeat_in_tree() const {
1724
ERR_READ_THREAD_GUARD_V(TEXTURE_REPEAT_DISABLED);
1725
_refresh_texture_repeat_cache();
1726
return (TextureRepeat)texture_repeat_cache;
1727
}
1728
1729
CanvasItem::CanvasItem() :
1730
xform_change(this) {
1731
canvas_item = RenderingServer::get_singleton()->canvas_item_create();
1732
}
1733
1734
CanvasItem::~CanvasItem() {
1735
ERR_FAIL_NULL(RenderingServer::get_singleton());
1736
RenderingServer::get_singleton()->free(canvas_item);
1737
}
1738
1739
///////////////////////////////////////////////////////////////////
1740
1741
void CanvasTexture::set_diffuse_texture(const Ref<Texture2D> &p_diffuse) {
1742
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_diffuse.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
1743
if (diffuse_texture == p_diffuse) {
1744
return;
1745
}
1746
diffuse_texture = p_diffuse;
1747
1748
RID tex_rid = diffuse_texture.is_valid() ? diffuse_texture->get_rid() : RID();
1749
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_DIFFUSE, tex_rid);
1750
emit_changed();
1751
}
1752
Ref<Texture2D> CanvasTexture::get_diffuse_texture() const {
1753
return diffuse_texture;
1754
}
1755
1756
void CanvasTexture::set_normal_texture(const Ref<Texture2D> &p_normal) {
1757
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_normal.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
1758
if (normal_texture == p_normal) {
1759
return;
1760
}
1761
normal_texture = p_normal;
1762
RID tex_rid = normal_texture.is_valid() ? normal_texture->get_rid() : RID();
1763
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_NORMAL, tex_rid);
1764
emit_changed();
1765
}
1766
Ref<Texture2D> CanvasTexture::get_normal_texture() const {
1767
return normal_texture;
1768
}
1769
1770
void CanvasTexture::set_specular_texture(const Ref<Texture2D> &p_specular) {
1771
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_specular.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
1772
if (specular_texture == p_specular) {
1773
return;
1774
}
1775
specular_texture = p_specular;
1776
RID tex_rid = specular_texture.is_valid() ? specular_texture->get_rid() : RID();
1777
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_SPECULAR, tex_rid);
1778
emit_changed();
1779
}
1780
1781
Ref<Texture2D> CanvasTexture::get_specular_texture() const {
1782
return specular_texture;
1783
}
1784
1785
void CanvasTexture::set_specular_color(const Color &p_color) {
1786
if (specular == p_color) {
1787
return;
1788
}
1789
specular = p_color;
1790
RS::get_singleton()->canvas_texture_set_shading_parameters(canvas_texture, specular, shininess);
1791
emit_changed();
1792
}
1793
1794
Color CanvasTexture::get_specular_color() const {
1795
return specular;
1796
}
1797
1798
void CanvasTexture::set_specular_shininess(real_t p_shininess) {
1799
if (shininess == p_shininess) {
1800
return;
1801
}
1802
shininess = p_shininess;
1803
RS::get_singleton()->canvas_texture_set_shading_parameters(canvas_texture, specular, shininess);
1804
emit_changed();
1805
}
1806
1807
real_t CanvasTexture::get_specular_shininess() const {
1808
return shininess;
1809
}
1810
1811
void CanvasTexture::set_texture_filter(CanvasItem::TextureFilter p_filter) {
1812
if (texture_filter == p_filter) {
1813
return;
1814
}
1815
texture_filter = p_filter;
1816
RS::get_singleton()->canvas_texture_set_texture_filter(canvas_texture, RS::CanvasItemTextureFilter(p_filter));
1817
emit_changed();
1818
}
1819
CanvasItem::TextureFilter CanvasTexture::get_texture_filter() const {
1820
return texture_filter;
1821
}
1822
1823
void CanvasTexture::set_texture_repeat(CanvasItem::TextureRepeat p_repeat) {
1824
if (texture_repeat == p_repeat) {
1825
return;
1826
}
1827
texture_repeat = p_repeat;
1828
RS::get_singleton()->canvas_texture_set_texture_repeat(canvas_texture, RS::CanvasItemTextureRepeat(p_repeat));
1829
emit_changed();
1830
}
1831
CanvasItem::TextureRepeat CanvasTexture::get_texture_repeat() const {
1832
return texture_repeat;
1833
}
1834
1835
int CanvasTexture::get_width() const {
1836
if (diffuse_texture.is_valid()) {
1837
return diffuse_texture->get_width();
1838
} else {
1839
return 1;
1840
}
1841
}
1842
int CanvasTexture::get_height() const {
1843
if (diffuse_texture.is_valid()) {
1844
return diffuse_texture->get_height();
1845
} else {
1846
return 1;
1847
}
1848
}
1849
1850
bool CanvasTexture::is_pixel_opaque(int p_x, int p_y) const {
1851
if (diffuse_texture.is_valid()) {
1852
return diffuse_texture->is_pixel_opaque(p_x, p_y);
1853
} else {
1854
return false;
1855
}
1856
}
1857
1858
bool CanvasTexture::has_alpha() const {
1859
if (diffuse_texture.is_valid()) {
1860
return diffuse_texture->has_alpha();
1861
} else {
1862
return false;
1863
}
1864
}
1865
1866
Ref<Image> CanvasTexture::get_image() const {
1867
if (diffuse_texture.is_valid()) {
1868
return diffuse_texture->get_image();
1869
} else {
1870
return Ref<Image>();
1871
}
1872
}
1873
1874
RID CanvasTexture::get_rid() const {
1875
return canvas_texture;
1876
}
1877
1878
void CanvasTexture::_bind_methods() {
1879
ClassDB::bind_method(D_METHOD("set_diffuse_texture", "texture"), &CanvasTexture::set_diffuse_texture);
1880
ClassDB::bind_method(D_METHOD("get_diffuse_texture"), &CanvasTexture::get_diffuse_texture);
1881
1882
ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &CanvasTexture::set_normal_texture);
1883
ClassDB::bind_method(D_METHOD("get_normal_texture"), &CanvasTexture::get_normal_texture);
1884
1885
ClassDB::bind_method(D_METHOD("set_specular_texture", "texture"), &CanvasTexture::set_specular_texture);
1886
ClassDB::bind_method(D_METHOD("get_specular_texture"), &CanvasTexture::get_specular_texture);
1887
1888
ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &CanvasTexture::set_specular_color);
1889
ClassDB::bind_method(D_METHOD("get_specular_color"), &CanvasTexture::get_specular_color);
1890
1891
ClassDB::bind_method(D_METHOD("set_specular_shininess", "shininess"), &CanvasTexture::set_specular_shininess);
1892
ClassDB::bind_method(D_METHOD("get_specular_shininess"), &CanvasTexture::get_specular_shininess);
1893
1894
ClassDB::bind_method(D_METHOD("set_texture_filter", "filter"), &CanvasTexture::set_texture_filter);
1895
ClassDB::bind_method(D_METHOD("get_texture_filter"), &CanvasTexture::get_texture_filter);
1896
1897
ClassDB::bind_method(D_METHOD("set_texture_repeat", "repeat"), &CanvasTexture::set_texture_repeat);
1898
ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasTexture::get_texture_repeat);
1899
1900
ADD_GROUP("Diffuse", "diffuse_");
1901
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "diffuse_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_diffuse_texture", "get_diffuse_texture");
1902
ADD_GROUP("NormalMap", "normal_");
1903
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normal_texture", "get_normal_texture");
1904
ADD_GROUP("Specular", "specular_");
1905
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "specular_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_specular_texture", "get_specular_texture");
1906
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular_color", "get_specular_color");
1907
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "specular_shininess", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_specular_shininess", "get_specular_shininess");
1908
ADD_GROUP("Texture", "texture_");
1909
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "Inherit,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic"), "set_texture_filter", "get_texture_filter");
1910
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Inherit,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat");
1911
}
1912
1913
CanvasTexture::CanvasTexture() {
1914
canvas_texture = RS::get_singleton()->canvas_texture_create();
1915
}
1916
CanvasTexture::~CanvasTexture() {
1917
ERR_FAIL_NULL(RenderingServer::get_singleton());
1918
RS::get_singleton()->free(canvas_texture);
1919
}
1920
1921