| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  canvas_item.cpp                                                      */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-01 14:40:08 +01:00
										 |  |  | /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* 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-09 22:10:30 -03:00
										 |  |  | #include "canvas_item.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-23 22:03:41 +07:00
										 |  |  | #include "core/method_bind_ext.gen.inc"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "message_queue.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "os/input.h"
 | 
					
						
							|  |  |  | #include "scene/main/canvas_layer.h"
 | 
					
						
							|  |  |  | #include "scene/main/viewport.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "scene/resources/font.h"
 | 
					
						
							|  |  |  | #include "scene/resources/style_box.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/resources/texture.h"
 | 
					
						
							|  |  |  | #include "scene/scene_string_names.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-05 00:30:39 -03:00
										 |  |  | #include "servers/visual/visual_server_raster.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "servers/visual_server.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | Mutex *CanvasItemMaterial::material_mutex = NULL; | 
					
						
							|  |  |  | SelfList<CanvasItemMaterial>::List CanvasItemMaterial::dirty_materials; | 
					
						
							|  |  |  | Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::init_shaders() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	material_mutex = Mutex::create(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::finish_shaders() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef NO_THREADS
 | 
					
						
							|  |  |  | 	memdelete(material_mutex); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::_update_shader() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dirty_materials.remove(&element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MaterialKey mk = _compute_key(); | 
					
						
							|  |  |  | 	if (mk.key == current_key.key) | 
					
						
							|  |  |  | 		return; //no update required in the end
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (shader_map.has(current_key)) { | 
					
						
							|  |  |  | 		shader_map[current_key].users--; | 
					
						
							|  |  |  | 		if (shader_map[current_key].users == 0) { | 
					
						
							|  |  |  | 			//deallocate shader, as it's no longer in use
 | 
					
						
							|  |  |  | 			VS::get_singleton()->free(shader_map[current_key].shader); | 
					
						
							|  |  |  | 			shader_map.erase(current_key); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	current_key = mk; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (shader_map.has(mk)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		VS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); | 
					
						
							|  |  |  | 		shader_map[mk].users++; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//must create a shader!
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String code = "shader_type canvas_item;\nrender_mode "; | 
					
						
							|  |  |  | 	switch (blend_mode) { | 
					
						
							|  |  |  | 		case BLEND_MODE_MIX: code += "blend_mix"; break; | 
					
						
							|  |  |  | 		case BLEND_MODE_ADD: code += "blend_add"; break; | 
					
						
							|  |  |  | 		case BLEND_MODE_SUB: code += "blend_sub"; break; | 
					
						
							|  |  |  | 		case BLEND_MODE_MUL: code += "blend_mul"; break; | 
					
						
							|  |  |  | 		case BLEND_MODE_PREMULT_ALPHA: code += "blend_premul_alpha"; break; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:24:29 +10:00
										 |  |  | 		case BLEND_MODE_DISABLED: code += "blend_disabled"; break; | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (light_mode) { | 
					
						
							|  |  |  | 		case LIGHT_MODE_NORMAL: break; | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | 		case LIGHT_MODE_UNSHADED: code += ",unshaded"; break; | 
					
						
							|  |  |  | 		case LIGHT_MODE_LIGHT_ONLY: code += ",light_only"; break; | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-18 21:37:17 +01:00
										 |  |  | 	code += ";\n"; //that's it.
 | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ShaderData shader_data; | 
					
						
							|  |  |  | 	shader_data.shader = VS::get_singleton()->shader_create(); | 
					
						
							|  |  |  | 	shader_data.users = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VS::get_singleton()->shader_set_code(shader_data.shader, code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	shader_map[mk] = shader_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VS::get_singleton()->material_set_shader(_get_material(), shader_data.shader); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::flush_changes() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->lock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (dirty_materials.first()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dirty_materials.first()->self()->_update_shader(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::_queue_shader_change() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->lock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!element.in_list()) { | 
					
						
							|  |  |  | 		dirty_materials.add(&element); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CanvasItemMaterial::_is_shader_dirty() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool dirty = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->lock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dirty = element.in_list(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return dirty; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void CanvasItemMaterial::set_blend_mode(BlendMode p_blend_mode) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	blend_mode = p_blend_mode; | 
					
						
							|  |  |  | 	_queue_shader_change(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItemMaterial::BlendMode CanvasItemMaterial::get_blend_mode() const { | 
					
						
							|  |  |  | 	return blend_mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::set_light_mode(LightMode p_light_mode) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	light_mode = p_light_mode; | 
					
						
							|  |  |  | 	_queue_shader_change(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItemMaterial::LightMode CanvasItemMaterial::get_light_mode() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return light_mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItemMaterial::_validate_property(PropertyInfo &property) const { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 15:44:51 -03:00
										 |  |  | RID CanvasItemMaterial::get_shader_rid() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); | 
					
						
							|  |  |  | 	return shader_map[current_key].shader; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:43:22 -03:00
										 |  |  | Shader::Mode CanvasItemMaterial::get_shader_mode() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Shader::MODE_CANVAS_ITEM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | void CanvasItemMaterial::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_blend_mode"), &CanvasItemMaterial::get_blend_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_light_mode", "light_mode"), &CanvasItemMaterial::set_light_mode); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_light_mode"), &CanvasItemMaterial::get_light_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,Premult Alpha"), "set_blend_mode", "get_blend_mode"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mode", PROPERTY_HINT_ENUM, "Normal,Unshaded,Light Only"), "set_light_mode", "get_light_mode"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_MIX); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_ADD); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_SUB); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_MUL); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_PREMULT_ALPHA); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(LIGHT_MODE_NORMAL); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(LIGHT_MODE_UNSHADED); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(LIGHT_MODE_LIGHT_ONLY); | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 21:36:34 +01:00
										 |  |  | CanvasItemMaterial::CanvasItemMaterial() : | 
					
						
							|  |  |  | 		element(this) { | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	blend_mode = BLEND_MODE_MIX; | 
					
						
							|  |  |  | 	light_mode = LIGHT_MODE_NORMAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	current_key.key = 0; | 
					
						
							|  |  |  | 	current_key.invalid_key = 1; | 
					
						
							|  |  |  | 	_queue_shader_change(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItemMaterial::~CanvasItemMaterial() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->lock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (shader_map.has(current_key)) { | 
					
						
							|  |  |  | 		shader_map[current_key].users--; | 
					
						
							|  |  |  | 		if (shader_map[current_key].users == 0) { | 
					
						
							|  |  |  | 			//deallocate shader, as it's no longer in use
 | 
					
						
							|  |  |  | 			VS::get_singleton()->free(shader_map[current_key].shader); | 
					
						
							|  |  |  | 			shader_map.erase(current_key); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		VS::get_singleton()->material_set_shader(_get_material(), RID()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (material_mutex) | 
					
						
							|  |  |  | 		material_mutex->unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | ///////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | bool CanvasItem::is_visible_in_tree() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	const CanvasItem *p = this; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while (p) { | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (!p->visible) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		p = p->get_parent_item(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_propagate_visibility_changed(bool p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 12:05:02 +02:00
										 |  |  | 	notification(NOTIFICATION_VISIBILITY_CHANGED); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) | 
					
						
							|  |  |  | 		update(); //todo optimize
 | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		emit_signal(SceneStringNames::get_singleton()->hide); | 
					
						
							|  |  |  | 	_block(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < get_child_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (c && c->visible) //should the toplevels stop propagation? i think so but..
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			c->_propagate_visibility_changed(p_visible); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_unblock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::show() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (visible) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	visible = true; | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-28 14:27:27 +09:00
										 |  |  | 	_propagate_visibility_changed(true); | 
					
						
							| 
									
										
										
										
											2017-04-03 18:34:44 +02:00
										 |  |  | 	_change_notify("visible"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::hide() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (!visible) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	visible = false; | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-28 14:27:27 +09:00
										 |  |  | 	_propagate_visibility_changed(false); | 
					
						
							| 
									
										
										
										
											2017-04-03 18:34:44 +02:00
										 |  |  | 	_change_notify("visible"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_update_callback() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		pending_update = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_clear(get_canvas_item()); | 
					
						
							|  |  |  | 	//todo updating = true - only allow drawing here
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (is_visible_in_tree()) { //todo optimize this!!
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (first_draw) { | 
					
						
							|  |  |  | 			notification(NOTIFICATION_VISIBILITY_CHANGED); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			first_draw = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		drawing = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		notification(NOTIFICATION_DRAW); | 
					
						
							|  |  |  | 		emit_signal(SceneStringNames::get_singleton()->draw); | 
					
						
							|  |  |  | 		if (get_script_instance()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, NULL, 0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		drawing = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03: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-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | Transform2D CanvasItem::get_global_transform_with_canvas() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-19 12:30:31 +02:00
										 |  |  | 	if (canvas_layer) | 
					
						
							|  |  |  | 		return canvas_layer->get_transform() * get_global_transform(); | 
					
						
							| 
									
										
										
										
											2016-01-02 11:23:30 -03:00
										 |  |  | 	else if (is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2018-08-19 12:30:31 +02:00
										 |  |  | 		return get_viewport()->get_canvas_transform() * get_global_transform(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return get_global_transform(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | Transform2D CanvasItem::get_global_transform() const { | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), get_transform()); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (global_invalid) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const CanvasItem *pi = get_parent_item(); | 
					
						
							|  |  |  | 		if (pi) | 
					
						
							|  |  |  | 			global_transform = pi->get_global_transform() * get_transform(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			global_transform = get_transform(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		global_invalid = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return global_transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | void CanvasItem::_toplevel_raise_self() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 	if (canvas_layer) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index()); | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_enter_canvas() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Node *n = this; | 
					
						
							| 
									
										
										
										
											2016-06-06 21:14:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_layer = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (n) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-09 22:10:30 -03: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-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RID canvas; | 
					
						
							|  |  |  | 		if (canvas_layer) | 
					
						
							| 
									
										
										
										
											2018-04-07 19:42:11 -03:00
										 |  |  | 			canvas = canvas_layer->get_canvas(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			canvas = get_viewport()->find_world_2d()->get_canvas(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		group = "root_canvas" + itos(canvas.get_id()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		add_to_group(group); | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 		if (canvas_layer) | 
					
						
							|  |  |  | 			canvas_layer->reset_sort_index(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			get_viewport()->gui_reset_canvas_sort_index(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		CanvasItem *parent = get_parent_item(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_layer = parent->canvas_layer; | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item()); | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	pending_update = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	notification(NOTIFICATION_ENTER_CANVAS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_exit_canvas() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
 | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, RID()); | 
					
						
							|  |  |  | 	canvas_layer = NULL; | 
					
						
							|  |  |  | 	group = ""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			first_draw = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			if (get_parent()) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 				CanvasItem *ci = Object::cast_to<CanvasItem>(get_parent()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				if (ci) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					C = ci->children_items.push_back(this); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			_enter_canvas(); | 
					
						
							|  |  |  | 			if (!block_transform_notify && !xform_change.in_list()) { | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 				get_tree()->xform_change_list.add(&xform_change); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_MOVED_IN_PARENT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 			if (!is_inside_tree()) | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (group != "") { | 
					
						
							|  |  |  | 				get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				CanvasItem *p = get_parent_item(); | 
					
						
							|  |  |  | 				ERR_FAIL_COND(!p); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 		case NOTIFICATION_EXIT_TREE: { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			if (xform_change.in_list()) | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 				get_tree()->xform_change_list.remove(&xform_change); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			_exit_canvas(); | 
					
						
							| 
									
										
										
										
											2014-04-05 18:50:09 -03:00
										 |  |  | 			if (C) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 				Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				C = NULL; | 
					
						
							| 
									
										
										
										
											2014-04-05 18:50:09 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			global_invalid = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_TRANSFORM_CHANGED: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_VISIBILITY_CHANGED: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			emit_signal(SceneStringNames::get_singleton()->visibility_changed); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | void CanvasItem::set_visible(bool p_visible) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) | 
					
						
							|  |  |  | 		show(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		hide(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | bool CanvasItem::is_visible() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	return visible; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::update() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	if (pending_update) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	pending_update = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	MessageQueue::get_singleton()->push_call(this, "_update_callback"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::set_modulate(const Color &p_modulate) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	modulate = p_modulate; | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | Color CanvasItem::get_modulate() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 	return modulate; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::set_as_toplevel(bool p_toplevel) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (toplevel == p_toplevel) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		toplevel = p_toplevel; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_exit_canvas(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	toplevel = p_toplevel; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_enter_canvas(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CanvasItem::is_set_as_toplevel() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return toplevel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItem *CanvasItem::get_parent_item() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (toplevel) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	return Object::cast_to<CanvasItem>(get_parent()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::set_self_modulate(const Color &p_self_modulate) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	self_modulate = p_self_modulate; | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | Color CanvasItem::get_self_modulate() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 	return self_modulate; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 19:39:44 -03:00
										 |  |  | void CanvasItem::set_light_mask(int p_light_mask) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	light_mask = p_light_mask; | 
					
						
							|  |  |  | 	VS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask); | 
					
						
							| 
									
										
										
										
											2015-02-18 19:39:44 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int CanvasItem::get_light_mask() const { | 
					
						
							| 
									
										
										
										
											2015-02-18 19:39:44 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return light_mask; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 23:44:14 -03:00
										 |  |  | void CanvasItem::item_rect_changed(bool p_size_changed) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 23:44:14 -03:00
										 |  |  | 	if (p_size_changed) | 
					
						
							|  |  |  | 		update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	emit_signal(SceneStringNames::get_singleton()->item_rect_changed); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-30 21:30:17 -03:00
										 |  |  | void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Color> colors; | 
					
						
							|  |  |  | 	colors.push_back(p_color); | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width, p_antialiased); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-09 14:11:26 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Color> colors; | 
					
						
							|  |  |  | 	colors.push_back(p_color); | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, colors, p_width, p_antialiased); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width, p_antialiased); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 16:25:45 -03:00
										 |  |  | void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 16:25:45 -03:00
										 |  |  | 	if (p_filled) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_add_rect(canvas_item, p_rect, p_color); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_rect.position, p_rect.position + Size2(p_rect.size.width, 0), p_color); | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_rect.position, p_rect.position + Size2(0, p_rect.size.height), p_color); | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_rect.position + Point2(0, p_rect.size.height), p_rect.position + p_rect.size, p_color); | 
					
						
							|  |  |  | 		VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_rect.position + Point2(p_rect.size.width, 0), p_rect.position + p_rect.size, p_color); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate, const Ref<Texture> &p_normal_map) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_texture.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 09:38:21 -03:00
										 |  |  | 	p_texture->draw(canvas_item, p_pos, p_modulate, false, p_normal_map); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | void CanvasItem::draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_texture.is_null()); | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | 	p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose, p_normal_map); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-06-18 22:55:02 -03:00
										 |  |  | void CanvasItem::draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_texture.is_null()); | 
					
						
							| 
									
										
										
										
											2017-06-18 22:55:02 -03:00
										 |  |  | 	p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_normal_map, p_clip_uv); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, float p_width, const Ref<Texture> &p_normal_map) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | 	RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_primitive(canvas_item, p_points, p_colors, p_uvs, rid, p_width, rid_normal); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Transform2D xform(p_rot, p_offset); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	xform.scale_basis(p_scale); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) { | 
					
						
							| 
									
										
										
										
											2016-06-26 13:01:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix); | 
					
						
							| 
									
										
										
										
											2016-06-26 13:01:17 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 13:14:04 -03:00
										 |  |  | void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | 	RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 13:14:04 -03:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, rid, rid_normal, p_antialiased); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 13:14:04 -03:00
										 |  |  | void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Color> colors; | 
					
						
							|  |  |  | 	colors.push_back(p_color); | 
					
						
							|  |  |  | 	RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2017-06-17 23:26:49 -03:00
										 |  |  | 	RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 13:14:04 -03:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, colors, p_uvs, rid, rid_normal, p_antialiased); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 17:23:27 -03:00
										 |  |  | void CanvasItem::draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture> &p_texture, const Ref<Texture> &p_normal_map) { | 
					
						
							| 
									
										
										
										
											2018-02-21 09:38:21 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_mesh.is_null()); | 
					
						
							|  |  |  | 	RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); | 
					
						
							|  |  |  | 	RID normal_map_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 17:23:27 -03:00
										 |  |  | 	VisualServer::get_singleton()->canvas_item_add_mesh(canvas_item, p_mesh->get_rid(), texture_rid, normal_map_rid); | 
					
						
							| 
									
										
										
										
											2018-02-21 09:38:21 -03:00
										 |  |  | } | 
					
						
							|  |  |  | void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture> &p_texture, const Ref<Texture> &p_normal_map) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_multimesh.is_null()); | 
					
						
							|  |  |  | 	RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); | 
					
						
							|  |  |  | 	RID normal_map_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_add_multimesh(canvas_item, p_multimesh->get_rid(), texture_rid, normal_map_rid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(p_font.is_null()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	p_font->draw(canvas_item, p_pos, p_text, p_modulate, p_clip_w); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next, const Color &p_modulate) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!drawing) { | 
					
						
							|  |  |  | 		ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); | 
					
						
							|  |  |  | 		ERR_FAIL_V(0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(p_char.length() != 1, 0); | 
					
						
							|  |  |  | 	ERR_FAIL_COND_V(p_font.is_null(), 0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], p_modulate); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::_notify_transform(CanvasItem *p_node) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 17:04:12 -03: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). | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | 	if (/*p_node->xform_change.in_list() &&*/ p_node->global_invalid) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; //nothing to do
 | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	p_node->global_invalid = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 08:29:46 -03:00
										 |  |  | 	if (p_node->notify_transform && !p_node->xform_change.in_list()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (!p_node->block_transform_notify) { | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 			if (p_node->is_inside_tree()) | 
					
						
							|  |  |  | 				get_tree()->xform_change_list.add(&p_node->xform_change); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		CanvasItem *ci = E->get(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (ci->toplevel) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		_notify_transform(ci); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Rect2 CanvasItem::get_viewport_rect() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 	return get_viewport()->get_visible_rect(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RID CanvasItem::get_canvas() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), RID()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (canvas_layer) | 
					
						
							| 
									
										
										
										
											2018-04-07 19:42:11 -03:00
										 |  |  | 		return canvas_layer->get_canvas(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 		return get_viewport()->find_world_2d()->get_canvas(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItem *CanvasItem::get_toplevel() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	CanvasItem *ci = const_cast<CanvasItem *>(this); | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	while (!ci->toplevel && Object::cast_to<CanvasItem>(ci->get_parent())) { | 
					
						
							|  |  |  | 		ci = Object::cast_to<CanvasItem>(ci->get_parent()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ci; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<World2D> CanvasItem::get_world_2d() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	CanvasItem *tl = get_toplevel(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 19:42:11 -03:00
										 |  |  | 	if (tl->get_viewport()) { | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 		return tl->get_viewport()->find_world_2d(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return Ref<World2D>(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RID CanvasItem::get_viewport_rid() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), RID()); | 
					
						
							| 
									
										
										
										
											2017-01-14 11:07:57 -03:00
										 |  |  | 	return get_viewport()->get_viewport_rid(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CanvasItem::set_block_transform_notify(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	block_transform_notify = p_enable; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CanvasItem::is_block_transform_notify_enabled() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return block_transform_notify; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 12:39:30 -03:00
										 |  |  | void CanvasItem::set_draw_behind_parent(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (behind == p_enable) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	behind = p_enable; | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool CanvasItem::is_draw_behind_parent_enabled() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 12:39:30 -03:00
										 |  |  | 	return behind; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | void CanvasItem::set_material(const Ref<Material> &p_material) { | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	material = p_material; | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | 	RID rid; | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | 	if (material.is_valid()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		rid = material->get_rid(); | 
					
						
							|  |  |  | 	VS::get_singleton()->canvas_item_set_material(canvas_item, rid); | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | 	_change_notify(); //properties for material exposed
 | 
					
						
							| 
									
										
										
										
											2015-01-12 20:44:02 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | void CanvasItem::set_use_parent_material(bool p_use_parent_material) { | 
					
						
							| 
									
										
										
										
											2015-01-12 20:44:02 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	use_parent_material = p_use_parent_material; | 
					
						
							|  |  |  | 	VS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material); | 
					
						
							| 
									
										
										
										
											2015-01-12 20:44:02 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool CanvasItem::get_use_parent_material() const { | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | 	return use_parent_material; | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | Ref<Material> CanvasItem::get_material() const { | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 00:54:10 -03:00
										 |  |  | 	return material; | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) const { | 
					
						
							| 
									
										
										
										
											2016-05-28 00:31:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), screen_point); | 
					
						
							| 
									
										
										
										
											2016-05-28 00:31:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:22:34 +02:00
										 |  |  | 	Transform2D local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse(); | 
					
						
							| 
									
										
										
										
											2016-05-28 00:31:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return local_matrix.xform(screen_point); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-11 11:43:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const { | 
					
						
							| 
									
										
										
										
											2015-03-22 01:46:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), p_event); | 
					
						
							| 
									
										
										
										
											2015-03-22 01:46:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse()); | 
					
						
							| 
									
										
										
										
											2015-03-22 01:46:18 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-02-11 06:51:20 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | Vector2 CanvasItem::get_global_mouse_position() const { | 
					
						
							| 
									
										
										
										
											2015-05-01 21:13:20 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!get_viewport(), Vector2()); | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 	return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position()); | 
					
						
							| 
									
										
										
										
											2015-05-01 21:13:20 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | Vector2 CanvasItem::get_local_mouse_position() const { | 
					
						
							| 
									
										
										
										
											2015-05-01 21:13:20 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!get_viewport(), Vector2()); | 
					
						
							| 
									
										
										
										
											2016-06-20 21:19:12 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 	return get_global_transform().affine_inverse().xform(get_global_mouse_position()); | 
					
						
							| 
									
										
										
										
											2015-05-01 21:13:20 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void CanvasItem::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											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-19 02:03:34 +07: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("update"), &CanvasItem::update); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &CanvasItem::set_as_toplevel); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &CanvasItem::is_set_as_toplevel); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_set_on_top", "on_top"), &CanvasItem::_set_on_top); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_is_on_top"), &CanvasItem::_is_on_top); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	//ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width", "antialiased"), &CanvasItem::draw_line, DEFVAL(1.0), DEFVAL(false)); | 
					
						
							| 
									
										
										
										
											2017-06-30 21:30:17 -03: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)); | 
					
						
							| 
									
										
										
										
											2017-12-09 14:11:26 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width", "antialiased"), &CanvasItem::draw_multiline, DEFVAL(1.0), DEFVAL(false)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_multiline_colors, DEFVAL(1.0), DEFVAL(false)); | 
					
						
							| 
									
										
										
										
											2017-06-21 16:25:45 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled"), &CanvasItem::draw_rect, DEFVAL(true)); | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::draw_circle); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate", "normal_map"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(Variant())); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose", "normal_map"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant())); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(true)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_style_box", "style_box", "rect"), &CanvasItem::draw_style_box); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_primitive", "points", "colors", "uvs", "texture", "width", "normal_map"), &CanvasItem::draw_primitive, DEFVAL(Variant()), DEFVAL(1.0), DEFVAL(Variant())); | 
					
						
							| 
									
										
										
										
											2017-08-19 13:14:04 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_polygon", "points", "colors", "uvs", "texture", "normal_map", "antialiased"), &CanvasItem::draw_polygon, DEFVAL(PoolVector2Array()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(false)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_colored_polygon", "points", "color", "uvs", "texture", "normal_map", "antialiased"), &CanvasItem::draw_colored_polygon, DEFVAL(PoolVector2Array()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(false)); | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_string", "font", "position", "text", "modulate", "clip_w"), &CanvasItem::draw_string, DEFVAL(Color(1, 1, 1)), DEFVAL(-1)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("draw_char", "font", "position", "char", "next", "modulate"), &CanvasItem::draw_char, DEFVAL(Color(1, 1, 1))); | 
					
						
							| 
									
										
										
										
											2018-02-21 17:23:27 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_mesh", "mesh", "texture", "normal_map"), &CanvasItem::draw_mesh, DEFVAL(Ref<Texture>())); | 
					
						
							| 
									
										
										
										
											2018-02-21 09:38:21 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_multimesh", "mesh", "texture", "normal_map"), &CanvasItem::draw_mesh, DEFVAL(Ref<Texture>())); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix); | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											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 11:29:38 -04: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 01:46:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	BIND_VMETHOD(MethodInfo("_draw")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_GROUP("Visibility", ""); | 
					
						
							|  |  |  | 	ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); | 
					
						
							|  |  |  | 	ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate"); | 
					
						
							|  |  |  | 	ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate"); | 
					
						
							|  |  |  | 	ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", 0), "_set_on_top", "_is_on_top"); //compatibility
 | 
					
						
							|  |  |  | 	ADD_PROPERTYNO(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ADD_GROUP("Material", ""); | 
					
						
							| 
									
										
										
										
											2017-06-23 14:31:21 -03:00
										 |  |  | 	ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial"), "set_material", "get_material"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material"); | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	//exporting these things doesn't really make much sense i think
 | 
					
						
							|  |  |  | 	// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toplevel", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_as_toplevel", "is_set_as_toplevel");
 | 
					
						
							|  |  |  | 	// ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled");
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("draw")); | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("visibility_changed")); | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("hide")); | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("item_rect_changed")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_MIX); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_ADD); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_SUB); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_MUL); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_PREMULT_ALPHA); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:24:29 +10:00
										 |  |  | 	BIND_ENUM_CONSTANT(BLEND_MODE_DISABLED); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-22 01:58:02 +07:00
										 |  |  | 	BIND_CONSTANT(NOTIFICATION_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); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | Transform2D CanvasItem::get_canvas_transform() const { | 
					
						
							| 
									
										
										
										
											2014-04-14 22:43:44 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); | 
					
						
							| 
									
										
										
										
											2014-04-14 22:43:44 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (canvas_layer) | 
					
						
							|  |  |  | 		return canvas_layer->get_transform(); | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	else if (Object::cast_to<CanvasItem>(get_parent())) | 
					
						
							|  |  |  | 		return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform(); | 
					
						
							| 
									
										
										
										
											2014-04-14 22:43:44 -03:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return get_viewport()->get_canvas_transform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | Transform2D CanvasItem::get_viewport_transform() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (canvas_layer) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 		if (get_viewport()) { | 
					
						
							|  |  |  | 			return get_viewport()->get_final_transform() * canvas_layer->get_transform(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			return canvas_layer->get_transform(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 07:39:40 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 		return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-15 22:07:03 -03:00
										 |  |  | void CanvasItem::set_notify_local_transform(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	notify_local_transform = p_enable; | 
					
						
							| 
									
										
										
										
											2015-09-15 22:07:03 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CanvasItem::is_local_transform_notification_enabled() const { | 
					
						
							|  |  |  | 	return notify_local_transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 20:35:46 -03:00
										 |  |  | void CanvasItem::set_notify_transform(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | 	if (notify_transform == p_enable) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	notify_transform = p_enable; | 
					
						
							| 
									
										
										
										
											2017-06-25 08:01:15 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (notify_transform && is_inside_tree()) { | 
					
						
							|  |  |  | 		//this ensures that invalid globals get resolved, so notifications can be received
 | 
					
						
							|  |  |  | 		get_global_transform(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-12 20:35:46 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CanvasItem::is_transform_notification_enabled() const { | 
					
						
							|  |  |  | 	return notify_transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 10:57:42 -03:00
										 |  |  | int CanvasItem::get_canvas_layer() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (canvas_layer) | 
					
						
							|  |  |  | 		return canvas_layer->get_layer(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 21:36:34 +01:00
										 |  |  | CanvasItem::CanvasItem() : | 
					
						
							|  |  |  | 		xform_change(this) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	canvas_item = VisualServer::get_singleton()->canvas_item_create(); | 
					
						
							|  |  |  | 	visible = true; | 
					
						
							|  |  |  | 	pending_update = false; | 
					
						
							|  |  |  | 	modulate = Color(1, 1, 1, 1); | 
					
						
							|  |  |  | 	self_modulate = Color(1, 1, 1, 1); | 
					
						
							|  |  |  | 	toplevel = false; | 
					
						
							|  |  |  | 	first_draw = false; | 
					
						
							|  |  |  | 	drawing = false; | 
					
						
							|  |  |  | 	behind = false; | 
					
						
							|  |  |  | 	block_transform_notify = false; | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	//viewport=NULL;
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	canvas_layer = NULL; | 
					
						
							|  |  |  | 	use_parent_material = false; | 
					
						
							|  |  |  | 	global_invalid = true; | 
					
						
							|  |  |  | 	notify_local_transform = false; | 
					
						
							|  |  |  | 	notify_transform = false; | 
					
						
							|  |  |  | 	light_mask = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	C = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CanvasItem::~CanvasItem() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VisualServer::get_singleton()->free(canvas_item); | 
					
						
							|  |  |  | } |