diff options
Diffstat (limited to 'scene')
37 files changed, 574 insertions, 102 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 52ae5d2954..b7b99f935a 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -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); @@ -489,14 +510,17 @@ void Camera2D::_bind_methods() { 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..dcf98d4295 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -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 abd532c156..275e4d0304 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -709,7 +709,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."); @@ -718,7 +718,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) { @@ -1156,6 +1156,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(); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 667fedc956..4c0386b953 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -211,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); diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 1479cb7881..616d3da7c9 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -113,6 +113,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; diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 85751fc735..56f68ae634 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -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/tile_map.cpp b/scene/2d/tile_map.cpp index 167b637bdc..1d48a9c8a0 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -32,6 +32,8 @@ #include "method_bind_ext.inc" #include "os/os.h" + + int TileMap::_get_quadrant_size() const { if (y_sort_mode) @@ -299,6 +301,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 +322,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) { @@ -331,11 +335,24 @@ void TileMap::_update_dirty_quadrants() { vs->canvas_item_set_transform( canvas_item, xform ); 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; + } } @@ -407,9 +424,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 +433,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 +465,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 +1089,24 @@ 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::_bind_methods() { @@ -1126,6 +1158,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 +1195,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 +1233,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..4676d1ef7a 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -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,9 @@ 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; + void clear(); TileMap(); diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 8cdf4dd039..2ff51d22c4 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -105,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/control.cpp b/scene/gui/control.cpp index bd6b8078ff..ec4886a6ac 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -580,8 +580,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); @@ -1927,6 +1927,7 @@ void Control::set_size(const Size2& p_size) { data.margin[3] = _s2a( y+h, data.anchor[3], ph ); _size_changed(); + } @@ -2412,9 +2413,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 { @@ -2728,6 +2729,39 @@ 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; +} + + void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("_window_input_event"),&Control::_window_input_event); @@ -2756,15 +2790,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)); @@ -2846,6 +2886,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 ); @@ -2928,6 +2970,8 @@ Control::Control() { data.v_size_flags=SIZE_FILL; data.expand=1; data.pending_min_size_update=false; + data.rotation=0; + 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..09a4b48e6b 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -107,7 +107,10 @@ private: float margin[4]; AnchorType anchor[4]; - FocusMode focus_mode; + FocusMode focus_mode; + + float rotation; + Vector2 scale; bool pending_resize; @@ -211,6 +214,8 @@ private: void _size_changed(); String _get_tooltip() const; + void _set_rotation_deg(float p_rot); + float _get_rotation_deg() const; protected: bool window_has_modal_stack() const; @@ -299,6 +304,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); @@ -382,7 +394,7 @@ public: void warp_mouse(const Point2& p_to_pos); - virtual bool is_text_field() const; + virtual bool is_text_field() const; Control(); ~Control(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index ff94a37be0..3cc5acc1a6 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -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); + } } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 20f28ecf10..9dc03272b2 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -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; + } @@ -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..30223469a3 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -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/slider.cpp b/scene/gui/slider.cpp index b6292c544b..78b5dabeb4 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -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/spin_box.cpp b/scene/gui/spin_box.cpp index a48136f541..051a8dd018 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -68,6 +68,25 @@ 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)) { + + int pos_y = Input::get_singleton()->get_mouse_pos().y-get_global_pos().y; + bool up = 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 +104,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 +135,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 +192,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 +253,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 +275,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..1b3bc6d817 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -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/tabs.cpp b/scene/gui/tabs.cpp index 47a55e0716..5f4215a1d5 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -74,6 +74,7 @@ Size2 Tabs::get_minimum_size() const { } } + ms.width=0; //should make this optional return ms; } @@ -85,6 +86,23 @@ 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++) { @@ -163,9 +181,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(); @@ -225,7 +268,46 @@ void Tabs::_notification(int p_what) { 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++) { + + Ref<Texture> tex = tabs[i].icon; + if (tex.is_valid()) { + if (tabs[i].text!="") + mw+=get_constant("hseparation"); + + } + mw+=font->get_string_size(tabs[i].text).width; + if (current==i) + mw+=tab_fg->get_minimum_size().width; + else + mw+=tab_bg->get_minimum_size().width; + + if (tabs[i].right_button.is_valid()) { + Ref<Texture> rb=tabs[i].right_button; + Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + + mw+=bms.width; + } + + if (tabs[i].close_button.is_valid()) { + Ref<Texture> cb=tabs[i].close_button; + Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + mw+=bms.width; + } + } + + } + + if (tab_align==ALIGN_CENTER) { w=(get_size().width-mw)/2; @@ -238,8 +320,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 +340,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; @@ -319,6 +414,16 @@ void Tabs::_notification(int p_what) { } + 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; @@ -484,6 +589,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; } @@ -673,8 +797,11 @@ 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 + offset=0; + max_drawn_tab=0; } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 1a8352bc93..48fbed1f76 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -65,6 +65,12 @@ private: 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; diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 5b2caecb5b..7e6bf2cbdf 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -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..49687986c4 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -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/tree.cpp b/scene/gui/tree.cpp index 16a12fe407..1b204cff65 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -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 = (Input::get_singleton()->get_mouse_pos()-get_global_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 = {}; // 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) { @@ -1564,9 +1597,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) ); @@ -1672,6 +1721,7 @@ void Tree::text_editor_enter(String p_text) { text_editor->hide(); + value_editor->hide(); if (!popup_edited_item) return; @@ -2024,6 +2074,8 @@ void Tree::_input_event(InputEvent p_event) { update_cache(); const InputEventMouseMotion& b=p_event.mouse_motion; + range_click_timer->stop(); + Ref<StyleBox> bg = cache.bg; Point2 pos = Point2(b.x,b.y) - bg->get_offset(); @@ -2031,7 +2083,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) { @@ -2108,6 +2159,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 +2168,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); - - text_editor->clear(); - text_editor->set_text( pressing_for_editor_text ); - text_editor->select_all(); + } else + edit_selected(); - text_editor->show_modal(); - text_editor->grab_focus(); - - } pressing_for_editor=false; } @@ -2228,10 +2272,13 @@ void Tree::_input_event(InputEvent p_event) { } break; case BUTTON_WHEEL_UP: { + + range_click_timer->stop(); v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 ); } break; case BUTTON_WHEEL_DOWN: { + range_click_timer->stop(); v_scroll->set_val( v_scroll->get_val()+v_scroll->get_page()/8 ); } break; } @@ -3135,6 +3182,7 @@ 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); @@ -3229,6 +3277,10 @@ 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"); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 8fb9b802a1..55ccc16d01 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -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); diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index d99da5e906..22b19f50b2 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -338,6 +338,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 +391,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..b14d3936b9 100644 --- a/scene/gui/video_player.h +++ b/scene/gui/video_player.h @@ -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/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/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index a1137ba614..86cf818ac3 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -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/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 25407a5b84..33e1eb338e 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -709,6 +709,10 @@ 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_font("font","Tabs", default_font ); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 2d93113b40..aad5e7cfdd 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -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); @@ -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..27e3045eaa 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -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/material.cpp b/scene/resources/material.cpp index 55bb4e9073..51d8be3294 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -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/packed_scene.cpp b/scene/resources/packed_scene.cpp index 863f2be699..443d1630a7 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -509,6 +509,19 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S } } + if (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; + } + } + if (exists && bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) { //exists and did not change @@ -1524,6 +1537,7 @@ void SceneState::add_editable_instance(const NodePath& p_path){ SceneState::SceneState() { base_scene_idx=-1; + last_modified_time=0; } @@ -1583,6 +1597,15 @@ Node *PackedScene::instance(bool p_gen_edit_state) const { return s; } +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; @@ -1594,6 +1617,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); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index f3ec0afb6d..67d0f4ba01 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -99,6 +99,8 @@ class SceneState : public Reference { String path; + uint64_t last_modified_time; + _FORCE_INLINE_ Ref<SceneState> _get_base_scene_state() const; static bool disable_placeholders; @@ -162,6 +164,9 @@ public: 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(); }; @@ -189,8 +194,13 @@ public: bool can_instance() const; Node *instance(bool p_gen_edit_state=false) const; + void recreate_state(); + 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/shader.cpp b/scene/resources/shader.cpp index a9376faf62..f0a2721016 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -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_graph.cpp b/scene/resources/shader_graph.cpp index 7b67eaeda8..f8a14e58a0 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -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); diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 31b28ee892..56fd8e212e 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -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")); } |