diff options
Diffstat (limited to 'scene')
369 files changed, 5455 insertions, 3150 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 458246671c..1ed508aed3 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h index 425f516b14..da4f1b99af 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index c44b46adbf..50a115174d 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -383,7 +383,11 @@ void Area2D::_clear_monitoring() { Object *obj = ObjectDB::get_instance(E->key()); Node *node = obj ? obj->cast_to<Node>() : NULL; - ERR_CONTINUE(!node); + + if (!node) //node may have been deleted in previous frame, this should not be an error + continue; + //ERR_CONTINUE(!node); + if (!E->get().in_tree) continue; @@ -416,13 +420,13 @@ void Area2D::_notification(int p_what) { void Area2D::set_enable_monitoring(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==monitoring) return; + if (locked) { + ERR_EXPLAIN("Function blocked during in/out signal. Use call_deferred(\"set_enable_monitoring\",true/false)"); + } + ERR_FAIL_COND(locked); monitoring=p_enable; @@ -652,7 +656,7 @@ void Area2D::_bind_methods() { ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); - ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); + ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index f5a88390e7..7f3f9c93cf 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -40,7 +40,9 @@ public: enum SpaceOverride { SPACE_OVERRIDE_DISABLED, SPACE_OVERRIDE_COMBINE, - SPACE_OVERRIDE_REPLACE + SPACE_OVERRIDE_COMBINE_REPLACE, + SPACE_OVERRIDE_REPLACE, + SPACE_OVERRIDE_REPLACE_COMBINE }; private: diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 52ae5d2954..67c1733759 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -118,10 +118,10 @@ Matrix32 Camera2D::get_camera_transform() { - if (smoothing>0.0) { + if (smoothing_enabled) { float c = smoothing*get_fixed_process_delta_time(); - smoothed_camera_pos = ((new_camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos; + smoothed_camera_pos = ((camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos; ret_camera_pos=smoothed_camera_pos; // camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; } else { @@ -440,6 +440,27 @@ float Camera2D::get_h_offset() const{ } +void Camera2D::_set_old_smoothing(float p_val) { + //compatibility + if (p_val>0) { + smoothing_enabled=true; + set_follow_smoothing(p_val); + } + +} + +void Camera2D::set_enable_follow_smoothing(bool p_enabled) { + + smoothing_enabled=p_enabled; + +} + +bool Camera2D::is_follow_smoothing_enabled() const { + + return smoothing_enabled; +} + + void Camera2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_offset","offset"),&Camera2D::set_offset); @@ -482,21 +503,24 @@ void Camera2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_camera_pos"),&Camera2D::get_camera_pos); ObjectTypeDB::bind_method(_MD("get_camera_screen_center"),&Camera2D::get_camera_screen_center); - ObjectTypeDB::bind_method(_MD("set_zoom"),&Camera2D::set_zoom); + ObjectTypeDB::bind_method(_MD("set_zoom","zoom"),&Camera2D::set_zoom); ObjectTypeDB::bind_method(_MD("get_zoom"),&Camera2D::get_zoom); ObjectTypeDB::bind_method(_MD("set_follow_smoothing","follow_smoothing"),&Camera2D::set_follow_smoothing); ObjectTypeDB::bind_method(_MD("get_follow_smoothing"),&Camera2D::get_follow_smoothing); + ObjectTypeDB::bind_method(_MD("set_enable_follow_smoothing","follow_smoothing"),&Camera2D::set_enable_follow_smoothing); + ObjectTypeDB::bind_method(_MD("is_follow_smoothing_enabled"),&Camera2D::is_follow_smoothing_enabled); + ObjectTypeDB::bind_method(_MD("force_update_scroll"),&Camera2D::force_update_scroll); + ObjectTypeDB::bind_method(_MD("_set_old_smoothing","follow_smoothing"),&Camera2D::_set_old_smoothing); ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset")); ADD_PROPERTY( PropertyInfo(Variant::INT,"anchor_mode",PROPERTY_HINT_ENUM,"Fixed TopLeft,Drag Center"),_SCS("set_anchor_mode"),_SCS("get_anchor_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"rotating"),_SCS("set_rotating"),_SCS("is_rotating")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"current"),_SCS("_set_current"),_SCS("is_current")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing"),_SCS("set_follow_smoothing"),_SCS("get_follow_smoothing") ); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"zoom"),_SCS("set_zoom"),_SCS("get_zoom") ); ADD_PROPERTYI( PropertyInfo(Variant::INT,"limit/left"),_SCS("set_limit"),_SCS("get_limit"),MARGIN_LEFT); @@ -507,6 +531,12 @@ void Camera2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"drag_margin/h_enabled"),_SCS("set_h_drag_enabled"),_SCS("is_h_drag_enabled") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"drag_margin/v_enabled"),_SCS("set_v_drag_enabled"),_SCS("is_v_drag_enabled") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"smoothing/enable"),_SCS("set_enable_follow_smoothing"),_SCS("is_follow_smoothing_enabled") ); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing/speed"),_SCS("set_follow_smoothing"),_SCS("get_follow_smoothing") ); + + //compatibility + ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing",PROPERTY_HINT_NONE,"",0),_SCS("_set_old_smoothing"),_SCS("get_follow_smoothing") ); + ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin/left",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drag_margin"),_SCS("get_drag_margin"),MARGIN_LEFT); ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin/top",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drag_margin"),_SCS("get_drag_margin"),MARGIN_TOP); ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin/right",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drag_margin"),_SCS("get_drag_margin"),MARGIN_RIGHT); @@ -535,8 +565,9 @@ Camera2D::Camera2D() { drag_margin[MARGIN_BOTTOM]=0.2; camera_pos=Vector2(); first=true; + smoothing_enabled=false; - smoothing=0.0; + smoothing=5.0; zoom = Vector2(1, 1); h_drag_enabled=true; diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 79d84f48d0..3c51bbf220 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -59,6 +59,7 @@ protected: bool rotating; bool current; float smoothing; + bool smoothing_enabled; int limit[4]; float drag_margin[4]; @@ -73,6 +74,8 @@ protected: void _make_current(Object *p_which); void _set_current(bool p_current); + + void _set_old_smoothing(float p_enable); protected: virtual Matrix32 get_camera_transform(); @@ -108,6 +111,9 @@ public: void set_h_offset(float p_offset); float get_h_offset() const; + void set_enable_follow_smoothing(bool p_enabled); + bool is_follow_smoothing_enabled() const; + void set_follow_smoothing(float p_speed); float get_follow_smoothing() const; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 357aaa225b..316097fbcf 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -309,6 +309,15 @@ void CanvasItem::hide() { _change_notify("visibility/visible"); } +void CanvasItem::set_hidden(bool p_hidden) { + + if (hidden == p_hidden) { + return; + } + + _set_visible_(!p_hidden); +} + Variant CanvasItem::edit_get_state() const { @@ -380,8 +389,8 @@ Matrix32 CanvasItem::get_global_transform_with_canvas() const { if (last_valid->canvas_layer) return last_valid->canvas_layer->get_transform() * xform; - else - return xform; + else if (is_inside_tree()) + return get_viewport()->get_canvas_transform() * xform; } Matrix32 CanvasItem::get_global_transform() const { @@ -539,6 +548,7 @@ void CanvasItem::_notification(int p_what) { get_parent()->cast_to<CanvasItem>()->children_items.erase(C); C=NULL; } + global_invalid=true; } break; case NOTIFICATION_DRAW: { @@ -700,7 +710,7 @@ void CanvasItem::draw_circle(const Point2& p_pos, float p_radius, const Color& p } -void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos) { +void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos,const Color& p_modulate) { if (!drawing) { ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); @@ -709,7 +719,7 @@ void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos) ERR_FAIL_COND(p_texture.is_null()); - p_texture->draw(canvas_item,p_pos); + p_texture->draw(canvas_item,p_pos,p_modulate); } void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) { @@ -764,7 +774,7 @@ void CanvasItem::draw_set_transform(const Point2& p_offset, float p_rot, const S Matrix32 xform(p_rot,p_offset); xform.scale_basis(p_scale); - VisualServer::get_singleton()->canvas_item_set_transform(canvas_item,xform); + VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,xform); } void CanvasItem::draw_polygon(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture) { @@ -1043,6 +1053,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_hidden"),&CanvasItem::is_hidden); ObjectTypeDB::bind_method(_MD("show"),&CanvasItem::show); ObjectTypeDB::bind_method(_MD("hide"),&CanvasItem::hide); + ObjectTypeDB::bind_method(_MD("set_hidden","hidden"),&CanvasItem::set_hidden); ObjectTypeDB::bind_method(_MD("update"),&CanvasItem::update); @@ -1070,7 +1081,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("draw_line","from","to","color","width"),&CanvasItem::draw_line,DEFVAL(1.0)); ObjectTypeDB::bind_method(_MD("draw_rect","rect","color"),&CanvasItem::draw_rect); ObjectTypeDB::bind_method(_MD("draw_circle","pos","radius","color"),&CanvasItem::draw_circle); - ObjectTypeDB::bind_method(_MD("draw_texture","texture:Texture","pos"),&CanvasItem::draw_texture); + ObjectTypeDB::bind_method(_MD("draw_texture","texture:Texture","pos","modulate"),&CanvasItem::draw_texture,DEFVAL(Color(1,1,1,1))); ObjectTypeDB::bind_method(_MD("draw_texture_rect","texture:Texture","rect","tile","modulate","transpose"),&CanvasItem::draw_texture_rect,DEFVAL(Color(1,1,1)),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate","transpose"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("draw_style_box","style_box:StyleBox","rect"),&CanvasItem::draw_style_box); @@ -1146,6 +1157,8 @@ Matrix32 CanvasItem::get_canvas_transform() const { if (canvas_layer) return canvas_layer->get_transform(); + else if (get_parent()->cast_to<CanvasItem>()) + return get_parent()->cast_to<CanvasItem>()->get_canvas_transform(); else return get_viewport()->get_canvas_transform(); @@ -1180,6 +1193,14 @@ bool CanvasItem::is_local_transform_notification_enabled() const { return notify_local_transform; } +int CanvasItem::get_canvas_layer() const { + + if (canvas_layer) + return canvas_layer->get_layer(); + else + return 0; +} + CanvasItem::CanvasItem() : xform_change(this) { diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 4885256c64..05a2e725e9 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -190,13 +190,14 @@ public: bool is_hidden() const; void show(); void hide(); + void set_hidden(bool p_hidden); void update(); void set_blend_mode(BlendMode p_blend_mode); BlendMode get_blend_mode() const; - void set_light_mask(int p_light_mask); + virtual void set_light_mask(int p_light_mask); int get_light_mask() const; void set_opacity(float p_opacity); @@ -210,7 +211,7 @@ public: void draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0); void draw_rect(const Rect2& p_rect, const Color& p_color); void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color); - void draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos); + void draw_texture(const Ref<Texture>& p_texture, const Point2& p_pos, const Color &p_modulate=Color(1,1,1,1)); void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect); @@ -267,6 +268,7 @@ public: void set_notify_local_transform(bool p_enable); bool is_local_transform_notification_enabled() const; + int get_canvas_layer() const; CanvasItem(); ~CanvasItem(); diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 82dd8012a5..77203a7110 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -5,10 +5,19 @@ void CanvasModulate::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_CANVAS) { - VS::get_singleton()->canvas_set_modulate(get_canvas(),color); + if (is_visible()) + VS::get_singleton()->canvas_set_modulate(get_canvas(),color); } else if (p_what==NOTIFICATION_EXIT_CANVAS) { - VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1)); + if (is_visible()) + VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1)); + } else if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + if (is_visible()) { + VS::get_singleton()->canvas_set_modulate(get_canvas(),color); + } else { + VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1)); + } } } diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 8b8caf13d3..3a45b0c84e 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -32,14 +32,14 @@ void CollisionObject2D::_update_shapes_from_children() { - shapes.resize(0); + shapes.clear(); for(int i=0;i<get_child_count();i++) { Node* n = get_child(i); n->call("_add_to_collision_object",this); } -// _update_shapes(); + _update_shapes(); } void CollisionObject2D::_notification(int p_what) { diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index 473f13d0ff..fc50c5c7cd 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 1479cb7881..2a40a6207d 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -30,7 +30,7 @@ #include "collision_object_2d.h" #include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" - +#include "triangulator.h" void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) { if (unparenting || !can_update_body) @@ -48,7 +48,7 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) { //here comes the sun, lalalala //decompose concave into multiple convex polygons and add them - Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon); + Vector< Vector<Vector2> > decomp = _decompose_in_convex(); shape_from=co->get_shape_count(); for(int i=0;i<decomp.size();i++) { Ref<ConvexPolygonShape2D> convex = memnew( ConvexPolygonShape2D ); @@ -106,6 +106,51 @@ void CollisionPolygon2D::_update_parent() { co->_update_shapes_from_children(); } +Vector< Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() { + + Vector< Vector<Vector2> > decomp; +#if 0 + //fast but imprecise triangulator, gave us problems + decomp = Geometry::decompose_polygon(polygon); +#else + + List<TriangulatorPoly> in_poly,out_poly; + + TriangulatorPoly inp; + inp.Init(polygon.size()); + for(int i=0;i<polygon.size();i++) { + inp.GetPoint(i)=polygon[i]; + } + inp.SetOrientation(TRIANGULATOR_CCW); + in_poly.push_back(inp); + TriangulatorPartition tpart; + if (tpart.ConvexPartition_HM(&in_poly,&out_poly)==0) { //failed! + ERR_PRINT("Convex decomposing failed!"); + return decomp; + } + + decomp.resize(out_poly.size()); + int idx=0; + + for(List<TriangulatorPoly>::Element*I = out_poly.front();I;I=I->next()) { + + TriangulatorPoly& tp = I->get(); + + decomp[idx].resize(tp.GetNumPoints()); + + for(int i=0;i<tp.GetNumPoints();i++) { + + decomp[idx][i]=tp.GetPoint(i); + } + + idx++; + } + +#endif + + return decomp; +} + void CollisionPolygon2D::_notification(int p_what) { @@ -113,6 +158,12 @@ void CollisionPolygon2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { unparenting=false; can_update_body=get_tree()->is_editor_hint(); + if (!get_tree()->is_editor_hint()) { + //display above all else + set_z_as_relative(false); + set_z(VS::CANVAS_ITEM_Z_MAX-1); + } + } break; case NOTIFICATION_EXIT_TREE: { can_update_body=false; @@ -146,10 +197,11 @@ void CollisionPolygon2D::_notification(int p_what) { Vector2 n = polygon[(i+1)%polygon.size()]; draw_line(p,n,Color(0.9,0.2,0.0,0.8),3); } -//#define DEBUG_DECOMPOSE +#define DEBUG_DECOMPOSE #if defined(TOOLS_ENABLED) && defined (DEBUG_DECOMPOSE) - Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon); + Vector< Vector<Vector2> > decomp = _decompose_in_convex(); + Color c(0.4,0.9,0.1); for(int i=0;i<decomp.size();i++) { @@ -251,10 +303,10 @@ void CollisionPolygon2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_polygon","polygon"),&CollisionPolygon2D::set_polygon); ObjectTypeDB::bind_method(_MD("get_polygon"),&CollisionPolygon2D::get_polygon); - ObjectTypeDB::bind_method(_MD("set_build_mode"),&CollisionPolygon2D::set_build_mode); + ObjectTypeDB::bind_method(_MD("set_build_mode","build_mode"),&CollisionPolygon2D::set_build_mode); ObjectTypeDB::bind_method(_MD("get_build_mode"),&CollisionPolygon2D::get_build_mode); - ObjectTypeDB::bind_method(_MD("set_trigger"),&CollisionPolygon2D::set_trigger); + ObjectTypeDB::bind_method(_MD("set_trigger","trigger"),&CollisionPolygon2D::set_trigger); ObjectTypeDB::bind_method(_MD("is_trigger"),&CollisionPolygon2D::is_trigger); ObjectTypeDB::bind_method(_MD("_set_shape_range","shape_range"),&CollisionPolygon2D::_set_shape_range); diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index 4bc9713c8a..b2bd4d189d 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -63,6 +63,7 @@ protected: void _set_shape_range(const Vector2& p_range); Vector2 _get_shape_range() const; + Vector< Vector<Vector2> > _decompose_in_convex(); protected: diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 85751fc735..405310450b 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -77,6 +77,11 @@ void CollisionShape2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { unparenting=false; can_update_body=get_tree()->is_editor_hint(); + if (!get_tree()->is_editor_hint()) { + //display above all else + set_z_as_relative(false); + set_z(VS::CANVAS_ITEM_Z_MAX-1); + } } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { @@ -120,6 +125,7 @@ void CollisionShape2D::_notification(int p_what) { rect=Rect2(); + Color draw_col=get_tree()->get_debug_collisions_color(); shape->draw(get_canvas_item(),draw_col); diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 82e1137174..b14dad73ba 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 1df936535f..053fc2c9c2 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -111,6 +111,19 @@ real_t Joint2D::get_bias() const{ return bias; } +void Joint2D::set_exclude_nodes_from_collision(bool p_enable) { + + if (exclude_from_collision==p_enable) + return; + exclude_from_collision=p_enable; + _update_joint(); +} + +bool Joint2D::get_exclude_nodes_from_collision() const{ + + return exclude_from_collision; +} + void Joint2D::_bind_methods() { @@ -124,9 +137,14 @@ void Joint2D::_bind_methods() { ObjectTypeDB::bind_method( _MD("set_bias","bias"), &Joint2D::set_bias ); ObjectTypeDB::bind_method( _MD("get_bias"), &Joint2D::get_bias ); + ObjectTypeDB::bind_method( _MD("set_exclude_nodes_from_collision","enable"), &Joint2D::set_exclude_nodes_from_collision ); + ObjectTypeDB::bind_method( _MD("get_exclude_nodes_from_collision"), &Joint2D::get_exclude_nodes_from_collision ); + ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.001"), _SCS("set_bias"),_SCS("get_bias") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), _SCS("set_exclude_nodes_from_collision"),_SCS("get_exclude_nodes_from_collision") ); + } @@ -135,6 +153,7 @@ void Joint2D::_bind_methods() { Joint2D::Joint2D() { bias=0; + exclude_from_collision=true; } /////////////////////////////////////////////////////////////////////////////// @@ -145,11 +164,17 @@ void PinJoint2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_DRAW: { - if (is_inside_tree() && get_tree()->is_editor_hint()) { - draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(0,-10),Point2(0,+10),Color(0.7,0.6,0.0,0.5),3); + if (!is_inside_tree()) + break; + + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { + break; } + + + draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(0,-10),Point2(0,+10),Color(0.7,0.6,0.0,0.5),3); } break; } @@ -173,7 +198,10 @@ RID PinJoint2D::_configure_joint() { SWAP(body_a,body_b); } else if (body_b) { //add a collision exception between both - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); } RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID()); Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness); @@ -219,13 +247,17 @@ void GrooveJoint2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_DRAW: { - if (is_inside_tree() && get_tree()->is_editor_hint()) { + if (!is_inside_tree()) + break; - draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(-10,initial_offset),Point2(+10,initial_offset),Color(0.8,0.8,0.9,0.5),5); + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { + break; } + + draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(-10,initial_offset),Point2(+10,initial_offset),Color(0.8,0.8,0.9,0.5),5); } break; } } @@ -245,7 +277,11 @@ RID GrooveJoint2D::_configure_joint(){ if (!body_a || !body_b) return RID(); - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); Matrix32 gt = get_global_transform(); Vector2 groove_A1 = gt.get_origin(); @@ -313,12 +349,17 @@ void DampedSpringJoint2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_DRAW: { - if (is_inside_tree() && get_tree()->is_editor_hint()) { - draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3); - draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3); + if (!is_inside_tree()) + break; + + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { + break; } + + draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3); + draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3); } break; } } @@ -338,7 +379,10 @@ RID DampedSpringJoint2D::_configure_joint(){ if (!body_a || !body_b) return RID(); - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); Matrix32 gt = get_global_transform(); Vector2 anchor_A = gt.get_origin(); diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index 908e3a158e..52ffd86e7c 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,6 +42,8 @@ class Joint2D : public Node2D { NodePath b; real_t bias; + bool exclude_from_collision; + protected: @@ -62,6 +64,9 @@ public: void set_bias(real_t p_bias); real_t get_bias() const; + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + RID get_joint() const { return joint; } Joint2D(); diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 852a6fb46b..9715afeaa4 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -34,10 +34,19 @@ Rect2 Light2D::get_item_rect() const { } +void Light2D::_update_light_visibility() { + + if (!is_inside_tree()) + return; + + VS::get_singleton()->canvas_light_set_enabled(canvas_light,enabled && is_visible()); +} + void Light2D::set_enabled( bool p_enabled) { - VS::get_singleton()->canvas_light_set_enabled(canvas_light,p_enabled); + enabled=p_enabled; + _update_light_visibility(); } bool Light2D::is_enabled() const { @@ -253,16 +262,22 @@ void Light2D::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, get_canvas() ); + _update_light_visibility(); } if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { VS::get_singleton()->canvas_light_set_transform( canvas_light, get_global_transform()); } + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + _update_light_visibility(); + } if (p_what==NOTIFICATION_EXIT_TREE) { VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, RID() ); + _update_light_visibility(); } } @@ -333,7 +348,7 @@ void Light2D::_bind_methods() { 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::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::INT,"mode",PROPERTY_HINT_ENUM,"Add,Sub,Mix,Mask"),_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")); @@ -349,6 +364,7 @@ void Light2D::_bind_methods() { BIND_CONSTANT( MODE_ADD ); BIND_CONSTANT( MODE_SUB ); BIND_CONSTANT( MODE_MIX ); + BIND_CONSTANT( MODE_MASK ); } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index bf61868bac..ca437769e7 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -11,6 +11,7 @@ public: MODE_ADD, MODE_SUB, MODE_MIX, + MODE_MASK, }; private: @@ -34,6 +35,7 @@ private: Ref<Texture> texture; Vector2 texture_offset; + void _update_light_visibility(); protected: void _notification(int p_what); diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 6ebd499f71..d98bed0ea3 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -93,12 +93,17 @@ void LightOccluder2D::_notification(int p_what) { VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas()); VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible()); } if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); } + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible()); + } if (p_what==NOTIFICATION_DRAW) { diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index b7d51730a0..fe1760b84a 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -494,7 +494,29 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect open_list.erase(least_cost_poly); } - +#if 0 +debug path + { + Polygon *p=end_poly; + int idx=0; + + while(true) { + int prev = p->prev_edge; + int prev_n = (p->prev_edge+1)%p->edges.size(); + Vector2 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point))*0.5; + String points; + for(int i=0;i<p->edges.size();i++) { + if (i>0) + points+=", "; + points+=_get_vertex(p->edges[i].point); + } + //print_line("poly "+itos(idx++)+" - "+points); + p = p->edges[prev].C; + if (p==begin_poly) + break; + } + } +#endif if (found_route) { Vector<Vector2> path; @@ -538,22 +560,29 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect bool skip=false; - /* print_line("-----\nAPEX: "+(apex_point-end_point)); + /* + print_line("-----\nAPEX: "+(apex_point-end_point)); print_line("LEFT:"); print_line("\tPortal: "+(portal_left-end_point)); print_line("\tPoint: "+(left-end_point)); - print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_left,left) >= 0)); + print_line("\tLeft Tangent: "+rtos(CLOCK_TANGENT(apex_point,portal_left,left))); + print_line("\tLeft Distance: "+rtos(portal_left.distance_squared_to(apex_point))); + print_line("\tLeft Test: "+rtos(CLOCK_TANGENT(apex_point,left,portal_right))); print_line("RIGHT:"); print_line("\tPortal: "+(portal_right-end_point)); print_line("\tPoint: "+(right-end_point)); - print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_right,right) <= 0)); -*/ + print_line("\tRight Tangent: "+rtos(CLOCK_TANGENT(apex_point,portal_right,right))); + print_line("\tRight Distance: "+rtos(portal_right.distance_squared_to(apex_point))); + print_line("\tRight Test: "+rtos(CLOCK_TANGENT(apex_point,right,portal_left))); + */ + if (CLOCK_TANGENT(apex_point,portal_left,left) >= 0){ //process if (portal_left.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,left,portal_right) > 0) { left_poly=p; portal_left=left; + //print_line("***ADVANCE LEFT"); } else { //_clip_path(path,apex_poly,portal_right,right_poly); @@ -568,6 +597,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect path.push_back(apex_point); skip=true; //print_line("addpoint left"); + //print_line("***CLIP LEFT"); } } @@ -576,6 +606,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect if (portal_right.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,right,portal_left) < 0) { right_poly=p; portal_right=right; + //print_line("***ADVANCE RIGHT"); } else { //_clip_path(path,apex_poly,portal_left,left_poly); @@ -589,6 +620,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) path.push_back(apex_point); //print_line("addpoint right"); + //print_line("***CLIP RIGHT"); } } diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 792f079ab0..4c00d8cec9 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -273,7 +273,7 @@ void NavigationPolygonInstance::set_enabled(bool p_enabled) { if (navpoly.is_valid()) { - nav_id = navigation->navpoly_create(navpoly,get_relative_transform(navigation),this); + nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this); } } @@ -309,7 +309,7 @@ void NavigationPolygonInstance::_notification(int p_what) { if (enabled && navpoly.is_valid()) { - nav_id = navigation->navpoly_create(navpoly,get_relative_transform(navigation),this); + nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this); } break; } @@ -321,7 +321,7 @@ void NavigationPolygonInstance::_notification(int p_what) { case NOTIFICATION_TRANSFORM_CHANGED: { if (navigation && nav_id!=-1) { - navigation->navpoly_set_transform(nav_id,get_relative_transform(navigation)); + navigation->navpoly_set_transform(nav_id,get_relative_transform_to_parent(navigation)); } } break; @@ -409,7 +409,7 @@ void NavigationPolygonInstance::set_navigation_polygon(const Ref<NavigationPolyg } if (navigation && navpoly.is_valid() && enabled) { - nav_id = navigation->navpoly_create(navpoly,get_relative_transform(navigation),this); + nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this); } //update_gizmo(); _change_notify("navpoly"); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 52b112f090..7ef81306b6 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -333,17 +333,18 @@ int Node2D::get_z() const{ return z; } -Matrix32 Node2D::get_relative_transform(const Node *p_parent) const { +Matrix32 Node2D::get_relative_transform_to_parent(const Node *p_parent) const { if (p_parent==this) return Matrix32(); Node2D *parent_2d = get_parent()->cast_to<Node2D>(); + ERR_FAIL_COND_V(!parent_2d,Matrix32()); if (p_parent==parent_2d) return get_transform(); else - return parent_2d->get_relative_transform(p_parent) * get_transform(); + return parent_2d->get_relative_transform_to_parent(p_parent) * get_transform(); } @@ -394,9 +395,9 @@ void Node2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_z_as_relative","enable"),&Node2D::set_z_as_relative); ObjectTypeDB::bind_method(_MD("is_z_relative"),&Node2D::is_z_relative); - ObjectTypeDB::bind_method(_MD("edit_set_pivot"),&Node2D::edit_set_pivot); + ObjectTypeDB::bind_method(_MD("edit_set_pivot","pivot"),&Node2D::edit_set_pivot); - ObjectTypeDB::bind_method(_MD("get_relative_transform"),&Node2D::get_relative_transform); + ObjectTypeDB::bind_method(_MD("get_relative_transform_to_parent","parent"),&Node2D::get_relative_transform_to_parent); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos")); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd")); diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 8efce33cda..49d616fc1f 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -99,7 +99,7 @@ public: void set_z_as_relative(bool p_enabled); bool is_z_relative() const; - Matrix32 get_relative_transform(const Node *p_parent) const; + Matrix32 get_relative_transform_to_parent(const Node *p_parent) const; diff --git a/scene/2d/node_2d_singleton.cpp b/scene/2d/node_2d_singleton.cpp index 361edf7587..b26804fedf 100644 --- a/scene/2d/node_2d_singleton.cpp +++ b/scene/2d/node_2d_singleton.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/node_2d_singleton.h b/scene/2d/node_2d_singleton.h index 6a21db2221..0aa6bbf992 100644 --- a/scene/2d/node_2d_singleton.h +++ b/scene/2d/node_2d_singleton.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 8bb4eb55ba..7f2e9efd96 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -193,7 +193,7 @@ void ParallaxBackground::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_limit_begin"),&ParallaxBackground::get_limit_begin); ObjectTypeDB::bind_method(_MD("set_limit_end","ofs"),&ParallaxBackground::set_limit_end); ObjectTypeDB::bind_method(_MD("get_limit_end"),&ParallaxBackground::get_limit_end); - ObjectTypeDB::bind_method(_MD("set_ignore_camera_zoom"), &ParallaxBackground::set_ignore_camera_zoom); + ObjectTypeDB::bind_method(_MD("set_ignore_camera_zoom","ignore"), &ParallaxBackground::set_ignore_camera_zoom); ObjectTypeDB::bind_method(_MD("is_ignore_camera_zoom"), &ParallaxBackground::is_ignore_camera_zoom); diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h index 8dede07a16..bdaf7d241f 100644 --- a/scene/2d/parallax_background.h +++ b/scene/2d/parallax_background.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 70612d7c9a..7a898e43c9 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/parallax_layer.h b/scene/2d/parallax_layer.h index 8fe2846897..6c24a9b9f7 100644 --- a/scene/2d/parallax_layer.h +++ b/scene/2d/parallax_layer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 8f805ceba2..5b13c32d93 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -697,7 +697,7 @@ bool Particles2D::is_emitting() const { void Particles2D::set_amount(int p_amount) { - ERR_FAIL_INDEX(p_amount,1024); + ERR_FAIL_INDEX(p_amount,1024+1); particles.resize(p_amount); } @@ -719,7 +719,7 @@ float Particles2D::get_emit_timeout() const { void Particles2D::set_lifetime(float p_lifetime) { - ERR_FAIL_INDEX(p_lifetime,3600); + ERR_FAIL_INDEX(p_lifetime,3600+1); lifetime=p_lifetime; } @@ -994,6 +994,15 @@ DVector<Vector2> Particles2D::get_emission_points() const{ return emission_points; } +void Particles2D::reset() { + + for(int i=0;i<particles.size();i++) { + particles[i].active=false; + } + time=0; + active_count=0; +} + void Particles2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_emitting","active"),&Particles2D::set_emitting); @@ -1057,6 +1066,7 @@ void Particles2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_color_phase_pos","phase"),&Particles2D::get_color_phase_pos); ObjectTypeDB::bind_method(_MD("pre_process","time"),&Particles2D::pre_process); + ObjectTypeDB::bind_method(_MD("reset"),&Particles2D::reset); ObjectTypeDB::bind_method(_MD("set_use_local_space","enable"),&Particles2D::set_use_local_space); ObjectTypeDB::bind_method(_MD("is_using_local_space"),&Particles2D::is_using_local_space); diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h index 4ee0fcf8da..101395589e 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/particles_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -248,6 +248,7 @@ public: DVector<Vector2> get_emission_points() const; void pre_process(float p_delta); + void reset(); Particles2D(); }; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 8f110b3931..bd7415aa04 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -31,9 +31,13 @@ void Path2D::_notification(int p_what) { - if (p_what==NOTIFICATION_DRAW && curve.is_valid() && is_inside_tree() && get_tree()->is_editor_hint()) { + if (p_what==NOTIFICATION_DRAW && curve.is_valid()) { //draw the curve!! + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) { + return; + } + for(int i=0;i<curve->get_point_count();i++) { Vector2 prev_p=curve->get_point_pos(i); @@ -70,6 +74,8 @@ void Path2D::set_curve(const Ref<Curve2D>& p_curve) { curve->connect("changed",this,"_curve_changed"); } + _curve_changed(); + } Ref<Curve2D> Path2D::get_curve() const{ diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h index c9114c5d7d..486a8ac9ac 100644 --- a/scene/2d/path_2d.h +++ b/scene/2d/path_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index c30921eb69..cc2e5c0d72 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -310,14 +310,20 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { ERR_FAIL_COND(!E); ERR_FAIL_COND(E->get().in_scene); + contact_monitor->locked=true; + E->get().in_scene=true; emit_signal(SceneStringNames::get_singleton()->body_enter,node); + for(int i=0;i<E->get().shapes.size();i++) { emit_signal(SceneStringNames::get_singleton()->body_enter_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + contact_monitor->locked=false; + + } void RigidBody2D::_body_exit_tree(ObjectID p_id) { @@ -329,11 +335,18 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) { ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->get().in_scene); E->get().in_scene=false; + + contact_monitor->locked=true; + emit_signal(SceneStringNames::get_singleton()->body_exit,node); + for(int i=0;i<E->get().shapes.size();i++) { emit_signal(SceneStringNames::get_singleton()->body_exit_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + + contact_monitor->locked=false; + } void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape) { @@ -439,6 +452,8 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { if (contact_monitor) { + contact_monitor->locked=true; + //untag all int rc=0; for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { @@ -520,6 +535,8 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { _body_inout(1,toadd[i].id,toadd[i].shape,toadd[i].local_shape); } + contact_monitor->locked=false; + } set_block_transform_notify(true); // don't want notify (would feedback loop) @@ -803,6 +820,11 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { if (!p_enabled) { + if (contact_monitor->locked) { + ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead"); + } + ERR_FAIL_COND(contact_monitor->locked); + for(Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { //clean up mess @@ -813,6 +835,7 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { } else { contact_monitor = memnew( ContactMonitor ); + contact_monitor->locked=false; } } @@ -1250,7 +1273,7 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_collider_velocity"),&KinematicBody2D::get_collider_velocity); ObjectTypeDB::bind_method(_MD("get_collider:Object"),&KinematicBody2D::_get_collider); ObjectTypeDB::bind_method(_MD("get_collider_shape"),&KinematicBody2D::get_collider_shape); - ObjectTypeDB::bind_method(_MD("get_collider_metadata"),&KinematicBody2D::get_collider_metadata); + ObjectTypeDB::bind_method(_MD("get_collider_metadata:Variant"),&KinematicBody2D::get_collider_metadata); ObjectTypeDB::bind_method(_MD("set_collision_margin","pixels"),&KinematicBody2D::set_collision_margin); ObjectTypeDB::bind_method(_MD("get_collision_margin","pixels"),&KinematicBody2D::get_collision_margin); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index b70fdd59cf..999e63dd5d 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -190,7 +190,7 @@ private: struct ContactMonitor { - + bool locked; Map<ObjectID,BodyState> body_map; }; diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp index f1591b5242..c293305cb2 100644 --- a/scene/2d/position_2d.cpp +++ b/scene/2d/position_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/position_2d.h b/scene/2d/position_2d.h index 16404e6ce8..23821e62d4 100644 --- a/scene/2d/position_2d.h +++ b/scene/2d/position_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 4a199e3418..4a774b0198 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h index 8c3ce8b3b3..54ec42c53e 100644 --- a/scene/2d/ray_cast_2d.h +++ b/scene/2d/ray_cast_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index 0fbd140cfb..6dcd980822 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/remote_transform_2d.h b/scene/2d/remote_transform_2d.h index 506bde8cd8..4a5f5f72ea 100644 --- a/scene/2d/remote_transform_2d.h +++ b/scene/2d/remote_transform_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sample_player_2d.cpp b/scene/2d/sample_player_2d.cpp index ec17ffc55e..bf09130238 100644 --- a/scene/2d/sample_player_2d.cpp +++ b/scene/2d/sample_player_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sample_player_2d.h b/scene/2d/sample_player_2d.h index c0f2734ad1..eddf84f77b 100644 --- a/scene/2d/sample_player_2d.h +++ b/scene/2d/sample_player_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp index 0c3987e6b1..fac94f19dc 100644 --- a/scene/2d/screen_button.cpp +++ b/scene/2d/screen_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -102,6 +102,10 @@ void TouchScreenButton::_notification(int p_what) { action_id=-1; } } break; + case NOTIFICATION_EXIT_TREE: { + if (is_pressed()) + Input::get_singleton()->action_release(action); + } break; } } @@ -161,7 +165,7 @@ void TouchScreenButton::_input(const InputEvent& p_event) { if (finger_pressed==-1 || p_event.screen_touch.index==finger_pressed) { - Point2 coord = (get_global_transform()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); + Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); bool touched=false; if (bitmask.is_valid()) { @@ -238,7 +242,7 @@ void TouchScreenButton::_input(const InputEvent& p_event) { if (finger_pressed!=-1) return; //already fingering - Point2 coord = (get_global_transform()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); + Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); bool touched=false; if (bitmask.is_valid()) { diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h index 159b829079..ff3b50bf5e 100644 --- a/scene/2d/screen_button.h +++ b/scene/2d/screen_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sound_player_2d.cpp b/scene/2d/sound_player_2d.cpp index 0eb18866af..41ce87faf9 100644 --- a/scene/2d/sound_player_2d.cpp +++ b/scene/2d/sound_player_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sound_player_2d.h b/scene/2d/sound_player_2d.h index a376cdbed7..0e75887235 100644 --- a/scene/2d/sound_player_2d.h +++ b/scene/2d/sound_player_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 89d9966958..001a1366a9 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h index ad782e746b..cbcaec9aeb 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 167b637bdc..179d1f451a 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -32,6 +32,8 @@ #include "method_bind_ext.inc" #include "os/os.h" + + int TileMap::_get_quadrant_size() const { if (y_sort_mode) @@ -116,7 +118,7 @@ void TileMap::_update_quadrant_transform() { Matrix32 nav_rel; if (navigation) - nav_rel = get_relative_transform(navigation); + nav_rel = get_relative_transform_to_parent(navigation); for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) { @@ -221,6 +223,14 @@ void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vect Size2 s=p_sc; Vector2 offset = p_offset; + if (s.y > s.x) { + if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose)) + offset.y += s.y - s.x; + } else if (s.y < s.x) { + if ((p_cell.flip_v && (p_cell.flip_h || p_cell.transpose)) || (p_cell.flip_h && !p_cell.transpose)) + offset.x += s.x - s.y; + } + if (p_cell.transpose) { SWAP(xform.elements[0].x, xform.elements[0].y); SWAP(xform.elements[1].x, xform.elements[1].y); @@ -259,7 +269,7 @@ void TileMap::_update_dirty_quadrants() { Vector2 tcenter = cell_size/2; Matrix32 nav_rel; if (navigation) - nav_rel = get_relative_transform(navigation); + nav_rel = get_relative_transform_to_parent(navigation); Vector2 qofs; @@ -299,6 +309,7 @@ void TileMap::_update_dirty_quadrants() { q.occluder_instances.clear(); Ref<CanvasItemMaterial> prev_material; RID prev_canvas_item; + RID prev_debug_canvas_item; for(int i=0;i<q.cells.size();i++) { @@ -319,6 +330,7 @@ void TileMap::_update_dirty_quadrants() { Ref<CanvasItemMaterial> mat = tile_set->tile_get_material(c.id); RID canvas_item; + RID debug_canvas_item; if (prev_canvas_item==RID() || prev_material!=mat) { @@ -329,13 +341,28 @@ void TileMap::_update_dirty_quadrants() { Matrix32 xform; xform.set_origin( q.pos ); vs->canvas_item_set_transform( canvas_item, xform ); + vs->canvas_item_set_light_mask(canvas_item,get_light_mask()); + q.canvas_items.push_back(canvas_item); + if (debug_shapes) { + + debug_canvas_item=vs->canvas_item_create(); + vs->canvas_item_set_parent( debug_canvas_item, canvas_item ); + vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item,false); + vs->canvas_item_set_z(debug_canvas_item,VS::CANVAS_ITEM_Z_MAX-1); + q.canvas_items.push_back(debug_canvas_item); + prev_debug_canvas_item=debug_canvas_item; + } + prev_canvas_item=canvas_item; prev_material=mat; } else { canvas_item=prev_canvas_item; + if (debug_shapes) { + debug_canvas_item=prev_debug_canvas_item; + } } @@ -357,13 +384,28 @@ void TileMap::_update_dirty_quadrants() { rect.pos=offset.floor(); rect.size=s; + if (rect.size.y > rect.size.x) { + if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) + tile_ofs.y += rect.size.y - rect.size.x; + } else if (rect.size.y < rect.size.x) { + if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) + tile_ofs.x += rect.size.x - rect.size.y; + } + /* rect.size.x+=fp_adjust; rect.size.y+=fp_adjust;*/ - if (c.flip_h) + if (c.transpose) + SWAP(tile_ofs.x, tile_ofs.y); + + if (c.flip_h) { rect.size.x=-rect.size.x; - if (c.flip_v) + tile_ofs.x=-tile_ofs.x; + } + if (c.flip_v) { rect.size.y=-rect.size.y; + tile_ofs.y=-tile_ofs.y; + } Vector2 center_ofs; @@ -407,9 +449,8 @@ void TileMap::_update_dirty_quadrants() { _fix_cell_transform(xform,c,shape_ofs+center_ofs,s); - if (debug_shapes) { - vs->canvas_item_add_set_transform(canvas_item,xform); - shape->draw(canvas_item,debug_collision_color); + if (debug_canvas_item) { + shape->draw(debug_canvas_item,debug_collision_color); } ps->body_add_shape(q.body,shape->get_rid(),xform); @@ -417,9 +458,6 @@ void TileMap::_update_dirty_quadrants() { } } - if (debug_shapes) { - vs->canvas_item_add_set_transform(canvas_item,Matrix32()); - } if (navigation) { Ref<NavigationPolygon> navpoly = tile_set->tile_get_navigation_polygon(c.id); @@ -452,6 +490,7 @@ void TileMap::_update_dirty_quadrants() { VS::get_singleton()->canvas_light_occluder_set_transform(orid,get_global_transform() * xform); VS::get_singleton()->canvas_light_occluder_set_polygon(orid,occluder->get_rid()); VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid,get_canvas()); + VS::get_singleton()->canvas_light_occluder_set_light_mask(orid,occluder_light_mask); Quadrant::Occluder oc; oc.xform=xform; oc.id=orid; @@ -1075,6 +1114,33 @@ Array TileMap::get_used_cells() const { return a; } +void TileMap::set_occluder_light_mask(int p_mask) { + + occluder_light_mask=p_mask; + for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) { + + for (Map<PosKey,Quadrant::Occluder>::Element *F=E->get().occluder_instances.front();F;F=F->next()) { + VisualServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id,occluder_light_mask); + } + } +} + +int TileMap::get_occluder_light_mask() const{ + + return occluder_light_mask; +} + +void TileMap::set_light_mask(int p_light_mask) { + + CanvasItem::set_light_mask(p_light_mask); + for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) { + + for (List<RID>::Element *F=E->get().canvas_items.front();F;F=F->next()) { + VisualServer::get_singleton()->canvas_item_set_light_mask(F->get(),get_light_mask()); + } + } +} + void TileMap::_bind_methods() { @@ -1126,6 +1192,9 @@ void TileMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_collision_bounce","value"),&TileMap::set_collision_bounce); ObjectTypeDB::bind_method(_MD("get_collision_bounce"),&TileMap::get_collision_bounce); + ObjectTypeDB::bind_method(_MD("set_occluder_light_mask","mask"),&TileMap::set_occluder_light_mask); + ObjectTypeDB::bind_method(_MD("get_occluder_light_mask"),&TileMap::get_occluder_light_mask); + ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y","transpose"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("set_cellv","pos","tile","flip_x","flip_y","transpose"),&TileMap::set_cellv,DEFVAL(false),DEFVAL(false),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_cell","x","y"),&TileMap::get_cell); @@ -1160,6 +1229,7 @@ void TileMap::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_bounce"),_SCS("get_collision_bounce")); ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_layer"),_SCS("get_collision_layer")); ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_mask"),_SCS("get_collision_mask")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"occluder/light_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_occluder_light_mask"),_SCS("get_occluder_light_mask")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_tile_data"),_SCS("_get_tile_data")); @@ -1197,6 +1267,7 @@ TileMap::TileMap() { use_kinematic=false; navigation=NULL; y_sort_mode=false; + occluder_light_mask=1; fp_adjust=0.00001; tile_origin=TILE_ORIGIN_TOP_LEFT; diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 60534cce15..14cb52b736 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -150,6 +150,8 @@ private: TileOrigin tile_origin; + int occluder_light_mask; + void _fix_cell_transform(Matrix32& xform, const Cell& p_cell, const Vector2 &p_offset, const Size2 &p_sc); Map<PosKey,Quadrant>::Element *_create_quadrant(const PosKey& p_qk); @@ -187,6 +189,7 @@ public: INVALID_CELL=-1 }; + void set_tileset(const Ref<TileSet>& p_tileset); Ref<TileSet> get_tileset() const; @@ -247,6 +250,11 @@ public: void set_y_sort_mode(bool p_enable); bool is_y_sort_mode_enabled() const; + void set_occluder_light_mask(int p_mask); + int get_occluder_light_mask() const; + + virtual void set_light_mask(int p_light_mask); + void clear(); TileMap(); diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index dc72c9a267..60fa7f69c8 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h index 1f7e4c6d45..6ec24fd4d0 100644 --- a/scene/2d/visibility_notifier_2d.h +++ b/scene/2d/visibility_notifier_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index ff35837bc0..7d4235e051 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -579,7 +579,7 @@ void Area::_bind_methods() { ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); - ADD_PROPERTY( 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::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),_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")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); diff --git a/scene/3d/area.h b/scene/3d/area.h index f03955d1e7..c250d27fb1 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -40,7 +40,9 @@ public: enum SpaceOverride { SPACE_OVERRIDE_DISABLED, SPACE_OVERRIDE_COMBINE, - SPACE_OVERRIDE_REPLACE + SPACE_OVERRIDE_COMBINE_REPLACE, + SPACE_OVERRIDE_REPLACE, + SPACE_OVERRIDE_REPLACE_COMBINE }; private: diff --git a/scene/3d/body_shape.cpp b/scene/3d/body_shape.cpp index b54cbfe0f9..3a47371de3 100644 --- a/scene/3d/body_shape.cpp +++ b/scene/3d/body_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -402,7 +402,7 @@ int CollisionShape::_get_update_shape_index() const{ void CollisionShape::_bind_methods() { //not sure if this should do anything - ObjectTypeDB::bind_method(_MD("resource_changed"),&CollisionShape::resource_changed); + ObjectTypeDB::bind_method(_MD("resource_changed","resource"),&CollisionShape::resource_changed); ObjectTypeDB::bind_method(_MD("set_shape","shape"),&CollisionShape::set_shape); ObjectTypeDB::bind_method(_MD("get_shape"),&CollisionShape::get_shape); ObjectTypeDB::bind_method(_MD("_add_to_collision_object"),&CollisionShape::_add_to_collision_object); diff --git a/scene/3d/body_shape.h b/scene/3d/body_shape.h index 6c0b89da56..dd005c0edd 100644 --- a/scene/3d/body_shape.h +++ b/scene/3d/body_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/bone_attachment.cpp b/scene/3d/bone_attachment.cpp index 9cc1719f94..1628ccc15e 100644 --- a/scene/3d/bone_attachment.cpp +++ b/scene/3d/bone_attachment.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/bone_attachment.h b/scene/3d/bone_attachment.h index ca36cc3694..f1c27a9650 100644 --- a/scene/3d/bone_attachment.h +++ b/scene/3d/bone_attachment.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index dce5060a44..3e78fef147 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -125,7 +125,7 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const { r_ret= int(keep_aspect); else if (p_name=="current") { - if (is_inside_tree() && get_tree()->is_editor_hint()) { + if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { r_ret=current; } else { r_ret=is_current(); @@ -192,12 +192,11 @@ void Camera::_update_camera() { // here goes listener stuff // if (viewport_ptr && is_inside_scene() && is_current()) -// viewport_ptr->_camera_transform_changed_notify(); +// get_viewport()->_camera_transform_changed_notify(); if (is_inside_tree() && is_current()) { - if (viewport_ptr) { - viewport_ptr->_camera_transform_changed_notify(); - } + get_viewport()->_camera_transform_changed_notify(); + } if (is_current() && get_world().is_valid()) { @@ -213,29 +212,10 @@ void Camera::_notification(int p_what) { case NOTIFICATION_ENTER_WORLD: { - viewport_ptr=NULL; - - { //find viewport stuff - Node *parent=get_parent(); - while(parent) { - - Viewport* viewport = parent->cast_to<Viewport>(); - - if (viewport) { - viewport_ptr=viewport; - break; - } - parent=parent->get_parent(); - } - - } - - camera_group = "_vp_cameras"+itos(get_viewport()->get_instance_ID()); - add_to_group(camera_group); - if (viewport_ptr) - viewport_ptr->cameras.insert(this); - if (current) + bool first_camera = get_viewport()->cameras.size()==0; + get_viewport()->cameras.insert(this); + if (!get_tree()->is_node_being_edited(this) && (current || first_camera)) make_current(); @@ -246,17 +226,17 @@ void Camera::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - if (is_current()) { - clear_current(); - current=true; //keep it true + if (!get_tree()->is_node_being_edited(this)) { + if (is_current()) { + clear_current(); + current=true; //keep it true - } else { - current=false; + } else { + current=false; + } } - if (viewport_ptr) - viewport_ptr->cameras.erase(this); - viewport_ptr=NULL; - remove_from_group(camera_group); + + get_viewport()->cameras.erase(this); } break; @@ -324,25 +304,12 @@ void Camera::make_current() { if (!is_inside_tree()) return; - if (viewport_ptr) { - viewport_ptr->_set_camera(this); - } + get_viewport()->_set_camera(this); //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this); } -void Camera::_camera_make_next_current(Node *p_exclude) { - - if (this==p_exclude) - return; - if (!is_inside_tree()) - return; - if (get_viewport()->get_camera()!=NULL) - return; - - make_current(); -} void Camera::clear_current() { @@ -351,12 +318,20 @@ void Camera::clear_current() { if (!is_inside_tree()) return; - if (viewport_ptr) { - if (viewport_ptr->get_camera()==this) { - viewport_ptr->_set_camera(NULL); - //a group is used beause this needs to be in order to be deterministic - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,camera_group,"_camera_make_next_current",this); + if (get_viewport()->get_camera()==this) { + get_viewport()->_set_camera(NULL); + //a group is used beause this needs to be in order to be deterministic + + for (Set<Camera*>::Element *E=get_viewport()->cameras.front();E;E=E->next()) { + if (this==E->get()) + continue; + if (!E->get()->is_inside_tree()) + continue; + if (get_viewport()->get_camera()!=NULL) + return; + + E->get()->make_current(); } } @@ -364,9 +339,9 @@ void Camera::clear_current() { bool Camera::is_current() const { - if (is_inside_tree()) { - if (viewport_ptr) - return viewport_ptr->get_camera()==this; + if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { + + return get_viewport()->get_camera()==this; } else return current; @@ -481,12 +456,12 @@ Vector3 Camera::project_local_ray_normal(const Point2& p_pos) const { #if 0 - Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Size2 viewport_size = get_viewport()->get_visible_rect().size; Vector2 cpos = p_pos; #else - Size2 viewport_size = viewport_ptr->get_camera_rect_size(); - Vector2 cpos = viewport_ptr->get_camera_coords(p_pos); + Size2 viewport_size = get_viewport()->get_camera_rect_size(); + Vector2 cpos = get_viewport()->get_camera_coords(p_pos); #endif Vector3 ray; @@ -514,12 +489,12 @@ Vector3 Camera::project_ray_origin(const Point2& p_pos) const { } #if 0 - Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Size2 viewport_size = get_viewport()->get_visible_rect().size; Vector2 cpos = p_pos; #else - Size2 viewport_size = viewport_ptr->get_camera_rect_size(); - Vector2 cpos = viewport_ptr->get_camera_coords(p_pos); + Size2 viewport_size = get_viewport()->get_camera_rect_size(); + Vector2 cpos = get_viewport()->get_camera_coords(p_pos); #endif ERR_FAIL_COND_V( viewport_size.y == 0, Vector3() ); @@ -566,7 +541,7 @@ Point2 Camera::unproject_position(const Vector3& p_pos) const { ERR_FAIL_COND_V(!is_inside_tree(),Vector2()); } - Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; @@ -597,7 +572,7 @@ Vector3 Camera::project_position(const Point2& p_point) const { ERR_FAIL_COND_V(!is_inside_tree(),Vector3()); } - Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; @@ -692,7 +667,6 @@ void Camera::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment); ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode); ObjectTypeDB::bind_method(_MD("get_keep_aspect_mode"),&Camera::get_keep_aspect_mode); - ObjectTypeDB::bind_method(_MD("_camera_make_next_current"),&Camera::_camera_make_next_current); //ObjectTypeDB::bind_method( _MD("_camera_make_current"),&Camera::_camera_make_current ); BIND_CONSTANT( PROJECTION_PERSPECTIVE ); @@ -745,7 +719,7 @@ Vector<Plane> Camera::get_frustum() const { ERR_FAIL_COND_V(!is_inside_world(),Vector<Plane>()); - Size2 viewport_size = viewport_ptr->get_visible_rect().size; + Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; if (mode==PROJECTION_PERSPECTIVE) cm.set_perspective(fov,viewport_size.get_aspect(),near,far,keep_aspect==KEEP_WIDTH); @@ -789,7 +763,6 @@ Camera::Camera() { near=0; far=0; current=false; - viewport_ptr=NULL; force_change=false; mode=PROJECTION_PERSPECTIVE; set_perspective(60.0,0.1,100.0); diff --git a/scene/3d/camera.h b/scene/3d/camera.h index e21f4865ec..02ca6ffb9a 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -68,18 +68,15 @@ private: RID camera; RID scenario_id; - String camera_group; + //String camera_group; uint32_t layers; - Viewport *viewport_ptr; Ref<Environment> environment; virtual bool _can_gizmo_scale() const; virtual RES _get_gizmo_geometry() const; - void _camera_make_next_current(Node *p_exclude); - //void _camera_make_current(Node *p_camera); friend class Viewport; diff --git a/scene/3d/character_camera.cpp b/scene/3d/character_camera.cpp index 19332bd056..2b22026fe9 100644 --- a/scene/3d/character_camera.cpp +++ b/scene/3d/character_camera.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/character_camera.h b/scene/3d/character_camera.h index 99b41c6eda..d636b4b1a5 100644 --- a/scene/3d/character_camera.h +++ b/scene/3d/character_camera.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp index 5ecadb48b8..373c356a45 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -31,14 +31,14 @@ #include "scene/scene_string_names.h" void CollisionObject::_update_shapes_from_children() { - shapes.resize(0); + shapes.clear(); for(int i=0;i<get_child_count();i++) { Node* n = get_child(i); n->call("_add_to_collision_object",this); } -// _update_shapes(); + _update_shapes(); } void CollisionObject::_notification(int p_what) { diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object.h index 548c9fb85b..f8daeb3ed2 100644 --- a/scene/3d/collision_object.h +++ b/scene/3d/collision_object.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon.cpp index bb0a1fca12..3b14e1d767 100644 --- a/scene/3d/collision_polygon.cpp +++ b/scene/3d/collision_polygon.cpp @@ -236,7 +236,7 @@ void CollisionPolygon::_bind_methods() { ObjectTypeDB::bind_method(_MD("_add_to_collision_object"),&CollisionPolygon::_add_to_collision_object); - ObjectTypeDB::bind_method(_MD("set_build_mode"),&CollisionPolygon::set_build_mode); + ObjectTypeDB::bind_method(_MD("set_build_mode","build_mode"),&CollisionPolygon::set_build_mode); ObjectTypeDB::bind_method(_MD("get_build_mode"),&CollisionPolygon::get_build_mode); ObjectTypeDB::bind_method(_MD("set_depth","depth"),&CollisionPolygon::set_depth); diff --git a/scene/3d/interpolated_camera.cpp b/scene/3d/interpolated_camera.cpp index f44713e8a0..96306d1180 100644 --- a/scene/3d/interpolated_camera.cpp +++ b/scene/3d/interpolated_camera.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/interpolated_camera.h b/scene/3d/interpolated_camera.h index a8ed649c42..dbe84327fb 100644 --- a/scene/3d/interpolated_camera.h +++ b/scene/3d/interpolated_camera.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 9f9c87b675..18463742c6 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -487,9 +487,9 @@ bool Light::is_editor_only() const{ void Light::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_parameter","variable","value"), &Light::set_parameter ); - ObjectTypeDB::bind_method(_MD("get_parameter"), &Light::get_parameter ); + ObjectTypeDB::bind_method(_MD("get_parameter","variable"), &Light::get_parameter ); ObjectTypeDB::bind_method(_MD("set_color","color","value"), &Light::set_color ); - ObjectTypeDB::bind_method(_MD("get_color"), &Light::get_color ); + ObjectTypeDB::bind_method(_MD("get_color","color"), &Light::get_color ); ObjectTypeDB::bind_method(_MD("set_project_shadows","enable"), &Light::set_project_shadows ); ObjectTypeDB::bind_method(_MD("has_project_shadows"), &Light::has_project_shadows ); ObjectTypeDB::bind_method(_MD("set_projector","projector:Texture"), &Light::set_projector ); diff --git a/scene/3d/light.h b/scene/3d/light.h index fb77ac9e64..b74085b7a9 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 62b32729c3..997d2dea7c 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance.h index 76a0eeea60..f26ef52000 100644 --- a/scene/3d/mesh_instance.h +++ b/scene/3d/mesh_instance.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/multimesh_instance.cpp b/scene/3d/multimesh_instance.cpp index cd620ff447..0e97a97943 100644 --- a/scene/3d/multimesh_instance.cpp +++ b/scene/3d/multimesh_instance.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/multimesh_instance.h b/scene/3d/multimesh_instance.h index be6b3677e2..7cd9a8ea82 100644 --- a/scene/3d/multimesh_instance.h +++ b/scene/3d/multimesh_instance.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/optimized_spatial_scene.cpp b/scene/3d/optimized_spatial_scene.cpp index 85c1b79a9a..27631c7a74 100644 --- a/scene/3d/optimized_spatial_scene.cpp +++ b/scene/3d/optimized_spatial_scene.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/optimized_spatial_scene.h b/scene/3d/optimized_spatial_scene.h index a55b5235da..e1e6e14f73 100644 --- a/scene/3d/optimized_spatial_scene.h +++ b/scene/3d/optimized_spatial_scene.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 6868646c48..dfd5c38266 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -422,14 +422,14 @@ void Particles::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_variable","variable","value"),&Particles::set_variable); ObjectTypeDB::bind_method(_MD("get_variable","variable"),&Particles::get_variable); ObjectTypeDB::bind_method(_MD("set_randomness","variable","randomness"),&Particles::set_randomness); - ObjectTypeDB::bind_method(_MD("get_randomness"),&Particles::get_randomness); + ObjectTypeDB::bind_method(_MD("get_randomness","variable"),&Particles::get_randomness); ObjectTypeDB::bind_method(_MD("set_color_phase_pos","phase","pos"),&Particles::set_color_phase_pos); ObjectTypeDB::bind_method(_MD("get_color_phase_pos","phase"),&Particles::get_color_phase_pos); ObjectTypeDB::bind_method(_MD("set_color_phase_color","phase","color"),&Particles::set_color_phase_color); ObjectTypeDB::bind_method(_MD("get_color_phase_color","phase"),&Particles::get_color_phase_color); ObjectTypeDB::bind_method(_MD("set_material","material:Material"),&Particles::set_material); ObjectTypeDB::bind_method(_MD("get_material:Material"),&Particles::get_material); - ObjectTypeDB::bind_method(_MD("set_emit_timeout"),&Particles::set_emit_timeout); + ObjectTypeDB::bind_method(_MD("set_emit_timeout","timeout"),&Particles::set_emit_timeout); ObjectTypeDB::bind_method(_MD("get_emit_timeout"),&Particles::get_emit_timeout); ObjectTypeDB::bind_method(_MD("set_height_from_velocity","enable"),&Particles::set_height_from_velocity); ObjectTypeDB::bind_method(_MD("has_height_from_velocity"),&Particles::has_height_from_velocity); diff --git a/scene/3d/particles.h b/scene/3d/particles.h index 260573fe5f..b9cae332e2 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/path.cpp b/scene/3d/path.cpp index 9cd41b25f6..d6cd3da7c3 100644 --- a/scene/3d/path.cpp +++ b/scene/3d/path.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/path.h b/scene/3d/path.h index 1b40ec413d..2e3573df3e 100644 --- a/scene/3d/path.h +++ b/scene/3d/path.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index d61859a3d0..1a2665b6ad 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -207,6 +207,9 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { ERR_FAIL_COND(E->get().in_tree); E->get().in_tree=true; + + contact_monitor->locked=true; + emit_signal(SceneStringNames::get_singleton()->body_enter,node); for(int i=0;i<E->get().shapes.size();i++) { @@ -214,6 +217,9 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { emit_signal(SceneStringNames::get_singleton()->body_enter_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + contact_monitor->locked=false; + + } void RigidBody::_body_exit_tree(ObjectID p_id) { @@ -225,11 +231,18 @@ void RigidBody::_body_exit_tree(ObjectID p_id) { ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->get().in_tree); E->get().in_tree=false; + + contact_monitor->locked=true; + emit_signal(SceneStringNames::get_singleton()->body_exit,node); + for(int i=0;i<E->get().shapes.size();i++) { emit_signal(SceneStringNames::get_singleton()->body_exit_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + + contact_monitor->locked=false; + } void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape) { @@ -317,6 +330,8 @@ void RigidBody::_direct_state_changed(Object *p_state) { if (contact_monitor) { + contact_monitor->locked=true; + //untag all int rc=0; for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { @@ -396,6 +411,8 @@ void RigidBody::_direct_state_changed(Object *p_state) { _body_inout(1,toadd[i].id,toadd[i].shape,toadd[i].local_shape); } + contact_monitor->locked=false; + } set_ignore_transform_notification(true); @@ -648,6 +665,11 @@ void RigidBody::set_contact_monitor(bool p_enabled) { if (!p_enabled) { + if (contact_monitor->locked) { + ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead"); + } + ERR_FAIL_COND(contact_monitor->locked); + for(Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { //clean up mess @@ -658,6 +680,8 @@ void RigidBody::set_contact_monitor(bool p_enabled) { } else { contact_monitor = memnew( ContactMonitor ); + contact_monitor->locked=false; + } } @@ -1073,7 +1097,7 @@ Vector3 KinematicBody::move_to(const Vector3& p_position) { return move(p_position-get_global_transform().origin); } -bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { +bool KinematicBody::can_teleport_to(const Vector3& p_position) { ERR_FAIL_COND_V(!is_inside_tree(),false); PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(get_world()->get_space()); @@ -1089,25 +1113,18 @@ bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { if (collide_character) mask|=PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY; - Vector3 motion = p_position-get_global_transform().origin; Transform xform=get_global_transform(); - - if (true || p_discrete) { - - xform.origin+=motion; - motion=Vector3(); - } + xform.origin=p_position; Set<RID> exclude; exclude.insert(get_rid()); - //fill exclude list.. for(int i=0;i<get_shape_count();i++) { if (is_shape_set_as_trigger(i)) continue; - bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,0,exclude,get_layer_mask(),mask); + bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_layer_mask(),mask); if (col) return false; } @@ -1205,7 +1222,7 @@ void KinematicBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody::move_to); - ObjectTypeDB::bind_method(_MD("can_move_to","position"),&KinematicBody::can_move_to); + ObjectTypeDB::bind_method(_MD("can_teleport_to","position"),&KinematicBody::can_teleport_to); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody::is_colliding); diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 66490ba925..da79d63f00 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -175,7 +175,7 @@ private: struct ContactMonitor { - + bool locked; Map<ObjectID,BodyState> body_map; }; @@ -304,7 +304,7 @@ public: Vector3 move(const Vector3& p_motion); Vector3 move_to(const Vector3& p_position); - bool can_move_to(const Vector3& p_position,bool p_discrete=false); + bool can_teleport_to(const Vector3& p_position); bool is_colliding() const; Vector3 get_collision_pos() const; Vector3 get_collision_normal() const; diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 0cc72b28e5..3f03b2aab3 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -34,8 +34,15 @@ void Joint::_update_joint(bool p_only_free) { if (joint.is_valid()) { - if (ba.is_valid() && bb.is_valid()) - PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + if (ba.is_valid() && bb.is_valid()) { + + if (exclude_from_collision) + PhysicsServer::get_singleton()->body_add_collision_exception(ba,bb); + else + PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + + } + PhysicsServer::get_singleton()->free(joint); joint=RID(); ba=RID(); @@ -134,7 +141,7 @@ void Joint::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { if (joint.is_valid()) { _update_joint(true); - PhysicsServer::get_singleton()->free(joint); + //PhysicsServer::get_singleton()->free(joint); joint=RID(); } } break; @@ -144,6 +151,19 @@ void Joint::_notification(int p_what) { } +void Joint::set_exclude_nodes_from_collision(bool p_enable) { + + if (exclude_from_collision==p_enable) + return; + exclude_from_collision=p_enable; + _update_joint(); +} + +bool Joint::get_exclude_nodes_from_collision() const{ + + return exclude_from_collision; +} + void Joint::_bind_methods() { @@ -156,10 +176,16 @@ void Joint::_bind_methods() { ObjectTypeDB::bind_method( _MD("set_solver_priority","priority"), &Joint::set_solver_priority ); ObjectTypeDB::bind_method( _MD("get_solver_priority"), &Joint::get_solver_priority ); + ObjectTypeDB::bind_method( _MD("set_exclude_nodes_from_collision","enable"), &Joint::set_exclude_nodes_from_collision ); + ObjectTypeDB::bind_method( _MD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision ); + ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "solver/priority",PROPERTY_HINT_RANGE,"1,8,1"), _SCS("set_solver_priority"),_SCS("get_solver_priority") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), _SCS("set_exclude_nodes_from_collision"),_SCS("get_exclude_nodes_from_collision") ); + + } @@ -167,6 +193,7 @@ void Joint::_bind_methods() { Joint::Joint() { + exclude_from_collision=true; solver_priority=1; } diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h index a5f4ea4bdb..55c26f296e 100644 --- a/scene/3d/physics_joint.h +++ b/scene/3d/physics_joint.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -45,6 +45,7 @@ class Joint : public Spatial { NodePath b; int solver_priority; + bool exclude_from_collision; protected: @@ -67,6 +68,9 @@ public: void set_solver_priority(int p_priority); int get_solver_priority() const; + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + RID get_joint() const { return joint; } Joint(); diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp index 34499578aa..84f94402d5 100644 --- a/scene/3d/portal.cpp +++ b/scene/3d/portal.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/portal.h b/scene/3d/portal.h index 14c1275312..388eac4dd3 100644 --- a/scene/3d/portal.h +++ b/scene/3d/portal.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/position_3d.cpp b/scene/3d/position_3d.cpp index d692c0f249..27130cbe6a 100644 --- a/scene/3d/position_3d.cpp +++ b/scene/3d/position_3d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/position_3d.h b/scene/3d/position_3d.h index 265c0b48c7..6bac540fcb 100644 --- a/scene/3d/position_3d.h +++ b/scene/3d/position_3d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/proximity_group.cpp b/scene/3d/proximity_group.cpp index 334246b033..a2182302a0 100644 --- a/scene/3d/proximity_group.cpp +++ b/scene/3d/proximity_group.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/proximity_group.h b/scene/3d/proximity_group.h index 35e3f3dd98..6d5c703827 100644 --- a/scene/3d/proximity_group.h +++ b/scene/3d/proximity_group.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/quad.cpp b/scene/3d/quad.cpp index 43bde8dc61..1a7eeef180 100644 --- a/scene/3d/quad.cpp +++ b/scene/3d/quad.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/quad.h b/scene/3d/quad.h index 5ef4af8b81..be55b0d1c9 100644 --- a/scene/3d/quad.h +++ b/scene/3d/quad.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 5f2c8e0ba3..ab2c4fc8dc 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h index 06e9e31396..520b4d5313 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp index 2ae75b8b68..e358da136b 100644 --- a/scene/3d/room_instance.cpp +++ b/scene/3d/room_instance.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/room_instance.h b/scene/3d/room_instance.h index 09fccc5ebc..c7df4ceadd 100644 --- a/scene/3d/room_instance.h +++ b/scene/3d/room_instance.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/scenario_fx.cpp b/scene/3d/scenario_fx.cpp index 59c8b5e0df..2e22ab36d3 100644 --- a/scene/3d/scenario_fx.cpp +++ b/scene/3d/scenario_fx.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/scenario_fx.h b/scene/3d/scenario_fx.h index b877cccc19..a3c13e03a1 100644 --- a/scene/3d/scenario_fx.h +++ b/scene/3d/scenario_fx.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index cb81228dff..64133f67b5 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index 6678722d12..033f212a58 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a65f68ed2c..0c1e1e2d1c 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -594,6 +594,15 @@ bool Spatial::is_hidden() const{ return !data.visible; } +void Spatial::set_hidden(bool p_hidden) { + + if (data.visible != p_hidden) { + return; + } + + _set_visible_(!p_hidden); +} + void Spatial::_set_visible_(bool p_visible) { if (p_visible) @@ -742,6 +751,7 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("hide"), &Spatial::hide); ObjectTypeDB::bind_method(_MD("is_visible"), &Spatial::is_visible); ObjectTypeDB::bind_method(_MD("is_hidden"), &Spatial::is_hidden); + ObjectTypeDB::bind_method(_MD("set_hidden","hidden"), &Spatial::set_hidden); ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 7fa6099d7a..23f1c6d103 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -191,6 +191,7 @@ public: void hide(); bool is_visible() const; bool is_hidden() const; + void set_hidden(bool p_hidden); #ifdef TOOLS_ENABLED void set_import_transform(const Transform& p_transform) ; diff --git a/scene/3d/spatial_indexer.cpp b/scene/3d/spatial_indexer.cpp index 2f7aee5c67..d5be36b2cb 100644 --- a/scene/3d/spatial_indexer.cpp +++ b/scene/3d/spatial_indexer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_indexer.h b/scene/3d/spatial_indexer.h index bc19b54d8f..13ce8badea 100644 --- a/scene/3d/spatial_indexer.h +++ b/scene/3d/spatial_indexer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_player.cpp b/scene/3d/spatial_player.cpp index 5948c01ff8..c7cf03e284 100644 --- a/scene/3d/spatial_player.cpp +++ b/scene/3d/spatial_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_player.h b/scene/3d/spatial_player.h index 2f54497847..5a8687b854 100644 --- a/scene/3d/spatial_player.h +++ b/scene/3d/spatial_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_sample_player.cpp b/scene/3d/spatial_sample_player.cpp index 28b8fdd01e..7114fd4b77 100644 --- a/scene/3d/spatial_sample_player.cpp +++ b/scene/3d/spatial_sample_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_sample_player.h b/scene/3d/spatial_sample_player.h index 1d7bb8e238..9b3220458e 100644 --- a/scene/3d/spatial_sample_player.h +++ b/scene/3d/spatial_sample_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/spatial_stream_player.cpp b/scene/3d/spatial_stream_player.cpp index 7ed2335fcb..dfef0faf4b 100644 --- a/scene/3d/spatial_stream_player.cpp +++ b/scene/3d/spatial_stream_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -60,7 +60,7 @@ void SpatialStreamPlayer::sp_set_mix_rate(int p_rate){ bool SpatialStreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { - if (resampler.is_ready()) { + if (resampler.is_ready() && !paused) { return resampler.mix(p_buffer,p_frames); } @@ -332,7 +332,7 @@ void SpatialStreamPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_stream","stream:Stream"),&SpatialStreamPlayer::set_stream); ObjectTypeDB::bind_method(_MD("get_stream:Stream"),&SpatialStreamPlayer::get_stream); - ObjectTypeDB::bind_method(_MD("play"),&SpatialStreamPlayer::play,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("play","offset"),&SpatialStreamPlayer::play,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("stop"),&SpatialStreamPlayer::stop); ObjectTypeDB::bind_method(_MD("is_playing"),&SpatialStreamPlayer::is_playing); diff --git a/scene/3d/spatial_stream_player.h b/scene/3d/spatial_stream_player.h index f2775a4982..0732b3fc10 100644 --- a/scene/3d/spatial_stream_player.h +++ b/scene/3d/spatial_stream_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/test_cube.cpp b/scene/3d/test_cube.cpp index 0acd1b3351..6440d95d55 100644 --- a/scene/3d/test_cube.cpp +++ b/scene/3d/test_cube.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/test_cube.h b/scene/3d/test_cube.h index 2dbd7c9856..21f2b3c794 100644 --- a/scene/3d/test_cube.h +++ b/scene/3d/test_cube.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index ad62f6d809..60097ad482 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/visibility_notifier.h b/scene/3d/visibility_notifier.h index 85c26bec94..a4709b7cf4 100644 --- a/scene/3d/visibility_notifier.h +++ b/scene/3d/visibility_notifier.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp index 41e8b6bf54..723b0a9af5 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h index 3c69f09978..e49f4fb82f 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index b1d6da7294..b1123897b2 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/animation_cache.h b/scene/animation/animation_cache.h index e94530d924..c9b4ff298c 100644 --- a/scene/animation/animation_cache.h +++ b/scene/animation/animation_cache.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index c2ea1c8bb6..f6d058c2fd 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -268,6 +268,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { TrackNodeCacheKey key; key.id=id; key.bone_idx=bone_idx; + if (node_cache_map.has(key)) { @@ -278,6 +279,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { node_cache_map[key]=TrackNodeCache(); p_anim->node_cache[i]=&node_cache_map[key]; + p_anim->node_cache[i]->path=a->track_get_path(i); p_anim->node_cache[i]->node=child; p_anim->node_cache[i]->resource=resource; p_anim->node_cache[i]->node_2d=child->cast_to<Node2D>(); @@ -320,6 +322,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { pa.prop=property; pa.object=resource.is_valid()?(Object*)resource.ptr():(Object*)child; pa.special=SP_NONE; + pa.owner=p_anim->node_cache[i]; if (false && p_anim->node_cache[i]->node_2d) { if (pa.prop==SceneStringNames::get_singleton()->transform_pos) @@ -410,7 +413,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p TrackNodeCache::PropertyAnim *pa = &E->get(); - if (a->value_track_is_continuous(i) || p_delta==0) { + if (a->value_track_is_continuous(i) || p_delta==0) { //delta == 0 means seek Variant value=a->value_track_interpolate(i,p_time); @@ -436,10 +439,42 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p Variant value=a->track_get_key_value(i,F->get()); switch(pa->special) { - case SP_NONE: pa->object->set(pa->prop,value); break; //you are not speshul - case SP_NODE2D_POS: static_cast<Node2D*>(pa->object)->set_pos(value); break; - case SP_NODE2D_ROT: static_cast<Node2D*>(pa->object)->set_rot(Math::deg2rad(value)); break; - case SP_NODE2D_SCALE: static_cast<Node2D*>(pa->object)->set_scale(value); break; + case SP_NONE: { + bool valid; + pa->object->set(pa->prop,value,&valid); //you are not speshul +#ifdef DEBUG_ENABLED + if (!valid) { + ERR_PRINTS("Failed setting track value '"+String(pa->owner->path)+"'. Check if property exists or the type of key is valid"); + } +#endif + + } break; + case SP_NODE2D_POS: { +#ifdef DEBUG_ENABLED + if (value.get_type()!=Variant::VECTOR2) { + ERR_PRINTS("Position key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not of type Vector2()"); + } +#endif + static_cast<Node2D*>(pa->object)->set_pos(value); + } break; + case SP_NODE2D_ROT: { +#ifdef DEBUG_ENABLED + if (value.is_num()) { + ERR_PRINTS("Rotation key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not numerical"); + } +#endif + + static_cast<Node2D*>(pa->object)->set_rot(Math::deg2rad(value)); + } break; + case SP_NODE2D_SCALE: { +#ifdef DEBUG_ENABLED + if (value.get_type()!=Variant::VECTOR2) { + ERR_PRINTS("Scale key at time "+rtos(p_time)+" in Animation Track '"+String(pa->owner->path)+"' not of type Vector2()"); + } +#endif + + static_cast<Node2D*>(pa->object)->set_scale(value); + } break; } } @@ -607,13 +642,53 @@ void AnimationPlayer::_animation_update_transforms() { ERR_CONTINUE( pa->accum_pass!=accum_pass ); #if 1 - switch(pa->special) { +/* switch(pa->special) { case SP_NONE: pa->object->set(pa->prop,pa->value_accum); break; //you are not speshul case SP_NODE2D_POS: static_cast<Node2D*>(pa->object)->set_pos(pa->value_accum); break; case SP_NODE2D_ROT: static_cast<Node2D*>(pa->object)->set_rot(Math::deg2rad(pa->value_accum)); break; case SP_NODE2D_SCALE: static_cast<Node2D*>(pa->object)->set_scale(pa->value_accum); break; + }*/ + + switch(pa->special) { + + case SP_NONE: { + bool valid; + pa->object->set(pa->prop,pa->value_accum,&valid); //you are not speshul +#ifdef DEBUG_ENABLED + if (!valid) { + ERR_PRINTS("Failed setting key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"'. Check if property exists or the type of key is right for the property"); + } +#endif + + } break; + case SP_NODE2D_POS: { +#ifdef DEBUG_ENABLED + if (pa->value_accum.get_type()!=Variant::VECTOR2) { + ERR_PRINTS("Position key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not of type Vector2()"); + } +#endif + static_cast<Node2D*>(pa->object)->set_pos(pa->value_accum); + } break; + case SP_NODE2D_ROT: { +#ifdef DEBUG_ENABLED + if (pa->value_accum.is_num()) { + ERR_PRINTS("Rotation key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not numerical"); + } +#endif + + static_cast<Node2D*>(pa->object)->set_rot(Math::deg2rad(pa->value_accum)); + } break; + case SP_NODE2D_SCALE: { +#ifdef DEBUG_ENABLED + if (pa->value_accum.get_type()!=Variant::VECTOR2) { + ERR_PRINTS("Scale key at time "+rtos(playback.current.pos)+" in Animation '"+get_current_animation()+"', Track '"+String(pa->owner->path)+"' not of type Vector2()"); + } +#endif + + static_cast<Node2D*>(pa->object)->set_scale(pa->value_accum); + } break; } #else diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 1e3c37c4d6..853526c80a 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -68,6 +68,7 @@ private: struct TrackNodeCache { + NodePath path; uint32_t id; RES resource; Node *node; @@ -84,6 +85,7 @@ private: struct PropertyAnim { + TrackNodeCache *owner; SpecialProperty special; //small optimization StringName prop; Object *object; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index c7e259c3c6..77d9f77bb5 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -432,7 +432,7 @@ void AnimationTreePlayer::_notification(int p_what) { } -float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode **r_prev_anim,float p_weight, float p_time, bool p_seek,const HashMap<NodePath,bool> *p_filter, float p_reverse_weight) { +float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode **r_prev_anim,float p_weight, float p_time, bool switched, bool p_seek,const HashMap<NodePath,bool> *p_filter, float p_reverse_weight) { ERR_FAIL_COND_V(!node_map.has(p_node), 0); NodeBase *nb=node_map[p_node]; @@ -445,7 +445,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode case NODE_OUTPUT: { NodeOut *on = static_cast<NodeOut*>(nb); - return _process_node(on->inputs[0].node,r_prev_anim,p_weight,p_time,p_seek); + return _process_node(on->inputs[0].node,r_prev_anim,p_weight,p_time,switched,p_seek); } break; case NODE_ANIMATION: { @@ -479,6 +479,9 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode an->time=anim_size; } + if (switched && an->time >= anim_size) { + an->time = 0.0; + } an->skip=true; for (List<AnimationNode::TrackRef>::Element *E=an->tref.front();E;E=E->next()) { @@ -520,7 +523,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (!osn->active) { //make it as if this node doesn't exist, pass input 0 by. - return _process_node(osn->inputs[0].node,r_prev_anim,p_weight,p_time,p_seek,p_filter,p_reverse_weight); + return _process_node(osn->inputs[0].node,r_prev_anim,p_weight,p_time,switched,p_seek,p_filter,p_reverse_weight); } if (p_seek) @@ -551,13 +554,13 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (!osn->filter.empty()) { - main_rem = _process_node(osn->inputs[0].node,r_prev_anim,(osn->mix?p_weight:p_weight*(1.0-blend)),p_time,p_seek,&osn->filter,p_weight); - os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_weight*blend,p_time,p_seek,&osn->filter,-1); + main_rem = _process_node(osn->inputs[0].node,r_prev_anim,(osn->mix?p_weight:p_weight*(1.0-blend)),p_time,switched,p_seek,&osn->filter,p_weight); + os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_weight*blend,p_time,osn->start,p_seek,&osn->filter,-1); } else { - main_rem = _process_node(osn->inputs[0].node,r_prev_anim,(osn->mix?p_weight:p_weight*(1.0-blend)),p_time,p_seek); - os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_weight*blend,p_time,p_seek); + main_rem = _process_node(osn->inputs[0].node,r_prev_anim,(osn->mix?p_weight:p_weight*(1.0-blend)),p_time,switched,p_seek); + os_rem = _process_node(osn->inputs[1].node,r_prev_anim,p_weight*blend,p_time,osn->start,p_seek); } if (osn->start) { @@ -578,8 +581,8 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode MixNode *mn = static_cast<MixNode*>(nb); - float rem = _process_node(mn->inputs[0].node,r_prev_anim,p_weight,p_time,p_seek,p_filter,p_reverse_weight); - _process_node(mn->inputs[1].node,r_prev_anim,p_weight*mn->amount,p_time,p_seek,p_filter,p_reverse_weight); + float rem = _process_node(mn->inputs[0].node,r_prev_anim,p_weight,p_time,switched,p_seek,p_filter,p_reverse_weight); + _process_node(mn->inputs[1].node,r_prev_anim,p_weight*mn->amount,p_time,switched,p_seek,p_filter,p_reverse_weight); return rem; } break; @@ -590,12 +593,12 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode float rem; if (!bn->filter.empty()) { - rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,p_seek,&bn->filter,p_weight); - _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value,p_time,p_seek,&bn->filter,-1); + rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,switched,p_seek,&bn->filter,p_weight); + _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value,p_time,switched,p_seek,&bn->filter,-1); } else { - rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,p_seek,p_filter,p_reverse_weight*(1.0-bn->value)); - _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value,p_time,p_seek,p_filter,p_reverse_weight*bn->value); + rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0-bn->value)); + _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value,p_time,switched,p_seek,p_filter,p_reverse_weight*bn->value); } return rem; @@ -606,16 +609,16 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode float rem; if (bn->value==0) { - rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight,p_time,p_seek,p_filter,p_reverse_weight); + rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight,p_time,switched,p_seek,p_filter,p_reverse_weight); } else if (bn->value>0) { - rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,p_seek,p_filter,p_reverse_weight*(1.0-bn->value)); - _process_node(bn->inputs[2].node,r_prev_anim,p_weight*bn->value,p_time,p_seek,p_filter,p_reverse_weight*bn->value); + rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight*(1.0-bn->value),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0-bn->value)); + _process_node(bn->inputs[2].node,r_prev_anim,p_weight*bn->value,p_time,switched,p_seek,p_filter,p_reverse_weight*bn->value); } else { - rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight*(1.0+bn->value),p_time,p_seek,p_filter,p_reverse_weight*(1.0+bn->value)); - _process_node(bn->inputs[0].node,r_prev_anim,p_weight*-bn->value,p_time,p_seek,p_filter,p_reverse_weight*-bn->value); + rem = _process_node(bn->inputs[1].node,r_prev_anim,p_weight*(1.0+bn->value),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0+bn->value)); + _process_node(bn->inputs[0].node,r_prev_anim,p_weight*-bn->value,p_time,switched,p_seek,p_filter,p_reverse_weight*-bn->value); } return rem; @@ -623,10 +626,10 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode case NODE_BLEND4: { Blend4Node *bn = static_cast<Blend4Node*>(nb); - float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value.x),p_time,p_seek,p_filter,p_reverse_weight*(1.0-bn->value.x)); - _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value.x,p_time,p_seek,p_filter,p_reverse_weight*bn->value.x); - float rem2 = _process_node(bn->inputs[2].node,r_prev_anim,p_weight*(1.0-bn->value.y),p_time,p_seek,p_filter,p_reverse_weight*(1.0-bn->value.y)); - _process_node(bn->inputs[3].node,r_prev_anim,p_weight*bn->value.y,p_time,p_seek,p_filter,p_reverse_weight*bn->value.y); + float rem = _process_node(bn->inputs[0].node,r_prev_anim,p_weight*(1.0-bn->value.x),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0-bn->value.x)); + _process_node(bn->inputs[1].node,r_prev_anim,p_weight*bn->value.x,p_time,switched,p_seek,p_filter,p_reverse_weight*bn->value.x); + float rem2 = _process_node(bn->inputs[2].node,r_prev_anim,p_weight*(1.0-bn->value.y),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0-bn->value.y)); + _process_node(bn->inputs[3].node,r_prev_anim,p_weight*bn->value.y,p_time,switched,p_seek,p_filter,p_reverse_weight*bn->value.y); return MAX(rem,rem2); @@ -634,9 +637,9 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode case NODE_TIMESCALE: { TimeScaleNode *tsn = static_cast<TimeScaleNode*>(nb); if (p_seek) - return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time,true,p_filter,p_reverse_weight); + return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time,switched,true,p_filter,p_reverse_weight); else - return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time*tsn->scale,false,p_filter,p_reverse_weight); + return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time*tsn->scale,switched,false,p_filter,p_reverse_weight); } break; case NODE_TIMESEEK: { @@ -644,12 +647,12 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode TimeSeekNode *tsn = static_cast<TimeSeekNode*>(nb); if (tsn->seek_pos>=0) { - float res = _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,tsn->seek_pos,true,p_filter,p_reverse_weight); + float res = _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,tsn->seek_pos,switched,true,p_filter,p_reverse_weight); tsn->seek_pos=-1; return res; } else - return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time,p_seek); + return _process_node(tsn->inputs[0].node,r_prev_anim,p_weight,p_time,switched,p_seek); } break; case NODE_TRANSITION: { @@ -658,7 +661,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (tn->prev<0) { - float rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight,p_time,p_seek,p_filter,p_reverse_weight); + float rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight,p_time,switched,p_seek,p_filter,p_reverse_weight); if (p_seek) tn->time=p_time; else @@ -687,10 +690,10 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (!p_seek && tn->switched) { //just switched - rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight*(1.0-blend),0,true,p_filter,p_reverse_weight*(1.0-blend)); + rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight*(1.0-blend),0,true,true,p_filter,p_reverse_weight*(1.0-blend)); } else { - rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight*(1.0-blend),p_time,p_seek,p_filter,p_reverse_weight*(1.0-blend)); + rem = _process_node(tn->inputs[tn->current].node,r_prev_anim,p_weight*(1.0-blend),p_time,switched,p_seek,p_filter,p_reverse_weight*(1.0-blend)); } @@ -700,10 +703,10 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (p_seek) { - _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_weight*blend,0,false,p_filter,p_reverse_weight*blend); + _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_weight*blend,0,true,false,p_filter,p_reverse_weight*blend); tn->time=p_time; } else { - _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_weight*blend,p_time,false,p_filter,p_reverse_weight*blend); + _process_node(tn->inputs[tn->prev].node,r_prev_anim,p_weight*blend,p_time,switched,false,p_filter,p_reverse_weight*blend); tn->time+=p_time; tn->prev_xfading-=p_time; if (tn->prev_xfading<0) { @@ -740,10 +743,10 @@ void AnimationTreePlayer::_process_animation(float p_delta) { AnimationNode *prev=NULL; if (reset_request) { - _process_node(out_name,&prev, 1.0, 0, true ); + _process_node(out_name,&prev, 1.0, 0, true, true ); reset_request=false; } else - _process_node(out_name,&prev, 1.0, p_delta, false ); + _process_node(out_name,&prev, 1.0, p_delta, false, false ); if (dirty_caches) { //some animation changed.. ignore this pass @@ -834,7 +837,7 @@ void AnimationTreePlayer::_process_animation(float p_delta) { StringName method = a->method_track_get_name(tr.local_track,E->get()); Vector<Variant> args=a->method_track_get_params(tr.local_track,E->get()); - ERR_CONTINUE(args.size()!=VARIANT_ARG_MAX); + args.resize(VARIANT_ARG_MAX); tr.track->node->call(method,args[0],args[1],args[2],args[3],args[4]); } } break; diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h index 9ea5ccf330..0fec9a9551 100644 --- a/scene/animation/animation_tree_player.h +++ b/scene/animation/animation_tree_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -267,7 +267,7 @@ private: Map<StringName,NodeBase*> node_map; // return time left to finish animation - float _process_node(const StringName& p_node,AnimationNode **r_prev_anim, float p_weight,float p_step, bool p_seek=false,const HashMap<NodePath,bool> *p_filter=NULL, float p_reverse_weight=0); + float _process_node(const StringName& p_node,AnimationNode **r_prev_anim, float p_weight,float p_step, bool switched, bool p_seek=false,const HashMap<NodePath,bool> *p_filter=NULL, float p_reverse_weight=0); void _process_animation(float p_delta); bool reset_request; diff --git a/scene/animation/transitioner.cpp b/scene/animation/transitioner.cpp index d210f29db0..adcf73d489 100644 --- a/scene/animation/transitioner.cpp +++ b/scene/animation/transitioner.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/transitioner.h b/scene/animation/transitioner.h index dba83cddd8..8b7ec4f3fa 100644 --- a/scene/animation/transitioner.h +++ b/scene/animation/transitioner.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 73d93e50ec..31f30dd1d9 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/tween.h b/scene/animation/tween.h index d504c63d8a..f06ca1e9e7 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/animation/tween_interpolaters.cpp b/scene/animation/tween_interpolaters.cpp index 9128d220de..80588d643e 100644 --- a/scene/animation/tween_interpolaters.cpp +++ b/scene/animation/tween_interpolaters.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/event_player.cpp b/scene/audio/event_player.cpp index 1bd692431d..eabe84a8ee 100644 --- a/scene/audio/event_player.cpp +++ b/scene/audio/event_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -312,16 +312,14 @@ void EventPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_pos"),&EventPlayer::get_pos); ObjectTypeDB::bind_method(_MD("seek_pos","time"),&EventPlayer::seek_pos); - ObjectTypeDB::bind_method(_MD("set_autoplay","enabled"),&EventPlayer::set_autoplay); - ObjectTypeDB::bind_method(_MD("has_autoplay"),&EventPlayer::has_autoplay); - - ObjectTypeDB::bind_method(_MD("set_channel_volume","idx","channel_volume"),&EventPlayer::set_channel_volume); - ObjectTypeDB::bind_method(_MD("get_channel_volume""idx"),&EventPlayer::get_channel_volume); - ObjectTypeDB::bind_method(_MD("get_length"),&EventPlayer::get_length); + ObjectTypeDB::bind_method(_MD("set_autoplay","enabled"),&EventPlayer::set_autoplay); + ObjectTypeDB::bind_method(_MD("has_autoplay"),&EventPlayer::has_autoplay); - ObjectTypeDB::bind_method(_MD("get_channel_last_note_time"),&EventPlayer::get_channel_last_note_time); + ObjectTypeDB::bind_method(_MD("set_channel_volume","channel","channel_volume"),&EventPlayer::set_channel_volume); + ObjectTypeDB::bind_method(_MD("get_channel_volume","channel"),&EventPlayer::get_channel_volume); + ObjectTypeDB::bind_method(_MD("get_channel_last_note_time","channel"),&EventPlayer::get_channel_last_note_time); ObjectTypeDB::bind_method(_MD("_set_play","play"),&EventPlayer::_set_play); ObjectTypeDB::bind_method(_MD("_get_play"),&EventPlayer::_get_play); diff --git a/scene/audio/event_player.h b/scene/audio/event_player.h index 05e78040d2..c04e85fe77 100644 --- a/scene/audio/event_player.h +++ b/scene/audio/event_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/sample_player.cpp b/scene/audio/sample_player.cpp index 7c0a926324..d7605ed1a9 100644 --- a/scene/audio/sample_player.cpp +++ b/scene/audio/sample_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/sample_player.h b/scene/audio/sample_player.h index 75a01aff86..1821c671dc 100644 --- a/scene/audio/sample_player.h +++ b/scene/audio/sample_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/sound_room_params.cpp b/scene/audio/sound_room_params.cpp index 8886113e03..bb2285c97f 100644 --- a/scene/audio/sound_room_params.cpp +++ b/scene/audio/sound_room_params.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/sound_room_params.h b/scene/audio/sound_room_params.h index 8af2ae8c12..4ca1eae2ce 100644 --- a/scene/audio/sound_room_params.h +++ b/scene/audio/sound_room_params.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/audio/stream_player.cpp b/scene/audio/stream_player.cpp index 4cfca0492a..f7cfc31b03 100644 --- a/scene/audio/stream_player.cpp +++ b/scene/audio/stream_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -58,7 +58,7 @@ void StreamPlayer::sp_set_mix_rate(int p_rate){ bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { - if (resampler.is_ready()) { + if (resampler.is_ready() && !paused) { return resampler.mix(p_buffer,p_frames); } @@ -75,7 +75,10 @@ void StreamPlayer::sp_update() { //check that all this audio has been flushed before stopping the stream int to_mix = resampler.get_total() - resampler.get_todo(); if (to_mix==0) { - stop(); + if (!stop_request) { + stop_request=true; + call_deferred("stop"); + } return; } @@ -164,8 +167,10 @@ void StreamPlayer::stop() { //_THREAD_SAFE_METHOD_ AudioServer::get_singleton()->stream_set_active(stream_rid,false); + stop_request=false; playback->stop(); resampler.flush(); + emit_signal("finished"); //set_idle_process(false); } @@ -329,7 +334,7 @@ void StreamPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_stream","stream:Stream"),&StreamPlayer::set_stream); ObjectTypeDB::bind_method(_MD("get_stream:Stream"),&StreamPlayer::get_stream); - ObjectTypeDB::bind_method(_MD("play"),&StreamPlayer::play,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("play","offset"),&StreamPlayer::play,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("stop"),&StreamPlayer::stop); ObjectTypeDB::bind_method(_MD("is_playing"),&StreamPlayer::is_playing); @@ -374,6 +379,8 @@ void StreamPlayer::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/paused"), _SCS("set_paused"), _SCS("is_paused") ); ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/loop_restart_time"), _SCS("set_loop_restart_time"), _SCS("get_loop_restart_time") ); ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/buffering_ms"), _SCS("set_buffering_msec"), _SCS("get_buffering_msec") ); + + ADD_SIGNAL(MethodInfo("finished")); } @@ -389,6 +396,7 @@ StreamPlayer::StreamPlayer() { stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream); buffering_ms=500; loop_point=0; + stop_request=false; } diff --git a/scene/audio/stream_player.h b/scene/audio/stream_player.h index be090f50e1..30840137e2 100644 --- a/scene/audio/stream_player.h +++ b/scene/audio/stream_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -66,6 +66,7 @@ class StreamPlayer : public Node { float volume; float loop_point; int buffering_ms; + volatile bool stop_request; AudioRBResampler resampler; diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 0c63a3bc74..698dbce2b5 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index e187a85eae..83c66326c5 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index b63b3de530..6fff90809e 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/box_container.h b/scene/gui/box_container.h index c357814baf..6e63e8bdac 100644 --- a/scene/gui/box_container.h +++ b/scene/gui/box_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index edeb18bfc1..b9ce46d738 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -137,8 +137,10 @@ void Button::_notification(int p_what) { text_ofs.y+=font->get_ascent(); font->draw( ci, text_ofs.floor(), text, color,clip_text?text_clip:-1); if (!_icon.is_null()) { + + int valign = size.height-style->get_minimum_size().y; - _icon->draw(ci,Point2(style->get_offset().x, Math::floor( (size.height-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); + _icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } diff --git a/scene/gui/button.h b/scene/gui/button.h index 690179b90c..bd244f5087 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp index b86e32dda7..9e3476899f 100644 --- a/scene/gui/button_array.cpp +++ b/scene/gui/button_array.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h index ea2c1e4968..39661eaabd 100644 --- a/scene/gui/button_array.h +++ b/scene/gui/button_array.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/button_group.cpp b/scene/gui/button_group.cpp index c92d7f2696..04ba5fc06d 100644 --- a/scene/gui/button_group.cpp +++ b/scene/gui/button_group.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/button_group.h b/scene/gui/button_group.h index 74e847e937..38c61991b7 100644 --- a/scene/gui/button_group.h +++ b/scene/gui/button_group.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp index 8a22a38980..844175e4c1 100644 --- a/scene/gui/center_container.cpp +++ b/scene/gui/center_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/center_container.h b/scene/gui/center_container.h index 4d8d06ac8c..dc95533525 100644 --- a/scene/gui/center_container.h +++ b/scene/gui/center_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 2aa82bc5f5..1381d6eb60 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h index 171fd55351..95dd4891d4 100644 --- a/scene/gui/check_box.h +++ b/scene/gui/check_box.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index d765aefe5e..ecaea251a5 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h index b90bb31c2d..022ade2193 100644 --- a/scene/gui/check_button.h +++ b/scene/gui/check_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index c30d473610..8685ec1c99 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -28,25 +28,43 @@ /*************************************************************************/ #include "color_picker.h" +#include "scene/gui/separator.h" +#include "scene/main/viewport.h" +#include "os/os.h" +#include "os/input.h" +#include "os/keyboard.h" +void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color) { + if (!mat.is_valid()) + return; + Ref<Shader> sdr = mat->get_shader(); + if (!sdr.is_valid()) + return; + mat->set_shader_param("R",p_color.r); + mat->set_shader_param("G",p_color.g); + mat->set_shader_param("B",p_color.b); + mat->set_shader_param("H",p_color.get_h()); + mat->set_shader_param("S",p_color.get_s()); + mat->set_shader_param("V",p_color.get_v()); + mat->set_shader_param("A",p_color.a); +} void ColorPicker::_notification(int p_what) { switch(p_what) { case NOTIFICATION_THEME_CHANGED: { - + uv_material->set_shader(get_shader("uv_editor")); + w_material->set_shader(get_shader("w_editor")); + update_material(uv_material,color); + update_material(w_material,color); _update_controls(); } break; -/* case NOTIFICATION_DRAW: { - - int w = get_constant("color_width"); - int h = ms.height; - VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(0,0,w,h),color); - - } break;*/ + case NOTIFICATION_ENTER_TREE: { + btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); + } } } @@ -64,10 +82,16 @@ void ColorPicker::_update_controls() { } - void ColorPicker::set_color(const Color& p_color) { color=p_color; + h=color.get_h(); + s=color.get_s(); + v=color.get_v(); + update_material(uv_material, color); + update_material(w_material, color); + uv_edit->get_child(0)->cast_to<Control>()->update(); + w_edit->get_child(0)->cast_to<Control>()->update(); _update_color(); } @@ -77,7 +101,7 @@ void ColorPicker::set_edit_alpha(bool p_show) { edit_alpha=p_show; _update_controls(); _update_color(); - color_box->update(); + sample->update(); } bool ColorPicker::is_editing_alpha() const { @@ -90,35 +114,17 @@ void ColorPicker::_value_changed(double) { if (updating) return; - switch(mode) { - - case MODE_RGB: { - - for(int i=0;i<4;i++) { - color.components[i] = scroll[i]->get_val() / 255.0; - } - - } break; - case MODE_HSV: { - - color.set_hsv( CLAMP(scroll[0]->get_val()/359,0,0.9972), scroll[1]->get_val()/100, scroll[2]->get_val()/100 ); - color.a=scroll[3]->get_val()/100.0; - - } break; - case MODE_RAW: { - - for(int i=0;i<4;i++) { - color.components[i] = scroll[i]->get_val(); - } - - } break; - + for(int i=0;i<3;i++) { + color.components[i] = scroll[i]->get_val()/(raw_mode_enabled?1.0:255.0); } + color.components[3] = scroll[3]->get_val()/255.0; + update_material(uv_material,color); + update_material(w_material,color); html->set_text(color.to_html(edit_alpha && color.a<1)); - color_box->update(); + sample->update(); emit_signal("color_changed",color); @@ -138,144 +144,325 @@ void ColorPicker::_update_color() { updating=true; - switch(mode) { - - case MODE_RAW: { - - static const char*_lt[4]={"R","G","B","A"}; - - for(int i=0;i<4;i++) { - scroll[i]->set_max(255); - scroll[i]->set_step(0.01); - scroll[i]->set_val(color.components[i]); - labels[i]->set_text(_lt[i]); - } - } break; - case MODE_RGB: { - - static const char*_lt[4]={"R","G","B","A"}; - - for(int i=0;i<4;i++) { - scroll[i]->set_max(255); - scroll[i]->set_step(1); - scroll[i]->set_val(color.components[i]*255); - labels[i]->set_text(_lt[i]); - } - - } break; - case MODE_HSV: { - - static const char*_lt[4]={"H","S","V","A"}; + for(int i=0;i<4;i++) { + scroll[i]->set_max(255); + scroll[i]->set_step(0.01); + if (raw_mode_enabled && i != 3) + scroll[i]->set_val(color.components[i]); + else + scroll[i]->set_val(color.components[i]*255); + } - for(int i=0;i<4;i++) { - labels[i]->set_text(_lt[i]); - } + html->set_text(color.to_html(edit_alpha && color.a<1)); - scroll[0]->set_max(359); - scroll[0]->set_step(0.01); - scroll[0]->set_val( color.get_h()*359 ); + sample->update(); + updating=false; +} - scroll[1]->set_max(100); - scroll[1]->set_step(0.01); - scroll[1]->set_val( color.get_s()*100 ); +void ColorPicker::_update_presets() +{ + Size2 size=bt_add_preset->get_size(); + preset->set_custom_minimum_size(Size2(size.width*presets.size(),size.height)); + Image i(size.x*presets.size(),size.y, false, Image::FORMAT_RGB); + for (int y=0;y<size.y;y++) + for (int x=0;x<size.x*presets.size();x++) + i.put_pixel(x,y,presets[(int)x/size.x]); + Ref<ImageTexture> t; + t.instance(); + t->create_from_image(i); + preset->set_texture(t); +} - scroll[2]->set_max(100); - scroll[2]->set_step(0.01); - scroll[2]->set_val( color.get_v()*100 ); +Color ColorPicker::get_color() const { - scroll[3]->set_max(100); - scroll[3]->set_step(0.01); - scroll[3]->set_val( color.a*100); + return color; +} - } break; +void ColorPicker::add_preset(const Color &p_color) +{ + if (presets.find(p_color)) { + presets.move_to_back(presets.find(p_color)); + } else { + presets.push_back(p_color); } + _update_presets(); + if (presets.size()==10) + bt_add_preset->hide(); +} - html->set_text(color.to_html(edit_alpha && color.a<1)); +void ColorPicker::set_raw_mode(bool p_enabled) { - color_box->update(); - updating=false; + if (raw_mode_enabled==p_enabled) + return; + raw_mode_enabled=p_enabled; + if (btn_mode->is_pressed()!=p_enabled) + btn_mode->set_pressed(p_enabled); + + _update_controls(); + _update_color(); } -Color ColorPicker::get_color() const { +bool ColorPicker::is_raw_mode() const { - return color; + return raw_mode_enabled; } +void ColorPicker::_sample_draw() { + sample->draw_rect(Rect2(Point2(),Size2(256,20)),color); +} -void ColorPicker::set_mode(Mode p_mode) { +void ColorPicker::_hsv_draw(int p_wich,Control* c) +{ + if (!c) + return; + if (p_wich==0) { + int x=c->get_size().x*color.get_s(); + int y=c->get_size().y-c->get_size().y*color.get_v(); + c->draw_line(Point2(x,0),Point2(x,c->get_size().y),color.inverted()); + c->draw_line(Point2(0,y),Point2(c->get_size().x,y),color.inverted()); + c->draw_line(Point2(x,y),Point2(x,y),Color(1,1,1),2); + } else if (p_wich==1) { + int y=c->get_size().y-c->get_size().y*color.get_h(); + Color col=Color(); + col.set_hsv(color.get_h(),1,1); + c->draw_line(Point2(0,y),Point2(c->get_size().x,y),col.inverted()); + } +} - ERR_FAIL_INDEX(p_mode,3); - mode=p_mode; - if (mode_box->get_selected()!=p_mode) - mode_box->select(p_mode); +void ColorPicker::_uv_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed) { + changing_color = true; + float x = CLAMP((float)bev.x,0,256); + float y = CLAMP((float)bev.y,0,256); + s=x/256; + v=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } else { + changing_color = false; + } + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &bev = ev.mouse_motion; + if (!changing_color) + return; + float x = CLAMP((float)bev.x,0,256); + float y = CLAMP((float)bev.y,0,256); + s=x/256; + v=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } +} - _update_controls(); - _update_color(); +void ColorPicker::_w_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed) { + changing_color = true; + h=1-((float)bev.y)/256.0; + + } else { + changing_color = false; + } + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &bev = ev.mouse_motion; + if (!changing_color) + return; + float y = CLAMP((float)bev.y,0,256); + h=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } } -ColorPicker::Mode ColorPicker::get_mode() const { +void ColorPicker::_preset_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed && bev.button_index==BUTTON_LEFT) { + int index = bev.x/(preset->get_size().x/presets.size()); + set_color(presets[index]); + } else if (bev.pressed && bev.button_index==BUTTON_RIGHT) { + int index = bev.x/(preset->get_size().x/presets.size()); + presets.erase(presets[index]); + _update_presets(); + bt_add_preset->show(); + } + _update_color(); + emit_signal("color_changed", color); + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &mev = ev.mouse_motion; + int index = mev.x/(preset->get_size().x/presets.size()); + if (index<0 || index >= presets.size()) + return; + preset->set_tooltip("Color: #"+presets[index].to_html(presets[index].a<1)+"\n" + "LMB: Set color\n" + "RMB: Remove preset"); + } +} - return mode; +void ColorPicker::_screen_input(const InputEvent &ev) +{ + if (ev.type==InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.button_index==BUTTON_LEFT&&!bev.pressed) { + emit_signal("color_changed", color); + screen->hide(); + } + } else if (ev.type==InputEvent::MOUSE_MOTION) { + const InputEventMouse &mev = ev.mouse_motion; + Viewport *r=get_tree()->get_root(); + if (!r->get_rect().has_point(Point2(mev.global_x,mev.global_y))) + return; + Image img =r->get_screen_capture(); + if (!img.empty()) + last_capture=img; + r->queue_screen_capture(); + if (!last_capture.empty()) + set_color(last_capture.get_pixel(mev.global_x,mev.global_y)); + } } -void ColorPicker::_color_box_draw() { +void ColorPicker::_add_preset_pressed() { + add_preset(color); +} - color_box->draw_rect( Rect2( Point2(), color_box->get_size()), color); +void ColorPicker::_screen_pick_pressed() +{ + Viewport *r=get_tree()->get_root(); + if (!screen) { + screen=memnew( Control ); + r->add_child(screen); + screen->set_area_as_parent_rect(); + screen->connect("input_event",this,"_screen_input"); + } + screen->raise(); + screen->show(); + r->queue_screen_capture(); } void ColorPicker::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_color","color"),&ColorPicker::set_color); ObjectTypeDB::bind_method(_MD("get_color"),&ColorPicker::get_color); - ObjectTypeDB::bind_method(_MD("set_mode","mode"),&ColorPicker::set_mode); - ObjectTypeDB::bind_method(_MD("get_mode"),&ColorPicker::get_mode); + ObjectTypeDB::bind_method(_MD("set_raw_mode","mode"),&ColorPicker::set_raw_mode); + ObjectTypeDB::bind_method(_MD("is_raw_mode"),&ColorPicker::is_raw_mode); ObjectTypeDB::bind_method(_MD("set_edit_alpha","show"),&ColorPicker::set_edit_alpha); ObjectTypeDB::bind_method(_MD("is_editing_alpha"),&ColorPicker::is_editing_alpha); + ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset); ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed); ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered); - ObjectTypeDB::bind_method(_MD("_color_box_draw"),&ColorPicker::_color_box_draw); + ObjectTypeDB::bind_method(_MD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); + ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); + ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw); + ObjectTypeDB::bind_method(_MD("_hsv_draw"),&ColorPicker::_hsv_draw); + ObjectTypeDB::bind_method(_MD("_uv_input"),&ColorPicker::_uv_input); + ObjectTypeDB::bind_method(_MD("_w_input"),&ColorPicker::_w_input); + ObjectTypeDB::bind_method(_MD("_preset_input"),&ColorPicker::_preset_input); + ObjectTypeDB::bind_method(_MD("_screen_input"),&ColorPicker::_screen_input); ADD_SIGNAL( MethodInfo("color_changed",PropertyInfo(Variant::COLOR,"color"))); } +ColorPicker::ColorPicker() : + BoxContainer(true) { - - -ColorPicker::ColorPicker() { - - - //edit_alpha=false; updating=true; edit_alpha=true; + raw_mode_enabled=false; + changing_color=false; + screen=NULL; + + HBoxContainer *hb_smpl = memnew( HBoxContainer ); + btn_pick = memnew( ToolButton ); + btn_pick->connect("pressed",this,"_screen_pick_pressed"); + + sample = memnew( TextureFrame ); + sample->set_h_size_flags(SIZE_EXPAND_FILL); + sample->connect("draw",this,"_sample_draw"); + + hb_smpl->add_child(sample); + hb_smpl->add_child(btn_pick); + add_child(hb_smpl); + + HBoxContainer *hb_edit = memnew( HBoxContainer ); + + uv_edit= memnew ( TextureFrame ); + Image i(256, 256, false, Image::FORMAT_RGB); + for (int y=0;y<256;y++) + for (int x=0;x<256;x++) + i.put_pixel(x,y,Color()); + Ref<ImageTexture> t; + t.instance(); + t->create_from_image(i); + uv_edit->set_texture(t); + uv_edit->set_ignore_mouse(false); + uv_edit->set_custom_minimum_size(Size2(256,256)); + uv_edit->connect("input_event", this, "_uv_input"); + Control *c= memnew( Control ); + uv_edit->add_child(c); + c->set_area_as_parent_rect(); + c->set_stop_mouse(false); + c->set_material(memnew ( CanvasItemMaterial )); + Vector<Variant> args=Vector<Variant>(); + args.push_back(0); + args.push_back(c); + c->connect("draw",this,"_hsv_draw",args); + + add_child(hb_edit); + w_edit= memnew( TextureFrame ); + i = Image(15, 256, false, Image::FORMAT_RGB); + for (int y=0;y<256;y++) + for (int x=0;x<15;x++) + i.put_pixel(x,y,Color()); + Ref<ImageTexture> tw; + tw.instance(); + tw->create_from_image(i); + w_edit->set_texture(tw); + w_edit->set_ignore_mouse(false); + w_edit->set_custom_minimum_size(Size2(15,256)); + w_edit->connect("input_event", this, "_w_input"); + c= memnew( Control ); + w_edit->add_child(c); + c->set_area_as_parent_rect(); + c->set_stop_mouse(false); + c->set_material(memnew ( CanvasItemMaterial )); + args.clear(); + args.push_back(1); + args.push_back(c); + c->connect("draw",this,"_hsv_draw",args); + + hb_edit->add_child(uv_edit); + hb_edit->add_child(memnew( VSeparator )); + hb_edit->add_child(w_edit); VBoxContainer *vbl = memnew( VBoxContainer ); add_child(vbl); - mode_box = memnew( OptionButton ); - mode_box->add_item("RGB"); - mode_box->add_item("HSV"); - mode_box->add_item("RAW"); - mode_box->connect("item_selected",this,"set_mode"); - - color_box=memnew( Control ); - color_box->set_v_size_flags(SIZE_EXPAND_FILL); - vbl->add_child(color_box); - color_box->connect("draw",this,"_color_box_draw"); - - vbl->add_child(mode_box); - + add_child(memnew( HSeparator )); VBoxContainer *vbr = memnew( VBoxContainer ); add_child(vbr); vbr->set_h_size_flags(SIZE_EXPAND_FILL); - + const char* lt[4] = {"R","G","B","A"}; for(int i=0;i<4;i++) { HBoxContainer *hbc = memnew( HBoxContainer ); - labels[i]=memnew( Label ); + labels[i]=memnew( Label(lt[i]) ); hbc->add_child(labels[i]); scroll[i]=memnew( HSlider ); @@ -294,10 +481,14 @@ ColorPicker::ColorPicker() { vbr->add_child(hbc); - } HBoxContainer *hhb = memnew( HBoxContainer ); + + btn_mode = memnew( CheckButton ); + btn_mode->set_text("RAW Mode"); + btn_mode->connect("toggled", this, "set_raw_mode"); + hhb->add_child(btn_mode); vbr->add_child(hhb); html_num = memnew( Label ); hhb->add_child(html_num); @@ -309,11 +500,49 @@ ColorPicker::ColorPicker() { html->set_h_size_flags(SIZE_EXPAND_FILL); - mode=MODE_RGB; _update_controls(); _update_color(); updating=false; + uv_material.instance(); + Ref<Shader> s_uv = get_shader("uv_editor"); + uv_material->set_shader(s_uv); + + w_material.instance(); + + Ref<Shader> s_w = get_shader("w_editor"); + w_material->set_shader(s_w); + + uv_edit->set_material(uv_material); + w_edit->set_material(w_material); + + set_color(Color(1,1,1)); + + i.create(256,20,false,Image::FORMAT_RGB); + for (int y=0;y<20;y++) + for(int x=0;x<256;x++) + if ((x/4+y/4)%2) + i.put_pixel(x,y,Color(1,1,1)); + else + i.put_pixel(x,y,Color(0.6,0.6,0.6)); + Ref<ImageTexture> t_smpl; + t_smpl.instance(); + t_smpl->create_from_image(i); + sample->set_texture(t_smpl); + + HBoxContainer *bbc = memnew( HBoxContainer ); + add_child(bbc); + + preset = memnew( TextureFrame ); + bbc->add_child(preset); + preset->set_ignore_mouse(false); + preset->connect("input_event", this, "_preset_input"); + + bt_add_preset = memnew ( Button ); + bt_add_preset->set_icon(get_icon("add_preset")); + bt_add_preset->set_tooltip("Add current color as a preset"); + bt_add_preset->connect("pressed", this, "_add_preset_pressed"); + bbc->add_child(bt_add_preset); } @@ -331,7 +560,7 @@ void ColorPickerButton::_color_changed(const Color& p_color) { void ColorPickerButton::pressed() { - Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + Size2 ms = Size2(300, picker->get_combined_minimum_size().height+10); popup->set_pos(get_global_pos()-Size2(0,ms.height)); popup->set_size(ms); popup->popup(); @@ -347,7 +576,6 @@ void ColorPickerButton::_notification(int p_what) { } } - void ColorPickerButton::set_color(const Color& p_color){ diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 0756e88cf2..c6c7fe537d 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -36,25 +36,29 @@ #include "scene/gui/button.h" #include "scene/gui/popup.h" #include "scene/gui/box_container.h" -#include "scene/gui/option_button.h" +#include "scene/gui/texture_frame.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/check_button.h" +#include "scene/resources/material.h" -class ColorPicker : public HBoxContainer { +class ColorPicker : public BoxContainer { - OBJ_TYPE(ColorPicker,HBoxContainer); -public: + OBJ_TYPE(ColorPicker,BoxContainer); - enum Mode { - MODE_RGB, - MODE_HSV, - MODE_RAW - }; private: - Mode mode; - - OptionButton *mode_box; - - Control *color_box; + Control *screen; + Image last_capture; + TextureFrame *uv_edit; + TextureFrame *w_edit; + TextureFrame *sample; + TextureFrame *preset; + Button *bt_add_preset; + List<Color> presets; + ToolButton *btn_pick; + CheckButton *btn_mode; + Ref<CanvasItemMaterial> uv_material; + Ref<CanvasItemMaterial> w_material; HSlider *scroll[4]; SpinBox *values[4]; Label *labels[4]; @@ -64,13 +68,25 @@ private: Size2i ms; Color color; + bool raw_mode_enabled; bool updating; + bool changing_color; + float h,s,v; void _html_entered(const String& p_html); void _value_changed(double); void _update_controls(); void _update_color(); - void _color_box_draw(); + void _update_presets(); + void _sample_draw(); + void _hsv_draw(int p_wich,Control *c); + + void _uv_input(const InputEvent& p_input); + void _w_input(const InputEvent& p_input); + void _preset_input(const InputEvent& p_input); + void _screen_input(const InputEvent& p_input); + void _add_preset_pressed(); + void _screen_pick_pressed(); protected: void _notification(int); @@ -83,15 +99,14 @@ public: void set_color(const Color& p_color); Color get_color() const; - void set_mode(Mode p_mode); - Mode get_mode() const; + void add_preset(const Color& p_color); + void set_raw_mode(bool p_enabled); + bool is_raw_mode() const; ColorPicker(); }; -VARIANT_ENUM_CAST( ColorPicker::Mode ); - class ColorPickerButton : public Button { OBJ_TYPE(ColorPickerButton,Button); diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 6c74bc3977..920c6bf1e6 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -52,6 +52,14 @@ void Container::add_child_notify(Node *p_child) { } +void Container::move_child_notify(Node *p_child) { + + if (!p_child->cast_to<Control>()) + return; + + queue_sort(); +} + void Container::remove_child_notify(Node *p_child) { @@ -97,6 +105,8 @@ void Container::fit_child_in_rect(Control *p_child,const Rect2& p_rect) { p_child->set_pos(r.pos); p_child->set_size(r.size); + p_child->set_rotation(0); + p_child->set_scale(Vector2(1,1)); } void Container::queue_sort() { diff --git a/scene/gui/container.h b/scene/gui/container.h index ba9bf2d60f..1c7587c155 100644 --- a/scene/gui/container.h +++ b/scene/gui/container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,6 +42,7 @@ protected: void queue_sort(); virtual void add_child_notify(Node *p_child); + virtual void move_child_notify(Node *p_child); virtual void remove_child_notify(Node *p_child); void _notification(int p_what); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bd6b8078ff..71a0f50240 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,37 +42,6 @@ #include <stdio.h> -class TooltipPanel : public Panel { - - OBJ_TYPE(TooltipPanel,Panel) -public: - TooltipPanel() {}; - -}; - -class TooltipLabel : public Label { - - OBJ_TYPE(TooltipLabel,Label) -public: - TooltipLabel() {}; - -}; - -Control::Window::Window() { - - - mouse_focus=NULL; - mouse_focus_button=-1; - key_focus=NULL; - mouse_over=NULL; - disable_input=false; - - cancelled_input_ID=0; - tooltip=NULL; - tooltip_popup=NULL; - tooltip_label=NULL; - subwindow_order_dirty=false; -} Variant Control::edit_get_state() const { @@ -140,6 +109,11 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { data.icon_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); update(); + } else if (name.begins_with("custom_shaders/")) { + String dname = name.get_slicec('/',1); + data.shader_override.erase(dname); + notification(NOTIFICATION_THEME_CHANGED); + update(); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/',1); data.style_override.erase(dname); @@ -168,6 +142,10 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { String dname = name.get_slicec('/',1); notification(NOTIFICATION_THEME_CHANGED); add_icon_override(dname,p_value); + } else if (name.begins_with("custom_shaders/")) { + String dname = name.get_slicec('/',1); + add_shader_override(dname,p_value); + notification(NOTIFICATION_THEME_CHANGED); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/',1); add_style_override(dname,p_value); @@ -220,6 +198,10 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { String name = sname.get_slicec('/',1); r_ret= data.icon_override.has(name)?Variant(data.icon_override[name]):Variant(); + } else if (sname.begins_with("custom_shaders/")) { + String name = sname.get_slicec('/',1); + + r_ret= data.shader_override.has(name)?Variant(data.shader_override[name]):Variant(); } else if (sname.begins_with("custom_styles/")) { String name = sname.get_slicec('/',1); @@ -269,6 +251,18 @@ void Control::_get_property_list( List<PropertyInfo> *p_list) const { } { List<StringName> names; + theme->get_shader_list(get_type_name(),&names); + for(List<StringName>::Element *E=names.front();E;E=E->next()) { + + uint32_t hint= PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_CHECKABLE; + if (data.shader_override.has(E->get())) + hint|=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_CHECKED; + + p_list->push_back( PropertyInfo(Variant::OBJECT,"custom_shaders/"+E->get(),PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph",hint) ); + } + } + { + List<StringName> names; theme->get_stylebox_list(get_type_name(),&names); for(List<StringName>::Element *E=names.front();E;E=E->next()) { @@ -325,19 +319,6 @@ Control *Control::get_parent_control() const { return data.parent; } -void Control::_input_text(const String& p_text) { - - if (!window) - return; - if (window->key_focus) - window->key_focus->call("set_text",p_text); - -} - -void Control::_gui_input(const InputEvent& p_event) { - - _window_input_event(p_event); -} void Control::_resize(const Size2& p_size) { @@ -353,79 +334,12 @@ void Control::_notification(int p_notification) { case NOTIFICATION_ENTER_TREE: { - if (data.window==this) { - - window = memnew( Window ); - add_to_group("_vp_gui_input"+itos(get_viewport()->get_instance_ID())); - add_to_group("windows"); - - window->tooltip_timer = memnew( Timer ); - add_child(window->tooltip_timer); - window->tooltip_timer->force_parent_owned(); - window->tooltip_timer->set_wait_time( GLOBAL_DEF("display/tooltip_delay",0.7)); - window->tooltip_timer->connect("timeout",this,"_window_show_tooltip"); - window->tooltip=NULL; - window->tooltip_popup = memnew( TooltipPanel ); - add_child(window->tooltip_popup); - window->tooltip_popup->force_parent_owned(); - window->tooltip_label = memnew( TooltipLabel ); - window->tooltip_popup->add_child(window->tooltip_label); - window->tooltip_popup->set_as_toplevel(true); - window->tooltip_popup->hide(); - window->drag_attempted=false; - window->drag_preview=NULL; - - if (get_tree()->is_editor_hint()) { - - Node *n = this; - while(n) { - - if (n->has_meta("_editor_disable_input")) { - window->disable_input=true; - break; - } - n=n->get_parent(); - } - } - - } else { - window=NULL; - } - _size_changed(); } break; case NOTIFICATION_EXIT_TREE: { - if (data.window) { - - if (data.window->window->mouse_focus == this) - data.window->window->mouse_focus=NULL; - if (data.window->window->key_focus == this) - data.window->window->key_focus=NULL; - if (data.window->window->mouse_over == this) - data.window->window->mouse_over=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; - } - - if (window) { - - remove_from_group("_vp_gui_input"+itos(get_viewport()->get_instance_ID())); - remove_from_group("windows"); - if (window->tooltip_timer) - memdelete(window->tooltip_timer); - window->tooltip_timer=NULL; - window->tooltip=NULL; - if (window->tooltip_popup) - memdelete(window->tooltip_popup); - window->tooltip_popup=NULL; - - memdelete(window); - window=NULL; - - } - + get_viewport()->_gui_remove_control(this); } break; @@ -433,112 +347,94 @@ void Control::_notification(int p_notification) { case NOTIFICATION_ENTER_CANVAS: { - data.window=NULL; - data.viewport=NULL; - data.parent=NULL; - - Control *_window=this; - bool gap=false; - bool gap_valid=true; - bool window_found=false; + data.parent=get_parent()->cast_to<Control>(); - Node *parent=_window->get_parent(); - if (parent && parent->cast_to<Control>()) { + if (is_set_as_toplevel()) { + data.SI=get_viewport()->_gui_add_subwindow_control(this); + } else { - data.parent=parent->cast_to<Control>(); - } - Viewport *viewport=NULL; + Node *parent=this; //meh + Node *parent_control=NULL; + bool subwindow=false; - parent=this; //meh + while(parent) { - while(parent) { + parent=parent->get_parent(); - Control *c=parent->cast_to<Control>(); + if (!parent) + break; - if (!window_found && c) { - if (!gap && c!=this) { - gap_valid=false; + CanvasItem *ci =parent->cast_to<CanvasItem>(); + if (ci && ci->is_set_as_toplevel()) { + subwindow=true; + break; } - _window = c; - } - - CanvasItem *ci =parent->cast_to<CanvasItem>(); + if (parent->cast_to<Control>()) { + parent_control=parent->cast_to<Control>(); + break; + } else if (ci) { - if ((ci && ci->is_set_as_toplevel()) || !ci) { - gap=true; + } else { + break; + } } - if (parent->cast_to<CanvasLayer>()) { - window_found=true; //don't go beyond canvas layer - } - viewport =parent->cast_to<Viewport>(); - if (viewport) { - break; //no go beyond viewport either + if (parent_control) { + //do nothing, has a parent control + } else if (subwindow) { + //is a subwindow (process input before other controls for that canvas) + data.SI=get_viewport()->_gui_add_subwindow_control(this); + } else { + //is a regular root control + data.RI=get_viewport()->_gui_add_root_control(this); } - parent=parent->get_parent(); - } - - data.window=_window; - data.viewport=viewport; - data.parent_canvas_item=get_parent_item(); + data.parent_canvas_item=get_parent_item(); - if (data.parent_canvas_item) { - - data.parent_canvas_item->connect("item_rect_changed",this,"_size_changed"); - } else if (data.viewport) { - - //connect viewport - data.viewport->connect("size_changed",this,"_size_changed"); - } else { + if (data.parent_canvas_item) { + data.parent_canvas_item->connect("item_rect_changed",this,"_size_changed"); + } else { + //connect viewport + get_viewport()->connect("size_changed",this,"_size_changed"); + } } - if (gap && gap_valid && data.window!=this) { - //is a subwindow, conditions to meet subwindow status are quite complex.. - data.SI = data.window->window->subwindows.push_back(this); - data.window->window->subwindow_order_dirty=true; - - } - } break; case NOTIFICATION_EXIT_CANVAS: { - if (data.parent_canvas_item) { data.parent_canvas_item->disconnect("item_rect_changed",this,"_size_changed"); data.parent_canvas_item=NULL; - } else if (data.viewport) { - + } else if (!is_set_as_toplevel()) { //disconnect viewport - data.viewport->disconnect("size_changed",this,"_size_changed"); - } else { + get_viewport()->disconnect("size_changed",this,"_size_changed"); } if (data.MI) { - - if (data.window && data.window->window) - data.window->window->modal_stack.erase(data.MI); + get_viewport()->_gui_remove_modal_control(data.MI); data.MI=NULL; } if (data.SI) { - //erase from subwindows - if (data.window && data.window->window) - data.window->window->subwindows.erase(data.SI); + get_viewport()->_gui_remove_subwindow_control(data.SI); data.SI=NULL; } - data.viewport=NULL; - data.window=NULL; + if (data.RI) { + get_viewport()->_gui_remove_root_control(data.RI); + data.RI=NULL; + } + data.parent=NULL; + data.parent_canvas_item=NULL; } break; @@ -569,8 +465,11 @@ void Control::_notification(int p_notification) { data.parent->update(); update(); - if (data.SI && data.window) { - data.window->window->subwindow_order_dirty=true; + if (data.SI) { + get_viewport()->_gui_set_subwindow_order_dirty(); + } + if (data.RI) { + get_viewport()->_gui_set_root_order_dirty(); } } break; @@ -580,8 +479,8 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_DRAW: { - Matrix32 xform; - xform.set_origin(get_pos()); + Matrix32 xform=Matrix32(data.rotation,get_pos()); + xform.scale_basis(data.scale); VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),xform); VisualServer::get_singleton()->canvas_item_set_custom_rect( get_canvas_item(),true, Rect2(Point2(),get_size())); //emit_signal(SceneStringNames::get_singleton()->draw); @@ -610,30 +509,16 @@ void Control::_notification(int p_notification) { update(); } break; + case NOTIFICATION_MODAL_CLOSE: { + + emit_signal("modal_close"); + } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { - if (data.window->window->mouse_focus == this) { - data.window->window->mouse_focus=NULL; - } - if (data.window==this) { - window->drag_data=Variant(); - if (window->drag_preview) { - memdelete( window->drag_preview); - window->drag_preview=NULL; - } - } - - if (data.window->window->key_focus == this) - data.window->window->key_focus=NULL; - if (data.window->window->mouse_over == this) - data.window->window->mouse_over=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; + get_viewport()->_gui_hid_control(this); _modal_stack_remove(); minimum_size_changed(); @@ -647,10 +532,7 @@ void Control::_notification(int p_notification) { } break; case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: { - if (!window) - return; - if (window->key_focus) - window->key_focus->release_focus(); + get_viewport()->_gui_unfocus_control(this); } break; @@ -726,605 +608,30 @@ void Control::drop_data(const Point2& p_point,const Variant& p_data){ void Control::force_drag(const Variant& p_data,Control *p_control) { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); ERR_FAIL_COND(p_data.get_type()==Variant::NIL); + get_viewport()->_gui_force_drag(this,p_data,p_control); - - data.window->window->drag_data=p_data; - data.window->window->mouse_focus=NULL; - - if (p_control) { - data.window->set_drag_preview(p_control); - } } void Control::set_drag_preview(Control *p_control) { - ERR_FAIL_NULL(p_control); - ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); - ERR_FAIL_COND(!is_inside_tree() || !data.window); - ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent()!=NULL); - - if (data.window->window->drag_preview) { - memdelete(data.window->window->drag_preview); - } - p_control->set_as_toplevel(true); - p_control->set_pos(data.window->window->last_mouse_pos); - data.window->add_child(p_control); - if (data.window->window->drag_preview) { - memdelete( data.window->window->drag_preview ); - } - - data.window->window->drag_preview=p_control; - -} - - -Control* Control::_find_next_visible_control_at_pos(Node* p_node,const Point2& p_global,Matrix32& r_xform) const { - - return NULL; + ERR_FAIL_COND(!is_inside_tree()); + get_viewport()->_gui_set_drag_preview(this,p_control); } -Control* Control::_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform) { - - if (p_node->cast_to<Viewport>()) - return NULL; - - Control *c=p_node->cast_to<Control>(); - - if (c) { - // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); - } - - if (c==data.window) { - //try subwindows first!! - - c->_window_sort_subwindows(); // sort them - - for (List<Control*>::Element *E=c->window->subwindows.back();E;E=E->prev()) { - - Control *sw = E->get(); - if (!sw->is_visible()) - continue; - - Matrix32 xform; - CanvasItem *pci = sw->get_parent_item(); - if (pci) - xform=pci->get_global_transform(); - - Control *ret = _find_control_at_pos(sw,p_global,xform,r_inv_xform); - if (ret) - return ret; - - } - } - - if (p_node->is_hidden()) { - //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); - return NULL; //canvas item hidden, discard - } - - Matrix32 matrix = p_xform * p_node->get_transform(); - - if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { - - for(int i=p_node->get_child_count()-1;i>=0;i--) { - - if (p_node==data.window->window->tooltip_popup) - continue; - - CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); - if (!ci || ci->is_set_as_toplevel()) - continue; - - Control *ret=_find_control_at_pos(ci,p_global,matrix,r_inv_xform);; - if (ret) - return ret; - } - } - - if (!c) - return NULL; - - matrix.affine_invert(); - - //conditions for considering this as a valid control for return - if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!window->drag_preview || (c!=window->drag_preview && !window->drag_preview->is_a_parent_of(c)))) { - r_inv_xform=matrix; - return c; - } else - return NULL; -} - -void Control::_window_cancel_input_ID(int p_input) { - window->cancelled_input_ID=(unsigned int)p_input; -} - -void Control::_window_remove_focus() { - - if (window->key_focus) { - Node *f=window->key_focus; - window->key_focus=NULL; - f->notification( NOTIFICATION_FOCUS_EXIT,true ); - - } -} -bool Control::window_has_modal_stack() const { +bool Control::is_window_modal_on_top() const { - if (!data.window) + if (!is_inside_tree()) return false; - return data.window->window->modal_stack.size(); -} - -void Control::_window_cancel_tooltip() { - - window->tooltip=NULL; - if (window->tooltip_timer) - window->tooltip_timer->stop(); - if (window->tooltip_popup) - window->tooltip_popup->hide(); - -} - -void Control::_window_show_tooltip() { - - if (!window->tooltip) { - return; - } - - String tooltip = window->tooltip->get_tooltip( window->tooltip->get_global_transform().xform_inv(window->tooltip_pos) ); - if (tooltip.length()==0) - return; // bye - - - if (!window->tooltip_label) { - return; - } - Ref<StyleBox> ttp = get_stylebox("panel","TooltipPanel"); - - window->tooltip_label->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); - window->tooltip_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); - window->tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); - window->tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); - window->tooltip_label->set_text(tooltip); - Rect2 r(window->tooltip_pos+Point2(10,10),window->tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); - Rect2 vr = get_viewport_rect(); - if (r.size.x+r.pos.x>vr.size.x) - r.pos.x=vr.size.x-r.size.x; - else if (r.pos.x<0) - r.pos.x=0; - - if (r.size.y+r.pos.y>vr.size.y) - r.pos.y=vr.size.y-r.size.y; - else if (r.pos.y<0) - r.pos.y=0; - - window->tooltip_popup->set_pos(r.pos); - window->tooltip_popup->set_size(r.size); - - window->tooltip_popup->raise(); - - window->tooltip_popup->show(); -} - - -void Control::_window_call_input(Control *p_control,const InputEvent& p_input) { - - - while(p_control) { - - p_control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); - if (window->key_event_accepted) - break; - p_control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); - if (p_control->is_set_as_toplevel()) { - break; - } - if (window->key_event_accepted) - break; - if (p_control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) - break; - p_control=p_control->data.parent; - } -} - -void Control::_window_input_event(InputEvent p_event) { - - - - if (!window) - return; - - if (window->disable_input) - return; - - if (p_event.ID==window->cancelled_input_ID) { - return; - } - if (!is_visible()) { - return; //simple and plain - } - switch(p_event.type) { - - case InputEvent::MOUSE_BUTTON: { - - - window->key_event_accepted=false; - - Point2 mpos =(get_canvas_transform()).affine_inverse().xform(Point2(p_event.mouse_button.x,p_event.mouse_button.y)); - if (p_event.mouse_button.pressed) { - - - - Size2 pos = mpos; - if (window->mouse_focus && p_event.mouse_button.button_index!=window->mouse_focus_button) { - - //do not steal mouse focus and stuff - - } else { - - - _window_sort_modal_stack(); - while (!window->modal_stack.empty()) { - - Control *top = window->modal_stack.back()->get(); - if (!top->has_point(top->get_global_transform().affine_inverse().xform(pos))) { - - if (top->data.modal_exclusive) { - //cancel event, sorry, modal exclusive EATS UP ALL - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - return; // no one gets the event if exclusive NO ONE - } - - top->notification(NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - } else { - break; - } - } - - - - Matrix32 parent_xform; - - if (data.parent_canvas_item) - parent_xform=data.parent_canvas_item->get_global_transform(); - - - - window->mouse_focus = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform); - //print_line("has mf "+itos(window->mouse_focus!=NULL)); - window->mouse_focus_button=p_event.mouse_button.button_index; - - if (!window->mouse_focus) { - break; - } - - if (p_event.mouse_button.button_index==BUTTON_LEFT) { - window->drag_accum=Vector2(); - window->drag_attempted=false; - window->drag_data=Variant(); - } - - - } - - p_event.mouse_button.global_x = pos.x; - p_event.mouse_button.global_y = pos.y; - - pos = window->focus_inv_xform.xform(pos); - p_event.mouse_button.x = pos.x; - p_event.mouse_button.y = pos.y; - -#ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { - - Array arr; - arr.push_back(window->mouse_focus->get_path()); - arr.push_back(window->mouse_focus->get_type()); - ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); - } - - /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { - - print_line(String(window->mouse_focus->get_path())+" - "+pos); - }*/ -#endif - - if (window->mouse_focus->get_focus_mode()!=FOCUS_NONE && window->mouse_focus!=window->key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { - // also get keyboard focus - window->mouse_focus->grab_focus(); - } - - - if (window->mouse_focus->can_process()) { - _window_call_input(window->mouse_focus,p_event); - } - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - window->tooltip_popup->hide(); - - } else { - - if (window->drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { - memdelete( window->drag_preview ); - window->drag_preview=NULL; - } - - if (!window->mouse_focus) { - - if (window->mouse_over && window->drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { - - Size2 pos = mpos; - pos = window->focus_inv_xform.xform(pos); - window->mouse_over->drop_data(pos,window->drag_data); - window->drag_data=Variant(); - //change mouse accordingly - } - - break; - } - - Size2 pos = mpos; - p_event.mouse_button.global_x = pos.x; - p_event.mouse_button.global_y = pos.y; - pos = window->focus_inv_xform.xform(pos); - p_event.mouse_button.x = pos.x; - p_event.mouse_button.y = pos.y; - - if (window->mouse_focus->can_process()) { - _window_call_input(window->mouse_focus,p_event); - } - - if (p_event.mouse_button.button_index==window->mouse_focus_button) { - window->mouse_focus=NULL; - window->mouse_focus_button=-1; - } - - if (window->drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { - window->drag_data=Variant(); //always clear - } - - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - } - } break; - case InputEvent::MOUSE_MOTION: { - window->key_event_accepted=false; - - Matrix32 localizer = (get_canvas_transform()).affine_inverse(); - Size2 pos = localizer.xform(Size2(p_event.mouse_motion.x,p_event.mouse_motion.y)); - Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); - Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); - - window->last_mouse_pos=pos; - - Control *over = NULL; - - Matrix32 parent_xform; - if (data.parent_canvas_item) - parent_xform=data.parent_canvas_item->get_global_transform(); - - // D&D - if (!window->drag_attempted && window->mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - window->drag_accum+=rel; - float len = window->drag_accum.length(); - if (len>10) { - window->drag_data=window->mouse_focus->get_drag_data(window->focus_inv_xform.xform(pos)-window->drag_accum); - if (window->drag_data.get_type()!=Variant::NIL) { - - window->mouse_focus=NULL; - } - window->drag_attempted=true; - } - } - - - if (window->mouse_focus) { - over=window->mouse_focus; - //recompute focus_inv_xform again here - - } else { - - over = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform); - } - - - if (window->drag_data.get_type()==Variant::NIL && over && !window->modal_stack.empty()) { - - Control *top = window->modal_stack.back()->get(); - if (over!=top && !top->is_a_parent_of(over)) { - - break; // don't send motion event to anything below modal stack top - } - } - - if (over!=window->mouse_over) { - - if (window->mouse_over) - window->mouse_over->notification(NOTIFICATION_MOUSE_EXIT); - - if (over) - over->notification(NOTIFICATION_MOUSE_ENTER); - - } - - window->mouse_over=over; - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_tooltip"); - - if (window->drag_preview) { - window->drag_preview->set_pos(pos); - } - - if (!over) { - OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW); - break; - } - - p_event.mouse_motion.global_x = pos.x; - p_event.mouse_motion.global_y = pos.y; - p_event.mouse_motion.speed_x=speed.x; - p_event.mouse_motion.speed_y=speed.y; - p_event.mouse_motion.relative_x=rel.x; - p_event.mouse_motion.relative_y=rel.y; - - if (p_event.mouse_motion.button_mask==0 && window->tooltip_timer) { - //nothing pressed - - bool can_tooltip=true; - - if (!window->modal_stack.empty()) { - if (window->modal_stack.back()->get()!=over && !window->modal_stack.back()->get()->is_a_parent_of(over)) - can_tooltip=false; - - } - - - if (can_tooltip) { - - window->tooltip=over; - window->tooltip_pos=(parent_xform * get_transform()).affine_inverse().xform(pos); - window->tooltip_timer->start(); - } - } - - - pos = window->focus_inv_xform.xform(pos); - - - p_event.mouse_motion.x = pos.x; - p_event.mouse_motion.y = pos.y; - - - CursorShape cursor_shape = over->get_cursor_shape(pos); - OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); - - - if (over->can_process()) { - _window_call_input(over,p_event); - } - - - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - - if (window->drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - /*bool can_drop =*/ over->can_drop_data(pos,window->drag_data); - //change mouse accordingly i guess - } - - } break; - case InputEvent::ACTION: - case InputEvent::JOYSTICK_BUTTON: - case InputEvent::KEY: { - - if (window->key_focus) { - - window->key_event_accepted=false; - if (window->key_focus->can_process()) { - window->key_focus->call_multilevel("_input_event",p_event); - if (window->key_focus) //maybe lost it - window->key_focus->emit_signal(SceneStringNames::get_singleton()->input_event,p_event); - } - - - if (window->key_event_accepted) { - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - break; - } - } - - - if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !window->modal_stack.empty()) { - - _window_sort_modal_stack(); - Control *top = window->modal_stack.back()->get(); - if (!top->data.modal_exclusive) { - - top->notification(NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - } - } - - - Control * from = window->key_focus ? window->key_focus : NULL; //hmm - - //keyboard focus - //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { - - if (from && p_event.is_pressed()) { - Control * next=NULL; - - if (p_event.is_action("ui_focus_next")) { - - next = from->find_next_valid_focus(); - } - - if (p_event.is_action("ui_focus_prev")) { - - next = from->find_prev_valid_focus(); - } - - if (p_event.is_action("ui_up")) { - - next = from->_get_focus_neighbour(MARGIN_TOP); - } - - if (p_event.is_action("ui_left")) { - - next = from->_get_focus_neighbour(MARGIN_LEFT); - } - - if (p_event.is_action("ui_right")) { - - next = from->_get_focus_neighbour(MARGIN_RIGHT); - } - - if (p_event.is_action("ui_down")) { - - next = from->_get_focus_neighbour(MARGIN_BOTTOM); - } - - - if (next) { - next->grab_focus(); - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - } - } - - } break; - } + return get_viewport()->_gui_is_modal_on_top(this); } -Control *Control::get_window() const { - - return data.window; -} - -bool Control::is_window() const { - - return (is_inside_tree() && window); -} Size2 Control::get_minimum_size() const { @@ -1372,6 +679,35 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type } +Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_type) const { + if (p_type==StringName()) { + + const Ref<Shader>* sdr = data.shader_override.getptr(p_name); + if (sdr) + return *sdr; + } + + StringName type = p_type?p_type:get_type_name(); + + // try with custom themes + Control *theme_owner = data.theme_owner; + + while(theme_owner) { + + if (theme_owner->data.theme->has_shader(p_name, type)) + return data.theme_owner->data.theme->get_shader(p_name, type ); + Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL; + + if (parent) + theme_owner=parent->data.theme_owner; + else + theme_owner=NULL; + + } + + return Theme::get_default()->get_shader( p_name, type ); +} + Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { if (p_type==StringName()) { @@ -1518,7 +854,37 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } return Theme::get_default()->has_icon( p_name, type ); + +} + +bool Control::has_shader(const StringName &p_name, const StringName &p_type) const +{ + if (p_type==StringName()) { + const Ref<Shader>* sdr = data.shader_override.getptr(p_name); + if (sdr) + return true; + } + + StringName type = p_type?p_type:get_type_name(); + + // try with custom themes + Control *theme_owner = data.theme_owner; + while(theme_owner) { + + if (theme_owner->data.theme->has_shader(p_name, type)) + return true; + Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL; + + if (parent) + theme_owner=parent->data.theme_owner; + else + theme_owner=NULL; + + } + + return Theme::get_default()->has_shader( p_name, type ); + } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { @@ -1650,9 +1016,9 @@ Size2 Control::get_parent_area_size() const { if (data.parent_canvas_item) { parent_size=data.parent_canvas_item->get_item_rect().size; - } else if (data.viewport) { + } else { - parent_size=data.viewport->get_visible_rect().size; + parent_size=get_viewport()->get_visible_rect().size; } return parent_size; @@ -1720,8 +1086,8 @@ float Control::_get_parent_range(int p_idx) const { } if (data.parent_canvas_item) { return data.parent_canvas_item->get_item_rect().size[p_idx&1]; - } else if (data.viewport) { - return data.viewport->get_visible_rect().size[p_idx&1]; + } else { + return get_viewport()->get_visible_rect().size[p_idx&1]; } return 1.0; @@ -1927,6 +1293,7 @@ void Control::set_size(const Size2& p_size) { data.margin[3] = _s2a( y+h, data.anchor[3], ph ); _size_changed(); + } @@ -1946,10 +1313,9 @@ Rect2 Control::get_global_rect() const { } Rect2 Control::get_window_rect() const { - + ERR_FAIL_COND_V(!is_inside_tree(),Rect2()); Rect2 gr = get_global_rect(); - if (data.viewport) - gr.pos+=data.viewport->get_visible_rect().pos; + gr.pos+=get_viewport()->get_visible_rect().pos; return gr; } @@ -1983,7 +1349,14 @@ void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_ data.icon_override[p_name]=p_icon; notification(NOTIFICATION_THEME_CHANGED); update(); + +} +void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { + ERR_FAIL_COND(p_shader.is_null()); + data.shader_override[p_name]=p_shader; + notification(NOTIFICATION_THEME_CHANGED); + update(); } void Control::add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style) { @@ -2091,7 +1464,17 @@ Control *Control::find_next_valid_focus() const { } if (!next_child) { - next_child=get_window(); + + next_child=const_cast<Control*>(this);; + while(next_child) { + + if (next_child->data.SI || next_child->data.RI) + break; + next_child=next_child->get_parent_control(); + + } + + } } @@ -2209,128 +1592,69 @@ Control::FocusMode Control::get_focus_mode() const { } bool Control::has_focus() const { - return (data.window && data.window->window->key_focus==this); + return is_inside_tree() && get_viewport()->_gui_control_has_focus(this); } void Control::grab_focus() { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); - if (data.focus_mode==FOCUS_NONE) return; - - //no need for change - if (data.window->window->key_focus && data.window->window->key_focus==this) - return; - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); - data.window->window->key_focus=this; - notification(NOTIFICATION_FOCUS_ENTER); -#ifdef DEBUG_ENABLED - if (GLOBAL_DEF("debug/print_clicked_control", false)) { - print_line(String(get_path())+" - focus"); - }; -#endif - update(); + + get_viewport()->_gui_control_grab_focus(this); } void Control::release_focus() { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); if (!has_focus()) return; - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); - //data.window->window->key_focus=this; - //notification(NOTIFICATION_FOCUS_ENTER); + get_viewport()->_gui_remove_focus(); update(); } bool Control::is_toplevel_control() const { - return is_inside_tree() && (!data.parent_canvas_item && !window && is_set_as_toplevel()); + return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel()); } void Control::show_modal(bool p_exclusive) { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.SI && data.window!=this); - ERR_FAIL_COND(!data.window); + ERR_FAIL_COND(!data.SI); if (is_visible()) hide(); - ERR_FAIL_COND( data.MI ); + ERR_FAIL_COND( data.MI!=NULL ); show(); raise(); - - data.window->window->modal_stack.push_back(this); - data.MI = data.window->window->modal_stack.back(); data.modal_exclusive=p_exclusive; - if (data.window->window->key_focus) - data.modal_prev_focus_owner = data.window->window->key_focus->get_instance_ID(); - else - data.modal_prev_focus_owner=0; + data.MI=get_viewport()->_gui_show_modal(this); } -void Control::_window_sort_subwindows() { - - if (!window->subwindow_order_dirty) - return; - - - window->modal_stack.sort_custom<CComparator>(); - window->subwindows.sort_custom<CComparator>(); - - window->subwindow_order_dirty=false; - -} - -void Control::_window_sort_modal_stack() { - - window->modal_stack.sort_custom<CComparator>(); +void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { + data.modal_prev_focus_owner=p_prev; } void Control::_modal_stack_remove() { - List<Control*>::Element *next=NULL; //transfer the focus stack to the next - - - if (data.window && data.MI) { - - next = data.MI->next(); - - - data.window->window->modal_stack.erase(data.MI); - data.MI=NULL; - } - - if (data.modal_prev_focus_owner) { - - if (!next) { //top of stack + ERR_FAIL_COND(!is_inside_tree()); - Object *pfo = ObjectDB::get_instance(data.modal_prev_focus_owner); - Control *pfoc = pfo->cast_to<Control>(); - if (!pfoc) - return; + if (!data.MI) + return; - if (!pfoc->is_inside_tree() || !pfoc->is_visible()) - return; - pfoc->grab_focus(); - } else { + get_viewport()->_gui_remove_from_modal_stack(data.MI,data.modal_prev_focus_owner); - next->get()->data.modal_prev_focus_owner=data.modal_prev_focus_owner; - } + data.MI=NULL; + data.modal_prev_focus_owner=0; - data.modal_prev_focus_owner=0; - } } void Control::_propagate_theme_changed(Control *p_owner) { @@ -2368,17 +1692,11 @@ void Control::set_theme(const Ref<Theme>& p_theme) { } -void Control::_window_accept_event() { +void Control::accept_event() { - window->key_event_accepted=true; if (is_inside_tree()) - get_tree()->set_input_as_handled(); - -} -void Control::accept_event() { + get_viewport()->_gui_accept_event(); - if (is_inside_tree() && get_window()) - get_window()->_window_accept_event(); } @@ -2412,9 +1730,9 @@ Control::CursorShape Control::get_cursor_shape(const Point2& p_pos) const { Matrix32 Control::get_transform() const { - Matrix32 xf; - xf.set_origin(get_pos()); - return xf; + Matrix32 xform=Matrix32(data.rotation,get_pos()); + xform.scale_basis(data.scale); + return xform; } String Control::_get_tooltip() const { @@ -2507,7 +1825,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin,int p_count) { if (c) { if (c->data.SI) break; - if (c==data.window) + if (c->data.RI) break; } base=base->get_parent(); @@ -2626,35 +1944,8 @@ void Control::grab_click_focus() { ERR_FAIL_COND(!is_inside_tree()); - if (data.window && data.window->window->mouse_focus) { - - Window *w=data.window->window; - if (w->mouse_focus==this) - return; - InputEvent ie; - ie.type=InputEvent::MOUSE_BUTTON; - InputEventMouseButton &mb=ie.mouse_button; - - //send unclic + get_viewport()->_gui_grab_click_focus(this); - Point2 click =w->mouse_focus->get_global_transform().affine_inverse().xform(w->last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=w->mouse_focus_button; - mb.pressed=false; - w->mouse_focus->call_deferred("_input_event",ie); - - - w->mouse_focus=this; - w->focus_inv_xform=w->mouse_focus->get_global_transform().affine_inverse(); - click =w->mouse_focus->get_global_transform().affine_inverse().xform(w->last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=w->mouse_focus_button; - mb.pressed=true; - w->mouse_focus->call_deferred("_input_event",ie); - - } } void Control::minimum_size_changed() { @@ -2703,8 +1994,7 @@ bool Control::is_stopping_mouse() const { Control *Control::get_focus_owner() const { ERR_FAIL_COND_V(!is_inside_tree(),NULL); - ERR_FAIL_COND_V(!data.window,NULL); - return data.window->window->key_focus; + return get_viewport()->_gui_get_focus_owner(); } @@ -2728,24 +2018,71 @@ bool Control::is_text_field() const { return false; } + +void Control::_set_rotation_deg(float p_rot) { + set_rotation(Math::deg2rad(p_rot)); +} + +float Control::_get_rotation_deg() const { + return Math::rad2deg(get_rotation()); +} + +void Control::set_rotation(float p_rotation) { + + data.rotation=p_rotation; + update(); + _notify_transform(); +} + +float Control::get_rotation() const{ + + return data.rotation; +} + +void Control::set_scale(const Vector2& p_scale){ + + data.scale=p_scale; + update(); + _notify_transform(); +} +Vector2 Control::get_scale() const{ + + return data.scale; +} + +Control *Control::get_root_parent_control() const { + + const CanvasItem *ci=this; + const Control *root=this; + + while(ci) { + + const Control *c = ci->cast_to<Control>(); + if (c) { + root=c; + + if (c->data.RI || c->data.MI || c->is_toplevel_control()) + break; + } + + ci=ci->get_parent_item(); + } + + return const_cast<Control*>(root); +} + + + void Control::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_window_input_event"),&Control::_window_input_event); - ObjectTypeDB::bind_method(_MD("_gui_input"),&Control::_gui_input); - ObjectTypeDB::bind_method(_MD("_input_text"),&Control::_input_text); + // ObjectTypeDB::bind_method(_MD("_window_resize_event"),&Control::_window_resize_event); - ObjectTypeDB::bind_method(_MD("_window_remove_focus"),&Control::_window_remove_focus); - ObjectTypeDB::bind_method(_MD("_cancel_input_ID"),&Control::_window_cancel_input_ID); - ObjectTypeDB::bind_method(_MD("_cancel_tooltip"),&Control::_window_cancel_tooltip); - ObjectTypeDB::bind_method(_MD("_window_show_tooltip"),&Control::_window_show_tooltip); ObjectTypeDB::bind_method(_MD("_size_changed"),&Control::_size_changed); ObjectTypeDB::bind_method(_MD("_update_minimum_size"),&Control::_update_minimum_size); ObjectTypeDB::bind_method(_MD("accept_event"),&Control::accept_event); ObjectTypeDB::bind_method(_MD("get_minimum_size"),&Control::get_minimum_size); ObjectTypeDB::bind_method(_MD("get_combined_minimum_size"),&Control::get_combined_minimum_size); - ObjectTypeDB::bind_method(_MD("is_window"),&Control::is_window); - ObjectTypeDB::bind_method(_MD("get_window"),&Control::get_window); ObjectTypeDB::bind_method(_MD("set_anchor","margin","anchor_mode"),&Control::set_anchor); ObjectTypeDB::bind_method(_MD("get_anchor","margin"),&Control::get_anchor); ObjectTypeDB::bind_method(_MD("set_margin","margin","offset"),&Control::set_margin); @@ -2756,15 +2093,21 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_size","size"),&Control::set_size); ObjectTypeDB::bind_method(_MD("set_custom_minimum_size","size"),&Control::set_custom_minimum_size); ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Control::set_global_pos); + ObjectTypeDB::bind_method(_MD("set_rotation","rotation"),&Control::set_rotation); + ObjectTypeDB::bind_method(_MD("_set_rotation_deg","rotation"),&Control::_set_rotation_deg); + ObjectTypeDB::bind_method(_MD("set_scale","scale"),&Control::set_scale); ObjectTypeDB::bind_method(_MD("get_margin","margin"),&Control::get_margin); ObjectTypeDB::bind_method(_MD("get_begin"),&Control::get_begin); ObjectTypeDB::bind_method(_MD("get_end"),&Control::get_end); ObjectTypeDB::bind_method(_MD("get_pos"),&Control::get_pos); ObjectTypeDB::bind_method(_MD("get_size"),&Control::get_size); + ObjectTypeDB::bind_method(_MD("get_rotation"),&Control::get_rotation); + ObjectTypeDB::bind_method(_MD("get_scale"),&Control::get_scale); ObjectTypeDB::bind_method(_MD("get_custom_minimum_size"),&Control::get_custom_minimum_size); ObjectTypeDB::bind_method(_MD("get_parent_area_size"),&Control::get_size); ObjectTypeDB::bind_method(_MD("get_global_pos"),&Control::get_global_pos); ObjectTypeDB::bind_method(_MD("get_rect"),&Control::get_rect); + ObjectTypeDB::bind_method(_MD("_get_rotation_deg"),&Control::_get_rotation_deg); ObjectTypeDB::bind_method(_MD("get_global_rect"),&Control::get_global_rect); ObjectTypeDB::bind_method(_MD("set_area_as_parent_rect","margin"),&Control::set_area_as_parent_rect,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("show_modal","exclusive"),&Control::show_modal,DEFVAL(false)); @@ -2785,8 +2128,9 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_theme","theme:Theme"),&Control::set_theme); ObjectTypeDB::bind_method(_MD("get_theme:Theme"),&Control::get_theme); - + ObjectTypeDB::bind_method(_MD("add_icon_override","name","texture:Texture"),&Control::add_icon_override); + ObjectTypeDB::bind_method(_MD("add_shader_override","name","shader:Shader"),&Control::add_shader_override); ObjectTypeDB::bind_method(_MD("add_style_override","name","stylebox:StyleBox"),&Control::add_style_override); ObjectTypeDB::bind_method(_MD("add_font_override","name","font:Font"),&Control::add_font_override); ObjectTypeDB::bind_method(_MD("add_color_override","name","color"),&Control::add_color_override); @@ -2846,6 +2190,8 @@ void Control::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/pos", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_EDITOR), _SCS("set_pos"),_SCS("get_pos") ); ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/size", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_EDITOR), _SCS("set_size"),_SCS("get_size") ); ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/min_size"), _SCS("set_custom_minimum_size"),_SCS("get_custom_minimum_size") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"rect/rotation",PROPERTY_HINT_RANGE,"-1080,1080,0.01"), _SCS("_set_rotation_deg"),_SCS("_get_rotation_deg") ); + ADD_PROPERTYNO( PropertyInfo(Variant::VECTOR2,"rect/scale"), _SCS("set_scale"),_SCS("get_scale") ); ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"hint/tooltip", PROPERTY_HINT_MULTILINE_TEXT), _SCS("set_tooltip"),_SCS("_get_tooltip") ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour/left" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_LEFT ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour/top" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_TOP ); @@ -2906,20 +2252,21 @@ void Control::_bind_methods() { ADD_SIGNAL( MethodInfo("focus_exit") ); ADD_SIGNAL( MethodInfo("size_flags_changed") ); ADD_SIGNAL( MethodInfo("minimum_size_changed") ); + ADD_SIGNAL( MethodInfo("modal_close") ); } Control::Control() { - data.parent=NULL; - data.window=NULL; - data.viewport=NULL; + data.parent=NULL; + data.ignore_mouse=false; data.stop_mouse=true; - window=NULL; + data.SI=NULL; data.MI=NULL; + data.RI=NULL; data.modal=false; data.theme_owner=NULL; data.modal_exclusive=false; @@ -2928,6 +2275,9 @@ Control::Control() { data.v_size_flags=SIZE_FILL; data.expand=1; data.pending_min_size_update=false; + data.rotation=0; + data.parent_canvas_item=NULL; + data.scale=Vector2(1,1); for (int i=0;i<4;i++) { diff --git a/scene/gui/control.h b/scene/gui/control.h index 4311b299c8..74d40b7579 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -97,7 +97,12 @@ private: struct CComparator { - bool operator()(const Control* p_a, const Control* p_b) const { return p_b->is_greater_than(p_a); } + bool operator()(const Control* p_a, const Control* p_b) const { + if (p_a->get_canvas_layer()==p_b->get_canvas_layer()) + return p_b->is_greater_than(p_a); + else + return p_a->get_canvas_layer() < p_b->get_canvas_layer(); + } }; struct Data { @@ -107,7 +112,10 @@ private: float margin[4]; AnchorType anchor[4]; - FocusMode focus_mode; + FocusMode focus_mode; + + float rotation; + Vector2 scale; bool pending_resize; @@ -121,7 +129,6 @@ private: bool stop_mouse; Control *parent; - Control *window; bool modal; bool modal_exclusive; Ref<Theme> theme; @@ -131,91 +138,55 @@ private: List<Control*>::Element *MI; //modal item List<Control*>::Element *SI; + List<Control*>::Element *RI; CanvasItem *parent_canvas_item; - Viewport *viewport; - ObjectID modal_prev_focus_owner; NodePath focus_neighbour[4]; HashMap<StringName, Ref<Texture>, StringNameHasher > icon_override; + HashMap<StringName, Ref<Shader>, StringNameHasher > shader_override; HashMap<StringName, Ref<StyleBox>, StringNameHasher > style_override; HashMap<StringName, Ref<Font>, StringNameHasher > font_override; HashMap<StringName, Color, StringNameHasher > color_override; HashMap<StringName, int, StringNameHasher > constant_override; } data; - - struct Window { - // info used when this is a window - - bool key_event_accepted; - Control *mouse_focus; - int mouse_focus_button; - Control *key_focus; - Control *mouse_over; - Control *tooltip; - Panel *tooltip_popup; - Label *tooltip_label; - Point2 tooltip_pos; - Point2 last_mouse_pos; - Point2 drag_accum; - bool drag_attempted; - Variant drag_data; - Control *drag_preview; - Timer *tooltip_timer; - List<Control*> modal_stack; - unsigned int cancelled_input_ID; - Matrix32 focus_inv_xform; - bool subwindow_order_dirty; - List<Control*> subwindows; - bool disable_input; - - Window(); - }; - - Window *window; - + // used internally - Control* _find_next_visible_control_at_pos(Node* p_node,const Point2& p_global,Matrix32& r_xform) const; Control* _find_control_at_pos(CanvasItem* p_node,const Point2& p_pos,const Matrix32& p_xform,Matrix32& r_inv_xform); - void _window_sort_subwindows(); - void _window_accept_event(); - void _window_remove_focus(); - void _window_cancel_input_ID(int p_input); - void _window_sort_modal_stack(); void _window_find_focus_neighbour(const Vector2& p_dir, Node *p_at, const Point2* p_points ,float p_min,float &r_closest_dist,Control **r_closest); Control *_get_focus_neighbour(Margin p_margin,int p_count=0); - void _window_call_input(Control *p_control,const InputEvent& p_input); + float _get_parent_range(int p_idx) const; float _get_range(int p_idx) const; float _s2a(float p_val, AnchorType p_anchor,float p_range) const; float _a2s(float p_val, AnchorType p_anchor,float p_range) const; - void _modal_stack_remove(); void _propagate_theme_changed(Control *p_owner); void _change_notify_margins(); - void _window_cancel_tooltip(); - void _window_show_tooltip(); void _update_minimum_size(); void _update_scroll(); - void _gui_input(const InputEvent& p_event); //used by scene main loop - void _input_text(const String& p_text); void _resize(const Size2& p_size); void _size_changed(); String _get_tooltip() const; + void _set_rotation_deg(float p_rot); + float _get_rotation_deg() const; + +friend class Viewport; + void _modal_stack_remove(); + void _modal_set_prev_focus_owner(ObjectID p_prev); protected: - bool window_has_modal_stack() const; - virtual void _window_input_event(InputEvent p_event); + //virtual void _window_input_event(InputEvent p_event); bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; @@ -265,8 +236,8 @@ public: void set_custom_minimum_size(const Size2& p_custom); Size2 get_custom_minimum_size() const; - bool is_window() const; - Control *get_window() const; + bool is_window_modal_on_top() const; + Control *get_parent_control() const; @@ -299,6 +270,13 @@ public: Rect2 get_rect() const; Rect2 get_global_rect() const; Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server + + void set_rotation(float p_rotation); + float get_rotation() const; + + void set_scale(const Vector2& p_scale); + Vector2 get_scale() const; + void set_area_as_parent_rect(int p_margin=0); @@ -343,18 +321,21 @@ public: /* SKINNING */ void add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon); + void add_shader_override(const StringName& p_name, const Ref<Shader>& p_shader); void add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style); void add_font_override(const StringName& p_name, const Ref<Font>& p_font); void add_color_override(const StringName& p_name, const Color& p_color); void add_constant_override(const StringName& p_name, int p_constant); Ref<Texture> get_icon(const StringName& p_name,const StringName& p_type=StringName()) const; + Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type=StringName()) const; Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const; Ref<Font> get_font(const StringName& p_name,const StringName& p_type=StringName()) const; Color get_color(const StringName& p_name,const StringName& p_type=StringName()) const; int get_constant(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_icon(const StringName& p_name,const StringName& p_type=StringName()) const; + bool has_shader(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_font(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_color(const StringName& p_name,const StringName& p_type=StringName()) const; @@ -382,11 +363,13 @@ public: void warp_mouse(const Point2& p_to_pos); - virtual bool is_text_field() const; + virtual bool is_text_field() const; + + Control *get_root_parent_control() const; Control(); ~Control(); - + }; VARIANT_ENUM_CAST(Control::AnchorType); diff --git a/scene/gui/custom_button.cpp b/scene/gui/custom_button.cpp index 53a3bf0914..a70af05418 100644 --- a/scene/gui/custom_button.cpp +++ b/scene/gui/custom_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/custom_button.h b/scene/gui/custom_button.h index 49fcf7408f..2492750489 100644 --- a/scene/gui/custom_button.h +++ b/scene/gui/custom_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index efda8a66e1..9f08b6f845 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 67c574a420..7c06ded866 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 8e428fd71c..56b9260837 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -46,12 +46,56 @@ VBoxContainer *FileDialog::get_vbox() { } void FileDialog::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + + refresh->set_icon(get_icon("reload")); + } if (p_what==NOTIFICATION_DRAW) { //RID ci = get_canvas_item(); //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); - } + } + + if (p_what==NOTIFICATION_POPUP_HIDE) { + + set_process_unhandled_input(false); + } +} + +void FileDialog::_unhandled_input(const InputEvent& p_event) { + + if (p_event.type==InputEvent::KEY && is_window_modal_on_top()) { + + const InputEventKey &k=p_event.key; + + if (k.pressed) { + + bool handled=true; + + switch (k.scancode) { + + case KEY_H: { + + if (k.mod.command) { + set_show_hidden_files(!show_hidden_files); + } else { + handled=false; + } + + } break; + case KEY_F5: { + + invalidate(); + } break; + default: { handled=false; } + } + + if (handled) + accept_event(); + } + } } void FileDialog::set_enable_multiple_selection(bool p_enable) { @@ -109,6 +153,8 @@ void FileDialog::_post_popup() { else tree->grab_focus(); + set_process_unhandled_input(true); + } void FileDialog::_action_pressed() { @@ -618,11 +664,13 @@ void FileDialog::_update_drives() { } } -bool FileDialog::default_show_hidden_files=true; +bool FileDialog::default_show_hidden_files=false; void FileDialog::_bind_methods() { + ObjectTypeDB::bind_method(_MD("_unhandled_input"),&FileDialog::_unhandled_input); + ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected); ObjectTypeDB::bind_method(_MD("_tree_db_selected"),&FileDialog::_tree_dc_selected); ObjectTypeDB::bind_method(_MD("_dir_entered"),&FileDialog::_dir_entered); @@ -645,7 +693,7 @@ 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("set_show_hidden_files","show"),&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); @@ -700,6 +748,10 @@ FileDialog::FileDialog() { pathhb->add_child(dir); dir->set_h_size_flags(SIZE_EXPAND_FILL); + refresh = memnew( ToolButton ); + refresh->connect("pressed",this,"_update_file_list"); + pathhb->add_child(refresh); + drives = memnew( OptionButton ); pathhb->add_child(drives); drives->connect("item_selected",this,"_select_drive"); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index ec42c7744a..b71a157fa7 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -34,6 +34,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" #include "scene/gui/dialogs.h" +#include "scene/gui/tool_button.h" #include "os/dir_access.h" #include "box_container.h" /** @@ -86,6 +87,8 @@ private: OptionButton *filter; DirAccess *dir_access; ConfirmationDialog *confirm_save; + + ToolButton *refresh; Vector<String> filters; @@ -114,6 +117,8 @@ private: void _update_drives(); + void _unhandled_input(const InputEvent& p_event); + virtual void _post_popup(); protected: diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index deb3151798..9472c589ca 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1,6 +1,9 @@ #include "graph_edit.h" #include "os/input.h" #include "os/keyboard.h" +#include "scene/gui/box_container.h" + + bool GraphEditFilter::has_point(const Point2& p_point) const { return ge->_filter_input(p_point); @@ -42,7 +45,6 @@ bool GraphEdit::is_node_connected(const StringName& p_from, int p_from_port,cons void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port){ - for(List<Connection>::Element *E=connections.front();E;E=E->next()) { if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) { @@ -54,14 +56,22 @@ void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const } } +bool GraphEdit::clips_input() const { + + return true; +} + void GraphEdit::get_connection_list(List<Connection> *r_connections) const { *r_connections=connections; } +Vector2 GraphEdit::get_scroll_ofs() const{ -void GraphEdit::_scroll_moved(double) { + return Vector2(h_scroll->get_val(),v_scroll->get_val()); +} +void GraphEdit::_scroll_moved(double) { _update_scroll_offset(); top_layer->update(); @@ -149,6 +159,7 @@ void GraphEdit::add_child_notify(Node *p_child) { top_layer->call_deferred("raise"); //top layer always on top! GraphNode *gn = p_child->cast_to<GraphNode>(); if (gn) { + gn->set_scale(Vector2(zoom,zoom)); gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); _graph_node_moved(gn); @@ -182,6 +193,8 @@ void GraphEdit::_notification(int p_what) { h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + zoom_icon->set_texture( get_icon("Zoom", "EditorIcons")); + } if (p_what==NOTIFICATION_DRAW) { VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); @@ -382,8 +395,6 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { } - - } void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) { @@ -523,7 +534,9 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { if (!gn) continue; - bool in_box = gn->get_rect().intersects(box_selecting_rect); + Rect2 r = gn->get_rect(); + r.size*=zoom; + bool in_box = r.intersects(box_selecting_rect); if (in_box) gn->set_selected(box_selection_mode_aditive); @@ -552,7 +565,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } top_layer->update(); } else { - emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + if (connecting) { + connecting = false; + top_layer->update(); + } else { + emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + } } } @@ -562,8 +580,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { for(int i=get_child_count()-1;i>=0;i--) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - gn->set_selected(false); + if (gn) { + Rect2 r = gn->get_rect(); + r.size*=zoom; + if (r.has_point(get_local_mouse_pos())) + gn->set_selected(false); + } } } @@ -592,8 +614,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { gn=get_child(i)->cast_to<GraphNode>(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - break; + if (gn) { + Rect2 r = gn->get_rect(); + r.size*=zoom; + if (r.has_point(get_local_mouse_pos())) + break; + } } if (gn) { @@ -622,6 +648,9 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } } else { + if (_filter_input(Vector2(b.x,b.y))) + return; + box_selecting = true; box_selecting_from = get_local_mouse_pos(); if (b.mod.control) { @@ -666,6 +695,14 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { previus_selected.clear(); top_layer->update(); } + + if (b.button_index==BUTTON_WHEEL_UP && b.pressed) { + sl_zoom->set_val(zoom/0.9); + } + + if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) { + sl_zoom->set_val(zoom*0.9); + } } if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_D && p_ev.key.pressed && p_ev.key.mod.command) { @@ -686,6 +723,29 @@ void GraphEdit::clear_connections() { update(); } +void GraphEdit::set_zoom(float p_zoom) { + + if (p_zoom<0.01) p_zoom=0.01; + if (p_zoom>4) p_zoom=4; + if (zoom == p_zoom) + return; + + float prev_zoom = zoom; + zoom = p_zoom; + for (int i = 0; i < get_child_count(); i++) { + GraphNode *child = get_child(i)->cast_to<GraphNode>(); + if (!child) + continue; + Point2 ofs = child->get_offset() / prev_zoom * zoom; + child->set_scale(Vector2(zoom,zoom)); + child->set_offset(ofs); + } + update(); +} + +float GraphEdit::get_zoom() const { + return zoom; +} void GraphEdit::set_right_disconnects(bool p_enable) { @@ -718,6 +778,10 @@ void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); + ObjectTypeDB::bind_method(_MD("get_scroll_ofs"),&GraphEdit::get_scroll_ofs); + + ObjectTypeDB::bind_method(_MD("set_zoom","p_zoom"),&GraphEdit::set_zoom); + ObjectTypeDB::bind_method(_MD("get_zoom"),&GraphEdit::get_zoom); ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); @@ -770,4 +834,21 @@ GraphEdit::GraphEdit() { h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); + + zoom = 1; + + HBoxContainer* tools = memnew( HBoxContainer ); + add_child(tools); + + zoom_icon = memnew( TextureFrame ); + tools->add_child(zoom_icon); + + sl_zoom = memnew( HSlider ); + sl_zoom->set_min(0.01); + sl_zoom->set_max(4); + sl_zoom->set_val(1); + sl_zoom->set_step(0.01); + sl_zoom->connect("value_changed", this, "set_zoom"); + tools->add_child(sl_zoom); + sl_zoom->set_custom_minimum_size(Size2(200,0)); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 44f5a369c2..fe9c36cee4 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -3,7 +3,8 @@ #include "scene/gui/graph_node.h" #include "scene/gui/scroll_bar.h" - +#include "scene/gui/slider.h" +#include "texture_frame.h" class GraphEdit; class GraphEditFilter : public Control { @@ -34,6 +35,8 @@ public: }; private: + TextureFrame* zoom_icon; + HSlider* sl_zoom; HScrollBar* h_scroll; VScrollBar* v_scroll; @@ -53,6 +56,8 @@ private: bool just_selected; Vector2 drag_accum; + float zoom; + bool box_selecting; bool box_selection_mode_aditive; Point2 box_selecting_from; @@ -88,7 +93,7 @@ protected: virtual void add_child_notify(Node *p_child); virtual void remove_child_notify(Node *p_child); void _notification(int p_what); - + virtual bool clips_input() const; public: Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); @@ -96,11 +101,16 @@ public: void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); void clear_connections(); + void set_zoom(float p_zoom); + float get_zoom() const; + GraphEditFilter *get_top_layer() const { return top_layer; } void get_connection_list(List<Connection> *r_connections) const; void set_right_disconnects(bool p_enable); bool is_right_disconnects_enabled() const; + + Vector2 get_scroll_ofs() const; GraphEdit(); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 5efc9757b7..762afb158a 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -474,7 +474,10 @@ Vector2 GraphNode::get_connection_input_pos(int p_idx) { _connpos_update(); ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); - return conn_input_cache[p_idx].pos; + Vector2 pos = conn_input_cache[p_idx].pos; + pos.x *= get_scale().x; + pos.y *= get_scale().y; + return pos; } int GraphNode::get_connection_input_type(int p_idx) { @@ -501,8 +504,10 @@ Vector2 GraphNode::get_connection_output_pos(int p_idx){ _connpos_update(); ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); - return conn_output_cache[p_idx].pos; - + Vector2 pos = conn_output_cache[p_idx].pos; + pos.x *= get_scale().x; + pos.y *= get_scale().y; + return pos; } int GraphNode::get_connection_output_type(int p_idx) { diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 201529380d..dc407a6809 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -49,6 +49,7 @@ class GraphNode : public Container { bool selected; protected: + void _input_event(const InputEvent& p_ev); void _notification(int p_what); static void _bind_methods(); diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 105f66f368..a514f1b3d7 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/grid_container.h b/scene/gui/grid_container.h index 8d8bc27293..588bb17fa1 100644 --- a/scene/gui/grid_container.h +++ b/scene/gui/grid_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 002e49cbcf..e8097c79a4 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/label.h b/scene/gui/label.h index 4ea9f5d377..3c14add60d 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 18de8ed568..fdced3f62f 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -245,12 +245,26 @@ void LineEdit::_input_event(InputEvent p_event) { delete_char(); } } break; + case KEY_KP_4: { + if (k.unicode != 0) { + handled = false; + break; + } + // numlock disabled. fallthrough to key_left + } case KEY_LEFT: { shift_selection_check_pre(k.mod.shift); set_cursor_pos(get_cursor_pos()-1); shift_selection_check_post(k.mod.shift); } break; + case KEY_KP_6: { + if (k.unicode != 0) { + handled = false; + break; + } + // numlock disabled. fallthrough to key_right + } case KEY_RIGHT: { shift_selection_check_pre(k.mod.shift); @@ -271,12 +285,26 @@ void LineEdit::_input_event(InputEvent p_event) { } } break; + case KEY_KP_7: { + if (k.unicode != 0) { + handled = false; + break; + } + // numlock disabled. fallthrough to key_home + } case KEY_HOME: { shift_selection_check_pre(k.mod.shift); set_cursor_pos(0); shift_selection_check_post(k.mod.shift); } break; + case KEY_KP_1: { + if (k.unicode != 0) { + handled = false; + break; + } + // numlock disabled. fallthrough to key_end + } case KEY_END: { shift_selection_check_pre(k.mod.shift); @@ -287,26 +315,29 @@ void LineEdit::_input_event(InputEvent p_event) { default: { - if (k.unicode>=32 && k.scancode!=KEY_DELETE) { - - if (editable) { - selection_delete(); - CharType ucodestr[2]={(CharType)k.unicode,0}; - append_at_cursor(ucodestr); - emit_signal("text_changed",text); - _change_notify("text"); - } - - } else { - handled=false; - } + handled=false; } break; } - if (handled) + if (handled) { accept_event(); - else - return; + } else { + if (k.unicode>=32 && k.scancode!=KEY_DELETE) { + + if (editable) { + selection_delete(); + CharType ucodestr[2]={(CharType)k.unicode,0}; + append_at_cursor(ucodestr); + emit_signal("text_changed",text); + _change_notify("text"); + + accept_event(); + } + + } else { + return; + } + } selection.old_shift=k.mod.shift; @@ -568,7 +599,7 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { int char_w = 0; if (font != NULL) { - int char_w = font->get_char_size(text[ofs]).width; + char_w = font->get_char_size(text[ofs]).width; } pixel_ofs+=char_w; diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index f28136d66e..bf6459361a 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index f10ca6353a..fde5df6b72 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/margin_container.h b/scene/gui/margin_container.h index 56f2344ea7..df9a5c9361 100644 --- a/scene/gui/margin_container.h +++ b/scene/gui/margin_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index be7a6b468a..26540843de 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 47e7382d34..2df632811f 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index ff94a37be0..5c8e5a7381 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -77,9 +77,14 @@ void OptionButton::_selected(int p_which) { } } - ERR_FAIL_COND(selid==-1); + if (selid==-1 && p_which>=0 && p_which<popup->get_item_count()) { + _select(p_which,true); + } else { - _select(selid,true); + ERR_FAIL_COND(selid==-1); + + _select(selid,true); + } } @@ -299,7 +304,7 @@ void OptionButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_item_count"),&OptionButton::get_item_count); ObjectTypeDB::bind_method(_MD("add_separator"),&OptionButton::add_separator); ObjectTypeDB::bind_method(_MD("clear"),&OptionButton::clear); - ObjectTypeDB::bind_method(_MD("select"),&OptionButton::select); + ObjectTypeDB::bind_method(_MD("select","idx"),&OptionButton::select); ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected); ObjectTypeDB::bind_method(_MD("get_selected_ID"),&OptionButton::get_selected_ID); ObjectTypeDB::bind_method(_MD("get_selected_metadata"),&OptionButton::get_selected_metadata); diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 7d850479aa..34e2bdd384 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index d9ba20810b..d40daa972c 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/panel.h b/scene/gui/panel.h index 7e6be62923..ee4bcd139e 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 5ee061356e..bcf75b79f8 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/panel_container.h b/scene/gui/panel_container.h index c09479241c..a40519c9f2 100644 --- a/scene/gui/panel_container.h +++ b/scene/gui/panel_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 5ce7e2e0d3..1f04985ec6 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -45,12 +45,20 @@ void Popup::_notification(int p_what) { emit_signal("popup_hide"); } } + + if (p_what==NOTIFICATION_ENTER_TREE) { + //small helper to make editing of these easier in editor +#ifdef TOOLS_ENABLED + if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + set_as_toplevel(false); + } +#endif + } + } void Popup::_fix_size() { - Control *window = get_window(); - ERR_FAIL_COND(!window); #if 0 Point2 pos = get_pos(); @@ -172,14 +180,12 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) { void Popup::popup_centered(const Size2& p_size) { - Control *window = get_window(); - ERR_FAIL_COND(!window); - + Point2 window_size = get_viewport_rect().size; emit_signal("about_to_show"); Rect2 rect; rect.size = p_size==Size2()?get_size():p_size; - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); + rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); set_size( rect.size ); @@ -199,13 +205,11 @@ void Popup::popup_centered(const Size2& p_size) { void Popup::popup_centered_ratio(float p_screen_ratio) { - Control *window = get_window(); - ERR_FAIL_COND(!window); emit_signal("about_to_show"); Rect2 rect; - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); + Point2 window_size = get_viewport_rect().size; rect.size = (window_size * p_screen_ratio).floor(); rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 6c72a3c82b..9c66e6d7bd 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 20f28ecf10..a93d8e524f 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -370,7 +370,7 @@ void PopupMenu::_input_event(const InputEvent &p_event) { } int over=_get_mouse_over(Point2(m.x,m.y)); - int id = (over<0 || items[over].separator || items[over].disabled)?-1:items[over].ID; + int id = (over<0 || items[over].separator || items[over].disabled)?-1:(items[over].ID>=0?items[over].ID:over); if (id<0) { mouse_over=-1; @@ -524,7 +524,7 @@ void PopupMenu::add_icon_item(const Ref<Texture>& p_icon,const String& p_label,i item.icon=p_icon; item.text=p_label; item.accel=p_accel; - item.ID=(p_ID<0)?idcount++:p_ID; + item.ID=p_ID; items.push_back(item); update(); } @@ -533,7 +533,7 @@ void PopupMenu::add_item(const String& p_label,int p_ID,uint32_t p_accel) { Item item; item.text=XL_MESSAGE(p_label); item.accel=p_accel; - item.ID=(p_ID<0)?idcount++:p_ID; + item.ID=p_ID; items.push_back(item); update(); } @@ -542,7 +542,7 @@ void PopupMenu::add_submenu_item(const String& p_label, const String& p_submenu, Item item; item.text=XL_MESSAGE(p_label); - item.ID=(p_ID<0)?idcount++:p_ID; + item.ID=p_ID; item.submenu=p_submenu; items.push_back(item); update(); @@ -554,7 +554,7 @@ void PopupMenu::add_icon_check_item(const Ref<Texture>& p_icon,const String& p_l item.icon=p_icon; item.text=XL_MESSAGE(p_label); item.accel=p_accel; - item.ID=(p_ID<0)?idcount++:p_ID; + item.ID=p_ID; item.checkable=true; items.push_back(item); update(); @@ -564,7 +564,7 @@ void PopupMenu::add_check_item(const String& p_label,int p_ID,uint32_t p_accel) Item item; item.text=XL_MESSAGE(p_label); item.accel=p_accel; - item.ID=(p_ID<0)?idcount++:p_ID; + item.ID=p_ID; item.checkable=true; items.push_back(item); update(); @@ -753,9 +753,11 @@ int PopupMenu::find_item_by_accelerator(uint32_t p_accel) const { void PopupMenu::activate_item(int p_item) { + ERR_FAIL_INDEX(p_item,items.size()); ERR_FAIL_COND(items[p_item].separator); - emit_signal("item_pressed",items[p_item].ID); + int id = items[p_item].ID>=0?items[p_item].ID:p_item; + emit_signal("item_pressed",id); //hide all parent PopupMenue's Node *next = get_parent(); @@ -789,7 +791,7 @@ void PopupMenu::clear() { items.clear(); mouse_over=-1; update(); - idcount=0; + } @@ -896,7 +898,7 @@ void PopupMenu::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_item_icon","idx","icon"),&PopupMenu::set_item_icon); ObjectTypeDB::bind_method(_MD("set_item_accelerator","idx","accel"),&PopupMenu::set_item_accelerator); ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&PopupMenu::set_item_metadata); - ObjectTypeDB::bind_method(_MD("set_item_checked","idx"),&PopupMenu::set_item_checked); + ObjectTypeDB::bind_method(_MD("set_item_checked","idx","checked"),&PopupMenu::set_item_checked); ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&PopupMenu::set_item_disabled); ObjectTypeDB::bind_method(_MD("set_item_submenu","idx","submenu"),&PopupMenu::set_item_submenu); ObjectTypeDB::bind_method(_MD("set_item_as_separator","idx","enable"),&PopupMenu::set_item_as_separator); @@ -937,7 +939,7 @@ void PopupMenu::set_invalidate_click_until_motion() { PopupMenu::PopupMenu() { - idcount=0; + mouse_over=-1; set_focus_mode(FOCUS_ALL); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index ed78fe6738..624f4f542a 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -59,7 +59,6 @@ class PopupMenu : public Popup { Timer *submenu_timer; List<Rect2> autohide_areas; Vector<Item> items; - int idcount; int mouse_over; int submenu_over; Rect2 parent_rect; diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index e7e2c88f4a..fc0e7be34f 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/progress_bar.h b/scene/gui/progress_bar.h index 33b0d5c185..f50df346ac 100644 --- a/scene/gui/progress_bar.h +++ b/scene/gui/progress_bar.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 7103ee651f..ffcdf98519 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -48,20 +48,20 @@ void Range::Shared::emit_value_changed() { } } -void Range::_changed_notify() { +void Range::_changed_notify(const char *p_what) { emit_signal("changed",shared->val); update(); - _change_notify(); + _change_notify(p_what); } -void Range::Shared::emit_changed() { +void Range::Shared::emit_changed(const char *p_what) { for (Set<Range*>::Element *E=owners.front();E;E=E->next()) { Range *r=E->get(); if (!r->is_inside_tree()) continue; - r->_changed_notify(); + r->_changed_notify(p_what); } } @@ -77,7 +77,11 @@ void Range::set_val(double p_val) { if (p_val<shared->min) p_val=shared->min; - + + //avoid to set -0 + if (p_val == 0) + p_val = 0; + if (shared->val==p_val) return; @@ -90,20 +94,20 @@ void Range::set_min(double p_min) { shared->min=p_min; set_val(shared->val); - shared->emit_changed(); + shared->emit_changed("range/min"); } void Range::set_max(double p_max) { shared->max=p_max; set_val(shared->val); - shared->emit_changed(); + shared->emit_changed("range/max"); } void Range::set_step(double p_step) { shared->step=p_step; - shared->emit_changed(); + shared->emit_changed("range/step"); } void Range::set_page(double p_page) { @@ -111,7 +115,7 @@ void Range::set_page(double p_page) { shared->page=p_page; set_val(shared->val); - shared->emit_changed(); + shared->emit_changed("range/page"); } double Range::get_val() const { @@ -216,11 +220,10 @@ void Range::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_val"),&Range::get_val); ObjectTypeDB::bind_method(_MD("get_value"),&Range::get_val); ObjectTypeDB::bind_method(_MD("get_min"),&Range::get_min); - ObjectTypeDB::bind_method(_MD("get_max"),&Range::get_max); - ObjectTypeDB::bind_method(_MD("get_step"),&Range::get_step); - ObjectTypeDB::bind_method(_MD("get_page"),&Range::get_page); - ObjectTypeDB::bind_method(_MD("get_unit_value"),&Range::get_unit_value); - ObjectTypeDB::bind_method(_MD("get_rounded_values"),&Range::get_rounded_values); + ObjectTypeDB::bind_method(_MD("get_max"),&Range::get_max); + ObjectTypeDB::bind_method(_MD("get_step"),&Range::get_step); + ObjectTypeDB::bind_method(_MD("get_page"),&Range::get_page); + ObjectTypeDB::bind_method(_MD("get_unit_value"),&Range::get_unit_value); ObjectTypeDB::bind_method(_MD("set_val","value"),&Range::set_val); ObjectTypeDB::bind_method(_MD("set_value","value"),&Range::set_val); ObjectTypeDB::bind_method(_MD("set_min","minimum"),&Range::set_min); @@ -228,7 +231,8 @@ void Range::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_step","step"),&Range::set_step); ObjectTypeDB::bind_method(_MD("set_page","pagesize"),&Range::set_page); ObjectTypeDB::bind_method(_MD("set_unit_value","value"),&Range::set_unit_value); - ObjectTypeDB::bind_method(_MD("set_rounded_values"),&Range::set_rounded_values); + ObjectTypeDB::bind_method(_MD("set_rounded_values","enabled"),&Range::set_rounded_values); + ObjectTypeDB::bind_method(_MD("is_rounded_values"),&Range::is_rounded_values); ObjectTypeDB::bind_method(_MD("set_exp_unit_value","enabled"),&Range::set_exp_unit_value); ObjectTypeDB::bind_method(_MD("is_unit_value_exp"),&Range::is_unit_value_exp); @@ -244,16 +248,18 @@ void Range::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/page" ), _SCS("set_page"), _SCS("get_page") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/value" ), _SCS("set_val"), _SCS("get_val") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "range/exp_edit" ), _SCS("set_exp_unit_value"), _SCS("is_unit_value_exp") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "rounded_values" ), _SCS("set_rounded_values"), _SCS("get_rounded_values") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "range/rounded" ), _SCS("set_rounded_values"), _SCS("is_rounded_values") ); } -void Range::set_rounded_values(bool p){ - _rounded_values = p; +void Range::set_rounded_values(bool p_enable) { + + _rounded_values = p_enable; } -bool Range::get_rounded_values() const{ - return _rounded_values; +bool Range::is_rounded_values() const { + + return _rounded_values; } void Range::set_exp_unit_value(bool p_enable) { diff --git a/scene/gui/range.h b/scene/gui/range.h index 48361ddb0e..d96ecdfb0b 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -44,7 +44,7 @@ class Range : public Control { bool exp_unit_value; Set<Range*> owners; void emit_value_changed(); - void emit_changed(); + void emit_changed(const char *p_what=""); }; Shared *shared; @@ -55,7 +55,7 @@ class Range : public Control { void _share(Node *p_range); void _value_changed_notify(); - void _changed_notify(); + void _changed_notify(const char *p_what=""); protected: @@ -72,22 +72,23 @@ public: void set_step(double p_step); void set_page(double p_page); void set_unit_value(double p_value); - void set_rounded_values(bool); - + double get_val() const; double get_min() const; double get_max() const; double get_step() const; double get_page() const; double get_unit_value() const; - bool get_rounded_values() const; + + void set_rounded_values(bool p_enable); + bool is_rounded_values() const; void set_exp_unit_value(bool p_enable); bool is_unit_value_exp() const; void share(Range *p_range); void unshare(); - + Range(); ~Range(); diff --git a/scene/gui/reference_frame.cpp b/scene/gui/reference_frame.cpp index b90ea8292d..d037664a62 100644 --- a/scene/gui/reference_frame.cpp +++ b/scene/gui/reference_frame.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/reference_frame.h b/scene/gui/reference_frame.h index 8915b1df0c..5d3694e6e8 100644 --- a/scene/gui/reference_frame.h +++ b/scene/gui/reference_frame.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index b98fec1bde..d4ac2652dc 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -30,35 +30,62 @@ #include "scene/scene_string_names.h" #include "os/keyboard.h" #include "os/os.h" -RichTextLabel::Item *RichTextLabel::_get_next_item(Item* p_item) { +RichTextLabel::Item *RichTextLabel::_get_next_item(Item* p_item,bool p_free) { - if (p_item->subitems.size()) { + if (p_free) { - return p_item->subitems.front()->get(); - } else if (!p_item->parent) { - return NULL; - } else if (p_item->E->next()) { + if (p_item->subitems.size()) { + + return p_item->subitems.front()->get(); + } else if (!p_item->parent) { + return NULL; + } else if (p_item->E->next()) { + + return p_item->E->next()->get(); + } else { + //go up until something with a next is found + while (p_item->parent && !p_item->E->next()) { + p_item=p_item->parent; + } + + + if (p_item->parent) + return p_item->E->next()->get(); + else + return NULL; - return p_item->E->next()->get(); - } else { - //go up until something with a next is found - while (p_item->parent && !p_item->E->next()) { - p_item=p_item->parent; } + } else { + if (p_item->subitems.size() && p_item->type!=ITEM_TABLE) { - if (p_item && p_item->parent) - return p_item->E->next()->get(); - else + return p_item->subitems.front()->get(); + } else if (p_item->type==ITEM_FRAME) { return NULL; + } else if (p_item->E->next()) { + return p_item->E->next()->get(); + } else { + //go up until something with a next is found + while (p_item->type!=ITEM_FRAME && !p_item->E->next()) { + p_item=p_item->parent; + } + + + if (p_item->type!=ITEM_FRAME) + return p_item->E->next()->get(); + else + return NULL; + + } } return NULL; } -void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) { + +void RichTextLabel::_process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) { RID ci; if (r_outside) @@ -70,7 +97,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p *r_click_item=NULL; } - Line &l = lines[p_line]; + Line &l = p_frame->lines[p_line]; Item *it = l.from; @@ -91,10 +118,13 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p l.offset_caches.clear(); l.height_caches.clear(); l.char_count=0; + l.minimum_width=0; } int wofs=margin; int spaces_size=0; + int align_ofs=0; + if (p_mode!=PROCESS_CACHE && align!=ALIGN_FILL) wofs+=line_ofs; @@ -125,7 +155,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p case ALIGN_LEFT: l.offset_caches.push_back(0); break;\ case ALIGN_CENTER: l.offset_caches.push_back(((p_width-margin)-used)/2); break;\ case ALIGN_RIGHT: l.offset_caches.push_back(((p_width-margin)-used)); break;\ - case ALIGN_FILL: l.offset_caches.push_back((p_width-margin)-used+spaces_size); break;\ + case ALIGN_FILL: l.offset_caches.push_back((p_width-margin)-used/*+spaces_size*/); break;\ }\ l.height_caches.push_back(line_height);\ l.space_caches.push_back(spaces);\ @@ -135,10 +165,11 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p spaces=0;\ spaces_size=0;\ wofs=begin;\ + align_ofs=0;\ if (p_mode!=PROCESS_CACHE) {\ lh=line<l.height_caches.size()?l.height_caches[line]:1;\ }\ - if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=y && p_click_pos.y<=y+lh && p_click_pos.x<wofs) {\ + if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x<p_ofs.x+wofs) {\ if (r_outside) *r_outside=true;\ *r_click_item=it;\ *r_click_char=rchar;\ @@ -148,12 +179,15 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p #define ENSURE_WIDTH(m_width) \ + if (p_mode==PROCESS_CACHE) { \ + l.minimum_width=MAX(l.minimum_width,wofs+m_width);\ + }\ if (wofs + m_width > p_width) {\ if (p_mode==PROCESS_CACHE) {\ if (spaces>0) \ spaces-=1;\ }\ - if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=y && p_click_pos.y<=y+lh && p_click_pos.x>wofs) {\ + if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>p_ofs.x+wofs) {\ if (r_outside) *r_outside=true; \ *r_click_item=it;\ *r_click_char=rchar;\ @@ -165,7 +199,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p #define ADVANCE(m_width) \ {\ - if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=y && p_click_pos.y<=y+lh && p_click_pos.x>=wofs && p_click_pos.x<wofs+m_width) {\ + if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>=p_ofs.x+wofs && p_click_pos.x<p_ofs.x+wofs+m_width) {\ if (r_outside) *r_outside=false; \ *r_click_item=it;\ *r_click_char=rchar;\ @@ -218,8 +252,10 @@ if (m_height > line_height) {\ underline=true; } + } else if (p_mode==PROCESS_CACHE) { l.char_count+=text->text.length(); + } rchar=0; @@ -246,6 +282,8 @@ if (m_height > line_height) {\ if (c[end]==' ') { + fw+=cw; + /* if (p_mode==PROCESS_CACHE) { fw+=cw; } else if (align==ALIGN_FILL && line<l.space_caches.size() && l.space_caches[line]>0) { @@ -254,7 +292,7 @@ if (m_height > line_height) {\ found_space=true; } else { fw+=cw; - } + }*/ } else { fw+=cw; } @@ -262,23 +300,26 @@ if (m_height > line_height) {\ end++; } - - ENSURE_WIDTH(w); - //print_line("END: "+String::chr(c[end])+"."); if (end && c[end-1]==' ') { - spaces++; if (p_mode==PROCESS_CACHE) { spaces_size+=font->get_char_size(' ').width; + } else if (align==ALIGN_FILL) { + int ln = MIN(l.offset_caches.size()-1,line); + if (l.space_caches[ln]) { + align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln]; + } } + spaces++; + /* if (found_space) { int ln = MIN(l.offset_caches.size()-1,line); fw+=l.offset_caches[ln]/l.space_caches[ln]; - } + }*/ } @@ -294,7 +335,7 @@ if (m_height > line_height) {\ - if (p_mode==PROCESS_POINTER && r_click_char && p_click_pos.y>=y && p_click_pos.y<=y+lh) { + if (p_mode==PROCESS_POINTER && r_click_char && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) { //int o = (wofs+w)-p_click_pos.x; @@ -303,7 +344,7 @@ if (m_height > line_height) {\ cw=tab_size*font->get_char_size(' ').width; } - if (p_click_pos.x-cw/2>pofs) { + if (p_click_pos.x-cw/2>p_ofs.x+align_ofs+pofs) { rchar=int((&c[i])-cf); //print_line("GOT: "+itos(rchar)); @@ -337,13 +378,13 @@ if (m_height > line_height) {\ if (selected) { cw = font->get_char_size(c[i],c[i+1]).x; - draw_rect(Rect2(pofs,y,cw,lh),selection_bg); + draw_rect(Rect2(p_ofs.x+pofs,p_ofs.y+y,cw,lh),selection_bg); if (visible) - font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); + font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); } else { if (visible) - cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); + cw=font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); } p_char_count++; @@ -359,7 +400,7 @@ if (m_height > line_height) {\ uc.a*=0.5; //VS::get_singleton()->canvas_item_add_line(ci,Point2(pofs,y+ascent+2),Point2(pofs+cw,y+ascent+2),uc); int uy = y+lh-fh+ascent+2; - VS::get_singleton()->canvas_item_add_line(ci,Point2(pofs,uy),Point2(pofs+cw,uy),uc); + VS::get_singleton()->canvas_item_add_line(ci,p_ofs+Point2(align_ofs+pofs,uy),p_ofs+Point2(align_ofs+pofs+cw,uy),uc); } ofs+=cw; } @@ -397,7 +438,7 @@ if (m_height > line_height) {\ bool visible = visible_characters<0 || p_char_count<visible_characters; if (p_mode==PROCESS_DRAW && visible) { - img->image->draw(ci,Point2(wofs,y+lh-font->get_descent()-img->image->get_height())); + img->image->draw(ci,p_ofs+Point2(align_ofs+wofs,y+lh-font->get_descent()-img->image->get_height())); } p_char_count++; @@ -435,6 +476,148 @@ if (m_height > line_height) {\ #endif } break; + case ITEM_TABLE: { + + lh=0; + ItemTable *table = static_cast<ItemTable*>(it); + int hseparation=get_constant("table_hseparation"); + int vseparation=get_constant("table_vseparation"); + Color ccolor = _find_color(table,p_base_color); + Vector2 draw_ofs = Point2(wofs,y); + int max_y=get_size().height; + + if (p_mode==PROCESS_CACHE) { + + int idx=0; + //set minimums to zero + for(int i=0;i<table->columns.size();i++) { + table->columns[i].min_width=0; + table->columns[i].width=0; + } + //compute minimum width for each cell + for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { + ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames + ItemFrame *frame = static_cast<ItemFrame*>(E->get()); + + int column = idx % table->columns.size(); + + int ly=0; + + + for(int i=0;i<frame->lines.size();i++) { + + _process_line(frame,Point2(),ly,p_width,i,PROCESS_CACHE,cfont,Color()); + table->columns[column].min_width=MAX( table->columns[i].min_width, frame->lines[i].minimum_width ); + } + idx++; + } + + //compute available width and total radio (for expanders) + + + int total_ratio=0; + int available_width=p_width - hseparation * (table->columns.size() -1); + table->total_width=hseparation; + + for(int i=0;i<table->columns.size();i++) { + available_width-=table->columns[i].min_width; + if (table->columns[i].expand) + total_ratio+=table->columns[i].expand_ratio; + } + + //assign actual widths + + for(int i=0;i<table->columns.size();i++) { + table->columns[i].width = table->columns[i].min_width; + if (table->columns[i].expand) + table->columns[i].width+=table->columns[i].expand_ratio*available_width/total_ratio; + table->total_width+=table->columns[i].width+hseparation; + } + + //compute caches properly again with the right width + idx=0; + for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { + ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames + ItemFrame *frame = static_cast<ItemFrame*>(E->get()); + + int column = idx % table->columns.size(); + + + for(int i=0;i<frame->lines.size();i++) { + + int ly=0; + _process_line(frame,Point2(),ly,table->columns[column].width,i,PROCESS_CACHE,cfont,Color()); + frame->lines[i].height_cache=ly; //actual height + frame->lines[i].height_accum_cache=ly; //actual height + } + idx++; + } + + } + + + + Point2 offset(align_ofs+hseparation,vseparation); + + int row_height=0; + //draw using computed caches + int idx=0; + for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { + ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames + ItemFrame *frame = static_cast<ItemFrame*>(E->get()); + + int column = idx % table->columns.size(); + + int ly=0; + int yofs=0; + + + int lines_h = frame->lines[frame->lines.size()-1].height_accum_cache - (frame->lines[0].height_accum_cache - frame->lines[0].height_cache); + int lines_ofs = p_ofs.y+offset.y+draw_ofs.y; + + bool visible = lines_ofs < get_size().height && lines_ofs+lines_h >=0; + + for(int i=0;i<frame->lines.size();i++) { + + + if (visible) { + if (p_mode==PROCESS_DRAW) { + _process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_DRAW,cfont,ccolor); + } else if (p_mode==PROCESS_POINTER) { + _process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_POINTER,cfont,ccolor,p_click_pos,r_click_item,r_click_char,r_outside); + } + } + + yofs+=frame->lines[i].height_cache; + if (p_mode==PROCESS_CACHE) { + frame->lines[i].height_accum_cache=offset.y+draw_ofs.y+frame->lines[i].height_cache; + } + + } + + row_height=MAX(yofs,row_height); + offset.x+=table->columns[column].width+hseparation; + + if (column==table->columns.size()-1) { + + offset.y+=row_height+vseparation; + offset.x=hseparation; + row_height=0; + } + idx++; + } + + int total_height = offset.y; + if (row_height) { + total_height=row_height+vseparation; + } + + + + ADVANCE( table->total_width ); + CHECK_HEIGHT( total_height ); + + } break; default: {} @@ -445,7 +628,7 @@ if (m_height > line_height) {\ it = _get_next_item(it); - if (p_mode == PROCESS_POINTER && r_click_item && itp && !it && p_click_pos.y>y+lh) { + if (p_mode == PROCESS_POINTER && r_click_item && itp && !it && p_click_pos.y>p_ofs.y+y+lh) { //at the end of all, return this if (r_outside) *r_outside=true; *r_click_item=itp; @@ -453,9 +636,9 @@ if (m_height > line_height) {\ return; } - if (it && (p_line+1 < lines.size()) && lines[p_line+1].from==it) { + if (it && (p_line+1 < p_frame->lines.size()) && p_frame->lines[p_line+1].from==it) { - if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=y && p_click_pos.y<=y+lh) { + if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) { //went to next line, but pointer was on the previous one if (r_outside) *r_outside=true; *r_click_item=itp; @@ -493,8 +676,8 @@ void RichTextLabel::_scroll_changed(double) { void RichTextLabel::_update_scroll() { int total_height=0; - if (lines.size()) - total_height=lines[lines.size()-1].height_accum_cache; + if (main->lines.size()) + total_height=main->lines[main->lines.size()-1].height_accum_cache; bool exceeds = total_height > get_size().height && scroll_active; @@ -503,18 +686,18 @@ void RichTextLabel::_update_scroll() { if (exceeds) { scroll_visible=true; - first_invalid_line=0; + main->first_invalid_line=0; scroll_w=vscroll->get_combined_minimum_size().width; vscroll->show(); vscroll->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_END,scroll_w); - _validate_line_caches(); + _validate_line_caches(main); } else { scroll_visible=false; vscroll->hide(); scroll_w=0; - _validate_line_caches(); + _validate_line_caches(main); } } @@ -527,7 +710,7 @@ void RichTextLabel::_notification(int p_what) { case NOTIFICATION_RESIZED: { - first_invalid_line=0; //invalidate ALL + main->first_invalid_line=0; //invalidate ALL update(); } break; @@ -535,7 +718,7 @@ void RichTextLabel::_notification(int p_what) { if (use_bbcode) parse_bbcode(bbcode); - first_invalid_line=0; //invalidate ALL + main->first_invalid_line=0; //invalidate ALL update(); } break; @@ -550,7 +733,7 @@ void RichTextLabel::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - _validate_line_caches(); + _validate_line_caches(main); _update_scroll(); @@ -571,25 +754,25 @@ void RichTextLabel::_notification(int p_what) { int from_line = 0; int total_chars = 0; - while (from_line<lines.size()) { + while (from_line<main->lines.size()) { - if (lines[from_line].height_accum_cache>=ofs) + if (main->lines[from_line].height_accum_cache>=ofs) break; from_line++; - total_chars+=lines[from_line].char_count; + total_chars+=main->lines[from_line].char_count; } - if (from_line>=lines.size()) + if (from_line>=main->lines.size()) break; //nothing to draw - int y = (lines[from_line].height_accum_cache - lines[from_line].height_cache) - ofs; + int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs; Ref<Font> base_font=get_font("normal_font"); Color base_color=get_color("default_color"); - while (y<size.height && from_line<lines.size()) { + while (y<size.height && from_line<main->lines.size()) { - _process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars); - total_chars+=lines[from_line].char_count; + _process_line(main,Point2(),y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars); + total_chars+=main->lines[from_line].char_count; from_line++; } } @@ -597,7 +780,7 @@ void RichTextLabel::_notification(int p_what) { } -void RichTextLabel::_find_click(const Point2i& p_click,Item **r_click_item,int *r_click_char,bool *r_outside) { +void RichTextLabel::_find_click(ItemFrame* p_frame,const Point2i& p_click,Item **r_click_item,int *r_click_char,bool *r_outside) { if (r_click_item) *r_click_item=NULL; @@ -609,26 +792,26 @@ void RichTextLabel::_find_click(const Point2i& p_click,Item **r_click_item,int * //todo, change to binary search int from_line = 0; - while (from_line<lines.size()) { + while (from_line<p_frame->lines.size()) { - if (lines[from_line].height_accum_cache>=ofs) + if (p_frame->lines[from_line].height_accum_cache>=ofs) break; from_line++; } - if (from_line>=lines.size()) + if (from_line>=p_frame->lines.size()) return; - int y = (lines[from_line].height_accum_cache - lines[from_line].height_cache) - ofs; + int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs; Ref<Font> base_font=get_font("normal_font"); Color base_color=get_color("default_color"); - while (y<size.height && from_line<lines.size()) { + while (y<size.height && from_line<p_frame->lines.size()) { - _process_line(y,size.width-scroll_w,from_line,PROCESS_POINTER,base_font,base_color,p_click,r_click_item,r_click_char,r_outside); + _process_line(p_frame,Point2(),y,size.width-scroll_w,from_line,PROCESS_POINTER,base_font,base_color,p_click,r_click_item,r_click_char,r_outside); if (r_click_item && *r_click_item) return; from_line++; @@ -643,13 +826,13 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2& p_pos) const if (!underline_meta || selection.click) return CURSOR_ARROW; - if (first_invalid_line<lines.size()) + if (main->first_invalid_line<main->lines.size()) return CURSOR_ARROW; //invalid int line=0; Item *item=NULL; - ((RichTextLabel*)(this))->_find_click(p_pos,&item,&line); + ((RichTextLabel*)(this))->_find_click(main,p_pos,&item,&line); if (item && ((RichTextLabel*)(this))->_find_meta(item,NULL)) @@ -665,7 +848,7 @@ void RichTextLabel::_input_event(InputEvent p_event) { case InputEvent::MOUSE_BUTTON: { - if (first_invalid_line<lines.size()) + if (main->first_invalid_line<main->lines.size()) return; const InputEventMouseButton& b = p_event.mouse_button; @@ -680,7 +863,7 @@ void RichTextLabel::_input_event(InputEvent p_event) { Item *item=NULL; bool outside; - _find_click(Point2i(b.x,b.y),&item,&line,&outside); + _find_click(main,Point2i(b.x,b.y),&item,&line,&outside); if (item) { @@ -719,7 +902,7 @@ void RichTextLabel::_input_event(InputEvent p_event) { case InputEvent::KEY: { const InputEventKey &k=p_event.key; - if (k.pressed && !k.mod.alt && !k.mod.shift && !k.mod.command && !k.mod.meta) { + if (k.pressed && !k.mod.alt && !k.mod.shift && !k.mod.meta) { bool handled=true; switch(k.scancode) { case KEY_PAGEUP: { @@ -773,7 +956,7 @@ void RichTextLabel::_input_event(InputEvent p_event) { } break; case InputEvent::MOUSE_MOTION: { - if (first_invalid_line<lines.size()) + if (main->first_invalid_line<main->lines.size()) return; const InputEventMouseMotion& m = p_event.mouse_motion; @@ -782,7 +965,7 @@ void RichTextLabel::_input_event(InputEvent p_event) { int line=0; Item *item=NULL; - _find_click(Point2i(m.x,m.y),&item,&line); + _find_click(main,Point2i(m.x,m.y),&item,&line); if (!item) return; // do not update @@ -950,9 +1133,9 @@ bool RichTextLabel::_find_meta(Item *p_item,Variant *r_meta) { } -void RichTextLabel::_validate_line_caches() { +void RichTextLabel::_validate_line_caches(ItemFrame* p_frame) { - if (first_invalid_line==lines.size()) + if (p_frame->first_invalid_line==p_frame->lines.size()) return; //validate invalid lines!s @@ -960,24 +1143,24 @@ void RichTextLabel::_validate_line_caches() { Ref<Font> base_font=get_font("normal_font"); - for(int i=first_invalid_line;i<lines.size();i++) { + for(int i=p_frame->first_invalid_line;i<p_frame->lines.size();i++) { int y=0; - _process_line(y,size.width-scroll_w,i,PROCESS_CACHE,base_font,Color()); - lines[i].height_cache=y; - lines[i].height_accum_cache=y; + _process_line(p_frame,Point2(),y,size.width-scroll_w,i,PROCESS_CACHE,base_font,Color()); + p_frame->lines[i].height_cache=y; + p_frame->lines[i].height_accum_cache=y; if (i>0) - lines[i].height_accum_cache+=lines[i-1].height_accum_cache; + p_frame->lines[i].height_accum_cache+=p_frame->lines[i-1].height_accum_cache; } int total_height=0; - if (lines.size()) - total_height=lines[lines.size()-1].height_accum_cache; + if (p_frame->lines.size()) + total_height=p_frame->lines[p_frame->lines.size()-1].height_accum_cache; - first_invalid_line=lines.size(); + main->first_invalid_line=p_frame->lines.size(); updating_scroll=true; vscroll->set_max(total_height); @@ -990,17 +1173,20 @@ void RichTextLabel::_validate_line_caches() { } -void RichTextLabel::_invalidate_current_line() { +void RichTextLabel::_invalidate_current_line(ItemFrame* p_frame) { - if (lines.size()-1 <= first_invalid_line) { + if (p_frame->lines.size()-1 <= p_frame->first_invalid_line) { - first_invalid_line=lines.size()-1; + p_frame->first_invalid_line=p_frame->lines.size()-1; update(); } } void RichTextLabel::add_text(const String& p_text) { + if (current->type==ITEM_TABLE) + return; //can't add anything here + int pos=0; while (pos<p_text.length()) { @@ -1027,7 +1213,7 @@ void RichTextLabel::add_text(const String& p_text) { //append text condition! ItemText *ti = static_cast<ItemText*>(current->subitems.back()->get()); ti->text+=line; - _invalidate_current_line(); + _invalidate_current_line(main); } else { //append item condition @@ -1043,11 +1229,11 @@ void RichTextLabel::add_text(const String& p_text) { if (eol) { ItemNewline *item = memnew( ItemNewline ); - item->line=lines.size(); + item->line=current_frame->lines.size(); _add_item(item,false); - lines.resize(lines.size()+1); - lines[lines.size()-1].from=item; - _invalidate_current_line(); + current_frame->lines.resize(current_frame->lines.size()+1); + current_frame->lines[current_frame->lines.size()-1].from=item; + _invalidate_current_line(current_frame); } @@ -1055,25 +1241,38 @@ void RichTextLabel::add_text(const String& p_text) { } } -void RichTextLabel::_add_item(Item *p_item, bool p_enter) { +void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) { + + p_item->parent=current; p_item->E=current->subitems.push_back(p_item); p_item->index=current_idx++; + if (p_enter) current=p_item; - if (lines[lines.size()-1].from==NULL) { - lines[lines.size()-1].from=p_item; + if (p_ensure_newline && current_frame->lines[current_frame->lines.size()-1].from) { + _invalidate_current_line(current_frame); + current_frame->lines.resize( current_frame->lines.size() +1 ); + + } + + if (current_frame->lines[current_frame->lines.size()-1].from==NULL) { + current_frame->lines[current_frame->lines.size()-1].from=p_item; } + p_item->line=current_frame->lines.size()-1; - _invalidate_current_line(); + _invalidate_current_line(current_frame); } void RichTextLabel::add_image(const Ref<Texture>& p_image) { + if (current->type==ITEM_TABLE) + return; + ERR_FAIL_COND(p_image.is_null()); ItemImage *item = memnew( ItemImage ); @@ -1084,15 +1283,18 @@ void RichTextLabel::add_image(const Ref<Texture>& p_image) { void RichTextLabel::add_newline() { + if (current->type==ITEM_TABLE) + return; ItemNewline *item = memnew( ItemNewline ); - item->line=lines.size(); - lines.resize(lines.size()+1); + item->line=current_frame->lines.size(); + current_frame->lines.resize(current_frame->lines.size()+1); _add_item(item,false); } void RichTextLabel::push_font(const Ref<Font>& p_font) { + ERR_FAIL_COND(current->type==ITEM_TABLE); ERR_FAIL_COND(p_font.is_null()); ItemFont *item = memnew( ItemFont ); @@ -1102,6 +1304,7 @@ void RichTextLabel::push_font(const Ref<Font>& p_font) { } void RichTextLabel::push_color(const Color& p_color) { + ERR_FAIL_COND(current->type==ITEM_TABLE); ItemColor *item = memnew( ItemColor ); item->color=p_color; @@ -1110,6 +1313,7 @@ void RichTextLabel::push_color(const Color& p_color) { } void RichTextLabel::push_underline() { + ERR_FAIL_COND(current->type==ITEM_TABLE); ItemUnderline *item = memnew( ItemUnderline ); _add_item(item,true); @@ -1118,47 +1322,40 @@ void RichTextLabel::push_underline() { void RichTextLabel::push_align(Align p_align) { - lines.resize(lines.size()+1); + ERR_FAIL_COND(current->type==ITEM_TABLE); ItemAlign *item = memnew( ItemAlign ); item->align=p_align; - _add_item(item,true); - - ItemNewline *itemnl = memnew( ItemNewline ); - itemnl->line=lines.size()-1; - _add_item(itemnl,false); + _add_item(item,true,true); } void RichTextLabel::push_indent(int p_level) { + ERR_FAIL_COND(current->type==ITEM_TABLE); ERR_FAIL_COND(p_level<0); - lines.resize(lines.size()+1); - ItemIndent *item = memnew( ItemIndent ); item->level=p_level; - _add_item(item,true); - - ItemNewline *itemnl = memnew( ItemNewline ); - itemnl->line=lines.size()-1; - _add_item(itemnl,false); + _add_item(item,true,true); } void RichTextLabel::push_list(ListType p_list) { + ERR_FAIL_COND(current->type==ITEM_TABLE); ERR_FAIL_INDEX(p_list,3); ItemList *item = memnew( ItemList ); item->list_type=p_list; - _add_item(item,true); + _add_item(item,true,true); } void RichTextLabel::push_meta(const Variant& p_meta) { + ERR_FAIL_COND(current->type==ITEM_TABLE); ItemMeta *item = memnew( ItemMeta ); item->meta=p_meta; @@ -1166,9 +1363,62 @@ void RichTextLabel::push_meta(const Variant& p_meta) { } +void RichTextLabel::push_table(int p_columns) { + + ERR_FAIL_COND( p_columns < 1); + ItemTable *item = memnew( ItemTable ); + + item->columns.resize(p_columns); + item->total_width=0; + for(int i=0;i<item->columns.size();i++) { + item->columns[i].expand=false; + item->columns[i].expand_ratio=1; + } + _add_item(item,true,true); + +} + +void RichTextLabel::set_table_column_expand(int p_column,bool p_expand,int p_ratio) { + + ERR_FAIL_COND(current->type!=ITEM_TABLE); + ItemTable *table = static_cast<ItemTable*>(current); + ERR_FAIL_INDEX(p_column,table->columns.size()); + table->columns[p_column].expand=p_expand; + table->columns[p_column].expand_ratio=p_ratio; +} + +void RichTextLabel::push_cell(){ + + ERR_FAIL_COND(current->type!=ITEM_TABLE); + + ItemFrame *item = memnew( ItemFrame ); + item->parent_frame=current_frame; + _add_item(item,true); + current_frame=item; + item->cell=true; + item->parent_line=item->parent_frame->lines.size()-1; + item->lines.resize(1); + item->lines[0].from=NULL; + item->first_invalid_line=0; + +} + +int RichTextLabel::get_current_table_column() const { + + ERR_FAIL_COND_V(current->type!=ITEM_TABLE,-1); + + ItemTable *table = static_cast<ItemTable*>(current); + + return table->subitems.size() % table->columns.size(); + +} + void RichTextLabel::pop() { ERR_FAIL_COND(!current->parent); + if (current->type==ITEM_FRAME) { + current_frame = static_cast<ItemFrame*>(current)->parent_frame; + } current=current->parent; } @@ -1176,9 +1426,10 @@ void RichTextLabel::clear() { main->_clear_children(); current=main; - lines.clear(); - lines.resize(1); - first_invalid_line=0; + current_frame=main; + main->lines.clear(); + main->lines.resize(1); + main->first_invalid_line=0; update(); selection.click=NULL; selection.active=false; @@ -1189,7 +1440,7 @@ void RichTextLabel::clear() { void RichTextLabel::set_tab_size(int p_spaces) { tab_size=p_spaces; - first_invalid_line=0; + main->first_invalid_line=0; update(); } @@ -1345,6 +1596,30 @@ Error RichTextLabel::append_bbcode(const String& p_bbcode) { push_font(mono_font); pos=brk_end+1; tag_stack.push_front(tag); + } else if (tag.begins_with("table=")) { + + int columns = tag.substr(6,tag.length()).to_int(); + if (columns<1) + columns=1; + //use monospace font + push_table(columns); + pos=brk_end+1; + tag_stack.push_front("table"); + } else if (tag=="cell") { + + push_cell(); + pos=brk_end+1; + tag_stack.push_front(tag); + } else if (tag.begins_with("cell=")) { + + int ratio = tag.substr(6,tag.length()).to_int(); + if (ratio<1) + ratio=1; + //use monospace font + set_table_column_expand(get_current_table_column(),true,ratio); + push_cell(); + pos=brk_end+1; + tag_stack.push_front("cell"); } else if (tag=="u") { //use underline @@ -1504,16 +1779,15 @@ Error RichTextLabel::append_bbcode(const String& p_bbcode) { void RichTextLabel::scroll_to_line(int p_line) { - p_line -= 1; - ERR_FAIL_INDEX(p_line,lines.size()); - _validate_line_caches(); - vscroll->set_val(lines[p_line].height_accum_cache-lines[p_line].height_cache); + ERR_FAIL_INDEX(p_line,main->lines.size()); + _validate_line_caches(main); + vscroll->set_val(main->lines[p_line].height_accum_cache-main->lines[p_line].height_cache); } int RichTextLabel::get_line_count() const { - return lines.size(); + return current_frame->lines.size(); } void RichTextLabel::set_selection_enabled(bool p_enabled) { @@ -1557,32 +1831,31 @@ bool RichTextLabel::search(const String& p_string,bool p_from_selection) { selection.active=true; update(); - if (line==-1) { + _validate_line_caches(main); - while(it) { + int fh = _find_font(t).is_valid()?_find_font(t)->get_height():get_font("normal_font")->get_height(); - if (it->type==ITEM_NEWLINE) { + float offset =0; - line=static_cast<ItemNewline*>(it)->line; - break; + int line = t->line; + Item *item =t; + while(item) { + if (item->type==ITEM_FRAME) { + ItemFrame *frame = static_cast<ItemFrame*>(item); + if (line>=0 && line<frame->lines.size()) { + offset+=frame->lines[line].height_accum_cache-frame->lines[line].height_cache; + line=frame->line; } - - it=_get_next_item(it); } - + item=item->parent; } - - if (line > 1) { - line-=1; - } - - scroll_to_line(line); + vscroll->set_val(offset-fh); return true; } } - it=_get_next_item(it); + it=_get_next_item(it,true); charidx=0; } @@ -1621,7 +1894,7 @@ void RichTextLabel::selection_copy() { if (item==selection.to) break; - item=_get_next_item(item); + item=_get_next_item(item,true); } if (text!="") { @@ -1674,6 +1947,9 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("push_list","type"),&RichTextLabel::push_list); ObjectTypeDB::bind_method(_MD("push_meta","data"),&RichTextLabel::push_meta); ObjectTypeDB::bind_method(_MD("push_underline"),&RichTextLabel::push_underline); + ObjectTypeDB::bind_method(_MD("push_table","columns"),&RichTextLabel::push_table); + ObjectTypeDB::bind_method(_MD("set_table_column_expand","column","expand","ratio"),&RichTextLabel::set_table_column_expand); + ObjectTypeDB::bind_method(_MD("push_cell"),&RichTextLabel::push_cell); ObjectTypeDB::bind_method(_MD("pop"),&RichTextLabel::pop); ObjectTypeDB::bind_method(_MD("clear"),&RichTextLabel::clear); @@ -1689,10 +1965,11 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_v_scroll"),&RichTextLabel::get_v_scroll); + ObjectTypeDB::bind_method(_MD("scroll_to_line","line"),&RichTextLabel::scroll_to_line); + ObjectTypeDB::bind_method(_MD("set_tab_size","spaces"),&RichTextLabel::set_tab_size); ObjectTypeDB::bind_method(_MD("get_tab_size"),&RichTextLabel::get_tab_size); - ObjectTypeDB::bind_method(_MD("set_selection_enabled","enabled"),&RichTextLabel::set_selection_enabled); ObjectTypeDB::bind_method(_MD("is_selection_enabled"),&RichTextLabel::is_selection_enabled); @@ -1725,7 +2002,7 @@ void RichTextLabel::_bind_methods() { BIND_CONSTANT( LIST_LETTERS ); BIND_CONSTANT( LIST_DOTS ); - BIND_CONSTANT( ITEM_MAIN ); + BIND_CONSTANT( ITEM_FRAME ); BIND_CONSTANT( ITEM_TEXT ); BIND_CONSTANT( ITEM_IMAGE ); BIND_CONSTANT( ITEM_NEWLINE ); @@ -1753,8 +2030,8 @@ int RichTextLabel::get_visible_characters() const { int RichTextLabel::get_total_character_count() const { int tc=0; - for(int i=0;i<lines.size();i++) - tc+=lines[i].char_count; + for(int i=0;i<current_frame->lines.size();i++) + tc+=current_frame->lines[i].char_count; return tc; } @@ -1763,12 +2040,13 @@ int RichTextLabel::get_total_character_count() const { RichTextLabel::RichTextLabel() { - main = memnew( ItemMain ); + main = memnew( ItemFrame ); main->index=0; current=main; - lines.resize(1); - lines[0].from=main; - first_invalid_line=0; + main->lines.resize(1); + main->lines[0].from=main; + main->first_invalid_line=0; + current_frame=main; tab_size=4; default_align=ALIGN_LEFT; underline_meta=true; diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index eaa8d5d60a..635fe87ad4 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -54,7 +54,7 @@ public: enum ItemType { - ITEM_MAIN, + ITEM_FRAME, ITEM_TEXT, ITEM_IMAGE, ITEM_NEWLINE, @@ -64,6 +64,7 @@ public: ITEM_ALIGN, ITEM_INDENT, ITEM_LIST, + ITEM_TABLE, ITEM_META }; @@ -72,6 +73,24 @@ protected: static void _bind_methods(); private: + struct Item; + + struct Line { + + Item *from; + Vector<int> offset_caches; + Vector<int> height_caches; + Vector<int> space_caches; + int height_cache; + int height_accum_cache; + int char_count; + int minimum_width; + + Line() { from=NULL; char_count=0; } + }; + + + struct Item { int index; @@ -79,18 +98,26 @@ private: ItemType type; List<Item*> subitems; List<Item*>::Element *E; + int line; void _clear_children() { while (subitems.size()) { memdelete(subitems.front()->get()); subitems.pop_front(); } } - Item() { parent=NULL; E=NULL; } + Item() { parent=NULL; E=NULL; line=0;} virtual ~Item() { _clear_children(); } }; - struct ItemMain : public Item { + struct ItemFrame : public Item{ + + int parent_line; + bool cell; + Vector<Line> lines; + int first_invalid_line; + ItemFrame *parent_frame; - ItemMain() { type=ITEM_MAIN; } + ItemFrame() { type=ITEM_FRAME; parent_frame=NULL; cell=false; parent_line=0; } }; + struct ItemText : public Item { String text; @@ -150,11 +177,28 @@ private: ItemNewline() { type=ITEM_NEWLINE; } }; - ItemMain *main; + + struct ItemTable : public Item{ + + struct Column { + bool expand; + int expand_ratio; + int min_width; + int width; + }; + + Vector<Column> columns; + int total_width; + ItemTable() { type=ITEM_TABLE; } + }; + + ItemFrame *main; Item *current; + ItemFrame *current_frame; VScrollBar *vscroll; + bool scroll_visible; bool scroll_follow; bool scroll_following; @@ -163,34 +207,16 @@ private: bool updating_scroll; int current_idx; - struct Line { - - Item *from; - Vector<int> offset_caches; - Vector<int> height_caches; - Vector<int> space_caches; - int height_cache; - int height_accum_cache; - int char_count; - - Line() { from=NULL; char_count=0; } - }; - - - - - Vector<Line> lines; - int first_invalid_line; int tab_size; bool underline_meta; Align default_align; - void _invalidate_current_line(); - void _validate_line_caches(); + void _invalidate_current_line(ItemFrame *p_frame); + void _validate_line_caches(ItemFrame *p_frame); - void _add_item(Item *p_item, bool p_enter=false); + void _add_item(Item *p_item, bool p_enter=false,bool p_ensure_newline=false); @@ -227,8 +253,8 @@ private: int visible_characters; - void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0); - void _find_click(const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); + void _process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0); + void _find_click(ItemFrame *p_frame, const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); Ref<Font> _find_font(Item *p_item); @@ -242,12 +268,12 @@ private: void _scroll_changed(double); void _input_event(InputEvent p_event); - Item *_get_next_item(Item* p_item); + Item *_get_next_item(Item* p_item, bool p_free=false); bool use_bbcode; String bbcode; - + void _update_all_lines(); protected: void _notification(int p_what); @@ -264,6 +290,10 @@ public: void push_indent(int p_level); void push_list(ListType p_list); void push_meta(const Variant& p_data); + void push_table(int p_columns); + void set_table_column_expand(int p_column, bool p_expand, int p_ratio=1); + int get_current_table_column() const; + void push_cell(); void pop(); void clear(); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index b1fd914fcd..0fd4286f38 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index 367bc3eb53..a629ddc56c 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index e5b5d531a0..a2fc038f9e 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index b8d37be08c..50ae236714 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 5e822a10ad..626b093a2f 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/separator.h b/scene/gui/separator.h index 17e9c11e34..7a7dc92b93 100644 --- a/scene/gui/separator.h +++ b/scene/gui/separator.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index b6292c544b..7ef9d4216b 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -50,9 +50,9 @@ void Slider::_input_event(InputEvent p_event) { grab.pos=orientation==VERTICAL?mb.y:mb.x; double max = orientation==VERTICAL ? get_size().height : get_size().width ; if (orientation==VERTICAL) - set_val( ( ( -(double)grab.pos / max) * ( get_max() - get_min() ) ) + get_max() ); + set_unit_value( 1 - ((double)grab.pos / max) ); else - set_val( ( ( (double)grab.pos / max) * ( get_max() - get_min() ) ) + get_min() ); + set_unit_value((double)grab.pos / max); grab.active=true; grab.uvalue=get_unit_value(); } else { diff --git a/scene/gui/slider.h b/scene/gui/slider.h index 5850c48ce3..f85e6d1807 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index a48136f541..2b64d36a81 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -68,6 +68,24 @@ void SpinBox::_line_edit_input(const InputEvent& p_event) { } +void SpinBox::_range_click_timeout() { + + if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + + bool up = get_local_mouse_pos().y < (get_size().height/2); + set_val( get_val() + (up?get_step():-get_step())); + + if (range_click_timer->is_one_shot()) { + range_click_timer->set_wait_time(0.075); + range_click_timer->set_one_shot(false); + range_click_timer->start(); + } + + } else { + range_click_timer->stop(); + } +} + void SpinBox::_input_event(const InputEvent& p_event) { @@ -85,6 +103,10 @@ void SpinBox::_input_event(const InputEvent& p_event) { set_val( get_val() + (up?get_step():-get_step())); + range_click_timer->set_wait_time(0.6); + range_click_timer->set_one_shot(true); + range_click_timer->start(); + } break; case BUTTON_RIGHT: { @@ -112,6 +134,8 @@ void SpinBox::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) { //set_default_cursor_shape(CURSOR_ARROW); + range_click_timer->stop(); + if (drag.enabled) { drag.enabled=false; Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); @@ -167,6 +191,7 @@ void SpinBox::_notification(int p_what) { Size2i size = get_size(); updown->draw(ci,Point2i(size.width-updown->get_width(),(size.height-updown->get_height())/2)); + } else if (p_what==NOTIFICATION_FOCUS_EXIT) { @@ -227,6 +252,7 @@ void SpinBox::_bind_methods() { ObjectTypeDB::bind_method(_MD("_line_edit_focus_exit"),&SpinBox::_line_edit_focus_exit); ObjectTypeDB::bind_method(_MD("get_line_edit"),&SpinBox::get_line_edit); ObjectTypeDB::bind_method(_MD("_line_edit_input"),&SpinBox::_line_edit_input); + ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&SpinBox::_range_click_timeout); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"editable"),_SCS("set_editable"),_SCS("is_editable")); @@ -248,4 +274,8 @@ SpinBox::SpinBox() { line_edit->connect("focus_exit",this,"_line_edit_focus_exit",Vector<Variant>(),CONNECT_DEFERRED); line_edit->connect("input_event",this,"_line_edit_input"); drag.enabled=false; + + range_click_timer = memnew( Timer ); + range_click_timer->connect("timeout",this,"_range_click_timeout"); + add_child(range_click_timer); } diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 4c8cb8432a..acaea822ab 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -31,6 +31,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/range.h" +#include "scene/main/timer.h" class SpinBox : public Range { @@ -39,6 +40,9 @@ class SpinBox : public Range { LineEdit *line_edit; int last_w; + Timer *range_click_timer; + void _range_click_timeout(); + void _text_entered(const String& p_string); virtual void _value_changed(double); String prefix; diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 49067bb3a0..d22f6a0229 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -109,7 +109,7 @@ void SplitContainer::_resort() { int sep=get_constant("separation"); Ref<Texture> g = get_icon("grabber"); - if (collapsed || !dragger_visible) { + if (dragger_visibility==DRAGGER_HIDDEN_COLLAPSED) { sep=0; } else { sep=MAX(sep,vertical?g->get_height():g->get_width()); @@ -221,7 +221,7 @@ Size2 SplitContainer::get_minimum_size() const { Size2i minimum; int sep=get_constant("separation"); Ref<Texture> g = get_icon("grabber"); - sep=dragger_visible?MAX(sep,vertical?g->get_height():g->get_width()):0; + sep=(dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED)?MAX(sep,vertical?g->get_height():g->get_width()):0; for(int i=0;i<2;i++) { @@ -278,19 +278,19 @@ void SplitContainer::_notification(int p_what) { if (collapsed || (!mouse_inside && get_constant("autohide"))) return; - int sep=dragger_visible?get_constant("separation"):0; + int sep=dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED?get_constant("separation"):0; Ref<Texture> tex = get_icon("grabber"); Size2 size=get_size(); if (vertical) { //draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep)); - if (dragger_visible) + if (dragger_visibility==DRAGGER_VISIBLE) draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2)); } else { //draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height)); - if (dragger_visible) + if (dragger_visibility==DRAGGER_VISIBLE) draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2)); } @@ -301,7 +301,7 @@ void SplitContainer::_notification(int p_what) { void SplitContainer::_input_event(const InputEvent& p_event) { - if (collapsed || !_getch(0) || !_getch(1) || !dragger_visible) + if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility!=DRAGGER_VISIBLE) return; if (p_event.type==InputEvent::MOUSE_BUTTON) { @@ -400,19 +400,19 @@ void SplitContainer::set_collapsed(bool p_collapsed) { } -void SplitContainer::set_dragger_visible(bool p_true) { +void SplitContainer::set_dragger_visibility(DraggerVisibility p_visibility) { - dragger_visible=p_true; + dragger_visibility=p_visibility; queue_sort(); update(); } -bool SplitContainer::is_dragger_visible() const{ +SplitContainer::DraggerVisibility SplitContainer::get_dragger_visibility() const { - - return dragger_visible; + return dragger_visibility; } + bool SplitContainer::is_collapsed() const { @@ -429,15 +429,18 @@ void SplitContainer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_collapsed","collapsed"),&SplitContainer::set_collapsed); ObjectTypeDB::bind_method(_MD("is_collapsed"),&SplitContainer::is_collapsed); - ObjectTypeDB::bind_method(_MD("set_dragger_visible","visible"),&SplitContainer::set_dragger_visible); - ObjectTypeDB::bind_method(_MD("is_dragger_visible"),&SplitContainer::is_dragger_visible); + ObjectTypeDB::bind_method(_MD("set_dragger_visibility","mode"),&SplitContainer::set_dragger_visibility); + ObjectTypeDB::bind_method(_MD("get_dragger_visibility"),&SplitContainer::get_dragger_visibility); ADD_SIGNAL( MethodInfo("dragged",PropertyInfo(Variant::INT,"offset"))); ADD_PROPERTY( PropertyInfo(Variant::INT,"split/offset"),_SCS("set_split_offset"),_SCS("get_split_offset")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/collapsed"),_SCS("set_collapsed"),_SCS("is_collapsed")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/dragger_visible"),_SCS("set_dragger_visible"),_SCS("is_dragger_visible")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"split/dragger_visibility",PROPERTY_HINT_ENUM,"Visible,Hidden,Hidden & Collapsed"),_SCS("set_dragger_visibility"),_SCS("get_dragger_visibility")); + BIND_CONSTANT( DRAGGER_VISIBLE ); + BIND_CONSTANT( DRAGGER_HIDDEN ); + BIND_CONSTANT( DRAGGER_HIDDEN_COLLAPSED ); } @@ -450,7 +453,8 @@ SplitContainer::SplitContainer(bool p_vertical) { vertical=p_vertical; dragging=false; collapsed=false; - dragger_visible=true; + dragger_visibility=DRAGGER_VISIBLE; + } diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index d7f56c6fb4..f721d16310 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -35,7 +35,13 @@ class SplitContainer : public Container { OBJ_TYPE(SplitContainer,Container); - +public: + enum DraggerVisibility { + DRAGGER_VISIBLE, + DRAGGER_HIDDEN, + DRAGGER_HIDDEN_COLLAPSED + }; +private: bool vertical; int expand_ofs; int middle_sep; @@ -43,7 +49,7 @@ class SplitContainer : public Container { int drag_from; int drag_ofs; bool collapsed; - bool dragger_visible; + DraggerVisibility dragger_visibility; bool mouse_inside; @@ -66,8 +72,8 @@ public: void set_collapsed(bool p_collapsed); bool is_collapsed() const; - void set_dragger_visible(bool p_true); - bool is_dragger_visible() const; + void set_dragger_visibility(DraggerVisibility p_visibility); + DraggerVisibility get_dragger_visibility() const; virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()); @@ -76,6 +82,7 @@ public: SplitContainer(bool p_vertical=false); }; +VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility); class HSplitContainer : public SplitContainer { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6fa701340d..91d0fc157e 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 602d248b46..979ce927a0 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 47a55e0716..ecce71bdbd 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -65,8 +65,8 @@ Size2 Tabs::get_minimum_size() const { ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height); } - if (tabs[i].close_button.is_valid()) { - Ref<Texture> cb=tabs[i].close_button; + if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) { + Ref<Texture> cb=get_icon("close"); Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_size(); bms.width+=get_constant("hseparation"); ms.width+=bms.width; @@ -74,6 +74,7 @@ Size2 Tabs::get_minimum_size() const { } } + ms.width=0; //should make this optional return ms; } @@ -85,19 +86,28 @@ void Tabs::_input_event(const InputEvent& p_event) { Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y ); + hilite_arrow=-1; + if (buttons_visible) { + + Ref<Texture> incr = get_icon("increment"); + Ref<Texture> decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + if (pos.x>limit+decr->get_width()) { + hilite_arrow=1; + } else if (pos.x>limit) { + hilite_arrow=0; + } + } + + + int hover_buttons=-1; hover=-1; for(int i=0;i<tabs.size();i++) { // test hovering tab to display close button if policy says so - if (cb_displaypolicy == SHOW_HOVER) { - int ofs=tabs[i].ofs_cache; - int size = tabs[i].ofs_cache; - if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) { - hover=i; - } - } - // test hovering right button and close button if (tabs[i].rb_rect.has_point(pos)) { @@ -163,9 +173,34 @@ void Tabs::_input_event(const InputEvent& p_event) { // clicks Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y ); + if (buttons_visible) { + + Ref<Texture> incr = get_icon("increment"); + Ref<Texture> decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + if (pos.x>limit+decr->get_width()) { + if (missing_right) { + offset++; + update(); + } + return; + } else if (pos.x>limit) { + if (offset>0) { + offset--; + update(); + } + return; + } + } + + int found=-1; for(int i=0;i<tabs.size();i++) { + if (i<offset) + continue; if (tabs[i].rb_rect.has_point(pos)) { rb_pressing=true; update(); @@ -208,6 +243,10 @@ void Tabs::_notification(int p_what) { hover=-1; update(); } break; + case NOTIFICATION_RESIZED: { + + _ensure_no_over_offset(); + } break; case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); @@ -217,15 +256,36 @@ void Tabs::_notification(int p_what) { Ref<Font> font = get_font("font"); Color color_fg = get_color("font_color_fg"); Color color_bg = get_color("font_color_bg"); + Ref<Texture> close=get_icon("close"); int h = get_size().height; int label_valign_fg = get_constant("label_valign_fg"); int label_valign_bg = get_constant("label_valign_bg"); + int w=0; - int mw = get_minimum_size().width; + int mw = 0; + + { + + + // h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") ); + + for(int i=0;i<tabs.size();i++) { + + int sz = get_tab_width(i); + + tabs[i].ofs_cache=mw; + mw+=sz; + + + } + + } + + if (tab_align==ALIGN_CENTER) { w=(get_size().width-mw)/2; @@ -238,8 +298,19 @@ void Tabs::_notification(int p_what) { w=0; } + Ref<Texture> incr = get_icon("increment"); + Ref<Texture> decr = get_icon("decrement"); + Ref<Texture> incr_hl = get_icon("increment_hilite"); + Ref<Texture> decr_hl = get_icon("decrement_hilite"); + + int limit=get_size().width - incr->get_size().width - decr->get_size().width; + + missing_right=false; + for(int i=0;i<tabs.size();i++) { + if (i<offset) + continue; tabs[i].ofs_cache=w; String s = tabs[i].text; @@ -247,6 +318,8 @@ void Tabs::_notification(int p_what) { int slen=font->get_string_size(s).width; lsize+=slen; + + Ref<Texture> icon; if (tabs[i].icon.is_valid()) { icon = tabs[i].icon; @@ -269,56 +342,25 @@ void Tabs::_notification(int p_what) { } - // Close button - switch (cb_displaypolicy) { - case SHOW_ALWAYS: { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> rb=tabs[i].close_button; - - lsize+=get_constant("hseparation"); - //lsize+=style->get_margin(MARGIN_LEFT); - lsize+=rb->get_width(); - //lsize+=style->get_margin(MARGIN_RIGHT); - } - } break; - case SHOW_ACTIVE_ONLY: { - if (i==current) { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> rb=tabs[i].close_button; - - lsize+=get_constant("hseparation"); - //lsize+=style->get_margin(MARGIN_LEFT); - lsize+=rb->get_width(); - //lsize+=style->get_margin(MARGIN_RIGHT); - - } - } - } break; - case SHOW_HOVER: { - if (i==current || i==hover) { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> rb=tabs[i].close_button; + if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) { - lsize+=get_constant("hseparation"); - //lsize+=style->get_margin(MARGIN_LEFT); - lsize+=rb->get_width(); - //lsize+=style->get_margin(MARGIN_RIGHT); - - } - } - } break; - case SHOW_NEVER: // by default, never show close button - default: { - // do nothing - } break; + lsize+=get_constant("hseparation"); + //lsize+=style->get_margin(MARGIN_LEFT); + lsize+=close->get_width(); + //lsize+=style->get_margin(MARGIN_RIGHT); + } + if (w+lsize > limit) { + max_drawn_tab=i-1; + missing_right=true; + break; + } else { + max_drawn_tab=i; } + Ref<StyleBox> sb; int va; Color col; @@ -382,100 +424,31 @@ void Tabs::_notification(int p_what) { } + if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) { + Ref<StyleBox> style = get_stylebox("button"); + Ref<Texture> cb=close; - // Close button - switch (cb_displaypolicy) { - case SHOW_ALWAYS: { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> cb=tabs[i].close_button; - - w+=get_constant("hseparation"); - - Rect2 cb_rect; - cb_rect.size=style->get_minimum_size()+cb->get_size(); - cb_rect.pos.x=w; - cb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(cb_rect.size.y))/2; - - if (cb_hover==i) { - if (cb_pressing) - get_stylebox("button_pressed")->draw(ci,cb_rect); - else - style->draw(ci,cb_rect); - } + w+=get_constant("hseparation"); - //w+=style->get_margin(MARGIN_LEFT); + Rect2 cb_rect; + cb_rect.size=style->get_minimum_size()+cb->get_size(); + cb_rect.pos.x=w; + cb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(cb_rect.size.y))/2; - cb->draw(ci,Point2i( w,cb_rect.pos.y+style->get_margin(MARGIN_TOP) )); - w+=cb->get_width(); - //w+=style->get_margin(MARGIN_RIGHT); - tabs[i].cb_rect=cb_rect; - } - } break; - case SHOW_ACTIVE_ONLY: { - if (current==i) { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> cb=tabs[i].close_button; - - w+=get_constant("hseparation"); - - Rect2 cb_rect; - cb_rect.size=style->get_minimum_size()+cb->get_size(); - cb_rect.pos.x=w; - cb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(cb_rect.size.y))/2; - - if (cb_hover==i) { - if (cb_pressing) - get_stylebox("button_pressed")->draw(ci,cb_rect); - else - style->draw(ci,cb_rect); - } - - //w+=style->get_margin(MARGIN_LEFT); - - cb->draw(ci,Point2i( w,cb_rect.pos.y+style->get_margin(MARGIN_TOP) )); - w+=cb->get_width(); - //w+=style->get_margin(MARGIN_RIGHT); - tabs[i].cb_rect=cb_rect; - } - } - } break; - case SHOW_HOVER: { - if (current==i || hover==i) { - if (tabs[i].close_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> cb=tabs[i].close_button; - - w+=get_constant("hseparation"); - - Rect2 cb_rect; - cb_rect.size=style->get_minimum_size()+cb->get_size(); - cb_rect.pos.x=w; - cb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(cb_rect.size.y))/2; - - if (cb_hover==i) { - if (cb_pressing) - get_stylebox("button_pressed")->draw(ci,cb_rect); - else - style->draw(ci,cb_rect); - } - - //w+=style->get_margin(MARGIN_LEFT); - - cb->draw(ci,Point2i( w,cb_rect.pos.y+style->get_margin(MARGIN_TOP) )); - w+=cb->get_width(); - //w+=style->get_margin(MARGIN_RIGHT); - tabs[i].cb_rect=cb_rect; - } + if (cb_hover==i) { + if (cb_pressing) + get_stylebox("button_pressed")->draw(ci,cb_rect); + else + style->draw(ci,cb_rect); } - } break; - case SHOW_NEVER: - default: { - // show nothing - } break; + //w+=style->get_margin(MARGIN_LEFT); + + cb->draw(ci,Point2i( w,cb_rect.pos.y+style->get_margin(MARGIN_TOP) )); + w+=cb->get_width(); + //w+=style->get_margin(MARGIN_RIGHT); + tabs[i].cb_rect=cb_rect; } w+=sb->get_margin(MARGIN_RIGHT); @@ -484,6 +457,25 @@ void Tabs::_notification(int p_what) { } + if (offset>0 || missing_right) { + + int vofs = (get_size().height-incr->get_size().height)/2; + + if (offset>0) + draw_texture(hilite_arrow==0?decr_hl:decr,Point2(limit,vofs)); + else + draw_texture(decr,Point2(limit,vofs),Color(1,1,1,0.5)); + + if (missing_right) + draw_texture(hilite_arrow==1?incr_hl:incr,Point2(limit+decr->get_size().width,vofs)); + else + draw_texture(incr,Point2(limit+decr->get_size().width,vofs),Color(1,1,1,0.5)); + + buttons_visible=true; + } else { + buttons_visible=false; + } + } break; } @@ -563,20 +555,6 @@ Ref<Texture> Tabs::get_tab_right_button(int p_tab) const{ } -void Tabs::set_tab_close_button(int p_tab, const Ref<Texture>& p_close_button) { - ERR_FAIL_INDEX(p_tab, tabs.size()); - tabs[p_tab].close_button=p_close_button; - update(); - minimum_size_changed(); -} - - -Ref<Texture> Tabs::get_tab_close_button(int p_tab) const{ - - ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref<Texture>()); - return tabs[p_tab].close_button; - -} void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) { @@ -584,8 +562,6 @@ void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) { t.text=p_str; t.icon=p_icon; - t.close_button = get_icon("Close","EditorIcons"); - tabs.push_back(t); update(); @@ -615,10 +591,8 @@ void Tabs::remove_tab(int p_idx) { //emit_signal("tab_changed",current); -} + _ensure_no_over_offset(); -void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_cb_displaypolicy) { - cb_displaypolicy = p_cb_displaypolicy; } @@ -633,6 +607,129 @@ Tabs::TabAlign Tabs::get_tab_align() const { return tab_align; } +int Tabs::get_tab_width(int p_idx) const { + + ERR_FAIL_INDEX_V(p_idx,tabs.size(),0); + + Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); + Ref<Font> font = get_font("font"); + Ref<Texture> close=get_icon("close"); + + int x=0; + + Ref<Texture> tex = tabs[p_idx].icon; + if (tex.is_valid()) { + if (tabs[p_idx].text!="") + x+=get_constant("hseparation"); + + } + + + x+=font->get_string_size(tabs[p_idx].text).width; + if (current==p_idx) + x+=tab_fg->get_minimum_size().width; + else + x+=tab_bg->get_minimum_size().width; + + if (tabs[p_idx].right_button.is_valid()) { + print_line("has right"); + Ref<Texture> rb=tabs[p_idx].right_button; + Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + + x+=bms.width; + } + + if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx==current)) { + + Size2 bms = close->get_size();//+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + x+=bms.width; + } + + return x; +} + + +void Tabs::_ensure_no_over_offset() { + + if (!is_inside_tree()) + return; + + Ref<Texture> incr = get_icon("increment"); + Ref<Texture> decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + while(offset>0) { + + int total_w=0; + for(int i=0;i<tabs.size();i++) { + + if (i<offset-1) + continue; + + total_w+=get_tab_width(i); + } + + if (total_w < limit) { + offset--; + update(); + } else { + break; + } + } + +} + + +void Tabs::ensure_tab_visible(int p_idx) { + + if (!is_inside_tree()) + return; + + ERR_FAIL_INDEX(p_idx,tabs.size()); + + _ensure_no_over_offset(); + + if (p_idx<=offset) { + offset=p_idx; + update(); + return; + } + + Ref<Texture> incr = get_icon("increment"); + Ref<Texture> decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + + + int x=0; + for(int i=0;i<tabs.size();i++) { + + if (i<offset) + continue; + + int sz = get_tab_width(i); + tabs[i].x_cache=x; + tabs[i].x_size_cache=sz; + x+=sz; + + } + + while(offset<tabs.size() && ( (tabs[p_idx].x_cache + tabs[p_idx].x_size_cache) - tabs[offset].x_cache) > limit) { + offset++; + } + + update(); +} + +void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) { + cb_displaypolicy=p_policy; + update(); +} void Tabs::_bind_methods() { @@ -648,6 +745,7 @@ void Tabs::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_tab","title","icon:Texture"),&Tabs::add_tab); ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&Tabs::set_tab_align); ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align); + ObjectTypeDB::bind_method(_MD("ensure_tab_visible","idx"),&Tabs::ensure_tab_visible); ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab"))); ADD_SIGNAL(MethodInfo("right_button_pressed",PropertyInfo(Variant::INT,"tab"))); @@ -660,10 +758,10 @@ void Tabs::_bind_methods() { BIND_CONSTANT( ALIGN_CENTER ); BIND_CONSTANT( ALIGN_RIGHT ); - BIND_CONSTANT( SHOW_ACTIVE_ONLY ); - BIND_CONSTANT( SHOW_ALWAYS ); - BIND_CONSTANT( SHOW_HOVER ); - BIND_CONSTANT( SHOW_NEVER ); + BIND_CONSTANT( CLOSE_BUTTON_SHOW_ACTIVE_ONLY ); + BIND_CONSTANT( CLOSE_BUTTON_SHOW_ALWAYS ); + BIND_CONSTANT( CLOSE_BUTTON_SHOW_NEVER ); + } @@ -673,8 +771,13 @@ Tabs::Tabs() { tab_align=ALIGN_CENTER; rb_hover=-1; rb_pressing=false; + hilite_arrow=-1; cb_hover=-1; cb_pressing=false; - cb_displaypolicy = SHOW_NEVER; // Default : no close button + cb_displaypolicy = CLOSE_BUTTON_SHOW_NEVER; // Default : no close button + offset=0; + max_drawn_tab=0; + + } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 1a8352bc93..5a4533c3d2 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -45,10 +45,9 @@ public: enum CloseButtonDisplayPolicy { - SHOW_ALWAYS, - SHOW_ACTIVE_ONLY, - SHOW_HOVER, - SHOW_NEVER + CLOSE_BUTTON_SHOW_NEVER, + CLOSE_BUTTON_SHOW_ACTIVE_ONLY, + CLOSE_BUTTON_SHOW_ALWAYS, }; private: @@ -59,12 +58,21 @@ private: Ref<Texture> icon; int ofs_cache; int size_cache; + int x_cache; + int x_size_cache; + Ref<Texture> right_button; Rect2 rb_rect; - Ref<Texture> close_button; Rect2 cb_rect; + }; + + int offset; + int max_drawn_tab; + int hilite_arrow; + bool buttons_visible; + bool missing_right; Vector<Tab> tabs; int current; Control *_get_tab(int idx) const; @@ -79,6 +87,9 @@ private: int hover; // hovered tab + int get_tab_width(int p_idx) const; + void _ensure_no_over_offset(); + protected: void _input_event(const InputEvent& p_event); @@ -98,13 +109,11 @@ public: void set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button); Ref<Texture> get_tab_right_button(int p_tab) const; - void set_tab_close_button(int p_tab, const Ref<Texture>& p_close_button); - Ref<Texture> get_tab_close_button(int p_tab) const; - void set_tab_close_display_policy(CloseButtonDisplayPolicy p_cb_displaypolicy); - void set_tab_align(TabAlign p_align); TabAlign get_tab_align() const; + void set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy); + int get_tab_count() const; void set_current_tab(int p_current); int get_current_tab() const; @@ -113,6 +122,8 @@ public: void clear_tabs(); + void ensure_tab_visible(int p_idx); + Size2 get_minimum_size() const; Tabs(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5415484009..7f7c8c023c 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -29,6 +29,7 @@ #include "text_edit.h" #include "os/keyboard.h" +#include "os/input.h" #include "os/os.h" #include "globals.h" @@ -349,6 +350,29 @@ void TextEdit::_update_scrollbars() { updating_scrolls=false; } +void TextEdit::_click_selection_held() { + + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode!=Selection::MODE_NONE) { + + Point2 mp = Input::get_singleton()->get_mouse_pos()-get_global_pos(); + + int row,col; + _get_mouse_pos(Point2i(mp.x,mp.y), row,col); + + select(selection.selecting_line,selection.selecting_column,row,col); + + cursor_set_line( row ); + cursor_set_column( col ); + update(); + + click_select_held->start(); + + } else { + + click_select_held->stop(); + } +} + void TextEdit::_notification(int p_what) { @@ -815,7 +839,7 @@ void TextEdit::_notification(int p_what) { } - if (cursor.column==str.length() && cursor.line==line) { + if (cursor.column==str.length() && cursor.line==line && (char_ofs+char_margin)>=xmargin_beg) { cursor_pos=Point2i( char_ofs+char_margin, ofs_y ); VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color); @@ -1292,6 +1316,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { update(); } } else { + + if (mb.button_index==BUTTON_LEFT) + click_select_held->stop(); // notify to show soft keyboard notification(NOTIFICATION_FOCUS_ENTER); @@ -1304,16 +1331,18 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (mm.button_mask&BUTTON_MASK_LEFT) { - int row,col; - _get_mouse_pos(Point2i(mm.x,mm.y), row,col); - if (selection.selecting_mode!=Selection::MODE_NONE) { + + int row,col; + _get_mouse_pos(Point2i(mm.x,mm.y), row,col); select(selection.selecting_line,selection.selecting_column,row,col); cursor_set_line( row ); cursor_set_column( col ); update(); + + click_select_held->start(); } @@ -1610,6 +1639,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { else break; } + if(auto_indent){ + // indent once again if previous line will end with ':' + // (i.e. colon precedes current cursor position) + if(cursor.column>0 && text[cursor.line][cursor.column-1]==':') { + ins+="\t"; + } + } _insert_text_at_cursor(ins); _push_current_op(); @@ -1704,6 +1740,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } break; + case KEY_KP_4: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_left + } case KEY_LEFT: { if (k.mod.shift) @@ -1750,6 +1793,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _post_shift_selection(); } break; + case KEY_KP_6: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_right + } case KEY_RIGHT: { if (k.mod.shift) @@ -1793,6 +1843,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _post_shift_selection(); } break; + case KEY_KP_8: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_up + } case KEY_UP: { if (k.mod.shift) @@ -1813,6 +1870,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _cancel_code_hint(); } break; + case KEY_KP_2: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_down + } case KEY_DOWN: { if (k.mod.shift) @@ -1901,6 +1965,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { update(); } break; + case KEY_KP_7: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_home + } #ifdef APPLE_STYLE_KEYS case KEY_HOME: { @@ -1914,18 +1985,6 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _post_shift_selection(); } break; - case KEY_END: { - - if (k.mod.shift) - _pre_shift_selection(); - - cursor_set_line(text.size()-1); - - if (k.mod.shift) - _post_shift_selection(); - - } break; - #else case KEY_HOME: { @@ -1956,6 +2015,27 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { completion_hint=""; } break; +#endif + case KEY_KP_1: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_end + } +#ifdef APPLE_STYLE_KEYS + case KEY_END: { + + if (k.mod.shift) + _pre_shift_selection(); + + cursor_set_line(text.size()-1); + + if (k.mod.shift) + _post_shift_selection(); + + } break; +#else case KEY_END: { if (k.mod.shift) @@ -1973,6 +2053,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } break; #endif + case KEY_KP_9: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_pageup + } case KEY_PAGEUP: { if (k.mod.shift) @@ -1988,6 +2075,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } break; + case KEY_KP_3: { + if (k.unicode != 0) { + scancode_handled = false; + break; + } + // numlock disabled. fallthrough to key_pageup + } case KEY_PAGEDOWN: { if (k.mod.shift) @@ -2869,6 +2963,10 @@ bool TextEdit::is_syntax_coloring_enabled() const { return syntax_coloring; } +void TextEdit::set_auto_indent(bool p_auto_indent) { + auto_indent = p_auto_indent; +} + void TextEdit::cut() { if (!selection.active) @@ -3686,6 +3784,7 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit); ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op); + ObjectTypeDB::bind_method(_MD("_click_selection_held"),&TextEdit::_click_selection_held); BIND_CONSTANT( SEARCH_MATCH_CASE ); BIND_CONSTANT( SEARCH_WHOLE_WORDS ); @@ -3701,10 +3800,10 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count); ObjectTypeDB::bind_method(_MD("get_text"),&TextEdit::get_text); - ObjectTypeDB::bind_method(_MD("get_line"),&TextEdit::get_line); + ObjectTypeDB::bind_method(_MD("get_line","line"),&TextEdit::get_line); - ObjectTypeDB::bind_method(_MD("cursor_set_column","column"),&TextEdit::cursor_set_column); - ObjectTypeDB::bind_method(_MD("cursor_set_line","line"),&TextEdit::cursor_set_line); + ObjectTypeDB::bind_method(_MD("cursor_set_column","column","adjust_viewport"),&TextEdit::cursor_set_column,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("cursor_set_line","line","adjust_viewport"),&TextEdit::cursor_set_line,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column); ObjectTypeDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line); @@ -3800,6 +3899,11 @@ TextEdit::TextEdit() { idle_detect->set_one_shot(true); idle_detect->set_wait_time(GLOBAL_DEF("display/text_edit_idle_detect_sec",3)); idle_detect->connect("timeout", this,"_push_current_op"); + + click_select_held = memnew( Timer ); + add_child(click_select_held); + click_select_held->set_wait_time(0.05); + click_select_held->connect("timeout", this,"_click_selection_held"); #if 0 syntax_coloring=true; @@ -3836,7 +3940,7 @@ TextEdit::TextEdit() { next_operation_is_complex=false; auto_brace_completion_enabled=false; brace_matching_enabled=false; - + auto_indent=false; } TextEdit::~TextEdit() diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 059e15dcff..2ca5ab054a 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -213,11 +213,13 @@ class TextEdit : public Control { bool auto_brace_completion_enabled; bool brace_matching_enabled; + bool auto_indent; bool cut_copy_line; uint64_t last_dblclk; Timer *idle_detect; + Timer *click_select_held; HScrollBar *h_scroll; VScrollBar *v_scroll; bool updating_scrolls; @@ -239,6 +241,7 @@ class TextEdit : public Control { void adjust_viewport_to_cursor(); void _scroll_moved(double); void _update_scrollbars(); + void _click_selection_held(); void _pre_shift_selection(); void _post_shift_selection(); @@ -323,6 +326,7 @@ public: brace_matching_enabled=p_enabled; update(); } + void set_auto_indent(bool p_auto_indent); void cursor_set_column(int p_col, bool p_adjust_viewport=true); void cursor_set_line(int p_row, bool p_adjust_viewport=true); diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 5b2caecb5b..c885b2d73e 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,22 +42,22 @@ Size2 TextureButton::get_minimum_size() const { else rscale= hover->get_size(); } else - rscale= pressed->get_size()*scale; + rscale=pressed->get_size(); } else rscale= normal->get_size(); - return rscale*scale; + return rscale*scale.abs(); } bool TextureButton::has_point(const Point2& p_point) const { - if (scale[0] <= 0 || scale[1] <= 0) { + if (scale[0] == 0 || scale[1] == 0) { return false; } - Point2 ppos = p_point/scale; + Point2 ppos = p_point/scale.abs(); if (click_mask.is_valid()) { @@ -145,7 +145,7 @@ void TextureButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture); ObjectTypeDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture); ObjectTypeDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask); - ObjectTypeDB::bind_method(_MD("set_scale","scale"),&TextureButton::set_scale); + ObjectTypeDB::bind_method(_MD("set_texture_scale","scale"),&TextureButton::set_texture_scale); ObjectTypeDB::bind_method(_MD("set_modulate","color"),&TextureButton::set_modulate); ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture); @@ -154,7 +154,7 @@ void TextureButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture); ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture); ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask); - ObjectTypeDB::bind_method(_MD("get_scale"),&TextureButton::get_scale); + ObjectTypeDB::bind_method(_MD("get_texture_scale"),&TextureButton::get_texture_scale); ObjectTypeDB::bind_method(_MD("get_modulate"),&TextureButton::get_modulate); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture")); @@ -163,7 +163,7 @@ void TextureButton::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture")); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture")); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ; - ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_scale"), _SCS("get_scale")); + ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_texture_scale"), _SCS("get_texture_scale")); ADD_PROPERTYNO(PropertyInfo(Variant::COLOR,"params/modulate"), _SCS("set_modulate"), _SCS("get_modulate")); } @@ -232,14 +232,14 @@ void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) { focused = p_focused; }; -void TextureButton::set_scale(Size2 p_scale) { +void TextureButton::set_texture_scale(Size2 p_scale) { scale=p_scale; minimum_size_changed(); update(); } -Size2 TextureButton::get_scale() const{ +Size2 TextureButton::get_texture_scale() const{ return scale; } diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index 01924c1c15..0556df8061 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -68,8 +68,8 @@ public: Ref<Texture> get_focused_texture() const; Ref<BitMap> get_click_mask() const; - void set_scale(Size2 p_scale); - Size2 get_scale() const; + void set_texture_scale(Size2 p_scale); + Size2 get_texture_scale() const; void set_modulate(const Color& p_modulate); Color get_modulate() const; diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp index 5a6bc86638..73fecf591a 100644 --- a/scene/gui/texture_frame.cpp +++ b/scene/gui/texture_frame.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/texture_frame.h b/scene/gui/texture_frame.h index 0ccbf5a591..f6fe6ae89d 100644 --- a/scene/gui/texture_frame.h +++ b/scene/gui/texture_frame.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index c8930add6e..e05d35a81d 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress.h index 7187fd5f07..a4bbd71e94 100644 --- a/scene/gui/texture_progress.h +++ b/scene/gui/texture_progress.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/tool_button.cpp b/scene/gui/tool_button.cpp index d5bcb73476..fd27800384 100644 --- a/scene/gui/tool_button.cpp +++ b/scene/gui/tool_button.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/tool_button.h b/scene/gui/tool_button.h index 648d776b51..f48d7d413c 100644 --- a/scene/gui/tool_button.h +++ b/scene/gui/tool_button.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 16a12fe407..e81c08dbea 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -672,7 +672,7 @@ void TreeItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("clear_custom_bg_color","column"),&TreeItem::clear_custom_bg_color); ObjectTypeDB::bind_method(_MD("get_custom_bg_color","column"),&TreeItem::get_custom_bg_color); - ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture"),&TreeItem::add_button); + ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx"),&TreeItem::add_button); ObjectTypeDB::bind_method(_MD("get_button_count","column"),&TreeItem::get_button_count); ObjectTypeDB::bind_method(_MD("get_button:Texture","column","button_idx"),&TreeItem::get_button); ObjectTypeDB::bind_method(_MD("erase_button","column","button_idx"),&TreeItem::erase_button); @@ -1369,7 +1369,40 @@ Rect2 Tree::search_item_rect(TreeItem *p_from, TreeItem *p_item) { } +void Tree::_range_click_timeout() { + if (range_item_last && !range_drag_enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + + Point2 pos = get_local_mouse_pos()-cache.bg->get_offset(); + if (show_column_titles) { + pos.y-=_get_title_button_height(); + + if (pos.y<0) { + range_click_timer->stop(); + return; + } + } + + click_handled=false; + InputModifierState mod = InputModifierState(); // should be irrelevant.. + + blocked++; + propagate_mouse_event(pos+cache.offset, 0, 0, false, root, BUTTON_LEFT, mod); + blocked--; + + if (range_click_timer->is_one_shot()) { + range_click_timer->set_wait_time(0.05); + range_click_timer->set_one_shot(false); + range_click_timer->start(); + } + + if (!click_handled) + range_click_timer->stop(); + + } else { + range_click_timer->stop(); + } +} int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod) { @@ -1381,6 +1414,10 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ if (!skip && p_pos.y<item_h) { // check event! + if (range_click_timer->get_time_left() > 0 && p_item != range_item_last) { + return -1; + } + if (!hide_folding && (p_pos.x >=x_ofs && p_pos.x < (x_ofs+cache.item_margin) )) { @@ -1564,9 +1601,25 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ bool up=p_pos.y < (item_h /2); if (p_button==BUTTON_LEFT) { + + if (range_click_timer->get_time_left() == 0) { + + range_item_last=p_item; + range_up_last=up; + + range_click_timer->set_wait_time(0.6); + range_click_timer->set_one_shot(true); + range_click_timer->start(); + + } else if (up != range_up_last) { + + return -1; // break. avoid changing direction on mouse held + } + p_item->set_range( col, c.val + (up?1.0:-1.0) * c.step ); item_edited(col,p_item); + } else if (p_button==BUTTON_RIGHT) { p_item->set_range( col, (up?c.max:c.min) ); @@ -1668,10 +1721,25 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } +void Tree::_text_editor_modal_close() { + + if ( Input::get_singleton()->is_key_pressed(KEY_ESCAPE) || + Input::get_singleton()->is_key_pressed(KEY_ENTER) || + Input::get_singleton()->is_key_pressed(KEY_RETURN) ) { + + return; + } + + + text_editor_enter(text_editor->get_text()); +} + + void Tree::text_editor_enter(String p_text) { text_editor->hide(); + value_editor->hide(); if (!popup_edited_item) return; @@ -2031,7 +2099,6 @@ void Tree::_input_event(InputEvent p_event) { Cache::ClickType old_hover = cache.hover_type; int old_index = cache.hover_index; - cache.hover_type=Cache::CLICK_NONE; cache.hover_index=0; if (show_column_titles) { @@ -2077,8 +2144,7 @@ void Tree::_input_event(InputEvent p_event) { float diff_y = -b.relative_y; diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y); diff_y*=0.1; - range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); - + range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); popup_edited_item->set_range(popup_edited_item_col,range_drag_base); item_edited(popup_edited_item_col,popup_edited_item); @@ -2108,6 +2174,8 @@ void Tree::_input_event(InputEvent p_event) { if (b.button_index==BUTTON_LEFT) { + range_click_timer->stop(); + if (pressing_for_editor) { if (range_drag_enabled) { @@ -2115,18 +2183,9 @@ void Tree::_input_event(InputEvent p_event) { range_drag_enabled=false; Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); - } else { - text_editor->set_pos(pressing_item_rect.pos); - text_editor->set_size(pressing_item_rect.size); + } else + edit_selected(); - text_editor->clear(); - text_editor->set_text( pressing_for_editor_text ); - text_editor->select_all(); - - text_editor->show_modal(); - text_editor->grab_focus(); - - } pressing_for_editor=false; } @@ -2228,6 +2287,7 @@ void Tree::_input_event(InputEvent p_event) { } break; case BUTTON_WHEEL_UP: { + v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 ); } break; case BUTTON_WHEEL_DOWN: { @@ -3135,9 +3195,11 @@ bool Tree::is_folding_hidden() const { void Tree::_bind_methods() { + ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&Tree::_range_click_timeout); ObjectTypeDB::bind_method(_MD("_input_event"),&Tree::_input_event); ObjectTypeDB::bind_method(_MD("_popup_select"),&Tree::popup_select); ObjectTypeDB::bind_method(_MD("_text_editor_enter"),&Tree::text_editor_enter); + ObjectTypeDB::bind_method(_MD("_text_editor_modal_close"),&Tree::_text_editor_modal_close); ObjectTypeDB::bind_method(_MD("_value_editor_changed"),&Tree::value_editor_changed); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&Tree::_scroll_moved); @@ -3145,11 +3207,11 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("create_item:TreeItem","parent:TreeItem"),&Tree::_create_item,DEFVAL((Object*)NULL)); ObjectTypeDB::bind_method(_MD("get_root:TreeItem"),&Tree::get_root); - ObjectTypeDB::bind_method(_MD("set_column_min_width"),&Tree::set_column_min_width); - ObjectTypeDB::bind_method(_MD("set_column_expand"),&Tree::set_column_expand); - ObjectTypeDB::bind_method(_MD("get_column_width"),&Tree::get_column_width); + ObjectTypeDB::bind_method(_MD("set_column_min_width","column","min_width"),&Tree::set_column_min_width); + ObjectTypeDB::bind_method(_MD("set_column_expand","column","expand"),&Tree::set_column_expand); + ObjectTypeDB::bind_method(_MD("get_column_width","column"),&Tree::get_column_width); - ObjectTypeDB::bind_method(_MD("set_hide_root"),&Tree::set_hide_root); + ObjectTypeDB::bind_method(_MD("set_hide_root","enable"),&Tree::set_hide_root); ObjectTypeDB::bind_method(_MD("get_next_selected:TreeItem","from:TreeItem"),&Tree::_get_next_selected); ObjectTypeDB::bind_method(_MD("get_selected:TreeItem"),&Tree::get_selected); ObjectTypeDB::bind_method(_MD("get_selected_column"),&Tree::get_selected_column); @@ -3229,9 +3291,14 @@ Tree::Tree() { add_child(h_scroll); add_child(v_scroll); + range_click_timer = memnew( Timer ); + range_click_timer->connect("timeout",this,"_range_click_timeout"); + add_child(range_click_timer); + h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); text_editor->connect("text_entered", this,"_text_editor_enter"); + text_editor->connect("modal_close", this,"_text_editor_modal_close"); popup_menu->connect("item_pressed", this,"_popup_select"); value_editor->connect("value_changed", this,"_value_editor_changed"); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 8fb9b802a1..e4d349978c 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -127,7 +127,7 @@ friend class Tree; - TreeItem(Tree *p_tree); + TreeItem(Tree *p_tree); void _changed_notify(int p_cell); @@ -301,6 +301,11 @@ friend class TreeItem; Vector<ColumnInfo> columns; + Timer *range_click_timer; + TreeItem *range_item_last; + bool range_up_last; + void _range_click_timeout(); + int compute_item_height(TreeItem *p_item) const; int get_item_height(TreeItem *p_item) const; // void draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); @@ -309,6 +314,7 @@ friend class TreeItem; void select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col,TreeItem *p_prev=NULL,bool *r_in_range=NULL); int propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod); void text_editor_enter(String p_text); + void _text_editor_modal_close(); void value_editor_changed(double p_value); void popup_select(int p_option); diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 9b9c797ed9..517cd414c5 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "video_player.h" - +#include "os/os.h" int VideoPlayer::InternalStream::get_channel_count() const { @@ -117,8 +117,9 @@ void VideoPlayer::_notification(int p_notification) { case NOTIFICATION_ENTER_TREE: { //set_idle_process(false); //don't annoy - if (stream.is_valid() && autoplay && !get_tree()->is_editor_hint()) + if (stream.is_valid() && autoplay && !get_tree()->is_editor_hint()) { play(); + } } break; case NOTIFICATION_PROCESS: { @@ -130,7 +131,7 @@ void VideoPlayer::_notification(int p_notification) { if (!playback->is_playing()) return; - double audio_time = AudioServer::get_singleton()->get_mix_time(); + double audio_time = OS::get_singleton()->get_ticks_usec()/1000000.0; //AudioServer::get_singleton()->get_mix_time(); double delta = last_audio_time==0?0:audio_time-last_audio_time; last_audio_time=audio_time; @@ -270,6 +271,7 @@ void VideoPlayer::set_paused(bool p_paused) { playback->set_paused(p_paused); set_process(!p_paused); }; + last_audio_time = 0; }; bool VideoPlayer::is_paused() const { @@ -338,6 +340,13 @@ float VideoPlayer::get_stream_pos() const { return playback->get_pos(); }; +Ref<Texture> VideoPlayer::get_video_texture() { + + if (playback.is_valid()) + return playback->get_texture(); + + return Ref<Texture> (); +} void VideoPlayer::set_autoplay(bool p_enable) { @@ -384,6 +393,8 @@ void VideoPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_buffering_msec","msec"),&VideoPlayer::set_buffering_msec); ObjectTypeDB::bind_method(_MD("get_buffering_msec"),&VideoPlayer::get_buffering_msec); + ObjectTypeDB::bind_method(_MD("get_video_texutre:Texture"), &VideoPlayer::get_video_texture ); + ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/audio_track",PROPERTY_HINT_RANGE,"0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track") ); ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream/stream", PROPERTY_HINT_RESOURCE_TYPE,"VideoStream"), _SCS("set_stream"), _SCS("get_stream") ); // ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), _SCS("set_loop"), _SCS("has_loop") ); diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h index c485e3d6b6..9ce1ba78f4 100644 --- a/scene/gui/video_player.h +++ b/scene/gui/video_player.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -88,6 +88,8 @@ public: bool has_expand() const; + Ref<Texture> get_video_texture(); + void set_stream(const Ref<VideoStream> &p_stream); Ref<VideoStream> get_stream() const; @@ -110,8 +112,8 @@ public: void set_autoplay(bool p_vol); bool has_autoplay() const; - void set_audio_track(int p_track); - int get_audio_track() const; + void set_audio_track(int p_track); + int get_audio_track() const; void set_buffering_msec(int p_msec); int get_buffering_msec() const; diff --git a/scene/io/resource_format_image.cpp b/scene/io/resource_format_image.cpp index f67d50b56c..c80975dbfe 100644 --- a/scene/io/resource_format_image.cpp +++ b/scene/io/resource_format_image.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/io/resource_format_image.h b/scene/io/resource_format_image.h index b5ec5a1200..6388aa641f 100644 --- a/scene/io/resource_format_image.h +++ b/scene/io/resource_format_image.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index 00b800b28b..9cf349eb7b 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/io/resource_format_wav.h b/scene/io/resource_format_wav.h index a74da041c1..4918d5c2e7 100644 --- a/scene/io/resource_format_wav.h +++ b/scene/io/resource_format_wav.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index ee3d7f5afd..e921795628 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index edd00c1a7a..809b3fae7f 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 12f6086bf0..f822107918 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -14,11 +14,24 @@ bool InstancePlaceholder::_set(const StringName& p_name, const Variant& p_value) bool InstancePlaceholder::_get(const StringName& p_name,Variant &r_ret) const{ + for (const List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { + if (E->get().name==p_name) { + r_ret=E->get().value; + return true; + } + } return false; } void InstancePlaceholder::_get_property_list( List<PropertyInfo> *p_list) const{ + for (const List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { + PropertyInfo pi; + pi.name=E->get().name; + pi.type=E->get().value.get_type(); + pi.usage=PROPERTY_USAGE_STORAGE; + p_list->push_back(pi); + } } diff --git a/scene/main/misc.cpp b/scene/main/misc.cpp index 108621baa5..35d8b4cdfb 100644 --- a/scene/main/misc.cpp +++ b/scene/main/misc.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/misc.h b/scene/main/misc.h index e7894aa68d..1c5bc7208e 100644 --- a/scene/main/misc.h +++ b/scene/main/misc.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 97c36ff71b..450578a241 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -33,6 +33,7 @@ #include "scene/resources/packed_scene.h" #include "io/resource_loader.h" #include "viewport.h" +#include "instance_placeholder.h" VARIANT_ENUM_CAST(Node::PauseMode); @@ -628,11 +629,11 @@ String Node::validate_child_name(const String& p_name) const { } -void Node::_validate_child_name(Node *p_child) { +void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { /* Make sure the name is unique */ - if (node_hrcr) { + if (node_hrcr || p_force_human_readable) { //this approach to autoset node names is human readable but very slow //it's turned on while running in the editor @@ -700,11 +701,7 @@ void Node::_validate_child_name(Node *p_child) { if (!unique) { node_hrcr_count.ref(); -#ifdef DEBUG_ENABLED - String name = "@"+String(p_child->get_type_name())+itos(node_hrcr_count.get()); -#else - String name = "@"+itos(node_hrcr_count.get()); -#endif + String name = "@"+String(p_child->get_name())+"@"+itos(node_hrcr_count.get()); p_child->data.name=name; } } @@ -732,24 +729,27 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { } -void Node::add_child(Node *p_child) { +void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_NULL(p_child); /* Fail if node has a parent */ - ERR_EXPLAIN("Can't add child "+p_child->get_name()+" to itself.") - ERR_FAIL_COND( p_child==this ); // adding to itself! + if (p_child==this) { + ERR_EXPLAIN("Can't add child "+p_child->get_name()+" to itself.") + ERR_FAIL_COND( p_child==this ); // adding to itself! + } ERR_EXPLAIN("Can't add child, already has a parent"); ERR_FAIL_COND( p_child->data.parent ); ERR_EXPLAIN("Can't add child while a notification is happening"); ERR_FAIL_COND( data.blocked > 0 ); /* Validate name */ - _validate_child_name(p_child); + _validate_child_name(p_child,p_legible_unique_name); _add_child_nocheck(p_child,p_child->data.name); } + void Node::_propagate_validate_owner() { if (data.owner) { @@ -803,6 +803,7 @@ void Node::remove_child(Node *p_child) { } ERR_FAIL_COND( idx==-1 ); + //ERR_FAIL_COND( p_child->data.blocked > 0 ); //if (data.scene) { does not matter @@ -857,7 +858,10 @@ Node *Node::_get_child_by_name(const StringName& p_name) const { Node *Node::_get_node(const NodePath& p_path) const { - ERR_FAIL_COND_V( !data.inside_tree && p_path.is_absolute(), NULL ); + if (!data.inside_tree && p_path.is_absolute()) { + ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); + ERR_FAIL_V(NULL); + } Node *current=NULL; Node *root=NULL; @@ -1468,7 +1472,14 @@ Node *Node::duplicate(bool p_use_instancing) const { bool instanced=false; - if (p_use_instancing && get_filename()!=String()) { + if (cast_to<InstancePlaceholder>()) { + + const InstancePlaceholder *ip = cast_to<const InstancePlaceholder>(); + InstancePlaceholder *nip = memnew( InstancePlaceholder ); + nip->set_instance_path( ip->get_instance_path() ); + node=nip; + + } else if (p_use_instancing && get_filename()!=String()) { Ref<PackedScene> res = ResourceLoader::load(get_filename()); ERR_FAIL_COND_V(res.is_null(),NULL); @@ -1507,6 +1518,15 @@ Node *Node::duplicate(bool p_use_instancing) const { node->set_name(get_name()); + List<GroupInfo> gi; + get_groups(&gi); + for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) { + + node->add_to_group(E->get().name, E->get().persistent); + } + + _duplicate_signals(this, node); + for(int i=0;i<get_child_count();i++) { if (get_child(i)->data.parent_owned) @@ -1984,7 +2004,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name); ObjectTypeDB::bind_method(_MD("get_name"),&Node::get_name); - ObjectTypeDB::bind_method(_MD("add_child","node:Node"),&Node::add_child); + ObjectTypeDB::bind_method(_MD("add_child","node:Node","legible_unique_name"),&Node::add_child,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("remove_child","node:Node"),&Node::remove_child); //ObjectTypeDB::bind_method(_MD("remove_and_delete_child","node:Node"),&Node::remove_and_delete_child); ObjectTypeDB::bind_method(_MD("get_child_count"),&Node::get_child_count); @@ -2002,7 +2022,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_greater_than","node:Node"),&Node::is_greater_than); ObjectTypeDB::bind_method(_MD("get_path"),&Node::get_path); ObjectTypeDB::bind_method(_MD("get_path_to","node:Node"),&Node::get_path_to); - ObjectTypeDB::bind_method(_MD("add_to_group","group"),&Node::add_to_group,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("add_to_group","group","persistent"),&Node::add_to_group,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("remove_from_group","group"),&Node::remove_from_group); ObjectTypeDB::bind_method(_MD("is_in_group","group"),&Node::is_in_group); ObjectTypeDB::bind_method(_MD("move_child","child_node:Node","to_pos"),&Node::move_child); @@ -2064,6 +2084,8 @@ void Node::_bind_methods() { BIND_CONSTANT( NOTIFICATION_UNPARENTED ); BIND_CONSTANT( NOTIFICATION_PAUSED ); BIND_CONSTANT( NOTIFICATION_UNPAUSED ); + BIND_CONSTANT( NOTIFICATION_INSTANCED ); + BIND_CONSTANT( PAUSE_MODE_INHERIT ); diff --git a/scene/main/node.h b/scene/main/node.h index 87fa4dd6ca..4d05dd381c 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -122,7 +122,7 @@ private: - void _validate_child_name(Node *p_name); + void _validate_child_name(Node *p_name, bool p_force_human_readable=false); void _propagate_reverse_notification(int p_notification); void _propagate_deferred_notification(int p_notification, bool p_reverse); @@ -187,7 +187,7 @@ public: StringName get_name() const; void set_name(const String& p_name); - void add_child(Node *p_child); + void add_child(Node *p_child,bool p_legible_unique_name=false); void remove_child(Node *p_child); int get_child_count() const; diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp index f49f626e78..219eea770a 100644 --- a/scene/main/resource_preloader.cpp +++ b/scene/main/resource_preloader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/resource_preloader.h b/scene/main/resource_preloader.h index b3e7496fb7..b06e558b59 100644 --- a/scene/main/resource_preloader.h +++ b/scene/main/resource_preloader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index adf053f5c9..8e2d6aa669 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -330,7 +330,8 @@ void SceneTree::input_text( const String& p_text ) { root_lock++; - call_group(GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"input",p_text); + call_group(GROUP_CALL_REALTIME,"_viewports","_vp_input_text",p_text); //special one for GUI, as controls use their own process check + root_lock--; } @@ -620,6 +621,14 @@ void SceneTree::set_editor_hint(bool p_enabled) { editor_hint=p_enabled; } +bool SceneTree::is_node_being_edited(const Node* p_node) const { +#ifdef TOOLS_ENABLED + return editor_hint && edited_scene_root && edited_scene_root->is_a_parent_of(p_node); +#else + return false; +#endif +} + bool SceneTree::is_editor_hint() const { return editor_hint; @@ -965,6 +974,10 @@ Array SceneTree::_get_nodes_in_group(const StringName& p_group) { return ret; } +bool SceneTree::has_group(const StringName& p_identifier) const { + + return group_map.has(p_identifier); +} void SceneTree::get_nodes_in_group(const StringName& p_group,List<Node*> *p_list) { @@ -1586,9 +1599,10 @@ void SceneTree::_bind_methods() { ObjectTypeDB::bind_method(_MD("notify_group","call_flags","group","notification"),&SceneTree::notify_group); ObjectTypeDB::bind_method(_MD("set_group","call_flags","group","property","value"),&SceneTree::set_group); - ObjectTypeDB::bind_method(_MD("get_nodes_in_group"),&SceneTree::_get_nodes_in_group); + ObjectTypeDB::bind_method(_MD("get_nodes_in_group","group"),&SceneTree::_get_nodes_in_group); ObjectTypeDB::bind_method(_MD("get_root:Viewport"),&SceneTree::get_root); + ObjectTypeDB::bind_method(_MD("has_group","name"),&SceneTree::has_group); ObjectTypeDB::bind_method(_MD("set_auto_accept_quit","enabled"),&SceneTree::set_auto_accept_quit); diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index 8d9021d24e..c6fc124345 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -279,6 +279,8 @@ public: void set_editor_hint(bool p_enabled); bool is_editor_hint() const; + bool is_node_being_edited(const Node* p_node) const; + void set_pause(bool p_enabled); bool is_paused() const; @@ -318,6 +320,8 @@ public: void queue_delete(Object *p_object); void get_nodes_in_group(const StringName& p_group,List<Node*> *p_list); + bool has_group(const StringName& p_identifier) const; + void set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect,const Size2 p_minsize); diff --git a/scene/main/scene_singleton.cpp b/scene/main/scene_singleton.cpp index 69eb6e24d9..3dcc6b1204 100644 --- a/scene/main/scene_singleton.cpp +++ b/scene/main/scene_singleton.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/scene_singleton.h b/scene/main/scene_singleton.h index 25157a26ac..0b209f7944 100644 --- a/scene/main/scene_singleton.h +++ b/scene/main/scene_singleton.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 1bd22a9db1..2c23b62b12 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/timer.h b/scene/main/timer.h index 4b9cecba84..0baea76fad 100644 --- a/scene/main/timer.h +++ b/scene/main/timer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index d19b5767c2..a1bfbda1fc 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -43,6 +43,13 @@ #include "scene/2d/collision_object_2d.h" +#include "scene/gui/panel.h" +#include "scene/gui/label.h" +#include "scene/main/timer.h" +#include "scene/scene_string_names.h" + +#include "globals.h" + int RenderTargetTexture::get_width() const { ERR_FAIL_COND_V(!vp,0); @@ -92,8 +99,42 @@ RenderTargetTexture::RenderTargetTexture(Viewport *p_vp){ flags=0; } +///////////////////////////////////// + +class TooltipPanel : public Panel { + + OBJ_TYPE(TooltipPanel,Panel) +public: + TooltipPanel() {}; + +}; + +class TooltipLabel : public Label { + + OBJ_TYPE(TooltipLabel,Label) +public: + TooltipLabel() {}; + +}; +Viewport::GUI::GUI() { + + + mouse_focus=NULL; + mouse_focus_button=-1; + key_focus=NULL; + mouse_over=NULL; + + cancelled_input_ID=0; + tooltip=NULL; + tooltip_popup=NULL; + tooltip_label=NULL; + subwindow_order_dirty=false; +} + + +///////////////////////////////////// void Viewport::_update_stretch_transform() { if (size_override_stretch && size_override) { @@ -121,11 +162,10 @@ void Viewport::_update_rect() { if (!is_inside_tree()) return; - Node *parent = get_parent(); - if (!render_target && parent && parent->cast_to<Control>()) { + if (!render_target && parent_control) { - Control *c = parent->cast_to<Control>(); + Control *c = parent_control; rect.pos=Point2(); rect.size=c->get_size(); @@ -134,6 +174,7 @@ void Viewport::_update_rect() { VisualServer::ViewportRect vr; vr.x=rect.pos.x; vr.y=rect.pos.y; + if (render_target) { vr.x=0; vr.y=0; @@ -165,11 +206,10 @@ void Viewport::_parent_draw() { void Viewport::_parent_visibility_changed() { - Node *parent = get_parent(); - if (parent && parent->cast_to<Control>()) { + if (parent_control) { - Control *c = parent->cast_to<Control>(); + Control *c = parent_control; VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,c->is_visible()); _update_listener(); @@ -182,11 +222,9 @@ void Viewport::_parent_visibility_changed() { void Viewport::_vp_enter_tree() { - Node *parent = get_parent(); - //none? - if (parent && parent->cast_to<Control>()) { + if (parent_control) { - Control *cparent=parent->cast_to<Control>(); + Control *cparent=parent_control; RID parent_ci = cparent->get_canvas_item(); ERR_FAIL_COND(!parent_ci.is_valid()); canvas_item = VisualServer::get_singleton()->canvas_item_create(); @@ -194,8 +232,8 @@ void Viewport::_vp_enter_tree() { VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent_ci); VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false); VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport); - parent->connect("resized",this,"_parent_resized"); - parent->connect("visibility_changed",this,"_parent_visibility_changed"); + parent_control->connect("resized",this,"_parent_resized"); + parent_control->connect("visibility_changed",this,"_parent_visibility_changed"); } else if (!parent){ VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0); @@ -207,15 +245,14 @@ void Viewport::_vp_enter_tree() { void Viewport::_vp_exit_tree() { - Node *parent = get_parent(); - if (parent && parent->cast_to<Control>()) { + if (parent_control) { - parent->disconnect("resized",this,"_parent_resized"); + parent_control->disconnect("resized",this,"_parent_resized"); } - if (parent && parent->cast_to<Control>()) { + if (parent_control) { - parent->disconnect("visibility_changed",this,"_parent_visibility_changed"); + parent_control->disconnect("visibility_changed",this,"_parent_visibility_changed"); } if (canvas_item.is_valid()) { @@ -287,22 +324,32 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { + if (get_parent()) { + Node *parent=get_parent(); + if (parent) { + parent_control=parent->cast_to<Control>(); + } + } - if (!render_target) - _vp_enter_tree(); - this->parent=NULL; - Node *parent=get_parent(); + parent=NULL; + Node *parent_node=get_parent(); - if (parent) { + while(parent_node) { - while(parent && !(this->parent=parent->cast_to<Viewport>())) { + parent = parent_node->cast_to<Viewport>(); + if (parent) + break; - parent=parent->get_parent(); - } + parent_node=parent_node->get_parent(); } + + if (!render_target) + _vp_enter_tree(); + + current_canvas=find_world_2d()->get_canvas(); VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); @@ -359,7 +406,7 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { - + _gui_cancel_tooltip(); if (world_2d.is_valid()) world_2d->_remove_viewport(this); @@ -382,10 +429,17 @@ void Viewport::_notification(int p_what) { } remove_from_group("_viewports"); + parent_control=NULL; } break; case NOTIFICATION_FIXED_PROCESS: { + if (gui.tooltip_timer>=0) { + gui.tooltip_timer-=get_fixed_process_delta_time(); + if (gui.tooltip_timer<0) { + _gui_show_tooltip(); + } + } if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { @@ -577,7 +631,7 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF); + bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); ObjectID new_collider=0; if (col) { @@ -617,7 +671,7 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF); + bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); ObjectID new_collider=0; if (col) { if (result.collider) { @@ -1223,15 +1277,34 @@ void Viewport::_make_input_local(InputEvent& ev) { } +void Viewport::_vp_input_text(const String& p_text) { + + if (gui.key_focus) { + gui.key_focus->call("set_text",p_text); + } +} void Viewport::_vp_input(const InputEvent& p_ev) { + if (disable_input) + return; + +#ifdef TOOLS_ENABLED + if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + return; + } +#endif + + if (parent_control && !parent_control->is_visible()) + return; + if (render_target && to_screen_rect==Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates //they are converted to viewport coordinates + InputEvent ev = p_ev; _make_input_local(ev); input(ev); @@ -1240,6 +1313,17 @@ void Viewport::_vp_input(const InputEvent& p_ev) { void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { + if (disable_input) + return; + +#ifdef TOOLS_ENABLED + if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + return; + } +#endif + + if (parent_control && !parent_control->is_visible()) + return; if (render_target && to_screen_rect==Rect2()) return; //if render target, can't get input events @@ -1264,17 +1348,874 @@ void Viewport::warp_mouse(const Vector2& p_pos) { Input::get_singleton()->warp_mouse_pos(gpos); } + + +void Viewport::_gui_sort_subwindows() { + + if (!gui.subwindow_order_dirty) + return; + + + gui.modal_stack.sort_custom<Control::CComparator>(); + gui.subwindows.sort_custom<Control::CComparator>(); + + gui.subwindow_order_dirty=false; +} + +void Viewport::_gui_sort_modal_stack() { + + gui.modal_stack.sort_custom<Control::CComparator>(); +} + + +void Viewport::_gui_sort_roots() { + + if (!gui.roots_order_dirty) + return; + + gui.roots.sort_custom<Control::CComparator>(); + + gui.roots_order_dirty=false; +} + + +void Viewport::_gui_cancel_tooltip() { + + gui.tooltip=NULL; + gui.tooltip_timer=-1; + if (gui.tooltip_popup) { + gui.tooltip_popup->queue_delete(); + gui.tooltip_popup=NULL; + } + +} + +void Viewport::_gui_show_tooltip() { + + if (!gui.tooltip) { + return; + } + + String tooltip = gui.tooltip->get_tooltip( gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos) ); + if (tooltip.length()==0) + return; // bye + + if (gui.tooltip_popup) { + memdelete(gui.tooltip_popup); + gui.tooltip_popup=NULL; + } + + Control *rp = gui.tooltip->get_root_parent_control(); + if (!rp) + return; + + + gui.tooltip_popup = memnew( TooltipPanel ); + + rp->add_child(gui.tooltip_popup); + gui.tooltip_popup->force_parent_owned(); + gui.tooltip_label = memnew( TooltipLabel ); + gui.tooltip_popup->add_child(gui.tooltip_label); + gui.tooltip_popup->set_as_toplevel(true); + gui.tooltip_popup->hide(); + + Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel","TooltipPanel"); + + gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); + gui.tooltip_label->set_text(tooltip); + Rect2 r(gui.tooltip_pos+Point2(10,10),gui.tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); + Rect2 vr = gui.tooltip_label->get_viewport_rect(); + if (r.size.x+r.pos.x>vr.size.x) + r.pos.x=vr.size.x-r.size.x; + else if (r.pos.x<0) + r.pos.x=0; + + if (r.size.y+r.pos.y>vr.size.y) + r.pos.y=vr.size.y-r.size.y; + else if (r.pos.y<0) + r.pos.y=0; + + gui.tooltip_popup->set_global_pos(r.pos); + gui.tooltip_popup->set_size(r.size); + + gui.tooltip_popup->raise(); + gui.tooltip_popup->show(); +} + + +void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { + +// _block(); + + while(p_control) { + + p_control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); + if (gui.key_event_accepted) + break; + if (!p_control->is_inside_tree()) + break; + p_control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); + if (!p_control->is_inside_tree() || p_control->is_set_as_toplevel()) { + break; + } + if (gui.key_event_accepted) + break; + if (p_control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) + break; + p_control=p_control->data.parent; + } + + //_unblock(); + +} + +Control* Viewport::_gui_find_control(const Point2& p_global) { + + _gui_sort_subwindows(); + + for (List<Control*>::Element *E=gui.subwindows.back();E;E=E->prev()) { + + Control *sw = E->get(); + if (!sw->is_visible()) + continue; + + Matrix32 xform; + CanvasItem *pci = sw->get_parent_item(); + if (pci) + xform=pci->get_global_transform_with_canvas(); + + + Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + if (ret) + return ret; + } + + _gui_sort_roots(); + + for (List<Control*>::Element *E=gui.roots.back();E;E=E->prev()) { + + Control *sw = E->get(); + if (!sw->is_visible()) + continue; + + Matrix32 xform; + CanvasItem *pci = sw->get_parent_item(); + if (pci) + xform=pci->get_global_transform_with_canvas(); + + + Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + if (ret) + return ret; + } + + return NULL; + +} + + +Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform) { + + if (p_node->cast_to<Viewport>()) + return NULL; + + Control *c=p_node->cast_to<Control>(); + + if (c) { + // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); + } + + //subwindows first!! + + if (p_node->is_hidden()) { + //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); + return NULL; //canvas item hidden, discard + } + + Matrix32 matrix = p_xform * p_node->get_transform(); + + if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { + + for(int i=p_node->get_child_count()-1;i>=0;i--) { + + if (p_node==gui.tooltip_popup) + continue; + + CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); + if (!ci || ci->is_set_as_toplevel()) + continue; + + Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform);; + if (ret) + return ret; + } + } + + if (!c) + return NULL; + + matrix.affine_invert(); + + //conditions for considering this as a valid control for return + if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { + r_inv_xform=matrix; + return c; + } else + return NULL; +} + +void Viewport::_gui_input_event(InputEvent p_event) { + + + + if (p_event.ID==gui.cancelled_input_ID) { + return; + } + //? +// if (!is_visible()) { +// return; //simple and plain +// } + + + switch(p_event.type) { + + case InputEvent::MOUSE_BUTTON: { + + + gui.key_event_accepted=false; + + Point2 mpos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + if (p_event.mouse_button.pressed) { + + + + Size2 pos = mpos; + if (gui.mouse_focus && p_event.mouse_button.button_index!=gui.mouse_focus_button) { + + //do not steal mouse focus and stuff + + } else { + + + _gui_sort_modal_stack(); + while (!gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); + if (!top->has_point(pos)) { + + if (top->data.modal_exclusive) { + //cancel event, sorry, modal exclusive EATS UP ALL + //get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + return; // no one gets the event if exclusive NO ONE + } + + top->notification(Control::NOTIFICATION_MODAL_CLOSE); + top->_modal_stack_remove(); + top->hide(); + } else { + break; + } + } + + + + Matrix32 parent_xform; + + //if (data.parent_canvas_item) + // parent_xform=data.parent_canvas_item->get_global_transform(); + + + + gui.mouse_focus = _gui_find_control(pos); + //print_line("has mf "+itos(gui.mouse_focus!=NULL)); + gui.mouse_focus_button=p_event.mouse_button.button_index; + + if (!gui.mouse_focus) { + break; + } + + if (p_event.mouse_button.button_index==BUTTON_LEFT) { + gui.drag_accum=Vector2(); + gui.drag_attempted=false; + gui.drag_data=Variant(); + } + + + } + + p_event.mouse_button.global_x = pos.x; + p_event.mouse_button.global_y = pos.y; + + pos = gui.focus_inv_xform.xform(pos); + p_event.mouse_button.x = pos.x; + p_event.mouse_button.y = pos.y; + +#ifdef DEBUG_ENABLED + if (ScriptDebugger::get_singleton()) { + + Array arr; + arr.push_back(gui.mouse_focus->get_path()); + arr.push_back(gui.mouse_focus->get_type()); + ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); + } + + /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { + + print_line(String(gui.mouse_focus->get_path())+" - "+pos); + }*/ +#endif + + if (gui.mouse_focus->get_focus_mode()!=Control::FOCUS_NONE && gui.mouse_focus!=gui.key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { + // also get keyboard focus + gui.mouse_focus->grab_focus(); + } + + + if (gui.mouse_focus->can_process()) { + _gui_call_input(gui.mouse_focus,p_event); + } + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + _gui_cancel_tooltip(); + //gui.tooltip_popup->hide(); + + } else { + + if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { + memdelete( gui.drag_preview ); + gui.drag_preview=NULL; + } + + if (!gui.mouse_focus) { + + if (gui.mouse_over && gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + + Size2 pos = mpos; + pos = gui.focus_inv_xform.xform(pos); + + gui.mouse_over->drop_data(pos,gui.drag_data); + gui.drag_data=Variant(); + //change mouse accordingly + } + + break; + } + + Size2 pos = mpos; + p_event.mouse_button.global_x = pos.x; + p_event.mouse_button.global_y = pos.y; + pos = gui.focus_inv_xform.xform(pos); + p_event.mouse_button.x = pos.x; + p_event.mouse_button.y = pos.y; + + if (gui.mouse_focus->can_process()) { + _gui_call_input(gui.mouse_focus,p_event); + } + + if (p_event.mouse_button.button_index==gui.mouse_focus_button) { + gui.mouse_focus=NULL; + gui.mouse_focus_button=-1; + } + + if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + gui.drag_data=Variant(); //always clear + } + + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + } + } break; + case InputEvent::MOUSE_MOTION: { + + gui.key_event_accepted=false; + Point2 mpos=Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + + gui.last_mouse_pos=mpos; + + Control *over = NULL; + + + // D&D + if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);; + float len = gui.drag_accum.length(); + if (len>10) { + gui.drag_data=gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos)-gui.drag_accum); + if (gui.drag_data.get_type()!=Variant::NIL) { + + gui.mouse_focus=NULL; + } + gui.drag_attempted=true; + } + } + + + if (gui.mouse_focus) { + over=gui.mouse_focus; + //recompute focus_inv_xform again here + + } else { + + over = _gui_find_control(mpos); + } + + + if (gui.drag_data.get_type()==Variant::NIL && over && !gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + if (over!=top && !top->is_a_parent_of(over)) { + + break; // don't send motion event to anything below modal stack top + } + } + + if (over!=gui.mouse_over) { + + if (gui.mouse_over) + gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT); + + if (over) + over->notification(Control::NOTIFICATION_MOUSE_ENTER); + + } + + gui.mouse_over=over; + + _gui_cancel_tooltip(); + + if (gui.drag_preview) { + gui.drag_preview->set_pos(mpos); + } + + if (!over) { + OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW); + break; + } + + + Matrix32 localizer = over->get_canvas_transform().affine_inverse(); + Size2 pos = localizer.xform(mpos); + Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); + Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); + + + p_event.mouse_motion.global_x = mpos.x; + p_event.mouse_motion.global_y = mpos.y; + p_event.mouse_motion.speed_x=speed.x; + p_event.mouse_motion.speed_y=speed.y; + p_event.mouse_motion.relative_x=rel.x; + p_event.mouse_motion.relative_y=rel.y; + + if (p_event.mouse_motion.button_mask==0) { + //nothing pressed + + bool can_tooltip=true; + + if (!gui.modal_stack.empty()) { + if (gui.modal_stack.back()->get()!=over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) + can_tooltip=false; + + } + + + if (can_tooltip) { + + gui.tooltip=over; + gui.tooltip_pos=mpos;//(parent_xform * get_transform()).affine_inverse().xform(pos); + gui.tooltip_timer=gui.tooltip_delay; + + } + } + + + pos = gui.focus_inv_xform.xform(pos); + + + p_event.mouse_motion.x = pos.x; + p_event.mouse_motion.y = pos.y; + + + Control::CursorShape cursor_shape = over->get_cursor_shape(pos); + OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); + + + if (over->can_process()) { + _gui_call_input(over,p_event); + } + + + + //get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + + if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + /*bool can_drop =*/ over->can_drop_data(pos,gui.drag_data); + //change mouse accordingly i guess + } + + } break; + case InputEvent::ACTION: + case InputEvent::JOYSTICK_BUTTON: + case InputEvent::KEY: { + + if (gui.key_focus) { + + gui.key_event_accepted=false; + if (gui.key_focus->can_process()) { + gui.key_focus->call_multilevel("_input_event",p_event); + if (gui.key_focus) //maybe lost it + gui.key_focus->emit_signal(SceneStringNames::get_singleton()->input_event,p_event); + } + + + if (gui.key_event_accepted) { + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + break; + } + } + + + if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !gui.modal_stack.empty()) { + + _gui_sort_modal_stack(); + Control *top = gui.modal_stack.back()->get(); + if (!top->data.modal_exclusive) { + + top->notification(Control::NOTIFICATION_MODAL_CLOSE); + top->_modal_stack_remove(); + top->hide(); + } + } + + + Control * from = gui.key_focus ? gui.key_focus : NULL; //hmm + + //keyboard focus + //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { + + if (from && p_event.is_pressed()) { + Control * next=NULL; + + if (p_event.is_action("ui_focus_next")) { + + next = from->find_next_valid_focus(); + } + + if (p_event.is_action("ui_focus_prev")) { + + next = from->find_prev_valid_focus(); + } + + if (p_event.is_action("ui_up")) { + + next = from->_get_focus_neighbour(MARGIN_TOP); + } + + if (p_event.is_action("ui_left")) { + + next = from->_get_focus_neighbour(MARGIN_LEFT); + } + + if (p_event.is_action("ui_right")) { + + next = from->_get_focus_neighbour(MARGIN_RIGHT); + } + + if (p_event.is_action("ui_down")) { + + next = from->_get_focus_neighbour(MARGIN_BOTTOM); + } + + + if (next) { + next->grab_focus(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + } + } + + } break; + } +} + + +List<Control*>::Element* Viewport::_gui_add_root_control(Control* p_control) { + + gui.roots_order_dirty=true; + return gui.roots.push_back(p_control); +} + +List<Control*>::Element* Viewport::_gui_add_subwindow_control(Control* p_control) { + + gui.subwindow_order_dirty=true; + return gui.subwindows.push_back(p_control); + +} + +void Viewport::_gui_set_subwindow_order_dirty() { + gui.subwindow_order_dirty=true; +} + +void Viewport::_gui_set_root_order_dirty() { + gui.roots_order_dirty=true; +} + +void Viewport::_gui_remove_modal_control(List<Control*>::Element *MI) { + + gui.modal_stack.erase(MI); +} + +void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner) { + + //transfer the focus stack to the next + + List<Control*>::Element *next = MI->next(); + + gui.modal_stack.erase(MI); + MI=NULL; + + if (p_prev_focus_owner) { + + // for previous window in stack, pass the focus so it feels more + // natural + + if (!next) { //top of stack + + Object *pfo = ObjectDB::get_instance(p_prev_focus_owner); + Control *pfoc = pfo->cast_to<Control>(); + if (!pfoc) + return; + + if (!pfoc->is_inside_tree() || !pfoc->is_visible()) + return; + pfoc->grab_focus(); + } else { + + next->get()->_modal_set_prev_focus_owner(p_prev_focus_owner); + } + } +} + +void Viewport::_gui_force_drag(Control *p_base, const Variant& p_data, Control *p_control) { + + gui.drag_data=p_data; + gui.mouse_focus=NULL; + + if (p_control) { + _gui_set_drag_preview(p_base,p_control); + } +} + +void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { + + ERR_FAIL_NULL(p_control); + ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); + ERR_FAIL_COND(p_control->is_inside_tree()); + ERR_FAIL_COND(p_control->get_parent()!=NULL); + + if (gui.drag_preview) { + memdelete(gui.drag_preview); + } + p_control->set_as_toplevel(true); + p_control->set_pos(gui.last_mouse_pos); + p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport + p_control->raise(); + if (gui.drag_preview) { + memdelete( gui.drag_preview ); + } + gui.drag_preview=p_control; +} + + +void Viewport::_gui_remove_root_control(List<Control*>::Element *RI) { + + gui.roots.erase(RI); +} + +void Viewport::_gui_remove_subwindow_control(List<Control*>::Element* SI){ + + gui.subwindows.erase(SI); +} + +void Viewport::_gui_unfocus_control(Control *p_control) { + + if (gui.key_focus==p_control) { + gui.key_focus->release_focus(); + } +} + +void Viewport::_gui_hid_control(Control *p_control) { + + if (gui.mouse_focus == p_control) { + gui.mouse_focus=NULL; + } + + /* ??? + if (data.window==p_control) { + window->drag_data=Variant(); + if (window->drag_preview) { + memdelete( window->drag_preview); + window->drag_preview=NULL; + } + } + */ + + if (gui.key_focus == p_control) + gui.key_focus=NULL; + if (gui.mouse_over == p_control) + gui.mouse_over=NULL; + if (gui.tooltip == p_control) + gui.tooltip=NULL; + if (gui.tooltip == p_control) { + gui.tooltip=NULL; + _gui_cancel_tooltip(); + } + +} + +void Viewport::_gui_remove_control(Control *p_control) { + + + if (gui.mouse_focus == p_control) + gui.mouse_focus=NULL; + if (gui.key_focus == p_control) + gui.key_focus=NULL; + if (gui.mouse_over == p_control) + gui.mouse_over=NULL; + if (gui.tooltip == p_control) + gui.tooltip=NULL; + if (gui.tooltip_popup == p_control) { + _gui_cancel_tooltip(); + } + + +} + +void Viewport::_gui_remove_focus() { + + if (gui.key_focus) { + Node *f=gui.key_focus; + gui.key_focus=NULL; + f->notification( Control::NOTIFICATION_FOCUS_EXIT,true ); + + + } +} + +bool Viewport::_gui_is_modal_on_top(const Control* p_control) { + + return (gui.modal_stack.size() && gui.modal_stack.back()->get()==p_control); + +} + +bool Viewport::_gui_control_has_focus(const Control* p_control) { + + return gui.key_focus==p_control; +} + +void Viewport::_gui_control_grab_focus(Control* p_control) { + + + //no need for change + if (gui.key_focus && gui.key_focus==p_control) + return; + + _gui_remove_focus(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_gui_remove_focus"); + gui.key_focus=p_control; + p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); + p_control->update(); + +} + +void Viewport::_gui_accept_event() { + + gui.key_event_accepted=true; + if (is_inside_tree()) + get_tree()->set_input_as_handled(); +} + + +List<Control*>::Element* Viewport::_gui_show_modal(Control* p_control) { + + gui.modal_stack.push_back(p_control); + if (gui.key_focus) + p_control->_modal_set_prev_focus_owner(gui.key_focus->get_instance_ID()); + else + p_control->_modal_set_prev_focus_owner(0); + + return gui.modal_stack.back(); +} + +Control *Viewport::_gui_get_focus_owner() { + + return gui.key_focus; +} + +void Viewport::_gui_grab_click_focus(Control *p_control) { + + if (gui.mouse_focus) { + + + if (gui.mouse_focus==p_control) + return; + InputEvent ie; + ie.type=InputEvent::MOUSE_BUTTON; + InputEventMouseButton &mb=ie.mouse_button; + + //send unclic + + Point2 click =gui.mouse_focus->get_global_transform().affine_inverse().xform(gui.last_mouse_pos); + mb.x=click.x; + mb.y=click.y; + mb.button_index=gui.mouse_focus_button; + mb.pressed=false; + gui.mouse_focus->call_deferred("_input_event",ie); + + + gui.mouse_focus=p_control; + gui.focus_inv_xform=gui.mouse_focus->get_global_transform().affine_inverse(); + click =gui.mouse_focus->get_global_transform().affine_inverse().xform(gui.last_mouse_pos); + mb.x=click.x; + mb.y=click.y; + mb.button_index=gui.mouse_focus_button; + mb.pressed=true; + gui.mouse_focus->call_deferred("_input_event",ie); + + } +} + + +/////////////////////////////// + + void Viewport::input(const InputEvent& p_event) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(input_group,"_input",p_event); - get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check + + + get_tree()->_call_input_pause(input_group,"_input",p_event); + _gui_input_event(p_event); + //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } void Viewport::unhandled_input(const InputEvent& p_event) { ERR_FAIL_COND(!is_inside_tree()); + get_tree()->_call_input_pause(unhandled_input_group,"_unhandled_input",p_event); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev); if (!get_tree()->input_handled && p_event.type==InputEvent::KEY) { @@ -1377,6 +2318,19 @@ bool Viewport::get_physics_object_picking() { return physics_object_picking; } +bool Viewport::gui_has_modal_stack() const { + + return gui.modal_stack.size(); +} + +void Viewport::set_disable_input(bool p_disable) { + disable_input=p_disable; +} + +bool Viewport::is_input_disabled() const { + + return disable_input; +} void Viewport::_bind_methods() { @@ -1405,6 +2359,7 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("_parent_resized"), &Viewport::_parent_resized); ObjectTypeDB::bind_method(_MD("_vp_input"), &Viewport::_vp_input); + ObjectTypeDB::bind_method(_MD("_vp_input_text","text"), &Viewport::_vp_input_text); ObjectTypeDB::bind_method(_MD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); ObjectTypeDB::bind_method(_MD("set_size_override","enable","size","margin"), &Viewport::set_size_override,DEFVAL(Size2(-1,-1)),DEFVAL(Size2(0,0))); @@ -1456,11 +2411,18 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d); ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d); - ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect"), &Viewport::set_render_target_to_screen_rect); + ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect","rect"), &Viewport::set_render_target_to_screen_rect); ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos); ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse); + ObjectTypeDB::bind_method(_MD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); + + ObjectTypeDB::bind_method(_MD("set_disable_input","disable"), &Viewport::set_disable_input); + ObjectTypeDB::bind_method(_MD("is_input_disabled"), &Viewport::is_input_disabled); + + ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") ); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") ); @@ -1475,6 +2437,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled") ); ADD_SIGNAL(MethodInfo("size_changed")); @@ -1491,6 +2454,7 @@ void Viewport::_bind_methods() { Viewport::Viewport() { + world_2d = Ref<World2D>( memnew( World2D )); viewport = VisualServer::get_singleton()->viewport_create(); @@ -1524,7 +2488,21 @@ Viewport::Viewport() { unhandled_input_group = "_vp_unhandled_input"+id; unhandled_key_input_group = "_vp_unhandled_key_input"+id; + disable_input=false; + + //window tooltip + gui.tooltip_timer = -1; + + //gui.tooltip_timer->force_parent_owned(); + gui.tooltip_delay=GLOBAL_DEF("display/tooltip_delay",0.7); + + gui.tooltip=NULL; + gui.tooltip_label=NULL; + gui.drag_preview=NULL; + gui.drag_attempted=false; + + parent_control=NULL; } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 843a1fd9b7..cff729612e 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -39,6 +39,11 @@ */ class Camera; +class Control; +class CanvasItem; +class Panel; +class Label; +class Timer; class Viewport; class RenderTargetTexture : public Texture { @@ -82,6 +87,9 @@ public: private: friend class RenderTargetTexture; + + + Control *parent_control; Viewport *parent; Camera *camera; @@ -162,6 +170,49 @@ friend class RenderTargetTexture; Ref<RenderTargetTexture> render_target_texture; + struct GUI { + // info used when this is a window + + bool key_event_accepted; + Control *mouse_focus; + int mouse_focus_button; + Control *key_focus; + Control *mouse_over; + Control *tooltip; + Panel *tooltip_popup; + Label *tooltip_label; + Point2 tooltip_pos; + Point2 last_mouse_pos; + Point2 drag_accum; + bool drag_attempted; + Variant drag_data; + Control *drag_preview; + float tooltip_timer; + float tooltip_delay; + List<Control*> modal_stack; + unsigned int cancelled_input_ID; + Matrix32 focus_inv_xform; + bool subwindow_order_dirty; + List<Control*> subwindows; + bool roots_order_dirty; + List<Control*> roots; + + + GUI(); + } gui; + + bool disable_input; + + void _gui_call_input(Control *p_control,const InputEvent& p_input); + void _gui_sort_subwindows(); + void _gui_sort_roots(); + void _gui_sort_modal_stack(); + Control* _gui_find_control(const Point2& p_global); + Control* _gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform); + + void _gui_input_event(InputEvent p_event); + + void update_worlds(); _FORCE_INLINE_ Matrix32 _get_input_pre_xform() const; @@ -170,9 +221,47 @@ friend class RenderTargetTexture; void _vp_exit_tree(); void _vp_input(const InputEvent& p_ev); + void _vp_input_text(const String& p_text); void _vp_unhandled_input(const InputEvent& p_ev); void _make_input_local(InputEvent& ev); + +friend class Control; + + List<Control*>::Element* _gui_add_root_control(Control* p_control); + List<Control*>::Element* _gui_add_subwindow_control(Control* p_control); + + void _gui_set_subwindow_order_dirty(); + void _gui_set_root_order_dirty(); + + + void _gui_remove_modal_control(List<Control*>::Element *MI); + void _gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner); + void _gui_remove_root_control(List<Control*>::Element *RI); + void _gui_remove_subwindow_control(List<Control*>::Element* SI); + + void _gui_cancel_tooltip(); + void _gui_show_tooltip(); + + + void _gui_remove_control(Control *p_control); + void _gui_hid_control(Control *p_control); + + void _gui_force_drag(Control *p_base,const Variant& p_data,Control *p_control); + void _gui_set_drag_preview(Control *p_base,Control *p_control); + + bool _gui_is_modal_on_top(const Control* p_control); + List<Control*>::Element* _gui_show_modal(Control* p_control); + + void _gui_remove_focus(); + void _gui_unfocus_control(Control *p_control); + bool _gui_control_has_focus(const Control* p_control); + void _gui_control_grab_focus(Control* p_control); + void _gui_grab_click_focus(Control *p_control); + void _gui_accept_event(); + + Control *_gui_get_focus_owner(); + friend class Camera; void _camera_transform_changed_notify(); void _set_camera(Camera* p_camera); @@ -254,6 +343,9 @@ public: void input(const InputEvent& p_event); void unhandled_input(const InputEvent& p_event); + void set_disable_input(bool p_disable); + bool is_input_disabled() const; + void set_render_target_to_screen_rect(const Rect2& p_rect); Rect2 get_render_target_to_screen_rect() const; @@ -263,6 +355,9 @@ public: void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); + bool gui_has_modal_stack() const; + + Viewport(); ~Viewport(); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index b3a9ab922e..3c1b5268fc 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -221,7 +221,7 @@ static ResourceFormatLoaderImage *resource_loader_image=NULL; static ResourceFormatLoaderWAV *resource_loader_wav=NULL; -static ResourceFormatLoaderBitMap *resource_loader_bitmap=NULL; + #ifdef TOOLS_ENABLED @@ -249,8 +249,6 @@ void register_scene_types() { resource_loader_wav = memnew( ResourceFormatLoaderWAV ); ResourceLoader::add_resource_format_loader( resource_loader_wav ); - resource_loader_bitmap = memnew( ResourceFormatLoaderBitMap ); - ResourceLoader::add_resource_format_loader( resource_loader_bitmap ); #ifdef TOOLS_ENABLED @@ -610,6 +608,7 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init + ObjectTypeDB::register_virtual_type<SceneState>(); ObjectTypeDB::register_type<PackedScene>(); ObjectTypeDB::register_type<SceneTree>(); @@ -631,7 +630,6 @@ void unregister_scene_types() { memdelete( resource_loader_image ); memdelete( resource_loader_wav ); - memdelete( resource_loader_bitmap ); #ifdef TOOLS_ENABLED diff --git a/scene/register_scene_types.h b/scene/register_scene_types.h index 7d36dbc101..15e1eb2980 100644 --- a/scene/register_scene_types.h +++ b/scene/register_scene_types.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index afd4dc5304..e8bd6c14ad 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 256826a4bb..405b8b6a05 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/audio_stream.cpp b/scene/resources/audio_stream.cpp index 569ed8620d..1dd702abd2 100644 --- a/scene/resources/audio_stream.cpp +++ b/scene/resources/audio_stream.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/audio_stream.h b/scene/resources/audio_stream.h index b16e62b8c7..a4a2ad7599 100644 --- a/scene/resources/audio_stream.h +++ b/scene/resources/audio_stream.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/audio_stream_resampled.cpp b/scene/resources/audio_stream_resampled.cpp index edbca60bd3..3e10048f57 100644 --- a/scene/resources/audio_stream_resampled.cpp +++ b/scene/resources/audio_stream_resampled.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/audio_stream_resampled.h b/scene/resources/audio_stream_resampled.h index 570c311878..64f9d17d88 100644 --- a/scene/resources/audio_stream_resampled.h +++ b/scene/resources/audio_stream_resampled.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/bit_mask.cpp b/scene/resources/bit_mask.cpp index 9a6452797a..f5bfce3ef8 100644 --- a/scene/resources/bit_mask.cpp +++ b/scene/resources/bit_mask.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -204,57 +204,3 @@ BitMap::BitMap() { ////////////////////////////////////// - -RES ResourceFormatLoaderBitMap::load(const String &p_path, const String& p_original_path, Error *r_error) { - - if (r_error) - *r_error=ERR_FILE_CANT_OPEN; - - BitMap* ptr = memnew(BitMap); - Ref<BitMap> bitmap( ptr ); - - - Image image; - - Error err = ImageLoader::load_image(p_path,&image); - - ERR_EXPLAIN("Failed loading image for BitMap: "+p_path); - ERR_FAIL_COND_V(err, RES()); - - bitmap->create_from_image_alpha(image); - if (r_error) - *r_error=OK; - - return bitmap; - -} - -bool ResourceFormatLoaderBitMap::handles_type(const String& p_type) const { - - return (p_type=="BitMap"); -} - -void ResourceFormatLoaderBitMap::get_recognized_extensions(List<String> *p_extensions) const { - - ImageLoader::get_recognized_extensions(p_extensions); -} - -String ResourceFormatLoaderBitMap::get_resource_type(const String &p_path) const { - - List<String> extensions; - ImageLoader::get_recognized_extensions(&extensions); - String ext=p_path.extension().to_lower(); - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - if (E->get()==ext) - return "BitMap"; - } - return ""; -} - - -ResourceFormatLoaderBitMap::ResourceFormatLoaderBitMap() { - - -} - - diff --git a/scene/resources/bit_mask.h b/scene/resources/bit_mask.h index a6b29bb919..b245ea1542 100644 --- a/scene/resources/bit_mask.h +++ b/scene/resources/bit_mask.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -62,16 +62,5 @@ public: BitMap(); }; -class ResourceFormatLoaderBitMap : public ResourceFormatLoader { - -public: - - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - - ResourceFormatLoaderBitMap(); -}; #endif // BIT_MASK_H diff --git a/scene/resources/bounds.cpp b/scene/resources/bounds.cpp index 7382d60535..65ce5e49e8 100644 --- a/scene/resources/bounds.cpp +++ b/scene/resources/bounds.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/bounds.h b/scene/resources/bounds.h index 68aca6f6a0..a1610e2b57 100644 --- a/scene/resources/bounds.h +++ b/scene/resources/bounds.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/box_shape.cpp b/scene/resources/box_shape.cpp index ba29a1b601..9a6fedeb0b 100644 --- a/scene/resources/box_shape.cpp +++ b/scene/resources/box_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/box_shape.h b/scene/resources/box_shape.h index 9667515657..88fca65eea 100644 --- a/scene/resources/box_shape.h +++ b/scene/resources/box_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/canvas.cpp b/scene/resources/canvas.cpp index 51953d9683..0c87d0473d 100644 --- a/scene/resources/canvas.cpp +++ b/scene/resources/canvas.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/canvas.h b/scene/resources/canvas.h index 71dc080e64..5120301a67 100644 --- a/scene/resources/canvas.h +++ b/scene/resources/canvas.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/capsule_shape.cpp b/scene/resources/capsule_shape.cpp index 67ceed6be0..4c53645d2d 100644 --- a/scene/resources/capsule_shape.cpp +++ b/scene/resources/capsule_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/capsule_shape.h b/scene/resources/capsule_shape.h index e516d0e3c7..4263c3a554 100644 --- a/scene/resources/capsule_shape.h +++ b/scene/resources/capsule_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 923a509ad5..1887ec11d7 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/capsule_shape_2d.h b/scene/resources/capsule_shape_2d.h index dc679966f9..18b5c12a52 100644 --- a/scene/resources/capsule_shape_2d.h +++ b/scene/resources/capsule_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp index c77395612c..7171af9670 100644 --- a/scene/resources/circle_shape_2d.cpp +++ b/scene/resources/circle_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/circle_shape_2d.h b/scene/resources/circle_shape_2d.h index a5902b189c..c36e00d106 100644 --- a/scene/resources/circle_shape_2d.h +++ b/scene/resources/circle_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp index 97d3fafd58..bf1f298e7a 100644 --- a/scene/resources/color_ramp.cpp +++ b/scene/resources/color_ramp.cpp @@ -26,6 +26,23 @@ ColorRamp::~ColorRamp() { void ColorRamp::_bind_methods() { + + + + + ObjectTypeDB::bind_method(_MD("add_point","offset","color"),&ColorRamp::add_point); + ObjectTypeDB::bind_method(_MD("remove_point","offset","color"),&ColorRamp::remove_point); + + ObjectTypeDB::bind_method(_MD("set_offset","point","offset"),&ColorRamp::set_offset); + ObjectTypeDB::bind_method(_MD("get_offset","point"),&ColorRamp::get_offset); + + ObjectTypeDB::bind_method(_MD("set_color","point","color"),&ColorRamp::set_color); + ObjectTypeDB::bind_method(_MD("get_color","point"),&ColorRamp::get_color); + + ObjectTypeDB::bind_method(_MD("interpolate","offset"),&ColorRamp::get_color_at_offset); + + ObjectTypeDB::bind_method(_MD("get_point_count"),&ColorRamp::get_points_count); + ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_OFFSETS,"offsets"),&ColorRamp::set_offsets); ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_OFFSETS),&ColorRamp::get_offsets); @@ -79,6 +96,23 @@ Vector<ColorRamp::Point>& ColorRamp::get_points() { return points; } +void ColorRamp::add_point(float p_offset, const Color& p_color) { + + Point p; + p.offset=p_offset; + p.color=p_color; + is_sorted=false; + points.push_back(p); + +} + +void ColorRamp::remove_point(int p_index) { + + ERR_FAIL_INDEX(p_index,points.size()); + ERR_FAIL_COND(points.size()<=2); + points.remove(p_index); +} + void ColorRamp::set_points(Vector<ColorRamp::Point>& p_points) { points = p_points; is_sorted = false; diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h index 8f6ba2c3e5..aab5698c2b 100644 --- a/scene/resources/color_ramp.h +++ b/scene/resources/color_ramp.h @@ -32,6 +32,9 @@ public: ColorRamp(); virtual ~ColorRamp(); + void add_point(float p_offset, const Color& p_color); + void remove_point(int p_index); + void set_points(Vector<Point>& points); Vector<Point>& get_points(); diff --git a/scene/resources/concave_polygon_shape.cpp b/scene/resources/concave_polygon_shape.cpp index 7aeac04a22..34bea038f4 100644 --- a/scene/resources/concave_polygon_shape.cpp +++ b/scene/resources/concave_polygon_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/concave_polygon_shape.h b/scene/resources/concave_polygon_shape.h index fae98ee046..a4845e9220 100644 --- a/scene/resources/concave_polygon_shape.h +++ b/scene/resources/concave_polygon_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 01b7531f14..2c66155cb8 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/concave_polygon_shape_2d.h b/scene/resources/concave_polygon_shape_2d.h index 29666c88c1..89b8914741 100644 --- a/scene/resources/concave_polygon_shape_2d.h +++ b/scene/resources/concave_polygon_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/convex_polygon_shape.cpp b/scene/resources/convex_polygon_shape.cpp index 6a405c9c94..7fcc9e97c0 100644 --- a/scene/resources/convex_polygon_shape.cpp +++ b/scene/resources/convex_polygon_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/convex_polygon_shape.h b/scene/resources/convex_polygon_shape.h index 48454deb2b..a4e504ee24 100644 --- a/scene/resources/convex_polygon_shape.h +++ b/scene/resources/convex_polygon_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index a1137ba614..5c0dadefc2 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -30,6 +30,8 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" +#include "geometry.h" + void ConvexPolygonShape2D::_update_shape() { Physics2DServer::get_singleton()->shape_set_data(get_rid(),points); @@ -40,7 +42,9 @@ void ConvexPolygonShape2D::_update_shape() { void ConvexPolygonShape2D::set_point_cloud(const Vector<Vector2>& p_points) { - + Vector<Point2> hull=Geometry::convex_hull_2d(p_points); + ERR_FAIL_COND(hull.size()<3); + set_points(hull); } void ConvexPolygonShape2D::set_points(const Vector<Vector2>& p_points) { diff --git a/scene/resources/convex_polygon_shape_2d.h b/scene/resources/convex_polygon_shape_2d.h index 1af7787f67..e1792a1075 100644 --- a/scene/resources/convex_polygon_shape_2d.h +++ b/scene/resources/convex_polygon_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index c1a389942f..7dec4029fc 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/curve.h b/scene/resources/curve.h index 4818632dc3..262f22b7d1 100644 --- a/scene/resources/curve.h +++ b/scene/resources/curve.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/default_theme/button_focus.png b/scene/resources/default_theme/button_focus.png Binary files differnew file mode 100644 index 0000000000..52af26483e --- /dev/null +++ b/scene/resources/default_theme/button_focus.png diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 25407a5b84..f713b9e979 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /*************************************************/ /* Source code within this file is: */ -/* (c) 2007-2010 Juan Linietsky, Ariel Manzur */ +/* (c) 2007-2016 Juan Linietsky, Ariel Manzur */ /* All Rights Reserved. */ /*************************************************/ @@ -80,6 +80,13 @@ static Ref<Texture> make_icon(T p_src) { return texture; } +static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,const char*lighting_code) { + Ref<Shader> shader = (memnew( Shader(Shader::MODE_CANVAS_ITEM) )); + shader->set_code(vertex_code, fragment_code, lighting_code); + + return shader; +} + static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) { @@ -543,7 +550,11 @@ void make_default_theme() { t->set_constant("close_v_ofs","WindowDialog", 20 ); t->set_constant("titlebar_height","WindowDialog", 18 ); t->set_constant("title_height","WindowDialog", 20 ); - + + + // File Dialog + + t->set_icon("reload","FileDialog",make_icon( icon_reload_png )); // Popup @@ -709,6 +720,11 @@ void make_default_theme() { t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) ); t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) ); + t->set_icon("increment","Tabs",make_icon( scroll_button_right_png)); + t->set_icon("increment_hilite","Tabs",make_icon( scroll_button_right_hl_png)); + t->set_icon("decrement","Tabs",make_icon( scroll_button_left_png)); + t->set_icon("decrement_hilite","Tabs",make_icon( scroll_button_left_hl_png)); + t->set_icon("close","Tabs",make_icon( tab_close_png)); t->set_font("font","Tabs", default_font ); @@ -758,7 +774,11 @@ void make_default_theme() { t->set_constant("label_width","ColorPicker", 20); t->set_constant("hseparator","ColorPicker", 4); - + t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) ); + t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) ); + + t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, "")); + t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, "")); // TooltipPanel @@ -793,6 +813,8 @@ void make_default_theme() { t->set_color("selection_color","RichTextLabel", Color(0.1,0.1,1,0.8) ); t->set_constant("line_separation","RichTextLabel", 1 ); + t->set_constant("table_hseparation","RichTextLabel", 3 ); + t->set_constant("table_vseparation","RichTextLabel", 3 ); diff --git a/scene/resources/default_theme/default_theme.h b/scene/resources/default_theme/default_theme.h index ddd8af46f0..44569ba192 100644 --- a/scene/resources/default_theme/default_theme.h +++ b/scene/resources/default_theme/default_theme.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /*************************************************/ /* Source code within this file is: */ -/* (c) 2007-2010 Juan Linietsky, Ariel Manzur */ +/* (c) 2007-2016 Juan Linietsky, Ariel Manzur */ /* All Rights Reserved. */ /*************************************************/ diff --git a/scene/resources/default_theme/frame_focus.png b/scene/resources/default_theme/frame_focus.png Binary files differnew file mode 100644 index 0000000000..0df195d83e --- /dev/null +++ b/scene/resources/default_theme/frame_focus.png diff --git a/scene/resources/default_theme/icon_add.png b/scene/resources/default_theme/icon_add.png Binary files differnew file mode 100644 index 0000000000..26283ca67c --- /dev/null +++ b/scene/resources/default_theme/icon_add.png diff --git a/scene/resources/default_theme/icon_color_pick.png b/scene/resources/default_theme/icon_color_pick.png Binary files differnew file mode 100644 index 0000000000..2896763834 --- /dev/null +++ b/scene/resources/default_theme/icon_color_pick.png diff --git a/scene/resources/default_theme/icon_reload.png b/scene/resources/default_theme/icon_reload.png Binary files differnew file mode 100644 index 0000000000..f7c6530d77 --- /dev/null +++ b/scene/resources/default_theme/icon_reload.png diff --git a/scene/resources/default_theme/make_png_header.py b/scene/resources/default_theme/make_header.py index 0f0ce1808f..2d3f989e01 100644 --- a/scene/resources/default_theme/make_png_header.py +++ b/scene/resources/default_theme/make_header.py @@ -3,9 +3,6 @@ import os; import glob; import string; -pixmaps = glob.glob("*.png"); - -pixmaps.sort(); #Generate include files @@ -15,27 +12,61 @@ f.write("// THIS FILE HAS BEEN AUTOGENERATED, DONT EDIT!!\n"); f.write("\n\n"); +#Generate png image block + +pixmaps = glob.glob("*.png"); + +pixmaps.sort(); + f.write("\n\n\n"); - - for x in pixmaps: - + var_str=x[:-4]+"_png"; - + f.write("static const unsigned char "+ var_str +"[]={\n"); - + pngf=open(x,"rb"); - + b=pngf.read(1); while(len(b)==1): f.write(hex(ord(b))) b=pngf.read(1); if (len(b)==1): f.write(",") - + f.write("\n};\n\n\n"); pngf.close(); - -f.close(); +#Generate shaders block + +shaders = glob.glob("*.gsl") + +shaders.sort(); + +f.write("\n\n\n"); + +for x in shaders: + + var_str=x[:-4]+"_shader_code"; + + f.write("static const char *"+ var_str +"=\n"); + + sf=open(x,"rb"); + + + b=sf.readline(); + while(b!=""): + if (b.endswith("\r\n")): + b=b[:-2] + if (b.endswith("\n")): + b=b[:-1] + f.write(" \""+b) + b=sf.readline(); + if (b!=""): + f.write("\"\n") + + f.write("\";\n\n\n"); + sf.close(); + +f.close(); diff --git a/scene/resources/default_theme/tab_close.png b/scene/resources/default_theme/tab_close.png Binary files differnew file mode 100644 index 0000000000..10e56d5bb8 --- /dev/null +++ b/scene/resources/default_theme/tab_close.png diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index c338126d3a..4c440ab99a 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -179,11 +179,21 @@ static const unsigned char hsplitter_png[]={ }; +static const unsigned char icon_add_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,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xec,0x49,0x44,0x41,0x54,0x38,0x8d,0xdd,0x92,0x41,0x4a,0xc4,0x30,0x18,0x85,0xbf,0x67,0x93,0xc,0xd9,0x28,0xb9,0x41,0xcf,0x21,0x7a,0x28,0xdd,0xcd,0x5,0x14,0x57,0x73,0x28,0xe7,0x20,0xbd,0x41,0x70,0x5c,0x14,0x93,0xe,0xbf,0xb,0xdb,0x61,0x5a,0x5a,0x70,0xab,0xf,0x2,0x21,0xfc,0xf9,0xf2,0xde,0x23,0xf0,0xe7,0xa5,0xb5,0xc3,0x9c,0xf3,0xae,0x94,0xf2,0xda,0xf7,0xfd,0x13,0x40,0x8c,0xf1,0x10,0x42,0xd8,0xa7,0x94,0xbe,0x96,0xb3,0x6e,0x3,0x6c,0x92,0x4e,0x40,0x1,0x90,0xf4,0x1,0xd8,0xda,0xe0,0xc,0x90,0x73,0xde,0x1,0x66,0x66,0xc1,0xcc,0x9a,0xb,0xcd,0xcc,0x99,0x59,0xc8,0x39,0x3,0xe8,0xda,0xc9,0xc,0x50,0x4a,0x79,0x91,0xf4,0x69,0x66,0xcd,0x30,0xc,0xf,0x40,0x3,0x30,0xee,0x91,0x74,0x36,0xb3,0x5b,0xe0,0x79,0xb5,0x83,0xae,0xeb,0x6c,0xb2,0x3d,0x5e,0x9e,0x5c,0x9c,0xc7,0x5,0x10,0xda,0xb6,0xbd,0xdc,0xbb,0xd9,0xe8,0xe0,0xd7,0x9a,0x45,0x88,0x31,0x1e,0x24,0x9d,0xa6,0x8,0xb5,0xd6,0x47,0x0,0xef,0xfd,0xbb,0x73,0xee,0x78,0x15,0x61,0x1d,0x10,0x42,0xd8,0x33,0x96,0x8,0x50,0x6b,0xbd,0x7,0x70,0xce,0x1d,0xbd,0xf7,0x6f,0x92,0xa,0x8b,0xd8,0x33,0xc0,0xd4,0x6e,0xce,0x19,0x49,0x53,0x66,0x24,0xd,0x92,0x4a,0x4a,0xa9,0xb0,0xd0,0xd6,0x3f,0xd0,0x68,0x35,0xf0,0x63,0xe9,0x6e,0xf9,0xf2,0x3f,0xd2,0x37,0xb9,0xed,0x67,0x29,0x9e,0xb,0x7f,0x1a,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char icon_close_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,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,0xd9,0xb,0x17,0x6,0x11,0xd,0x6a,0x1e,0x9a,0x6f,0x0,0x0,0x0,0x5e,0x49,0x44,0x41,0x54,0x38,0xcb,0xd5,0x53,0xcb,0xe,0xc0,0x30,0x8,0x12,0xb2,0xff,0xff,0x65,0x77,0x5a,0xb3,0x36,0xf8,0x48,0xcc,0xe,0xf3,0xd4,0x3,0xa2,0x40,0x85,0x9b,0xdb,0xa4,0x68,0xc3,0x1a,0x13,0x5c,0xcf,0x3,0x86,0xa5,0xc5,0xcd,0xa1,0xc0,0xa,0x43,0xd5,0xf4,0x6,0x56,0x3,0x36,0x9,0x11,0x49,0xb6,0x1d,0x54,0xa,0x6a,0x83,0x48,0x1a,0xbb,0xc0,0xc8,0x97,0x6f,0x62,0xac,0x4c,0x4c,0x9,0x4e,0xc3,0xaa,0x74,0xd8,0x89,0x2a,0x23,0x61,0xf7,0x23,0x85,0x11,0xff,0xff,0x98,0x6e,0x7,0x20,0x33,0x1a,0x5b,0xf5,0xcc,0xfe,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; +static const unsigned char icon_color_pick_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,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x11,0x0,0x0,0xb,0x11,0x1,0x7f,0x64,0x5f,0x91,0x0,0x0,0x0,0x18,0x74,0x45,0x58,0x74,0x53,0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x0,0x70,0x61,0x69,0x6e,0x74,0x2e,0x6e,0x65,0x74,0x20,0x34,0x2e,0x30,0x2e,0x36,0xfc,0x8c,0x63,0xdf,0x0,0x0,0x1,0xf7,0x49,0x44,0x41,0x54,0x38,0x4f,0x8d,0x90,0xbd,0x6b,0x53,0x51,0x18,0xc6,0xaf,0x26,0xed,0x62,0x70,0x71,0xd0,0xc1,0x2f,0x70,0xa9,0xda,0x4d,0xc7,0x8e,0xd6,0x42,0xc5,0x52,0xa5,0x42,0xa1,0xa4,0xb6,0x20,0x75,0x50,0xf4,0x52,0x41,0x1d,0x6a,0x87,0x96,0xfe,0x1,0x42,0xa1,0x20,0x52,0x71,0x56,0x50,0xf3,0xd5,0x94,0x24,0xed,0x50,0x5d,0xc4,0x41,0xa9,0x70,0xd3,0xc4,0xe7,0x9c,0xa0,0xc5,0xf,0x1c,0x2,0x6,0x29,0x4d,0xe2,0x7d,0x7d,0x4e,0x72,0xc,0xe9,0x7,0xb5,0xf,0xfc,0x48,0xee,0xcd,0xf3,0x7b,0xcf,0x7b,0xe2,0xfc,0x2f,0xc5,0x62,0x31,0x98,0xc8,0xfd,0x8,0x5c,0x8c,0xa1,0xa5,0x3f,0x81,0xe0,0x8d,0x14,0x4e,0xdc,0xcd,0x60,0x6a,0x64,0x1e,0x3,0x3d,0x31,0x84,0x6c,0x6d,0x6b,0x6,0xe6,0x10,0x1c,0x4a,0xe2,0xc0,0xf3,0x8f,0xab,0x7b,0x87,0x53,0x2a,0x40,0xf9,0x24,0xe5,0xa7,0xf7,0x17,0xf0,0xe7,0x5e,0x6,0x55,0x3e,0x7f,0xee,0x8c,0xe0,0xa0,0xad,0x3b,0x8e,0x88,0x34,0x30,0x19,0x4c,0x22,0x70,0x2b,0x85,0xa3,0x7d,0x71,0x1c,0xb9,0x1c,0x47,0x68,0x34,0x8d,0x35,0xca,0xe2,0xa6,0x21,0xe1,0x39,0xf8,0x5d,0x11,0xac,0x9f,0x8b,0xe0,0x71,0xad,0x6c,0xd2,0x2c,0x9b,0xf4,0xc6,0x70,0xfc,0xda,0x3c,0xd6,0x2e,0xc5,0xf0,0x75,0x38,0x89,0x99,0xb1,0x5,0xf8,0x77,0xd2,0xf0,0xaf,0xc4,0x51,0x3d,0x1f,0x41,0x99,0xb2,0x22,0xa7,0x6d,0x7d,0xeb,0x0,0x9e,0x70,0xa6,0x27,0x8a,0x32,0xd7,0x14,0x6e,0x20,0xdc,0xc0,0xe7,0xea,0x3e,0x4f,0x2f,0x71,0xc0,0x7,0xca,0x61,0xd2,0x62,0xeb,0xf5,0x1,0xcd,0x59,0xfe,0xa4,0xdd,0x47,0x6f,0x21,0xdd,0x51,0xf8,0x1c,0xe2,0xf3,0x2a,0xc2,0x3f,0xce,0x6c,0xf0,0x8e,0xc3,0x7,0x29,0xef,0xb3,0xd5,0x7a,0x9a,0x7,0x14,0xa,0x85,0x3e,0x52,0xc9,0x2b,0x5d,0x19,0x5d,0xc4,0x2c,0xcb,0x25,0xb3,0x9,0x87,0xc9,0x85,0x28,0xbe,0xf3,0xfb,0x31,0xbe,0xdb,0x63,0xeb,0xf5,0xfc,0xbb,0x2,0xc5,0xe,0x52,0x22,0x42,0x6e,0xba,0x8b,0xd8,0x3f,0xf5,0x46,0xe5,0x79,0xaa,0x50,0x32,0x54,0x49,0xe7,0xb6,0x3,0x28,0xb4,0x91,0xa2,0x95,0x27,0x49,0x90,0x3c,0xcb,0x42,0xcb,0xf8,0x92,0xfa,0x6d,0x65,0x9f,0xbc,0x22,0xad,0x56,0xad,0x87,0xc5,0x10,0xf1,0x88,0x91,0x9f,0x90,0x9a,0x6c,0x9f,0x7f,0x26,0x96,0xf5,0x59,0x4a,0x2e,0x79,0x49,0x4e,0x91,0x8d,0x1b,0xb0,0xf4,0x42,0xe7,0xb5,0x60,0x36,0xb7,0x8a,0xeb,0x5e,0xb8,0x49,0x36,0xd7,0xe9,0x30,0x1b,0x1a,0x89,0xb4,0x6e,0x27,0xf7,0xea,0xf7,0x4a,0x30,0xb1,0x52,0x46,0xd8,0x2b,0xe3,0x41,0xf6,0xcb,0x66,0x79,0x33,0x1b,0xc2,0x92,0xa7,0x1e,0xe6,0x4,0x57,0xbd,0x75,0xb8,0xd9,0x5f,0x5a,0xeb,0x1d,0x65,0x43,0x23,0x2c,0xb5,0xab,0xc,0x4,0x23,0x9e,0xe0,0xb6,0x57,0xd1,0x2b,0x35,0xf9,0xdb,0x4e,0xb2,0xa1,0x11,0x16,0xf,0x61,0x3a,0x57,0x55,0xaf,0x61,0x44,0x43,0x8a,0x1c,0xb6,0x3f,0xef,0x2e,0x14,0xda,0xc9,0x98,0xf9,0xb4,0xaf,0x76,0x19,0xc7,0xf9,0xb,0x8e,0xb3,0xf3,0x95,0xda,0x15,0xd3,0x79,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char icon_folder_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,0xde,0x9,0xf,0x14,0x33,0x39,0x1,0xd2,0x43,0x4c,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x36,0x49,0x44,0x41,0x54,0x38,0x8d,0xc5,0x92,0xcd,0x4a,0xc3,0x40,0x14,0x85,0xbf,0x7b,0x67,0x12,0x48,0x3,0x12,0x62,0x45,0xfa,0x30,0x7d,0x5,0x5d,0xfa,0x8,0xbe,0x88,0x3e,0x45,0x5f,0xc1,0x9d,0x4b,0x77,0x3e,0x81,0x2e,0xa4,0x15,0xa5,0x10,0xb2,0xc8,0xa2,0x9b,0x41,0x2c,0x62,0x4c,0x66,0x5c,0x34,0x8a,0x3f,0x95,0x26,0x2b,0xf,0xc,0xcc,0x9d,0x3b,0xe7,0xce,0x39,0x87,0x81,0xff,0x86,0x14,0x45,0x11,0xb6,0x35,0xe2,0x38,0xbe,0x9c,0x4c,0x26,0x47,0xce,0xb9,0x78,0x4b,0x3b,0x64,0x59,0xf6,0x6,0x20,0x65,0x59,0x56,0xde,0xfb,0x43,0x40,0x80,0x0,0x34,0xdd,0xa5,0x28,0x49,0x92,0x73,0x11,0x79,0xf9,0x49,0x16,0x91,0xd5,0x78,0x3c,0x9e,0x1,0x58,0x63,0x4c,0xe9,0xbd,0x3f,0x0,0xc,0x20,0xa3,0xd1,0xe8,0x2c,0x84,0x10,0x1,0x88,0xc8,0x6b,0x37,0xf8,0x9b,0xea,0x10,0xc2,0xa7,0x2a,0xa9,0xaa,0xea,0xa2,0xae,0xeb,0x63,0x40,0xd3,0x34,0x3d,0x5d,0xaf,0xd7,0xb3,0xde,0xfe,0x45,0x9e,0xd4,0x18,0x53,0x0,0x1e,0xd0,0x10,0x42,0xda,0x97,0xc,0x78,0x55,0xad,0x54,0x44,0x96,0x80,0xfd,0xf0,0x37,0x64,0x80,0x31,0x66,0xa1,0xaa,0xfa,0x8,0x68,0x77,0xb8,0x7,0xd4,0x83,0x6,0x88,0xc8,0x3,0x80,0x31,0x66,0xde,0x34,0xcd,0x94,0x4d,0x98,0x7d,0x10,0xab,0xea,0xad,0xe6,0x79,0xbe,0x4,0x88,0xa2,0xe8,0xba,0xae,0xeb,0xe9,0x17,0x35,0x3b,0xa1,0xaa,0x37,0xf6,0x4b,0x71,0x7,0x24,0x7d,0xc9,0x0,0x79,0x9e,0xcf,0x2d,0x80,0x88,0x3c,0xf,0x79,0x99,0x4d,0xd8,0x1e,0xba,0xf4,0x55,0x75,0xd5,0xed,0xdb,0x6e,0xed,0x42,0x63,0xad,0xbd,0x7,0xb0,0xce,0x39,0x6d,0xdb,0xf6,0x44,0x55,0x17,0x49,0x92,0xec,0xff,0xf1,0xfb,0x7e,0x29,0x50,0xd5,0x2b,0xe7,0x9c,0x8,0x80,0x73,0xce,0x74,0x92,0xa2,0x1,0x36,0xda,0x2c,0xcb,0xda,0x77,0xe3,0x5,0x64,0xf1,0xba,0x53,0xe9,0x44,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -194,6 +204,11 @@ static const unsigned char icon_play_png[]={ }; +static const unsigned char icon_reload_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,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x94,0x49,0x44,0x41,0x54,0x38,0x8d,0x85,0xd3,0xbd,0x6a,0x55,0x41,0x14,0xc5,0xf1,0xdf,0xb9,0x1f,0x91,0x20,0x5a,0x89,0xd8,0x8,0x4b,0xd0,0x42,0x1f,0xc0,0x42,0x4,0x4b,0xb,0x1b,0x9b,0xbc,0x80,0x58,0x45,0xc5,0x56,0x51,0x50,0x6b,0x21,0x9d,0xa5,0x6f,0x20,0x88,0x20,0xa8,0xad,0xa8,0xa0,0x2f,0x60,0x21,0xe8,0x4e,0x63,0xa9,0x85,0x22,0x31,0x37,0x37,0xb1,0xb8,0x73,0xc2,0xf1,0x23,0x38,0xd5,0x9c,0x61,0xaf,0x3d,0x7b,0xfe,0x6b,0x9d,0xce,0x1e,0xab,0xaa,0xc6,0x18,0xa1,0xc3,0xe,0xb6,0x92,0xec,0xfc,0x59,0x37,0xda,0x43,0x8,0xc7,0x70,0x9,0x37,0xb0,0xd2,0xd7,0x56,0x55,0x57,0x55,0xbb,0xf5,0xdd,0x1f,0xe2,0xae,0x9,0x9f,0xe2,0x24,0xb6,0x6,0x97,0x8c,0xf0,0x32,0xc9,0xb9,0xaa,0x9a,0x62,0x96,0x64,0xd1,0xa0,0x75,0x1c,0xe3,0x2,0x9e,0x34,0xc1,0x2b,0x3c,0xc6,0x3a,0x8e,0xe3,0x76,0xab,0x59,0xc6,0x41,0xfc,0xc0,0xbc,0x6f,0x30,0xc6,0x61,0x7c,0x6e,0xe2,0x53,0x49,0xde,0x57,0xd5,0x12,0xb6,0xd1,0x25,0x99,0x55,0xd5,0x3,0xac,0x36,0x1e,0xd3,0x5d,0x6,0x49,0xe6,0x78,0xd4,0xc4,0xe7,0xf1,0xa9,0x9d,0x6f,0x26,0xd9,0xc2,0xac,0x7d,0x5f,0xc1,0x73,0xcc,0xab,0xea,0x7a,0x55,0x4d,0x7b,0x30,0x37,0x71,0x6,0xdf,0x70,0x34,0xc9,0xc6,0x90,0x4d,0x92,0x21,0xa3,0x15,0xec,0xc3,0x6a,0x92,0x59,0x57,0x55,0x13,0x4c,0xdb,0x9b,0x36,0x92,0x2c,0x57,0xd5,0xb8,0x4d,0xf5,0xcf,0x55,0x55,0x33,0x4c,0x92,0x74,0xa3,0x46,0x7a,0x8e,0x13,0x38,0xd8,0x1a,0xfe,0x53,0x3c,0xb0,0xef,0x4b,0xbf,0x19,0xb5,0xf1,0x36,0xf1,0x31,0xc9,0xcc,0x22,0x34,0xff,0x5b,0x87,0xf1,0x95,0xbf,0x73,0xb0,0x86,0x5b,0xf8,0x89,0xed,0xfe,0xed,0x83,0xdb,0x97,0x70,0x19,0x6b,0x78,0x88,0xab,0xbd,0x8d,0x13,0x9c,0xc6,0x6b,0xac,0x27,0x49,0xb3,0x70,0x96,0x64,0xa7,0xc1,0x9b,0xe0,0x90,0x66,0x75,0x92,0xae,0xaa,0xba,0xde,0xc6,0xad,0x24,0x6f,0xf0,0xc,0x47,0xaa,0xea,0x3b,0x2e,0xe,0xb2,0xbf,0xdf,0x22,0xd2,0x7d,0x4e,0xce,0xb7,0x34,0xee,0xec,0x26,0x71,0x60,0xd5,0x5d,0xdc,0xb1,0x0,0xd9,0xff,0x17,0x2c,0xb2,0x30,0xc5,0x59,0xbc,0xee,0xeb,0xfb,0x9,0x86,0x84,0xef,0xe1,0x0,0xee,0xe3,0x2d,0x3e,0xe0,0x5,0xae,0x25,0xe9,0xf0,0x6e,0xc8,0xe6,0x37,0x88,0x3,0x58,0x1d,0xc6,0x2d,0x85,0xfd,0xf9,0x92,0x85,0x5b,0x86,0xd,0x7e,0x1,0x82,0x4c,0xaa,0x69,0x77,0x3c,0x4b,0x15,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char icon_stop_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,0xde,0x9,0xf,0x14,0x33,0x24,0x62,0xd4,0x2f,0x95,0x0,0x0,0x0,0x39,0x49,0x44,0x41,0x54,0x38,0x8d,0x63,0x60,0xa0,0x6,0xf8,0xf0,0xe1,0x3,0x33,0xb9,0x7a,0x18,0x61,0x2,0xf,0x1f,0x3e,0xfc,0x4f,0x8a,0x1,0xf2,0xf2,0xf2,0x8c,0xc,0xc,0xc,0xc,0x4c,0xa4,0xda,0x8c,0xe,0x46,0xd,0x18,0x35,0x60,0x70,0x18,0xc0,0xc0,0xc0,0x40,0x59,0x66,0xa2,0x18,0x0,0x0,0x2a,0xc7,0xf,0x64,0xd5,0xe,0x11,0x85,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -394,6 +409,11 @@ static const unsigned char tab_behind_png[]={ }; +static const unsigned char tab_close_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,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x1b,0x49,0x44,0x41,0x54,0x38,0x8d,0xcd,0x52,0xbb,0x4e,0xc4,0x40,0xc,0x9c,0x73,0xd2,0x50,0x38,0xd1,0x8a,0x82,0x36,0x3d,0x8,0xc4,0x43,0x88,0x13,0x12,0x20,0xf8,0x67,0x8a,0xfb,0x1,0xe,0x89,0x13,0x3d,0x47,0xb1,0x7f,0xb0,0x85,0x53,0x41,0xce,0xa6,0xd9,0x45,0xbe,0x24,0x1f,0x70,0x96,0x56,0x96,0xed,0x9d,0x91,0x3d,0x36,0x70,0x50,0x96,0x52,0xaa,0xbd,0x1f,0xd5,0xaa,0xb9,0x1a,0x79,0xb0,0x99,0x9d,0xc4,0x18,0x4d,0x55,0x2f,0xfd,0xc7,0x94,0x12,0xa9,0xea,0x53,0x8c,0xd1,0xcc,0xac,0xf1,0xb5,0x85,0x67,0x8b,0x31,0x1a,0x0,0x5,0x40,0xcc,0x7c,0x4b,0x44,0x9f,0x0,0x54,0x55,0x5f,0x44,0x64,0x5,0x60,0x7,0xa0,0xea,0xba,0x6e,0x31,0x21,0x48,0x29,0xd5,0xaa,0x7a,0x25,0x22,0xef,0x25,0xc7,0xcc,0x4b,0x33,0xb,0x7d,0xdf,0xbf,0xba,0xdc,0x29,0x11,0x7d,0x85,0x10,0x86,0x49,0x7,0x99,0xe4,0x5a,0x44,0xd6,0x73,0x1a,0x65,0xf0,0x77,0x8,0xe1,0x67,0xa2,0x1,0x0,0x84,0x10,0x6,0x22,0xda,0x30,0xf3,0x7d,0x4e,0x59,0x7e,0x60,0xe6,0xb,0x22,0xda,0x7a,0xf0,0x84,0x20,0x9b,0x9a,0x59,0xeb,0xe2,0xd2,0x65,0x53,0xc8,0x30,0x53,0x2c,0x23,0x54,0xaa,0xfa,0x9c,0x5,0x9b,0x1b,0xe1,0x8e,0x88,0x36,0x65,0xfe,0xbd,0xe,0x32,0xf8,0xd1,0x83,0x99,0xf9,0x9c,0x99,0x1f,0x4a,0x2c,0x22,0xeb,0xf1,0x8a,0xe7,0xd6,0xb8,0x3,0x50,0x65,0xc1,0xb6,0x0,0x4c,0x55,0x6f,0x44,0xe4,0xd,0xc0,0x0,0xa0,0xf6,0x6b,0xdc,0x3b,0xa4,0xa6,0x69,0x8e,0x33,0xf8,0x2c,0xab,0xfd,0x9b,0x85,0xfd,0x60,0xe6,0x25,0x80,0xaa,0x6d,0xdb,0xa3,0xb9,0x4b,0xfd,0x27,0xf1,0x7e,0xac,0x8f,0xf7,0x87,0x63,0x7f,0xc3,0xca,0xa9,0x49,0x35,0x25,0x97,0x14,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char tab_container_bg_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,0xa,0x45,0x69,0x43,0x43,0x50,0x49,0x43,0x43,0x20,0x70,0x72,0x6f,0x66,0x69,0x6c,0x65,0x0,0x0,0x78,0xda,0x9d,0x53,0x67,0x54,0x53,0xe9,0x16,0x3d,0xf7,0xde,0xf4,0x42,0x4b,0x88,0x80,0x94,0x4b,0x6f,0x52,0x15,0x8,0x20,0x52,0x42,0x8b,0x80,0x14,0x91,0x26,0x2a,0x21,0x9,0x10,0x4a,0x88,0x21,0xa1,0xd9,0x15,0x51,0xc1,0x11,0x45,0x45,0x4,0x1b,0xc8,0xa0,0x88,0x3,0x8e,0x8e,0x80,0x8c,0x15,0x51,0x2c,0xc,0x8a,0xa,0xd8,0x7,0xe4,0x21,0xa2,0x8e,0x83,0xa3,0x88,0x8a,0xca,0xfb,0xe1,0x7b,0xa3,0x6b,0xd6,0xbc,0xf7,0xe6,0xcd,0xfe,0xb5,0xd7,0x3e,0xe7,0xac,0xf3,0x9d,0xb3,0xcf,0x7,0xc0,0x8,0xc,0x96,0x48,0x33,0x51,0x35,0x80,0xc,0xa9,0x42,0x1e,0x11,0xe0,0x83,0xc7,0xc4,0xc6,0xe1,0xe4,0x2e,0x40,0x81,0xa,0x24,0x70,0x0,0x10,0x8,0xb3,0x64,0x21,0x73,0xfd,0x23,0x1,0x0,0xf8,0x7e,0x3c,0x3c,0x2b,0x22,0xc0,0x7,0xbe,0x0,0x1,0x78,0xd3,0xb,0x8,0x0,0xc0,0x4d,0x9b,0xc0,0x30,0x1c,0x87,0xff,0xf,0xea,0x42,0x99,0x5c,0x1,0x80,0x84,0x1,0xc0,0x74,0x91,0x38,0x4b,0x8,0x80,0x14,0x0,0x40,0x7a,0x8e,0x42,0xa6,0x0,0x40,0x46,0x1,0x80,0x9d,0x98,0x26,0x53,0x0,0xa0,0x4,0x0,0x60,0xcb,0x63,0x62,0xe3,0x0,0x50,0x2d,0x0,0x60,0x27,0x7f,0xe6,0xd3,0x0,0x80,0x9d,0xf8,0x99,0x7b,0x1,0x0,0x5b,0x94,0x21,0x15,0x1,0xa0,0x91,0x0,0x20,0x13,0x65,0x88,0x44,0x0,0x68,0x3b,0x0,0xac,0xcf,0x56,0x8a,0x45,0x0,0x58,0x30,0x0,0x14,0x66,0x4b,0xc4,0x39,0x0,0xd8,0x2d,0x0,0x30,0x49,0x57,0x66,0x48,0x0,0xb0,0xb7,0x0,0xc0,0xce,0x10,0xb,0xb2,0x0,0x8,0xc,0x0,0x30,0x51,0x88,0x85,0x29,0x0,0x4,0x7b,0x0,0x60,0xc8,0x23,0x23,0x78,0x0,0x84,0x99,0x0,0x14,0x46,0xf2,0x57,0x3c,0xf1,0x2b,0xae,0x10,0xe7,0x2a,0x0,0x0,0x78,0x99,0xb2,0x3c,0xb9,0x24,0x39,0x45,0x81,0x5b,0x8,0x2d,0x71,0x7,0x57,0x57,0x2e,0x1e,0x28,0xce,0x49,0x17,0x2b,0x14,0x36,0x61,0x2,0x61,0x9a,0x40,0x2e,0xc2,0x79,0x99,0x19,0x32,0x81,0x34,0xf,0xe0,0xf3,0xcc,0x0,0x0,0xa0,0x91,0x15,0x11,0xe0,0x83,0xf3,0xfd,0x78,0xce,0xe,0xae,0xce,0xce,0x36,0x8e,0xb6,0xe,0x5f,0x2d,0xea,0xbf,0x6,0xff,0x22,0x62,0x62,0xe3,0xfe,0xe5,0xcf,0xab,0x70,0x40,0x0,0x0,0xe1,0x74,0x7e,0xd1,0xfe,0x2c,0x2f,0xb3,0x1a,0x80,0x3b,0x6,0x80,0x6d,0xfe,0xa2,0x25,0xee,0x4,0x68,0x5e,0xb,0xa0,0x75,0xf7,0x8b,0x66,0xb2,0xf,0x40,0xb5,0x0,0xa0,0xe9,0xda,0x57,0xf3,0x70,0xf8,0x7e,0x3c,0x3c,0x45,0xa1,0x90,0xb9,0xd9,0xd9,0xe5,0xe4,0xe4,0xd8,0x4a,0xc4,0x42,0x5b,0x61,0xca,0x57,0x7d,0xfe,0x67,0xc2,0x5f,0xc0,0x57,0xfd,0x6c,0xf9,0x7e,0x3c,0xfc,0xf7,0xf5,0xe0,0xbe,0xe2,0x24,0x81,0x32,0x5d,0x81,0x47,0x4,0xf8,0xe0,0xc2,0xcc,0xf4,0x4c,0xa5,0x1c,0xcf,0x92,0x9,0x84,0x62,0xdc,0xe6,0x8f,0x47,0xfc,0xb7,0xb,0xff,0xfc,0x1d,0xd3,0x22,0xc4,0x49,0x62,0xb9,0x58,0x2a,0x14,0xe3,0x51,0x12,0x71,0x8e,0x44,0x9a,0x8c,0xf3,0x32,0xa5,0x22,0x89,0x42,0x92,0x29,0xc5,0x25,0xd2,0xff,0x64,0xe2,0xdf,0x2c,0xfb,0x3,0x3e,0xdf,0x35,0x0,0xb0,0x6a,0x3e,0x1,0x7b,0x91,0x2d,0xa8,0x5d,0x63,0x3,0xf6,0x4b,0x27,0x10,0x58,0x74,0xc0,0xe2,0xf7,0x0,0x0,0xf2,0xbb,0x6f,0xc1,0xd4,0x28,0x8,0x3,0x80,0x68,0x83,0xe1,0xcf,0x77,0xff,0xef,0x3f,0xfd,0x47,0xa0,0x25,0x0,0x80,0x66,0x49,0x92,0x71,0x0,0x0,0x5e,0x44,0x24,0x2e,0x54,0xca,0xb3,0x3f,0xc7,0x8,0x0,0x0,0x44,0xa0,0x81,0x2a,0xb0,0x41,0x1b,0xf4,0xc1,0x18,0x2c,0xc0,0x6,0x1c,0xc1,0x5,0xdc,0xc1,0xb,0xfc,0x60,0x36,0x84,0x42,0x24,0xc4,0xc2,0x42,0x10,0x42,0xa,0x64,0x80,0x1c,0x72,0x60,0x29,0xac,0x82,0x42,0x28,0x86,0xcd,0xb0,0x1d,0x2a,0x60,0x2f,0xd4,0x40,0x1d,0x34,0xc0,0x51,0x68,0x86,0x93,0x70,0xe,0x2e,0xc2,0x55,0xb8,0xe,0x3d,0x70,0xf,0xfa,0x61,0x8,0x9e,0xc1,0x28,0xbc,0x81,0x9,0x4,0x41,0xc8,0x8,0x13,0x61,0x21,0xda,0x88,0x1,0x62,0x8a,0x58,0x23,0x8e,0x8,0x17,0x99,0x85,0xf8,0x21,0xc1,0x48,0x4,0x12,0x8b,0x24,0x20,0xc9,0x88,0x14,0x51,0x22,0x4b,0x91,0x35,0x48,0x31,0x52,0x8a,0x54,0x20,0x55,0x48,0x1d,0xf2,0x3d,0x72,0x2,0x39,0x87,0x5c,0x46,0xba,0x91,0x3b,0xc8,0x0,0x32,0x82,0xfc,0x86,0xbc,0x47,0x31,0x94,0x81,0xb2,0x51,0x3d,0xd4,0xc,0xb5,0x43,0xb9,0xa8,0x37,0x1a,0x84,0x46,0xa2,0xb,0xd0,0x64,0x74,0x31,0x9a,0x8f,0x16,0xa0,0x9b,0xd0,0x72,0xb4,0x1a,0x3d,0x8c,0x36,0xa1,0xe7,0xd0,0xab,0x68,0xf,0xda,0x8f,0x3e,0x43,0xc7,0x30,0xc0,0xe8,0x18,0x7,0x33,0xc4,0x6c,0x30,0x2e,0xc6,0xc3,0x42,0xb1,0x38,0x2c,0x9,0x93,0x63,0xcb,0xb1,0x22,0xac,0xc,0xab,0xc6,0x1a,0xb0,0x56,0xac,0x3,0xbb,0x89,0xf5,0x63,0xcf,0xb1,0x77,0x4,0x12,0x81,0x45,0xc0,0x9,0x36,0x4,0x77,0x42,0x20,0x61,0x1e,0x41,0x48,0x58,0x4c,0x58,0x4e,0xd8,0x48,0xa8,0x20,0x1c,0x24,0x34,0x11,0xda,0x9,0x37,0x9,0x3,0x84,0x51,0xc2,0x27,0x22,0x93,0xa8,0x4b,0xb4,0x26,0xba,0x11,0xf9,0xc4,0x18,0x62,0x32,0x31,0x87,0x58,0x48,0x2c,0x23,0xd6,0x12,0x8f,0x13,0x2f,0x10,0x7b,0x88,0x43,0xc4,0x37,0x24,0x12,0x89,0x43,0x32,0x27,0xb9,0x90,0x2,0x49,0xb1,0xa4,0x54,0xd2,0x12,0xd2,0x46,0xd2,0x6e,0x52,0x23,0xe9,0x2c,0xa9,0x9b,0x34,0x48,0x1a,0x23,0x93,0xc9,0xda,0x64,0x6b,0xb2,0x7,0x39,0x94,0x2c,0x20,0x2b,0xc8,0x85,0xe4,0x9d,0xe4,0xc3,0xe4,0x33,0xe4,0x1b,0xe4,0x21,0xf2,0x5b,0xa,0x9d,0x62,0x40,0x71,0xa4,0xf8,0x53,0xe2,0x28,0x52,0xca,0x6a,0x4a,0x19,0xe5,0x10,0xe5,0x34,0xe5,0x6,0x65,0x98,0x32,0x41,0x55,0xa3,0x9a,0x52,0xdd,0xa8,0xa1,0x54,0x11,0x35,0x8f,0x5a,0x42,0xad,0xa1,0xb6,0x52,0xaf,0x51,0x87,0xa8,0x13,0x34,0x75,0x9a,0x39,0xcd,0x83,0x16,0x49,0x4b,0xa5,0xad,0xa2,0x95,0xd3,0x1a,0x68,0x17,0x68,0xf7,0x69,0xaf,0xe8,0x74,0xba,0x11,0xdd,0x95,0x1e,0x4e,0x97,0xd0,0x57,0xd2,0xcb,0xe9,0x47,0xe8,0x97,0xe8,0x3,0xf4,0x77,0xc,0xd,0x86,0x15,0x83,0xc7,0x88,0x67,0x28,0x19,0x9b,0x18,0x7,0x18,0x67,0x19,0x77,0x18,0xaf,0x98,0x4c,0xa6,0x19,0xd3,0x8b,0x19,0xc7,0x54,0x30,0x37,0x31,0xeb,0x98,0xe7,0x99,0xf,0x99,0x6f,0x55,0x58,0x2a,0xb6,0x2a,0x7c,0x15,0x91,0xca,0xa,0x95,0x4a,0x95,0x26,0x95,0x1b,0x2a,0x2f,0x54,0xa9,0xaa,0xa6,0xaa,0xde,0xaa,0xb,0x55,0xf3,0x55,0xcb,0x54,0x8f,0xa9,0x5e,0x53,0x7d,0xae,0x46,0x55,0x33,0x53,0xe3,0xa9,0x9,0xd4,0x96,0xab,0x55,0xaa,0x9d,0x50,0xeb,0x53,0x1b,0x53,0x67,0xa9,0x3b,0xa8,0x87,0xaa,0x67,0xa8,0x6f,0x54,0x3f,0xa4,0x7e,0x59,0xfd,0x89,0x6,0x59,0xc3,0x4c,0xc3,0x4f,0x43,0xa4,0x51,0xa0,0xb1,0x5f,0xe3,0xbc,0xc6,0x20,0xb,0x63,0x19,0xb3,0x78,0x2c,0x21,0x6b,0xd,0xab,0x86,0x75,0x81,0x35,0xc4,0x26,0xb1,0xcd,0xd9,0x7c,0x76,0x2a,0xbb,0x98,0xfd,0x1d,0xbb,0x8b,0x3d,0xaa,0xa9,0xa1,0x39,0x43,0x33,0x4a,0x33,0x57,0xb3,0x52,0xf3,0x94,0x66,0x3f,0x7,0xe3,0x98,0x71,0xf8,0x9c,0x74,0x4e,0x9,0xe7,0x28,0xa7,0x97,0xf3,0x7e,0x8a,0xde,0x14,0xef,0x29,0xe2,0x29,0x1b,0xa6,0x34,0x4c,0xb9,0x31,0x65,0x5c,0x6b,0xaa,0x96,0x97,0x96,0x58,0xab,0x48,0xab,0x51,0xab,0x47,0xeb,0xbd,0x36,0xae,0xed,0xa7,0x9d,0xa6,0xbd,0x45,0xbb,0x59,0xfb,0x81,0xe,0x41,0xc7,0x4a,0x27,0x5c,0x27,0x47,0x67,0x8f,0xce,0x5,0x9d,0xe7,0x53,0xd9,0x53,0xdd,0xa7,0xa,0xa7,0x16,0x4d,0x3d,0x3a,0xf5,0xae,0x2e,0xaa,0x6b,0xa5,0x1b,0xa1,0xbb,0x44,0x77,0xbf,0x6e,0xa7,0xee,0x98,0x9e,0xbe,0x5e,0x80,0x9e,0x4c,0x6f,0xa7,0xde,0x79,0xbd,0xe7,0xfa,0x1c,0x7d,0x2f,0xfd,0x54,0xfd,0x6d,0xfa,0xa7,0xf5,0x47,0xc,0x58,0x6,0xb3,0xc,0x24,0x6,0xdb,0xc,0xce,0x18,0x3c,0xc5,0x35,0x71,0x6f,0x3c,0x1d,0x2f,0xc7,0xdb,0xf1,0x51,0x43,0x5d,0xc3,0x40,0x43,0xa5,0x61,0x95,0x61,0x97,0xe1,0x84,0x91,0xb9,0xd1,0x3c,0xa3,0xd5,0x46,0x8d,0x46,0xf,0x8c,0x69,0xc6,0x5c,0xe3,0x24,0xe3,0x6d,0xc6,0x6d,0xc6,0xa3,0x26,0x6,0x26,0x21,0x26,0x4b,0x4d,0xea,0x4d,0xee,0x9a,0x52,0x4d,0xb9,0xa6,0x29,0xa6,0x3b,0x4c,0x3b,0x4c,0xc7,0xcd,0xcc,0xcd,0xa2,0xcd,0xd6,0x99,0x35,0x9b,0x3d,0x31,0xd7,0x32,0xe7,0x9b,0xe7,0x9b,0xd7,0x9b,0xdf,0xb7,0x60,0x5a,0x78,0x5a,0x2c,0xb6,0xa8,0xb6,0xb8,0x65,0x49,0xb2,0xe4,0x5a,0xa6,0x59,0xee,0xb6,0xbc,0x6e,0x85,0x5a,0x39,0x59,0xa5,0x58,0x55,0x5a,0x5d,0xb3,0x46,0xad,0x9d,0xad,0x25,0xd6,0xbb,0xad,0xbb,0xa7,0x11,0xa7,0xb9,0x4e,0x93,0x4e,0xab,0x9e,0xd6,0x67,0xc3,0xb0,0xf1,0xb6,0xc9,0xb6,0xa9,0xb7,0x19,0xb0,0xe5,0xd8,0x6,0xdb,0xae,0xb6,0x6d,0xb6,0x7d,0x61,0x67,0x62,0x17,0x67,0xb7,0xc5,0xae,0xc3,0xee,0x93,0xbd,0x93,0x7d,0xba,0x7d,0x8d,0xfd,0x3d,0x7,0xd,0x87,0xd9,0xe,0xab,0x1d,0x5a,0x1d,0x7e,0x73,0xb4,0x72,0x14,0x3a,0x56,0x3a,0xde,0x9a,0xce,0x9c,0xee,0x3f,0x7d,0xc5,0xf4,0x96,0xe9,0x2f,0x67,0x58,0xcf,0x10,0xcf,0xd8,0x33,0xe3,0xb6,0x13,0xcb,0x29,0xc4,0x69,0x9d,0x53,0x9b,0xd3,0x47,0x67,0x17,0x67,0xb9,0x73,0x83,0xf3,0x88,0x8b,0x89,0x4b,0x82,0xcb,0x2e,0x97,0x3e,0x2e,0x9b,0x1b,0xc6,0xdd,0xc8,0xbd,0xe4,0x4a,0x74,0xf5,0x71,0x5d,0xe1,0x7a,0xd2,0xf5,0x9d,0x9b,0xb3,0x9b,0xc2,0xed,0xa8,0xdb,0xaf,0xee,0x36,0xee,0x69,0xee,0x87,0xdc,0x9f,0xcc,0x34,0x9f,0x29,0x9e,0x59,0x33,0x73,0xd0,0xc3,0xc8,0x43,0xe0,0x51,0xe5,0xd1,0x3f,0xb,0x9f,0x95,0x30,0x6b,0xdf,0xac,0x7e,0x4f,0x43,0x4f,0x81,0x67,0xb5,0xe7,0x23,0x2f,0x63,0x2f,0x91,0x57,0xad,0xd7,0xb0,0xb7,0xa5,0x77,0xaa,0xf7,0x61,0xef,0x17,0x3e,0xf6,0x3e,0x72,0x9f,0xe3,0x3e,0xe3,0x3c,0x37,0xde,0x32,0xde,0x59,0x5f,0xcc,0x37,0xc0,0xb7,0xc8,0xb7,0xcb,0x4f,0xc3,0x6f,0x9e,0x5f,0x85,0xdf,0x43,0x7f,0x23,0xff,0x64,0xff,0x7a,0xff,0xd1,0x0,0xa7,0x80,0x25,0x1,0x67,0x3,0x89,0x81,0x41,0x81,0x5b,0x2,0xfb,0xf8,0x7a,0x7c,0x21,0xbf,0x8e,0x3f,0x3a,0xdb,0x65,0xf6,0xb2,0xd9,0xed,0x41,0x8c,0xa0,0xb9,0x41,0x15,0x41,0x8f,0x82,0xad,0x82,0xe5,0xc1,0xad,0x21,0x68,0xc8,0xec,0x90,0xad,0x21,0xf7,0xe7,0x98,0xce,0x91,0xce,0x69,0xe,0x85,0x50,0x7e,0xe8,0xd6,0xd0,0x7,0x61,0xe6,0x61,0x8b,0xc3,0x7e,0xc,0x27,0x85,0x87,0x85,0x57,0x86,0x3f,0x8e,0x70,0x88,0x58,0x1a,0xd1,0x31,0x97,0x35,0x77,0xd1,0xdc,0x43,0x73,0xdf,0x44,0xfa,0x44,0x96,0x44,0xde,0x9b,0x67,0x31,0x4f,0x39,0xaf,0x2d,0x4a,0x35,0x2a,0x3e,0xaa,0x2e,0x6a,0x3c,0xda,0x37,0xba,0x34,0xba,0x3f,0xc6,0x2e,0x66,0x59,0xcc,0xd5,0x58,0x9d,0x58,0x49,0x6c,0x4b,0x1c,0x39,0x2e,0x2a,0xae,0x36,0x6e,0x6c,0xbe,0xdf,0xfc,0xed,0xf3,0x87,0xe2,0x9d,0xe2,0xb,0xe3,0x7b,0x17,0x98,0x2f,0xc8,0x5d,0x70,0x79,0xa1,0xce,0xc2,0xf4,0x85,0xa7,0x16,0xa9,0x2e,0x12,0x2c,0x3a,0x96,0x40,0x4c,0x88,0x4e,0x38,0x94,0xf0,0x41,0x10,0x2a,0xa8,0x16,0x8c,0x25,0xf2,0x13,0x77,0x25,0x8e,0xa,0x79,0xc2,0x1d,0xc2,0x67,0x22,0x2f,0xd1,0x36,0xd1,0x88,0xd8,0x43,0x5c,0x2a,0x1e,0x4e,0xf2,0x48,0x2a,0x4d,0x7a,0x92,0xec,0x91,0xbc,0x35,0x79,0x24,0xc5,0x33,0xa5,0x2c,0xe5,0xb9,0x84,0x27,0xa9,0x90,0xbc,0x4c,0xd,0x4c,0xdd,0x9b,0x3a,0x9e,0x16,0x9a,0x76,0x20,0x6d,0x32,0x3d,0x3a,0xbd,0x31,0x83,0x92,0x91,0x90,0x71,0x42,0xaa,0x21,0x4d,0x93,0xb6,0x67,0xea,0x67,0xe6,0x66,0x76,0xcb,0xac,0x65,0x85,0xb2,0xfe,0xc5,0x6e,0x8b,0xb7,0x2f,0x1e,0x95,0x7,0xc9,0x6b,0xb3,0x90,0xac,0x5,0x59,0x2d,0xa,0xb6,0x42,0xa6,0xe8,0x54,0x5a,0x28,0xd7,0x2a,0x7,0xb2,0x67,0x65,0x57,0x66,0xbf,0xcd,0x89,0xca,0x39,0x96,0xab,0x9e,0x2b,0xcd,0xed,0xcc,0xb3,0xca,0xdb,0x90,0x37,0x9c,0xef,0x9f,0xff,0xed,0x12,0xc2,0x12,0xe1,0x92,0xb6,0xa5,0x86,0x4b,0x57,0x2d,0x1d,0x58,0xe6,0xbd,0xac,0x6a,0x39,0xb2,0x3c,0x71,0x79,0xdb,0xa,0xe3,0x15,0x5,0x2b,0x86,0x56,0x6,0xac,0x3c,0xb8,0x8a,0xb6,0x2a,0x6d,0xd5,0x4f,0xab,0xed,0x57,0x97,0xae,0x7e,0xbd,0x26,0x7a,0x4d,0x6b,0x81,0x5e,0xc1,0xca,0x82,0xc1,0xb5,0x1,0x6b,0xeb,0xb,0x55,0xa,0xe5,0x85,0x7d,0xeb,0xdc,0xd7,0xed,0x5d,0x4f,0x58,0x2f,0x59,0xdf,0xb5,0x61,0xfa,0x86,0x9d,0x1b,0x3e,0x15,0x89,0x8a,0xae,0x14,0xdb,0x17,0x97,0x15,0x7f,0xd8,0x28,0xdc,0x78,0xe5,0x1b,0x87,0x6f,0xca,0xbf,0x99,0xdc,0x94,0xb4,0xa9,0xab,0xc4,0xb9,0x64,0xcf,0x66,0xd2,0x66,0xe9,0xe6,0xde,0x2d,0x9e,0x5b,0xe,0x96,0xaa,0x97,0xe6,0x97,0xe,0x6e,0xd,0xd9,0xda,0xb4,0xd,0xdf,0x56,0xb4,0xed,0xf5,0xf6,0x45,0xdb,0x2f,0x97,0xcd,0x28,0xdb,0xbb,0x83,0xb6,0x43,0xb9,0xa3,0xbf,0x3c,0xb8,0xbc,0x65,0xa7,0xc9,0xce,0xcd,0x3b,0x3f,0x54,0xa4,0x54,0xf4,0x54,0xfa,0x54,0x36,0xee,0xd2,0xdd,0xb5,0x61,0xd7,0xf8,0x6e,0xd1,0xee,0x1b,0x7b,0xbc,0xf6,0x34,0xec,0xd5,0xdb,0x5b,0xbc,0xf7,0xfd,0x3e,0xc9,0xbe,0xdb,0x55,0x1,0x55,0x4d,0xd5,0x66,0xd5,0x65,0xfb,0x49,0xfb,0xb3,0xf7,0x3f,0xae,0x89,0xaa,0xe9,0xf8,0x96,0xfb,0x6d,0x5d,0xad,0x4e,0x6d,0x71,0xed,0xc7,0x3,0xd2,0x3,0xfd,0x7,0x23,0xe,0xb6,0xd7,0xb9,0xd4,0xd5,0x1d,0xd2,0x3d,0x54,0x52,0x8f,0xd6,0x2b,0xeb,0x47,0xe,0xc7,0x1f,0xbe,0xfe,0x9d,0xef,0x77,0x2d,0xd,0x36,0xd,0x55,0x8d,0x9c,0xc6,0xe2,0x23,0x70,0x44,0x79,0xe4,0xe9,0xf7,0x9,0xdf,0xf7,0x1e,0xd,0x3a,0xda,0x76,0x8c,0x7b,0xac,0xe1,0x7,0xd3,0x1f,0x76,0x1d,0x67,0x1d,0x2f,0x6a,0x42,0x9a,0xf2,0x9a,0x46,0x9b,0x53,0x9a,0xfb,0x5b,0x62,0x5b,0xba,0x4f,0xcc,0x3e,0xd1,0xd6,0xea,0xde,0x7a,0xfc,0x47,0xdb,0x1f,0xf,0x9c,0x34,0x3c,0x59,0x79,0x4a,0xf3,0x54,0xc9,0x69,0xda,0xe9,0x82,0xd3,0x93,0x67,0xf2,0xcf,0x8c,0x9d,0x95,0x9d,0x7d,0x7e,0x2e,0xf9,0xdc,0x60,0xdb,0xa2,0xb6,0x7b,0xe7,0x63,0xce,0xdf,0x6a,0xf,0x6f,0xef,0xba,0x10,0x74,0xe1,0xd2,0x45,0xff,0x8b,0xe7,0x3b,0xbc,0x3b,0xce,0x5c,0xf2,0xb8,0x74,0xf2,0xb2,0xdb,0xe5,0x13,0x57,0xb8,0x57,0x9a,0xaf,0x3a,0x5f,0x6d,0xea,0x74,0xea,0x3c,0xfe,0x93,0xd3,0x4f,0xc7,0xbb,0x9c,0xbb,0x9a,0xae,0xb9,0x5c,0x6b,0xb9,0xee,0x7a,0xbd,0xb5,0x7b,0x66,0xf7,0xe9,0x1b,0x9e,0x37,0xce,0xdd,0xf4,0xbd,0x79,0xf1,0x16,0xff,0xd6,0xd5,0x9e,0x39,0x3d,0xdd,0xbd,0xf3,0x7a,0x6f,0xf7,0xc5,0xf7,0xf5,0xdf,0x16,0xdd,0x7e,0x72,0x27,0xfd,0xce,0xcb,0xbb,0xd9,0x77,0x27,0xee,0xad,0xbc,0x4f,0xbc,0x5f,0xf4,0x40,0xed,0x41,0xd9,0x43,0xdd,0x87,0xd5,0x3f,0x5b,0xfe,0xdc,0xd8,0xef,0xdc,0x7f,0x6a,0xc0,0x77,0xa0,0xf3,0xd1,0xdc,0x47,0xf7,0x6,0x85,0x83,0xcf,0xfe,0x91,0xf5,0x8f,0xf,0x43,0x5,0x8f,0x99,0x8f,0xcb,0x86,0xd,0x86,0xeb,0x9e,0x38,0x3e,0x39,0x39,0xe2,0x3f,0x72,0xfd,0xe9,0xfc,0xa7,0x43,0xcf,0x64,0xcf,0x26,0x9e,0x17,0xfe,0xa2,0xfe,0xcb,0xae,0x17,0x16,0x2f,0x7e,0xf8,0xd5,0xeb,0xd7,0xce,0xd1,0x98,0xd1,0xa1,0x97,0xf2,0x97,0x93,0xbf,0x6d,0x7c,0xa5,0xfd,0xea,0xc0,0xeb,0x19,0xaf,0xdb,0xc6,0xc2,0xc6,0x1e,0xbe,0xc9,0x78,0x33,0x31,0x5e,0xf4,0x56,0xfb,0xed,0xc1,0x77,0xdc,0x77,0x1d,0xef,0xa3,0xdf,0xf,0x4f,0xe4,0x7c,0x20,0x7f,0x28,0xff,0x68,0xf9,0xb1,0xf5,0x53,0xd0,0xa7,0xfb,0x93,0x19,0x93,0x93,0xff,0x4,0x3,0x98,0xf3,0xfc,0xef,0x35,0x94,0x82,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,0xa,0x15,0x0,0x5,0x21,0x33,0xd5,0x5f,0x4d,0x0,0x0,0x1,0x3a,0x49,0x44,0x41,0x54,0x38,0xcb,0xa5,0x93,0x41,0x4a,0x3,0x51,0xc,0x86,0xbf,0x37,0xef,0xd1,0x11,0x5d,0x74,0x40,0xc1,0x5a,0xea,0x45,0xc4,0xa5,0x27,0xf0,0x34,0x73,0x84,0xe2,0x61,0x3c,0x81,0xee,0xc4,0x8b,0x8,0x76,0xd3,0xea,0x14,0x5a,0xe8,0x74,0xde,0x4b,0x5c,0x4c,0x46,0x2a,0xd4,0x3a,0xc5,0x40,0x20,0x8b,0xe4,0x4f,0xfe,0xf0,0xff,0xe,0x8,0xc0,0x0,0xc8,0x81,0x13,0xab,0x3d,0x90,0xf1,0x33,0x4,0x48,0xc0,0x16,0xd8,0x0,0x35,0xb0,0xed,0x86,0xcf,0x80,0x2,0x18,0x5a,0x9d,0x3,0xce,0x12,0x40,0x2d,0x6b,0x60,0xd,0x2c,0x81,0xa,0xdb,0x9e,0x3,0xc5,0xed,0xcd,0xdd,0xfd,0xf8,0xea,0xba,0x8c,0x29,0x16,0xaa,0xec,0xd,0xe7,0x20,0xf8,0x50,0xbd,0xcf,0xde,0xa6,0x2f,0xaf,0x4f,0x8f,0x40,0xc,0x76,0xf6,0x70,0x3c,0x9a,0x94,0xd5,0xe7,0xa2,0x88,0x31,0xa2,0xec,0x47,0x70,0x38,0x42,0x8,0xc5,0x78,0x34,0x29,0x81,0x67,0x60,0xf5,0x4d,0xa1,0x89,0x4d,0xd1,0xc4,0xe6,0xd7,0xe1,0x96,0x87,0xd2,0xc4,0x86,0x26,0x36,0x85,0x51,0x1d,0x4,0x7b,0x58,0x2e,0x22,0x88,0xa,0x7f,0x85,0xa2,0x88,0x8,0x46,0xdd,0x7,0xfb,0xb6,0x53,0x51,0x54,0x94,0x3e,0x61,0x7d,0xe,0xc8,0x42,0x47,0x2f,0x69,0xea,0x75,0x1,0x40,0xd2,0xd4,0x1,0x10,0x76,0x51,0x55,0x8f,0xba,0x80,0x5d,0x0,0x55,0x3d,0x2,0xa0,0xed,0xd3,0xe,0x40,0x5a,0xd0,0x84,0xf6,0xa4,0x20,0x2d,0x5,0x5,0x24,0x98,0x3c,0x6b,0x84,0xde,0x4f,0xa4,0xdd,0x53,0x3,0x29,0x33,0x6d,0xaf,0x71,0x59,0x95,0x79,0x8f,0xa8,0x1e,0xcc,0xcc,0x7b,0x70,0x59,0x65,0x92,0xde,0x6,0x33,0xc6,0x72,0xbe,0x98,0x4d,0x2f,0xce,0x2f,0xcb,0x24,0xa9,0xe0,0x80,0x96,0x7d,0x16,0x3e,0xe6,0x8b,0xd9,0x83,0xf9,0x61,0xe3,0x80,0xd3,0x7f,0x98,0x69,0x1d,0x8c,0x2,0x40,0x4,0x56,0xc7,0xda,0xf9,0xb,0x57,0x2d,0xbb,0xf5,0x2d,0xe4,0x89,0x1b,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -509,3 +529,42 @@ static const unsigned char vsplitter_png[]={ }; + + + +static const char *uv_editor_shader_code= + "vec3 nd1sl2=vec3(UV,0);" + "uniform float H=0;" + "float nd4sl0=H;" + "float nd7sl0=nd1sl2.x;" + "float nd7sl1=nd1sl2.y;" + "float nd7sl2=nd1sl2.z;" + "float nd2sl1def=-1;" + "float nd2sl0=nd7sl1*nd2sl1def;" + "float nd6sl1def=1;" + "float nd6sl0=nd2sl0+nd6sl1def;" + "vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);" + "vec3 nd5sl0;" + "{" + " vec3 c = nd3sl0;" + " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);" + " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);" + " nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);" + "}" + "COLOR.rgb=nd5sl0;"; + + +static const char *w_editor_shader_code= + "vec3 nd1sl2=vec3(UV,0);" + "float nd2sl1=1-nd1sl2.y;" + "vec3 nd3sl0=vec3(nd2sl1,1,1);" + "vec3 nd6sl0;" + "{" + " vec3 c = nd3sl0;" + " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);" + " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);" + " nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);" + "}" + "COLOR.rgb=nd6sl0;"; + + diff --git a/scene/resources/default_theme/uv_editor.gsl b/scene/resources/default_theme/uv_editor.gsl new file mode 100644 index 0000000000..8c24e76dd5 --- /dev/null +++ b/scene/resources/default_theme/uv_editor.gsl @@ -0,0 +1,19 @@ +vec3 nd1sl2=vec3(UV,0);
+uniform float H=0;
+float nd4sl0=H;
+float nd7sl0=nd1sl2.x;
+float nd7sl1=nd1sl2.y;
+float nd7sl2=nd1sl2.z;
+float nd2sl1def=-1;
+float nd2sl0=nd7sl1*nd2sl1def;
+float nd6sl1def=1;
+float nd6sl0=nd2sl0+nd6sl1def;
+vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);
+vec3 nd5sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd5sl0;
\ No newline at end of file diff --git a/scene/resources/default_theme/w_editor.gsl b/scene/resources/default_theme/w_editor.gsl new file mode 100644 index 0000000000..6d2dd9a0bb --- /dev/null +++ b/scene/resources/default_theme/w_editor.gsl @@ -0,0 +1,11 @@ +vec3 nd1sl2=vec3(UV,0);
+float nd2sl1=1-nd1sl2.y;
+vec3 nd3sl0=vec3(nd2sl1,1,1);
+vec3 nd6sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd6sl0;
\ No newline at end of file diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index ffa02e819c..4551aff0ef 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/environment.h b/scene/resources/environment.h index bee45b78cd..4620bf567a 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/event_stream.cpp b/scene/resources/event_stream.cpp index e8cd08c064..8667bcc5db 100644 --- a/scene/resources/event_stream.cpp +++ b/scene/resources/event_stream.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/event_stream.h b/scene/resources/event_stream.h index f9a5e3785a..6ee9b76717 100644 --- a/scene/resources/event_stream.h +++ b/scene/resources/event_stream.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 2d93113b40..0aae6fd978 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -462,31 +462,16 @@ void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,fl void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const { - Point2 pos=p_pos; - float ofs=0; - VisualServer *vs = VisualServer::get_singleton(); + Vector2 ofs; for (int i=0;i<p_text.length();i++) { - const Character * c = char_map.getptr(p_text[i]); + int width = get_char_size(p_text[i]).width; - if (!c) - continue; - -// if (p_clip_w>=0 && (ofs+c->rect.size.width)>(p_clip_w)) -// break; //width exceeded - - if (p_clip_w>=0 && (ofs+c->rect.size.width)>p_clip_w) + if (p_clip_w>=0 && (ofs.x+width)>p_clip_w) break; //clip - Point2 cpos=pos; - cpos.x+=ofs+c->h_align; - cpos.y-=ascent; - cpos.y+=c->v_align; - ERR_CONTINUE( c->texture_idx<-1 || c->texture_idx>=textures.size()); - if (c->texture_idx!=-1) - textures[c->texture_idx]->draw_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), c->rect, p_modulate ); - - ofs+=get_char_size(p_text[i],p_text[i+1]).width; + + ofs.x+=draw_char(p_canvas_item,p_pos+ofs,p_text[i],p_text[i+1],p_modulate); } } @@ -494,8 +479,11 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ const Character * c = char_map.getptr(p_char); - if (!c) + if (!c) { + if (fallback.is_valid()) + return fallback->draw_char(p_canvas_item,p_pos,p_char,p_next,p_modulate); return 0; + } Point2 cpos=p_pos; cpos.x+=c->h_align; @@ -508,6 +496,16 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ return get_char_size(p_char,p_next).width; } +void Font::set_fallback(const Ref<Font> &p_fallback) { + + fallback=p_fallback; +} + +Ref<Font> Font::get_fallback() const{ + + return fallback; +} + void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); @@ -519,7 +517,7 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_descent"),&Font::get_descent); ObjectTypeDB::bind_method(_MD("add_kerning_pair","char_a","char_b","kerning"),&Font::add_kerning_pair); - ObjectTypeDB::bind_method(_MD("get_kerning_pair"),&Font::get_kerning_pair); + ObjectTypeDB::bind_method(_MD("get_kerning_pair","char_a","char_b"),&Font::get_kerning_pair); 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)); @@ -548,6 +546,8 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_textures"),&Font::_set_textures); ObjectTypeDB::bind_method(_MD("_get_textures"),&Font::_get_textures); + ObjectTypeDB::bind_method(_MD("set_fallback","fallback"),&Font::set_fallback); + ObjectTypeDB::bind_method(_MD("get_fallback"),&Font::get_fallback); ADD_PROPERTY( PropertyInfo( Variant::ARRAY, "textures", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_textures"), _SCS("_get_textures") ); ADD_PROPERTY( PropertyInfo( Variant::INT_ARRAY, "chars", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_chars"), _SCS("_get_chars") ); @@ -556,6 +556,7 @@ 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") ); + ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "fallback", PROPERTY_HINT_RESOURCE_TYPE,"Font" ), _SCS("set_fallback"), _SCS("get_fallback") ); } diff --git a/scene/resources/font.h b/scene/resources/font.h index 6728b59f8e..61f0352992 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -84,6 +84,7 @@ private: void _set_textures(const Vector<Variant> & p_textures); Vector<Variant> _get_textures() const; + Ref<Font> fallback; protected: static void _bind_methods(); @@ -113,9 +114,13 @@ public: int get_kerning_pair(CharType p_A,CharType p_B) const; Vector<KerningPairKey> get_kerning_pair_keys() const; - _FORCE_INLINE_ Size2 get_char_size(CharType p_char,CharType p_next=0) const; + inline Size2 get_char_size(CharType p_char,CharType p_next=0) const; Size2 get_string_size(const String& p_string) const; + + void set_fallback(const Ref<Font> &p_fallback); + Ref<Font> get_fallback() const; + void clear(); void set_distance_field_hint(bool p_distance_field); @@ -134,8 +139,11 @@ Size2 Font::get_char_size(CharType p_char,CharType p_next) const { const Character * c = char_map.getptr(p_char); - if (!c) + if (!c) { + if (fallback.is_valid()) + return fallback->get_char_size(p_char,p_next); return Size2(); + } Size2 ret(c->advance,c->rect.size.y); diff --git a/scene/resources/gibberish_stream.cpp b/scene/resources/gibberish_stream.cpp index 7af81bd992..9d67069a6c 100644 --- a/scene/resources/gibberish_stream.cpp +++ b/scene/resources/gibberish_stream.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/gibberish_stream.h b/scene/resources/gibberish_stream.h index 77393db9f4..e06dc5eff2 100644 --- a/scene/resources/gibberish_stream.h +++ b/scene/resources/gibberish_stream.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/height_map_shape.cpp b/scene/resources/height_map_shape.cpp index 2c7c5384fa..e7b53c92c2 100644 --- a/scene/resources/height_map_shape.cpp +++ b/scene/resources/height_map_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/height_map_shape.h b/scene/resources/height_map_shape.h index 46d49dab08..5494075107 100644 --- a/scene/resources/height_map_shape.h +++ b/scene/resources/height_map_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 55bb4e9073..e56314c1f8 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -535,6 +535,8 @@ void ShaderMaterial::_shader_changed() { void ShaderMaterial::set_shader(const Ref<Shader>& p_shader) { + ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_MATERIAL); + if (shader.is_valid()) shader->disconnect(SceneStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_shader_changed); shader=p_shader; @@ -570,8 +572,8 @@ void ShaderMaterial::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"), &ShaderMaterial::set_shader ); ObjectTypeDB::bind_method(_MD("get_shader:Shader"), &ShaderMaterial::get_shader ); - ObjectTypeDB::bind_method(_MD("set_shader_param","param","value:var"), &ShaderMaterial::set_shader_param); - ObjectTypeDB::bind_method(_MD("get_shader_param:var","param"), &ShaderMaterial::get_shader_param); + ObjectTypeDB::bind_method(_MD("set_shader_param","param","value:Variant"), &ShaderMaterial::set_shader_param); + ObjectTypeDB::bind_method(_MD("get_shader_param:Variant","param"), &ShaderMaterial::get_shader_param); ObjectTypeDB::bind_method(_MD("_shader_changed"), &ShaderMaterial::_shader_changed ); } diff --git a/scene/resources/material.h b/scene/resources/material.h index 7b7bc50567..96b33ce129 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 8cb0904415..9537fa269f 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -971,7 +971,7 @@ void Mesh::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_morph_target_mode","mode"),&Mesh::set_morph_target_mode); ObjectTypeDB::bind_method(_MD("get_morph_target_mode"),&Mesh::get_morph_target_mode); - ObjectTypeDB::bind_method(_MD("add_surface","primitive","arrays","morph_arrays"),&Mesh::add_surface,DEFVAL(Array())); + ObjectTypeDB::bind_method(_MD("add_surface","primitive","arrays","morph_arrays","alphasort"),&Mesh::add_surface,DEFVAL(Array()),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_surface_count"),&Mesh::get_surface_count); ObjectTypeDB::bind_method(_MD("surface_remove","surf_idx"),&Mesh::surface_remove); ObjectTypeDB::bind_method(_MD("surface_get_array_len","surf_idx"),&Mesh::surface_get_array_len); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 50463ce80e..e0d9bdf7a8 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 42aaed39e1..fb0fc2a247 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/mesh_data_tool.h b/scene/resources/mesh_data_tool.h index e7e7924e98..4a26fc2628 100644 --- a/scene/resources/mesh_data_tool.h +++ b/scene/resources/mesh_data_tool.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 5ebab9be76..8643e96303 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index a6a7b71669..9a468d5555 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index 0755d101b2..c5ade63124 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -224,13 +224,13 @@ void MultiMesh::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MultiMesh::set_mesh); ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MultiMesh::get_mesh); - ObjectTypeDB::bind_method(_MD("set_instance_count"),&MultiMesh::set_instance_count); + ObjectTypeDB::bind_method(_MD("set_instance_count","count"),&MultiMesh::set_instance_count); ObjectTypeDB::bind_method(_MD("get_instance_count"),&MultiMesh::get_instance_count); - ObjectTypeDB::bind_method(_MD("set_instance_transform"),&MultiMesh::set_instance_transform); - ObjectTypeDB::bind_method(_MD("get_instance_transform"),&MultiMesh::get_instance_transform); - ObjectTypeDB::bind_method(_MD("set_instance_color"),&MultiMesh::set_instance_color); - ObjectTypeDB::bind_method(_MD("get_instance_color"),&MultiMesh::get_instance_color); - ObjectTypeDB::bind_method(_MD("set_aabb"),&MultiMesh::set_aabb); + ObjectTypeDB::bind_method(_MD("set_instance_transform","instance","transform"),&MultiMesh::set_instance_transform); + ObjectTypeDB::bind_method(_MD("get_instance_transform","instance"),&MultiMesh::get_instance_transform); + ObjectTypeDB::bind_method(_MD("set_instance_color","instance","color"),&MultiMesh::set_instance_color); + ObjectTypeDB::bind_method(_MD("get_instance_color","instance"),&MultiMesh::get_instance_color); + ObjectTypeDB::bind_method(_MD("set_aabb","visibility_aabb"),&MultiMesh::set_aabb); ObjectTypeDB::bind_method(_MD("get_aabb"),&MultiMesh::get_aabb); ObjectTypeDB::bind_method(_MD("generate_aabb"),&MultiMesh::generate_aabb); diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h index c2736e3070..0cf9e92def 100644 --- a/scene/resources/multimesh.h +++ b/scene/resources/multimesh.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 896b4fb2fa..43196a43d4 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -33,7 +33,7 @@ #include "scene/gui/control.h" #include "scene/2d/node_2d.h" #include "scene/main/instance_placeholder.h" - +#include "core/core_string_names.h" #define PACK_VERSION 2 bool SceneState::can_instance() const { @@ -99,6 +99,7 @@ Node *SceneState::instance(bool p_gen_edit_state) const { Node *node=NULL; + if (i==0 && base_scene_idx>=0) { //scene inheritance on root node //print_line("scene inherit"); @@ -193,7 +194,26 @@ Node *SceneState::instance(bool p_gen_edit_state) const { ERR_FAIL_INDEX_V( nprops[j].name, sname_count, NULL ); ERR_FAIL_INDEX_V( nprops[j].value, prop_count, NULL ); - node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid); + if (snames[ nprops[j].name ]==CoreStringNames::get_singleton()->_script) { + //work around to avoid old script variables from disappearing, should be the proper fix to: + //https://github.com/godotengine/godot/issues/2958 + + //store old state + List<Pair<StringName,Variant> > old_state; + if (node->get_script_instance()) { + node->get_script_instance()->get_property_state(old_state); + } + + node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid); + + //restore old state for new script, if exists + for (List<Pair<StringName,Variant> >::Element *E=old_state.front();E;E=E->next()) { + node->set(E->get().first,E->get().second); + } + } else { + + node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid); + } } } @@ -460,6 +480,7 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S List<PropertyInfo> plist; p_node->get_property_list(&plist); + bool saved_script=false; for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { @@ -508,8 +529,23 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S break; } } +#if 0 +// this workaround ended up causing problems: +https://github.com/godotengine/godot/issues/3127 + if (saved_script && exists && p_node->get_script_instance()) { + //if this is an overriden value by another script, save it anyway + //as the script change will erase it + //https://github.com/godotengine/godot/issues/2958 + + bool valid=false; + p_node->get_script_instance()->get_property_type(name,&valid); + if (valid) { + exists=false; + isdefault=false; + } + } - +#endif if (exists && bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) { //exists and did not change continue; @@ -530,6 +566,9 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S } } + if (name=="script/script") + saved_script=true; + NodeData::Property prop; prop.name=_nm_get_string( name,name_map); prop.value=_vm_get_variant( value, variant_map); @@ -1280,15 +1319,18 @@ StringName SceneState::get_node_name(int p_idx) const { Ref<PackedScene> SceneState::get_node_instance(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,nodes.size(),Ref<PackedScene>()); + if (nodes[p_idx].instance>=0) { return variants[nodes[p_idx].instance]; - } else if (nodes[p_idx].parent<=0 || nodes[p_idx].parent==NO_PARENT_SAVED) { + } else if (nodes[p_idx].parent<0 || nodes[p_idx].parent==NO_PARENT_SAVED) { if (base_scene_idx>=0) { return variants[base_scene_idx]; } } + + return Ref<PackedScene>(); @@ -1438,11 +1480,122 @@ Array SceneState::get_connection_binds(int p_idx) const { Vector<NodePath> SceneState::get_editable_instances() const { return editable_instances; } +//add + +int SceneState::add_name(const StringName& p_name) { + + names.push_back(p_name); + return names.size()-1; +} + +int SceneState::add_value(const Variant& p_value) { + + variants.push_back(p_value); + return variants.size()-1; +} + +int SceneState::add_node_path(const NodePath& p_path){ + + node_paths.push_back(p_path); + return (node_paths.size()-1)|FLAG_ID_IS_PATH; +} +int SceneState::add_node(int p_parent,int p_owner,int p_type,int p_name, int p_instance){ + + NodeData nd; + nd.parent=p_parent; + nd.owner=p_owner; + nd.type=p_type; + nd.name=p_name; + nd.instance=p_instance; + + nodes.push_back(nd); + + return nodes.size()-1; +} +void SceneState::add_node_property(int p_node,int p_name,int p_value){ + ERR_FAIL_INDEX(p_node,nodes.size()); + ERR_FAIL_INDEX(p_name,names.size()); + ERR_FAIL_INDEX(p_value,variants.size()); + + NodeData::Property prop; + prop.name=p_name; + prop.value=p_value; + nodes[p_node].properties.push_back(prop); +} +void SceneState::add_node_group(int p_node,int p_group){ + + ERR_FAIL_INDEX(p_node,nodes.size()); + ERR_FAIL_INDEX(p_group,names.size()); + nodes[p_node].groups.push_back(p_group); + +} +void SceneState::set_base_scene(int p_idx){ + + ERR_FAIL_INDEX(p_idx,variants.size()); + base_scene_idx=p_idx; +} +void SceneState::add_connection(int p_from,int p_to, int p_signal, int p_method, int p_flags,const Vector<int>& p_binds){ + + ERR_FAIL_INDEX(p_signal,names.size()); + ERR_FAIL_INDEX(p_method,names.size()); + + for(int i=0;i<p_binds.size();i++) { + ERR_FAIL_INDEX(p_binds[i],variants.size()); + } + ConnectionData c; + c.from=p_from; + c.to=p_to; + c.signal=p_signal; + c.method=p_method; + c.flags=p_flags; + c.binds=p_binds; + connections.push_back(c); + +} +void SceneState::add_editable_instance(const NodePath& p_path){ + + editable_instances.push_back(p_path); +} + +DVector<String> SceneState::_get_node_groups(int p_idx) const { + + Vector<StringName> groups = get_node_groups(p_idx); + DVector<String> ret; + + for(int i=0;i<groups.size();i++) + ret.push_back(groups[i]); + + return ret; +} + +void SceneState::_bind_methods() { + + //unbuild API + + ObjectTypeDB::bind_method(_MD("get_node_count"),&SceneState::get_node_count); + ObjectTypeDB::bind_method(_MD("get_node_type","idx"),&SceneState::get_node_type); + ObjectTypeDB::bind_method(_MD("get_node_name","idx"),&SceneState::get_node_name); + ObjectTypeDB::bind_method(_MD("get_node_path","idx","for_parent"),&SceneState::get_node_path,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("get_node_owner_path","idx"),&SceneState::get_node_owner_path); + ObjectTypeDB::bind_method(_MD("get_node_instance:PackedScene","idx"),&SceneState::get_node_instance); + ObjectTypeDB::bind_method(_MD("get_node_groups","idx"),&SceneState::_get_node_groups); + ObjectTypeDB::bind_method(_MD("get_node_property_count","idx"),&SceneState::get_node_property_count); + ObjectTypeDB::bind_method(_MD("get_node_property_name","idx","prop_idx"),&SceneState::get_node_property_name); + ObjectTypeDB::bind_method(_MD("get_node_property_value","idx","prop_idx"),&SceneState::get_node_property_value); + ObjectTypeDB::bind_method(_MD("get_connection_count"),&SceneState::get_connection_count); + ObjectTypeDB::bind_method(_MD("get_connection_source","idx"),&SceneState::get_connection_source); + ObjectTypeDB::bind_method(_MD("get_connection_signal","idx"),&SceneState::get_connection_signal); + ObjectTypeDB::bind_method(_MD("get_connection_target","idx"),&SceneState::get_connection_target); + ObjectTypeDB::bind_method(_MD("get_connection_method","idx"),&SceneState::get_connection_method); + ObjectTypeDB::bind_method(_MD("get_connection_flags","idx"),&SceneState::get_connection_flags); + ObjectTypeDB::bind_method(_MD("get_connection_binds","idx"),&SceneState::get_connection_binds); +} SceneState::SceneState() { base_scene_idx=-1; + last_modified_time=0; } @@ -1502,6 +1655,25 @@ Node *PackedScene::instance(bool p_gen_edit_state) const { return s; } +void PackedScene::replace_state(Ref<SceneState> p_by) { + + state=p_by; + state->set_path(get_path()); +#ifdef TOOLS_ENABLED + state->set_last_modified_time(get_last_modified_time()); +#endif + +} + +void PackedScene::recreate_state() { + + state = Ref<SceneState>( memnew( SceneState )); + state->set_path(get_path()); +#ifdef TOOLS_ENABLED + state->set_last_modified_time(get_last_modified_time()); +#endif +} + Ref<SceneState> PackedScene::get_state() { return state; @@ -1513,6 +1685,7 @@ void PackedScene::set_path(const String& p_path,bool p_take_over) { Resource::set_path(p_path,p_take_over); } + void PackedScene::_bind_methods() { ObjectTypeDB::bind_method(_MD("pack","path:Node"),&PackedScene::pack); @@ -1520,6 +1693,7 @@ void PackedScene::_bind_methods() { ObjectTypeDB::bind_method(_MD("can_instance"),&PackedScene::can_instance); ObjectTypeDB::bind_method(_MD("_set_bundled_scene"),&PackedScene::_set_bundled_scene); ObjectTypeDB::bind_method(_MD("_get_bundled_scene"),&PackedScene::_get_bundled_scene); + ObjectTypeDB::bind_method(_MD("get_state:SceneState"),&PackedScene::get_state); ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_bundled"),_SCS("_set_bundled_scene"),_SCS("_get_bundled_scene")); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index 3956d2abe4..7fda4392d8 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -36,6 +36,8 @@ class SceneState : public Reference { OBJ_TYPE( SceneState, Reference ); + + Vector<StringName> names; Vector<Variant> variants; Vector<NodePath> node_paths; @@ -50,7 +52,6 @@ class SceneState : public Reference { FLAG_INSTANCE_IS_PLACEHOLDER=(1<<30), FLAG_MASK=(1<<24)-1, NO_PARENT_SAVED=0x7FFFFFFF, - TYPE_INSTANCED=0x7FFFFFFF, }; @@ -99,11 +100,24 @@ class SceneState : public Reference { String path; + uint64_t last_modified_time; + _FORCE_INLINE_ Ref<SceneState> _get_base_scene_state() const; static bool disable_placeholders; + + DVector<String> _get_node_groups(int p_idx) const; + +protected: + + static void _bind_methods(); + public: + enum { + TYPE_INSTANCED=0x7FFFFFFF + }; + static void set_disable_placeholders(bool p_disable); int find_node_by_path(const NodePath& p_node) const; @@ -126,7 +140,7 @@ public: Node *instance(bool p_gen_edit_state=false) const; - //build-unbuild API + //unbuild API int get_node_count() const; StringName get_node_type(int p_idx) const; @@ -150,6 +164,22 @@ public: Vector<NodePath> get_editable_instances() const; + //build API + + int add_name(const StringName& p_name); + int add_value(const Variant& p_value); + int add_node_path(const NodePath& p_path); + int add_node(int p_parent,int p_owner,int p_type,int p_name, int p_instance); + void add_node_property(int p_node,int p_name,int p_value); + void add_node_group(int p_node,int p_group); + void set_base_scene(int p_idx); + void add_connection(int p_from,int p_to, int p_signal, int p_method, int p_flags,const Vector<int>& p_binds); + void add_editable_instance(const NodePath& p_path); + + virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; } + uint64_t get_last_modified_time() const { return last_modified_time; } + + SceneState(); }; @@ -176,8 +206,14 @@ public: bool can_instance() const; Node *instance(bool p_gen_edit_state=false) const; + void recreate_state(); + void replace_state(Ref<SceneState> p_by); + virtual void set_path(const String& p_path,bool p_take_over=false); +#ifdef TOOLS_ENABLED + virtual void set_last_modified_time(uint64_t p_time) { state->set_last_modified_time(p_time); } +#endif Ref<SceneState> get_state(); PackedScene(); diff --git a/scene/resources/plane_shape.cpp b/scene/resources/plane_shape.cpp index 760a36a91e..f551414f61 100644 --- a/scene/resources/plane_shape.cpp +++ b/scene/resources/plane_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/plane_shape.h b/scene/resources/plane_shape.h index dd285171c4..543c433965 100644 --- a/scene/resources/plane_shape.h +++ b/scene/resources/plane_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/ray_shape.cpp b/scene/resources/ray_shape.cpp index ee55cc6e37..73ce4de976 100644 --- a/scene/resources/ray_shape.cpp +++ b/scene/resources/ray_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/ray_shape.h b/scene/resources/ray_shape.h index edb29b83b5..0218045247 100644 --- a/scene/resources/ray_shape.h +++ b/scene/resources/ray_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp index 7903d88736..bc0f86f0a7 100644 --- a/scene/resources/rectangle_shape_2d.cpp +++ b/scene/resources/rectangle_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/rectangle_shape_2d.h b/scene/resources/rectangle_shape_2d.h index 96de02fb70..1ffbe1e356 100644 --- a/scene/resources/rectangle_shape_2d.h +++ b/scene/resources/rectangle_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/rich_text.cpp b/scene/resources/rich_text.cpp index 7e58a19ac3..8acf5ff39b 100644 --- a/scene/resources/rich_text.cpp +++ b/scene/resources/rich_text.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/rich_text.h b/scene/resources/rich_text.h index 9dfffbfeb3..c74a391b10 100644 --- a/scene/resources/rich_text.h +++ b/scene/resources/rich_text.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/room.cpp b/scene/resources/room.cpp index 3673b18394..0f9eb85244 100644 --- a/scene/resources/room.cpp +++ b/scene/resources/room.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/room.h b/scene/resources/room.h index f621d8f1bf..c5aaea311e 100644 --- a/scene/resources/room.h +++ b/scene/resources/room.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/sample.cpp b/scene/resources/sample.cpp index 0a785e7bf6..4b25a2c490 100644 --- a/scene/resources/sample.cpp +++ b/scene/resources/sample.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -210,11 +210,11 @@ void Sample::_bind_methods(){ ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"), _SCS("_get_data") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "stereo"), _SCS(""), _SCS("is_stereo") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "length"), _SCS(""), _SCS("get_length") ); + ADD_PROPERTY( PropertyInfo( Variant::INT, "length",PROPERTY_HINT_RANGE,"0,999999999"), _SCS(""), _SCS("get_length") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "mix_rate", PROPERTY_HINT_RANGE,"1,192000,1" ), _SCS("set_mix_rate"), _SCS("get_mix_rate") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_format", PROPERTY_HINT_ENUM,"None,Forward,PingPong" ), _SCS("set_loop_format"), _SCS("get_loop_format") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_begin", PROPERTY_HINT_RANGE,"0,"+itos(99999999)+",1"), _SCS("set_loop_begin"), _SCS("get_loop_begin") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_end", PROPERTY_HINT_RANGE,"0,"+itos(99999999)+",1"), _SCS("set_loop_end"), _SCS("get_loop_end") ); + ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_begin", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_begin"), _SCS("get_loop_begin") ); + ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_end", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_end"), _SCS("get_loop_end") ); BIND_CONSTANT( FORMAT_PCM8 ); BIND_CONSTANT( FORMAT_PCM16 ); diff --git a/scene/resources/sample.h b/scene/resources/sample.h index 4877e0b841..0a88167233 100644 --- a/scene/resources/sample.h +++ b/scene/resources/sample.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/sample_library.cpp b/scene/resources/sample_library.cpp index ffcaa1e675..5b70ee0e11 100644 --- a/scene/resources/sample_library.cpp +++ b/scene/resources/sample_library.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/sample_library.h b/scene/resources/sample_library.h index 88519e7035..8377967106 100644 --- a/scene/resources/sample_library.h +++ b/scene/resources/sample_library.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 4fc3ece758..f3dcf16e28 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -9,11 +9,7 @@ #include "version.h" #include "os/dir_access.h" - -Error ResourceInteractiveLoaderText::parse_property(Variant& r_v, String &r_name) { - - return OK; -} +#define _printerr() ERR_PRINT(String(res_path+":"+itos(lines)+" - Parse Error: "+error_text).utf8().get_data()); @@ -29,44 +25,113 @@ Ref<Resource> ResourceInteractiveLoaderText::get_resource() { return resource; } -Error ResourceInteractiveLoaderText::poll() { -#if 0 - if (error!=OK) - return error; +Error ResourceInteractiveLoaderText::_parse_sub_resource(VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str) { - bool exit; - Tag *tag = parse_tag(&exit); + VariantParser::Token token; + VariantParser::get_token(p_stream,token,line,r_err_str); + if (token.type!=VariantParser::TK_NUMBER) { + r_err_str="Expected number (sub-resource index)"; + return ERR_PARSE_ERROR; + } + int index = token.value; - if (!tag) { - error=ERR_FILE_CORRUPT; - if (!exit) // shouldn't have exited - ERR_FAIL_V(error); - error=ERR_FILE_EOF; - return error; + String path = local_path+"::"+itos(index); + + if (!ResourceCache::has(path)) { + r_err_str="Can't load cached sub-resource: "+path; + return ERR_PARSE_ERROR; } - RES res; - //Object *obj=NULL; + r_res=RES(ResourceCache::get(path)); - bool main; + VariantParser::get_token(p_stream,token,line,r_err_str); + if (token.type!=VariantParser::TK_PARENTHESIS_CLOSE) { + r_err_str="Expected ')'"; + return ERR_PARSE_ERROR; + } - if (tag->name=="ext_resource") { - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field."); - ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT); + return OK; +} + +Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str){ + + VariantParser::Token token; + VariantParser::get_token(p_stream,token,line,r_err_str); + if (token.type!=VariantParser::TK_NUMBER) { + r_err_str="Expected number (sub-resource index)"; + return ERR_PARSE_ERROR; + } + + int id = token.value; + + + if (!ext_resources.has(id)) { + r_err_str="Can't load cached ext-resource #"+itos(id); + return ERR_PARSE_ERROR; + } + + String path = ext_resources[id].path; + String type = ext_resources[id].type; + + if (path.find("://")==-1 && path.is_rel_path()) { + // path is relative to file being loaded, so convert to a resource path + path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); + + } + + r_res=ResourceLoader::load(path,type); + + if (r_res.is_null()) { + WARN_PRINT(String("Couldn't load external resource: "+path).utf8().get_data()); + } + + VariantParser::get_token(p_stream,token,line,r_err_str); + if (token.type!=VariantParser::TK_PARENTHESIS_CLOSE) { + r_err_str="Expected ')'"; + return ERR_PARSE_ERROR; + } + + + return OK; +} - String type="Resource"; - if (tag->args.has("type")) - type=tag->args["type"]; - String path = tag->args["path"]; +Error ResourceInteractiveLoaderText::poll() { + + if (error!=OK) + return error; + + if (next_tag.name=="ext_resource") { + + + if (!next_tag.fields.has("path")) { + error=ERR_FILE_CORRUPT; + error_text="Missing 'path' in external resource tag"; + _printerr(); + return error; + } + + if (!next_tag.fields.has("type")) { + error=ERR_FILE_CORRUPT; + error_text="Missing 'type' in external resource tag"; + _printerr(); + return error; + } + if (!next_tag.fields.has("id")) { + error=ERR_FILE_CORRUPT; + error_text="Missing 'id' in external resource tag"; + _printerr(); + return error; + } + + String path=next_tag.fields["path"]; + String type=next_tag.fields["type"]; + int index=next_tag.fields["id"]; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?."); - ERR_FAIL_COND_V(path.begins_with("local://"),ERR_FILE_CORRUPT); if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path @@ -82,8 +147,10 @@ Error ResourceInteractiveLoaderText::poll() { if (res.is_null()) { if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path); - ERR_FAIL_V(error); + error=ERR_FILE_CORRUPT; + error_text="[ext_resource] referenced nonexistent resource at: "+path; + _printerr(); + return error; } else { ResourceLoader::notify_dependency_error(local_path,path,type); } @@ -92,236 +159,443 @@ Error ResourceInteractiveLoaderText::poll() { resource_cache.push_back(res); } - if (tag->args.has("index")) { - ExtResource er; - er.path=path; - er.type=type; - ext_resources[tag->args["index"].to_int()]=er; + ExtResource er; + er.path=path; + er.type=type; + ext_resources[index]=er; + + error = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); + + if (error) { + _printerr(); } + return error; + + + } else if (next_tag.name=="sub_resource") { + + + if (!next_tag.fields.has("type")) { + error=ERR_FILE_CORRUPT; + error_text="Missing 'type' in external resource tag"; + _printerr(); + return error; + } - Error err = close_tag("ext_resource"); - if (err) + if (!next_tag.fields.has("id")) { + error=ERR_FILE_CORRUPT; + error_text="Missing 'index' in external resource tag"; + _printerr(); return error; + } + String type=next_tag.fields["type"]; + int id=next_tag.fields["id"]; - error=OK; - resource_current++; - return error; + String path = local_path+"::"+itos(id); - } else if (tag->name=="resource") { - main=false; - } else if (tag->name=="main_resource") { - main=true; - } else { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": unexpected main tag: "+tag->name); - error=ERR_FILE_CORRUPT; - ERR_FAIL_V(error); - } + //bool exists=ResourceCache::has(path); + Ref<Resource> res; - String type; - String path; - int subres=0; + if ( !ResourceCache::has(path)) { //only if it doesn't exist - if (!main) { - //loading resource + Object *obj = ObjectTypeDB::instance(type); + if (!obj) { + + error_text+="Can't create sub resource of type: "+type; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'len' field."); - ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT); - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'type' field."); - ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT); - path=tag->args["path"]; - error=OK; + Resource *r = obj->cast_to<Resource>(); + if (!r) { - if (path.begins_with("local://")) { - //built-in resource (but really external) + error_text+="Can't create sub resource of type, because not a resource: "+type; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } + + res=Ref<Resource>(r); + resource_cache.push_back(res); + res->set_path(path); - path=path.replace("local://",""); - subres=path.to_int(); - path=local_path+"::"+path; } + while(true) { - if (ResourceCache::has(path)) { - Error err = close_tag(tag->name); - if (err) { + String assign; + Variant value; + + error = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,&rp); + + if (error) { + _printerr(); + return error; + } + + if (assign!=String()) { + if (res.is_valid()) { + res->set(assign,value); + } + //it's assignment + } else if (next_tag.name!=String()) { + + error=OK; + break; + } else { error=ERR_FILE_CORRUPT; + error_text="Premature end of file while parsing [sub_resource]"; + _printerr(); + return error; } - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unable to close <resource> tag."); - ERR_FAIL_COND_V( err, err ); - resource_current++; - error=OK; - return OK; + + } - type = tag->args["type"]; - } else { - type=resource_type; - } + return OK; - Object *obj = ObjectTypeDB::instance(type); - if (!obj) { - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object of unrecognized type in file: "+type); - } - ERR_FAIL_COND_V(!obj,ERR_FILE_CORRUPT); + } else if (next_tag.name=="resource") { - Resource *r = obj->cast_to<Resource>(); - if (!r) { - error=ERR_FILE_CORRUPT; - memdelete(obj); //bye - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object type in resource field not a resource, type is: "+obj->get_type()); - ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT); - } + if (is_scene) { - res = RES( r ); - if (path!="") - r->set_path(path); - r->set_subindex(subres); + error_text+="found the 'resource' tag on a scene file!"; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } - //load properties + Object *obj = ObjectTypeDB::instance(res_type); + if (!obj) { - while(true) { + error_text+="Can't create sub resource of type: "+res_type; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } - String name; - Variant v; - Error err; - err = parse_property(v,name); - if (err==ERR_FILE_EOF) //tag closed - break; - if (err!=OK) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Text Parsing aborted."); - ERR_FAIL_COND_V(err!=OK,ERR_FILE_CORRUPT); + + Resource *r = obj->cast_to<Resource>(); + if (!r) { + + error_text+="Can't create sub resource of type, because not a resource: "+res_type; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; } - obj->set(name,v); - } -#ifdef TOOLS_ENABLED - res->set_edited(false); -#endif - resource_cache.push_back(res); //keep it in mem until finished loading - resource_current++; - if (main) { - f->close(); - resource=res; - resource->set_path(res_path); - error=ERR_FILE_EOF; - return error; + resource=Ref<Resource>(r); - } - error=OK; -#endif - return OK; -} + while(true) { -int ResourceInteractiveLoaderText::get_stage() const { + String assign; + Variant value; - return resource_current; -} -int ResourceInteractiveLoaderText::get_stage_count() const { + error = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,&rp); - return resources_total;//+ext_resources; -} + if (error) { + if (error!=ERR_FILE_EOF) { + _printerr(); + } else { + if (!ResourceCache::has(res_path)) { + resource->set_path(res_path); + } + } + return error; + } -ResourceInteractiveLoaderText::~ResourceInteractiveLoaderText() { + if (assign!=String()) { + resource->set(assign,value); + //it's assignment + } else if (next_tag.name!=String()) { - memdelete(f); -} + error=ERR_FILE_CORRUPT; + error_text="Extra tag found when parsing main resource file"; + _printerr(); + return error; + } else { + error=ERR_FILE_EOF; + return error; + } -void ResourceInteractiveLoaderText::get_dependencies(FileAccess *f,List<String> *p_dependencies,bool p_add_types) { + } -#if 0 - open(f); - ERR_FAIL_COND(error!=OK); + return OK; - while(true) { - bool exit; - Tag *tag = parse_tag(&exit); + } else if (next_tag.name=="node") { + if (!is_scene) { - if (!tag) { + error_text+="found the 'node' tag on a resource file!"; + _printerr(); error=ERR_FILE_CORRUPT; - ERR_FAIL_COND(!exit); - error=ERR_FILE_EOF; - return; + return error; } - if (tag->name!="ext_resource") { + /* + int add_name(const StringName& p_name); + int add_value(const Variant& p_value); + int add_node_path(const NodePath& p_path); + int add_node(int p_parent,int p_owner,int p_type,int p_name, int p_instance); + void add_node_property(int p_node,int p_name,int p_value); + void add_node_group(int p_node,int p_group); + void set_base_scene(int p_idx); + void add_connection(int p_from,int p_to, int p_signal, int p_method, int p_flags,const Vector<int>& p_binds); + void add_editable_instance(const NodePath& p_path); + + */ + + int parent=-1; + int owner=-1; + int type=-1; + int name=-1; + int instance=-1; +// int base_scene=-1; + + if (next_tag.fields.has("name")) { + name=packed_scene->get_state()->add_name(next_tag.fields["name"]); + } - return; + if (next_tag.fields.has("parent")) { + parent=packed_scene->get_state()->add_node_path(next_tag.fields["parent"]); } - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field."); - ERR_FAIL_COND(!tag->args.has("path")); - String path = tag->args["path"]; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?."); - ERR_FAIL_COND(path.begins_with("local://")); + if (next_tag.fields.has("type")) { + type=packed_scene->get_state()->add_name(next_tag.fields["type"]); + } else { + type=SceneState::TYPE_INSTANCED; //no type? assume this was instanced + } - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); + + if (next_tag.fields.has("instance")) { + + instance=packed_scene->get_state()->add_value(next_tag.fields["instance"]); + + if (packed_scene->get_state()->get_node_count()==0 && parent==-1) { + packed_scene->get_state()->set_base_scene(instance); + instance=-1; + } } - if (path.ends_with("*")) { - ERR_FAIL_COND(!tag->args.has("type")); - String type = tag->args["type"]; - path = ResourceLoader::guess_full_filename(path,type); + if (next_tag.fields.has("owner")) { + owner=packed_scene->get_state()->add_node_path(next_tag.fields["owner"]); + } else { + if (parent!=-1 && !(type==SceneState::TYPE_INSTANCED && instance==-1)) + owner=0; //if no owner, owner is root } - if (p_add_types && tag->args.has("type")) { - path+="::"+tag->args["type"]; + int node_id = packed_scene->get_state()->add_node(parent,owner,type,name,instance); + + if (next_tag.fields.has("groups")) { + + Array groups = next_tag.fields["groups"]; + for (int i=0;i<groups.size();i++) { + packed_scene->get_state()->add_node_group(node_id,packed_scene->get_state()->add_name(groups[i])); + } } - p_dependencies->push_back(path); + while(true) { - Error err = close_tag("ext_resource"); - if (err) - return; + String assign; + Variant value; - error=OK; - } -#endif -} + error = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,&rp); -Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) { + if (error) { + if (error!=ERR_FILE_EOF) { + _printerr(); + } else { + resource=packed_scene; + if (!ResourceCache::has(res_path)) { + packed_scene->set_path(res_path); + } + } + return error; + } + + if (assign!=String()) { + int nameidx = packed_scene->get_state()->add_name(assign); + int valueidx = packed_scene->get_state()->add_value(value); + packed_scene->get_state()->add_node_property(node_id,nameidx,valueidx); + //it's assignment + } else if (next_tag.name!=String()) { + + error=OK; + return error; + } else { + resource=packed_scene; + error=ERR_FILE_EOF; + return error; + } + } - if (next_tag.name=="ext_resource") { + return OK; - Error err; + } else if (next_tag.name=="connection") { + + if (!is_scene) { + + error_text+="found the 'connection' tag on a resource file!"; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } + + if (!next_tag.fields.has("from")) { + error=ERR_FILE_CORRUPT; + error_text="missing 'from' field fron connection tag"; + return error; + } + + if (!next_tag.fields.has("to")) { + error=ERR_FILE_CORRUPT; + error_text="missing 'to' field fron connection tag"; + return error; + } + + if (!next_tag.fields.has("signal")) { + error=ERR_FILE_CORRUPT; + error_text="missing 'signal' field fron connection tag"; + return error; + } + + if (!next_tag.fields.has("method")) { + error=ERR_FILE_CORRUPT; + error_text="missing 'method' field fron connection tag"; + return error; + } + + NodePath from = next_tag.fields["from"]; + NodePath to = next_tag.fields["to"]; + StringName method = next_tag.fields["method"]; + StringName signal = next_tag.fields["signal"]; + int flags=CONNECT_PERSIST; + Array binds; + + if (next_tag.fields.has("flags")) { + flags=next_tag.fields["flags"]; + } + + if (next_tag.fields.has("binds")) { + binds=next_tag.fields["binds"]; + } + + Vector<int> bind_ints; + for(int i=0;i<binds.size();i++) { + bind_ints.push_back( packed_scene->get_state()->add_value( binds[i] ) ); + } + + packed_scene->get_state()->add_connection( + packed_scene->get_state()->add_node_path(from.simplified()), + packed_scene->get_state()->add_node_path(to.simplified()), + packed_scene->get_state()->add_name(signal), + packed_scene->get_state()->add_name(method), + flags, + bind_ints + ); + + error = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); + + if (error) { + if (error!=ERR_FILE_EOF) { + _printerr(); + } else { + resource=packed_scene; + } + } + + return error; + } else if (next_tag.name=="editable") { + + if (!is_scene) { + + error_text+="found the 'editable' tag on a resource file!"; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } if (!next_tag.fields.has("path")) { - err=ERR_FILE_CORRUPT; - error_text="Missing 'path' in external resource tag"; + error=ERR_FILE_CORRUPT; + error_text="missing 'path' field fron connection tag"; _printerr(); - return err; + return error; } + NodePath path = next_tag.fields["path"]; + + packed_scene->get_state()->add_editable_instance(path.simplified()); + + error = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); + + if (error) { + if (error!=ERR_FILE_EOF) { + _printerr(); + } else { + resource=packed_scene; + } + } + + return error; + + } else { + + error_text+="Unknown tag in file: "+next_tag.name; + _printerr(); + error=ERR_FILE_CORRUPT; + return error; + } + + return OK; +} + +int ResourceInteractiveLoaderText::get_stage() const { + + return resource_current; +} +int ResourceInteractiveLoaderText::get_stage_count() const { + + return resources_total;//+ext_resources; +} + +ResourceInteractiveLoaderText::~ResourceInteractiveLoaderText() { + + memdelete(f); +} + +void ResourceInteractiveLoaderText::get_dependencies(FileAccess *f,List<String> *p_dependencies,bool p_add_types) { + + + open(f); + ERR_FAIL_COND(error!=OK); + + while(next_tag.name=="ext_resource") { + if (!next_tag.fields.has("type")) { - err=ERR_FILE_CORRUPT; + error=ERR_FILE_CORRUPT; error_text="Missing 'type' in external resource tag"; _printerr(); - return err; + return; } - if (!next_tag.fields.has("index")) { - err=ERR_FILE_CORRUPT; + if (!next_tag.fields.has("id")) { + error=ERR_FILE_CORRUPT; error_text="Missing 'index' in external resource tag"; _printerr(); - return err; + return; } String path=next_tag.fields["path"]; String type=next_tag.fields["type"]; - int index=next_tag.fields["index"]; if (path.find("://")==-1 && path.is_rel_path()) { @@ -329,95 +603,85 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } - if (remaps.has(path)) { - path=remaps[path]; - } - - RES res = ResourceLoader::load(path,type); - - if (res.is_null()) { - - if (ResourceLoader::get_abort_on_missing_resources()) { - error=ERR_FILE_CORRUPT; - error_text="[ext_resource] referenced nonexistent resource at: "+path; - _printerr(); - return error; - } else { - ResourceLoader::notify_dependency_error(local_path,path,type); - } - } else { - resource_cache.push_back(res); + if (p_add_types) { + path+="::"+type; } - ExtResource er; - er.path=path; - er.type=type; - ext_resources[index]=er; + p_dependencies->push_back(path); - err = VariantParser::parse_tag(&stream,lines,error_text,next_tag); + Error err = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); if (err) { error_text="Unexpected end of file"; _printerr(); error=ERR_FILE_CORRUPT; - return error; } - return OK; - } +} + +Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) { -#if 0 - open(p_f); + + open(p_f,true); ERR_FAIL_COND_V(error!=OK,error); //FileAccess - bool old_format=false; - FileAccess *fw = NULL; String base_path=local_path.get_base_dir(); + + uint64_t tag_end = f->get_pos(); + + while(true) { - bool exit; - List<String> order; - Tag *tag = parse_tag(&exit,true,&order); - bool done=false; - if (!tag) { + Error err = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); + + if (err!=OK) { if (fw) { memdelete(fw); } error=ERR_FILE_CORRUPT; - ERR_FAIL_COND_V(!exit,error); - error=ERR_FILE_EOF; - - return error; + ERR_FAIL_V(error); } - if (tag->name=="ext_resource") { + if (next_tag.name!="ext_resource") { + + //nothing was done + if (!fw) + return OK; + + break; - if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) { - old_format=true; - break; - } + + } else { if (!fw) { fw=FileAccess::open(p_path+".depren",FileAccess::WRITE); - fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape - fw->store_line("<resource_file type=\""+resource_type+"\" subresource_count=\""+itos(resources_total)+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\">"); + if (is_scene) { + fw->store_line("[gd_scene load_steps="+itos(resources_total)+" format="+itos(FORMAT_VERSION)+"]\n"); + } else { + fw->store_line("[gd_resource type=\""+res_type+"\" load_steps="+itos(resources_total)+" format="+itos(FORMAT_VERSION)+"]\n"); + } + } + if (!next_tag.fields.has("path") || !next_tag.fields.has("id") || !next_tag.fields.has("type")) { + memdelete(fw); + error=ERR_FILE_CORRUPT; + ERR_FAIL_V(error); } - String path = tag->args["path"]; - String index = tag->args["index"]; - String type = tag->args["type"]; + String path = next_tag.fields["path"]; + int index = next_tag.fields["id"]; + String type = next_tag.fields["type"]; bool relative=false; @@ -426,7 +690,6 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const relative=true; } - if (p_map.has(path)) { String np=p_map[path]; path=np; @@ -437,74 +700,15 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const path=base_path.path_to_file(path); } - tag->args["path"]=path; - tag->args["index"]=index; - tag->args["type"]=type; + fw->store_line("[ext_resource path=\""+path+"\" type=\""+type+"\" id="+itos(index)+"]"); - } else { - - done=true; - } - - String tagt="\t<"; - if (exit) - tagt+="/"; - tagt+=tag->name; - - for(List<String>::Element *E=order.front();E;E=E->next()) { - tagt+=" "+E->get()+"=\""+tag->args[E->get()]+"\""; - } - tagt+=">"; - fw->store_line(tagt); - if (done) - break; - close_tag("ext_resource"); - fw->store_line("\t</ext_resource>"); - - } - - - if (old_format) { - if (fw) - memdelete(fw); - - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - da->remove(p_path+".depren"); - memdelete(da); - //fuck it, use the old approach; - - WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: "+p_path).utf8().get_data()); - - Error err; - FileAccess *f2 = FileAccess::open(p_path,FileAccess::READ,&err); - if (err!=OK) { - ERR_FAIL_COND_V(err!=OK,ERR_FILE_CANT_OPEN); - } - - Ref<ResourceInteractiveLoaderText> ria = memnew( ResourceInteractiveLoaderText ); - ria->local_path=Globals::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; - ria->remaps=p_map; - // ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->open(f2); - - err = ria->poll(); + tag_end = f->get_pos(); - while(err==OK) { - err=ria->poll(); } - ERR_FAIL_COND_V(err!=ERR_FILE_EOF,ERR_FILE_CORRUPT); - RES res = ria->get_resource(); - ERR_FAIL_COND_V(!res.is_valid(),ERR_FILE_CORRUPT); - - return ResourceFormatSaverText::singleton->save(p_path,res); } - if (!fw) { - - return OK; //nothing to rename, do nothing - } + f->seek(tag_end); uint8_t c=f->get_8(); while(!f->eof_reached()) { @@ -524,13 +728,13 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const da->remove(p_path); da->rename(p_path+".depren",p_path); memdelete(da); -#endif + return OK; } -void ResourceInteractiveLoaderText::open(FileAccess *p_f) { +void ResourceInteractiveLoaderText::open(FileAccess *p_f,bool p_skip_first_tag) { error=OK; @@ -562,10 +766,11 @@ void ResourceInteractiveLoaderText::open(FileAccess *p_f) { } } - print_line("TAG NAME: "+tag.name); if (tag.name=="gd_scene") { is_scene=true; + packed_scene.instance(); + } else if (tag.name=="gd_resource") { if (!tag.fields.has("type")) { error_text="Missing 'type' field in 'gd_resource' tag"; @@ -592,21 +797,25 @@ void ResourceInteractiveLoaderText::open(FileAccess *p_f) { resources_total=0; } + if (!p_skip_first_tag) { - err = VariantParser::parse_tag(&stream,lines,error_text,next_tag); + err = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); - if (err) { - error_text="Unexpected end of file"; - _printerr(); - error=ERR_FILE_CORRUPT; + if (err) { + error_text="Unexpected end of file"; + _printerr(); + error=ERR_FILE_CORRUPT; + } } + rp.ext_func=_parse_ext_resources; + rp.sub_func=_parse_sub_resources; + rp.func=NULL; + rp.userdata=this; + } -void ResourceInteractiveLoaderText::_printerr() { - ERR_PRINT(String(res_path+":"+itos(lines)+" - Parse Error: "+error_text).utf8().get_data()); -} String ResourceInteractiveLoaderText::recognize(FileAccess *p_f) { @@ -682,6 +891,10 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const { + if (p_type=="") { + get_recognized_extensions(p_extensions); + return; + } if (p_type=="PackedScene") p_extensions->push_back("tscn"); @@ -707,6 +920,8 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const{ String ext=p_path.extension().to_lower(); if (ext=="tscn") return "PackedScene"; + else if (ext!="tres") + return String(); //for anyhting else must test.. @@ -770,431 +985,37 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path,const M /*****************************************************************************************************/ -void ResourceFormatSaverTextInstance::write_property(const String& p_name,const Variant& p_property,bool *r_ok) { - - if (r_ok) - *r_ok=false; - - if (p_name!=String()) { - f->store_string(p_name+" = "); - } - - switch( p_property.get_type() ) { - - case Variant::NIL: { - f->store_string("null"); - } break; - case Variant::BOOL: { - - f->store_string(p_property.operator bool() ? "true":"false" ); - } break; - case Variant::INT: { - - f->store_string( itos(p_property.operator int()) ); - } break; - case Variant::REAL: { - - f->store_string( rtoss(p_property.operator real_t()) ); - } break; - case Variant::STRING: { - - String str=p_property; - - str="\""+str.c_escape()+"\""; - f->store_string( str ); - } break; - case Variant::VECTOR2: { - - Vector2 v = p_property; - f->store_string("Vector2( "+rtoss(v.x) +", "+rtoss(v.y)+" )" ); - } break; - case Variant::RECT2: { - - Rect2 aabb = p_property; - f->store_string("Rect2( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y)+" )" ); - - } break; - case Variant::VECTOR3: { - - Vector3 v = p_property; - f->store_string("Vector3( "+rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z)+" )"); - } break; - case Variant::PLANE: { - - Plane p = p_property; - f->store_string("Plane( "+rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d)+" )" ); - - } break; - case Variant::_AABB: { - - AABB aabb = p_property; - f->store_string("AABB( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z)+" )" ); - - } break; - case Variant::QUAT: { - - Quat quat = p_property; - f->store_string("Quat( "+rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+" )"); - - } break; - case Variant::MATRIX32: { - - String s="Matrix32( "; - Matrix32 m3 = p_property; - for (int i=0;i<3;i++) { - for (int j=0;j<2;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - f->store_string(s+" )"); - - } break; - case Variant::MATRIX3: { - - String s="Matrix3( "; - Matrix3 m3 = p_property; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - f->store_string(s+" )"); - - } break; - case Variant::TRANSFORM: { - - String s="Transform( "; - Transform t = p_property; - Matrix3 &m3 = t.basis; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z); - - f->store_string(s+" )"); - } break; - - // misc types - case Variant::COLOR: { - - Color c = p_property; - f->store_string("Color( "+rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a)+" )"); - - } break; - case Variant::IMAGE: { - - - Image img=p_property; - - if (img.empty()) { - f->store_string("Image()"); - break; - } - - String imgstr="Image( "; - imgstr+=itos(img.get_width()); - imgstr+=", "+itos(img.get_height()); - imgstr+=", "+itos(img.get_mipmaps()); - imgstr+=", "; - - switch(img.get_format()) { - - case Image::FORMAT_GRAYSCALE: imgstr+="GRAYSCALE"; break; - case Image::FORMAT_INTENSITY: imgstr+="INTENSITY"; break; - case Image::FORMAT_GRAYSCALE_ALPHA: imgstr+="GRAYSCALE_ALPHA"; break; - case Image::FORMAT_RGB: imgstr+="RGB"; break; - case Image::FORMAT_RGBA: imgstr+="RGBA"; break; - case Image::FORMAT_INDEXED : imgstr+="INDEXED"; break; - case Image::FORMAT_INDEXED_ALPHA: imgstr+="INDEXED_ALPHA"; break; - case Image::FORMAT_BC1: imgstr+="BC1"; break; - case Image::FORMAT_BC2: imgstr+="BC2"; break; - case Image::FORMAT_BC3: imgstr+="BC3"; break; - case Image::FORMAT_BC4: imgstr+="BC4"; break; - case Image::FORMAT_BC5: imgstr+="BC5"; break; - case Image::FORMAT_PVRTC2: imgstr+="PVRTC2"; break; - case Image::FORMAT_PVRTC2_ALPHA: imgstr+="PVRTC2_ALPHA"; break; - case Image::FORMAT_PVRTC4: imgstr+="PVRTC4"; break; - case Image::FORMAT_PVRTC4_ALPHA: imgstr+="PVRTC4_ALPHA"; break; - case Image::FORMAT_ETC: imgstr+="ETC"; break; - case Image::FORMAT_ATC: imgstr+="ATC"; break; - case Image::FORMAT_ATC_ALPHA_EXPLICIT: imgstr+="ATC_ALPHA_EXPLICIT"; break; - case Image::FORMAT_ATC_ALPHA_INTERPOLATED: imgstr+="ATC_ALPHA_INTERPOLATED"; break; - case Image::FORMAT_CUSTOM: imgstr+="CUSTOM"; break; - default: {} - } - - - String s; - - DVector<uint8_t> data = img.get_data(); - int len = data.size(); - DVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; - for (int i=0;i<len;i++) { - - if (i>0) - s+=", "; - s+=itos(ptr[i]); - } - - imgstr+=", "; - f->store_string(imgstr); - f->store_string(s); - f->store_string(" )"); - } break; - case Variant::NODE_PATH: { - - String str=p_property; - - str="NodePath(\""+str.c_escape()+"\")"; - f->store_string(str); - - } break; - - case Variant::OBJECT: { - - RES res = p_property; - if (res.is_null()) { - f->store_string("null"); - if (r_ok) - *r_ok=true; - - break; // don't save it - } - - if (external_resources.has(res)) { - - f->store_string("Resource( "+itos(external_resources[res]+1)+" )"); - } else { - - if (internal_resources.has(res)) { - f->store_string("SubResource( "+itos(internal_resources[res])+" )"); - } else if (res->get_path().length() && res->get_path().find("::")==-1) { - - //external resource - String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path(); - f->store_string("Resource( \""+path+"\" )"); - } else { - f->store_string("null"); - ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); - ERR_BREAK(true); - //internal resource - } - } - - } break; - case Variant::INPUT_EVENT: { - - f->store_string("InputEvent()"); //will be added later - } break; - case Variant::DICTIONARY: { - - Dictionary dict = p_property; - - List<Variant> keys; - dict.get_key_list(&keys); - keys.sort(); - - f->store_string("{ "); - for(List<Variant>::Element *E=keys.front();E;E=E->next()) { - - //if (!_check_type(dict[E->get()])) - // continue; - bool ok; - write_property("",E->get(),&ok); - ERR_CONTINUE(!ok); - - f->store_string(":"); - write_property("",dict[E->get()],&ok); - if (!ok) - write_property("",Variant()); //at least make the file consistent.. - if (E->next()) - f->store_string(", "); - } +String ResourceFormatSaverTextInstance::_write_resources(void *ud,const RES& p_resource) { + ResourceFormatSaverTextInstance *rsi=(ResourceFormatSaverTextInstance*)ud; + return rsi->_write_resource(p_resource); - f->store_string(" }"); - - - } break; - case Variant::ARRAY: { - - f->store_string("[ "); - Array array = p_property; - int len=array.size(); - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - write_property("",array[i]); - - - } - f->store_string(" ]"); - - } break; - - case Variant::RAW_ARRAY: { - - f->store_string("ByteArray( "); - String s; - DVector<uint8_t> data = p_property; - int len = data.size(); - DVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - - f->store_string(itos(ptr[i])); - - } - - f->store_string(" )"); - - } break; - case Variant::INT_ARRAY: { - - f->store_string("IntArray( "); - DVector<int> data = p_property; - int len = data.size(); - DVector<int>::Read r = data.read(); - const int *ptr=r.ptr();; - - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - - f->store_string(itos(ptr[i])); - } - - - f->store_string(" )"); - - } break; - case Variant::REAL_ARRAY: { - - f->store_string("FloatArray( "); - DVector<real_t> data = p_property; - int len = data.size(); - DVector<real_t>::Read r = data.read(); - const real_t *ptr=r.ptr();; - - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - f->store_string(rtoss(ptr[i])); - } - - f->store_string(" )"); - - } break; - case Variant::STRING_ARRAY: { - - f->store_string("StringArray( "); - DVector<String> data = p_property; - int len = data.size(); - DVector<String>::Read r = data.read(); - const String *ptr=r.ptr();; - String s; - //write_string("\n"); - - - - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - String str=ptr[i]; - f->store_string(""+str.c_escape()+"\""); - } - - f->store_string(" )"); - - } break; - case Variant::VECTOR2_ARRAY: { - - f->store_string("Vector2Array( "); - DVector<Vector2> data = p_property; - int len = data.size(); - DVector<Vector2>::Read r = data.read(); - const Vector2 *ptr=r.ptr();; - - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - f->store_string(rtoss(ptr[i].x)+", "+rtoss(ptr[i].y) ); - } - - f->store_string(" )"); - - } break; - case Variant::VECTOR3_ARRAY: { - - f->store_string("Vector3Array( "); - DVector<Vector3> data = p_property; - int len = data.size(); - DVector<Vector3>::Read r = data.read(); - const Vector3 *ptr=r.ptr();; - - for (int i=0;i<len;i++) { - - if (i>0) - f->store_string(", "); - f->store_string(rtoss(ptr[i].x)+", "+rtoss(ptr[i].y)+", "+rtoss(ptr[i].z) ); - } - - f->store_string(" )"); - - } break; - case Variant::COLOR_ARRAY: { - - f->store_string("ColorArray( "); - - DVector<Color> data = p_property; - int len = data.size(); - DVector<Color>::Read r = data.read(); - const Color *ptr=r.ptr();; - - for (int i=0;i<len;i++) { +} - if (i>0) - f->store_string(", "); +String ResourceFormatSaverTextInstance::_write_resource(const RES& res) { - f->store_string(rtoss(ptr[i].r)+", "+rtoss(ptr[i].g)+", "+rtoss(ptr[i].b)+", "+rtoss(ptr[i].a) ); + if (external_resources.has(res)) { - } - f->store_string(" )"); + return "ExtResource( "+itos(external_resources[res]+1)+" )"; + } else { - } break; - default: {} + if (internal_resources.has(res)) { + return "SubResource( "+itos(internal_resources[res])+" )"; + } else if (res->get_path().length() && res->get_path().find("::")==-1) { + //external resource + String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path(); + return "Resource( \""+path+"\" )"; + } else { + ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); + ERR_FAIL_V("null"); + //internal resource + } } - if (r_ok) - *r_ok=true; - + return "null"; } - void ResourceFormatSaverTextInstance::_find_resources(const Variant& p_variant,bool p_main) { @@ -1328,11 +1149,18 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re } + Vector<RES> sorted_er; + sorted_er.resize(external_resources.size()); + for(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) { - String p = E->key()->get_path(); + sorted_er[E->get()]=E->key(); + } + + for(int i=0;i<sorted_er.size();i++) { + String p = sorted_er[i]->get_path(); - f->store_string("[ext_resource path=\""+p+"\" type=\""+E->key()->get_save_type()+"\" id="+itos(E->get()+1)+"]\n"); //bundled + f->store_string("[ext_resource path=\""+p+"\" type=\""+sorted_er[i]->get_save_type()+"\" id="+itos(i+1)+"]\n"); //bundled } if (external_resources.size()) @@ -1411,8 +1239,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re if (PE->get().type==Variant::OBJECT && value.is_zero()) continue; - write_property(name,value); - f->store_string("\n"); + String vars; + VariantWriter::write_to_string(value,vars,_write_resources,this); + f->store_string(name+" = "+vars+"\n"); } @@ -1434,6 +1263,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re Ref<PackedScene> instance = state->get_node_instance(i); Vector<StringName> groups = state->get_node_groups(i); + if (instance.is_valid()) + print_line("for path "+String(path)+" instance "+instance->get_path()); + String header="[node"; header+=" name=\""+String(name)+"\""; if (type!=StringName()) { @@ -1451,7 +1283,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re for(int j=0;j<groups.size();j++) { if (j>0) sgroups+=", "; - sgroups+="\""+groups[i].operator String().c_escape()+"\""; + sgroups+="\""+groups[j].operator String().c_escape()+"\""; } sgroups+=" ]"; header+=sgroups; @@ -1460,17 +1292,22 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re f->store_string(header); if (instance.is_valid()) { + + String vars; f->store_string(" instance="); - write_property("",instance); + VariantWriter::write_to_string(instance,vars,_write_resources,this); + f->store_string(vars); + } f->store_line("]\n"); for(int j=0;j<state->get_node_property_count(i);j++) { - write_property(state->get_node_property_name(i,j),state->get_node_property_value(i,j)); - f->store_line(String()); + String vars; + VariantWriter::write_to_string(state->get_node_property_value(i,j),vars,_write_resources,this); + f->store_string(String(state->get_node_property_name(i,j))+" = "+vars+"\n"); } if (state->get_node_property_count(i)) { @@ -1495,8 +1332,10 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re Array binds=state->get_connection_binds(i); f->store_string(connstr); if (binds.size()) { - f->store_string(" binds="); - write_property("",binds); + String vars; + VariantWriter::write_to_string(binds,vars,_write_resources,this); + f->store_string(" binds= "+vars); + } f->store_line("]\n"); @@ -1541,9 +1380,10 @@ bool ResourceFormatSaverText::recognize(const RES& p_resource) const { } void ResourceFormatSaverText::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const { - p_extensions->push_back("tres"); //text resource if (p_resource->get_type()=="PackedScene") p_extensions->push_back("tscn"); //text scene + else + p_extensions->push_back("tres"); //text resource } diff --git a/scene/resources/scene_format_text.h b/scene/resources/scene_format_text.h index 16260835f8..02436a6e2d 100644 --- a/scene/resources/scene_format_text.h +++ b/scene/resources/scene_format_text.h @@ -43,12 +43,23 @@ class ResourceInteractiveLoaderText : public ResourceInteractiveLoader { mutable int lines; Map<String,String> remaps; - void _printerr(); + //void _printerr(); + + static Error _parse_sub_resources(void* p_self, VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str) { return reinterpret_cast<ResourceInteractiveLoaderText*>(p_self)->_parse_sub_resource(p_stream,r_res,line,r_err_str); } + static Error _parse_ext_resources(void* p_self, VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str) { return reinterpret_cast<ResourceInteractiveLoaderText*>(p_self)->_parse_ext_resource(p_stream,r_res,line,r_err_str); } + + Error _parse_sub_resource(VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str); + Error _parse_ext_resource(VariantParser::Stream* p_stream,Ref<Resource>& r_res,int &line,String &r_err_str); + + VariantParser::ResourceParser rp; + + + Ref<PackedScene> packed_scene; + friend class ResourceFormatLoaderText; List<RES> resource_cache; - Error parse_property(Variant& r_v, String &r_name); Error error; RES resource; @@ -61,7 +72,7 @@ public: virtual int get_stage() const; virtual int get_stage_count() const; - void open(FileAccess *p_f); + void open(FileAccess *p_f, bool p_skip_first_tag=false); String recognize(FileAccess *p_f); void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types); Error rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map); @@ -105,7 +116,10 @@ class ResourceFormatSaverTextInstance { Map<RES,int> internal_resources; void _find_resources(const Variant& p_variant,bool p_main=false); - void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL); + + static String _write_resources(void *ud,const RES& p_resource); + String _write_resource(const RES& res); + public: diff --git a/scene/resources/scene_preloader.cpp b/scene/resources/scene_preloader.cpp index 09001c1a94..c031f3c721 100644 --- a/scene/resources/scene_preloader.cpp +++ b/scene/resources/scene_preloader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/scene_preloader.h b/scene/resources/scene_preloader.h index d60d08afd4..2317c9e0bd 100644 --- a/scene/resources/scene_preloader.h +++ b/scene/resources/scene_preloader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 88f7adcd9b..b8b14fd6fc 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/segment_shape_2d.h b/scene/resources/segment_shape_2d.h index 37c68b6c92..6f7b2f2d38 100644 --- a/scene/resources/segment_shape_2d.h +++ b/scene/resources/segment_shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index a9376faf62..ee9f23dd2a 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -448,31 +448,19 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String& p_origi void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("shader"); + ObjectTypeDB::get_extensions_for_type("Shader", p_extensions); } + bool ResourceFormatLoaderShader::handles_type(const String& p_type) const { - return p_type=="Shader"; + return ObjectTypeDB::is_type(p_type, "Shader"); } String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="shader") + if (p_path.extension().to_lower()=="shd") return "Shader"; return ""; } - - - - - - - - - - - - - diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 61a369c408..6ee8d4e793 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 7b67eaeda8..eabc84c41e 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -179,25 +179,25 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("default_get_value","shader_type","id","param_id"), &ShaderGraph::default_get_value); ObjectTypeDB::bind_method(_MD("scalar_const_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_const_node_set_value); - ObjectTypeDB::bind_method(_MD("scalar_const_node_get_value","shader_type","id"),&ShaderGraph::scalar_const_node_set_value); + ObjectTypeDB::bind_method(_MD("scalar_const_node_get_value","shader_type","id"),&ShaderGraph::scalar_const_node_get_value); ObjectTypeDB::bind_method(_MD("vec_const_node_set_value","shader_type","id","value"),&ShaderGraph::vec_const_node_set_value); - ObjectTypeDB::bind_method(_MD("vec_const_node_get_value","shader_type","id"),&ShaderGraph::vec_const_node_set_value); + ObjectTypeDB::bind_method(_MD("vec_const_node_get_value","shader_type","id"),&ShaderGraph::vec_const_node_get_value); ObjectTypeDB::bind_method(_MD("rgb_const_node_set_value","shader_type","id","value"),&ShaderGraph::rgb_const_node_set_value); - ObjectTypeDB::bind_method(_MD("rgb_const_node_get_value","shader_type","id"),&ShaderGraph::rgb_const_node_set_value); + ObjectTypeDB::bind_method(_MD("rgb_const_node_get_value","shader_type","id"),&ShaderGraph::rgb_const_node_get_value); ObjectTypeDB::bind_method(_MD("xform_const_node_set_value","shader_type","id","value"),&ShaderGraph::xform_const_node_set_value); - ObjectTypeDB::bind_method(_MD("xform_const_node_get_value","shader_type","id"),&ShaderGraph::xform_const_node_set_value); + ObjectTypeDB::bind_method(_MD("xform_const_node_get_value","shader_type","id"),&ShaderGraph::xform_const_node_get_value); // void get_node_list(ShaderType p_which,List<int> *p_node_list) const; ObjectTypeDB::bind_method(_MD("texture_node_set_filter_size","shader_type","id","filter_size"),&ShaderGraph::texture_node_set_filter_size); - ObjectTypeDB::bind_method(_MD("texture_node_get_filter_size","shader_type","id"),&ShaderGraph::texture_node_set_filter_size); + ObjectTypeDB::bind_method(_MD("texture_node_get_filter_size","shader_type","id"),&ShaderGraph::texture_node_get_filter_size); ObjectTypeDB::bind_method(_MD("texture_node_set_filter_strength","shader_type","id","filter_strength"),&ShaderGraph::texture_node_set_filter_strength); - ObjectTypeDB::bind_method(_MD("texture_node_get_filter_strength","shader_type","id"),&ShaderGraph::texture_node_set_filter_strength); + ObjectTypeDB::bind_method(_MD("texture_node_get_filter_strength","shader_type","id"),&ShaderGraph::texture_node_get_filter_strength); ObjectTypeDB::bind_method(_MD("scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::scalar_op_node_set_op); ObjectTypeDB::bind_method(_MD("scalar_op_node_get_op","shader_type","id"),&ShaderGraph::scalar_op_node_get_op); @@ -260,7 +260,7 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("clear","shader_type"),&ShaderGraph::clear); ObjectTypeDB::bind_method(_MD("node_set_state","shader_type","id","state"),&ShaderGraph::node_set_state); - ObjectTypeDB::bind_method(_MD("node_get_state:var","shader_type","id"),&ShaderGraph::node_get_state); + ObjectTypeDB::bind_method(_MD("node_get_state:Variant","shader_type","id"),&ShaderGraph::node_get_state); ObjectTypeDB::bind_method(_MD("_set_data"),&ShaderGraph::_set_data); ObjectTypeDB::bind_method(_MD("_get_data"),&ShaderGraph::_get_data); @@ -1533,7 +1533,7 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= { {NODE_CURVE_MAP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve) {NODE_SCALAR_INPUT,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar uniform (assignable in material) {NODE_VEC_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 uniform (assignable in material) - {NODE_RGB_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // color uniform (assignable in material) + {NODE_RGB_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // color uniform (assignable in material) {NODE_XFORM_INPUT,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 uniform (assignable in material) {NODE_TEXTURE_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // texture input (assignable in material) {NODE_CUBEMAP_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material) @@ -2576,8 +2576,9 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str String name = p_node->param1; Color dv= p_node->param2; - code +="uniform color "+name+"=vec4("+rtos(dv.r)+","+rtos(dv.g)+","+rtos(dv.g)+","+rtos(dv.a)+");\n"; + code +="uniform color "+name+"=vec4("+rtos(dv.r)+","+rtos(dv.g)+","+rtos(dv.b)+","+rtos(dv.a)+");\n"; code += OUTNAME(p_node->id,0)+"="+name+".rgb;\n"; + code += OUTNAME(p_node->id,1)+"="+name+".a;\n"; }break; case NODE_XFORM_INPUT: { diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index f867ae0388..1e6fc3507c 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp index 143ef82d51..a71e414f61 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shape.h b/scene/resources/shape.h index 1992ce51c3..bfd423a300 100644 --- a/scene/resources/shape.h +++ b/scene/resources/shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 31b28ee892..6a9773bf14 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -108,8 +108,8 @@ void Shape2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_custom_solver_bias"),&Shape2D::get_custom_solver_bias); ObjectTypeDB::bind_method(_MD("collide","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide); ObjectTypeDB::bind_method(_MD("collide_with_motion","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion); - ObjectTypeDB::bind_method(_MD("collide_and_get_contacts:var","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide_and_get_contacts); - ObjectTypeDB::bind_method(_MD("collide_with_motion_and_get_contacts:var","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion_and_get_contacts); + ObjectTypeDB::bind_method(_MD("collide_and_get_contacts:Variant","local_xform","with_shape:Shape2D","shape_xform"),&Shape2D::collide_and_get_contacts); + ObjectTypeDB::bind_method(_MD("collide_with_motion_and_get_contacts:Variant","local_xform","local_motion","with_shape:Shape2D","shape_xform","shape_motion"),&Shape2D::collide_with_motion_and_get_contacts); ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_solver_bias",PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_custom_solver_bias"),_SCS("get_custom_solver_bias")); } diff --git a/scene/resources/shape_2d.h b/scene/resources/shape_2d.h index 1737301d9d..4059af62c6 100644 --- a/scene/resources/shape_2d.h +++ b/scene/resources/shape_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shape_line_2d.cpp b/scene/resources/shape_line_2d.cpp index 97e9985754..4133d2218f 100644 --- a/scene/resources/shape_line_2d.cpp +++ b/scene/resources/shape_line_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/shape_line_2d.h b/scene/resources/shape_line_2d.h index f32ad7fb7c..f6f75e7a95 100644 --- a/scene/resources/shape_line_2d.h +++ b/scene/resources/shape_line_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/space_2d.cpp b/scene/resources/space_2d.cpp index 6dbf7c4a73..d328ee3de4 100644 --- a/scene/resources/space_2d.cpp +++ b/scene/resources/space_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/space_2d.h b/scene/resources/space_2d.h index eb3e13ee62..270f8de3ea 100644 --- a/scene/resources/space_2d.h +++ b/scene/resources/space_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/sphere_shape.cpp b/scene/resources/sphere_shape.cpp index a7e28eb727..4764937371 100644 --- a/scene/resources/sphere_shape.cpp +++ b/scene/resources/sphere_shape.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/sphere_shape.h b/scene/resources/sphere_shape.h index 2543d94439..50682f38bb 100644 --- a/scene/resources/sphere_shape.h +++ b/scene/resources/sphere_shape.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 527fae5946..71a775ee24 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -83,7 +83,7 @@ void StyleBox::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_center_size"),&StyleBox::get_center_size); ObjectTypeDB::bind_method(_MD("get_offset"),&StyleBox::get_offset); - ObjectTypeDB::bind_method(_MD("draw"),&StyleBox::draw); + ObjectTypeDB::bind_method(_MD("draw","canvas_item","rect"),&StyleBox::draw); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "content_margin/left", PROPERTY_HINT_RANGE,"-1,2048,1" ), _SCS("set_default_margin"),_SCS("get_default_margin"), MARGIN_LEFT ); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "content_margin/right", PROPERTY_HINT_RANGE,"-1,2048,1" ), _SCS("set_default_margin"),_SCS("get_default_margin"), MARGIN_RIGHT ); @@ -182,10 +182,10 @@ void StyleBoxTexture::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&StyleBoxTexture::get_texture); ObjectTypeDB::bind_method(_MD("set_margin_size","margin","size"),&StyleBoxTexture::set_margin_size); - ObjectTypeDB::bind_method(_MD("get_margin_size"),&StyleBoxTexture::get_margin_size); + ObjectTypeDB::bind_method(_MD("get_margin_size","margin"),&StyleBoxTexture::get_margin_size); ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxTexture::set_expand_margin_size); - ObjectTypeDB::bind_method(_MD("get_expand_margin_size"),&StyleBoxTexture::get_expand_margin_size); + ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxTexture::get_expand_margin_size); ObjectTypeDB::bind_method(_MD("set_draw_center","enable"),&StyleBoxTexture::set_draw_center); ObjectTypeDB::bind_method(_MD("get_draw_center"),&StyleBoxTexture::get_draw_center); @@ -392,7 +392,7 @@ void StyleBoxImageMask::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_expand","expand"),&StyleBoxImageMask::set_expand); ObjectTypeDB::bind_method(_MD("get_expand"),&StyleBoxImageMask::get_expand); ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxImageMask::set_expand_margin_size); - ObjectTypeDB::bind_method(_MD("get_expand_margin_size"),&StyleBoxImageMask::get_expand_margin_size); + ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxImageMask::get_expand_margin_size); ADD_PROPERTY( PropertyInfo(Variant::IMAGE, "image"), _SCS("set_image"), _SCS("get_image")); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "expand"), _SCS("set_expand"), _SCS("get_expand")); diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 337bb54026..d0466ed5f1 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 418df97f51..bf5070fd7d 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index ed91b4df61..1d329f23c0 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 994473f11e..28754480f1 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -70,9 +70,9 @@ void Texture::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_alpha"),&Texture::has_alpha); ObjectTypeDB::bind_method(_MD("set_flags","flags"),&Texture::set_flags); ObjectTypeDB::bind_method(_MD("get_flags"),&Texture::get_flags); - ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","modulate"),&Texture::draw,DEFVAL(Color(1,1,1)),DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("draw_rect","canvas_item","rect","tile","modulate"),&Texture::draw_rect,DEFVAL(Color(1,1,1)),DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("draw_rect_region","canvas_item","rect","src_rect","modulate"),&Texture::draw_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","modulate","transpose"),&Texture::draw,DEFVAL(Color(1,1,1)),DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("draw_rect","canvas_item","rect","tile","modulate","transpose"),&Texture::draw_rect,DEFVAL(Color(1,1,1)),DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("draw_rect_region","canvas_item","rect","src_rect","modulate","transpose"),&Texture::draw_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false)); BIND_CONSTANT( FLAG_MIPMAPS ); BIND_CONSTANT( FLAG_REPEAT ); @@ -329,6 +329,16 @@ void ImageTexture::normal_to_xy() { create_from_image(img,flags); } +void ImageTexture::shrink_x2_and_keep_size() { + + Size2 sizeov=get_size(); + Image img = get_data(); + img.resize(img.get_width()/2,img.get_height()/2,Image::INTERPOLATE_BILINEAR); + create_from_image(img,flags); + set_size_override(sizeov); + +} + bool ImageTexture::has_alpha() const { return ( format==Image::FORMAT_GRAYSCALE_ALPHA || format==Image::FORMAT_INDEXED_ALPHA || format==Image::FORMAT_RGBA ); @@ -424,10 +434,13 @@ void ImageTexture::_bind_methods() { 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("shrink_x2_and_keep_size"),&ImageTexture::shrink_x2_and_keep_size); + 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::set_method_flags(get_type_static(),_SCS("shrink_x2_and_keep_size"),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 1a4f211af1..2627b9480a 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -148,6 +148,7 @@ public: void fix_alpha_edges(); void premultiply_alpha(); void normal_to_xy(); + void shrink_x2_and_keep_size(); void set_size_override(const Size2& p_size); diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 651e234b49..685b2e07e1 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -266,7 +266,52 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { p_list->push_back(*key); } + +} + +void Theme::set_shader(const StringName &p_name,const StringName &p_type,const Ref<Shader>& p_shader) { + bool new_value=!shader_map.has(p_type) || !shader_map[p_type].has(p_name); + + shader_map[p_type][p_name]=p_shader; + if (new_value) { + _change_notify(); + emit_changed();; + } +} + +Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_type) const { + if (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()) { + return shader_map[p_type][p_name]; + } else { + return NULL; + } +} + +bool Theme::has_shader(const StringName &p_name, const StringName &p_type) const { + return (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()); +} + +void Theme::clear_shader(const StringName &p_name, const StringName &p_type) { + ERR_FAIL_COND(!shader_map.has(p_type)); + ERR_FAIL_COND(!shader_map[p_type].has(p_name)); + + shader_map[p_type].erase(p_name); + _change_notify(); + emit_changed();; +} + +void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const { + if (!shader_map.has(p_type)) + return; + + const StringName *key=NULL; + + while((key=shader_map[p_type].next(key))) { + + p_list->push_back(*key); + } + } @@ -552,36 +597,36 @@ void Theme::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_icon:Texture","name","type"),&Theme::get_icon); ObjectTypeDB::bind_method(_MD("has_icon","name","type"),&Theme::has_icon); ObjectTypeDB::bind_method(_MD("clear_icon","name","type"),&Theme::clear_icon); - ObjectTypeDB::bind_method(_MD("get_icon_list"),&Theme::_get_icon_list); + ObjectTypeDB::bind_method(_MD("get_icon_list","type"),&Theme::_get_icon_list); ObjectTypeDB::bind_method(_MD("set_stylebox","name","type","texture:StyleBox"),&Theme::set_stylebox); ObjectTypeDB::bind_method(_MD("get_stylebox:StyleBox","name","type"),&Theme::get_stylebox); ObjectTypeDB::bind_method(_MD("has_stylebox","name","type"),&Theme::has_stylebox); ObjectTypeDB::bind_method(_MD("clear_stylebox","name","type"),&Theme::clear_stylebox); - ObjectTypeDB::bind_method(_MD("get_stylebox_list"),&Theme::_get_stylebox_list); + ObjectTypeDB::bind_method(_MD("get_stylebox_list","type"),&Theme::_get_stylebox_list); ObjectTypeDB::bind_method(_MD("set_font","name","type","font:Font"),&Theme::set_font); ObjectTypeDB::bind_method(_MD("get_font:Font","name","type"),&Theme::get_font); ObjectTypeDB::bind_method(_MD("has_font","name","type"),&Theme::has_font); ObjectTypeDB::bind_method(_MD("clear_font","name","type"),&Theme::clear_font); - ObjectTypeDB::bind_method(_MD("get_font_list"),&Theme::_get_font_list); + ObjectTypeDB::bind_method(_MD("get_font_list","type"),&Theme::_get_font_list); ObjectTypeDB::bind_method(_MD("set_color","name","type","color"),&Theme::set_color); ObjectTypeDB::bind_method(_MD("get_color","name","type"),&Theme::get_color); ObjectTypeDB::bind_method(_MD("has_color","name","type"),&Theme::has_color); ObjectTypeDB::bind_method(_MD("clear_color","name","type"),&Theme::clear_color); - ObjectTypeDB::bind_method(_MD("get_color_list"),&Theme::_get_color_list); + ObjectTypeDB::bind_method(_MD("get_color_list","type"),&Theme::_get_color_list); ObjectTypeDB::bind_method(_MD("set_constant","name","type","constant"),&Theme::set_constant); ObjectTypeDB::bind_method(_MD("get_constant","name","type"),&Theme::get_constant); ObjectTypeDB::bind_method(_MD("has_constant","name","type"),&Theme::has_constant); ObjectTypeDB::bind_method(_MD("clear_constant","name","type"),&Theme::clear_constant); - ObjectTypeDB::bind_method(_MD("get_constant_list"),&Theme::_get_constant_list); + ObjectTypeDB::bind_method(_MD("get_constant_list","type"),&Theme::_get_constant_list); ObjectTypeDB::bind_method(_MD("set_default_font","font"),&Theme::set_default_theme_font); ObjectTypeDB::bind_method(_MD("get_default_font"),&Theme::get_default_theme_font); - ObjectTypeDB::bind_method(_MD("get_type_list"),&Theme::_get_type_list); + ObjectTypeDB::bind_method(_MD("get_type_list","type"),&Theme::_get_type_list); ObjectTypeDB::bind_method("copy_default_theme",&Theme::copy_default_theme); diff --git a/scene/resources/theme.h b/scene/resources/theme.h index cfa0762595..180f55381d 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ @@ -33,6 +33,7 @@ #include "scene/resources/font.h" #include "scene/resources/style_box.h" #include "scene/resources/texture.h" +#include "scene/resources/shader.h" #include "io/resource_loader.h" /** @@ -48,6 +49,7 @@ class Theme : public Resource { HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map; HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map; HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map; + HashMap<StringName,HashMap<StringName,Ref<Shader>,StringNameHasher >, StringNameHasher > shader_map; HashMap<StringName,HashMap<StringName,Color,StringNameHasher >,StringNameHasher > color_map; HashMap<StringName,HashMap<StringName,int,StringNameHasher>,StringNameHasher > constant_map; protected: @@ -86,7 +88,13 @@ public: bool has_icon(const StringName& p_name,const StringName& p_type) const; void clear_icon(const StringName& p_name,const StringName& p_type); void get_icon_list(StringName p_type, List<StringName> *p_list) const; - + + void set_shader(const StringName& p_name,const StringName& p_type,const Ref<Shader>& p_shader); + Ref<Shader> get_shader(const StringName& p_name,const StringName& p_type) const; + bool has_shader(const StringName& p_name,const StringName& p_type) const; + void clear_shader(const StringName& p_name,const StringName& p_type); + void get_shader_list(const StringName& p_name, List<StringName> *p_list) const; + void set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style); Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type) const; bool has_stylebox(const StringName& p_name,const StringName& p_type) const; diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 28e179b34c..6f71287750 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 96048bf06b..fb0e832c1e 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/video_stream.cpp b/scene/resources/video_stream.cpp index c957fd4c67..8e16f2e024 100644 --- a/scene/resources/video_stream.cpp +++ b/scene/resources/video_stream.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h index a23ef0c64f..b05a7cf773 100644 --- a/scene/resources/video_stream.h +++ b/scene/resources/video_stream.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/volume.cpp b/scene/resources/volume.cpp index a668a39c4f..8eb96cb4ad 100644 --- a/scene/resources/volume.cpp +++ b/scene/resources/volume.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/volume.h b/scene/resources/volume.h index f929792b74..be3cbddbbd 100644 --- a/scene/resources/volume.h +++ b/scene/resources/volume.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp index fb3469102c..0a88abf252 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/world.h b/scene/resources/world.h index 165122124d..5a74f27235 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 3b1f1d2346..8cacc0fce7 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index a3a79dee09..a939d935c4 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 9509878dc9..57bde00de4 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 48f17ed38b..b2c0e9abf0 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 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 */ |