2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* canvas_item.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "canvas_item.h"
|
2020-03-01 23:14:37 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/message_queue.h"
|
2020-10-28 19:34:27 +01:00
|
|
|
#include "scene/2d/canvas_group.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/main/canvas_layer.h"
|
2020-03-04 02:51:12 +01:00
|
|
|
#include "scene/main/window.h"
|
2021-08-13 01:05:59 +02:00
|
|
|
#include "scene/resources/canvas_item_material.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/resources/font.h"
|
2021-08-13 01:05:59 +02:00
|
|
|
#include "scene/resources/multimesh.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/resources/style_box.h"
|
2021-08-13 01:05:59 +02:00
|
|
|
#include "scene/resources/world_2d.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/scene_string_names.h"
|
2015-03-02 04:54:10 +01:00
|
|
|
|
2019-10-21 23:37:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2018-03-08 21:35:41 +01:00
|
|
|
bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
|
|
|
|
if (_edit_use_rect()) {
|
|
|
|
return _edit_get_rect().has_point(p_point);
|
|
|
|
} else {
|
|
|
|
return p_point.length() < p_tolerance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 12:11:06 +02:00
|
|
|
Transform2D CanvasItem::_edit_get_transform() const {
|
|
|
|
return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot());
|
|
|
|
}
|
2019-10-21 23:37:07 +02:00
|
|
|
#endif
|
2019-10-20 12:11:06 +02:00
|
|
|
|
2017-01-13 14:45:50 +01:00
|
|
|
bool CanvasItem::is_visible_in_tree() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2022-02-19 13:24:35 +01:00
|
|
|
return visible && parent_visible_in_tree;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 01:13:32 +01:00
|
|
|
void CanvasItem::_propagate_visibility_changed(bool p_parent_visible_in_tree) {
|
|
|
|
parent_visible_in_tree = p_parent_visible_in_tree;
|
|
|
|
if (!visible) {
|
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-22 01:13:32 +01:00
|
|
|
_handle_visibility_change(p_parent_visible_in_tree);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 22:39:59 +01:00
|
|
|
void CanvasItem::set_visible(bool p_visible) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-12 22:39:59 +01:00
|
|
|
if (visible == p_visible) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-12 22:39:59 +01:00
|
|
|
visible = p_visible;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-19 13:24:35 +01:00
|
|
|
if (!parent_visible_in_tree) {
|
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED);
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-22 01:13:32 +01:00
|
|
|
_handle_visibility_change(p_visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_handle_visibility_change(bool p_visible) {
|
|
|
|
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible);
|
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED);
|
|
|
|
|
|
|
|
if (p_visible) {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2022-02-22 01:13:32 +01:00
|
|
|
} else {
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
_block();
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
|
|
|
|
|
|
|
|
if (c) { // Should the top_levels stop propagation? I think so, but...
|
|
|
|
c->_propagate_visibility_changed(p_visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_unblock();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 22:39:59 +01:00
|
|
|
void CanvasItem::show() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-12 22:39:59 +01:00
|
|
|
set_visible(true);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-12 22:39:59 +01:00
|
|
|
void CanvasItem::hide() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-12 22:39:59 +01:00
|
|
|
set_visible(false);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-12 22:39:59 +01:00
|
|
|
bool CanvasItem::is_visible() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2022-01-12 22:39:59 +01:00
|
|
|
return visible;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
CanvasItem *CanvasItem::current_item_drawn = nullptr;
|
2019-01-24 14:21:56 +01:00
|
|
|
CanvasItem *CanvasItem::get_current_item_drawn() {
|
|
|
|
return current_item_drawn;
|
|
|
|
}
|
|
|
|
|
2022-08-13 23:21:24 +02:00
|
|
|
void CanvasItem::_redraw_callback() {
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pending_update = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_clear(get_canvas_item());
|
2014-02-10 02:10:30 +01:00
|
|
|
//todo updating = true - only allow drawing here
|
2022-02-06 00:26:28 +01:00
|
|
|
if (is_visible_in_tree()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
drawing = true;
|
2019-01-24 14:21:56 +01:00
|
|
|
current_item_drawn = this;
|
2014-02-10 02:10:30 +01:00
|
|
|
notification(NOTIFICATION_DRAW);
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->draw);
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_CALL(_draw);
|
2020-04-02 01:20:12 +02:00
|
|
|
current_item_drawn = nullptr;
|
2017-03-05 16:44:50 +01:00
|
|
|
drawing = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
//todo updating = false
|
2017-03-05 16:44:50 +01:00
|
|
|
pending_update = false; // don't change to false until finished drawing (avoid recursive update)
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 22:37:00 +02:00
|
|
|
void CanvasItem::_invalidate_global_transform() {
|
2023-05-17 01:44:41 +02:00
|
|
|
_set_global_invalid(true);
|
2023-03-30 22:37:00 +02:00
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D CanvasItem::get_global_transform_with_canvas() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform2D());
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2022-10-07 12:17:10 +02:00
|
|
|
return canvas_layer->get_final_transform() * get_global_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (is_inside_tree()) {
|
2018-08-19 12:30:31 +02:00
|
|
|
return get_viewport()->get_canvas_transform() * get_global_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-08-19 12:30:31 +02:00
|
|
|
return get_global_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
Transform2D CanvasItem::get_screen_transform() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform2D());
|
2020-03-12 13:37:40 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
|
2022-11-13 21:38:29 +01:00
|
|
|
return get_viewport()->get_popup_base_transform() * get_global_transform_with_canvas();
|
2020-03-12 13:37:40 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D CanvasItem::get_global_transform() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform2D());
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_is_global_invalid()) {
|
2023-05-12 13:53:15 +02:00
|
|
|
// This code can enter multiple times from threads if dirty, this is expected.
|
2014-02-10 02:10:30 +01:00
|
|
|
const CanvasItem *pi = get_parent_item();
|
2023-05-12 13:53:15 +02:00
|
|
|
Transform2D new_global;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pi) {
|
2023-05-12 13:53:15 +02:00
|
|
|
new_global = pi->get_global_transform() * get_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2023-05-12 13:53:15 +02:00
|
|
|
new_global = get_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
global_transform = new_global;
|
2023-05-17 01:44:41 +02:00
|
|
|
_set_global_invalid(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return global_transform;
|
|
|
|
}
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
void CanvasItem::_set_global_invalid(bool p_invalid) const {
|
|
|
|
if (is_group_processing()) {
|
|
|
|
if (p_invalid) {
|
|
|
|
global_invalid.mt.set();
|
|
|
|
} else {
|
|
|
|
global_invalid.mt.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
global_invalid.st = p_invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 23:03:52 +02:00
|
|
|
void CanvasItem::_top_level_raise_self() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_inside_tree()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index());
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index());
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_enter_canvas() {
|
2023-02-02 17:20:31 +01:00
|
|
|
// Resolves to nullptr if the node is top_level.
|
2023-01-09 17:59:55 +01:00
|
|
|
CanvasItem *parent_item = get_parent_item();
|
|
|
|
|
2023-04-05 18:53:32 +02:00
|
|
|
if (get_parent()) {
|
|
|
|
get_viewport()->canvas_parent_mark_dirty(get_parent());
|
|
|
|
}
|
|
|
|
|
2023-01-09 17:59:55 +01:00
|
|
|
if (parent_item) {
|
|
|
|
canvas_layer = parent_item->canvas_layer;
|
|
|
|
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, parent_item->get_canvas_item());
|
|
|
|
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, visibility_layer);
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
Node *n = this;
|
2016-06-07 02:14:25 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
canvas_layer = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (n) {
|
2017-08-24 22:58:51 +02:00
|
|
|
canvas_layer = Object::cast_to<CanvasLayer>(n);
|
2016-06-07 07:39:40 +02:00
|
|
|
if (canvas_layer) {
|
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-07-18 20:34:21 +02:00
|
|
|
if (Object::cast_to<Viewport>(n)) {
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
n = n->get_parent();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RID canvas;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2018-04-08 00:42:11 +02:00
|
|
|
canvas = canvas_layer->get_canvas();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas = get_viewport()->find_world_2d()->get_canvas();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);
|
2021-09-02 20:07:04 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, visibility_layer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-04-17 01:42:21 +02:00
|
|
|
canvas_group = "_root_canvas" + itos(canvas.get_id());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-20 12:44:44 +02:00
|
|
|
add_to_group(canvas_group);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2016-10-03 21:33:42 +02:00
|
|
|
canvas_layer->reset_sort_index();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-10-03 21:33:42 +02:00
|
|
|
get_viewport()->gui_reset_canvas_sort_index();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pending_update = false;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
notification(NOTIFICATION_ENTER_CANVAS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_exit_canvas() {
|
2017-03-05 16:44:50 +01:00
|
|
|
notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
|
2020-04-02 01:20:12 +02:00
|
|
|
canvas_layer = nullptr;
|
2022-07-20 12:44:44 +02:00
|
|
|
if (canvas_group != StringName()) {
|
|
|
|
remove_from_group(canvas_group);
|
|
|
|
canvas_group = StringName();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_notification(int p_what) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_what) {
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2021-10-23 22:30:18 +02:00
|
|
|
ERR_FAIL_COND(!is_inside_tree());
|
2022-02-06 00:26:28 +01:00
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
Node *parent = get_parent();
|
|
|
|
if (parent) {
|
|
|
|
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
|
2022-02-06 00:26:28 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (ci) {
|
2022-02-19 13:24:35 +01:00
|
|
|
parent_visible_in_tree = ci->is_visible_in_tree();
|
2017-03-05 16:44:50 +01:00
|
|
|
C = ci->children_items.push_back(this);
|
2022-02-06 00:26:28 +01:00
|
|
|
} else {
|
|
|
|
CanvasLayer *cl = Object::cast_to<CanvasLayer>(parent);
|
|
|
|
|
|
|
|
if (cl) {
|
2022-02-19 13:24:35 +01:00
|
|
|
parent_visible_in_tree = cl->is_visible();
|
2022-02-06 00:26:28 +01:00
|
|
|
} else {
|
|
|
|
// Look for a window.
|
|
|
|
Viewport *viewport = nullptr;
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
viewport = Object::cast_to<Viewport>(parent);
|
|
|
|
if (viewport) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent = parent->get_parent();
|
2020-03-06 18:00:16 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 00:26:28 +01:00
|
|
|
ERR_FAIL_COND(!viewport);
|
2020-03-06 18:00:16 +01:00
|
|
|
|
2022-02-06 00:26:28 +01:00
|
|
|
window = Object::cast_to<Window>(viewport);
|
|
|
|
if (window) {
|
|
|
|
window->connect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed));
|
2022-02-19 13:24:35 +01:00
|
|
|
parent_visible_in_tree = window->is_visible();
|
2022-02-06 00:26:28 +01:00
|
|
|
} else {
|
2022-02-19 13:24:35 +01:00
|
|
|
parent_visible_in_tree = true;
|
2022-02-06 00:26:28 +01:00
|
|
|
}
|
2020-03-06 18:00:16 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2022-02-06 00:26:28 +01:00
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
_set_global_invalid(true);
|
2023-03-22 20:01:18 +01:00
|
|
|
_enter_canvas();
|
|
|
|
|
2022-07-20 15:43:40 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, is_visible_in_tree()); // The visibility of the parent may change.
|
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED); // Considered invisible until entered.
|
|
|
|
}
|
2021-12-06 06:54:59 +01:00
|
|
|
|
|
|
|
_update_texture_filter_changed(false);
|
|
|
|
_update_texture_repeat_changed(false);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!block_transform_notify && !xform_change.in_list()) {
|
2014-11-06 01:20:42 +01:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2023-04-05 18:53:32 +02:00
|
|
|
if (get_viewport()) {
|
|
|
|
get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()), CONNECT_REFERENCE_COUNTED);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (xform_change.in_list()) {
|
2014-11-06 01:20:42 +01:00
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
_exit_canvas();
|
2014-04-05 23:50:09 +02:00
|
|
|
if (C) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C);
|
2020-04-02 01:20:12 +02:00
|
|
|
C = nullptr;
|
2014-04-05 23:50:09 +02:00
|
|
|
}
|
2020-03-06 18:00:16 +01:00
|
|
|
if (window) {
|
|
|
|
window->disconnect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed));
|
2022-09-02 04:30:08 +02:00
|
|
|
window = nullptr;
|
2020-03-06 18:00:16 +01:00
|
|
|
}
|
2023-05-17 01:44:41 +02:00
|
|
|
_set_global_invalid(true);
|
2022-02-19 13:24:35 +01:00
|
|
|
parent_visible_in_tree = false;
|
2023-04-05 18:53:32 +02:00
|
|
|
|
|
|
|
if (get_viewport()) {
|
|
|
|
get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()));
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
|
|
|
|
} break;
|
2022-01-25 04:01:59 +01:00
|
|
|
case NOTIFICATION_WORLD_2D_CHANGED: {
|
|
|
|
_exit_canvas();
|
|
|
|
_enter_canvas();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 18:53:32 +02:00
|
|
|
void CanvasItem::update_draw_order() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
|
|
2023-04-05 18:53:32 +02:00
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canvas_group != StringName()) {
|
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE | SceneTree::GROUP_CALL_DEFERRED, canvas_group, "_top_level_raise_self");
|
|
|
|
} else {
|
|
|
|
ERR_FAIL_COND_MSG(!get_parent_item(), "Moved child is in incorrect state (no canvas group, no canvas item parent).");
|
|
|
|
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
void CanvasItem::_window_visibility_changed() {
|
2023-04-10 16:18:46 +02:00
|
|
|
_propagate_visibility_changed(window->is_visible());
|
2020-03-06 18:00:16 +01:00
|
|
|
}
|
|
|
|
|
2022-08-13 23:21:24 +02:00
|
|
|
void CanvasItem::queue_redraw() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD; // Calling from thread is safe.
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_inside_tree()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (pending_update) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pending_update = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-08-12 17:55:08 +02:00
|
|
|
MessageQueue::get_singleton()->push_callable(callable_mp(this, &CanvasItem::_redraw_callback));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-04-10 20:52:55 +02:00
|
|
|
void CanvasItem::move_to_front() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-04-10 20:52:55 +02:00
|
|
|
if (!get_parent()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-09-10 03:54:04 +02:00
|
|
|
get_parent()->move_child(this, -1);
|
2022-04-10 20:52:55 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItem::set_modulate(const Color &p_modulate) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (modulate == p_modulate) {
|
2019-08-31 21:50:37 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-31 21:50:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
modulate = p_modulate;
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Color CanvasItem::get_modulate() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Color());
|
2016-10-03 21:33:42 +02:00
|
|
|
return modulate;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-12-19 11:51:37 +01:00
|
|
|
Color CanvasItem::get_modulate_in_tree() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Color());
|
2022-12-19 11:51:37 +01:00
|
|
|
Color final_modulate = modulate;
|
|
|
|
CanvasItem *parent_item = get_parent_item();
|
|
|
|
while (parent_item) {
|
|
|
|
final_modulate *= parent_item->get_modulate();
|
|
|
|
parent_item = parent_item->get_parent_item();
|
|
|
|
}
|
|
|
|
return final_modulate;
|
|
|
|
}
|
|
|
|
|
2020-10-02 23:03:52 +02:00
|
|
|
void CanvasItem::set_as_top_level(bool p_top_level) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2020-10-02 23:03:52 +02:00
|
|
|
if (top_level == p_top_level) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree()) {
|
2020-10-02 23:03:52 +02:00
|
|
|
top_level = p_top_level;
|
2023-03-30 22:37:00 +02:00
|
|
|
propagate_call(SNAME("_invalidate_global_transform"));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit_canvas();
|
2020-10-02 23:03:52 +02:00
|
|
|
top_level = p_top_level;
|
2023-02-02 17:20:31 +01:00
|
|
|
_top_level_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
_enter_canvas();
|
2020-10-27 13:44:35 +01:00
|
|
|
|
|
|
|
_notify_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-02 17:20:31 +01:00
|
|
|
void CanvasItem::_top_level_changed() {
|
|
|
|
// Inform children that top_level status has changed on a parent.
|
2023-02-01 08:45:41 +01:00
|
|
|
int children = get_child_count();
|
|
|
|
for (int i = 0; i < children; i++) {
|
2022-10-16 19:41:42 +02:00
|
|
|
CanvasItem *child = Object::cast_to<CanvasItem>(get_child(i));
|
|
|
|
if (child) {
|
2023-02-02 17:20:31 +01:00
|
|
|
child->_top_level_changed_on_parent();
|
2022-10-16 19:41:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 17:20:31 +01:00
|
|
|
void CanvasItem::_top_level_changed_on_parent() {
|
|
|
|
// Inform children that top_level status has changed on a parent.
|
|
|
|
_top_level_changed();
|
2022-10-16 19:41:42 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 09:17:33 +02:00
|
|
|
bool CanvasItem::is_set_as_top_level() const {
|
|
|
|
return top_level;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem *CanvasItem::get_parent_item() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(nullptr);
|
2020-10-01 09:17:33 +02:00
|
|
|
if (top_level) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
return Object::cast_to<CanvasItem>(get_parent());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItem::set_self_modulate(const Color &p_self_modulate) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (self_modulate == p_self_modulate) {
|
2019-08-31 21:50:37 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-31 21:50:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
self_modulate = p_self_modulate;
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Color CanvasItem::get_self_modulate() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Color());
|
2016-10-03 21:33:42 +02:00
|
|
|
return self_modulate;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 23:39:44 +01:00
|
|
|
void CanvasItem::set_light_mask(int p_light_mask) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (light_mask == p_light_mask) {
|
2019-08-31 21:50:37 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-31 21:50:37 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
light_mask = p_light_mask;
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask);
|
2015-02-18 23:39:44 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int CanvasItem::get_light_mask() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2015-02-18 23:39:44 +01:00
|
|
|
return light_mask;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
void CanvasItem::item_rect_changed(bool p_size_changed) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_size_changed) {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->item_rect_changed);
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:11:06 +01:00
|
|
|
void CanvasItem::set_z_index(int p_z) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-11-29 17:11:06 +01:00
|
|
|
ERR_FAIL_COND(p_z < RS::CANVAS_ITEM_Z_MIN);
|
|
|
|
ERR_FAIL_COND(p_z > RS::CANVAS_ITEM_Z_MAX);
|
|
|
|
z_index = p_z;
|
|
|
|
RS::get_singleton()->canvas_item_set_z_index(canvas_item, z_index);
|
|
|
|
update_configuration_warnings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::set_z_as_relative(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-11-29 17:11:06 +01:00
|
|
|
if (z_relative == p_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
z_relative = p_enabled;
|
|
|
|
RS::get_singleton()->canvas_item_set_z_as_relative_to_parent(canvas_item, p_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::is_z_relative() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2022-11-29 17:11:06 +01:00
|
|
|
return z_relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CanvasItem::get_z_index() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2022-11-29 17:11:06 +01:00
|
|
|
return z_index;
|
|
|
|
}
|
|
|
|
|
2022-11-10 22:55:57 +01:00
|
|
|
int CanvasItem::get_effective_z_index() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2022-11-10 22:55:57 +01:00
|
|
|
int effective_z_index = z_index;
|
|
|
|
if (is_z_relative()) {
|
|
|
|
CanvasItem *p = get_parent_item();
|
|
|
|
if (p) {
|
|
|
|
effective_z_index += p->get_effective_z_index();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return effective_z_index;
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:11:06 +01:00
|
|
|
void CanvasItem::set_y_sort_enabled(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-11-29 17:11:06 +01:00
|
|
|
y_sort_enabled = p_enabled;
|
|
|
|
RS::get_singleton()->canvas_item_set_sort_children_by_y(canvas_item, y_sort_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::is_y_sort_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2022-11-29 17:11:06 +01:00
|
|
|
return y_sort_enabled;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:30:12 +01:00
|
|
|
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) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-02-21 18:34:16 +01:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2023-02-17 07:53:08 +01:00
|
|
|
ERR_FAIL_COND(p_dash <= 0.0);
|
2022-02-21 18:34:16 +01:00
|
|
|
|
|
|
|
float length = (p_to - p_from).length();
|
2023-02-16 16:49:18 +01:00
|
|
|
Vector2 step = p_dash * (p_to - p_from).normalized();
|
|
|
|
|
2023-02-17 07:53:08 +01:00
|
|
|
if (length < p_dash || step == Vector2()) {
|
2022-02-21 18:34:16 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-13 09:30:12 +01:00
|
|
|
int steps = (p_aligned) ? Math::ceil(length / p_dash) : Math::floor(length / p_dash);
|
|
|
|
if (steps % 2 == 0) {
|
|
|
|
steps--;
|
|
|
|
}
|
|
|
|
|
|
|
|
Point2 off = p_from;
|
|
|
|
if (p_aligned) {
|
|
|
|
off += (p_to - p_from).normalized() * (length - steps * p_dash) / 2.0;
|
|
|
|
}
|
2023-02-08 08:44:12 +01:00
|
|
|
|
|
|
|
Vector<Vector2> points;
|
|
|
|
points.resize(steps + 1);
|
2023-01-13 09:30:12 +01:00
|
|
|
for (int i = 0; i < steps; i += 2) {
|
2023-02-08 08:44:12 +01:00
|
|
|
points.write[i] = (i == 0) ? p_from : off;
|
|
|
|
points.write[i + 1] = (p_aligned && i == steps - 1) ? p_to : (off + step);
|
2023-01-13 09:30:12 +01:00
|
|
|
off += step * 2;
|
2022-02-21 18:34:16 +01:00
|
|
|
}
|
2023-02-08 08:44:12 +01:00
|
|
|
|
|
|
|
Vector<Color> colors = { p_color };
|
|
|
|
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, points, colors, p_width);
|
2022-02-21 18:34:16 +01:00
|
|
|
}
|
|
|
|
|
2022-04-11 19:42:46 +02:00
|
|
|
void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, bool p_antialiased) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-11 19:42:46 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width, bool p_antialiased) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2017-07-01 02:30:17 +02:00
|
|
|
|
2023-03-13 22:09:55 +01:00
|
|
|
Vector<Color> colors = { p_color };
|
2020-11-24 16:15:10 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width, p_antialiased);
|
2017-07-01 02:30:17 +02:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width, bool p_antialiased) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2017-07-01 02:30:17 +02:00
|
|
|
|
2020-11-24 16:15:10 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
|
2017-07-01 02:30:17 +02:00
|
|
|
}
|
2017-12-09 18:11:26 +01:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
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) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-10-15 17:47:58 +02:00
|
|
|
Vector<Point2> points;
|
|
|
|
points.resize(p_point_count);
|
2023-01-18 14:51:17 +01:00
|
|
|
Point2 *points_ptr = points.ptrw();
|
|
|
|
|
|
|
|
// Clamp angle difference to full circle so arc won't overlap itself.
|
|
|
|
const real_t delta_angle = CLAMP(p_end_angle - p_start_angle, -Math_TAU, Math_TAU);
|
2019-10-15 17:47:58 +02:00
|
|
|
for (int i = 0; i < p_point_count; i++) {
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle;
|
2023-01-18 14:51:17 +01:00
|
|
|
points_ptr[i] = p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius;
|
2019-10-15 17:47:58 +02:00
|
|
|
}
|
|
|
|
|
2020-11-24 16:15:10 +01:00
|
|
|
draw_polyline(points, p_color, p_width, p_antialiased);
|
2019-10-15 17:47:58 +02:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2017-12-09 18:11:26 +01:00
|
|
|
|
2023-03-13 22:09:55 +01:00
|
|
|
Vector<Color> colors = { p_color };
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, colors, p_width);
|
2017-12-09 18:11:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2017-12-09 18:11:26 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width);
|
2017-12-09 18:11:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled, real_t p_width) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-01-16 13:55:24 +01:00
|
|
|
Rect2 rect = p_rect.abs();
|
|
|
|
|
2017-06-21 21:25:45 +02:00
|
|
|
if (p_filled) {
|
2023-01-14 06:28:55 +01:00
|
|
|
if (p_width != -1.0) {
|
2019-07-09 15:22:01 +02:00
|
|
|
WARN_PRINT("The draw_rect() \"width\" argument has no effect when \"filled\" is \"true\".");
|
|
|
|
}
|
|
|
|
|
2023-01-16 13:55:24 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_rect(canvas_item, rect, p_color);
|
|
|
|
} else if (p_width >= rect.size.width || p_width >= rect.size.height) {
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_rect(canvas_item, rect.grow(0.5f * p_width), p_color);
|
2017-06-21 21:25:45 +02:00
|
|
|
} else {
|
2023-02-08 08:44:12 +01:00
|
|
|
Vector<Vector2> points;
|
|
|
|
points.resize(5);
|
|
|
|
points.write[0] = rect.position;
|
|
|
|
points.write[1] = rect.position + Vector2(rect.size.x, 0);
|
|
|
|
points.write[2] = rect.position + rect.size;
|
|
|
|
points.write[3] = rect.position + Vector2(0, rect.size.y);
|
|
|
|
points.write[4] = rect.position;
|
|
|
|
|
|
|
|
Vector<Color> colors = { p_color };
|
|
|
|
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, points, colors, p_width);
|
2017-06-21 21:25:45 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(p_texture.is_null());
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
p_texture->draw(canvas_item, p_pos, p_modulate, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(p_texture.is_null());
|
2020-10-24 17:15:43 +02:00
|
|
|
p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
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) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(p_texture.is_null());
|
2020-10-24 17:15:43 +02:00
|
|
|
p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_clip_uv);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-12-17 21:47:33 +01:00
|
|
|
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) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-12-27 14:30:33 +01:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_texture.is_null());
|
2022-12-17 21:47:33 +01:00
|
|
|
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);
|
2020-12-27 14:30:33 +01:00
|
|
|
}
|
|
|
|
|
2022-08-12 13:03:28 +02:00
|
|
|
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) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-08-12 13:03:28 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_texture.is_null());
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(canvas_item, p_rect, p_texture->get_rid(), p_src_rect, p_modulate);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(p_style_box.is_null());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
p_style_box->draw(canvas_item, p_rect);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2023-01-14 06:28:55 +01:00
|
|
|
void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
|
2023-01-14 06:28:55 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_primitive(canvas_item, p_points, p_colors, p_uvs, rid);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasItem::draw_set_transform(const Point2 &p_offset, real_t p_rot, const Size2 &p_scale) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D xform(p_rot, p_offset);
|
2014-02-10 02:10:30 +01:00
|
|
|
xform.scale_basis(p_scale);
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2016-06-26 18:01:17 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix);
|
2016-06-26 18:01:17 +02:00
|
|
|
}
|
2021-06-17 16:30:20 +02:00
|
|
|
void CanvasItem::draw_animation_slice(double p_animation_length, double p_slice_begin, double p_slice_end, double p_offset) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-06-17 16:30:20 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_animation_slice(canvas_item, p_animation_length, p_slice_begin, p_slice_end, p_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::draw_end_animation() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-06-17 16:30:20 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
|
|
|
|
RenderingServer::get_singleton()->canvas_item_add_animation_slice(canvas_item, 1, 0, 2, 0);
|
|
|
|
}
|
2016-06-26 18:01:17 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, rid);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-03-13 22:09:55 +01:00
|
|
|
Vector<Color> colors = { p_color };
|
2014-02-10 02:10:30 +01:00
|
|
|
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
|
2020-10-24 17:15:43 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, colors, p_uvs, rid);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Transform2D &p_transform, const Color &p_modulate) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2018-02-21 13:38:21 +01:00
|
|
|
ERR_FAIL_COND(p_mesh.is_null());
|
|
|
|
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_mesh(canvas_item, p_mesh->get_rid(), p_transform, p_modulate, texture_rid);
|
2018-02-21 13:38:21 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2018-02-21 13:38:21 +01:00
|
|
|
ERR_FAIL_COND(p_multimesh.is_null());
|
|
|
|
RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
|
2020-10-24 17:15:43 +02:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_multimesh(canvas_item, p_multimesh->get_rid(), texture_rid);
|
2018-02-21 13:38:21 +01:00
|
|
|
}
|
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
2022-05-09 11:47:10 +02:00
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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);
|
2022-05-09 11:47:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-05-09 11:47:10 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-09-03 13:22:16 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
2022-05-09 11:47:10 +02:00
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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);
|
2020-09-03 13:22:16 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-05-09 11:47:10 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
|
|
|
|
2022-07-11 11:40:31 +02:00
|
|
|
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);
|
2022-05-09 11:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-05-09 11:47:10 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_char.length() != 1);
|
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
|
|
|
|
|
|
|
p_font->draw_char(canvas_item, p_pos, p_char[0], p_font_size, p_modulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-05-09 11:47:10 +02:00
|
|
|
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
|
|
|
|
ERR_FAIL_COND(p_char.length() != 1);
|
|
|
|
ERR_FAIL_COND(p_font.is_null());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-09 11:47:10 +02:00
|
|
|
p_font->draw_char_outline(canvas_item, p_pos, p_char[0], p_font_size, p_size, p_modulate);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
void CanvasItem::_notify_transform_deferred() {
|
|
|
|
if (is_inside_tree() && notify_transform && !xform_change.in_list()) {
|
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItem::_notify_transform(CanvasItem *p_node) {
|
2018-04-07 22:04:12 +02:00
|
|
|
/* This check exists to avoid re-propagating the transform
|
|
|
|
* notification down the tree on dirty nodes. It provides
|
|
|
|
* optimization by avoiding redundancy (nodes are dirty, will get the
|
|
|
|
* notification anyway).
|
|
|
|
*/
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
if (/*p_node->xform_change.in_list() &&*/ p_node->_is_global_invalid()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return; //nothing to do
|
2017-06-25 13:01:15 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
p_node->_set_global_invalid(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-15 12:29:46 +01:00
|
|
|
if (p_node->notify_transform && !p_node->xform_change.in_list()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!p_node->block_transform_notify) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_node->is_inside_tree()) {
|
2023-05-12 13:53:15 +02:00
|
|
|
if (is_accessible_from_caller_thread()) {
|
|
|
|
get_tree()->xform_change_list.add(&p_node->xform_change);
|
|
|
|
} else {
|
|
|
|
// Should be rare, but still needs to be handled.
|
|
|
|
MessageQueue::get_singleton()->push_callable(callable_mp(p_node, &CanvasItem::_notify_transform_deferred));
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 05:45:57 +02:00
|
|
|
for (CanvasItem *ci : p_node->children_items) {
|
2020-10-01 09:17:33 +02:00
|
|
|
if (ci->top_level) {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
_notify_transform(ci);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 CanvasItem::get_viewport_rect() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Rect2());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
|
2014-04-10 05:18:27 +02:00
|
|
|
return get_viewport()->get_visible_rect();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RID CanvasItem::get_canvas() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(RID());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2018-04-08 00:42:11 +02:00
|
|
|
return canvas_layer->get_canvas();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-04-10 05:18:27 +02:00
|
|
|
return get_viewport()->find_world_2d()->get_canvas();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-08-25 00:03:26 +02:00
|
|
|
ObjectID CanvasItem::get_canvas_layer_instance_id() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(ObjectID());
|
2018-08-25 00:03:26 +02:00
|
|
|
if (canvas_layer) {
|
|
|
|
return canvas_layer->get_instance_id();
|
|
|
|
} else {
|
2020-02-12 18:24:06 +01:00
|
|
|
return ObjectID();
|
2018-08-25 00:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 09:17:33 +02:00
|
|
|
CanvasItem *CanvasItem::get_top_level() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(nullptr);
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *ci = const_cast<CanvasItem *>(this);
|
2020-10-01 09:17:33 +02:00
|
|
|
while (!ci->top_level && Object::cast_to<CanvasItem>(ci->get_parent())) {
|
2017-08-24 22:58:51 +02:00
|
|
|
ci = Object::cast_to<CanvasItem>(ci->get_parent());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<World2D> CanvasItem::get_world_2d() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Ref<World2D>());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-01 09:17:33 +02:00
|
|
|
CanvasItem *tl = get_top_level();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-08 00:42:11 +02:00
|
|
|
if (tl->get_viewport()) {
|
2014-04-10 05:18:27 +02:00
|
|
|
return tl->get_viewport()->find_world_2d();
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
return Ref<World2D>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RID CanvasItem::get_viewport_rid() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(RID());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), RID());
|
2017-01-14 15:07:57 +01:00
|
|
|
return get_viewport()->get_viewport_rid();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::set_block_transform_notify(bool p_enable) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2017-03-05 16:44:50 +01:00
|
|
|
block_transform_notify = p_enable;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::is_block_transform_notify_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
return block_transform_notify;
|
|
|
|
}
|
|
|
|
|
2014-04-05 17:39:30 +02:00
|
|
|
void CanvasItem::set_draw_behind_parent(bool p_enable) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (behind == p_enable) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
behind = p_enable;
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool CanvasItem::is_draw_behind_parent_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2014-04-05 17:39:30 +02:00
|
|
|
return behind;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-23 19:31:21 +02:00
|
|
|
void CanvasItem::set_material(const Ref<Material> &p_material) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2017-03-05 16:44:50 +01:00
|
|
|
material = p_material;
|
2015-01-11 15:43:31 +01:00
|
|
|
RID rid;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (material.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
rid = material->get_rid();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_set_material(canvas_item, rid);
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed(); //properties for material exposed
|
2015-01-13 00:44:02 +01:00
|
|
|
}
|
|
|
|
|
2015-03-02 04:54:10 +01:00
|
|
|
void CanvasItem::set_use_parent_material(bool p_use_parent_material) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2017-03-05 16:44:50 +01:00
|
|
|
use_parent_material = p_use_parent_material;
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material);
|
2015-01-13 00:44:02 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool CanvasItem::get_use_parent_material() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2015-03-02 04:54:10 +01:00
|
|
|
return use_parent_material;
|
2015-01-11 15:43:31 +01:00
|
|
|
}
|
|
|
|
|
2017-06-23 19:31:21 +02:00
|
|
|
Ref<Material> CanvasItem::get_material() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Ref<Material>());
|
2015-03-02 04:54:10 +01:00
|
|
|
return material;
|
2015-01-11 15:43:31 +01:00
|
|
|
}
|
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector2());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), screen_point);
|
2016-05-28 09:31:07 +02:00
|
|
|
|
2017-04-07 19:22:34 +02:00
|
|
|
Transform2D local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse();
|
2016-05-28 09:31:07 +02:00
|
|
|
|
|
|
|
return local_matrix.xform(screen_point);
|
|
|
|
}
|
2015-01-11 15:43:31 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Ref<InputEvent>());
|
2019-06-22 14:52:51 +02:00
|
|
|
ERR_FAIL_COND_V(p_event.is_null(), p_event);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), p_event);
|
2015-03-22 05:46:18 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse());
|
2015-03-22 05:46:18 +01:00
|
|
|
}
|
2015-02-11 10:51:20 +01:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
Vector2 CanvasItem::get_global_mouse_position() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector2());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!get_viewport(), Vector2());
|
2017-03-29 17:29:38 +02:00
|
|
|
return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position());
|
2015-05-02 02:13:20 +02:00
|
|
|
}
|
2017-09-10 15:37:49 +02:00
|
|
|
|
|
|
|
Vector2 CanvasItem::get_local_mouse_position() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector2());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!get_viewport(), Vector2());
|
2016-06-21 02:19:12 +02:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
return get_global_transform().affine_inverse().xform(get_global_mouse_position());
|
2015-05-02 02:13:20 +02:00
|
|
|
}
|
|
|
|
|
2018-09-07 01:38:16 +02:00
|
|
|
void CanvasItem::force_update_transform() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2018-09-07 01:38:16 +02:00
|
|
|
ERR_FAIL_COND(!is_inside_tree());
|
|
|
|
if (!xform_change.in_list()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
|
|
|
|
|
|
|
notification(NOTIFICATION_TRANSFORM_CHANGED);
|
|
|
|
}
|
|
|
|
|
2023-01-26 13:17:26 +01:00
|
|
|
void CanvasItem::_validate_property(PropertyInfo &p_property) const {
|
|
|
|
if (hide_clip_children && p_property.name == "clip_children") {
|
|
|
|
p_property.usage = PROPERTY_USAGE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItem::_bind_methods() {
|
2020-10-02 23:03:52 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_top_level_raise_self"), &CanvasItem::_top_level_raise_self);
|
2023-03-30 22:37:00 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_invalidate_global_transform"), &CanvasItem::_invalidate_global_transform);
|
2019-10-21 23:37:07 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2017-11-15 23:03:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_state", "state"), &CanvasItem::_edit_set_state);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_state"), &CanvasItem::_edit_get_state);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_position", "position"), &CanvasItem::_edit_set_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_position"), &CanvasItem::_edit_get_position);
|
2018-03-08 21:35:41 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_scale", "scale"), &CanvasItem::_edit_set_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_scale"), &CanvasItem::_edit_get_scale);
|
2017-11-15 23:03:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_rect", "rect"), &CanvasItem::_edit_set_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_rect"), &CanvasItem::_edit_get_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_use_rect"), &CanvasItem::_edit_use_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_rotation", "degrees"), &CanvasItem::_edit_set_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_rotation"), &CanvasItem::_edit_get_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_use_rotation"), &CanvasItem::_edit_use_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
|
|
|
|
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
|
2019-10-20 12:11:06 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform);
|
2019-10-21 23:37:07 +02:00
|
|
|
#endif
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-07-18 21:03:34 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &CanvasItem::set_visible);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_visible"), &CanvasItem::is_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &CanvasItem::is_visible_in_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("show"), &CanvasItem::show);
|
|
|
|
ClassDB::bind_method(D_METHOD("hide"), &CanvasItem::hide);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2022-08-13 23:21:24 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("queue_redraw"), &CanvasItem::queue_redraw);
|
2022-04-10 20:52:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("move_to_front"), &CanvasItem::move_to_front);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2020-10-02 23:03:52 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &CanvasItem::set_as_top_level);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &CanvasItem::is_set_as_top_level);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_light_mask", "light_mask"), &CanvasItem::set_light_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_light_mask"), &CanvasItem::get_light_mask);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &CanvasItem::set_modulate);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_modulate"), &CanvasItem::get_modulate);
|
2022-11-29 17:11:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_self_modulate", "self_modulate"), &CanvasItem::set_self_modulate);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_self_modulate"), &CanvasItem::get_self_modulate);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2022-12-20 03:59:14 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_z_index", "z_index"), &CanvasItem::set_z_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_z_index"), &CanvasItem::get_z_index);
|
2022-11-29 17:11:06 +01:00
|
|
|
|
2022-12-20 03:59:14 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &CanvasItem::set_z_as_relative);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_z_relative"), &CanvasItem::is_z_relative);
|
2022-11-29 17:11:06 +01:00
|
|
|
|
2022-12-20 03:59:14 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_y_sort_enabled", "enabled"), &CanvasItem::set_y_sort_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_y_sort_enabled"), &CanvasItem::is_y_sort_enabled);
|
2022-11-29 17:11:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_draw_behind_parent", "enable"), &CanvasItem::set_draw_behind_parent);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"), &CanvasItem::is_draw_behind_parent_enabled);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2023-01-14 06:28:55 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width", "antialiased"), &CanvasItem::draw_line, DEFVAL(-1.0), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash", "aligned"), &CanvasItem::draw_dashed_line, DEFVAL(-1.0), DEFVAL(2.0), DEFVAL(true));
|
2023-01-19 13:38:15 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(-1.0), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(-1.0), DEFVAL(false));
|
|
|
|
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));
|
2023-01-14 06:28:55 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width"), &CanvasItem::draw_multiline, DEFVAL(-1.0));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0));
|
2017-09-10 15:37:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::draw_circle);
|
2020-10-24 17:15:43 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
|
|
|
|
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));
|
|
|
|
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));
|
2022-12-17 21:47:33 +01:00
|
|
|
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));
|
2022-08-12 13:03:28 +02:00
|
|
|
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)));
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_style_box", "style_box", "rect"), &CanvasItem::draw_style_box);
|
2023-01-14 06:28:55 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_primitive", "points", "colors", "uvs", "texture"), &CanvasItem::draw_primitive, DEFVAL(Ref<Texture2D>()));
|
2020-10-24 17:15:43 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_polygon", "points", "colors", "uvs", "texture"), &CanvasItem::draw_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_colored_polygon", "points", "color", "uvs", "texture"), &CanvasItem::draw_colored_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()));
|
2023-03-23 10:22:37 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_string", "font", "pos", "text", "alignment", "width", "font_size", "modulate", "justification_flags", "direction", "orientation"), &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));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_multiline_string", "font", "pos", "text", "alignment", "width", "font_size", "max_lines", "modulate", "brk_flags", "justification_flags", "direction", "orientation"), &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));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_string_outline", "font", "pos", "text", "alignment", "width", "font_size", "size", "modulate", "justification_flags", "direction", "orientation"), &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));
|
|
|
|
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"), &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));
|
2022-05-09 11:47:10 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_char", "font", "pos", "char", "font_size", "modulate"), &CanvasItem::draw_char, DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(Color(1.0, 1.0, 1.0)));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_char_outline", "font", "pos", "char", "font_size", "size", "modulate"), &CanvasItem::draw_char_outline, DEFVAL(Font::DEFAULT_FONT_SIZE), DEFVAL(-1), DEFVAL(Color(1.0, 1.0, 1.0)));
|
2020-10-24 17:15:43 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_mesh", "mesh", "texture", "transform", "modulate"), &CanvasItem::draw_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1, 1)));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_multimesh", "multimesh", "texture"), &CanvasItem::draw_multimesh);
|
2020-01-08 19:21:30 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform, DEFVAL(0.0), DEFVAL(Size2(1.0, 1.0)));
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix);
|
2021-06-17 16:30:20 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("draw_animation_slice", "animation_length", "slice_begin", "slice_end", "offset"), &CanvasItem::draw_animation_slice, DEFVAL(0.0));
|
|
|
|
ClassDB::bind_method(D_METHOD("draw_end_animation"), &CanvasItem::draw_end_animation);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasItem::get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform"), &CanvasItem::get_global_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform_with_canvas"), &CanvasItem::get_global_transform_with_canvas);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_viewport_transform"), &CanvasItem::get_viewport_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_viewport_rect"), &CanvasItem::get_viewport_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_canvas_transform"), &CanvasItem::get_canvas_transform);
|
2022-03-13 16:02:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_screen_transform"), &CanvasItem::get_screen_transform);
|
2017-09-10 15:37:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_local_mouse_position"), &CanvasItem::get_local_mouse_position);
|
2017-03-29 17:29:38 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_mouse_position"), &CanvasItem::get_global_mouse_position);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasItem::get_canvas);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d);
|
2017-02-13 12:47:24 +01:00
|
|
|
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport);
|
|
|
|
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_material", "material"), &CanvasItem::set_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_material"), &CanvasItem::get_material);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &CanvasItem::set_notify_local_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &CanvasItem::is_local_transform_notification_enabled);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &CanvasItem::set_notify_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &CanvasItem::is_transform_notification_enabled);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2018-09-07 01:38:16 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("force_update_transform"), &CanvasItem::force_update_transform);
|
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("make_canvas_position_local", "screen_point"), &CanvasItem::make_canvas_position_local);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("make_input_local", "event"), &CanvasItem::make_input_local);
|
2015-03-22 05:46:18 +01:00
|
|
|
|
2021-09-02 20:07:04 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_visibility_layer", "layer"), &CanvasItem::set_visibility_layer);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_visibility_layer"), &CanvasItem::get_visibility_layer);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_visibility_layer_bit", "layer", "enabled"), &CanvasItem::set_visibility_layer_bit);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_visibility_layer_bit", "layer"), &CanvasItem::get_visibility_layer_bit);
|
|
|
|
|
2019-06-25 03:24:07 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_filter", "mode"), &CanvasItem::set_texture_filter);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_filter"), &CanvasItem::get_texture_filter);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_repeat", "mode"), &CanvasItem::set_texture_repeat);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasItem::get_texture_repeat);
|
|
|
|
|
2022-10-12 21:45:47 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_clip_children_mode", "mode"), &CanvasItem::set_clip_children_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_clip_children_mode"), &CanvasItem::get_clip_children_mode);
|
2020-10-28 19:34:27 +01:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_draw);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Visibility", "");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled");
|
2020-10-01 09:17:33 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
|
2022-10-28 14:51:26 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "clip_children", PROPERTY_HINT_ENUM, "Disabled,Clip Only,Clip + Draw"), "set_clip_children_mode", "get_clip_children_mode");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask");
|
2021-09-02 20:07:04 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_layer", PROPERTY_HINT_LAYERS_2D_RENDER), "set_visibility_layer", "get_visibility_layer");
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2022-11-29 17:11:06 +01:00
|
|
|
ADD_GROUP("Ordering", "");
|
|
|
|
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");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "y_sort_enabled"), "set_y_sort_enabled", "is_y_sort_enabled");
|
|
|
|
|
2019-06-25 03:24:07 +02:00
|
|
|
ADD_GROUP("Texture", "texture_");
|
2022-08-23 02:47:58 +02:00
|
|
|
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");
|
2020-06-14 23:02:00 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Inherit,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat");
|
2019-06-25 03:24:07 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Material", "");
|
2021-07-04 17:49:36 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial"), "set_material", "get_material");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material");
|
2018-01-11 23:35:12 +01:00
|
|
|
// ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("draw"));
|
|
|
|
ADD_SIGNAL(MethodInfo("visibility_changed"));
|
2020-12-08 11:02:17 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("hidden"));
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("item_rect_changed"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-21 20:58:02 +02:00
|
|
|
BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
|
2022-03-20 14:59:15 +01:00
|
|
|
BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_CONSTANT(NOTIFICATION_DRAW);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS);
|
2022-01-25 04:01:59 +01:00
|
|
|
BIND_CONSTANT(NOTIFICATION_WORLD_2D_CHANGED);
|
2019-06-25 03:24:07 +02:00
|
|
|
|
2019-07-21 16:31:30 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_PARENT_NODE);
|
2019-06-25 03:24:07 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST);
|
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR);
|
2020-02-20 00:31:43 +01:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS);
|
2019-07-21 16:31:30 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS);
|
2020-02-20 00:31:43 +01:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC);
|
2019-07-21 16:31:30 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC);
|
2019-06-25 03:24:07 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_FILTER_MAX);
|
|
|
|
|
2019-07-21 16:31:30 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_PARENT_NODE);
|
2019-06-25 03:24:07 +02:00
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_DISABLED);
|
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_ENABLED);
|
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MIRROR);
|
|
|
|
BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MAX);
|
2022-10-12 21:45:47 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(CLIP_CHILDREN_DISABLED);
|
|
|
|
BIND_ENUM_CONSTANT(CLIP_CHILDREN_ONLY);
|
|
|
|
BIND_ENUM_CONSTANT(CLIP_CHILDREN_AND_DRAW);
|
|
|
|
BIND_ENUM_CONSTANT(CLIP_CHILDREN_MAX);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D CanvasItem::get_canvas_transform() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform2D());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
|
2014-04-15 03:43:44 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2022-10-07 12:17:10 +02:00
|
|
|
return canvas_layer->get_final_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (Object::cast_to<CanvasItem>(get_parent())) {
|
2017-08-24 22:58:51 +02:00
|
|
|
return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-04-15 03:43:44 +02:00
|
|
|
return get_viewport()->get_canvas_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-04-15 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D CanvasItem::get_viewport_transform() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform2D());
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (canvas_layer) {
|
2022-10-07 12:17:10 +02:00
|
|
|
return get_viewport()->get_final_transform() * canvas_layer->get_final_transform();
|
2016-06-07 07:39:40 +02:00
|
|
|
} else {
|
2014-04-10 05:18:27 +02:00
|
|
|
return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 03:07:03 +02:00
|
|
|
void CanvasItem::set_notify_local_transform(bool p_enable) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2017-03-05 16:44:50 +01:00
|
|
|
notify_local_transform = p_enable;
|
2015-09-16 03:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::is_local_transform_notification_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2015-09-16 03:07:03 +02:00
|
|
|
return notify_local_transform;
|
|
|
|
}
|
|
|
|
|
2017-01-13 00:35:46 +01:00
|
|
|
void CanvasItem::set_notify_transform(bool p_enable) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (notify_transform == p_enable) {
|
2017-06-25 13:01:15 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-06-25 13:01:15 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
notify_transform = p_enable;
|
2017-06-25 13:01:15 +02:00
|
|
|
|
|
|
|
if (notify_transform && is_inside_tree()) {
|
2022-01-19 20:46:17 +01:00
|
|
|
// This ensures that invalid globals get resolved, so notifications can be received.
|
|
|
|
_ALLOW_DISCARD_ get_global_transform();
|
2017-06-25 13:01:15 +02:00
|
|
|
}
|
2017-01-13 00:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::is_transform_notification_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2017-01-13 00:35:46 +01:00
|
|
|
return notify_transform;
|
|
|
|
}
|
|
|
|
|
2016-01-24 14:57:42 +01:00
|
|
|
int CanvasItem::get_canvas_layer() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (canvas_layer) {
|
2016-01-24 14:57:42 +01:00
|
|
|
return canvas_layer->get_layer();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-01-24 14:57:42 +01:00
|
|
|
return 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-01-24 14:57:42 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 20:07:04 +02:00
|
|
|
void CanvasItem::set_visibility_layer(uint32_t p_visibility_layer) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-09-02 20:07:04 +02:00
|
|
|
visibility_layer = p_visibility_layer;
|
|
|
|
RenderingServer::get_singleton()->canvas_item_set_visibility_layer(canvas_item, p_visibility_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CanvasItem::get_visibility_layer() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2021-09-02 20:07:04 +02:00
|
|
|
return visibility_layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::set_visibility_layer_bit(uint32_t p_visibility_layer, bool p_enable) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-11-02 22:36:01 +01:00
|
|
|
ERR_FAIL_UNSIGNED_INDEX(p_visibility_layer, 32);
|
2021-09-02 20:07:04 +02:00
|
|
|
if (p_enable) {
|
|
|
|
set_visibility_layer(visibility_layer | (1 << p_visibility_layer));
|
|
|
|
} else {
|
|
|
|
set_visibility_layer(visibility_layer & (~(1 << p_visibility_layer)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItem::get_visibility_layer_bit(uint32_t p_visibility_layer) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(0);
|
2022-11-02 22:36:01 +01:00
|
|
|
ERR_FAIL_UNSIGNED_INDEX_V(p_visibility_layer, 32, false);
|
2021-09-02 20:07:04 +02:00
|
|
|
return (visibility_layer & (1 << p_visibility_layer));
|
|
|
|
}
|
|
|
|
|
2022-09-28 16:50:58 +02:00
|
|
|
void CanvasItem::_refresh_texture_filter_cache() {
|
2019-06-25 03:24:07 +02:00
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-21 16:31:30 +02:00
|
|
|
if (texture_filter == TEXTURE_FILTER_PARENT_NODE) {
|
2019-06-25 03:24:07 +02:00
|
|
|
CanvasItem *parent_item = get_parent_item();
|
|
|
|
if (parent_item) {
|
|
|
|
texture_filter_cache = parent_item->texture_filter_cache;
|
|
|
|
} else {
|
2020-10-24 17:15:43 +02:00
|
|
|
texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-27 19:21:27 +01:00
|
|
|
texture_filter_cache = RS::CanvasItemTextureFilter(texture_filter);
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
2022-09-28 16:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
|
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_refresh_texture_filter_cache();
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_set_default_texture_filter(get_canvas_item(), texture_filter_cache);
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2019-06-25 03:24:07 +02:00
|
|
|
|
|
|
|
if (p_propagate) {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (CanvasItem *E : children_items) {
|
|
|
|
if (!E->top_level && E->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
|
|
|
|
E->_update_texture_filter_changed(true);
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::set_texture_filter(TextureFilter p_texture_filter) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD; // Goes down in the tree, so only main thread can set.
|
2019-06-25 03:24:07 +02:00
|
|
|
ERR_FAIL_INDEX(p_texture_filter, TEXTURE_FILTER_MAX);
|
|
|
|
if (texture_filter == p_texture_filter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
texture_filter = p_texture_filter;
|
|
|
|
_update_texture_filter_changed(true);
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem::TextureFilter CanvasItem::get_texture_filter() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(TEXTURE_FILTER_NEAREST);
|
2019-06-25 03:24:07 +02:00
|
|
|
return texture_filter;
|
|
|
|
}
|
|
|
|
|
2022-09-28 16:50:58 +02:00
|
|
|
void CanvasItem::_refresh_texture_repeat_cache() {
|
2019-06-25 03:24:07 +02:00
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-21 16:31:30 +02:00
|
|
|
if (texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
|
2019-06-25 03:24:07 +02:00
|
|
|
CanvasItem *parent_item = get_parent_item();
|
|
|
|
if (parent_item) {
|
|
|
|
texture_repeat_cache = parent_item->texture_repeat_cache;
|
|
|
|
} else {
|
2020-10-24 17:15:43 +02:00
|
|
|
texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-27 19:21:27 +01:00
|
|
|
texture_repeat_cache = RS::CanvasItemTextureRepeat(texture_repeat);
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
2022-09-28 16:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::_update_texture_repeat_changed(bool p_propagate) {
|
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_refresh_texture_repeat_cache();
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), texture_repeat_cache);
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2019-06-25 03:24:07 +02:00
|
|
|
if (p_propagate) {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (CanvasItem *E : children_items) {
|
|
|
|
if (!E->top_level && E->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
|
|
|
|
E->_update_texture_repeat_changed(true);
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItem::set_texture_repeat(TextureRepeat p_texture_repeat) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD; // Goes down in the tree, so only main thread can set.
|
2019-06-25 03:24:07 +02:00
|
|
|
ERR_FAIL_INDEX(p_texture_repeat, TEXTURE_REPEAT_MAX);
|
|
|
|
if (texture_repeat == p_texture_repeat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
texture_repeat = p_texture_repeat;
|
|
|
|
_update_texture_repeat_changed(true);
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-06-25 03:24:07 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 21:45:47 +02:00
|
|
|
void CanvasItem::set_clip_children_mode(ClipChildrenMode p_clip_mode) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-10-12 21:45:47 +02:00
|
|
|
ERR_FAIL_COND(p_clip_mode >= CLIP_CHILDREN_MAX);
|
|
|
|
|
|
|
|
if (clip_children_mode == p_clip_mode) {
|
2020-10-28 19:34:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-10-12 21:45:47 +02:00
|
|
|
clip_children_mode = p_clip_mode;
|
2020-10-28 19:34:27 +01:00
|
|
|
|
|
|
|
if (Object::cast_to<CanvasGroup>(this) != nullptr) {
|
|
|
|
//avoid accidental bugs, make this not work on CanvasGroup
|
|
|
|
return;
|
|
|
|
}
|
2022-10-12 21:45:47 +02:00
|
|
|
|
|
|
|
RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CanvasGroupMode(clip_children_mode));
|
2020-10-28 19:34:27 +01:00
|
|
|
}
|
2022-10-12 21:45:47 +02:00
|
|
|
CanvasItem::ClipChildrenMode CanvasItem::get_clip_children_mode() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(CLIP_CHILDREN_DISABLED);
|
2022-10-12 21:45:47 +02:00
|
|
|
return clip_children_mode;
|
2020-10-28 19:34:27 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 03:24:07 +02:00
|
|
|
CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(TEXTURE_REPEAT_DISABLED);
|
2019-06-25 03:24:07 +02:00
|
|
|
return texture_repeat;
|
|
|
|
}
|
|
|
|
|
2022-09-28 16:50:58 +02:00
|
|
|
CanvasItem::TextureFilter CanvasItem::get_texture_filter_in_tree() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(TEXTURE_FILTER_NEAREST);
|
2022-09-28 16:50:58 +02:00
|
|
|
_refresh_texture_filter_cache();
|
|
|
|
return (TextureFilter)texture_filter_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem::TextureRepeat CanvasItem::get_texture_repeat_in_tree() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(TEXTURE_REPEAT_DISABLED);
|
2022-09-28 16:50:58 +02:00
|
|
|
_refresh_texture_repeat_cache();
|
|
|
|
return (TextureRepeat)texture_repeat_cache;
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
CanvasItem::CanvasItem() :
|
|
|
|
xform_change(this) {
|
2020-03-27 19:21:27 +01:00
|
|
|
canvas_item = RenderingServer::get_singleton()->canvas_item_create();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem::~CanvasItem() {
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(RenderingServer::get_singleton());
|
2020-03-27 19:21:27 +01:00
|
|
|
RenderingServer::get_singleton()->free(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-10-24 17:15:43 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CanvasTexture::set_diffuse_texture(const Ref<Texture2D> &p_diffuse) {
|
2021-05-20 12:07:26 +02:00
|
|
|
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_diffuse.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
|
2020-10-24 17:15:43 +02:00
|
|
|
diffuse_texture = p_diffuse;
|
|
|
|
|
|
|
|
RID tex_rid = diffuse_texture.is_valid() ? diffuse_texture->get_rid() : RID();
|
|
|
|
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_DIFFUSE, tex_rid);
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
Ref<Texture2D> CanvasTexture::get_diffuse_texture() const {
|
|
|
|
return diffuse_texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::set_normal_texture(const Ref<Texture2D> &p_normal) {
|
2021-05-20 12:07:26 +02:00
|
|
|
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_normal.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
|
2020-10-24 17:15:43 +02:00
|
|
|
normal_texture = p_normal;
|
|
|
|
RID tex_rid = normal_texture.is_valid() ? normal_texture->get_rid() : RID();
|
|
|
|
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_NORMAL, tex_rid);
|
|
|
|
}
|
|
|
|
Ref<Texture2D> CanvasTexture::get_normal_texture() const {
|
|
|
|
return normal_texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::set_specular_texture(const Ref<Texture2D> &p_specular) {
|
2021-05-20 12:07:26 +02:00
|
|
|
ERR_FAIL_COND_MSG(Object::cast_to<CanvasTexture>(p_specular.ptr()) != nullptr, "Can't self-assign a CanvasTexture");
|
2020-10-24 17:15:43 +02:00
|
|
|
specular_texture = p_specular;
|
|
|
|
RID tex_rid = specular_texture.is_valid() ? specular_texture->get_rid() : RID();
|
|
|
|
RS::get_singleton()->canvas_texture_set_channel(canvas_texture, RS::CANVAS_TEXTURE_CHANNEL_SPECULAR, tex_rid);
|
|
|
|
}
|
2021-01-30 05:10:32 +01:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
Ref<Texture2D> CanvasTexture::get_specular_texture() const {
|
|
|
|
return specular_texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::set_specular_color(const Color &p_color) {
|
|
|
|
specular = p_color;
|
|
|
|
RS::get_singleton()->canvas_texture_set_shading_parameters(canvas_texture, specular, shininess);
|
|
|
|
}
|
2021-01-30 05:10:32 +01:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
Color CanvasTexture::get_specular_color() const {
|
|
|
|
return specular;
|
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void CanvasTexture::set_specular_shininess(real_t p_shininess) {
|
2020-10-24 17:15:43 +02:00
|
|
|
shininess = p_shininess;
|
|
|
|
RS::get_singleton()->canvas_texture_set_shading_parameters(canvas_texture, specular, shininess);
|
|
|
|
}
|
2021-01-30 05:10:32 +01:00
|
|
|
|
|
|
|
real_t CanvasTexture::get_specular_shininess() const {
|
2020-10-24 17:15:43 +02:00
|
|
|
return shininess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::set_texture_filter(CanvasItem::TextureFilter p_filter) {
|
|
|
|
texture_filter = p_filter;
|
|
|
|
RS::get_singleton()->canvas_texture_set_texture_filter(canvas_texture, RS::CanvasItemTextureFilter(p_filter));
|
|
|
|
}
|
|
|
|
CanvasItem::TextureFilter CanvasTexture::get_texture_filter() const {
|
|
|
|
return texture_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::set_texture_repeat(CanvasItem::TextureRepeat p_repeat) {
|
|
|
|
texture_repeat = p_repeat;
|
|
|
|
RS::get_singleton()->canvas_texture_set_texture_repeat(canvas_texture, RS::CanvasItemTextureRepeat(p_repeat));
|
|
|
|
}
|
|
|
|
CanvasItem::TextureRepeat CanvasTexture::get_texture_repeat() const {
|
|
|
|
return texture_repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CanvasTexture::get_width() const {
|
|
|
|
if (diffuse_texture.is_valid()) {
|
|
|
|
return diffuse_texture->get_width();
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int CanvasTexture::get_height() const {
|
|
|
|
if (diffuse_texture.is_valid()) {
|
|
|
|
return diffuse_texture->get_height();
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasTexture::is_pixel_opaque(int p_x, int p_y) const {
|
|
|
|
if (diffuse_texture.is_valid()) {
|
|
|
|
return diffuse_texture->is_pixel_opaque(p_x, p_y);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasTexture::has_alpha() const {
|
|
|
|
if (diffuse_texture.is_valid()) {
|
|
|
|
return diffuse_texture->has_alpha();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-28 13:32:17 +02:00
|
|
|
Ref<Image> CanvasTexture::get_image() const {
|
2020-10-24 17:15:43 +02:00
|
|
|
if (diffuse_texture.is_valid()) {
|
2021-03-28 13:32:17 +02:00
|
|
|
return diffuse_texture->get_image();
|
2020-10-24 17:15:43 +02:00
|
|
|
} else {
|
|
|
|
return Ref<Image>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RID CanvasTexture::get_rid() const {
|
|
|
|
return canvas_texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasTexture::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_diffuse_texture", "texture"), &CanvasTexture::set_diffuse_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_diffuse_texture"), &CanvasTexture::get_diffuse_texture);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &CanvasTexture::set_normal_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_normal_texture"), &CanvasTexture::get_normal_texture);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_specular_texture", "texture"), &CanvasTexture::set_specular_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_specular_texture"), &CanvasTexture::get_specular_texture);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &CanvasTexture::set_specular_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_specular_color"), &CanvasTexture::get_specular_color);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_specular_shininess", "shininess"), &CanvasTexture::set_specular_shininess);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_specular_shininess"), &CanvasTexture::get_specular_shininess);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_filter", "filter"), &CanvasTexture::set_texture_filter);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_filter"), &CanvasTexture::get_texture_filter);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_repeat", "repeat"), &CanvasTexture::set_texture_repeat);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasTexture::get_texture_repeat);
|
|
|
|
|
|
|
|
ADD_GROUP("Diffuse", "diffuse_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "diffuse_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_diffuse_texture", "get_diffuse_texture");
|
2022-04-14 23:20:28 +02:00
|
|
|
ADD_GROUP("NormalMap", "normal_");
|
2020-10-24 17:15:43 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normal_texture", "get_normal_texture");
|
|
|
|
ADD_GROUP("Specular", "specular_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "specular_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_specular_texture", "get_specular_texture");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular_color", "get_specular_color");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "specular_shininess", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_specular_shininess", "get_specular_shininess");
|
|
|
|
ADD_GROUP("Texture", "texture_");
|
2022-08-23 02:47:58 +02:00
|
|
|
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");
|
2020-10-24 17:15:43 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Inherit,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat");
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasTexture::CanvasTexture() {
|
|
|
|
canvas_texture = RS::get_singleton()->canvas_texture_create();
|
|
|
|
}
|
|
|
|
CanvasTexture::~CanvasTexture() {
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(RenderingServer::get_singleton());
|
2020-10-24 17:15:43 +02:00
|
|
|
RS::get_singleton()->free(canvas_texture);
|
|
|
|
}
|