diff options
author | Anton Yabchinskiy <arn@bestmx.ru> | 2015-04-04 09:31:21 +0300 |
---|---|---|
committer | Anton Yabchinskiy <arn@bestmx.ru> | 2015-04-04 09:31:21 +0300 |
commit | 16746f157f83d666079ba3266acec13d35b84c3f (patch) | |
tree | 8c872d18ccdef90a15e72622cd0139e0e64801a6 /scene | |
parent | 43713810deaadfec6a1656767cf5520073e58a06 (diff) | |
parent | 5d99e15e43d5a446b35d48e8a3b08a478f1998a9 (diff) |
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'scene')
52 files changed, 1290 insertions, 124 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index fce21f6001..a5c455ce64 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -216,6 +216,119 @@ void Area2D::_body_inout(int p_status,const RID& p_body, int p_instance, int p_b } + +void Area2D::_area_enter_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_FAIL_COND(!node); + + Map<ObjectID,AreaState>::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(E->get().in_tree); + + E->get().in_tree=true; + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area2D::_area_exit_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_FAIL_COND(!node); + Map<ObjectID,AreaState>::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(!E->get().in_tree); + E->get().in_tree=false; + emit_signal(SceneStringNames::get_singleton()->area_exit,node); + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area2D::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) { + + bool area_in = p_status==Physics2DServer::AREA_BODY_ADDED; + ObjectID objid=p_instance; + + Object *obj = ObjectDB::get_instance(objid); + Node *node = obj ? obj->cast_to<Node>() : NULL; + + Map<ObjectID,AreaState>::Element *E=area_map.find(objid); + + ERR_FAIL_COND(!area_in && !E); + + locked=true; + + if (area_in) { + if (!E) { + + E = area_map.insert(objid,AreaState()); + E->get().rc=0; + E->get().in_tree=node && node->is_inside_tree(); + if (node) { + node->connect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid)); + if (E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + } + } + + } + E->get().rc++; + if (node) + E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape)); + + + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,objid,node,p_area_shape,p_self_shape); + } + + } else { + + E->get().rc--; + + if (node) + E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape)); + + bool eraseit=false; + + if (E->get().rc==0) { + + if (node) { + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + if (E->get().in_tree) + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + + } + + eraseit=true; + + } + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,objid,obj,p_area_shape,p_self_shape); + } + + if (eraseit) + area_map.erase(E); + + } + + locked=false; + + +} + + + void Area2D::_clear_monitoring() { if (locked) { @@ -223,27 +336,56 @@ void Area2D::_clear_monitoring() { } ERR_FAIL_COND(locked); - Map<ObjectID,BodyState> bmcopy = body_map; - body_map.clear(); - //disconnect all monitored stuff + { + Map<ObjectID,BodyState> bmcopy = body_map; + body_map.clear(); + //disconnect all monitored stuff - for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) { + for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) { - Object *obj = ObjectDB::get_instance(E->key()); - Node *node = obj ? obj->cast_to<Node>() : NULL; - ERR_CONTINUE(!node); - if (!E->get().in_tree) - continue; + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; - for(int i=0;i<E->get().shapes.size();i++) { + for(int i=0;i<E->get().shapes.size();i++) { - emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + } + + emit_signal(SceneStringNames::get_singleton()->body_exit,obj); + + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); } - emit_signal(SceneStringNames::get_singleton()->body_exit,obj); + } - node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); + { + + Map<ObjectID,AreaState> bmcopy = area_map; + area_map.clear(); + //disconnect all monitored stuff + + for (Map<ObjectID,AreaState>::Element *E=bmcopy.front();E;E=E->next()) { + + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; + + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + } } } @@ -276,8 +418,10 @@ void Area2D::set_enable_monitoring(bool p_enable) { if (monitoring) { Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,"_body_inout"); + Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,"_area_inout"); } else { Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName()); + Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName()); _clear_monitoring(); } @@ -288,6 +432,26 @@ bool Area2D::is_monitoring_enabled() const { return monitoring; } +void Area2D::set_monitorable(bool p_enable) { + + if (locked) { + ERR_EXPLAIN("This function can't be used during the in/out signal."); + } + ERR_FAIL_COND(locked); + + if (p_enable==monitorable) + return; + + monitorable=p_enable; + + Physics2DServer::get_singleton()->area_set_monitorable(get_rid(),monitorable); +} + +bool Area2D::is_monitorable() const { + + return monitorable; +} + Array Area2D::get_overlapping_bodies() const { ERR_FAIL_COND_V(!monitoring,Array()); @@ -307,12 +471,56 @@ Array Area2D::get_overlapping_bodies() const { return ret; } +Array Area2D::get_overlapping_areas() const { + + ERR_FAIL_COND_V(!monitoring,Array()); + Array ret; + ret.resize(area_map.size()); + int idx=0; + for (const Map<ObjectID,AreaState>::Element *E=area_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} + +bool Area2D::overlaps_area(Node* p_area) const { + + ERR_FAIL_NULL_V(p_area,false); + const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + + + +} + +bool Area2D::overlaps_body(Node* p_body) const{ + + ERR_FAIL_NULL_V(p_body,false); + const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + +} + void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area2D::_body_enter_tree); ObjectTypeDB::bind_method(_MD("_body_exit_tree","id"),&Area2D::_body_exit_tree); + ObjectTypeDB::bind_method(_MD("_area_enter_tree","id"),&Area2D::_area_enter_tree); + ObjectTypeDB::bind_method(_MD("_area_exit_tree","id"),&Area2D::_area_exit_tree); + ObjectTypeDB::bind_method(_MD("set_space_override_mode","enable"),&Area2D::set_space_override_mode); ObjectTypeDB::bind_method(_MD("get_space_override_mode"),&Area2D::get_space_override_mode); @@ -337,15 +545,29 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled); + ObjectTypeDB::bind_method(_MD("set_monitorable","enable"),&Area2D::set_monitorable); + ObjectTypeDB::bind_method(_MD("is_monitorable"),&Area2D::is_monitorable); + ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies); + ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area2D::get_overlapping_areas); + + ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody2D","body"),&Area2D::overlaps_body); + ObjectTypeDB::bind_method(_MD("overlaps_area:Area2D","area"),&Area2D::overlaps_area); ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout); + ObjectTypeDB::bind_method(_MD("_area_inout"),&Area2D::_area_inout); + + + ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); + ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); + ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_exit_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); + ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); - ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); - ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); - ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body"))); - ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body"))); ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); @@ -355,6 +577,7 @@ void Area2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp")); ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable")); } @@ -369,7 +592,9 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea locked=false; priority=0; monitoring=false; + monitorable=false; set_enable_monitoring(true); + set_monitorable(true); } diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index f770e88a19..6a6c757e0c 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -53,6 +53,7 @@ private: real_t angular_damp; int priority; bool monitoring; + bool monitorable; bool locked; void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape); @@ -84,6 +85,36 @@ private: Map<ObjectID,BodyState> body_map; + + + void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape); + + void _area_enter_tree(ObjectID p_id); + void _area_exit_tree(ObjectID p_id); + + struct AreaShapePair { + + int area_shape; + int self_shape; + bool operator<(const AreaShapePair& p_sp) const { + if (area_shape==p_sp.area_shape) + return self_shape < p_sp.self_shape; + else + return area_shape < p_sp.area_shape; + } + + AreaShapePair() {} + AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; } + }; + + struct AreaState { + + int rc; + bool in_tree; + VSet<AreaShapePair> shapes; + }; + + Map<ObjectID,AreaState> area_map; void _clear_monitoring(); @@ -117,8 +148,14 @@ public: void set_enable_monitoring(bool p_enable); bool is_monitoring_enabled() const; + void set_monitorable(bool p_enable); + bool is_monitorable() const; + Array get_overlapping_bodies() const; //function for script + Array get_overlapping_areas() const; //function for script + bool overlaps_area(Node* p_area) const; + bool overlaps_body(Node* p_body) const; Area2D(); ~Area2D(); diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp new file mode 100644 index 0000000000..245b3ba7eb --- /dev/null +++ b/scene/2d/back_buffer_copy.cpp @@ -0,0 +1,75 @@ +#include "back_buffer_copy.h" + +void BackBufferCopy::_update_copy_mode() { + + switch(copy_mode) { + + case COPY_MODE_DISALED: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2()); + } break; + case COPY_MODE_RECT: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect); + } break; + case COPY_MODE_VIEWPORT: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2()); + + } break; + + } +} + +Rect2 BackBufferCopy::get_item_rect() const { + + return rect; +} + +void BackBufferCopy::set_rect(const Rect2& p_rect) { + + rect=p_rect; + _update_copy_mode(); +} + +Rect2 BackBufferCopy::get_rect() const{ + return rect; +} + +void BackBufferCopy::set_copy_mode(CopyMode p_mode){ + + copy_mode=p_mode; + _update_copy_mode(); +} +BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const{ + + return copy_mode; +} + + +void BackBufferCopy::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_rect","rect"),&BackBufferCopy::set_rect); + ObjectTypeDB::bind_method(_MD("get_rect"),&BackBufferCopy::get_rect); + + ObjectTypeDB::bind_method(_MD("set_copy_mode","copy_mode"),&BackBufferCopy::set_copy_mode); + ObjectTypeDB::bind_method(_MD("get_copy_mode"),&BackBufferCopy::get_copy_mode); + + ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),_SCS("set_copy_mode"),_SCS("get_copy_mode")); + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),_SCS("set_rect"),_SCS("get_rect")); + + BIND_CONSTANT( COPY_MODE_DISALED ); + BIND_CONSTANT( COPY_MODE_RECT ); + BIND_CONSTANT( COPY_MODE_VIEWPORT ); + +} + +BackBufferCopy::BackBufferCopy(){ + + rect=Rect2(-100,-100,200,200); + copy_mode=COPY_MODE_RECT; + _update_copy_mode(); +} +BackBufferCopy::~BackBufferCopy(){ + +} diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h new file mode 100644 index 0000000000..3a86ffa309 --- /dev/null +++ b/scene/2d/back_buffer_copy.h @@ -0,0 +1,41 @@ +#ifndef BACKBUFFERCOPY_H +#define BACKBUFFERCOPY_H + +#include "scene/2d/node_2d.h" + +class BackBufferCopy : public Node2D { + OBJ_TYPE( BackBufferCopy,Node2D); +public: + enum CopyMode { + COPY_MODE_DISALED, + COPY_MODE_RECT, + COPY_MODE_VIEWPORT + }; +private: + + Rect2 rect; + CopyMode copy_mode; + + void _update_copy_mode(); + +protected: + + static void _bind_methods(); + +public: + + void set_rect(const Rect2& p_rect); + Rect2 get_rect() const; + + void set_copy_mode(CopyMode p_mode); + CopyMode get_copy_mode() const; + + Rect2 get_item_rect() const; + + BackBufferCopy(); + ~BackBufferCopy(); +}; + +VARIANT_ENUM_CAST(BackBufferCopy::CopyMode); + +#endif // BACKBUFFERCOPY_H diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 1002713740..118ba33bc6 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -42,9 +42,8 @@ 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()->shader_unshaded) { - set_unshaded(p_value); - print_line("set unshaded"); + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { + set_shading_mode(ShadingMode(p_value.operator int())); return true; } else { @@ -75,10 +74,10 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const { r_ret=get_shader(); return true; - } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { - r_ret=unshaded; + r_ret=shading_mode; return true; } else { @@ -101,7 +100,7 @@ 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::BOOL, "shader/unshaded") ); + p_list->push_back( PropertyInfo( Variant::INT, "shader/shading_mode",PROPERTY_HINT_ENUM,"Normal,Unshaded,Light Only") ); if (!shader.is_null()) { @@ -162,25 +161,30 @@ RID CanvasItemMaterial::get_rid() const { return material; } -void CanvasItemMaterial::set_unshaded(bool p_unshaded) { +void CanvasItemMaterial::set_shading_mode(ShadingMode p_mode) { - unshaded=p_unshaded; - VS::get_singleton()->canvas_item_material_set_unshaded(material,p_unshaded); + shading_mode=p_mode; + VS::get_singleton()->canvas_item_material_set_shading_mode(material,VS::CanvasItemShadingMode(p_mode)); } -bool CanvasItemMaterial::is_unshaded() const{ - - return unshaded; +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_unshaded","unshaded"),&CanvasItemMaterial::set_unshaded); - ObjectTypeDB::bind_method(_MD("is_unshaded"),&CanvasItemMaterial::is_unshaded); + ObjectTypeDB::bind_method(_MD("set_shading_mode","mode"),&CanvasItemMaterial::set_shading_mode); + ObjectTypeDB::bind_method(_MD("get_shading_mode"),&CanvasItemMaterial::get_shading_mode); + + BIND_CONSTANT( SHADING_NORMAL ); + BIND_CONSTANT( SHADING_UNSHADED ); + BIND_CONSTANT( SHADING_ONLY_LIGHT ); + } @@ -203,7 +207,7 @@ void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p CanvasItemMaterial::CanvasItemMaterial() { material=VS::get_singleton()->canvas_item_material_create(); - unshaded=false; + shading_mode=SHADING_NORMAL; } CanvasItemMaterial::~CanvasItemMaterial(){ @@ -944,8 +948,68 @@ Ref<CanvasItemMaterial> CanvasItem::get_material() const{ } +InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const { + + ERR_FAIL_COND_V(!is_inside_tree(),p_event); + + InputEvent ev = p_event; + + Matrix32 local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse(); + + switch(ev.type) { + + case InputEvent::MOUSE_BUTTON: { + + Vector2 g = local_matrix.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); + Vector2 l = local_matrix.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)); + ev.mouse_button.x=l.x; + ev.mouse_button.y=l.y; + ev.mouse_button.global_x=g.x; + ev.mouse_button.global_y=g.y; + + } break; + case InputEvent::MOUSE_MOTION: { + + Vector2 g = local_matrix.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); + Vector2 l = local_matrix.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); + Vector2 r = local_matrix.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); + Vector2 s = local_matrix.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); + ev.mouse_motion.x=l.x; + ev.mouse_motion.y=l.y; + ev.mouse_motion.global_x=g.x; + ev.mouse_motion.global_y=g.y; + ev.mouse_motion.relative_x=r.x; + ev.mouse_motion.relative_y=r.y; + ev.mouse_motion.speed_x=s.x; + ev.mouse_motion.speed_y=s.y; + + } break; + case InputEvent::SCREEN_TOUCH: { + Vector2 t = local_matrix.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)); + ev.screen_touch.x=t.x; + ev.screen_touch.y=t.y; + + } break; + case InputEvent::SCREEN_DRAG: { + + + Vector2 t = local_matrix.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); + Vector2 r = local_matrix.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); + Vector2 s = local_matrix.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); + ev.screen_drag.x=t.x; + ev.screen_drag.y=t.y; + ev.screen_drag.relative_x=r.x; + ev.screen_drag.relative_y=r.y; + ev.screen_drag.speed_x=s.x; + ev.screen_drag.speed_y=s.y; + } break; + } + + return ev; +} + void CanvasItem::_bind_methods() { @@ -1022,6 +1086,8 @@ void CanvasItem::_bind_methods() { 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_input_local","event"),&CanvasItem::make_input_local); + BIND_VMETHOD(MethodInfo("_draw")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") ); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 0c7be261ab..167f2b96f3 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -45,10 +45,17 @@ class CanvasItemMaterial : public Resource{ OBJ_TYPE(CanvasItemMaterial,Resource); RID material; Ref<Shader> shader; - bool unshaded; +public: + enum ShadingMode { + SHADING_NORMAL, + SHADING_UNSHADED, + SHADING_ONLY_LIGHT, + }; protected: + ShadingMode shading_mode; + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; @@ -66,14 +73,16 @@ public: void set_shader_param(const StringName& p_param,const Variant& p_value); Variant get_shader_param(const StringName& p_param) const; - void set_unshaded(bool p_unshaded); - bool is_unshaded() const; + void set_shading_mode(ShadingMode p_mode); + ShadingMode get_shading_mode() const; virtual RID get_rid() const; CanvasItemMaterial(); ~CanvasItemMaterial(); }; +VARIANT_ENUM_CAST( CanvasItemMaterial::ShadingMode ); + class CanvasItem : public Node { @@ -249,6 +258,7 @@ public: void set_use_parent_material(bool p_use_parent_material); bool get_use_parent_material() const; + InputEvent make_input_local(const InputEvent& pevent) const; CanvasItem(); ~CanvasItem(); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 3b859d9366..a883fee103 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -28,6 +28,7 @@ /*************************************************************************/ #include "collision_object_2d.h" #include "servers/physics_2d_server.h" +#include "scene/scene_string_names.h" void CollisionObject2D::_update_shapes_from_children() { @@ -58,9 +59,15 @@ void CollisionObject2D::_notification(int p_what) { } else Physics2DServer::get_singleton()->body_set_space(rid,space); + _update_pickable(); + //get space } + case NOTIFICATION_VISIBILITY_CHANGED: { + + _update_pickable(); + } break; case NOTIFICATION_TRANSFORM_CHANGED: { if (area) @@ -166,6 +173,57 @@ void CollisionObject2D::_get_property_list( List<PropertyInfo> *p_list) const { } } + +void CollisionObject2D::set_pickable(bool p_enabled) { + + if (pickable==p_enabled) + return; + + pickable=p_enabled; + _update_pickable(); +} + +bool CollisionObject2D::is_pickable() const { + + return pickable; +} + +void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape) { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_input_event,p_viewport,p_input_event,p_shape); + } + emit_signal(SceneStringNames::get_singleton()->input_event,p_viewport,p_input_event,p_shape); +} + +void CollisionObject2D::_mouse_enter() { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); + } + emit_signal(SceneStringNames::get_singleton()->mouse_enter); +} + + +void CollisionObject2D::_mouse_exit() { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); + } + emit_signal(SceneStringNames::get_singleton()->mouse_exit); + +} + +void CollisionObject2D::_update_pickable() { + if (!is_inside_tree()) + return; + bool pickable = this->pickable && is_inside_tree() && is_visible(); + if (area) + Physics2DServer::get_singleton()->area_set_pickable(rid,pickable); + else + Physics2DServer::get_singleton()->body_set_pickable(rid,pickable); +} + void CollisionObject2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_shape","shape:Shape2D","transform"),&CollisionObject2D::add_shape,DEFVAL(Matrix32())); @@ -180,6 +238,17 @@ void CollisionObject2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("clear_shapes"),&CollisionObject2D::clear_shapes); ObjectTypeDB::bind_method(_MD("get_rid"),&CollisionObject2D::get_rid); + ObjectTypeDB::bind_method(_MD("set_pickable","enabled"),&CollisionObject2D::set_pickable); + ObjectTypeDB::bind_method(_MD("is_pickable"),&CollisionObject2D::is_pickable); + + BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx"))); + + ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx"))); + ADD_SIGNAL( MethodInfo("mouse_enter")); + ADD_SIGNAL( MethodInfo("mouse_exit")); + + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"input/pickable"),_SCS("set_pickable"),_SCS("is_pickable")); + } @@ -262,7 +331,9 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { rid=p_rid; area=p_area; + pickable=true; if (p_area) { + Physics2DServer::get_singleton()->area_attach_object_instance_ID(rid,get_instance_ID()); } else { Physics2DServer::get_singleton()->body_attach_object_instance_ID(rid,get_instance_ID()); diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index 4a529ce062..393973ce90 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -38,6 +38,7 @@ class CollisionObject2D : public Node2D { bool area; RID rid; + bool pickable; struct ShapeData { Matrix32 xform; @@ -66,9 +67,17 @@ protected: bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; static void _bind_methods(); + + void _update_pickable(); +friend class Viewport; + void _input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape); + void _mouse_enter(); + void _mouse_exit(); + public: + void add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p_transform=Matrix32()); int get_shape_count() const; void set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape); @@ -80,6 +89,9 @@ public: void remove_shape(int p_shape_idx); void clear_shapes(); + void set_pickable(bool p_enabled); + bool is_pickable() const; + _FORCE_INLINE_ RID get_rid() const { return rid; } CollisionObject2D(); diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 1c0be60764..049017c0a5 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -33,6 +33,9 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) { + if (unparenting) + return; + CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>(); ERR_FAIL_COND(!co); @@ -96,6 +99,9 @@ void CollisionPolygon2D::_notification(int p_what) { switch(p_what) { + case NOTIFICATION_ENTER_TREE: { + unparenting=false; + } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { if (!is_inside_tree()) @@ -123,6 +129,11 @@ void CollisionPolygon2D::_notification(int p_what) { } #endif } break; + case NOTIFICATION_UNPARENTED: { + unparenting = true; + _update_parent(); + } break; + } } @@ -203,6 +214,7 @@ CollisionPolygon2D::CollisionPolygon2D() { aabb=Rect2(-10,-10,20,20); build_mode=BUILD_SOLIDS; trigger=false; + unparenting=false; } diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index b8e27b6fb4..735110efad 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -51,6 +51,7 @@ protected: BuildMode build_mode; Vector<Point2> polygon; bool trigger; + bool unparenting; void _add_to_collision_object(Object *p_obj); void _update_parent(); diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 5472e0b00e..c0ab544d42 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const { Size2i s; - s = texture->get_size(); + s = texture->get_size()*_scale; Point2i ofs=texture_offset; ofs-=s/2; @@ -63,6 +63,8 @@ void Light2D::set_texture_offset( const Vector2& p_offset) { texture_offset=p_offset; VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset); + item_rect_changed(); + } Vector2 Light2D::get_texture_offset() const { @@ -87,11 +89,42 @@ void Light2D::set_height( float p_height) { VS::get_singleton()->canvas_light_set_height(canvas_light,height); } + + float Light2D::get_height() const { return height; } +void Light2D::set_energy( float p_energy) { + + energy=p_energy; + VS::get_singleton()->canvas_light_set_energy(canvas_light,energy); + +} + + +float Light2D::get_energy() const { + + return energy; +} + + + +void Light2D::set_texture_scale( float p_scale) { + + _scale=p_scale; + VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale); + item_rect_changed(); + +} + + +float Light2D::get_texture_scale() const { + + return _scale; +} + void Light2D::set_z_range_min( int p_min_z) { z_min=p_min_z; @@ -160,15 +193,15 @@ int Light2D::get_item_shadow_mask() const { return item_shadow_mask; } -void Light2D::set_subtract_mode( bool p_enable ) { +void Light2D::set_mode( Mode p_mode ) { - subtract_mode=p_enable; - VS::get_singleton()->canvas_light_set_subtract_mode(canvas_light,p_enable); + mode=p_mode; + VS::get_singleton()->canvas_light_set_mode(canvas_light,VS::CanvasLightMode(p_mode)); } -bool Light2D::get_subtract_mode() const { +Light2D::Mode Light2D::get_mode() const { - return subtract_mode; + return mode; } void Light2D::set_shadow_enabled( bool p_enabled) { @@ -242,6 +275,13 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); + ObjectTypeDB::bind_method(_MD("set_energy","energy"),&Light2D::set_energy); + ObjectTypeDB::bind_method(_MD("get_energy"),&Light2D::get_energy); + + ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale); + ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale); + + ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min); @@ -261,8 +301,8 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_item_shadow_mask","item_shadow_mask"),&Light2D::set_item_shadow_mask); ObjectTypeDB::bind_method(_MD("get_item_shadow_mask"),&Light2D::get_item_shadow_mask); - ObjectTypeDB::bind_method(_MD("set_subtract_mode","enable"),&Light2D::set_subtract_mode); - ObjectTypeDB::bind_method(_MD("get_subtract_mode"),&Light2D::get_subtract_mode); + ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Light2D::set_mode); + ObjectTypeDB::bind_method(_MD("get_mode"),&Light2D::get_mode); ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); @@ -276,8 +316,10 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy"),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Add,Sub,Mix"),_SCS("set_mode"),_SCS("get_mode")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max")); @@ -289,6 +331,10 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier")); ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask")); + BIND_CONSTANT( MODE_ADD ); + BIND_CONSTANT( MODE_SUB ); + BIND_CONSTANT( MODE_MIX ); + } @@ -299,15 +345,17 @@ Light2D::Light2D() { shadow=false; color=Color(1,1,1); height=0; + _scale=1.0; z_min=-1024; z_max=1024; layer_min=0; layer_max=0; item_mask=1; item_shadow_mask=1; - subtract_mode=false; + mode=MODE_ADD; shadow_buffer_size=2048; shadow_esm_multiplier=80; + energy=1.0; } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 26dc1f4d44..ef875aec2f 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -6,12 +6,21 @@ class Light2D : public Node2D { OBJ_TYPE(Light2D,Node2D); +public: + enum Mode { + MODE_ADD, + MODE_SUB, + MODE_MIX, + }; + private: RID canvas_light; bool enabled; bool shadow; Color color; float height; + float _scale; + float energy; int z_min; int z_max; int layer_min; @@ -20,7 +29,7 @@ private: int item_shadow_mask; int shadow_buffer_size; float shadow_esm_multiplier; - bool subtract_mode; + Mode mode; Ref<Texture> texture; Vector2 texture_offset; @@ -50,6 +59,12 @@ public: void set_height( float p_height); float get_height() const; + void set_energy( float p_energy); + float get_energy() const; + + void set_texture_scale( float p_scale); + float get_texture_scale() const; + void set_z_range_min( int p_min_z); int get_z_range_min() const; @@ -68,8 +83,8 @@ public: void set_item_shadow_mask( int p_mask); int get_item_shadow_mask() const; - void set_subtract_mode( bool p_enable ); - bool get_subtract_mode() const; + void set_mode( Mode p_mode ); + Mode get_mode() const; void set_shadow_enabled( bool p_enabled); bool is_shadow_enabled() const; @@ -86,5 +101,6 @@ public: ~Light2D(); }; +VARIANT_ENUM_CAST(Light2D::Mode); #endif // LIGHT_2D_H diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 36b6b220b3..0b098f0cad 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -65,7 +65,7 @@ void Node2D::edit_set_state(const Variant& p_state) { pos = state[0]; angle = state[1]; - scale = state[2]; + _scale = state[2]; _update_transform(); _change_notify("transform/rot"); _change_notify("transform/scale"); @@ -93,11 +93,11 @@ void Node2D::edit_set_rect(const Rect2& p_edit_rect) { Point2 new_pos = p_edit_rect.pos + p_edit_rect.size*zero_offset;//p_edit_rect.pos - r.pos; Matrix32 postxf; - postxf.set_rotation_and_scale(angle,scale); + postxf.set_rotation_and_scale(angle,_scale); new_pos = postxf.xform(new_pos); pos+=new_pos; - scale*=new_scale; + _scale*=new_scale; _update_transform(); _change_notify("transform/scale"); @@ -118,14 +118,14 @@ void Node2D::_update_xform_values() { pos=_mat.elements[2]; angle=_mat.get_rotation(); - scale=_mat.get_scale(); + _scale=_mat.get_scale(); _xform_dirty=false; } void Node2D::_update_transform() { Matrix32 mat(angle,pos); - _mat.set_rotation_and_scale(angle,scale); + _mat.set_rotation_and_scale(angle,_scale); _mat.elements[2]=pos; VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat); @@ -161,11 +161,11 @@ void Node2D::set_scale(const Size2& p_scale) { if (_xform_dirty) ((Node2D*)this)->_update_xform_values(); - scale=p_scale; - if (scale.x==0) - scale.x=CMP_EPSILON; - if (scale.y==0) - scale.y=CMP_EPSILON; + _scale=p_scale; + if (_scale.x==0) + _scale.x=CMP_EPSILON; + if (_scale.y==0) + _scale.y=CMP_EPSILON; _update_transform(); _change_notify("transform/scale"); @@ -187,7 +187,7 @@ Size2 Node2D::get_scale() const { if (_xform_dirty) ((Node2D*)this)->_update_xform_values(); - return scale; + return _scale; } void Node2D::_set_rotd(float p_angle) { @@ -224,11 +224,27 @@ Rect2 Node2D::get_item_rect() const { return Rect2(Point2(-32,-32),Size2(64,64)); } -void Node2D::rotate(float p_degrees) { +void Node2D::rotate(float p_radians) { - set_rot( get_rot() + p_degrees); + set_rot( get_rot() + p_radians); } +void Node2D::translate(const Vector2& p_amount) { + + set_pos( get_pos() + p_amount ); +} + +void Node2D::global_translate(const Vector2& p_amount) { + + set_global_pos( get_global_pos() + p_amount ); +} + +void Node2D::scale(const Vector2& p_amount) { + + set_scale( get_scale() * p_amount ); +} + + void Node2D::move_x(float p_delta,bool p_scaled){ Matrix32 t = get_transform(); @@ -345,9 +361,12 @@ void Node2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_rot"),&Node2D::get_rot); ObjectTypeDB::bind_method(_MD("get_scale"),&Node2D::get_scale); - ObjectTypeDB::bind_method(_MD("rotate","degrees"),&Node2D::rotate); + ObjectTypeDB::bind_method(_MD("rotate","radians"),&Node2D::rotate); ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("translate","offset"),&Node2D::translate); + ObjectTypeDB::bind_method(_MD("global_translate","offset"),&Node2D::global_translate); + ObjectTypeDB::bind_method(_MD("scale","ratio"),&Node2D::scale); ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos); ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos); @@ -379,7 +398,7 @@ Node2D::Node2D() { angle=0; - scale=Vector2(1,1); + _scale=Vector2(1,1); _xform_dirty=false; z=0; z_relative=true; diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 7b059008c2..39a1061195 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -37,7 +37,7 @@ class Node2D : public CanvasItem { Point2 pos; float angle; - Size2 scale; + Size2 _scale; int z; bool z_relative; @@ -72,9 +72,12 @@ public: void set_rot(float p_angle); void set_scale(const Size2& p_scale); - void rotate(float p_degrees); + void rotate(float p_radians); void move_x(float p_delta,bool p_scaled=false); void move_y(float p_delta,bool p_scaled=false); + void translate(const Vector2& p_amount); + void global_translate(const Vector2& p_amount); + void scale(const Vector2& p_amount); Point2 get_pos() const; float get_rot() const; @@ -96,6 +99,7 @@ public: Matrix32 get_relative_transform(const Node *p_parent) const; + Matrix32 get_transform() const; Node2D(); diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 6e2cf5954b..c9dd92ff3d 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -1077,13 +1077,18 @@ void Particles2D::_bind_methods() { BIND_CONSTANT( PARAM_SPREAD ); BIND_CONSTANT( PARAM_LINEAR_VELOCITY ); BIND_CONSTANT( PARAM_SPIN_VELOCITY ); + BIND_CONSTANT( PARAM_ORBIT_VELOCITY ); BIND_CONSTANT( PARAM_GRAVITY_DIRECTION ); BIND_CONSTANT( PARAM_GRAVITY_STRENGTH ); BIND_CONSTANT( PARAM_RADIAL_ACCEL ); BIND_CONSTANT( PARAM_TANGENTIAL_ACCEL ); + BIND_CONSTANT( PARAM_DAMPING ); + BIND_CONSTANT( PARAM_INITIAL_ANGLE ); BIND_CONSTANT( PARAM_INITIAL_SIZE ); BIND_CONSTANT( PARAM_FINAL_SIZE ); BIND_CONSTANT( PARAM_HUE_VARIATION ); + BIND_CONSTANT( PARAM_ANIM_SPEED_SCALE ); + BIND_CONSTANT( PARAM_ANIM_INITIAL_POS ); BIND_CONSTANT( PARAM_MAX ); BIND_CONSTANT( MAX_COLOR_PHASES ); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 6f18325212..5457182ea7 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -98,6 +98,7 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject mask=1; set_one_way_collision_max_depth(0); + set_pickable(false); } @@ -1197,7 +1198,7 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody2D::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody2D::move_to); - ObjectTypeDB::bind_method(_MD("can_move_to","position"),&KinematicBody2D::can_move_to); + ObjectTypeDB::bind_method(_MD("can_move_to","position","discrete"),&KinematicBody2D::can_move_to,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody2D::is_colliding); diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index cd3c788b65..abaaf3262a 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -65,8 +65,13 @@ void VisibilityNotifier2D::_exit_viewport(Viewport* p_viewport){ void VisibilityNotifier2D::set_rect(const Rect2& p_rect){ rect=p_rect; - if (is_inside_tree()) + if (is_inside_tree()) { get_world_2d()->_update_notifier(this,get_global_transform().xform(rect)); + if (get_tree()->is_editor_hint()) { + update(); + item_rect_changed(); + } + } _change_notify("rect"); } diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 1109139180..db69182ca0 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -680,8 +680,6 @@ void Camera::_bind_methods() { ObjectTypeDB::bind_method( _MD("get_projection"),&Camera::get_projection ); ObjectTypeDB::bind_method( _MD("set_visible_layers","mask"),&Camera::set_visible_layers ); ObjectTypeDB::bind_method( _MD("get_visible_layers"),&Camera::get_visible_layers ); - ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Camera::look_at ); - ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Camera::look_at_from_pos ); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&Camera::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment); ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode); @@ -752,22 +750,6 @@ Vector<Plane> Camera::get_frustum() const { -void Camera::look_at(const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=get_camera_transform().origin; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); -} - -void Camera::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=p_pos; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); - -} void Camera::set_v_offset(float p_offset) { diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 950688dfda..de03282021 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -139,8 +139,6 @@ public: void set_keep_aspect_mode(KeepAspect p_aspect); KeepAspect get_keep_aspect_mode() const; - void look_at(const Vector3& p_target, const Vector3& p_up_normal); - void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void set_v_offset(float p_offset); float get_v_offset() const; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index ce002fb44b..6612d6bf12 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -490,10 +490,10 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector } -Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to) { +Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision) { - bool use_collision=false; + bool use_collision=p_use_collision; Vector3 closest_point; float closest_point_d=1e20; NavMesh *closest_navmesh=NULL; @@ -633,7 +633,7 @@ void Navigation::_bind_methods() { ObjectTypeDB::bind_method(_MD("navmesh_remove","id"),&Navigation::navmesh_remove); ObjectTypeDB::bind_method(_MD("get_simple_path","start","end","optimize"),&Navigation::get_simple_path,DEFVAL(true)); - ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end"),&Navigation::get_closest_point_to_segment); + ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end","use_collision"),&Navigation::get_closest_point_to_segment,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_closest_point","to_point"),&Navigation::get_closest_point); ObjectTypeDB::bind_method(_MD("get_closest_point_normal","to_point"),&Navigation::get_closest_point_normal); diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 69d48531a7..19977c3110 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -135,7 +135,7 @@ public: void navmesh_remove(int p_id); Vector<Vector3> get_simple_path(const Vector3& p_start, const Vector3& p_end,bool p_optimize=true); - Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to); + Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision=false); Vector3 get_closest_point(const Vector3& p_point); Vector3 get_closest_point_normal(const Vector3& p_point); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a5b009823c..6e11855543 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -593,6 +593,97 @@ bool Spatial::_is_visible_() const { return !is_hidden(); } +void Spatial::rotate(const Vector3& p_normal,float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(p_normal,p_radians); + set_transform(t); +} + +void Spatial::rotate_x(float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(Vector3(1,0,0),p_radians); + set_transform(t); + +} + +void Spatial::rotate_y(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,1,0),p_radians); + set_transform(t); + +} +void Spatial::rotate_z(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,0,1),p_radians); + set_transform(t); + +} + +void Spatial::translate(const Vector3& p_offset){ + + Transform t =get_transform(); + t.origin+=p_offset; + set_transform(t); + +} +void Spatial::scale(const Vector3& p_ratio){ + + Transform t =get_transform(); + t.basis.scale(p_ratio); + set_transform(t); + +} +void Spatial::global_rotate(const Vector3& p_normal,float p_radians){ + + Matrix3 rotation(p_normal,p_radians); + Transform t = get_global_transform(); + t.basis= rotation * t.basis; + set_global_transform(t); + +} +void Spatial::global_translate(const Vector3& p_offset){ + Transform t = get_global_transform(); + t.origin+=p_offset; + set_global_transform(t); + +} + +void Spatial::orthonormalize() { + + Transform t = get_transform(); + t.orthonormalize(); + set_transform(t); + +} + +void Spatial::set_identity() { + + set_transform(Transform()); + +} + + +void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=get_global_transform().origin; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); +} + +void Spatial::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=p_pos; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); + +} + void Spatial::_bind_methods() { @@ -633,6 +724,28 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + ObjectTypeDB::bind_method( _MD("rotate","normal","radians"),&Spatial::rotate ); + ObjectTypeDB::bind_method( _MD("global_rotate","normal","radians"),&Spatial::global_rotate ); + ObjectTypeDB::bind_method( _MD("rotate_x","radians"),&Spatial::rotate_x ); + ObjectTypeDB::bind_method( _MD("rotate_y","radians"),&Spatial::rotate_y ); + ObjectTypeDB::bind_method( _MD("rotate_z","radians"),&Spatial::rotate_z ); + ObjectTypeDB::bind_method( _MD("translate","offset"),&Spatial::translate ); + ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); + ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); + ObjectTypeDB::bind_method( _MD("set_identity"),&Spatial::set_identity ); + + ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Spatial::look_at ); + ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); + BIND_CONSTANT( NOTIFICATION_TRANSFORM_CHANGED ); BIND_CONSTANT( NOTIFICATION_ENTER_WORLD ); BIND_CONSTANT( NOTIFICATION_EXIT_WORLD ); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 49ecf5779b..f2cde8f1e6 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -167,6 +167,21 @@ public: Transform get_relative_transform(const Node *p_parent) const; + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + void look_at(const Vector3& p_target, const Vector3& p_up_normal); + void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); + + void orthonormalize(); + void set_identity(); + void show(); void hide(); bool is_visible() const; diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 0167687621..bbe15da1cc 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -279,12 +279,12 @@ void BaseButton::set_disabled(bool p_disabled) { set_focus_mode(FOCUS_NONE); else set_focus_mode(FOCUS_ALL); -}; +} bool BaseButton::is_disabled() const { return status.disabled; -}; +} void BaseButton::set_pressed(bool p_pressed) { @@ -391,6 +391,7 @@ void BaseButton::_bind_methods() { ADD_SIGNAL( MethodInfo("toggled", PropertyInfo( Variant::BOOL,"pressed") ) ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "disabled"), _SCS("set_disabled"), _SCS("is_disabled")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode")); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press")); diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp new file mode 100644 index 0000000000..309152ba8f --- /dev/null +++ b/scene/gui/check_box.cpp @@ -0,0 +1,79 @@ +/*************************************************************************/ +/* check_button.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "check_box.h" + +#include "servers/visual_server.h" +#include "button_group.h" + + +void CheckBox::_notification(int p_what) { + + if (p_what==NOTIFICATION_DRAW) { + + RID ci = get_canvas_item(); + + Ref<Texture> on=Control::get_icon(is_radio() ? "radio_checked" : "checked"); + Ref<Texture> off=Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked"); + + Vector2 ofs; + ofs.x = 0; + ofs.y = int((get_size().height - on->get_height())/2); + + if (is_pressed()) + on->draw(ci,ofs); + else + off->draw(ci,ofs); + + + } +} + +bool CheckBox::is_radio() +{ + Node* parent = this; + do { + parent = parent->get_parent(); + if (dynamic_cast< ButtonGroup* >(parent)) + break; + } while (parent); + + return (parent != 0); +} + +CheckBox::CheckBox(const String &p_text): + Button(p_text) +{ + set_toggle_mode(true); + set_text_align(ALIGN_LEFT); + +} + +CheckBox::~CheckBox() +{ +} diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h new file mode 100644 index 0000000000..171fd55351 --- /dev/null +++ b/scene/gui/check_box.h @@ -0,0 +1,55 @@ +/*************************************************************************/ +/* check_box.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef CHECK_BOX_H +#define CHECK_BOX_H + + +#include "scene/gui/button.h" +/** +@author Mariano Suligoy <marianognu.esyrpg@gmail.com> +*/ +class CheckBox : public Button { + + OBJ_TYPE( CheckBox, Button ); + + +protected: + void _notification(int p_what); + + bool is_radio(); + + +public: + + CheckBox(const String& p_text=String()); + ~CheckBox(); + +}; + +#endif diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 193649c815..d944b804a5 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -352,6 +352,7 @@ void ColorPickerButton::set_color(const Color& p_color){ picker->set_color(p_color); + update(); } Color ColorPickerButton::get_color() const{ diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 86f442fd8c..c539dc3284 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2869,7 +2869,7 @@ void Control::_bind_methods() { BIND_CONSTANT( SIZE_EXPAND_FILL ); ADD_SIGNAL( MethodInfo("resized") ); - ADD_SIGNAL( MethodInfo("input_event") ); + ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) ); ADD_SIGNAL( MethodInfo("mouse_enter") ); ADD_SIGNAL( MethodInfo("mouse_exit") ); ADD_SIGNAL( MethodInfo("focus_enter") ); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index fbcfdb69bb..2e8a84e39b 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -29,6 +29,8 @@ #include "file_dialog.h" #include "scene/gui/label.h" #include "print_string.h" +#include "os/keyboard.h" + FileDialog::GetIconFunc FileDialog::get_icon_func=NULL; @@ -278,13 +280,20 @@ void FileDialog::update_file_list() { List<String> dirs; bool isdir; + bool ishidden; + bool show_hidden = show_hidden_files; String item; + while ((item=dir_access->get_next(&isdir))!="") { - - if (!isdir) - files.push_back(item); - else - dirs.push_back(item); + + ishidden = dir_access->current_is_hidden(); + + if (show_hidden || !ishidden) { + if (!isdir) + files.push_back(item); + else + dirs.push_back(item); + } } dirs.sort_custom<NoCaseComparator>(); @@ -616,6 +625,9 @@ void FileDialog::_update_drives() { } } +bool FileDialog::default_show_hidden_files=true; + + void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected); @@ -640,6 +652,8 @@ void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_vbox:VBoxContainer"),&FileDialog::get_vbox); ObjectTypeDB::bind_method(_MD("set_access","access"),&FileDialog::set_access); ObjectTypeDB::bind_method(_MD("get_access"),&FileDialog::get_access); + ObjectTypeDB::bind_method(_MD("set_show_hidden_files"),&FileDialog::set_show_hidden_files); + ObjectTypeDB::bind_method(_MD("is_showing_hidden_files"),&FileDialog::is_showing_hidden_files); ObjectTypeDB::bind_method(_MD("_select_drive"),&FileDialog::_select_drive); ObjectTypeDB::bind_method(_MD("_make_dir"),&FileDialog::_make_dir); ObjectTypeDB::bind_method(_MD("_make_dir_confirm"),&FileDialog::_make_dir_confirm); @@ -664,9 +678,23 @@ void FileDialog::_bind_methods() { } +void FileDialog::set_show_hidden_files(bool p_show) { + show_hidden_files=p_show; + invalidate(); +} + +bool FileDialog::is_showing_hidden_files() const { + return show_hidden_files; +} + +void FileDialog::set_default_show_hidden_files(bool p_show) { + default_show_hidden_files=p_show; +} FileDialog::FileDialog() { - + + show_hidden_files=true; + VBoxContainer *vbc = memnew( VBoxContainer ); add_child(vbc); set_child_rect(vbc); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index bda1797696..6b35035829 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -89,6 +89,10 @@ private: Vector<String> filters; + + static bool default_show_hidden_files; + bool show_hidden_files; + bool invalidated; void update_dir(); @@ -141,6 +145,11 @@ public: void set_access(Access p_access); Access get_access() const; + void set_show_hidden_files(bool p_show); + bool is_showing_hidden_files() const; + + static void set_default_show_hidden_files(bool p_show); + void invalidate(); FileDialog(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index d2e1e7f0b9..892e4c9bc7 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -72,6 +72,7 @@ void Label::_notification(int p_what) { if (clip && !autowrap) VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + if (word_cache_dirty) regenerate_word_cache(); @@ -87,7 +88,8 @@ void Label::_notification(int p_what) { bool use_outlinde = get_constant("shadow_as_outline"); Point2 shadow_ofs(get_constant("shadow_offset_x"),get_constant("shadow_offset_y")); - + VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(),font.is_valid() && font->is_distance_field_hint()); + int font_h = font->get_height(); int line_from=(int)get_val(); // + p_exposed.pos.y / font_h; int lines_visible = size.y/font_h; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8855627bb4..b26b55f076 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -498,7 +498,29 @@ void TextEdit::_notification(int p_what) { for(int j=from;j<text[i].length();j++) { CharType cc = text[i][j]; - if (cc==c) + //ignore any brackets inside a string + if (cc== '"' | cc == '\'') { + CharType quotation = cc; + do { + j++; + if (!(j<text[i].length())) { + break; + } + cc=text[i][j]; + //skip over escaped quotation marks inside strings + if (cc=='\\') { + bool escaped = true; + while (j+1<text[i].length() && text[i][j+1]=='\\') { + escaped=!escaped; + j++; + } + if (escaped) { + j++; + continue; + } + } + } while (cc!= quotation); + } else if (cc==c) stack++; else if (cc==closec) stack--; @@ -547,7 +569,30 @@ void TextEdit::_notification(int p_what) { for(int j=from;j>=0;j--) { CharType cc = text[i][j]; - if (cc==c) + //ignore any brackets inside a string + if (cc== '"' | cc == '\'') { + CharType quotation = cc; + do { + j--; + if (!(j>=0)) { + break; + } + cc=text[i][j]; + //skip over escaped quotation marks inside strings + if (cc==quotation) { + bool escaped = false; + while (j-1>=0 && text[i][j-1]=='\\') { + escaped=!escaped; + j--; + } + if (escaped) { + j--; + cc='\\'; + continue; + } + } + } while (cc!= quotation); + } else if (cc==c) stack++; else if (cc==closec) stack--; @@ -1345,7 +1390,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { return; } - if (k.scancode==KEY_HOME) { + if (k.scancode==KEY_HOME && completion_index>0) { completion_index=0; completion_current=completion_options[completion_index]; @@ -1354,7 +1399,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { return; } - if (k.scancode==KEY_END) { + if (k.scancode==KEY_END && completion_index<completion_options.size()-1) { completion_index=completion_options.size()-1; completion_current=completion_options[completion_index]; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 02e009866f..ee400ae6d5 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -30,7 +30,7 @@ #include "os/os.h" #include "scene/3d/spatial.h" #include "os/input.h" - +#include "servers/physics_2d_server.h" //#include "scene/3d/camera.h" #include "servers/spatial_sound_server.h" @@ -40,7 +40,7 @@ #include "scene/3d/spatial_indexer.h" #include "scene/3d/collision_object.h" - +#include "scene/2d/collision_object_2d.h" int RenderTargetTexture::get_width() const { @@ -104,8 +104,10 @@ void Viewport::_update_stretch_transform() { stretch_transform.scale(scale); stretch_transform.elements[2]=size_override_margin*scale; + } else { + stretch_transform=Matrix32(); } @@ -355,11 +357,12 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_FIXED_PROCESS: { if (physics_object_picking) { -#ifndef _3D_DISABLED + Vector2 last_pos(1e20,1e20); CollisionObject *last_object; ObjectID last_id=0; PhysicsDirectSpaceState::RayResult result; + Physics2DDirectSpaceState *ss2d=Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); bool motion_tested=false; @@ -392,6 +395,60 @@ void Viewport::_notification(int p_what) { } + if (ss2d) { + //send to 2D + + + uint64_t frame = get_tree()->get_frame(); + + Vector2 point = get_canvas_transform().affine_inverse().xform(pos); + Physics2DDirectSpaceState::ShapeResult res[64]; + int rc = ss2d->intersect_point(point,res,64,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF); + for(int i=0;i<rc;i++) { + + if (res[i].collider) { + CollisionObject2D *co=res[i].collider->cast_to<CollisionObject2D>(); + if (co) { + + Map<ObjectID,uint64_t>::Element *E=physics_2d_mouseover.find(res[i].collider_id); + if (!E) { + E=physics_2d_mouseover.insert(res[i].collider_id,frame); + co->_mouse_enter(); + } else { + E->get()=frame; + } + + co->_input_event(this,ev,res[i].shape); + } + } + } + + List<Map<ObjectID,uint64_t>::Element*> to_erase; + + for (Map<ObjectID,uint64_t>::Element*E=physics_2d_mouseover.front();E;E=E->next()) { + if (E->get()!=frame) { + Object *o=ObjectDB::get_instance(E->key()); + if (o) { + + CollisionObject2D *co=o->cast_to<CollisionObject2D>(); + if (co) { + co->_mouse_exit(); + } + } + to_erase.push_back(E); + } + } + + while(to_erase.size()) { + physics_2d_mouseover.erase(to_erase.front()->get()); + to_erase.pop_front(); + } + + } + + + +#ifndef _3D_DISABLED bool captured=false; if (physics_object_capture!=0) { @@ -499,9 +556,9 @@ void Viewport::_notification(int p_what) { _test_new_mouseover(new_collider); } - - } #endif + } + } } break; @@ -1021,8 +1078,9 @@ Matrix32 Viewport::_get_input_pre_xform() const { ERR_FAIL_COND_V(to_screen_rect.size.x==0,pre_xf); ERR_FAIL_COND_V(to_screen_rect.size.y==0,pre_xf); - pre_xf.scale(rect.size/to_screen_rect.size); + pre_xf.elements[2]=-to_screen_rect.pos; + pre_xf.scale(rect.size/to_screen_rect.size); } else { pre_xf.elements[2]=-rect.pos; @@ -1086,6 +1144,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; } + } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d2a22401bd..14f4f68217 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -124,6 +124,7 @@ friend class RenderTargetTexture; ObjectID physics_object_over; Vector2 physics_last_mousepos; void _test_new_mouseover(ObjectID new_collider); + Map<ObjectID,uint64_t> physics_2d_mouseover; void _update_rect(); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index f90db42614..afadbf0170 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -53,6 +53,7 @@ #include "scene/gui/color_picker.h" #include "scene/gui/texture_frame.h" #include "scene/gui/menu_button.h" +#include "scene/gui/check_box.h" #include "scene/gui/check_button.h" #include "scene/gui/tab_container.h" #include "scene/gui/panel_container.h" @@ -76,6 +77,7 @@ #include "scene/gui/reference_frame.h" #include "scene/gui/graph_node.h" #include "scene/gui/graph_edit.h" +#include "scene/gui/tool_button.h" #include "scene/resources/video_stream.h" #include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" @@ -86,6 +88,7 @@ #include "scene/2d/sprite.h" #include "scene/2d/animated_sprite.h" #include "scene/2d/polygon_2d.h" +#include "scene/2d/back_buffer_copy.h" #include "scene/2d/visibility_notifier_2d.h" @@ -288,7 +291,9 @@ void register_scene_types() { ObjectTypeDB::register_type<Popup>(); ObjectTypeDB::register_type<PopupPanel>(); ObjectTypeDB::register_type<MenuButton>(); + ObjectTypeDB::register_type<CheckBox>(); ObjectTypeDB::register_type<CheckButton>(); + ObjectTypeDB::register_type<ToolButton>(); ObjectTypeDB::register_type<Panel>(); ObjectTypeDB::register_type<Range>(); @@ -481,6 +486,7 @@ void register_scene_types() { ObjectTypeDB::register_type<LightOccluder2D>(); ObjectTypeDB::register_type<OccluderPolygon2D>(); ObjectTypeDB::register_type<YSort>(); + ObjectTypeDB::register_type<BackBufferCopy>(); ObjectTypeDB::set_type_enabled("CollisionShape2D",false); ObjectTypeDB::set_type_enabled("CollisionPolygon2D",false); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 4d1e9896db..7d5981522e 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -300,6 +300,40 @@ void make_default_theme() { t->set_constant("hseparation","MenuButton", 0 ); + // CheckBox + + Ref<StyleBox> cbx_empty = memnew( StyleBoxEmpty ); + cbx_empty->set_default_margin(MARGIN_LEFT,22); + cbx_empty->set_default_margin(MARGIN_RIGHT,4); + cbx_empty->set_default_margin(MARGIN_TOP,4); + cbx_empty->set_default_margin(MARGIN_BOTTOM,5); + Ref<StyleBox> cbx_focus = focus; + cbx_focus->set_default_margin(MARGIN_LEFT,4); + cbx_focus->set_default_margin(MARGIN_RIGHT,22); + cbx_focus->set_default_margin(MARGIN_TOP,4); + cbx_focus->set_default_margin(MARGIN_BOTTOM,5); + + t->set_stylebox("normal","CheckBox", cbx_empty ); + t->set_stylebox("pressed","CheckBox", cbx_empty ); + t->set_stylebox("disabled","CheckBox", cbx_empty ); + t->set_stylebox("hover","CheckBox", cbx_empty ); + t->set_stylebox("focus","CheckBox", cbx_focus ); + + t->set_icon("checked", "CheckBox", make_icon(checked_png)); + t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png)); + t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png)); + t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png)); + + t->set_font("font","CheckBox", default_font ); + + t->set_color("font_color","CheckBox", control_font_color ); + t->set_color("font_color_pressed","CheckBox", control_font_color_pressed ); + t->set_color("font_color_hover","CheckBox", control_font_color_hover ); + t->set_color("font_color_disabled","CheckBox", control_font_color_disabled ); + + t->set_constant("hseparation","CheckBox",4); + t->set_constant("check_vadjust","CheckBox",0); + // CheckButton @@ -308,7 +342,7 @@ void make_default_theme() { cb_empty->set_default_margin(MARGIN_LEFT,6); cb_empty->set_default_margin(MARGIN_RIGHT,70); cb_empty->set_default_margin(MARGIN_TOP,4); - cb_empty->set_default_margin(MARGIN_BOTTOM,4); + cb_empty->set_default_margin(MARGIN_BOTTOM,4); t->set_stylebox("normal","CheckButton", cb_empty ); t->set_stylebox("pressed","CheckButton", cb_empty ); @@ -540,7 +574,7 @@ void make_default_theme() { // Tree Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0); - Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); + Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) ); t->set_stylebox("bg_focus","Tree", focus ); diff --git a/scene/resources/default_theme/radio_checked.png b/scene/resources/default_theme/radio_checked.png Binary files differnew file mode 100644 index 0000000000..ada8dde3c1 --- /dev/null +++ b/scene/resources/default_theme/radio_checked.png diff --git a/scene/resources/default_theme/radio_unchecked.png b/scene/resources/default_theme/radio_unchecked.png Binary files differnew file mode 100644 index 0000000000..018af99afd --- /dev/null +++ b/scene/resources/default_theme/radio_unchecked.png diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index e9a6d3dad6..78e210239d 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -264,6 +264,16 @@ static const unsigned char progress_fill_png[]={ }; +static const unsigned char radio_checked_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x3,0x1,0x4,0x19,0x36,0x83,0x13,0x8d,0xb2,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x1,0x9d,0x49,0x44,0x41,0x54,0x38,0xcb,0xad,0x93,0x31,0x6b,0xdb,0x50,0x14,0x85,0x3f,0x59,0x8a,0x21,0xbb,0x17,0xd1,0x37,0xa4,0xa4,0xb5,0x10,0xb5,0x3,0xfa,0x7,0x5d,0x3a,0x74,0xf2,0x56,0x39,0x64,0x4d,0x97,0x42,0x9b,0xce,0x6d,0x7e,0x44,0xe3,0x8e,0xf5,0x60,0x4,0xc5,0x22,0x9b,0x27,0x63,0xe8,0xea,0xc5,0x43,0x4d,0x48,0x40,0x7a,0xe9,0xd0,0xe0,0xd4,0x68,0x32,0x18,0x3c,0x8,0x64,0xc3,0xed,0x50,0x59,0x34,0x71,0xa7,0x3a,0x7,0xde,0x72,0xef,0x79,0x87,0x7b,0xde,0x3d,0xf,0xb6,0x84,0x71,0xbf,0xe0,0x38,0xce,0x23,0xe0,0x2d,0xf0,0x12,0xa8,0xe6,0xe5,0x6b,0xa0,0xf,0x7c,0xd6,0x5a,0x4f,0xff,0x29,0x60,0x99,0x16,0xfb,0x4f,0xf6,0x8f,0x81,0x56,0xb3,0x79,0xb4,0x7b,0x78,0xf8,0xa,0xc3,0xf8,0xd3,0x16,0x11,0xba,0xdd,0x73,0xc2,0xf0,0x6b,0xa,0xbc,0x9b,0x4c,0x26,0xed,0x34,0x4d,0xef,0xa,0x38,0x8e,0x73,0xbc,0xb7,0xf7,0xf8,0xcb,0xd9,0xd9,0xa7,0xe2,0xe2,0x7d,0x88,0x8,0x27,0x27,0xef,0xb9,0xb9,0xf9,0xf9,0x5a,0x6b,0xdd,0x2e,0x4,0xf2,0xb1,0x7f,0xf4,0x7a,0xbd,0x5d,0xc3,0x30,0xc8,0xb2,0x8c,0xf1,0x78,0x4c,0x14,0x45,0x0,0xb8,0xae,0x8b,0xe7,0x79,0x94,0xcb,0x65,0x44,0x84,0x46,0xa3,0x91,0x2,0x4f,0xb5,0xd6,0x53,0x13,0xa0,0x52,0xa9,0x7c,0x6c,0x36,0x8f,0x9e,0x1f,0x1c,0xd4,0xc8,0xb2,0x8c,0x4e,0xa7,0x43,0xab,0xd5,0x62,0x30,0x18,0x30,0x1c,0xe,0x19,0x8d,0x46,0xac,0x56,0x2b,0xea,0xf5,0x3a,0x96,0x65,0x21,0x52,0xda,0xb9,0xba,0xba,0x5c,0xce,0x66,0xb3,0x6f,0xeb,0xf1,0x2f,0xe2,0x38,0x16,0xad,0xb5,0x4,0x41,0x20,0x4a,0x29,0x1,0xee,0x1c,0xa5,0x94,0x4,0x41,0x20,0x5a,0x6b,0x89,0xe3,0x58,0x1c,0xc7,0xb9,0x0,0x28,0xe5,0xf6,0xaa,0x6b,0xdf,0x51,0x14,0x91,0x24,0xc9,0x86,0xff,0x24,0x49,0xa,0x4b,0x39,0xb7,0xfa,0xb7,0xc0,0x7f,0x63,0x2d,0x70,0x2d,0x22,0xc5,0x83,0xd9,0xb6,0xbd,0x41,0xb4,0x6d,0x1b,0xd7,0x75,0x8b,0x6d,0xe4,0xd9,0x28,0x4,0xfa,0xdd,0xee,0x39,0x0,0x9e,0xe7,0xe1,0xfb,0x3e,0x4a,0x29,0x4c,0xd3,0xc4,0x34,0x4d,0x94,0x52,0xf8,0xbe,0x8f,0xe7,0x79,0x0,0xe4,0xdc,0xfe,0x83,0xac,0x71,0xeb,0x20,0x99,0xeb,0xe6,0x62,0xb1,0xf8,0x6e,0x18,0x4c,0xc3,0x30,0x7c,0x21,0x52,0xda,0xa9,0xd5,0x9e,0x6d,0x44,0xf9,0xf4,0xf4,0x43,0x3a,0x9f,0xcf,0xdf,0xdc,0xde,0xfe,0x6a,0x2f,0x97,0xcb,0x87,0xf9,0x4c,0x5b,0xe3,0x37,0x57,0xdf,0xd7,0x8,0xe6,0x62,0x7d,0xab,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + +static const unsigned char radio_unchecked_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x3,0x1,0x4,0x1b,0x6,0x97,0xfc,0xdf,0x9c,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x1,0x9,0x49,0x44,0x41,0x54,0x38,0xcb,0xad,0x93,0xbd,0x72,0x82,0x40,0x14,0x85,0xf,0x68,0xa,0x9e,0x21,0x8d,0x8e,0x9,0xdb,0xc4,0xc7,0x48,0x41,0x43,0x2b,0xa3,0xad,0x69,0x32,0xc3,0xda,0xc7,0xa7,0x8,0x94,0xa1,0xd,0x68,0x4b,0xc3,0x5b,0xd8,0x5f,0x2d,0xe2,0x60,0xe8,0x99,0xa1,0xd8,0x82,0xc2,0x34,0x17,0x67,0x35,0x19,0x43,0x34,0xa7,0xbc,0x7b,0xee,0x37,0xf7,0x6f,0x81,0x2b,0x65,0x9c,0x6,0x84,0x10,0xb7,0x0,0x7c,0x0,0xe,0x0,0x9b,0xc3,0x6b,0x0,0x19,0x80,0x90,0x88,0x8a,0x1f,0x1,0xdd,0x4e,0x17,0x83,0xbb,0xc1,0x14,0x40,0xe0,0x79,0x13,0x6b,0x3c,0x1e,0x1d,0x81,0xe3,0x78,0x89,0xc5,0xe2,0x5d,0x1,0x90,0x79,0x9e,0x47,0x4a,0xa9,0x63,0x80,0x10,0x62,0xda,0xeb,0xf5,0xdf,0x82,0xe0,0xf5,0x6c,0xc9,0x52,0xce,0xb0,0xdd,0x7e,0x3c,0x11,0x51,0x74,0x0,0x70,0xd9,0x9b,0x34,0x4d,0xad,0x36,0x7d,0xbb,0xae,0xab,0x0,0xdc,0x13,0x51,0x61,0x72,0xcc,0xf7,0xbc,0x89,0xd5,0x76,0x70,0xec,0xf5,0x1,0xa0,0x1,0x38,0xa7,0x3d,0x9f,0x13,0x7b,0x1d,0x1d,0x60,0x5f,0xb0,0x41,0x5b,0x7,0x5c,0x2c,0x53,0xdb,0xf3,0x5f,0xb5,0xd6,0x1,0x59,0x1c,0x2f,0x5b,0x67,0xb2,0x37,0xd3,0x1,0x21,0x1f,0x49,0x2b,0xb1,0x37,0x3c,0x0,0xf8,0x3c,0xa5,0x94,0xb3,0x5f,0x93,0xd9,0x23,0x9b,0x93,0xee,0x34,0xf,0x55,0x55,0xad,0xc,0x3,0x45,0x92,0x24,0x8f,0xfb,0xbd,0x79,0x33,0x1c,0x3e,0x7c,0x2b,0x7b,0x3e,0x7f,0x51,0x65,0x59,0x3e,0xef,0x76,0x9f,0x51,0x5d,0xd7,0xff,0xf3,0x99,0xae,0xd6,0x17,0xf,0x97,0x66,0x8b,0x3d,0xf1,0x64,0x47,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char reference_border_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdb,0x7,0x9,0x11,0x2b,0x1a,0xed,0xf3,0x18,0x82,0x0,0x0,0x0,0x5b,0x49,0x44,0x41,0x54,0x38,0xcb,0x63,0xfc,0xbf,0x7d,0xfb,0x7f,0x6,0x6,0x6,0x6,0x86,0xae,0x2e,0x6,0x92,0x40,0x59,0x19,0x84,0x86,0x1b,0x40,0x6,0xf8,0xbf,0x7d,0xfb,0x7f,0xc6,0xff,0x8e,0x8e,0xff,0x19,0xf7,0xef,0x67,0xfc,0x7f,0xf1,0x22,0x49,0x9a,0x19,0xf5,0xf5,0x19,0xfe,0x3b,0x3a,0xfe,0x67,0x41,0x17,0x24,0xca,0x66,0x24,0xcb,0x98,0x18,0x28,0x4,0xa3,0x6,0x8c,0x1a,0xc0,0xc0,0xc0,0xc0,0xc0,0x82,0x2b,0x85,0x91,0x94,0x21,0x28,0xcb,0x4c,0x14,0x66,0x67,0x0,0x0,0x2b,0x27,0xc7,0x5e,0xa8,0x15,0xe4,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 3c4bc3ac75..1e3b9772ee 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -108,13 +108,14 @@ void Environment::_bind_methods() { ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fxaa/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_FXAA); - ADD_PROPERTY( PropertyInfo(Variant::INT,"background/mode",PROPERTY_HINT_ENUM,"Keep,Default Color,Color,Texture,Cubemap,Texture RGBE,Cubemap RGBE"),_SCS("set_background"),_SCS("get_background")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"background/mode",PROPERTY_HINT_ENUM,"Keep,Default Color,Color,Texture,Cubemap,Canvas"),_SCS("set_background"),_SCS("get_background")); ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"background/color"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_COLOR); ADD_PROPERTYI( PropertyInfo(Variant::OBJECT,"background/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_TEXTURE); ADD_PROPERTYI( PropertyInfo(Variant::OBJECT,"background/cubemap",PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_CUBEMAP); ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/energy",PROPERTY_HINT_RANGE,"0,128,0.01"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_ENERGY); ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/scale",PROPERTY_HINT_RANGE,"0.001,16,0.001"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_SCALE); ADD_PROPERTYI( PropertyInfo(Variant::REAL,"background/glow",PROPERTY_HINT_RANGE,"0.00,8,0.01"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_GLOW); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"background/canvas_max_layer"),_SCS("set_background_param"),_SCS("get_background_param"), BG_PARAM_CANVAS_MAX_LAYER); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"glow/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_GLOW); ADD_PROPERTYI( PropertyInfo(Variant::INT,"glow/blur_passes",PROPERTY_HINT_RANGE,"1,4,1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_GLOW_BLUR_PASSES); @@ -182,10 +183,10 @@ void Environment::_bind_methods() { BIND_CONSTANT( BG_COLOR ); BIND_CONSTANT( BG_TEXTURE ); BIND_CONSTANT( BG_CUBEMAP ); - BIND_CONSTANT( BG_TEXTURE_RGBE ); - BIND_CONSTANT( BG_CUBEMAP_RGBE ); + BIND_CONSTANT( BG_CANVAS ); BIND_CONSTANT( BG_MAX ); + BIND_CONSTANT( BG_PARAM_CANVAS_MAX_LAYER ); BIND_CONSTANT( BG_PARAM_COLOR ); BIND_CONSTANT( BG_PARAM_TEXTURE ); BIND_CONSTANT( BG_PARAM_CUBEMAP ); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index a9e2f422b9..d672a898d5 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -44,14 +44,14 @@ public: BG_COLOR=VS::ENV_BG_COLOR, BG_TEXTURE=VS::ENV_BG_TEXTURE, BG_CUBEMAP=VS::ENV_BG_CUBEMAP, - BG_TEXTURE_RGBE=VS::ENV_BG_TEXTURE_RGBE, - BG_CUBEMAP_RGBE=VS::ENV_BG_CUBEMAP_RGBE, + BG_CANVAS=VS::ENV_BG_CANVAS, BG_MAX=VS::ENV_BG_MAX }; enum BGParam { - BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, + BG_PARAM_CANVAS_MAX_LAYER=VS::ENV_BG_PARAM_CANVAS_MAX_LAYER, + BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, BG_PARAM_TEXTURE=VS::ENV_BG_PARAM_TEXTURE, BG_PARAM_CUBEMAP=VS::ENV_BG_PARAM_CUBEMAP, BG_PARAM_ENERGY=VS::ENV_BG_PARAM_ENERGY, diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 49ee3ee017..79316f0019 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -398,6 +398,17 @@ int Font::get_kerning_pair(CharType p_A,CharType p_B) const { return 0; } +void Font::set_distance_field_hint(bool p_distance_field) { + + distance_field_hint=p_distance_field; + emit_changed(); +} + +bool Font::is_distance_field_hint() const{ + + return distance_field_hint; +} + void Font::clear() { @@ -406,6 +417,7 @@ void Font::clear() { char_map.clear(); textures.clear(); kerning_map.clear(); + distance_field_hint=false; } Size2 Font::get_string_size(const String& p_string) const { @@ -511,9 +523,16 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_texture","texture:Texture"),&Font::add_texture); ObjectTypeDB::bind_method(_MD("add_char","character","texture","rect","align","advance"),&Font::add_char,DEFVAL(Point2()),DEFVAL(-1)); + + ObjectTypeDB::bind_method(_MD("get_texture_count"),&Font::get_texture_count); + ObjectTypeDB::bind_method(_MD("get_texture:Texture","idx"),&Font::get_texture); + ObjectTypeDB::bind_method(_MD("get_char_size","char","next"),&Font::get_char_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size); + ObjectTypeDB::bind_method(_MD("set_distance_field_hint","enable"),&Font::set_distance_field_hint); + ObjectTypeDB::bind_method(_MD("is_distance_field_hint"),&Font::is_distance_field_hint); + ObjectTypeDB::bind_method(_MD("clear"),&Font::clear); ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","string","modulate","clip_w"),&Font::draw,DEFVAL(Color(1,1,1)),DEFVAL(-1)); @@ -535,12 +554,14 @@ void Font::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_height"), _SCS("get_height") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "ascent", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_ascent"), _SCS("get_ascent") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "distance_field" ), _SCS("set_distance_field_hint"), _SCS("is_distance_field_hint") ); } Font::Font() { clear(); + } diff --git a/scene/resources/font.h b/scene/resources/font.h index a64ec1ef7a..498bc6863a 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -75,6 +75,7 @@ private: float height; float ascent; + bool distance_field_hint; void _set_chars(const DVector<int>& p_chars); DVector<int> _get_chars() const; @@ -116,6 +117,9 @@ public: Size2 get_string_size(const String& p_string) const; void clear(); + + void set_distance_field_hint(bool p_distance_field); + bool is_distance_field_hint() const; void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const; diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index b0d9ceee0e..be54d649e2 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1351,15 +1351,24 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, //canvas item light in {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDist","LIGHT_DISTANCE","",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDir","vec3(LIGHT_DIR,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightHeight","LIGHT_HEIGHT","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN}, {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN}, //canvas item light out - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT.a","",SLOT_TYPE_SCALAR,SLOT_OUT}, //end {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT}, + + }; void ShaderGraph::get_input_output_node_slot_info(Mode p_mode, ShaderType p_type, List<SlotInfo> *r_slots) { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 2c1502288b..8d3cbadd06 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -321,6 +321,13 @@ void ImageTexture::premultiply_alpha() { } } +void ImageTexture::normal_to_xy() { + + Image img = get_data(); + img.normalmap_to_xy(); + create_from_image(img,flags); +} + bool ImageTexture::has_alpha() const { return ( format==Image::FORMAT_GRAYSCALE_ALPHA || format==Image::FORMAT_INDEXED_ALPHA || format==Image::FORMAT_RGBA ); @@ -405,9 +412,11 @@ void ImageTexture::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_lossy_storage_quality"),&ImageTexture::get_lossy_storage_quality); ObjectTypeDB::bind_method(_MD("fix_alpha_edges"),&ImageTexture::fix_alpha_edges); ObjectTypeDB::bind_method(_MD("premultiply_alpha"),&ImageTexture::premultiply_alpha); + ObjectTypeDB::bind_method(_MD("normal_to_xy"),&ImageTexture::normal_to_xy); ObjectTypeDB::bind_method(_MD("set_size_override","size"),&ImageTexture::set_size_override); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("fix_alpha_edges"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("premultiply_alpha"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::set_method_flags(get_type_static(),_SCS("normal_to_xy"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::bind_method(_MD("_reload_hook","rid"),&ImageTexture::_reload_hook); diff --git a/scene/resources/texture.h b/scene/resources/texture.h index c1122b005d..e853a4b05f 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -146,6 +146,8 @@ public: void fix_alpha_edges(); void premultiply_alpha(); + void normal_to_xy(); + void set_size_override(const Size2& p_size); diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp index 880a3a32e3..30cf58bdd8 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -307,6 +307,11 @@ Ref<Environment> World::get_environment() const { } +PhysicsDirectSpaceState *World::get_direct_space_state() { + + return PhysicsServer::get_singleton()->space_get_direct_state(space); +} + void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_space"),&World::get_space); @@ -314,6 +319,7 @@ void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_sound_space"),&World::get_sound_space); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&World::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&World::get_environment); + ObjectTypeDB::bind_method(_MD("get_direct_space_state:PhysicsDirectSpaceState"),&World::get_direct_space_state); ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment"),_SCS("set_environment"),_SCS("get_environment")); } diff --git a/scene/resources/world.h b/scene/resources/world.h index 60b3b99ab0..b10cadd6e0 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -75,6 +75,8 @@ public: void set_environment(const Ref<Environment>& p_environment); Ref<Environment> get_environment() const; + PhysicsDirectSpaceState *get_direct_space_state(); + World(); ~World(); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 0dd6a3d5e7..43a7af4bfd 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -352,8 +352,17 @@ void World2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_canvas"),&World2D::get_canvas); ObjectTypeDB::bind_method(_MD("get_space"),&World2D::get_space); ObjectTypeDB::bind_method(_MD("get_sound_space"),&World2D::get_sound_space); + + ObjectTypeDB::bind_method(_MD("get_direct_space_state:Physics2DDirectSpaceState"),&World2D::get_direct_space_state); + +} + +Physics2DDirectSpaceState *World2D::get_direct_space_state() { + + return Physics2DServer::get_singleton()->space_get_direct_state(space); } + World2D::World2D() { canvas = VisualServer::get_singleton()->canvas_create(); diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 3feb23495d..865ec28fe9 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -30,7 +30,7 @@ #define WORLD_2D_H #include "resource.h" - +#include "servers/physics_2d_server.h" class SpatialIndexer2D; class VisibilityNotifier2D; @@ -68,6 +68,8 @@ public: RID get_space(); RID get_sound_space(); + Physics2DDirectSpaceState *get_direct_space_state(); + World2D(); ~World2D(); }; diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index c30ff0044e..76cb5929cf 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -42,6 +42,7 @@ SceneStringNames::SceneStringNames() { input_event=StaticCString::create("input_event"); shader_shader=StaticCString::create("shader/shader"); shader_unshaded=StaticCString::create("shader/unshaded"); + shading_mode=StaticCString::create("shader/shading_mode"); enter_tree=StaticCString::create("enter_tree"); exit_tree=StaticCString::create("exit_tree"); item_rect_changed=StaticCString::create("item_rect_changed"); @@ -64,6 +65,9 @@ SceneStringNames::SceneStringNames() { body_exit_shape = StaticCString::create("body_exit_shape"); body_exit = StaticCString::create("body_exit"); + area_enter_shape = StaticCString::create("area_enter_shape"); + area_exit_shape = StaticCString::create("area_exit_shape"); + idle=StaticCString::create("idle"); iteration=StaticCString::create("iteration"); @@ -103,6 +107,9 @@ SceneStringNames::SceneStringNames() { _body_enter_tree = StaticCString::create("_body_enter_tree"); _body_exit_tree = StaticCString::create("_body_exit_tree"); + _area_enter_tree = StaticCString::create("_area_enter_tree"); + _area_exit_tree = StaticCString::create("_area_exit_tree"); + _input_event=StaticCString::create("_input_event"); changed=StaticCString::create("changed"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 184cbe347b..a69e8ba0b5 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -57,6 +57,7 @@ public: StringName item_rect_changed; StringName shader_shader; StringName shader_unshaded; + StringName shading_mode; StringName enter_tree; StringName exit_tree; StringName size_flags_changed; @@ -83,6 +84,10 @@ public: StringName body_exit_shape; StringName body_exit; + StringName area_enter_shape; + StringName area_exit_shape; + + StringName _get_gizmo_geometry; StringName _can_gizmo_scale; @@ -124,6 +129,9 @@ public: StringName _body_enter_tree; StringName _body_exit_tree; + StringName _area_enter_tree; + StringName _area_exit_tree; + StringName changed; StringName _shader_changed; |