summaryrefslogtreecommitdiff
path: root/scene/2d/canvas_item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/canvas_item.cpp')
-rw-r--r--scene/2d/canvas_item.cpp417
1 files changed, 174 insertions, 243 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index ed1d606ba8..817707f96e 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,9 +42,6 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
if (p_name==SceneStringNames::get_singleton()->shader_shader) {
set_shader(p_value);
return true;
- } else if (p_name==SceneStringNames::get_singleton()->shading_mode) {
- set_shading_mode(ShadingMode(p_value.operator int()));
- return true;
} else {
if (shader.is_valid()) {
@@ -58,7 +55,7 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
}
}
if (pr) {
- VisualServer::get_singleton()->canvas_item_material_set_shader_param(material,pr,p_value);
+ VisualServer::get_singleton()->material_set_param(_get_material(),pr,p_value);
return true;
}
}
@@ -74,18 +71,14 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
r_ret=get_shader();
return true;
- } else if (p_name==SceneStringNames::get_singleton()->shading_mode) {
-
- r_ret=shading_mode;
- return true;
} else {
if (shader.is_valid()) {
StringName pr = shader->remap_param(p_name);
if (pr) {
- r_ret=VisualServer::get_singleton()->canvas_item_material_get_shader_param(material,pr);
+ r_ret=VisualServer::get_singleton()->material_get_param(_get_material(),pr);
return true;
}
}
@@ -100,7 +93,6 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
void CanvasItemMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) );
- p_list->push_back( PropertyInfo( Variant::INT, "shader/shading_mode",PROPERTY_HINT_ENUM,"Normal,Unshaded,Light Only") );
if (!shader.is_null()) {
@@ -119,7 +111,7 @@ void CanvasItemMaterial::set_shader(const Ref<Shader>& p_shader) {
if (shader.is_valid())
rid=shader->get_rid();
- VS::get_singleton()->canvas_item_material_set_shader(material,rid);
+ VS::get_singleton()->material_set_shader(_get_material(),rid);
_change_notify(); //properties for shader exposed
emit_changed();
}
@@ -131,42 +123,23 @@ Ref<Shader> CanvasItemMaterial::get_shader() const{
void CanvasItemMaterial::set_shader_param(const StringName& p_param,const Variant& p_value){
- VS::get_singleton()->canvas_item_material_set_shader_param(material,p_param,p_value);
+ VS::get_singleton()->material_set_param(_get_material(),p_param,p_value);
}
Variant CanvasItemMaterial::get_shader_param(const StringName& p_param) const{
- return VS::get_singleton()->canvas_item_material_get_shader_param(material,p_param);
-}
-
-RID CanvasItemMaterial::get_rid() const {
-
- return material;
-}
-
-void CanvasItemMaterial::set_shading_mode(ShadingMode p_mode) {
-
- shading_mode=p_mode;
- VS::get_singleton()->canvas_item_material_set_shading_mode(material,VS::CanvasItemShadingMode(p_mode));
+ return VS::get_singleton()->material_get_param(_get_material(),p_param);
}
-CanvasItemMaterial::ShadingMode CanvasItemMaterial::get_shading_mode() const {
- return shading_mode;
-}
void CanvasItemMaterial::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader);
- ObjectTypeDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader);
- ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param);
- ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param);
- ObjectTypeDB::bind_method(_MD("set_shading_mode","mode"),&CanvasItemMaterial::set_shading_mode);
- ObjectTypeDB::bind_method(_MD("get_shading_mode"),&CanvasItemMaterial::get_shading_mode);
+ ClassDB::bind_method(_MD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader);
+ ClassDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader);
+ ClassDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param);
+ ClassDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param);
- BIND_CONSTANT( SHADING_NORMAL );
- BIND_CONSTANT( SHADING_UNSHADED );
- BIND_CONSTANT( SHADING_ONLY_LIGHT );
}
@@ -189,13 +162,13 @@ void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p
CanvasItemMaterial::CanvasItemMaterial() {
- material=VS::get_singleton()->canvas_item_material_create();
- shading_mode=SHADING_NORMAL;
+
+
}
CanvasItemMaterial::~CanvasItemMaterial(){
- VS::get_singleton()->free(material);
+
}
@@ -209,7 +182,7 @@ CanvasItemMaterial::~CanvasItemMaterial(){
-bool CanvasItem::is_visible() const {
+bool CanvasItem::is_visible_in_tree() const {
if (!is_inside_tree())
return false;
@@ -217,7 +190,7 @@ bool CanvasItem::is_visible() const {
const CanvasItem *p=this;
while(p) {
- if (p->hidden)
+ if (!p->visible)
return false;
p=p->get_parent_item();
}
@@ -226,13 +199,6 @@ bool CanvasItem::is_visible() const {
return true;
}
-bool CanvasItem::is_hidden() const {
-
- /*if (!is_inside_scene())
- return false;*/
-
- return hidden;
-}
void CanvasItem::_propagate_visibility_changed(bool p_visible) {
@@ -248,7 +214,7 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
- if (c && !c->hidden) //should the toplevels stop propagation? i think so but..
+ if (c && c->visible) //should the toplevels stop propagation? i think so but..
c->_propagate_visibility_changed(p_visible);
}
@@ -258,50 +224,35 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
void CanvasItem::show() {
- if (!hidden)
+ if (visible)
return;
-
- hidden=false;
+ visible=true;
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,true);
if (!is_inside_tree())
return;
- if (is_visible()) {
- _propagate_visibility_changed(true);
- }
+ _propagate_visibility_changed(true);
_change_notify("visibility/visible");
}
void CanvasItem::hide() {
- if (hidden)
+ if (!visible)
return;
- bool propagate=is_inside_tree() && is_visible();
- hidden=true;
+ visible=false;
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false);
if (!is_inside_tree())
return;
- if (propagate)
- _propagate_visibility_changed(false);
+ _propagate_visibility_changed(false);
_change_notify("visibility/visible");
}
-void CanvasItem::set_hidden(bool p_hidden) {
-
- if (hidden == p_hidden) {
- return;
- }
-
- _set_visible_(!p_hidden);
-}
-
-
Variant CanvasItem::edit_get_state() const {
@@ -338,7 +289,7 @@ void CanvasItem::_update_callback() {
VisualServer::get_singleton()->canvas_item_clear(get_canvas_item());
//todo updating = true - only allow drawing here
- if (is_visible()) { //todo optimize this!!
+ if (is_visible_in_tree()) { //todo optimize this!!
if (first_draw) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
first_draw=false;
@@ -357,10 +308,10 @@ void CanvasItem::_update_callback() {
pending_update=false; // don't change to false until finished drawing (avoid recursive update)
}
-Matrix32 CanvasItem::get_global_transform_with_canvas() const {
+Transform2D CanvasItem::get_global_transform_with_canvas() const {
const CanvasItem *ci = this;
- Matrix32 xform;
+ Transform2D xform;
const CanvasItem *last_valid=NULL;
while(ci) {
@@ -374,9 +325,11 @@ Matrix32 CanvasItem::get_global_transform_with_canvas() const {
return last_valid->canvas_layer->get_transform() * xform;
else if (is_inside_tree())
return get_viewport()->get_canvas_transform() * xform;
+
+ return xform;
}
-Matrix32 CanvasItem::get_global_transform() const {
+Transform2D CanvasItem::get_global_transform() const {
if (global_invalid) {
@@ -394,42 +347,17 @@ Matrix32 CanvasItem::get_global_transform() const {
}
-
-void CanvasItem::_queue_sort_children() {
-
- if (pending_children_sort)
- return;
-
- pending_children_sort=true;
- MessageQueue::get_singleton()->push_call(this,"_sort_children");
-}
-
-void CanvasItem::_sort_children() {
-
- pending_children_sort=false;
+void CanvasItem::_toplevel_raise_self() {
if (!is_inside_tree())
return;
- for(int i=0;i<get_child_count();i++) {
-
- Node *n = get_child(i);
- CanvasItem *ci=n->cast_to<CanvasItem>();
-
- if (ci) {
- if (ci->toplevel || ci->group!="")
- continue;
- VisualServer::get_singleton()->canvas_item_raise(n->cast_to<CanvasItem>()->canvas_item);
- }
- }
-}
-
-void CanvasItem::_raise_self() {
+ if (canvas_layer)
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,canvas_layer->get_sort_index());
+ else
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_viewport()->gui_get_canvas_sort_index());
- if (!is_inside_tree())
- return;
- VisualServer::get_singleton()->canvas_item_raise(canvas_item);
}
@@ -461,14 +389,19 @@ void CanvasItem::_enter_canvas() {
group = "root_canvas"+itos(canvas.get_id());
add_to_group(group);
- get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self");
+ if (canvas_layer)
+ canvas_layer->reset_sort_index();
+ else
+ get_viewport()->gui_reset_canvas_sort_index();
+
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
} else {
CanvasItem *parent = get_parent_item();
canvas_layer=parent->canvas_layer;
VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item());
- parent->_queue_sort_children();
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
}
pending_update=false;
@@ -495,7 +428,6 @@ void CanvasItem::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
first_draw=true;
- pending_children_sort=false;
if (get_parent()) {
CanvasItem *ci = get_parent()->cast_to<CanvasItem>();
if (ci)
@@ -508,13 +440,15 @@ void CanvasItem::_notification(int p_what) {
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
+ if (!is_inside_tree())
+ break;
if (group!="") {
- get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
} else {
CanvasItem *p = get_parent_item();
ERR_FAIL_COND(!p);
- p->_queue_sort_children();
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
}
@@ -544,16 +478,16 @@ void CanvasItem::_notification(int p_what) {
}
}
-void CanvasItem::_set_visible_(bool p_visible) {
+void CanvasItem::set_visible(bool p_visible) {
if (p_visible)
show();
else
hide();
}
-bool CanvasItem::_is_visible_() const {
+bool CanvasItem::is_visible() const {
- return !is_hidden();
+ return visible;
}
@@ -569,15 +503,15 @@ void CanvasItem::update() {
MessageQueue::get_singleton()->push_call(this,"_update_callback");
}
-void CanvasItem::set_opacity(float p_opacity) {
+void CanvasItem::set_modulate(const Color& p_modulate) {
- opacity=p_opacity;
- VisualServer::get_singleton()->canvas_item_set_opacity(canvas_item,opacity);
+ modulate=p_modulate;
+ VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item,modulate);
}
-float CanvasItem::get_opacity() const {
+Color CanvasItem::get_modulate() const {
- return opacity;
+ return modulate;
}
@@ -614,29 +548,17 @@ CanvasItem *CanvasItem::get_parent_item() const {
}
-void CanvasItem::set_self_opacity(float p_self_opacity) {
-
- self_opacity=p_self_opacity;
- VisualServer::get_singleton()->canvas_item_set_self_opacity(canvas_item,self_opacity);
+void CanvasItem::set_self_modulate(const Color& p_self_modulate) {
-}
-float CanvasItem::get_self_opacity() const {
+ self_modulate=p_self_modulate;
+ VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item,self_modulate);
- return self_opacity;
}
+Color CanvasItem::get_self_modulate() const {
-void CanvasItem::set_blend_mode(BlendMode p_blend_mode) {
-
- ERR_FAIL_INDEX(p_blend_mode,5);
- blend_mode=p_blend_mode;
- VisualServer::get_singleton()->canvas_item_set_blend_mode(canvas_item,VS::MaterialBlendMode(blend_mode));
-
+ return self_modulate;
}
-CanvasItem::BlendMode CanvasItem::get_blend_mode() const {
-
- return blend_mode;
-}
void CanvasItem::set_light_mask(int p_light_mask) {
@@ -752,12 +674,12 @@ void CanvasItem::draw_set_transform(const Point2& p_offset, float p_rot, const S
ERR_FAIL();
}
- Matrix32 xform(p_rot,p_offset);
+ Transform2D xform(p_rot,p_offset);
xform.scale_basis(p_scale);
VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,xform);
}
-void CanvasItem::draw_set_transform_matrix(const Matrix32& p_matrix) {
+void CanvasItem::draw_set_transform_matrix(const Transform2D& p_matrix) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -830,7 +752,7 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
p_node->global_invalid=true;
- if (!p_node->xform_change.in_list()) {
+ if (notify_transform && !p_node->xform_change.in_list()) {
if (!p_node->block_transform_notify) {
if (p_node->is_inside_tree())
get_tree()->xform_change_list.add(&p_node->xform_change);
@@ -896,7 +818,7 @@ Ref<World2D> CanvasItem::get_world_2d() const {
RID CanvasItem::get_viewport_rid() const {
ERR_FAIL_COND_V(!is_inside_tree(),RID());
- return get_viewport()->get_viewport();
+ return get_viewport()->get_viewport_rid();
}
void CanvasItem::set_block_transform_notify(bool p_enable) {
@@ -913,7 +835,7 @@ void CanvasItem::set_draw_behind_parent(bool p_enable) {
if (behind==p_enable)
return;
behind=p_enable;
- VisualServer::get_singleton()->canvas_item_set_on_top(canvas_item,!behind);
+ VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item,behind);
}
@@ -953,7 +875,7 @@ Vector2 CanvasItem::make_canvas_pos_local(const Vector2& screen_point) const {
ERR_FAIL_COND_V(!is_inside_tree(),screen_point);
- Matrix32 local_matrix = (get_canvas_transform() *
+ Transform2D local_matrix = (get_canvas_transform() *
get_global_transform()).affine_inverse();
return local_matrix.xform(screen_point);
@@ -983,101 +905,102 @@ Vector2 CanvasItem::get_local_mouse_pos() const{
void CanvasItem::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("_sort_children"),&CanvasItem::_sort_children);
- ObjectTypeDB::bind_method(_MD("_raise_self"),&CanvasItem::_raise_self);
- ObjectTypeDB::bind_method(_MD("_update_callback"),&CanvasItem::_update_callback);
- ObjectTypeDB::bind_method(_MD("_set_visible_"),&CanvasItem::_set_visible_);
- ObjectTypeDB::bind_method(_MD("_is_visible_"),&CanvasItem::_is_visible_);
-
- ObjectTypeDB::bind_method(_MD("edit_set_state","state"),&CanvasItem::edit_set_state);
- ObjectTypeDB::bind_method(_MD("edit_get_state:Variant"),&CanvasItem::edit_get_state);
- ObjectTypeDB::bind_method(_MD("edit_set_rect","rect"),&CanvasItem::edit_set_rect);
- ObjectTypeDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate);
-
- ObjectTypeDB::bind_method(_MD("get_item_rect"),&CanvasItem::get_item_rect);
- ObjectTypeDB::bind_method(_MD("get_item_and_children_rect"),&CanvasItem::get_item_and_children_rect);
- //ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
-
- ObjectTypeDB::bind_method(_MD("get_canvas_item"),&CanvasItem::get_canvas_item);
-
- ObjectTypeDB::bind_method(_MD("is_visible"),&CanvasItem::is_visible);
- ObjectTypeDB::bind_method(_MD("is_hidden"),&CanvasItem::is_hidden);
- ObjectTypeDB::bind_method(_MD("show"),&CanvasItem::show);
- ObjectTypeDB::bind_method(_MD("hide"),&CanvasItem::hide);
- ObjectTypeDB::bind_method(_MD("set_hidden","hidden"),&CanvasItem::set_hidden);
-
- ObjectTypeDB::bind_method(_MD("update"),&CanvasItem::update);
-
- ObjectTypeDB::bind_method(_MD("set_as_toplevel","enable"),&CanvasItem::set_as_toplevel);
- ObjectTypeDB::bind_method(_MD("is_set_as_toplevel"),&CanvasItem::is_set_as_toplevel);
-
- ObjectTypeDB::bind_method(_MD("set_blend_mode","blend_mode"),&CanvasItem::set_blend_mode);
- ObjectTypeDB::bind_method(_MD("get_blend_mode"),&CanvasItem::get_blend_mode);
-
- ObjectTypeDB::bind_method(_MD("set_light_mask","light_mask"),&CanvasItem::set_light_mask);
- ObjectTypeDB::bind_method(_MD("get_light_mask"),&CanvasItem::get_light_mask);
-
- ObjectTypeDB::bind_method(_MD("set_opacity","opacity"),&CanvasItem::set_opacity);
- ObjectTypeDB::bind_method(_MD("get_opacity"),&CanvasItem::get_opacity);
- ObjectTypeDB::bind_method(_MD("set_self_opacity","self_opacity"),&CanvasItem::set_self_opacity);
- ObjectTypeDB::bind_method(_MD("get_self_opacity"),&CanvasItem::get_self_opacity);
-
- ObjectTypeDB::bind_method(_MD("set_draw_behind_parent","enable"),&CanvasItem::set_draw_behind_parent);
- ObjectTypeDB::bind_method(_MD("is_draw_behind_parent_enabled"),&CanvasItem::is_draw_behind_parent_enabled);
-
- ObjectTypeDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
- ObjectTypeDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top);
- //ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
-
- ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width","antialiased"),&CanvasItem::draw_line,DEFVAL(1.0),DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("draw_rect","rect","color"),&CanvasItem::draw_rect);
- ObjectTypeDB::bind_method(_MD("draw_circle","pos","radius","color"),&CanvasItem::draw_circle);
- ObjectTypeDB::bind_method(_MD("draw_texture","texture:Texture","pos","modulate"),&CanvasItem::draw_texture,DEFVAL(Color(1,1,1,1)));
- ObjectTypeDB::bind_method(_MD("draw_texture_rect","texture:Texture","rect","tile","modulate","transpose"),&CanvasItem::draw_texture_rect,DEFVAL(Color(1,1,1)),DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate","transpose"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("draw_style_box","style_box:StyleBox","rect"),&CanvasItem::draw_style_box);
- ObjectTypeDB::bind_method(_MD("draw_primitive","points","colors","uvs","texture:Texture","width"),&CanvasItem::draw_primitive,DEFVAL(Variant()),DEFVAL(1.0));
- ObjectTypeDB::bind_method(_MD("draw_polygon","points","colors","uvs","texture:Texture"),&CanvasItem::draw_polygon,DEFVAL(Vector2Array()),DEFVAL(Variant()));
- ObjectTypeDB::bind_method(_MD("draw_colored_polygon","points","color","uvs","texture:Texture"),&CanvasItem::draw_colored_polygon,DEFVAL(Vector2Array()),DEFVAL(Variant()));
- ObjectTypeDB::bind_method(_MD("draw_string","font:Font","pos","text","modulate","clip_w"),&CanvasItem::draw_string,DEFVAL(Color(1,1,1)),DEFVAL(-1));
- ObjectTypeDB::bind_method(_MD("draw_char","font:Font","pos","char","next","modulate"),&CanvasItem::draw_char,DEFVAL(Color(1,1,1)));
-
- ObjectTypeDB::bind_method(_MD("draw_set_transform","pos","rot","scale"),&CanvasItem::draw_set_transform);
- ObjectTypeDB::bind_method(_MD("draw_set_transform_matrix","xform"),&CanvasItem::draw_set_transform_matrix);
- ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
- ObjectTypeDB::bind_method(_MD("get_global_transform"),&CanvasItem::get_global_transform);
- ObjectTypeDB::bind_method(_MD("get_global_transform_with_canvas"),&CanvasItem::get_global_transform_with_canvas);
- ObjectTypeDB::bind_method(_MD("get_viewport_transform"),&CanvasItem::get_viewport_transform);
- ObjectTypeDB::bind_method(_MD("get_viewport_rect"),&CanvasItem::get_viewport_rect);
- ObjectTypeDB::bind_method(_MD("get_canvas_transform"),&CanvasItem::get_canvas_transform);
- ObjectTypeDB::bind_method(_MD("get_local_mouse_pos"),&CanvasItem::get_local_mouse_pos);
- ObjectTypeDB::bind_method(_MD("get_global_mouse_pos"),&CanvasItem::get_global_mouse_pos);
- ObjectTypeDB::bind_method(_MD("get_canvas"),&CanvasItem::get_canvas);
- ObjectTypeDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d);
- //ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport);
-
- ObjectTypeDB::bind_method(_MD("set_material","material:CanvasItemMaterial"),&CanvasItem::set_material);
- ObjectTypeDB::bind_method(_MD("get_material:CanvasItemMaterial"),&CanvasItem::get_material);
-
- ObjectTypeDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material);
- ObjectTypeDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material);
-
- ObjectTypeDB::bind_method(_MD("make_canvas_pos_local","screen_point"),
+ ClassDB::bind_method(_MD("_toplevel_raise_self"),&CanvasItem::_toplevel_raise_self);
+ ClassDB::bind_method(_MD("_update_callback"),&CanvasItem::_update_callback);
+
+ ClassDB::bind_method(_MD("edit_set_state","state"),&CanvasItem::edit_set_state);
+ ClassDB::bind_method(_MD("edit_get_state:Variant"),&CanvasItem::edit_get_state);
+ ClassDB::bind_method(_MD("edit_set_rect","rect"),&CanvasItem::edit_set_rect);
+ ClassDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate);
+
+ ClassDB::bind_method(_MD("get_item_rect"),&CanvasItem::get_item_rect);
+ ClassDB::bind_method(_MD("get_item_and_children_rect"),&CanvasItem::get_item_and_children_rect);
+ //ClassDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
+
+ ClassDB::bind_method(_MD("get_canvas_item"),&CanvasItem::get_canvas_item);
+
+ ClassDB::bind_method(_MD("set_visible"),&CanvasItem::set_visible);
+ ClassDB::bind_method(_MD("is_visible"),&CanvasItem::is_visible);
+ ClassDB::bind_method(_MD("is_visible_in_tree"),&CanvasItem::is_visible_in_tree);
+ ClassDB::bind_method(_MD("show"),&CanvasItem::show);
+ ClassDB::bind_method(_MD("hide"),&CanvasItem::hide);
+
+ ClassDB::bind_method(_MD("update"),&CanvasItem::update);
+
+ ClassDB::bind_method(_MD("set_as_toplevel","enable"),&CanvasItem::set_as_toplevel);
+ ClassDB::bind_method(_MD("is_set_as_toplevel"),&CanvasItem::is_set_as_toplevel);
+
+ ClassDB::bind_method(_MD("set_light_mask","light_mask"),&CanvasItem::set_light_mask);
+ ClassDB::bind_method(_MD("get_light_mask"),&CanvasItem::get_light_mask);
+
+ ClassDB::bind_method(_MD("set_modulate","modulate"),&CanvasItem::set_modulate);
+ ClassDB::bind_method(_MD("get_modulate"),&CanvasItem::get_modulate);
+ ClassDB::bind_method(_MD("set_self_modulate","self_modulate"),&CanvasItem::set_self_modulate);
+ ClassDB::bind_method(_MD("get_self_modulate"),&CanvasItem::get_self_modulate);
+
+ ClassDB::bind_method(_MD("set_draw_behind_parent","enable"),&CanvasItem::set_draw_behind_parent);
+ ClassDB::bind_method(_MD("is_draw_behind_parent_enabled"),&CanvasItem::is_draw_behind_parent_enabled);
+
+ ClassDB::bind_method(_MD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
+ ClassDB::bind_method(_MD("_is_on_top"),&CanvasItem::_is_on_top);
+ //ClassDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
+
+ ClassDB::bind_method(_MD("draw_line","from","to","color","width","antialiased"),&CanvasItem::draw_line,DEFVAL(1.0),DEFVAL(false));
+ ClassDB::bind_method(_MD("draw_rect","rect","color"),&CanvasItem::draw_rect);
+ ClassDB::bind_method(_MD("draw_circle","pos","radius","color"),&CanvasItem::draw_circle);
+ ClassDB::bind_method(_MD("draw_texture","texture:Texture","pos","modulate"),&CanvasItem::draw_texture,DEFVAL(Color(1,1,1,1)));
+ ClassDB::bind_method(_MD("draw_texture_rect","texture:Texture","rect","tile","modulate","transpose"),&CanvasItem::draw_texture_rect,DEFVAL(Color(1,1,1)),DEFVAL(false));
+ ClassDB::bind_method(_MD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate","transpose"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false));
+ ClassDB::bind_method(_MD("draw_style_box","style_box:StyleBox","rect"),&CanvasItem::draw_style_box);
+ ClassDB::bind_method(_MD("draw_primitive","points","colors","uvs","texture:Texture","width"),&CanvasItem::draw_primitive,DEFVAL(Variant()),DEFVAL(1.0));
+ ClassDB::bind_method(_MD("draw_polygon","points","colors","uvs","texture:Texture"),&CanvasItem::draw_polygon,DEFVAL(PoolVector2Array()),DEFVAL(Variant()));
+ ClassDB::bind_method(_MD("draw_colored_polygon","points","color","uvs","texture:Texture"),&CanvasItem::draw_colored_polygon,DEFVAL(PoolVector2Array()),DEFVAL(Variant()));
+ ClassDB::bind_method(_MD("draw_string","font:Font","pos","text","modulate","clip_w"),&CanvasItem::draw_string,DEFVAL(Color(1,1,1)),DEFVAL(-1));
+ ClassDB::bind_method(_MD("draw_char","font:Font","pos","char","next","modulate"),&CanvasItem::draw_char,DEFVAL(Color(1,1,1)));
+
+ ClassDB::bind_method(_MD("draw_set_transform","pos","rot","scale"),&CanvasItem::draw_set_transform);
+ ClassDB::bind_method(_MD("draw_set_transform_matrix","xform"),&CanvasItem::draw_set_transform_matrix);
+ ClassDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
+ ClassDB::bind_method(_MD("get_global_transform"),&CanvasItem::get_global_transform);
+ ClassDB::bind_method(_MD("get_global_transform_with_canvas"),&CanvasItem::get_global_transform_with_canvas);
+ ClassDB::bind_method(_MD("get_viewport_transform"),&CanvasItem::get_viewport_transform);
+ ClassDB::bind_method(_MD("get_viewport_rect"),&CanvasItem::get_viewport_rect);
+ ClassDB::bind_method(_MD("get_canvas_transform"),&CanvasItem::get_canvas_transform);
+ ClassDB::bind_method(_MD("get_local_mouse_pos"),&CanvasItem::get_local_mouse_pos);
+ ClassDB::bind_method(_MD("get_global_mouse_pos"),&CanvasItem::get_global_mouse_pos);
+ ClassDB::bind_method(_MD("get_canvas"),&CanvasItem::get_canvas);
+ ClassDB::bind_method(_MD("get_world_2d"),&CanvasItem::get_world_2d);
+ //ClassDB::bind_method(_MD("get_viewport"),&CanvasItem::get_viewport);
+
+ ClassDB::bind_method(_MD("set_material","material:CanvasItemMaterial"),&CanvasItem::set_material);
+ ClassDB::bind_method(_MD("get_material:CanvasItemMaterial"),&CanvasItem::get_material);
+
+ ClassDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material);
+ ClassDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material);
+
+ ClassDB::bind_method(_MD("set_notify_local_transform","enable"),&CanvasItem::set_notify_local_transform);
+ ClassDB::bind_method(_MD("is_local_transform_notification_enabled"),&CanvasItem::is_local_transform_notification_enabled);
+
+ ClassDB::bind_method(_MD("set_notify_transform","enable"),&CanvasItem::set_notify_transform);
+ ClassDB::bind_method(_MD("is_transform_notification_enabled"),&CanvasItem::is_transform_notification_enabled);
+
+ ClassDB::bind_method(_MD("make_canvas_pos_local","screen_point"),
&CanvasItem::make_canvas_pos_local);
- ObjectTypeDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local);
+ ClassDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local);
BIND_VMETHOD(MethodInfo("_draw"));
- ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
- ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
- ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
-
- ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
- ADD_PROPERTYNO( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material/material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), _SCS("set_material"),_SCS("get_material") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"material/use_parent"), _SCS("set_use_parent_material"),_SCS("get_use_parent_material") );
+ ADD_GROUP("Visibility","");
+ ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visible"), _SCS("set_visible"),_SCS("is_visible") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::COLOR,"modulate"), _SCS("set_modulate"),_SCS("get_modulate") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::COLOR,"self_modulate"), _SCS("set_self_modulate"),_SCS("get_self_modulate") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"show_behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
+ ADD_PROPERTYNO( PropertyInfo(Variant::INT,"light_mask",PROPERTY_HINT_LAYERS_2D_RENDER), _SCS("set_light_mask"),_SCS("get_light_mask") );
+
+ ADD_GROUP("Material","");
+ ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), _SCS("set_material"),_SCS("get_material") );
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"use_parent_material"), _SCS("set_use_parent_material"),_SCS("get_use_parent_material") );
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), _SCS("set_as_toplevel"),_SCS("is_set_as_toplevel") );
//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),_SCS("set_transform_notify"),_SCS("is_transform_notify_enabled"));
@@ -1105,9 +1028,9 @@ void CanvasItem::_bind_methods() {
}
-Matrix32 CanvasItem::get_canvas_transform() const {
+Transform2D CanvasItem::get_canvas_transform() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Matrix32());
+ ERR_FAIL_COND_V(!is_inside_tree(),Transform2D());
if (canvas_layer)
return canvas_layer->get_transform();
@@ -1118,9 +1041,9 @@ Matrix32 CanvasItem::get_canvas_transform() const {
}
-Matrix32 CanvasItem::get_viewport_transform() const {
+Transform2D CanvasItem::get_viewport_transform() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Matrix32());
+ ERR_FAIL_COND_V(!is_inside_tree(),Transform2D());
if (canvas_layer) {
@@ -1145,6 +1068,15 @@ bool CanvasItem::is_local_transform_notification_enabled() const {
return notify_local_transform;
}
+
+void CanvasItem::set_notify_transform(bool p_enable) {
+ notify_transform=p_enable;
+}
+
+bool CanvasItem::is_transform_notification_enabled() const {
+ return notify_transform;
+}
+
int CanvasItem::get_canvas_layer() const {
if (canvas_layer)
@@ -1174,22 +1106,21 @@ CanvasItem::CanvasItem() : xform_change(this) {
canvas_item=VisualServer::get_singleton()->canvas_item_create();
- hidden=false;
+ visible=true;
pending_update=false;
- opacity=1;
- self_opacity=1;
+ modulate=Color(1,1,1,1);
+ self_modulate=Color(1,1,1,1);
toplevel=false;
- pending_children_sort=false;
first_draw=false;
- blend_mode=BLEND_MODE_MIX;
drawing=false;
behind=false;
- block_transform_notify=false;
-// viewport=NULL;
+ block_transform_notify=false;
+ //viewport=NULL;
canvas_layer=NULL;
use_parent_material=false;
global_invalid=true;
notify_local_transform=false;
+ notify_transform=false;
light_mask=1;
C=NULL;