diff options
Diffstat (limited to 'scene')
31 files changed, 418 insertions, 205 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 8c8ac835e8..f699c8f0e8 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -695,16 +695,16 @@ InputEvent CanvasItem::make_input_local(const InputEvent &p_event) const { return p_event.xform_by((get_canvas_transform() * get_global_transform()).affine_inverse()); } -Vector2 CanvasItem::get_global_mouse_pos() const { +Vector2 CanvasItem::get_global_mouse_position() const { ERR_FAIL_COND_V(!get_viewport(), Vector2()); - return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_pos()); + return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position()); } Vector2 CanvasItem::get_local_mouse_pos() const { ERR_FAIL_COND_V(!get_viewport(), Vector2()); - return get_global_transform().affine_inverse().xform(get_global_mouse_pos()); + return get_global_transform().affine_inverse().xform(get_global_mouse_position()); } void CanvasItem::_bind_methods() { @@ -771,7 +771,7 @@ void CanvasItem::_bind_methods() { ClassDB::bind_method(D_METHOD("get_viewport_rect"), &CanvasItem::get_viewport_rect); ClassDB::bind_method(D_METHOD("get_canvas_transform"), &CanvasItem::get_canvas_transform); ClassDB::bind_method(D_METHOD("get_local_mouse_pos"), &CanvasItem::get_local_mouse_pos); - ClassDB::bind_method(D_METHOD("get_global_mouse_pos"), &CanvasItem::get_global_mouse_pos); + ClassDB::bind_method(D_METHOD("get_global_mouse_position"), &CanvasItem::get_global_mouse_position); ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasItem::get_canvas); ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d); //ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index ce72f7e0c9..72fe5b93da 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -212,7 +212,7 @@ public: InputEvent make_input_local(const InputEvent &pevent) const; Vector2 make_canvas_pos_local(const Vector2 &screen_point) const; - Vector2 get_global_mouse_pos() const; + Vector2 get_global_mouse_position() const; Vector2 get_local_mouse_pos() const; void set_notify_local_transform(bool p_enable); diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 2d047f0096..b91d9b835c 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -571,13 +571,13 @@ void Particles2D::_notification(int p_what) { src_rect.pos.x = size.x * (frame % h_frames); src_rect.pos.y = size.y * (frame / h_frames); } - + Rect2 dst_rect(Point2(), size); if (flip_h) - src_rect.size.x = -src_rect.size.x; + dst_rect.size.x = -dst_rect.size.x; if (flip_v) - src_rect.size.y = -src_rect.size.y; + dst_rect.size.y = -dst_rect.size.y; - texture->draw_rect_region(ci, Rect2(Point2(), size), src_rect, color); + texture->draw_rect_region(ci, dst_rect, src_rect, color); //VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color); } else { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(), size), color); @@ -1046,7 +1046,7 @@ void Particles2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "config/amount", PROPERTY_HINT_EXP_RANGE, "1,1024"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "config/lifetime", PROPERTY_HINT_EXP_RANGE, "0.1,3600,0.1"), "set_lifetime", "get_lifetime"); ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "config/time_scale", PROPERTY_HINT_EXP_RANGE, "0.01,128,0.01"), "set_time_scale", "get_time_scale"); - ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/preprocess", PROPERTY_HINT_EXP_RANGE, "0.1,3600,0.1"), "set_pre_process_time", "get_pre_process_time"); + ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/preprocess", PROPERTY_HINT_EXP_RANGE, "0,3600,0.1"), "set_pre_process_time", "get_pre_process_time"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/emit_timeout", PROPERTY_HINT_RANGE, "0,3600,0.1"), "set_emit_timeout", "get_emit_timeout"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "config/emitting"), "set_emitting", "is_emitting"); ADD_PROPERTY(PropertyInfo(Variant::INT, "config/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_process_mode", "get_process_mode"); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 06d1e128c6..080276eb25 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -877,6 +877,26 @@ void TileMap::set_collision_mask(uint32_t p_mask) { } } +void TileMap::set_collision_layer_bit(int p_bit, bool p_value) { + + uint32_t layer = get_collision_layer(); + if (p_value) + layer |= 1 << p_bit; + else + layer &= ~(1 << p_bit); + set_collision_layer(layer); +} + +void TileMap::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask |= 1 << p_bit; + else + mask &= ~(1 << p_bit); + set_collision_mask(mask); +} + bool TileMap::get_collision_use_kinematic() const { return use_kinematic; @@ -928,6 +948,16 @@ uint32_t TileMap::get_collision_mask() const { return collision_mask; } +bool TileMap::get_collision_layer_bit(int p_bit) const { + + return get_collision_layer() & (1 << p_bit); +} + +bool TileMap::get_collision_mask_bit(int p_bit) const { + + return get_collision_mask() & (1 << p_bit); +} + void TileMap::set_mode(Mode p_mode) { _clear_quadrants(); @@ -1197,12 +1227,18 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collision_use_kinematic", "use_kinematic"), &TileMap::set_collision_use_kinematic); ClassDB::bind_method(D_METHOD("get_collision_use_kinematic"), &TileMap::get_collision_use_kinematic); - ClassDB::bind_method(D_METHOD("set_collision_layer", "mask"), &TileMap::set_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &TileMap::set_collision_layer); ClassDB::bind_method(D_METHOD("get_collision_layer"), &TileMap::get_collision_layer); ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &TileMap::set_collision_mask); ClassDB::bind_method(D_METHOD("get_collision_mask"), &TileMap::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &TileMap::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &TileMap::get_collision_layer_bit); + + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &TileMap::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &TileMap::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_friction", "value"), &TileMap::set_collision_friction); ClassDB::bind_method(D_METHOD("get_collision_friction"), &TileMap::get_collision_friction); diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 8979476aa5..3468854a61 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -233,6 +233,12 @@ public: void set_collision_mask(uint32_t p_mask); uint32_t get_collision_mask() const; + void set_collision_layer_bit(int p_bit, bool p_value); + bool get_collision_layer_bit(int p_bit) const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + void set_collision_use_kinematic(bool p_use_kinematic); bool get_collision_use_kinematic() const; diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index b7ee26de57..038ca33a41 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -71,15 +71,12 @@ void Particles::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; VS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); } -void Particles::set_custom_aabb(const Rect3 &p_aabb) { +void Particles::set_visibility_aabb(const Rect3 &p_aabb) { - custom_aabb = p_aabb; - VS::get_singleton()->particles_set_custom_aabb(particles, custom_aabb); -} -void Particles::set_gravity(const Vector3 &p_gravity) { - - gravity = p_gravity; - VS::get_singleton()->particles_set_gravity(particles, gravity); + visibility_aabb = p_aabb; + VS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb); + update_gizmo(); + _change_notify("visibility_aabb"); } void Particles::set_use_local_coordinates(bool p_enable) { @@ -93,6 +90,14 @@ void Particles::set_process_material(const Ref<Material> &p_material) { if (process_material.is_valid()) material_rid = process_material->get_rid(); VS::get_singleton()->particles_set_process_material(particles, material_rid); + + update_configuration_warning(); +} + +void Particles::set_speed_scale(float p_scale) { + + speed_scale = p_scale; + VS::get_singleton()->particles_set_speed_scale(particles, p_scale); } bool Particles::is_emitting() const { @@ -119,13 +124,9 @@ float Particles::get_randomness_ratio() const { return randomness_ratio; } -Rect3 Particles::get_custom_aabb() const { - - return custom_aabb; -} -Vector3 Particles::get_gravity() const { +Rect3 Particles::get_visibility_aabb() const { - return gravity; + return visibility_aabb; } bool Particles::get_use_local_coordinates() const { @@ -136,6 +137,11 @@ Ref<Material> Particles::get_process_material() const { return process_material; } +float Particles::get_speed_scale() const { + + return speed_scale; +} + void Particles::set_draw_order(DrawOrder p_order) { draw_order = p_order; @@ -170,6 +176,8 @@ void Particles::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { mesh_rid = p_mesh->get_rid(); VS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid); + + update_configuration_warning(); } Ref<Mesh> Particles::get_draw_pass_mesh(int p_pass) const { @@ -197,6 +205,37 @@ bool Particles::get_fractional_delta() const { return fractional_delta; } +String Particles::get_configuration_warning() const { + + String warnings; + + bool meshes_found = false; + + for (int i = 0; i < draw_passes.size(); i++) { + if (draw_passes[i].is_valid()) { + meshes_found = true; + break; + } + } + + if (!meshes_found) { + warnings += "- " + TTR("Nothing is visible because meshes have not been assigned to draw passes."); + } + + if (process_material.is_null()) { + if (warnings != String()) + warnings += "\n"; + warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted."); + } + + return warnings; +} + +Rect3 Particles::capture_aabb() const { + + return VS::get_singleton()->particles_get_current_aabb(particles); +} + void Particles::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("draw_pass_")) { @@ -216,12 +255,12 @@ void Particles::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &Particles::set_pre_process_time); ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &Particles::set_explosiveness_ratio); ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &Particles::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &Particles::set_custom_aabb); - ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &Particles::set_gravity); + ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &Particles::set_visibility_aabb); ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &Particles::set_use_local_coordinates); ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &Particles::set_fixed_fps); ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &Particles::set_fractional_delta); ClassDB::bind_method(D_METHOD("set_process_material", "material:Material"), &Particles::set_process_material); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &Particles::set_speed_scale); ClassDB::bind_method(D_METHOD("is_emitting"), &Particles::is_emitting); ClassDB::bind_method(D_METHOD("get_amount"), &Particles::get_amount); @@ -229,12 +268,12 @@ void Particles::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles::get_pre_process_time); ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &Particles::get_explosiveness_ratio); ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &Particles::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_custom_aabb"), &Particles::get_custom_aabb); - ClassDB::bind_method(D_METHOD("get_gravity"), &Particles::get_gravity); + ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &Particles::get_visibility_aabb); ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &Particles::get_use_local_coordinates); ClassDB::bind_method(D_METHOD("get_fixed_fps"), &Particles::get_fixed_fps); ClassDB::bind_method(D_METHOD("get_fractional_delta"), &Particles::get_fractional_delta); ClassDB::bind_method(D_METHOD("get_process_material:Material"), &Particles::get_process_material); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &Particles::get_speed_scale); ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &Particles::set_draw_order); @@ -246,20 +285,23 @@ void Particles::_bind_methods() { ClassDB::bind_method(D_METHOD("get_draw_passes"), &Particles::get_draw_passes); ClassDB::bind_method(D_METHOD("get_draw_pass_mesh:Mesh", "pass"), &Particles::get_draw_pass_mesh); + ClassDB::bind_method(D_METHOD("capture_aabb"), &Particles::capture_aabb); + ADD_GROUP("Parameters", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,100000,1"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio"); - ADD_PROPERTY(PropertyInfo(Variant::RECT3, "custom_aabb"), "set_custom_aabb", "get_custom_aabb"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity"), "set_gravity", "get_gravity"); + ADD_PROPERTY(PropertyInfo(Variant::RECT3, "visibility_aabb"), "set_visibility_aabb", "get_visibility_aabb"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates"); ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ParticlesMaterial,ShaderMaterial"), "set_process_material", "get_process_material"); ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,View Depth"), "set_draw_order", "get_draw_order"); + ADD_GROUP("Process Material", ""); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ParticlesMaterial,ShaderMaterial"), "set_process_material", "get_process_material"); ADD_GROUP("Draw Passes", "draw_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_passes", PROPERTY_HINT_RANGE, "0," + itos(MAX_DRAW_PASSES) + ",1"), "set_draw_passes", "get_draw_passes"); for (int i = 0; i < MAX_DRAW_PASSES; i++) { @@ -278,16 +320,18 @@ Particles::Particles() { particles = VS::get_singleton()->particles_create(); set_base(particles); set_emitting(true); - set_amount(100); + set_amount(8); set_lifetime(1); set_fixed_fps(0); set_fractional_delta(true); set_pre_process_time(0); set_explosiveness_ratio(0); set_randomness_ratio(0); - set_gravity(Vector3(0, -9.8, 0)); + set_visibility_aabb(Rect3(Vector3(-4, -4, -4), Vector3(8, 8, 8))); set_use_local_coordinates(true); set_draw_passes(1); + set_draw_order(DRAW_ORDER_INDEX); + set_speed_scale(1); } Particles::~Particles() { @@ -362,6 +406,8 @@ void ParticlesMaterial::init_shaders() { shader_names->trail_divisor = "trail_divisor"; shader_names->trail_size_modifier = "trail_size_modifier"; shader_names->trail_color_modifier = "trail_color_modifier"; + + shader_names->gravity = "gravity"; } void ParticlesMaterial::finish_shaders() { @@ -437,6 +483,8 @@ void ParticlesMaterial::_update_shader() { code += "uniform int trail_divisor;\n"; + code += "uniform vec3 gravity;\n"; + if (color_ramp.is_valid()) code += "uniform sampler2D color_ramp;\n"; @@ -633,7 +681,7 @@ void ParticlesMaterial::_update_shader() { else code += " float tex_anim_offset = 0.0;\n"; - code += " vec3 force = vec3(0.0); \n"; + code += " vec3 force = gravity; \n"; code += " vec3 pos = TRANSFORM[3].xyz; \n"; code += " //apply linear acceleration\n"; code += " force+=normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random);\n"; @@ -643,7 +691,7 @@ void ParticlesMaterial::_update_shader() { code += " //org=p_transform.origin;\n"; code += " force+=normalize(pos-org) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random);\n"; code += " //apply tangential acceleration;\n"; - code += " force+=normalize(cross(normalize(pos-org),normalize(GRAVITY))) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; + code += " force+=normalize(cross(normalize(pos-org),normalize(gravity))) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; code += " //apply attractor forces\n"; code += " VELOCITY+=force * DELTA;\n"; if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) @@ -1168,6 +1216,21 @@ Ref<GradientTexture> ParticlesMaterial::get_trail_color_modifier() const { return trail_color_modifier; } +void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) { + + gravity = p_gravity; + Vector3 gset = gravity; + if (gset == Vector3()) { + gset = Vector3(0, -0.000001, 0); //as gravity is used as upvector in some calculations + } + VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->gravity, gset); +} + +Vector3 ParticlesMaterial::get_gravity() const { + + return gravity; +} + void ParticlesMaterial::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { @@ -1248,6 +1311,9 @@ void ParticlesMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_trail_color_modifier", "texture:GradientTexture"), &ParticlesMaterial::set_trail_color_modifier); ClassDB::bind_method(D_METHOD("get_trail_color_modifier:GradientTexture"), &ParticlesMaterial::get_trail_color_modifier); + ClassDB::bind_method(D_METHOD("get_gravity"), &ParticlesMaterial::get_gravity); + ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &ParticlesMaterial::set_gravity); + ADD_GROUP("Trail", "trail_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "trail_divisor", PROPERTY_HINT_RANGE, "1,1000000,1"), "set_trail_divisor", "get_trail_divisor"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "trail_size_modifier", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_trail_size_modifier", "get_trail_size_modifier"); @@ -1265,6 +1331,8 @@ void ParticlesMaterial::_bind_methods() { ADD_GROUP("Spread", ""); ADD_PROPERTY(PropertyInfo(Variant::REAL, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "flatness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_flatness", "get_flatness"); + ADD_GROUP("Gravity", ""); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity"), "set_gravity", "get_gravity"); ADD_GROUP("Initial Velocity", "initial_"); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity", PROPERTY_HINT_RANGE, "0,1000,0.01"), "set_param", "get_param", PARAM_INITIAL_LINEAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_INITIAL_LINEAR_VELOCITY); @@ -1361,6 +1429,7 @@ ParticlesMaterial::ParticlesMaterial() set_emission_sphere_radius(1); set_emission_box_extents(Vector3(1, 1, 1)); set_trail_divisor(1); + set_gravity(Vector3(0, -9.8, 0)); emission_point_count = 1; for (int i = 0; i < PARAM_MAX; i++) { diff --git a/scene/3d/particles.h b/scene/3d/particles.h index 3a46269396..63ebd7ed7b 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -63,8 +63,8 @@ private: float pre_process_time; float explosiveness_ratio; float randomness_ratio; - Rect3 custom_aabb; - Vector3 gravity; + float speed_scale; + Rect3 visibility_aabb; bool local_coords; int fixed_fps; bool fractional_delta; @@ -89,10 +89,10 @@ public: void set_pre_process_time(float p_time); void set_explosiveness_ratio(float p_ratio); void set_randomness_ratio(float p_ratio); - void set_custom_aabb(const Rect3 &p_aabb); - void set_gravity(const Vector3 &p_gravity); + void set_visibility_aabb(const Rect3 &p_aabb); void set_use_local_coordinates(bool p_enable); void set_process_material(const Ref<Material> &p_material); + void set_speed_scale(float p_scale); bool is_emitting() const; int get_amount() const; @@ -100,10 +100,10 @@ public: float get_pre_process_time() const; float get_explosiveness_ratio() const; float get_randomness_ratio() const; - Rect3 get_custom_aabb() const; - Vector3 get_gravity() const; + Rect3 get_visibility_aabb() const; bool get_use_local_coordinates() const; Ref<Material> get_process_material() const; + float get_speed_scale() const; void set_fixed_fps(int p_count); int get_fixed_fps() const; @@ -120,6 +120,9 @@ public: void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh); Ref<Mesh> get_draw_pass_mesh(int p_pass) const; + virtual String get_configuration_warning() const; + + Rect3 capture_aabb() const; Particles(); ~Particles(); }; @@ -270,6 +273,8 @@ private: StringName trail_divisor; StringName trail_size_modifier; StringName trail_color_modifier; + + StringName gravity; }; static ShaderNames *shader_names; @@ -304,6 +309,8 @@ private: Ref<CurveTexture> trail_size_modifier; Ref<GradientTexture> trail_color_modifier; + Vector3 gravity; + //do not save emission points here protected: @@ -358,6 +365,9 @@ public: void set_trail_color_modifier(const Ref<GradientTexture> &p_trail_color_modifier); Ref<GradientTexture> get_trail_color_modifier() const; + void set_gravity(const Vector3 &p_gravity); + Vector3 get_gravity() const; + static void init_shaders(); static void finish_shaders(); static void flush_changes(); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index d6c68a1d82..c4ea42d461 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -611,7 +611,7 @@ void AnimationPlayer::_animation_update_transforms() { 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_POS: static_cast<Node2D*>(pa->object)->set_position(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; }*/ diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 8a94d4918f..adb5e2f0b6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -591,7 +591,7 @@ void ColorPickerButton::_color_changed(const Color &p_color) { void ColorPickerButton::pressed() { Size2 ms = Size2(300, picker->get_combined_minimum_size().height + 10); - popup->set_pos(get_global_pos() - Size2(0, ms.height)); + popup->set_position(get_global_position() - Size2(0, ms.height)); popup->set_size(ms); popup->popup(); picker->set_focus_on_line_edit(); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 0bc9205175..c6f73fe6e6 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -62,7 +62,7 @@ void ColorRampEdit::_show_color_picker() { return; Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10); picker->set_pick_color(points[grabbed].color); - popup->set_pos(get_global_pos() - Vector2(ms.width - get_size().width, ms.height)); + popup->set_position(get_global_position() - Vector2(ms.width - get_size().width, ms.height)); popup->set_size(ms); popup->popup(); } diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index d3096d7806..c428d524a4 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -107,7 +107,7 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) { for (int i = 0; i < 4; i++) p_child->set_anchor(Margin(i), ANCHOR_BEGIN); - p_child->set_pos(r.pos); + p_child->set_position(r.pos); p_child->set_size(r.size); p_child->set_rotation(0); p_child->set_scale(Vector2(1, 1)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bda54181c7..e62a993651 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -58,7 +58,7 @@ void Control::edit_set_state(const Variant &p_state) { Dictionary s = p_state; Rect2 state = s["rect"]; - set_pos(state.pos); + set_position(state.pos); set_size(state.size); set_rotation(s["rot"]); set_scale(s["scale"]); @@ -96,13 +96,13 @@ void Control::edit_set_rect(const Rect2 &p_edit_rect) { postxf.set_rotation_and_scale(data.rotation, data.scale); Vector2 new_pos = postxf.xform(p_edit_rect.pos); - Vector2 pos = get_pos() + new_pos; + Vector2 pos = get_position() + new_pos; Rect2 new_rect = get_rect(); new_rect.pos = pos.snapped(Vector2(1, 1)); new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1)); - set_pos(new_rect.pos); + set_position(new_rect.pos); set_size(new_rect.size); } @@ -353,7 +353,7 @@ void Control::remove_child_notify(Node *p_child) { void Control::_update_canvas_item_transform() { - Transform2D xform = Transform2D(data.rotation, get_pos()); + Transform2D xform = Transform2D(data.rotation, get_position()); xform.scale_basis(data.scale); VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); } @@ -1390,12 +1390,12 @@ Size2 Control::get_end() const { return Size2(data.margin[2], data.margin[3]); } -Point2 Control::get_global_pos() const { +Point2 Control::get_global_position() const { return get_global_transform().get_origin(); } -void Control::set_global_pos(const Point2 &p_point) { +void Control::set_global_position(const Point2 &p_point) { Transform2D inv; @@ -1404,10 +1404,10 @@ void Control::set_global_pos(const Point2 &p_point) { inv = data.parent_canvas_item->get_global_transform().affine_inverse(); } - set_pos(inv.xform(p_point)); + set_position(inv.xform(p_point)); } -void Control::set_pos(const Size2 &p_point) { +void Control::set_position(const Size2 &p_point) { float pw = _get_parent_range(0); float ph = _get_parent_range(1); @@ -1459,7 +1459,7 @@ void Control::set_size(const Size2 &p_size) { _size_changed(); } -Size2 Control::get_pos() const { +Size2 Control::get_position() const { return data.pos_cache; } @@ -1471,7 +1471,7 @@ Size2 Control::get_size() const { Rect2 Control::get_global_rect() const { - return Rect2(get_global_pos(), get_size()); + return Rect2(get_global_position(), get_size()); } Rect2 Control::get_window_rect() const { @@ -1483,7 +1483,7 @@ Rect2 Control::get_window_rect() const { Rect2 Control::get_rect() const { - return Rect2(get_pos(), get_size()); + return Rect2(get_position(), get_size()); } Rect2 Control::get_item_rect() const { @@ -1886,7 +1886,7 @@ Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const { Transform2D Control::get_transform() const { - Transform2D xform = Transform2D(data.rotation, get_pos()); + Transform2D xform = Transform2D(data.rotation, get_position()); xform.scale_basis(data.scale); return xform; } @@ -2315,10 +2315,10 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor_mode", "offset"), &Control::set_anchor_and_margin); ClassDB::bind_method(D_METHOD("set_begin", "pos"), &Control::set_begin); ClassDB::bind_method(D_METHOD("set_end", "pos"), &Control::set_end); - ClassDB::bind_method(D_METHOD("set_pos", "pos"), &Control::set_pos); + ClassDB::bind_method(D_METHOD("set_position", "pos"), &Control::set_position); ClassDB::bind_method(D_METHOD("set_size", "size"), &Control::set_size); ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size); - ClassDB::bind_method(D_METHOD("set_global_pos", "pos"), &Control::set_global_pos); + ClassDB::bind_method(D_METHOD("set_global_position", "pos"), &Control::set_global_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation); ClassDB::bind_method(D_METHOD("set_rotation_deg", "degrees"), &Control::set_rotation_deg); // TODO: Obsolete this method (old name) properly (GH-4397) @@ -2327,7 +2327,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin); ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin); ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end); - ClassDB::bind_method(D_METHOD("get_pos"), &Control::get_pos); + ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position); ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size); ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation); ClassDB::bind_method(D_METHOD("get_rotation_deg"), &Control::get_rotation_deg); @@ -2336,7 +2336,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale); ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size); ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size); - ClassDB::bind_method(D_METHOD("get_global_pos"), &Control::get_global_pos); + ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); ClassDB::bind_method(D_METHOD("set_area_as_parent_rect", "margin"), &Control::set_area_as_parent_rect, DEFVAL(0)); @@ -2438,7 +2438,7 @@ void Control::_bind_methods() { ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM); ADD_GROUP("Rect", "rect_"); - ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_pos", "get_pos"); + ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position"); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size"); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg"); diff --git a/scene/gui/control.h b/scene/gui/control.h index 9075c5a6ed..5834d1550a 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -277,12 +277,12 @@ public: Point2 get_begin() const; Point2 get_end() const; - void set_pos(const Point2 &p_point); + void set_position(const Point2 &p_point); void set_size(const Size2 &p_size); - void set_global_pos(const Point2 &p_point); + void set_global_position(const Point2 &p_point); - Point2 get_pos() const; - Point2 get_global_pos() const; + Point2 get_position() const; + Point2 get_global_position() const; Size2 get_size() const; Rect2 get_rect() const; Rect2 get_global_rect() const; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index c53b2bdb21..835775e13b 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -36,6 +36,8 @@ #include "editor/editor_node.h" #endif +// WindowDialog + void WindowDialog::_post_popup() { drag_type = DRAG_NONE; // just in case @@ -46,20 +48,20 @@ void WindowDialog::_fix_size() { // Perhaps this should be called when the viewport resizes as well or windows go out of bounds... // Ensure the whole window is visible. - Point2i pos = get_global_pos(); + Point2i pos = get_global_position(); Size2i size = get_size(); Size2i viewport_size = get_viewport_rect().size; // Windows require additional padding to keep the window chrome visible. - Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); - float top = panel->get_margin(MARGIN_TOP); - float left = panel->get_margin(MARGIN_LEFT); - float bottom = panel->get_margin(MARGIN_BOTTOM); - float right = panel->get_margin(MARGIN_RIGHT); + Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog"); + float top = panel->get_expand_margin_size(MARGIN_TOP); + float left = panel->get_expand_margin_size(MARGIN_LEFT); + float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM); + float right = panel->get_expand_margin_size(MARGIN_RIGHT); pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); - set_global_pos(pos); + set_global_position(pos); // Also resize the window to fit if a resize should be possible at all. if (resizable) { @@ -74,9 +76,9 @@ bool WindowDialog::has_point(const Point2 &p_point) const { Rect2 r(Point2(), get_size()); // Enlarge upwards for title bar. - int titlebar_height = get_constant("titlebar_height", "WindowDialog"); - r.pos.y -= titlebar_height; - r.size.y += titlebar_height; + int title_height = get_constant("title_height", "WindowDialog"); + r.pos.y -= title_height; + r.size.y += title_height; // Inflate by the resizable border thickness. if (resizable) { @@ -98,8 +100,8 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { // Begin a possible dragging operation. drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y)); if (drag_type != DRAG_NONE) - drag_offset = get_global_mouse_pos() - get_pos(); - drag_offset_far = get_pos() + get_size() - get_global_mouse_pos(); + drag_offset = get_global_mouse_position() - get_position(); + drag_offset_far = get_position() + get_size() - get_global_mouse_position(); } else if (drag_type != DRAG_NONE && !p_event.mouse_button.pressed) { // End a dragging operation. drag_type = DRAG_NONE; @@ -136,7 +138,7 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { set_default_cursor_shape(cursor); } else { // Update while in a dragging operation. - Point2 global_pos = get_global_mouse_pos(); + Point2 global_pos = get_global_mouse_position(); global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible. Rect2 rect = get_rect(); @@ -164,7 +166,7 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { } set_size(rect.size); - set_pos(rect.pos); + set_position(rect.pos); } } } @@ -173,30 +175,21 @@ void WindowDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - RID canvas = get_canvas_item(); - Size2 size = get_size(); + // Draw the background. Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); - int margin_left = static_cast<int>(panel->get_margin(MARGIN_LEFT)); - int margin_top = static_cast<int>(panel->get_margin(MARGIN_TOP)); - int margin_right = static_cast<int>(panel->get_margin(MARGIN_RIGHT)); - int margin_bottom = static_cast<int>(panel->get_margin(MARGIN_BOTTOM)); - - Rect2 rect; - rect.pos.x = -margin_left; - rect.pos.y = -margin_top; - rect.size.width = size.width + margin_left + margin_right; - rect.size.height = size.height + margin_top + margin_bottom; - - panel->draw(canvas, rect); + Size2 size = get_size(); + panel->draw(canvas, Rect2(0, 0, size.x, size.y)); - int title_height = get_constant("title_height", "WindowDialog"); + // Draw the title bar text. + Ref<Font> title_font = get_font("title_font", "WindowDialog"); Color title_color = get_color("title_color", "WindowDialog"); - Ref<Font> font = get_font("title_font", "WindowDialog"); - int ofs = (size.width - font->get_string_size(title).width) / 2; - draw_string(font, Point2(ofs, -title_height + font->get_ascent()), title, title_color, size.width - panel->get_minimum_size().width); - + int title_height = get_constant("title_height", "WindowDialog"); + int font_height = title_font->get_height() - title_font->get_descent() * 2; + int x = (size.x - title_font->get_string_size(title).x) / 2; + int y = (-title_height + font_height) / 2; + title_font->draw(canvas, Point2(x, y), title, title_color, size.x - panel->get_minimum_size().x); } break; case NOTIFICATION_THEME_CHANGED: @@ -238,12 +231,12 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const { int drag_type = DRAG_NONE; if (resizable) { - int titlebar_height = get_constant("titlebar_height", "WindowDialog"); + int title_height = get_constant("title_height", "WindowDialog"); int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); Rect2 rect = get_rect(); - if (pos.y < (-titlebar_height + scaleborder_size)) + if (pos.y < (-title_height + scaleborder_size)) drag_type = DRAG_RESIZE_TOP; else if (pos.y >= (rect.size.height - scaleborder_size)) drag_type = DRAG_RESIZE_BOTTOM; @@ -317,6 +310,8 @@ WindowDialog::WindowDialog() { WindowDialog::~WindowDialog() { } +// PopupDialog + void PopupDialog::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -416,14 +411,14 @@ void AcceptDialog::_update_child_rects() { if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel()) continue; - c->set_pos(cpos); + c->set_position(cpos); c->set_size(csize); } cpos.y += csize.y + margin; csize.y = hminsize.y; - hbc->set_pos(cpos); + hbc->set_position(cpos); hbc->set_size(csize); } @@ -554,6 +549,8 @@ AcceptDialog::AcceptDialog() { AcceptDialog::~AcceptDialog() { } +// ConfirmationDialog + void ConfirmationDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 76baf20526..0c092a4e17 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -140,13 +140,13 @@ void GraphEdit::_update_scroll_offset() { Point2 pos = gn->get_offset() * zoom; pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - gn->set_pos(pos); + gn->set_position(pos); if (gn->get_scale() != Vector2(zoom, zoom)) { gn->set_scale(Vector2(zoom, zoom)); } } - connections_layer->set_pos(-Point2(h_scroll->get_value(), v_scroll->get_value())); + connections_layer->set_position(-Point2(h_scroll->get_value(), v_scroll->get_value())); set_block_minimum_size_adjust(false); awaiting_scroll_offset_update = false; } @@ -350,14 +350,14 @@ bool GraphEdit::_filter_input(const Point2 &p_point) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); if (pos.distance_to(p_point) < grab_r) return true; } for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); if (pos.distance_to(p_point) < grab_r) { return true; } @@ -383,7 +383,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); if (pos.distance_to(mpos) < grab_r) { if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) { @@ -430,7 +430,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); if (pos.distance_to(mpos) < grab_r) { @@ -497,7 +497,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { if (!connecting_out) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); int type = gn->get_connection_output_type(j); if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && pos.distance_to(mpos) < grab_r) { @@ -512,7 +512,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); int type = gn->get_connection_input_type(j); if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && pos.distance_to(mpos) < grab_r) { connecting_target = true; @@ -704,7 +704,7 @@ void GraphEdit::_top_layer_draw() { pos = from->get_connection_output_pos(connecting_index); else pos = from->get_connection_input_pos(connecting_index); - pos += from->get_pos(); + pos += from->get_position(); Vector2 topos; topos = connecting_to; @@ -1229,7 +1229,7 @@ GraphEdit::GraphEdit() { HBoxContainer *zoom_hb = memnew(HBoxContainer); top_layer->add_child(zoom_hb); - zoom_hb->set_pos(Vector2(10, 10)); + zoom_hb->set_position(Vector2(10, 10)); zoom_minus = memnew(ToolButton); zoom_hb->add_child(zoom_minus); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 30bc4d1663..9abf9649c0 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -51,7 +51,7 @@ void LineEdit::_gui_input(InputEvent p_event) { const InputEventMouseButton &b = p_event.mouse_button; if (b.pressed && b.button_index == BUTTON_RIGHT) { - menu->set_pos(get_global_transform().xform(get_local_mouse_pos())); + menu->set_position(get_global_transform().xform(get_local_mouse_pos())); menu->set_size(Vector2(1, 1)); menu->popup(); grab_focus(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 16277ed0d0..cf468f2257 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -50,10 +50,10 @@ void MenuButton::pressed() { emit_signal("about_to_show"); Size2 size = get_size(); - Point2 gp = get_global_pos(); - popup->set_global_pos(gp + Size2(0, size.height)); + Point2 gp = get_global_position(); + popup->set_global_position(gp + Size2(0, size.height)); popup->set_size(Size2(size.width, 0)); - popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_pos()), get_size())); + popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size())); popup->popup(); popup->call_deferred("grab_click_focus"); popup->set_invalidate_click_until_motion(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 0bb68e7fa1..0806d35d48 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -87,7 +87,7 @@ void OptionButton::_selected(int p_which) { void OptionButton::pressed() { Size2 size = get_size(); - popup->set_global_pos(get_global_pos() + Size2(0, size.height)); + popup->set_global_position(get_global_position() + Size2(0, size.height)); popup->set_size(Size2(size.width, 0)); popup->popup(); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 523633166c..7d0b91a366 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -58,12 +58,12 @@ void Popup::_notification(int p_what) { void Popup::_fix_size() { #if 0 - Point2 pos = get_pos(); + Point2 pos = get_position(); Size2 size = get_size(); Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); #else - Point2 pos = get_global_pos(); + Point2 pos = get_global_position(); Size2 size = get_size(); Point2 window_size = get_viewport_rect().size; @@ -79,10 +79,10 @@ void Popup::_fix_size() { pos.y = 0; #if 0 if (pos!=get_pos()) - set_pos(pos); + set_position(pos); #else - if (pos != get_pos()) - set_global_pos(pos); + if (pos != get_position()) + set_global_position(pos); #endif } @@ -171,7 +171,7 @@ void Popup::popup_centered(const Size2 &p_size) { rect.size = p_size == Size2() ? get_size() : p_size; rect.pos = ((window_size - rect.size) / 2.0).floor(); - set_pos(rect.pos); + set_position(rect.pos); set_size(rect.size); show_modal(exclusive); @@ -194,7 +194,7 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { 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); + set_position(rect.pos); set_size(rect.size); show_modal(exclusive); @@ -216,7 +216,7 @@ void Popup::popup(const Rect2 &bounds) { // Fit the popup into the optionally provided bounds. if (!bounds.has_no_area()) { - set_pos(bounds.pos); + set_position(bounds.pos); set_size(bounds.size); } _fix_size(); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index de16f3c525..6ac6eac655 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -169,7 +169,7 @@ void PopupMenu::_activate_submenu(int over) { if (pm->is_visible_in_tree()) return; //already visible! - Point2 p = get_global_pos(); + Point2 p = get_global_position(); Rect2 pr(p, get_size()); Ref<StyleBox> style = get_stylebox("panel"); @@ -179,13 +179,13 @@ void PopupMenu::_activate_submenu(int over) { if (pos.x + size.width > get_viewport_rect().size.width) pos.x = p.x - size.width; - pm->set_pos(pos); + pm->set_position(pos); pm->popup(); PopupMenu *pum = pm->cast_to<PopupMenu>(); if (pum) { - pr.pos -= pum->get_global_pos(); + pr.pos -= pum->get_global_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y, pr.size.x, items[over]._ofs_cache)); if (over < items.size() - 1) { @@ -266,15 +266,15 @@ void PopupMenu::_gui_input(const InputEvent &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_global_pos().y + get_size().y > get_viewport_rect().size.y) { + if (get_global_position().y + get_size().y > get_viewport_rect().size.y) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); - Point2 pos = get_pos(); + Point2 pos = get_position(); int s = (vseparation + font->get_height()) * 3; pos.y -= s; - set_pos(pos); + set_position(pos); //update hover InputEvent ie; @@ -286,15 +286,15 @@ void PopupMenu::_gui_input(const InputEvent &p_event) { } break; case BUTTON_WHEEL_UP: { - if (get_global_pos().y < 0) { + if (get_global_position().y < 0) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); - Point2 pos = get_pos(); + Point2 pos = get_position(); int s = (vseparation + font->get_height()) * 3; pos.y += s; - set_pos(pos); + set_position(pos); //update hover InputEvent ie; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 0ef6fbdebd..0c7a58dc16 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -79,11 +79,11 @@ void TabContainer::_gui_input(const InputEvent &p_event) { if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); - Vector2 popup_pos = get_global_pos(); + Vector2 popup_pos = get_global_position(); popup_pos.x += size.width - popup->get_size().width; popup_pos.y += menu->get_height(); - popup->set_global_pos(popup_pos); + popup->set_global_position(popup_pos); popup->popup(); return; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8cbd6675f0..3c8545bd75 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -101,15 +101,15 @@ void TextEdit::Text::set_font(const Ref<Font> &p_font) { font = p_font; } -void TextEdit::Text::set_tab_size(int p_tab_size) { +void TextEdit::Text::set_indent_size(int p_indent_size) { - tab_size = p_tab_size; + indent_size = p_indent_size; } void TextEdit::Text::_update_line_cache(int p_line) const { int w = 0; - int tab_w = font->get_char_size(' ').width * tab_size; + int tab_w = font->get_char_size(' ').width * indent_size; int len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); @@ -360,7 +360,7 @@ 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(); + Point2 mp = Input::get_singleton()->get_mouse_position() - get_global_position(); int row, col; _get_mouse_pos(Point2i(mp.x, mp.y), row, col); @@ -456,7 +456,7 @@ void TextEdit::_notification(int p_what) { int visible_rows = get_visible_rows(); - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; Color color = cache.font_color; int in_region = -1; @@ -1305,7 +1305,38 @@ void TextEdit::backspace_at_cursor() { _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) { _consume_backspace_for_pair_symbol(prev_line, prev_column); } else { - _remove_text(prev_line, prev_column, cursor.line, cursor.column); + // handle space indentation + if (cursor.column - indent_size >= 0 && indent_using_spaces) { + + // if there is enough spaces to count as a tab + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } + + // and it is before the first character + int i = 0; + while (i < cursor.column && i < text[cursor.line].length()) { + if (text[cursor.line][i] != ' ' && text[cursor.line][i] != '\t') { + unindent = false; + break; + } + i++; + } + + // then we can remove it as a single character. + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + prev_column = cursor.column - indent_size; + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } } cursor_set_line(prev_line); @@ -1328,7 +1359,11 @@ void TextEdit::indent_selection_right() { for (int i = start_line; i <= end_line; i++) { String line_text = get_line(i); - line_text = '\t' + line_text; + if (indent_using_spaces) { + line_text = space_indent + line_text; + } else { + line_text = '\t' + line_text; + } set_line(i, line_text); } @@ -1359,8 +1394,8 @@ void TextEdit::indent_selection_left() { if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); set_line(i, line_text); - } else if (line_text.begins_with(" ")) { - line_text = line_text.substr(4, line_text.length()); + } else if (line_text.begins_with(space_indent)) { + line_text = line_text.substr(indent_size, line_text.length()); set_line(i, line_text); } } @@ -1586,7 +1621,7 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { if (mb.button_index == BUTTON_RIGHT && context_menu_enabled) { - menu->set_pos(get_global_transform().xform(get_local_mouse_pos())); + menu->set_position(get_global_transform().xform(get_local_mouse_pos())); menu->set_size(Vector2(1, 1)); menu->popup(); grab_focus(); @@ -1931,17 +1966,39 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { String ins = "\n"; //keep indentation + int space_count = 0; for (int i = 0; i < text[cursor.line].length(); i++) { - if (text[cursor.line][i] == '\t') - ins += "\t"; - else + if (text[cursor.line][i] == '\t') { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } else if (text[cursor.line][i] == ' ') { + space_count++; + + if (space_count == indent_size) { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } + } 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"; + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } } } @@ -1987,15 +2044,36 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { } else { if (k.mod.shift) { + //simple unindent int cc = cursor.column; - if (cc > 0 && cc <= text[cursor.line].length() && text[cursor.line][cursor.column - 1] == '\t') { - //simple unindent + if (cc > 0 && cc <= text[cursor.line].length()) { + if (text[cursor.line][cursor.column - 1] == '\t') { + backspace_at_cursor(); + } else { + if (cursor.column - indent_size >= 0) { + + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } - backspace_at_cursor(); + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + cursor_set_column(cursor.column - indent_size); + } + } + } } } else { //simple indent - _insert_text_at_cursor("\t"); + if (indent_using_spaces) { + _insert_text_at_cursor(space_indent); + } else { + _insert_text_at_cursor("\t"); + } } } @@ -3103,7 +3181,7 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const { int px = 0; int c = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; while (c < p_str.length()) { @@ -3135,7 +3213,7 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) { int px = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; for (int i = 0; i < p_char; i++) { @@ -3952,10 +4030,24 @@ void TextEdit::_push_current_op() { current_op.chain_forward = false; } -void TextEdit::set_tab_size(const int p_size) { +void TextEdit::set_indent_using_spaces(const bool p_use_spaces) { + indent_using_spaces = p_use_spaces; +} + +bool TextEdit::is_indent_using_spaces() const { + return indent_using_spaces; +} + +void TextEdit::set_indent_size(const int p_size) { ERR_FAIL_COND(p_size <= 0); - tab_size = p_size; - text.set_tab_size(p_size); + indent_size = p_size; + text.set_indent_size(p_size); + + space_indent = ""; + for (int i = 0; i < p_size; i++) { + space_indent += " "; + } + update(); } @@ -4542,8 +4634,8 @@ TextEdit::TextEdit() { cache.breakpoint_gutter_width = 0; breakpoint_gutter_width = 0; - tab_size = 4; - text.set_tab_size(tab_size); + indent_size = 4; + text.set_indent_size(indent_size); text.clear(); //text.insert(1,"Mongolia.."); //text.insert(2,"PAIS GENEROSO!!"); @@ -4631,6 +4723,8 @@ TextEdit::TextEdit() { auto_brace_completion_enabled = false; brace_matching_enabled = false; highlight_all_occurrences = false; + indent_using_spaces = false; + space_indent = " "; auto_indent = false; insert_mode = false; window_has_focus = true; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index d5fe2950f4..905ea46bd7 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -141,12 +141,12 @@ class TextEdit : public Control { const Vector<ColorRegion> *color_regions; mutable Vector<Line> text; Ref<Font> font; - int tab_size; + int indent_size; void _update_line_cache(int p_line) const; public: - void set_tab_size(int p_tab_size); + void set_indent_size(int p_indent_size); void set_font(const Ref<Font> &p_font); void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; } int get_line_width(int p_line) const; @@ -163,7 +163,7 @@ class TextEdit : public Control { void clear(); void clear_caches(); _FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; } - Text() { tab_size = 4; } + Text() { indent_size = 4; } }; struct TextOperation { @@ -221,7 +221,9 @@ class TextEdit : public Control { int max_chars; bool readonly; bool syntax_coloring; - int tab_size; + bool indent_using_spaces; + int indent_size; + String space_indent; Timer *caret_blink_timer; bool caret_blink_enabled; @@ -461,7 +463,9 @@ public: void redo(); void clear_undo_history(); - void set_tab_size(const int p_size); + void set_indent_using_spaces(const bool p_use_spaces); + bool is_indent_using_spaces() const; + void set_indent_size(const int p_size); void set_draw_tabs(bool p_draw); bool is_drawing_tabs() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 1cfaa58b92..bc7b7485d8 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1041,7 +1041,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 cache.selected->draw(ci, r); } if (text_editor->is_visible_in_tree()) { - text_editor->set_pos(get_global_pos() + r.pos); + text_editor->set_position(get_global_position() + r.pos); } } @@ -1503,7 +1503,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool cache.click_id = c.buttons[j].id; cache.click_item = p_item; cache.click_column = col; - cache.click_pos = get_global_mouse_pos() - get_global_pos(); + cache.click_pos = get_global_mouse_position() - get_global_position(); update(); //emit_signal("button_pressed"); return -1; @@ -1627,7 +1627,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } popup_menu->set_size(Size2(col_width, 0)); - popup_menu->set_pos(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h) - cache.offset); + popup_menu->set_position(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h) - cache.offset); popup_menu->popup(); popup_edited_item = p_item; popup_edited_item_col = col; @@ -1693,7 +1693,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool case TreeItem::CELL_MODE_CUSTOM: { edited_item = p_item; edited_col = col; - custom_popup_rect = Rect2i(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); + custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2)))); bring_up_editor = false; @@ -1710,7 +1710,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool popup_edited_item = p_item; popup_edited_item_col = col; - pressing_item_rect = Rect2(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - cache.offset, Size2(col_width, item_h)); + pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - cache.offset, Size2(col_width, item_h)); pressing_for_editor_text = editor_text; pressing_for_editor = true; @@ -2379,7 +2379,7 @@ bool Tree::edit_selected() { edited_item = s; edited_col = col; - custom_popup_rect = Rect2i(get_global_pos() + rect.pos, rect.size); + custom_popup_rect = Rect2i(get_global_position() + rect.pos, rect.size); emit_signal("custom_popup_edited", false); item_edited(col, s); @@ -2394,7 +2394,7 @@ bool Tree::edit_selected() { } popup_menu->set_size(Size2(rect.size.width, 0)); - popup_menu->set_pos(get_global_pos() + rect.pos + Point2i(0, rect.size.height)); + popup_menu->set_position(get_global_position() + rect.pos + Point2i(0, rect.size.height)); popup_menu->popup(); popup_edited_item = s; popup_edited_item_col = col; @@ -2402,8 +2402,8 @@ bool Tree::edit_selected() { } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { - Point2i textedpos = get_global_pos() + rect.pos; - text_editor->set_pos(textedpos); + Point2i textedpos = get_global_position() + rect.pos; + text_editor->set_position(textedpos); text_editor->set_size(rect.size); text_editor->clear(); text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::step_decimals(c.step))); @@ -2411,7 +2411,7 @@ bool Tree::edit_selected() { if (c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { - value_editor->set_pos(textedpos + Point2i(0, text_editor->get_size().height)); + value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height)); value_editor->set_size(Size2(rect.size.width, 1)); value_editor->show_modal(); updating_value_editor = true; @@ -2529,7 +2529,7 @@ void Tree::_notification(int p_what) { if (p_what == NOTIFICATION_DRAG_BEGIN) { single_select_defer = NULL; - if (cache.scroll_speed > 0 && get_rect().has_point(get_viewport()->get_mouse_pos() - get_global_pos())) { + if (cache.scroll_speed > 0 && get_rect().has_point(get_viewport()->get_mouse_position() - get_global_position())) { scrolling = true; set_fixed_process(true); } @@ -2577,7 +2577,7 @@ void Tree::_notification(int p_what) { } if (scrolling) { - Point2 point = get_viewport()->get_mouse_pos() - get_global_pos(); + Point2 point = get_viewport()->get_mouse_position() - get_global_position(); if (point.x < cache.scroll_border) { point.x -= cache.scroll_border; } else if (point.x > get_size().width - cache.scroll_border) { diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index 53eefd26fe..dabbb79de3 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -98,7 +98,7 @@ RES ResourceFormatLoaderWAV::load(const String &p_path, const String& p_original /* chunk size */ uint32_t chunksize=file->get_32(); - uint32_t file_pos=file->get_pos(); //save file pos, so we can skip to next chunk safely + uint32_t file_pos=file->get_position(); //save file pos, so we can skip to next chunk safely if (file->eof_reached()) { diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 83f60bb9e9..be28479f39 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -2317,7 +2317,7 @@ SceneTree::SceneTree() { stretch_aspect = STRETCH_ASPECT_IGNORE; last_screen_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); - root->set_size(last_screen_size); + _update_root_rect(); if (ScriptDebugger::get_singleton()) { ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree, this); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 31c9cb15a8..406640275c 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1444,9 +1444,9 @@ void Viewport::_vp_unhandled_input(const InputEvent &p_ev) { unhandled_input(ev); } -Vector2 Viewport::get_mouse_pos() const { +Vector2 Viewport::get_mouse_position() const { - return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos() - _get_window_offset()); + return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_position() - _get_window_offset()); } void Viewport::warp_mouse(const Vector2 &p_pos) { @@ -1538,7 +1538,7 @@ void Viewport::_gui_show_tooltip() { else if (r.pos.y < 0) r.pos.y = 0; - gui.tooltip_popup->set_global_pos(r.pos); + gui.tooltip_popup->set_global_position(r.pos); gui.tooltip_popup->set_size(r.size); gui.tooltip_popup->raise(); @@ -1640,7 +1640,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ Control *c = p_node->cast_to<Control>(); if (c) { - //print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); + //print_line("at "+String(c->get_path())+" POS "+c->get_position()+" bt "+p_xform); } //subwindows first!! @@ -1993,7 +1993,7 @@ void Viewport::_gui_input_event(InputEvent p_event) { gui.mouse_over = over; if (gui.drag_preview) { - gui.drag_preview->set_pos(mpos); + gui.drag_preview->set_position(mpos); } if (!over) { @@ -2237,7 +2237,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { memdelete(gui.drag_preview); } p_control->set_as_toplevel(true); - p_control->set_pos(gui.last_mouse_pos); + p_control->set_position(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) { @@ -2649,7 +2649,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("is_audio_listener_2d", "enable"), &Viewport::is_audio_listener_2d); ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect", "rect"), &Viewport::set_attach_to_screen_rect); - ClassDB::bind_method(D_METHOD("get_mouse_pos"), &Viewport::get_mouse_pos); + ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); ClassDB::bind_method(D_METHOD("warp_mouse", "to_pos"), &Viewport::warp_mouse); ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 242ee4b4e6..d784fc8ee9 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -400,7 +400,7 @@ public: void set_attach_to_screen_rect(const Rect2 &p_rect); Rect2 get_attach_to_screen_rect() const; - Vector2 get_mouse_pos() const; + Vector2 get_mouse_position() const; void warp_mouse(const Vector2 &p_pos); void set_physics_object_picking(bool p_enable); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 595c0ecfd8..3a824a56a3 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -284,16 +284,10 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< // ToolButton - Ref<StyleBox> tb_empty = memnew(StyleBoxEmpty); - tb_empty->set_default_margin(MARGIN_LEFT, 6 * scale); - tb_empty->set_default_margin(MARGIN_RIGHT, 6 * scale); - tb_empty->set_default_margin(MARGIN_TOP, 4 * scale); - tb_empty->set_default_margin(MARGIN_BOTTOM, 4 * scale); - - t->set_stylebox("normal", "ToolButton", tb_empty); - t->set_stylebox("pressed", "ToolButton", make_stylebox(button_pressed_png, 4, 4, 4, 4)); - t->set_stylebox("hover", "ToolButton", make_stylebox(button_normal_png, 4, 4, 4, 4)); - t->set_stylebox("disabled", "ToolButton", make_empty_stylebox(4, 4, 4, 4)); + t->set_stylebox("normal", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); + t->set_stylebox("pressed", "ToolButton", make_stylebox(button_pressed_png, 4, 4, 4, 4, 6, 4, 6, 4)); + t->set_stylebox("hover", "ToolButton", make_stylebox(button_normal_png, 4, 4, 4, 4, 6, 4, 6, 4)); + t->set_stylebox("disabled", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); t->set_stylebox("focus", "ToolButton", focus); t->set_font("font", "ToolButton", default_font); @@ -538,10 +532,8 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< // WindowDialog - Ref<StyleBoxTexture> style_pp_win = sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6); - t->set_stylebox("panel", "WindowDialog", style_pp_win); - t->set_constant("titlebar_height", "WindowDialog", 20 * scale); - t->set_constant("scaleborder_size", "WindowDialog", 4); + t->set_stylebox("panel", "WindowDialog", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6)); + t->set_constant("scaleborder_size", "WindowDialog", 4 * scale); t->set_font("title_font", "WindowDialog", large_font); t->set_color("title_color", "WindowDialog", Color(0, 0, 0)); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 7738157330..50fbb6a162 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1775,7 +1775,7 @@ void PackedScene::set_path(const String &p_path, bool p_take_over) { void PackedScene::_bind_methods() { ClassDB::bind_method(D_METHOD("pack", "path:Node"), &PackedScene::pack); - ClassDB::bind_method(D_METHOD("instance:Node", "edit_state"), &PackedScene::instance, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("instance:Node", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED)); ClassDB::bind_method(D_METHOD("can_instance"), &PackedScene::can_instance); ClassDB::bind_method(D_METHOD("_set_bundled_scene"), &PackedScene::_set_bundled_scene); ClassDB::bind_method(D_METHOD("_get_bundled_scene"), &PackedScene::_get_bundled_scene); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 35158806ca..13529c8572 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -138,6 +138,11 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { texture->get_rect_region(rect, src_rect, rect, src_rect); + rect.pos.x -= expand_margin[MARGIN_LEFT]; + rect.pos.y -= expand_margin[MARGIN_TOP]; + rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT]; + rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM]; + VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate); } |