2023-01-10 14:26:54 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* canvas_layer.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-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "canvas_layer.h"
|
2022-02-10 08:50:27 +00:00
|
|
|
#include "scene/2d/canvas_item.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "viewport.h"
|
|
|
|
|
|
|
|
void CanvasLayer::set_layer(int p_xform) {
|
2017-03-05 15:44:50 +00:00
|
|
|
layer = p_xform;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (viewport.is_valid()) {
|
2022-12-12 11:43:01 +00:00
|
|
|
// For the sublayer, we will use the order in which the layer occurs in the scene tree
|
|
|
|
// rather than just the child_id via get_position_in_parent().
|
|
|
|
// We have 32 bits to play with for the sublayer (or more likely 31, as sublayer is signed)
|
|
|
|
// (see Viewport::CanvasKey constructor in visual_server_viewport.h).
|
|
|
|
VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, _layer_order_in_tree);
|
2022-03-24 18:14:14 +00:00
|
|
|
vp->_gui_set_root_order_dirty();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int CanvasLayer::get_layer() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2022-02-10 08:50:27 +00:00
|
|
|
void CanvasLayer::set_visible(bool p_visible) {
|
|
|
|
if (p_visible == visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visible = p_visible;
|
|
|
|
emit_signal("visibility_changed");
|
|
|
|
|
2022-03-07 17:27:58 +00:00
|
|
|
// For CanvasItems that is explicitly top level or has non-CanvasItem parents.
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
const String group = "root_canvas" + itos(canvas.get_id());
|
2022-12-04 06:49:19 +00:00
|
|
|
get_tree()->call_group(group, "_toplevel_visibility_changed", p_visible);
|
2022-02-10 08:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 11:43:01 +00:00
|
|
|
// Make sure layer orders are up to date whenever moving layers in the tree.
|
|
|
|
void CanvasLayer::_update_layer_orders() {
|
|
|
|
if (is_inside_tree() && get_tree()) {
|
|
|
|
Node *root = get_tree()->get_root();
|
|
|
|
if (root) {
|
|
|
|
uint32_t layer_order_count = 0;
|
|
|
|
_calculate_layer_orders_in_tree(root, layer_order_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When rendering layers, if the layer id (set by user) and sublayer (child id) is the same
|
|
|
|
// we need something else sensible which we can sort repeatably to determine which layers should render first,
|
|
|
|
// so we will simply calculate the order that the layers occur throughout the scene tree.
|
|
|
|
void CanvasLayer::_calculate_layer_orders_in_tree(Node *p_node, uint32_t &r_order) {
|
|
|
|
CanvasLayer *layer = Object::cast_to<CanvasLayer>(p_node);
|
|
|
|
if (layer) {
|
|
|
|
layer->_layer_order_in_tree = r_order++;
|
|
|
|
|
|
|
|
// Force an update of the layer order in the VisualServer
|
|
|
|
set_layer(get_layer());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int n = 0; n < p_node->get_child_count(); n++) {
|
|
|
|
_calculate_layer_orders_in_tree(p_node->get_child(n), r_order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 13:25:18 +00:00
|
|
|
void CanvasLayer::show() {
|
|
|
|
set_visible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasLayer::hide() {
|
|
|
|
set_visible(false);
|
|
|
|
}
|
|
|
|
|
2022-02-10 08:50:27 +00:00
|
|
|
bool CanvasLayer::is_visible() const {
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CanvasLayer::set_transform(const Transform2D &p_xform) {
|
|
|
|
transform = p_xform;
|
|
|
|
locrotscale_dirty = true;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (viewport.is_valid()) {
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D CanvasLayer::get_transform() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2022-12-19 18:18:54 +00:00
|
|
|
Transform2D CanvasLayer::get_final_transform() const {
|
|
|
|
if (is_following_viewport()) {
|
|
|
|
Transform2D follow;
|
|
|
|
follow.scale(Vector2(get_follow_viewport_scale(), get_follow_viewport_scale()));
|
|
|
|
if (vp) {
|
|
|
|
follow = vp->get_canvas_transform() * follow;
|
|
|
|
}
|
|
|
|
return follow * transform;
|
|
|
|
}
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void CanvasLayer::_update_xform() {
|
2017-03-05 15:44:50 +00:00
|
|
|
transform.set_rotation_and_scale(rot, scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
transform.set_origin(ofs);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (viewport.is_valid()) {
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasLayer::_update_locrotscale() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ofs = transform.elements[2];
|
|
|
|
rot = transform.get_rotation();
|
|
|
|
scale = transform.get_scale();
|
|
|
|
locrotscale_dirty = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CanvasLayer::set_offset(const Vector2 &p_offset) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ofs = p_offset;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_xform();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 CanvasLayer::get_offset() const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2017-03-05 15:44:50 +00:00
|
|
|
const_cast<CanvasLayer *>(this)->_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return ofs;
|
|
|
|
}
|
|
|
|
|
2016-05-06 21:38:08 +00:00
|
|
|
void CanvasLayer::set_rotation(real_t p_radians) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rot = p_radians;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_xform();
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t CanvasLayer::get_rotation() const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2017-03-05 15:44:50 +00:00
|
|
|
const_cast<CanvasLayer *>(this)->_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return rot;
|
|
|
|
}
|
|
|
|
|
2017-11-10 10:07:52 +00:00
|
|
|
void CanvasLayer::set_rotation_degrees(real_t p_degrees) {
|
2016-05-06 21:38:08 +00:00
|
|
|
set_rotation(Math::deg2rad(p_degrees));
|
|
|
|
}
|
|
|
|
|
2017-11-10 10:07:52 +00:00
|
|
|
real_t CanvasLayer::get_rotation_degrees() const {
|
2016-05-06 21:38:08 +00:00
|
|
|
return Math::rad2deg(get_rotation());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void CanvasLayer::set_scale(const Vector2 &p_scale) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale = p_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_xform();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 CanvasLayer::get_scale() const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (locrotscale_dirty) {
|
2017-03-05 15:44:50 +00:00
|
|
|
const_cast<CanvasLayer *>(this)->_update_locrotscale();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasLayer::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2016-09-14 18:55:14 +00:00
|
|
|
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
vp = custom_viewport;
|
2016-09-14 18:55:14 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
vp = Node::get_viewport();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2021-10-22 02:36:02 +00:00
|
|
|
ERR_FAIL_NULL_MSG(vp, "Viewport is not initialized.");
|
2018-08-24 22:03:26 +00:00
|
|
|
|
|
|
|
vp->_canvas_layer_add(this);
|
2017-03-05 15:44:50 +00:00
|
|
|
viewport = vp->get_viewport_rid();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas);
|
|
|
|
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
|
2019-04-05 13:24:54 +00:00
|
|
|
_update_follow_viewport();
|
2022-12-12 11:43:01 +00:00
|
|
|
_update_layer_orders();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2021-10-22 02:36:02 +00:00
|
|
|
ERR_FAIL_NULL_MSG(vp, "Viewport is not initialized.");
|
2022-12-12 11:43:01 +00:00
|
|
|
_update_layer_orders();
|
2021-10-22 02:36:02 +00:00
|
|
|
|
2018-08-24 22:03:26 +00:00
|
|
|
vp->_canvas_layer_remove(this);
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas);
|
2017-03-05 15:44:50 +00:00
|
|
|
viewport = RID();
|
2019-04-05 13:24:54 +00:00
|
|
|
_update_follow_viewport(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2018-10-30 20:53:00 +00:00
|
|
|
case NOTIFICATION_MOVED_IN_PARENT: {
|
2022-12-12 11:43:01 +00:00
|
|
|
// Note: As this step requires traversing the entire scene tree, it is thus expensive
|
|
|
|
// to move the canvas layer multiple times. Take special care when deleting / moving
|
|
|
|
// multiple nodes to prevent multiple NOTIFICATION_MOVED_IN_PARENT occurring.
|
|
|
|
_update_layer_orders();
|
2018-10-30 20:53:00 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 CanvasLayer::get_viewport_size() const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!is_inside_tree()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
return Size2(1, 1);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-09-14 18:55:14 +00:00
|
|
|
|
2021-10-22 02:36:02 +00:00
|
|
|
ERR_FAIL_NULL_V_MSG(vp, Size2(1, 1), "Viewport is not initialized.");
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Rect2 r = vp->get_visible_rect();
|
|
|
|
return r.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID CanvasLayer::get_viewport() const {
|
|
|
|
return viewport;
|
|
|
|
}
|
|
|
|
|
2016-09-14 18:55:14 +00:00
|
|
|
void CanvasLayer::set_custom_viewport(Node *p_viewport) {
|
2021-10-22 02:36:02 +00:00
|
|
|
ERR_FAIL_NULL_MSG(p_viewport, "Cannot set viewport to nullptr.");
|
2016-09-14 18:55:14 +00:00
|
|
|
if (is_inside_tree()) {
|
2018-08-24 22:03:26 +00:00
|
|
|
vp->_canvas_layer_remove(this);
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas);
|
2017-03-05 15:44:50 +00:00
|
|
|
viewport = RID();
|
2016-09-14 18:55:14 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
custom_viewport = Object::cast_to<Viewport>(p_viewport);
|
2016-09-14 18:55:14 +00:00
|
|
|
|
|
|
|
if (custom_viewport) {
|
2017-08-07 10:17:31 +00:00
|
|
|
custom_viewport_id = custom_viewport->get_instance_id();
|
2016-09-14 18:55:14 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
custom_viewport_id = 0;
|
2016-09-14 18:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_inside_tree()) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (custom_viewport) {
|
2017-03-05 15:44:50 +00:00
|
|
|
vp = custom_viewport;
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
vp = Node::get_viewport();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-09-14 18:55:14 +00:00
|
|
|
|
2018-08-24 22:03:26 +00:00
|
|
|
vp->_canvas_layer_add(this);
|
2017-01-14 14:07:57 +00:00
|
|
|
viewport = vp->get_viewport_rid();
|
2016-09-14 18:55:14 +00:00
|
|
|
|
2018-04-07 22:42:11 +00:00
|
|
|
VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas);
|
|
|
|
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
|
2022-12-12 11:43:01 +00:00
|
|
|
_update_layer_orders();
|
2016-09-14 18:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *CanvasLayer::get_custom_viewport() const {
|
2016-09-14 18:55:14 +00:00
|
|
|
return custom_viewport;
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void CanvasLayer::reset_sort_index() {
|
2017-03-05 15:44:50 +00:00
|
|
|
sort_index = 0;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CanvasLayer::get_sort_index() {
|
|
|
|
return sort_index++;
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:42:11 +00:00
|
|
|
RID CanvasLayer::get_canvas() const {
|
|
|
|
return canvas;
|
|
|
|
}
|
2019-04-05 13:24:54 +00:00
|
|
|
|
|
|
|
void CanvasLayer::set_follow_viewport(bool p_enable) {
|
|
|
|
if (follow_viewport == p_enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
follow_viewport = p_enable;
|
|
|
|
_update_follow_viewport();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasLayer::is_following_viewport() const {
|
|
|
|
return follow_viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasLayer::set_follow_viewport_scale(float p_ratio) {
|
|
|
|
follow_viewport_scale = p_ratio;
|
|
|
|
_update_follow_viewport();
|
|
|
|
}
|
|
|
|
|
|
|
|
float CanvasLayer::get_follow_viewport_scale() const {
|
|
|
|
return follow_viewport_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasLayer::_update_follow_viewport(bool p_force_exit) {
|
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p_force_exit || !follow_viewport) {
|
|
|
|
VS::get_singleton()->canvas_set_parent(canvas, RID(), 1.0);
|
|
|
|
} else {
|
|
|
|
VS::get_singleton()->canvas_set_parent(canvas, vp->get_world_2d()->get_canvas(), follow_viewport_scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void CanvasLayer::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_layer", "layer"), &CanvasLayer::set_layer);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_layer"), &CanvasLayer::get_layer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-02-10 08:50:27 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &CanvasLayer::set_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_visible"), &CanvasLayer::is_visible);
|
2022-02-15 13:25:18 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("show"), &CanvasLayer::show);
|
|
|
|
ClassDB::bind_method(D_METHOD("hide"), &CanvasLayer::hide);
|
2022-02-10 08:50:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CanvasLayer::set_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasLayer::get_transform);
|
2022-12-19 18:18:54 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_final_transform"), &CanvasLayer::get_final_transform);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CanvasLayer::set_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_offset"), &CanvasLayer::get_offset);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &CanvasLayer::set_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation"), &CanvasLayer::get_rotation);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-10 10:07:52 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &CanvasLayer::set_rotation_degrees);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &CanvasLayer::get_rotation_degrees);
|
2016-05-06 21:38:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &CanvasLayer::set_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_scale"), &CanvasLayer::get_scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-04-05 13:24:54 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_follow_viewport", "enable"), &CanvasLayer::set_follow_viewport);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_following_viewport"), &CanvasLayer::is_following_viewport);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_follow_viewport_scale", "scale"), &CanvasLayer::set_follow_viewport_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_follow_viewport_scale"), &CanvasLayer::get_follow_viewport_scale);
|
|
|
|
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport"), &CanvasLayer::set_custom_viewport);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_custom_viewport"), &CanvasLayer::get_custom_viewport);
|
2016-09-14 18:55:14 +00:00
|
|
|
|
2018-04-07 22:42:11 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasLayer::get_canvas);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-04-05 13:24:54 +00:00
|
|
|
ADD_GROUP("Layer", "");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), "set_layer", "get_layer");
|
2022-02-10 08:50:27 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
2019-04-05 13:24:54 +00:00
|
|
|
ADD_GROUP("Transform", "");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
|
2018-08-16 12:36:36 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation_degrees", PROPERTY_HINT_RANGE, "-1080,1080,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees");
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation");
|
2022-06-14 14:33:44 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale", PROPERTY_HINT_LINK), "set_scale", "get_scale");
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform");
|
2019-04-05 13:24:54 +00:00
|
|
|
ADD_GROUP("", "");
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport");
|
2019-04-05 13:24:54 +00:00
|
|
|
ADD_GROUP("Follow Viewport", "follow_viewport");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_viewport_enable"), "set_follow_viewport", "is_following_viewport");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "follow_viewport_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001,or_greater,or_lesser"), "set_follow_viewport_scale", "get_follow_viewport_scale");
|
2022-02-10 08:50:27 +00:00
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("visibility_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 19:12:35 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
StringName CanvasLayer::get_property_store_alias(const StringName &p_property) const {
|
|
|
|
if (p_property == "rotation_degrees") {
|
|
|
|
return "rotation";
|
|
|
|
} else {
|
|
|
|
return Node::get_property_store_alias(p_property);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CanvasLayer::CanvasLayer() {
|
2021-05-04 14:00:45 +00:00
|
|
|
vp = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
scale = Vector2(1, 1);
|
|
|
|
rot = 0;
|
|
|
|
locrotscale_dirty = false;
|
|
|
|
layer = 1;
|
2021-11-09 12:00:07 +00:00
|
|
|
canvas = RID_PRIME(VS::get_singleton()->canvas_create());
|
2021-05-04 14:00:45 +00:00
|
|
|
custom_viewport = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
custom_viewport_id = 0;
|
|
|
|
sort_index = 0;
|
2022-02-10 08:50:27 +00:00
|
|
|
visible = true;
|
2019-04-05 13:24:54 +00:00
|
|
|
follow_viewport = false;
|
|
|
|
follow_viewport_scale = 1.0;
|
2022-12-12 11:43:01 +00:00
|
|
|
_layer_order_in_tree = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2018-04-07 22:42:11 +00:00
|
|
|
|
|
|
|
CanvasLayer::~CanvasLayer() {
|
|
|
|
VS::get_singleton()->free(canvas);
|
|
|
|
}
|