diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-03-09 00:14:08 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-03-09 00:14:08 +0100 |
commit | e46e43d2aaa6339a1675eb989f41885e745bf5c3 (patch) | |
tree | cf91f2869ff8f058c6682569fb31e22e5ee736ad /scene | |
parent | 1dad6eca812e5c2e313b54265114de8a1d73d999 (diff) | |
parent | 4a4f2479146aa33e235ed57cde311efda68d3c8f (diff) |
Merge pull request #3928 from Marqin/whitespace
remove trailing whitespace - sorry for the broken PRs, please rebase :)
Diffstat (limited to 'scene')
115 files changed, 2782 insertions, 2782 deletions
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 3c51bbf220..22e5bc382a 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -103,7 +103,7 @@ public: bool is_v_drag_enabled() const; void set_drag_margin(Margin p_margin,float p_drag_margin); - float get_drag_margin(Margin p_margin) const; + float get_drag_margin(Margin p_margin) const; void set_v_offset(float p_offset); float get_v_offset() const; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 316097fbcf..483feea5c4 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -233,7 +233,7 @@ bool CanvasItem::is_visible() const { const CanvasItem *p=this; - while(p) { + while(p) { if (p->hidden) return false; p=p->get_parent_item(); @@ -310,11 +310,11 @@ void CanvasItem::hide() { } void CanvasItem::set_hidden(bool p_hidden) { - + if (hidden == p_hidden) { return; } - + _set_visible_(!p_hidden); } @@ -1209,7 +1209,7 @@ CanvasItem::CanvasItem() : xform_change(this) { pending_update=false; opacity=1; self_opacity=1; - toplevel=false; + toplevel=false; pending_children_sort=false; first_draw=false; blend_mode=BLEND_MODE_MIX; diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 3a45b0c84e..b5a6cc435f 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -261,7 +261,7 @@ void CollisionObject2D::add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p else Physics2DServer::get_singleton()->body_add_shape(get_rid(),p_shape->get_rid(),p_transform); - shapes.push_back(sdata); + shapes.push_back(sdata); } int CollisionObject2D::get_shape_count() const { diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 5b13c32d93..ffea060e82 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -504,7 +504,7 @@ void Particles2D::_notification(int p_what) { invxform=get_global_transform().affine_inverse(); int start_particle = (int)(time * (float)particle_count / lifetime); - + for (int id=0;id<particle_count;++id) { int i = start_particle + id; if (i >= particle_count) { @@ -645,7 +645,7 @@ static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={ "randomness/gravity_strength", "randomness/radial_accel", "randomness/tangential_accel", - "randomness/damping", + "randomness/damping", "randomness/initial_angle", "randomness/initial_size", "randomness/final_size", diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h index 101395589e..06dcda7165 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/particles_2d.h @@ -88,7 +88,7 @@ public: enum Parameter { PARAM_DIRECTION, PARAM_SPREAD, - PARAM_LINEAR_VELOCITY, + PARAM_LINEAR_VELOCITY, PARAM_SPIN_VELOCITY, PARAM_ORBIT_VELOCITY, PARAM_GRAVITY_DIRECTION, @@ -150,7 +150,7 @@ private: Point2 emissor_offset; Vector2 initial_velocity; Vector2 extents; - DVector<Vector2> emission_points; + DVector<Vector2> emission_points; float time; int active_count; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 1cd6399962..34a67c088f 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -454,7 +454,7 @@ void TileMap::_update_dirty_quadrants() { shape->draw(debug_canvas_item,debug_collision_color); } - ps->body_add_shape(q.body,shape->get_rid(),xform); + ps->body_add_shape(q.body,shape->get_rid(),xform); ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y)); } diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp index 1ae7866f0b..4487415030 100644 --- a/scene/3d/baked_light_instance.cpp +++ b/scene/3d/baked_light_instance.cpp @@ -13,7 +13,7 @@ RID BakedLightInstance::get_baked_light_instance() const { void BakedLightInstance::set_baked_light(const Ref<BakedLight>& p_baked_light) { - baked_light=p_baked_light; + baked_light=p_baked_light; RID base_rid; diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 01163e40e8..e76c0938fb 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -56,8 +56,8 @@ void Camera::_update_camera_mode() { } break; case PROJECTION_ORTHOGONAL: { set_orthogonal(size,near,far); - } break; - + } break; + } } @@ -81,7 +81,7 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) { else if (p_name=="near") near=p_value; else if (p_name=="far") - far=p_value; + far=p_value; else if (p_name=="keep_aspect") set_keep_aspect_mode(KeepAspect(int(p_value))); else if (p_name=="vaspect") @@ -102,7 +102,7 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) { set_environment(p_value); } else return false; - + _update_camera_mode(); if (changed_all) _change_notify(); @@ -147,21 +147,21 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const { void Camera::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal") ); - + switch(mode) { - + case PROJECTION_PERSPECTIVE: { - + p_list->push_back( PropertyInfo( Variant::REAL, "fov" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_NOEDITOR) ); if (keep_aspect==KEEP_WIDTH) p_list->push_back( PropertyInfo( Variant::REAL, "fovx" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) ); else p_list->push_back( PropertyInfo( Variant::REAL, "fovy" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) ); - + } break; case PROJECTION_ORTHOGONAL: { - + p_list->push_back( PropertyInfo( Variant::REAL, "size" , PROPERTY_HINT_RANGE, "1,16384,0.01",PROPERTY_USAGE_NOEDITOR ) ); if (keep_aspect==KEEP_WIDTH) p_list->push_back( PropertyInfo( Variant::REAL, "sizex" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) ); @@ -169,9 +169,9 @@ void Camera::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL, "sizey" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) ); } break; - + } - + p_list->push_back( PropertyInfo( Variant::REAL, "near" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") ); p_list->push_back( PropertyInfo( Variant::REAL, "far" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") ); p_list->push_back( PropertyInfo( Variant::INT, "keep_aspect",PROPERTY_HINT_ENUM,"Keep Width,Keep Height") ); @@ -209,7 +209,7 @@ void Camera::_update_camera() { void Camera::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_WORLD: { @@ -218,13 +218,13 @@ void Camera::_notification(int p_what) { make_current(); - } break; + } break; case NOTIFICATION_TRANSFORM_CHANGED: { - + _request_camera_update(); } break; case NOTIFICATION_EXIT_WORLD: { - + if (!get_tree()->is_node_being_edited(this)) { if (is_current()) { clear_current(); @@ -250,7 +250,7 @@ void Camera::_notification(int p_what) { } } break; - + } } @@ -270,7 +270,7 @@ void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far near=p_z_near; far=p_z_far; mode=PROJECTION_PERSPECTIVE; - + VisualServer::get_singleton()->camera_set_perspective(camera,fov,near,far); update_gizmo(); force_change=false; @@ -281,12 +281,12 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { return; size = p_size; - + near=p_z_near; far=p_z_far; mode=PROJECTION_ORTHOGONAL; force_change=false; - + VisualServer::get_singleton()->camera_set_orthogonal(camera,size,near,far); update_gizmo(); } diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 02ca6ffb9a..30c6928245 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -41,7 +41,7 @@ class Camera : public Spatial { OBJ_TYPE( Camera, Spatial ); public: enum Projection { - + PROJECTION_PERSPECTIVE, PROJECTION_ORTHOGONAL }; @@ -57,14 +57,14 @@ private: bool current; Projection mode; - + float fov; float size; float near,far; float v_offset; float h_offset; KeepAspect keep_aspect; - + RID camera; RID scenario_id; @@ -86,14 +86,14 @@ protected: void _update_camera(); virtual void _request_camera_update(); void _update_camera_mode(); - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; void _notification(int p_what); - + static void _bind_methods(); - + public: enum { @@ -104,7 +104,7 @@ public: void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_orthogonal(float p_size, float p_z_near, float p_z_far); - + void make_current(); void clear_current(); bool is_current() const; @@ -145,7 +145,7 @@ public: float get_h_offset() const; - Camera(); + Camera(); ~Camera(); }; diff --git a/scene/3d/character_camera.cpp b/scene/3d/character_camera.cpp index 2b22026fe9..fc3dfcd645 100644 --- a/scene/3d/character_camera.cpp +++ b/scene/3d/character_camera.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "character_camera.h" - + #include "physics_body.h" #if 0 void CharacterCamera::_set(const String& p_name, const Variant& p_value) { diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 18463742c6..227bb3a59d 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "light.h" - + #include "globals.h" #include "scene/resources/surface_tool.h" @@ -86,7 +86,7 @@ void Light::set_project_shadows(bool p_enabled) { _change_notify("shadow"); } bool Light::has_project_shadows() const { - + return shadows; } @@ -175,9 +175,9 @@ RES Light::_get_gizmo_geometry() const { Ref< Mesh > mesh; Ref<SurfaceTool> surftool( memnew( SurfaceTool )); - + switch(type) { - + case VisualServer::LIGHT_DIRECTIONAL: { @@ -260,9 +260,9 @@ RES Light::_get_gizmo_geometry() const { surftool->set_material(mat_light); mesh=surftool->commit(mesh); } break; - + case VisualServer::LIGHT_SPOT: { - + _make_sphere( 5,5,0.1, surftool ); surftool->set_material(mat_light); mesh=surftool->commit(mesh); @@ -273,14 +273,14 @@ RES Light::_get_gizmo_geometry() const { float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len; surftool->begin(Mesh::PRIMITIVE_TRIANGLES); - + for(int i = 0; i < points; i++) { - + float x0=Math::sin(i * Math_PI * 2 / points); float y0=Math::cos(i * Math_PI * 2 / points); float x1=Math::sin((i+1) * Math_PI * 2 / points); float y1=Math::cos((i+1) * Math_PI * 2 / points); - + Vector3 v1=Vector3(x0*size,y0*size,-len).normalized()*len; Vector3 v2=Vector3(x1*size,y1*size,-len).normalized()*len; @@ -288,7 +288,7 @@ RES Light::_get_gizmo_geometry() const { Vector3 v4=Vector3(0,0,v1.z); Vector3 n = Plane(v1,v2,v3).normal; - + surftool->add_normal(n); surftool->add_vertex(v1); @@ -306,7 +306,7 @@ RES Light::_get_gizmo_geometry() const { surftool->add_normal(n); surftool->add_vertex(v4); - + } surftool->set_material(mat_area); @@ -323,15 +323,15 @@ RES Light::_get_gizmo_geometry() const { AABB Light::get_aabb() const { if (type==VisualServer::LIGHT_DIRECTIONAL) { - - return AABB( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) ); - + + return AABB( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) ); + } else if (type==VisualServer::LIGHT_OMNI) { - + return AABB( Vector3(-1,-1,-1) * vars[PARAM_RADIUS], Vector3(2, 2, 2 ) * vars[PARAM_RADIUS]); - + } else if (type==VisualServer::LIGHT_SPOT) { - + float len=vars[PARAM_RADIUS]; float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len; return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) ); @@ -542,7 +542,7 @@ void Light::_bind_methods() { BIND_CONSTANT( COLOR_DIFFUSE ); - BIND_CONSTANT( COLOR_SPECULAR ); + BIND_CONSTANT( COLOR_SPECULAR ); BIND_CONSTANT( BAKE_MODE_DISABLED ); BIND_CONSTANT( BAKE_MODE_INDIRECT ); diff --git a/scene/3d/light.h b/scene/3d/light.h index b74085b7a9..b25c6a44b5 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -43,7 +43,7 @@ class Light : public VisualInstance { OBJ_CATEGORY("3D Light Nodes"); public: - + enum Parameter { PARAM_RADIUS=VisualServer::LIGHT_PARAM_RADIUS, PARAM_ENERGY=VisualServer::LIGHT_PARAM_ENERGY, @@ -57,10 +57,10 @@ public: PARAM_SHADOW_BLUR_PASSES=VisualServer::LIGHT_PARAM_SHADOW_BLUR_PASSES, PARAM_MAX=VisualServer::LIGHT_PARAM_MAX }; - - + + enum LightColor { - + COLOR_DIFFUSE=VisualServer::LIGHT_COLOR_DIFFUSE, COLOR_SPECULAR=VisualServer::LIGHT_COLOR_SPECULAR }; @@ -81,13 +81,13 @@ public: OPERATOR_SUB }; private: - - + + Ref<Texture> projector; float vars[PARAM_MAX]; Color colors[3]; - - + + BakeMode bake_mode; VisualServer::LightType type; bool shadows; @@ -98,18 +98,18 @@ private: void _update_visibility(); // bind helpers -protected: +protected: RID light; virtual bool _can_gizmo_scale() const; virtual RES _get_gizmo_geometry() const; - + static void _bind_methods(); void _notification(int p_what); - - Light(VisualServer::LightType p_type); + + Light(VisualServer::LightType p_type); public: VS::LightType get_light_type() const { return type; } diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 997d2dea7c..cfe273fa20 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -139,7 +139,7 @@ AABB MeshInstance::get_aabb() const { if (!mesh.is_null()) return mesh->get_aabb(); - + return AABB(); } @@ -150,7 +150,7 @@ DVector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { if (mesh.is_null()) return DVector<Face3>(); - + return mesh->get_faces(); } @@ -177,7 +177,7 @@ void MeshInstance::create_trimesh_collision() { StaticBody* static_body = create_trimesh_collision_node()->cast_to<StaticBody>(); ERR_FAIL_COND(!static_body); static_body->set_name( String(get_name()) + "_col" ); - + add_child(static_body); if (get_owner()) static_body->set_owner( get_owner() ); @@ -233,7 +233,7 @@ void MeshInstance::_notification(int p_what) { void MeshInstance::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh); ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MeshInstance::get_mesh); ObjectTypeDB::bind_method(_MD("set_skeleton_path","skeleton_path:NodePath"),&MeshInstance::set_skeleton_path); diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance.h index f26ef52000..7c605c2d6d 100644 --- a/scene/3d/mesh_instance.h +++ b/scene/3d/mesh_instance.h @@ -38,7 +38,7 @@ class MeshInstance : public GeometryInstance { OBJ_TYPE( MeshInstance, GeometryInstance ); - + Ref<Mesh> mesh; NodePath skeleton_path; @@ -68,7 +68,7 @@ public: void set_skeleton_path(const NodePath& p_skeleton); NodePath get_skeleton_path(); - + Node* create_trimesh_collision_node(); void create_trimesh_collision(); @@ -78,7 +78,7 @@ public: virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; - MeshInstance(); + MeshInstance(); ~MeshInstance(); }; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index ce28350be0..186f0d8e00 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -455,7 +455,7 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector _clip_path(path,apex_poly,portal_right,right_poly); - apex_point=portal_right; + apex_point=portal_right; p=right_poly; left_poly=p; apex_poly=p; diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 47662bcccb..3ac5d8ed7b 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -100,10 +100,10 @@ void Particles::set_amount(int p_amount) { VisualServer::get_singleton()->particles_set_amount(particles,p_amount); } int Particles::get_amount() const { - + return amount; } - + void Particles::set_emitting(bool p_emitting) { emitting=p_emitting; @@ -115,19 +115,19 @@ bool Particles::is_emitting() const { return emitting; } - + void Particles::set_visibility_aabb(const AABB& p_aabb) { visibility_aabb=p_aabb; VisualServer::get_singleton()->particles_set_visibility_aabb(particles,p_aabb); update_gizmo(); - + } AABB Particles::get_visibility_aabb() const { return visibility_aabb; } - + void Particles::set_emission_points(const DVector<Vector3>& p_points) { @@ -179,7 +179,7 @@ Vector3 Particles::get_gravity_normal() const { return gravity_normal; } - + void Particles::set_variable(Variable p_variable,float p_value) { ERR_FAIL_INDEX(p_variable,VAR_MAX); @@ -273,7 +273,7 @@ float Particles::get_emit_timeout() const { Ref<Material> Particles::get_material() const { return material; -} +} void Particles::set_height_from_velocity(bool p_enable) { @@ -507,11 +507,11 @@ Particles::Particles() { set_amount(64); set_emitting(true); set_visibility_aabb(AABB( Vector3(-4,-4,-4), Vector3(8,8,8) ) ); - + for (int i=0;i<VAR_MAX;i++) { set_randomness((Variable)i,0.0); } - + set_variable( VAR_LIFETIME, 5.0); set_variable( VAR_SPREAD, 0.2); set_variable( VAR_GRAVITY, 9.8); @@ -523,7 +523,7 @@ Particles::Particles() { set_variable( VAR_DAMPING, 0.0); set_variable( VAR_INITIAL_SIZE, 1.0); set_variable( VAR_FINAL_SIZE, 1.0); - set_variable( VAR_INITIAL_ANGLE, 0.0); + set_variable( VAR_INITIAL_ANGLE, 0.0); set_variable( VAR_HEIGHT, 1.0); set_variable( VAR_HEIGHT_SPEED_SCALE, 0.0); diff --git a/scene/3d/particles.h b/scene/3d/particles.h index b9cae332e2..42d27c41d7 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -63,7 +63,7 @@ private: OBJ_TYPE( Particles, GeometryInstance ); RID particles; - + int amount; bool emitting; float emit_timeout; @@ -71,14 +71,14 @@ private: Vector3 gravity_normal; Vector3 emission_half_extents; bool using_points; - float var[VAR_MAX]; - float var_random[VAR_MAX]; + float var[VAR_MAX]; + float var_random[VAR_MAX]; bool height_from_velocity; Vector3 emission_base_velocity; bool local_coordinates; - + struct ColorPhase { - + Color color; float pos; }; @@ -87,18 +87,18 @@ private: virtual RES _get_gizmo_geometry() const; int color_phase_count; - + ColorPhase color_phase[4]; - + Ref<Material> material; Timer* timer; void setup_timer(); -protected: - +protected: + static void _bind_methods(); - + public: @@ -107,13 +107,13 @@ public: void set_amount(int p_amount); int get_amount() const; - + void set_emitting(bool p_emitting); bool is_emitting() const; - + void set_visibility_aabb(const AABB& p_aabb); AABB get_visibility_aabb() const; - + void set_emission_half_extents(const Vector3& p_half_extents); Vector3 get_emission_half_extents() const; @@ -125,25 +125,25 @@ public: void set_gravity_normal(const Vector3& p_normal); Vector3 get_gravity_normal() const; - + void set_variable(Variable p_variable,float p_value); float get_variable(Variable p_variable) const; - + void set_randomness(Variable p_variable,float p_randomness); float get_randomness(Variable p_variable) const; void set_color_phases(int p_phases); int get_color_phases() const; - + void set_color_phase_pos(int p_phase, float p_pos); float get_color_phase_pos(int p_phase) const; - + void set_color_phase_color(int p_phase, const Color& p_color); Color get_color_phase_color(int p_phase) const; void set_height_from_velocity(bool p_enable); bool has_height_from_velocity() const; - + void set_material(const Ref<Material>& p_material); Ref<Material> get_material() const; @@ -156,7 +156,7 @@ public: void start_emitting(float p_time); - Particles(); + Particles(); ~Particles(); }; diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp index 84f94402d5..23bc64615d 100644 --- a/scene/3d/portal.cpp +++ b/scene/3d/portal.cpp @@ -40,7 +40,7 @@ bool Portal::_set(const StringName& p_name, const Variant& p_value) { ERR_FAIL_COND_V(src_coords_size%2,false); points.resize(src_coords_size/2); for (int i=0;i<points.size();i++) { - + points[i].x=src_coords[i*2+0]; points[i].y=src_coords[i*2+1]; set_shape(points); @@ -65,13 +65,13 @@ bool Portal::_get(const StringName& p_name,Variant &r_ret) const { Vector<Point2> points=get_shape(); DVector<float> dst_coords; dst_coords.resize(points.size()*2); - + for (int i=0;i<points.size();i++) { - + dst_coords.set(i*2+0,points[i].x); dst_coords.set(i*2+1,points[i].y); } - + r_ret= dst_coords; } else if (p_name=="enabled") { r_ret= is_enabled(); @@ -115,17 +115,17 @@ RES Portal::_get_gizmo_geometry() const { Vector2 center; for (int i=0;i<shape.size();i++) { - + int n=(i+1)%shape.size(); Vector<Vector3> points; surface_tool->add_vertex( Vector3( shape[i].x, shape[i].y,0 )); surface_tool->add_vertex( Vector3( shape[n].x, shape[n].y,0 )); center+=shape[i]; - + } if (shape.size()>0) { - + center/=shape.size(); Vector<Vector3> points; surface_tool->add_vertex( Vector3( center.x, center.y,0 )); @@ -139,7 +139,7 @@ RES Portal::_get_gizmo_geometry() const { AABB Portal::get_aabb() const { - return aabb; + return aabb; } DVector<Face3> Portal::get_faces(uint32_t p_usage_flags) const { @@ -149,28 +149,28 @@ DVector<Face3> Portal::get_faces(uint32_t p_usage_flags) const { Vector<Point2> shape = get_shape(); if (shape.size()==0) return DVector<Face3>(); - + Vector2 center; for (int i=0;i<shape.size();i++) { - + center+=shape[i]; - + } - + DVector<Face3> ret; center/=shape.size(); for (int i=0;i<shape.size();i++) { int n=(i+1)%shape.size(); - + Face3 f; f.vertex[0]=Vector3( center.x, center.y, 0 ); f.vertex[1]=Vector3( shape[i].x, shape[i].y, 0 ); f.vertex[2]=Vector3( shape[n].x, shape[n].y, 0 ); ret.push_back(f); } - + return ret; } diff --git a/scene/3d/portal.h b/scene/3d/portal.h index 388eac4dd3..149a56900f 100644 --- a/scene/3d/portal.h +++ b/scene/3d/portal.h @@ -45,14 +45,14 @@ class Portal : public VisualInstance { OBJ_TYPE(Portal, VisualInstance); - + RID portal; - + bool enabled; float disable_distance; Color disabled_color; float connect_range; - + AABB aabb; virtual RES _get_gizmo_geometry() const; @@ -62,9 +62,9 @@ protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static void _bind_methods(); - + public: virtual AABB get_aabb() const; diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp index e358da136b..9e6867d2a2 100644 --- a/scene/3d/room_instance.cpp +++ b/scene/3d/room_instance.cpp @@ -29,7 +29,7 @@ #include "room_instance.h" #include "servers/visual_server.h" - + #include "geometry.h" #include "globals.h" #include "scene/resources/surface_tool.h" diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 64133f67b5..d0b739e17f 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "skeleton.h" - + #include "message_queue.h" #include "scene/resources/surface_tool.h" @@ -40,19 +40,19 @@ bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { if (!path.begins_with("bones/")) return false; - + int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); if (which==bones.size() && what=="name") { - + add_bone(p_value); return true; } - + ERR_FAIL_INDEX_V( which, bones.size(), false ); - + if (what=="parent") set_bone_parent(which, p_value ); else if (what=="rest") @@ -63,11 +63,11 @@ bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { set_bone_pose(which, p_value); else if (what=="bound_childs") { Array children=p_value; - + bones[which].nodes_bound.clear(); - + for (int i=0;i<children.size();i++) { - + NodePath path=children[i]; ERR_CONTINUE( path.operator String()=="" ); Node *node = get_node(path); @@ -87,12 +87,12 @@ bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { if (!path.begins_with("bones/")) return false; - + int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); - + ERR_FAIL_INDEX_V( which, bones.size(), false ); - + if (what=="name") r_ret=get_bone_name(which); else if (what=="parent") @@ -105,29 +105,29 @@ bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { r_ret=get_bone_pose(which); else if (what=="bound_childs") { Array children; - + for (const List<uint32_t>::Element *E=bones[which].nodes_bound.front();E;E=E->next()) { - + Object *obj=ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); Node *node=obj->cast_to<Node>(); ERR_CONTINUE(!node); NodePath path=get_path_to(node); children.push_back(path); - + } - + r_ret=children; } else return false; - + return true; } void Skeleton::_get_property_list( List<PropertyInfo>* p_list ) const { for (int i=0;i<bones.size();i++) { - + String prep="bones/"+itos(i)+"/"; p_list->push_back( PropertyInfo( Variant::STRING, prep+"name" ) ); p_list->push_back( PropertyInfo( Variant::INT, prep+"parent" , PROPERTY_HINT_RANGE,"-1,"+itos(i-1)+",1") ); @@ -141,18 +141,18 @@ void Skeleton::_get_property_list( List<PropertyInfo>* p_list ) const { void Skeleton::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_WORLD: { - + if (dirty) { - + dirty=false; _make_dirty(); // property make it dirty } - + } break; case NOTIFICATION_EXIT_WORLD: { - + } break; case NOTIFICATION_UPDATE_SKELETON: { @@ -178,15 +178,15 @@ void Skeleton::_notification(int p_what) { Bone &b=bonesptr[i]; b.rest_global_inverse.affine_invert(); } - + rest_global_inverse_dirty=false; } - + for (int i=0;i<len;i++) { - + Bone &b=bonesptr[i]; - + if (b.disable_rest) { if (b.enabled) { @@ -241,7 +241,7 @@ void Skeleton::_notification(int p_what) { } } } - + vs->skeleton_bone_set_transform( skeleton, i, b.pose_global * b.rest_global_inverse ); for(List<uint32_t>::Element *E=b.nodes_bound.front();E;E=E->next()) { @@ -255,7 +255,7 @@ void Skeleton::_notification(int p_what) { } dirty=false; - } break; + } break; } } @@ -298,16 +298,16 @@ RID Skeleton::get_skeleton() const { void Skeleton::add_bone(const String& p_name) { ERR_FAIL_COND( p_name=="" || p_name.find(":")!=-1 || p_name.find("/")!=-1 ); - + for (int i=0;i<bones.size();i++) { - + ERR_FAIL_COND( bones[i].name=="p_name"); } Bone b; b.name=p_name; bones.push_back(b); - + rest_global_inverse_dirty=true; _make_dirty(); update_gizmo(); @@ -315,11 +315,11 @@ void Skeleton::add_bone(const String& p_name) { int Skeleton::find_bone(String p_name) const { for (int i=0;i<bones.size();i++) { - + if (bones[i].name==p_name) return i; } - + return -1; } String Skeleton::get_bone_name(int p_bone) const { @@ -338,7 +338,7 @@ void Skeleton::set_bone_parent(int p_bone, int p_parent) { ERR_FAIL_INDEX( p_bone, bones.size() ); ERR_FAIL_COND( p_parent!=-1 && (p_parent<0 || p_parent>=p_bone)); - + bones[p_bone].parent=p_parent; rest_global_inverse_dirty=true; _make_dirty(); @@ -378,14 +378,14 @@ bool Skeleton::is_bone_rest_disabled(int p_bone) const { int Skeleton::get_bone_parent(int p_bone) const { ERR_FAIL_INDEX_V( p_bone, bones.size(), -1 ); - + return bones[p_bone].parent; } void Skeleton::set_bone_rest(int p_bone, const Transform& p_rest) { ERR_FAIL_INDEX( p_bone, bones.size() ); - + bones[p_bone].rest=p_rest; rest_global_inverse_dirty=true; _make_dirty(); @@ -394,7 +394,7 @@ void Skeleton::set_bone_rest(int p_bone, const Transform& p_rest) { Transform Skeleton::get_bone_rest(int p_bone) const { ERR_FAIL_INDEX_V( p_bone, bones.size(), Transform() ); - + return bones[p_bone].rest; } @@ -402,7 +402,7 @@ Transform Skeleton::get_bone_rest(int p_bone) const { void Skeleton::set_bone_enabled(int p_bone, bool p_enabled) { ERR_FAIL_INDEX( p_bone, bones.size() ); - + bones[p_bone].enabled=p_enabled; rest_global_inverse_dirty=true; _make_dirty(); @@ -418,23 +418,23 @@ void Skeleton::bind_child_node_to_bone(int p_bone,Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX( p_bone, bones.size() ); - + uint32_t id=p_node->get_instance_ID(); - + for (List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) { - + if (E->get()==id) return; // already here } - + bones[p_bone].nodes_bound.push_back(id); - + } void Skeleton::unbind_child_node_from_bone(int p_bone,Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX( p_bone, bones.size() ); - + uint32_t id=p_node->get_instance_ID(); bones[p_bone].nodes_bound.erase(id); @@ -442,9 +442,9 @@ void Skeleton::unbind_child_node_from_bone(int p_bone,Node *p_node) { void Skeleton::get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const { ERR_FAIL_INDEX( p_bone, bones.size() ); - + for (const List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) { - + Object *obj=ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); p_bound->push_back(obj->cast_to<Node>()); @@ -465,7 +465,7 @@ void Skeleton::set_bone_pose(int p_bone, const Transform& p_pose) { ERR_FAIL_INDEX( p_bone, bones.size() ); ERR_FAIL_COND( !is_inside_tree() ); - + bones[p_bone].pose=p_pose; _make_dirty(); @@ -501,7 +501,7 @@ void Skeleton::_make_dirty() { if (dirty) return; - + if (!is_inside_tree()) { dirty=true; return; @@ -538,13 +538,13 @@ RES Skeleton::_get_gizmo_geometry() const { int len=bones.size(); for (int i=0;i<len;i++) { - + const Bone &b=bonesptr[i]; - + Transform t; if (b.parent<0) continue; - + Vector3 v1=(bonesptr[b.parent].pose_global * bonesptr[b.parent].rest_global_inverse).xform(bonesptr[b.parent].rest_global_inverse.affine_inverse().origin); Vector3 v2=(b.pose_global * b.rest_global_inverse).xform(b.rest_global_inverse.affine_inverse().origin); @@ -576,10 +576,10 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_bone","name"),&Skeleton::add_bone); ObjectTypeDB::bind_method(_MD("find_bone","name"),&Skeleton::find_bone); ObjectTypeDB::bind_method(_MD("get_bone_name","bone_idx"),&Skeleton::get_bone_name); - + ObjectTypeDB::bind_method(_MD("get_bone_parent","bone_idx"),&Skeleton::get_bone_parent); ObjectTypeDB::bind_method(_MD("set_bone_parent","bone_idx","parent_idx"),&Skeleton::set_bone_parent); - + ObjectTypeDB::bind_method(_MD("get_bone_count"),&Skeleton::get_bone_count); ObjectTypeDB::bind_method(_MD("unparent_bone_and_rest","bone_idx"),&Skeleton::unparent_bone_and_rest); @@ -593,9 +593,9 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("bind_child_node_to_bone","bone_idx","node:Node"),&Skeleton::bind_child_node_to_bone); ObjectTypeDB::bind_method(_MD("unbind_child_node_from_bone","bone_idx","node:Node"),&Skeleton::unbind_child_node_from_bone); ObjectTypeDB::bind_method(_MD("get_bound_child_nodes_to_bone","bone_idx"),&Skeleton::_get_bound_child_nodes_to_bone); - + ObjectTypeDB::bind_method(_MD("clear_bones"),&Skeleton::clear_bones); - + ObjectTypeDB::bind_method(_MD("get_bone_pose","bone_idx"),&Skeleton::get_bone_pose); ObjectTypeDB::bind_method(_MD("set_bone_pose","bone_idx","pose"),&Skeleton::set_bone_pose); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index 033f212a58..bfdb1d1499 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -49,36 +49,36 @@ class Skeleton : public Spatial { bool disable_rest; Transform rest; Transform rest_global_inverse; - + Transform pose; Transform pose_global; bool custom_pose_enable; Transform custom_pose; - + List<uint32_t> nodes_bound; - + Bone() { parent=-1; enabled=true; custom_pose_enable=false; disable_rest=false; } }; bool rest_global_inverse_dirty; Vector<Bone> bones; - + RID skeleton; - + void _make_dirty(); bool dirty; - + //bind helpers Array _get_bound_child_nodes_to_bone(int p_bone) const { - + Array bound; List<Node*> childs; get_bound_child_nodes_to_bone(p_bone,&childs); - + for (int i=0;i<childs.size();i++) { - + bound.push_back( childs[i] ); } return bound; @@ -93,11 +93,11 @@ protected: void _get_property_list( List<PropertyInfo>* p_list ) const; void _notification(int p_what); static void _bind_methods(); - + public: enum { - + NOTIFICATION_UPDATE_SKELETON=50 }; @@ -108,7 +108,7 @@ public: void add_bone(const String&p_name); int find_bone(String p_name) const; String get_bone_name(int p_bone) const; - + void set_bone_parent(int p_bone, int p_parent); int get_bone_parent(int p_bone) const; @@ -118,7 +118,7 @@ public: bool is_bone_rest_disabled(int p_bone) const; int get_bone_count() const; - + void set_bone_rest(int p_bone, const Transform& p_rest); Transform get_bone_rest(int p_bone) const; Transform get_bone_transform(int p_bone) const; @@ -128,15 +128,15 @@ public: void set_bone_enabled(int p_bone, bool p_enabled); bool is_bone_enabled(int p_bone) const; - + void bind_child_node_to_bone(int p_bone,Node *p_node); void unbind_child_node_from_bone(int p_bone,Node *p_node); void get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const; - + void clear_bones(); - + // posing api - + void set_bone_pose(int p_bone, const Transform& p_pose); Transform get_bone_pose(int p_bone) const; @@ -144,8 +144,8 @@ public: Transform get_bone_custom_pose(int p_bone) const; void localize_rests(); // used for loaders and tools - - Skeleton(); + + Skeleton(); ~Skeleton(); }; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 0c1e1e2d1c..c2d318e8a7 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "spatial.h" - + #include "scene/main/viewport.h" #include "message_queue.h" #include "scene/scene_string_names.h" @@ -99,14 +99,14 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { // return; //already dirty data.children_lock++; - + for (List<Spatial*>::Element *E=data.children.front();E;E=E->next()) { - + if (E->get()->data.toplevel_active) continue; //don't propagate to a toplevel E->get()->_propagate_transform_changed(p_origin); } - + if (!data.ignore_notification && !xform_change.in_list()) { @@ -211,14 +211,14 @@ void Spatial::_notification(int p_what) { case NOTIFICATION_TRANSFORM_CHANGED: { - + #ifdef TOOLS_ENABLED if (data.gizmo.is_valid()) { data.gizmo->transform(); } #endif } break; - + default: {} } } @@ -257,7 +257,7 @@ Transform Spatial::get_transform() const { _update_local_transform(); } - + return data.local_transform; } Transform Spatial::get_global_transform() const { @@ -272,16 +272,16 @@ Transform Spatial::get_global_transform() const { } if (data.parent && !data.toplevel_active) { - + data.global_transform=data.parent->get_global_transform() * data.local_transform; } else { - + data.global_transform=data.local_transform; } - + data.dirty&=~DIRTY_GLOBAL; } - + return data.global_transform; } #if 0 @@ -290,7 +290,7 @@ void Spatial::add_child_notify(Node *p_child) { Spatial *s=p_child->cast_to<Spatial>(); if (!s) return; - + ERR_FAIL_COND(data.children_lock>0); s->data.dirty=DIRTY_GLOBAL; // don't allow global transform to be valid @@ -305,12 +305,12 @@ void Spatial::remove_child_notify(Node *p_child) { Spatial *s=p_child->cast_to<Spatial>(); if (!s) return; - + ERR_FAIL_COND(data.children_lock>0); - + if (s->data.C) data.children.erase(s->data.C); - s->data.parent=NULL; + s->data.parent=NULL; s->data.C=NULL; */ } @@ -595,11 +595,11 @@ bool Spatial::is_hidden() const{ } void Spatial::set_hidden(bool p_hidden) { - + if (data.visible != p_hidden) { return; } - + _set_visible_(!p_hidden); } diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 23f1c6d103..50123b2d81 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -57,7 +57,7 @@ class Spatial : public Node { OBJ_TYPE( Spatial, Node ); OBJ_CATEGORY("3D"); - + enum TransformDirty { DIRTY_NONE=0, DIRTY_VECTORS=1, @@ -68,7 +68,7 @@ class Spatial : public Node { mutable SelfList<Node> xform_change; struct Data { - + mutable Transform global_transform; @@ -84,12 +84,12 @@ class Spatial : public Node { bool toplevel_active; bool toplevel; bool inside_world; - + int children_lock; Spatial *parent; List<Spatial*> children; List<Spatial*>::Element *C; - + bool ignore_notification; bool notify_local_transform; @@ -130,7 +130,7 @@ protected: public: enum { - + NOTIFICATION_TRANSFORM_CHANGED=SceneTree::NOTIFICATION_TRANSFORM_CHANGED, NOTIFICATION_ENTER_WORLD=41, NOTIFICATION_EXIT_WORLD=42, @@ -153,7 +153,7 @@ public: void set_transform(const Transform& p_transform); void set_global_transform(const Transform& p_transform); - + Transform get_transform() const; Transform get_global_transform() const; @@ -198,7 +198,7 @@ public: Transform get_import_transform() const; #endif - Spatial(); + Spatial(); ~Spatial(); }; diff --git a/scene/3d/spatial_sample_player.h b/scene/3d/spatial_sample_player.h index 9b3220458e..037cdc906a 100644 --- a/scene/3d/spatial_sample_player.h +++ b/scene/3d/spatial_sample_player.h @@ -47,7 +47,7 @@ public: typedef int VoiceID; -private: +private: Ref<SampleLibrary> library; int polyphony; diff --git a/scene/3d/test_cube.h b/scene/3d/test_cube.h index 21f2b3c794..332276ab89 100644 --- a/scene/3d/test_cube.h +++ b/scene/3d/test_cube.h @@ -42,14 +42,14 @@ class TestCube : public GeometryInstance { OBJ_TYPE( TestCube, GeometryInstance ); RID instance; - + public: virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; - TestCube(); + TestCube(); ~TestCube(); }; diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h index 2b8292261b..e286d5fa88 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance.h @@ -65,7 +65,7 @@ public: RID get_instance() const; virtual AABB get_aabb() const=0; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const=0; - + virtual AABB get_transformed_aabb() const; // helper void set_base(const RID& p_base); @@ -74,7 +74,7 @@ public: uint32_t get_layer_mask() const; - VisualInstance(); + VisualInstance(); ~VisualInstance(); }; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 0bc54b3d43..32958112e5 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "animation_player.h" - + #include "message_queue.h" #include "scene/scene_string_names.h" @@ -50,10 +50,10 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { else play(which); } else if (name.begins_with("anims/")) { - + String which=name.get_slicec('/',1); - + add_animation(which,p_value); } else if (name.begins_with("next/")) { @@ -62,7 +62,7 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { animation_set_next(which,p_value); } else if (p_name==SceneStringNames::get_singleton()->blend_times) { - + Array array=p_value; int len = array.size(); ERR_FAIL_COND_V(len%3,false); @@ -79,7 +79,7 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { } else if (p_name==SceneStringNames::get_singleton()->autoplay) { autoplay=p_value; - + } else return false; @@ -92,7 +92,7 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; if (name=="playback/speed") { //bw compatibility - + r_ret=speed_scale; } else if (name=="playback/active") { @@ -105,9 +105,9 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { r_ret="[stop]"; } else if (name.begins_with("anims/")) { - + String which=name.get_slicec('/',1); - + r_ret= get_animation(which).get_ref_ptr(); } else if (name.begins_with("next/")) { @@ -117,7 +117,7 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { } else if (name=="blend_times") { - + Array array; array.resize(blend_times.size()*3); @@ -195,7 +195,7 @@ void AnimationPlayer::advance(float p_time) { void AnimationPlayer::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_TREE: { if (!processing) { @@ -222,7 +222,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (animation_process_mode==ANIMATION_PROCESS_IDLE) break; @@ -230,7 +230,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_TREE: { - + //stop_all(); clear_caches(); } break; @@ -240,15 +240,15 @@ void AnimationPlayer::_notification(int p_what) { void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { Node *parent = get_node(root); - + ERR_FAIL_COND(!parent); Animation *a=p_anim->animation.operator->(); - + p_anim->node_cache.resize( a->get_track_count() ); - + for (int i=0;i<a->get_track_count();i++) { - + p_anim->node_cache[i]=NULL; RES resource; Node *child = parent->get_node_and_resource(a->track_get_path(i),resource); @@ -267,7 +267,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { continue; } } - + { if (!child->is_connected("exit_tree",this,"_node_removed")) child->connect("exit_tree",this,"_node_removed",make_binds(child),CONNECT_ONESHOT); @@ -277,15 +277,15 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { key.id=id; key.bone_idx=bone_idx; - + if (node_cache_map.has(key)) { - + p_anim->node_cache[i]=&node_cache_map[key]; } else { - + node_cache_map[key]=TrackNodeCache(); - + p_anim->node_cache[i]=&node_cache_map[key]; p_anim->node_cache[i]->path=a->track_get_path(i); p_anim->node_cache[i]->node=child; @@ -293,7 +293,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { p_anim->node_cache[i]->node_2d=child->cast_to<Node2D>(); if (a->track_get_type(i)==Animation::TYPE_TRANSFORM) { // special cases and caches for transform tracks - + // cache spatial p_anim->node_cache[i]->spatial=child->cast_to<Spatial>(); // cache skeleton @@ -302,7 +302,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { StringName bone_name=a->track_get_path(i).get_property(); if (bone_name.operator String()!="") { - + p_anim->node_cache[i]->bone_idx=p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx<0) { // broken track (nonexistent bone) @@ -314,9 +314,9 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { } } else { // no property, just use spatialnode - p_anim->node_cache[i]->skeleton=NULL; + p_anim->node_cache[i]->skeleton=NULL; } - + } } } @@ -356,29 +356,29 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p ERR_FAIL_COND( p_anim->node_cache.size() != p_anim->animation->get_track_count() ); - + Animation *a=p_anim->animation.operator->(); bool can_call = is_inside_tree() && !get_tree()->is_editor_hint(); - + for (int i=0;i<a->get_track_count();i++) { - + TrackNodeCache *nc=p_anim->node_cache[i]; - + if (!nc) // no node cache for this track, skip it continue; - + if (a->track_get_key_count(i)==0) continue; // do nothing if track is empty switch(a->track_get_type(i)) { - + case Animation::TYPE_TRANSFORM: { - + if (!nc->spatial) continue; - - + + Vector3 loc; Quat rot; Vector3 scale; @@ -406,10 +406,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p nc->scale_accum=nc->scale_accum.linear_interpolate(scale,p_interp); } - + } break; case Animation::TYPE_VALUE: { - + if (!nc->node) continue; @@ -488,21 +488,21 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p } } - + } break; case Animation::TYPE_METHOD: { - + if (!nc->node) continue; if (p_delta==0) continue; if (!p_allow_discrete) break; - + List<int> indices; a->method_track_get_key_indices(i,p_time,p_delta,&indices); - + for(List<int>::Element *E=indices.front();E;E=E->next()) { StringName method=a->method_track_get_name(i,E->get()); @@ -523,8 +523,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p ); } } - - + + } break; } } @@ -535,17 +535,17 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo float delta=p_delta*speed_scale*cd.speed_scale; bool backwards=delta<0; float next_pos=cd.pos+delta; - + float len=cd.from->animation->get_length(); bool loop=cd.from->animation->has_loop(); - + if (!loop) { - + if (next_pos<0) next_pos=0; else if (next_pos>len) next_pos=len; - + // fix delta delta=next_pos-cd.pos; @@ -564,39 +564,39 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo } } else { - + next_pos=Math::fposmod(next_pos,len); } - + cd.pos=next_pos; _animation_process_animation(cd.from,cd.pos,delta,p_blend,&cd == &playback.current); - + } void AnimationPlayer::_animation_process2(float p_delta) { Playback &c=playback; - + float prev_blend=1.0; accum_pass++; - + int pop_count=1; int pop=0; // if >0, then amount of elements to pop from the back for (List<Blend>::Element *E=c.blend.back();E;E=E->prev(),pop_count++) { - + Blend& b=E->get(); _animation_process_data(b.data,p_delta,prev_blend); - + prev_blend=1.0-b.blend_left/b.blend_time; - + b.blend_left-=Math::absf(speed_scale*p_delta); - + if (b.blend_left<0) { pop=pop_count; @@ -608,22 +608,22 @@ void AnimationPlayer::_animation_process2(float p_delta) { c.blend.pop_back(); } - + _animation_process_data(c.current,p_delta,prev_blend); - + } void AnimationPlayer::_animation_update_transforms() { for (int i=0;i<cache_update_size;i++) { - + TrackNodeCache *nc=cache_update[i]; ERR_CONTINUE( nc->accum_pass!=accum_pass ); if (nc->spatial) { - + Transform t; t.origin=nc->loc_accum; t.basis=nc->rot_accum; @@ -638,9 +638,9 @@ void AnimationPlayer::_animation_update_transforms() { nc->spatial->set_transform(t); } } - + } - + cache_update_size=0; for (int i=0;i<cache_update_prop_size;i++) { @@ -712,7 +712,7 @@ void AnimationPlayer::_animation_process(float p_delta) { // bool any_active=false; - + if (playback.current.from) { end_notify=false; @@ -750,7 +750,7 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati #endif ERR_FAIL_COND_V( p_animation.is_null() , ERR_INVALID_PARAMETER ); - + //print_line("Add anim: "+String(p_name)+" name: "+p_animation->get_name()); if (animation_set.has(p_name)) { @@ -759,12 +759,12 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati animation_set[p_name].animation=p_animation; clear_caches(); } else { - + AnimationData ad; ad.animation=p_animation; ad.name=p_name; animation_set[p_name]=ad; - } + } _ref_anim(p_animation); _change_notify(); @@ -774,10 +774,10 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati void AnimationPlayer::remove_animation(const StringName& p_name) { ERR_FAIL_COND(!animation_set.has(p_name) ); - + stop_all(); _unref_anim(animation_set[p_name].animation); - animation_set.erase(p_name); + animation_set.erase(p_name); clear_caches(); _change_notify(); @@ -876,7 +876,7 @@ Ref<Animation> AnimationPlayer::get_animation(const StringName& p_name) const { ERR_FAIL_COND_V( !animation_set.has(p_name), Ref<Animation>() ); const AnimationData& data = animation_set[p_name]; - + return data.animation; } @@ -950,7 +950,7 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float //printf("animation is %ls\n", String(p_name).c_str()); //ERR_FAIL_COND(!is_inside_scene()); StringName name=p_name; - + if (String(name)=="") name=playback.assigned; @@ -958,11 +958,11 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float ERR_EXPLAIN("Animation not found: "+name); ERR_FAIL(); } - + Playback &c=playback; if (c.current.from) { - + float blend_time=0; // find if it can blend BlendKey bk; @@ -972,37 +972,37 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float if (p_custom_blend>=0) { blend_time=p_custom_blend; } else if (blend_times.has(bk)) { - + blend_time=blend_times[bk]; } else { - + bk.from="*"; if (blend_times.has(bk)) { blend_time=blend_times[bk]; } else { - + bk.from=c.current.from->name; bk.to="*"; - + if (blend_times.has(bk)) { - + blend_time=blend_times[bk]; } } } - + if (p_custom_blend<0 && blend_time==0 && default_blend_time) blend_time=default_blend_time; if (blend_time>0) { - + Blend b; b.data=c.current; b.blend_time=b.blend_left=blend_time; - c.blend.push_back(b); + c.blend.push_back(b); } } - + c.current.from=&animation_set[name]; c.current.pos=p_from_end ? c.current.from->animation->get_length() : 0; c.current.speed_scale=p_custom_scale; @@ -1059,7 +1059,7 @@ String AnimationPlayer::get_current_animation() const { } void AnimationPlayer::stop(bool p_reset) { - + Playback &c=playback; c.blend.clear(); if (p_reset) { @@ -1073,15 +1073,15 @@ void AnimationPlayer::stop(bool p_reset) { void AnimationPlayer::stop_all() { stop(); - + _set_process(false); // always process when starting an animation - + } void AnimationPlayer::set_speed(float p_speed) { speed_scale=p_speed; - + } float AnimationPlayer::get_speed() const { @@ -1151,7 +1151,7 @@ void AnimationPlayer::_node_removed(Node *p_node) { void AnimationPlayer::clear_caches() { - + node_cache_map.clear(); for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) { @@ -1296,7 +1296,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_animation","name"),&AnimationPlayer::has_animation); ObjectTypeDB::bind_method(_MD("get_animation:Animation","name"),&AnimationPlayer::get_animation); ObjectTypeDB::bind_method(_MD("get_animation_list"),&AnimationPlayer::_get_animation_list); - + ObjectTypeDB::bind_method(_MD("set_blend_time","anim_from","anim_to","sec"),&AnimationPlayer::set_blend_time); ObjectTypeDB::bind_method(_MD("get_blend_time","anim_from","anim_to"),&AnimationPlayer::get_blend_time); @@ -1315,7 +1315,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_active","active"),&AnimationPlayer::set_active); ObjectTypeDB::bind_method(_MD("is_active"),&AnimationPlayer::is_active); - + ObjectTypeDB::bind_method(_MD("set_speed","speed"),&AnimationPlayer::set_speed); ObjectTypeDB::bind_method(_MD("get_speed"),&AnimationPlayer::get_speed); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 853526c80a..2ae3a0756c 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -53,7 +53,7 @@ public: private: enum { - + NODE_CACHE_UPDATE_MAX=1024, BLEND_FROM_MAX=3 }; @@ -96,23 +96,23 @@ private: Map<StringName,PropertyAnim> property_anim; - + TrackNodeCache() { skeleton=NULL; spatial=NULL; node=NULL; accum_pass=0; bone_idx=-1; node_2d=NULL; } - + }; struct TrackNodeCacheKey { - + uint32_t id; int bone_idx; inline bool operator<(const TrackNodeCacheKey& p_right) const { - + if (id<p_right.id) return true; else if (id>p_right.id) return false; - else + else return bone_idx<p_right.bone_idx; } }; @@ -135,7 +135,7 @@ private: StringName next; Vector<TrackNodeCache*> node_cache; Ref<Animation> animation; - + }; Map<StringName, AnimationData> animation_set; @@ -148,41 +148,41 @@ private: Map<BlendKey, float > blend_times; - - + + struct PlaybackData { - + AnimationData* from; float pos; float speed_scale; PlaybackData() { - + pos=0; speed_scale=1.0; - from=NULL; + from=NULL; } }; - + struct Blend { - + PlaybackData data; - + float blend_time; float blend_left; - + Blend() { - + blend_left=0; blend_time=0; } }; - + struct Playback { - - List<Blend> blend; + + List<Blend> blend; PlaybackData current; StringName assigned; } playback; @@ -197,25 +197,25 @@ private: bool active; NodePath root; - + void _animation_process_animation(AnimationData* p_anim,float p_time, float p_delta,float p_interp, bool p_allow_discrete=true); - - void _generate_node_caches(AnimationData* p_anim); + + void _generate_node_caches(AnimationData* p_anim); void _animation_process_data(PlaybackData &cd,float p_delta,float p_blend); void _animation_process2(float p_delta); void _animation_update_transforms(); void _animation_process(float p_delta); - + void _node_removed(Node *p_node); - + // bind helpers DVector<String> _get_animation_list() const { - + List<StringName> animations; get_animation_list(&animations); DVector<String> ret; while(animations.size()) { - + ret.push_back( animations.front()->get()); animations.pop_front(); } @@ -236,9 +236,9 @@ protected: bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; void _notification(int p_what); - - static void _bind_methods(); - + + static void _bind_methods(); + public: StringName find_animation(const Ref<Animation>& p_animation) const; @@ -249,7 +249,7 @@ public: bool has_animation(const StringName& p_name) const; Ref<Animation> get_animation(const StringName& p_name) const; void get_animation_list( List<StringName> * p_animations) const; - + void set_blend_time(const StringName& p_animation1, const StringName& p_animation2, float p_time); float get_blend_time( const StringName& p_animation1, const StringName& p_animation2) const; @@ -258,7 +258,7 @@ public: void set_default_blend_time(float p_default); float get_default_blend_time() const; - + void play(const StringName& p_name=StringName(),float p_custom_blend=-1,float p_custom_scale=1.0,bool p_from_end=false); void play_backwards(const StringName& p_name=StringName(),float p_custom_blend=-1); void queue(const StringName& p_name); @@ -271,7 +271,7 @@ public: void set_active(bool p_active); bool is_active() const; bool is_valid() const; - + void set_speed(float p_speed); float get_speed() const; @@ -295,8 +295,8 @@ public: void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; - - AnimationPlayer(); + + AnimationPlayer(); ~AnimationPlayer(); }; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index a66a2849ae..cc9e6c71e3 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -420,7 +420,7 @@ void AnimationTreePlayer::_notification(int p_what) { _process_animation( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (animation_process_mode==ANIMATION_PROCESS_IDLE) break; @@ -507,7 +507,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (!(*r_prev_anim)) active_list=an; - else + else (*r_prev_anim)->next=an; an->next=NULL; @@ -1831,7 +1831,7 @@ void AnimationTreePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("reset"),&AnimationTreePlayer::reset); - ObjectTypeDB::bind_method(_MD("recompute_caches"),&AnimationTreePlayer::recompute_caches); + ObjectTypeDB::bind_method(_MD("recompute_caches"),&AnimationTreePlayer::recompute_caches); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_animation_process_mode"), _SCS("get_animation_process_mode")); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 31f30dd1d9..7edd57603b 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -126,7 +126,7 @@ bool Tween::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; if (name=="playback/speed") { //bw compatibility - + r_ret=speed_scale; } else if (name=="playback/active") { @@ -149,7 +149,7 @@ void Tween::_get_property_list(List<PropertyInfo> *p_list) const { void Tween::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_TREE: { if (!processing) { @@ -170,7 +170,7 @@ void Tween::_notification(int p_what) { _tween_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (tween_process_mode==TWEEN_PROCESS_IDLE) break; @@ -178,7 +178,7 @@ void Tween::_notification(int p_what) { _tween_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_TREE: { - + stop_all(); } break; } @@ -1183,7 +1183,7 @@ bool Tween::interpolate_callback(Object *p_object args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; data.args = args; @@ -1247,7 +1247,7 @@ bool Tween::interpolate_deferred_callback(Object *p_object args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; data.args = args; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index f06ca1e9e7..d0455cdc71 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -57,7 +57,7 @@ public: TRANS_COUNT, }; - + enum EaseType { EASE_IN, EASE_OUT, @@ -206,7 +206,7 @@ public: , String p_callback , VARIANT_ARG_DECLARE ); - + bool interpolate_deferred_callback(Object *p_object , real_t p_times_in_sec , String p_callback diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 698dbce2b5..3bcc60b86a 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -37,19 +37,19 @@ void BaseButton::_input_event(InputEvent p_event) { if (status.disabled) // no interaction with disabled button return; - + switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b=p_event.mouse_button; - + if ( status.disabled || b.button_index!=1 ) return; if (status.pressing_button) break; - + if (status.click_on_press) { if (b.pressed) { @@ -96,13 +96,13 @@ void BaseButton::_input_event(InputEvent p_event) { } if (b.pressed) { - + status.press_attempt=true; status.pressing_inside=true; - + } else { - - + + if (status.press_attempt &&status.pressing_inside) { if (!toggle_mode) { //mouse press attempt @@ -114,14 +114,14 @@ void BaseButton::_input_event(InputEvent p_event) { } emit_signal("pressed"); - + } else { status.pressed=!status.pressed; - + pressed(); emit_signal("pressed"); - + toggled(status.pressed); emit_signal("toggled",status.pressed); if (get_script_instance()) { @@ -134,10 +134,10 @@ void BaseButton::_input_event(InputEvent p_event) { } status.press_attempt=false; - + } - - update(); + + update(); } break; case InputEvent::MOUSE_MOTION: { @@ -151,7 +151,7 @@ void BaseButton::_input_event(InputEvent p_event) { case InputEvent::ACTION: case InputEvent::JOYSTICK_BUTTON: case InputEvent::KEY: { - + if (p_event.is_echo()) { break; @@ -166,7 +166,7 @@ void BaseButton::_input_event(InputEvent p_event) { } if (p_event.is_action("ui_accept")) { - + if (p_event.is_pressed()) { status.pressing_button++; @@ -183,18 +183,18 @@ void BaseButton::_input_event(InputEvent p_event) { status.press_attempt=false; status.pressing_inside=false; - + if (!toggle_mode) { //mouse press attempt - + pressed(); - emit_signal("pressed"); + emit_signal("pressed"); } else { - + status.pressed=!status.pressed; - + pressed(); emit_signal("pressed"); - + toggled(status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); @@ -202,29 +202,29 @@ void BaseButton::_input_event(InputEvent p_event) { emit_signal("toggled",status.pressed); } } - + accept_event(); - update(); + update(); } - } - + } + } } void BaseButton::_notification(int p_what) { - + if (p_what==NOTIFICATION_MOUSE_ENTER) { - + status.hovering=true; update(); } - + if (p_what==NOTIFICATION_MOUSE_EXIT) { status.hovering=false; update(); - } + } if (p_what==NOTIFICATION_FOCUS_EXIT) { if (status.pressing_button && status.press_attempt) { @@ -282,7 +282,7 @@ void BaseButton::toggled(bool p_pressed) { void BaseButton::set_disabled(bool p_disabled) { - + status.disabled = p_disabled; update(); _change_notify("disabled"); @@ -298,7 +298,7 @@ bool BaseButton::is_disabled() const { } void BaseButton::set_pressed(bool p_pressed) { - + if (!toggle_mode) return; if (status.pressed==p_pressed) @@ -309,12 +309,12 @@ void BaseButton::set_pressed(bool p_pressed) { } bool BaseButton::is_pressing() const{ - + return status.press_attempt; } bool BaseButton::is_pressed() const { - + return toggle_mode?status.pressed:status.press_attempt; } @@ -324,11 +324,11 @@ bool BaseButton::is_hovered() const { } BaseButton::DrawMode BaseButton::get_draw_mode() const { - + if (status.disabled) { return DRAW_DISABLED; }; - + //print_line("press attempt: "+itos(status.press_attempt)+" hover: "+itos(status.hovering)+" pressed: "+itos(status.pressed)); if (status.press_attempt==false && status.hovering && !status.pressed) { @@ -336,34 +336,34 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const { return DRAW_HOVER; } else { /* determine if pressed or not */ - + bool pressing; if (status.press_attempt) { - + pressing=status.pressing_inside; if (status.pressed) pressing=!pressing; } else { - + pressing=status.pressed; } - - if (pressing) + + if (pressing) return DRAW_PRESSED; - else + else return DRAW_NORMAL; - } + } return DRAW_NORMAL; } void BaseButton::set_toggle_mode(bool p_on) { - + toggle_mode=p_on; } bool BaseButton::is_toggle_mode() const { - + return toggle_mode; } @@ -414,7 +414,7 @@ void BaseButton::_bind_methods() { } BaseButton::BaseButton() { - + toggle_mode=false; status.pressed=false; status.press_attempt=false; @@ -426,7 +426,7 @@ BaseButton::BaseButton() { set_focus_mode( FOCUS_ALL ); group=NULL; - + } BaseButton::~BaseButton() diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 83c66326c5..9a5213d971 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -42,9 +42,9 @@ class BaseButton : public Control { OBJ_TYPE( BaseButton, Control ); bool toggle_mode; - + struct Status { - + bool pressed; bool hovering; bool press_attempt; @@ -55,15 +55,15 @@ class BaseButton : public Control { int pressing_button; } status; - + ButtonGroup *group; - + protected: - + virtual void pressed(); virtual void toggled(bool p_pressed); static void _bind_methods(); @@ -82,7 +82,7 @@ public: DrawMode get_draw_mode() const; /* Signals */ - + bool is_pressed() const; ///< return wether button is pressed (toggled in) bool is_pressing() const; ///< return wether button is pressed (toggled in) bool is_hovered() const; @@ -90,7 +90,7 @@ public: void set_pressed(bool p_pressed); ///only works in toggle mode void set_toggle_mode(bool p_on); bool is_toggle_mode() const; - + void set_disabled(bool p_disabled); bool is_disabled() const; @@ -98,7 +98,7 @@ public: bool get_click_on_press() const; - BaseButton(); + BaseButton(); ~BaseButton(); }; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index b9ce46d738..0f3f762ba1 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -45,7 +45,7 @@ Size2 Button::get_minimum_size() const { _icon=icon; if (!_icon.is_null()) { - + minsize.height=MAX( minsize.height, _icon->get_height() ); minsize.width+=_icon->get_width(); if (text!="") @@ -53,48 +53,48 @@ Size2 Button::get_minimum_size() const { } return get_stylebox("normal" )->get_minimum_size() + minsize; - + } void Button::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); Size2 size=get_size(); Color color; //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); - + switch( get_draw_mode() ) { - + case DRAW_NORMAL: { - + if (!flat) get_stylebox("normal" )->draw( ci, Rect2(Point2(0,0), size) ); - color=get_color("font_color"); + color=get_color("font_color"); } break; case DRAW_PRESSED: { - + get_stylebox("pressed" )->draw( ci, Rect2(Point2(0,0), size) ); if (has_color("font_color_pressed")) color=get_color("font_color_pressed"); else color=get_color("font_color"); - + } break; case DRAW_HOVER: { - + get_stylebox("hover" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_hover"); - + } break; case DRAW_DISABLED: { get_stylebox("disabled" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_disabled"); - + } break; } @@ -139,12 +139,12 @@ void Button::_notification(int p_what) { if (!_icon.is_null()) { int valign = size.height-style->get_minimum_size().y; - + _icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } - + } } @@ -236,7 +236,7 @@ void Button::_bind_methods() { } Button::Button(const String &p_text) { - + flat=false; clip_text=false; set_stop_mouse(true); diff --git a/scene/gui/button.h b/scene/gui/button.h index bd244f5087..8a17a164a0 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Button : public BaseButton { - + OBJ_TYPE( Button, BaseButton ); public: @@ -49,25 +49,25 @@ private: bool flat; String text; - Ref<Texture> icon; + Ref<Texture> icon; bool clip_text; TextAlign align; - -protected: + +protected: virtual Size2 get_minimum_size() const; void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: -// +// void set_text(const String& p_text); String get_text() const; - + void set_icon(const Ref<Texture>& p_icon); Ref<Texture> get_icon() const; - + void set_flat(bool p_flat); bool is_flat() const; diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp index 9e3476899f..de77b83403 100644 --- a/scene/gui/button_array.cpp +++ b/scene/gui/button_array.cpp @@ -171,9 +171,9 @@ void ButtonArray::_notification(int p_what) { case NOTIFICATION_READY:{ MethodInfo mi; mi.name="mouse_sub_enter"; - + add_user_signal(mi); - + }break; case NOTIFICATION_DRAW: { diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h index 39661eaabd..c4b9b0c9e3 100644 --- a/scene/gui/button_array.h +++ b/scene/gui/button_array.h @@ -69,7 +69,7 @@ protected: void _notification(int p_what); static void _bind_methods(); - + public: void _input_event(const InputEvent& p_event); diff --git a/scene/gui/button_group.h b/scene/gui/button_group.h index 38c61991b7..4afba22228 100644 --- a/scene/gui/button_group.h +++ b/scene/gui/button_group.h @@ -55,7 +55,7 @@ friend class BaseButton; public: void get_button_list(List<BaseButton*> *p_buttons) const; - BaseButton *get_pressed_button() const; + BaseButton *get_pressed_button() const; BaseButton *get_focused_button() const; void set_pressed_button(BaseButton *p_button); int get_pressed_button_index() const; diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index ecaea251a5..f8c0c6b208 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -33,9 +33,9 @@ void CheckButton::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); Ref<Texture> on=Control::get_icon("on"); @@ -50,17 +50,17 @@ void CheckButton::_notification(int p_what) { else off->draw(ci,ofs); - + } } CheckButton::CheckButton() { - + set_toggle_mode(true); set_text_align(ALIGN_LEFT); - + } diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h index 022ade2193..a1ed4c1896 100644 --- a/scene/gui/check_button.h +++ b/scene/gui/check_button.h @@ -35,18 +35,18 @@ @author Juan Linietsky <reduzio@gmail.com> */ class CheckButton : public Button { - + OBJ_TYPE( CheckButton, Button ); - - -protected: + + +protected: void _notification(int p_what); public: - - CheckButton(); + + CheckButton(); ~CheckButton(); - + }; #endif diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index f1b910d23f..f8f8b1f6d1 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -246,7 +246,7 @@ void ColorPicker::set_raw_mode(bool p_enabled) { raw_mode_enabled=p_enabled; if (btn_mode->is_pressed()!=p_enabled) btn_mode->set_pressed(p_enabled); - + if (!is_inside_tree()) return; @@ -322,7 +322,7 @@ void ColorPicker::_w_input(const InputEvent &ev) { if (bev.pressed) { changing_color = true; h=1-((float)bev.y)/256.0; - + } else { changing_color = false; } @@ -502,7 +502,7 @@ ColorPicker::ColorPicker() : args.push_back(1); args.push_back(c); c->connect("draw",this,"_hsv_draw",args); - + hb_edit->add_child(uv_edit); hb_edit->add_child(memnew( VSeparator )); hb_edit->add_child(w_edit); @@ -543,7 +543,7 @@ ColorPicker::ColorPicker() : } HBoxContainer *hhb = memnew( HBoxContainer ); - + btn_mode = memnew( CheckButton ); btn_mode->set_text("RAW Mode"); btn_mode->connect("toggled", this, "set_raw_mode"); @@ -570,7 +570,7 @@ ColorPicker::ColorPicker() : uv_material->set_shader(s_uv); w_material.instance(); - + Ref<Shader> s_w = get_shader("w_editor"); w_material->set_shader(s_w); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 14a48fe3d3..2ab004e04b 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -185,7 +185,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { int x = p_event.mouse_motion.x; float newofs = CLAMP(x/float(total_w),0,1); - + //Snap to nearest point if holding shift if (p_event.key.mod.shift) { float snap_treshhold = 0.03; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index af3b37bec2..295ec03702 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -226,9 +226,9 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { return false; - + return true; - + } void Control::_get_property_list( List<PropertyInfo> *p_list) const { @@ -326,7 +326,7 @@ Control *Control::get_parent_control() const { void Control::_resize(const Size2& p_size) { - + _size_changed(); } @@ -626,7 +626,7 @@ void Control::set_drag_preview(Control *p_control) { } - + bool Control::is_window_modal_on_top() const { @@ -640,7 +640,7 @@ bool Control::is_window_modal_on_top() const { Size2 Control::get_minimum_size() const { - + ScriptInstance *si = const_cast<Control*>(this)->get_script_instance(); if (si) { @@ -654,7 +654,7 @@ Size2 Control::get_minimum_size() const { Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Texture>* tex = data.icon_override.getptr(p_name); @@ -714,7 +714,7 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ } Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<StyleBox>* style = data.style_override.getptr(p_name); if (style) @@ -828,12 +828,12 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con return Theme::get_default()->get_constant( p_name, type ); - + } bool Control::has_icon(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Texture>* tex = data.icon_override.getptr(p_name); if (tex) @@ -859,7 +859,7 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } return Theme::get_default()->has_icon( p_name, type ); - + } bool Control::has_shader(const StringName &p_name, const StringName &p_type) const @@ -889,10 +889,10 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con } return Theme::get_default()->has_shader( p_name, type ); - + } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<StyleBox>* style = data.style_override.getptr(p_name); @@ -922,7 +922,7 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co } bool Control::has_font(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Font>* font = data.font_override.getptr(p_name); if (font) @@ -952,7 +952,7 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const } bool Control::has_color(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Color* color = data.color_override.getptr(p_name); if (color) @@ -1024,7 +1024,7 @@ Size2 Control::get_parent_area_size() const { } else { parent_size=get_viewport()->get_visible_rect().size; - } + } return parent_size; } @@ -1083,11 +1083,11 @@ void Control::_size_changed() { } float Control::_get_parent_range(int p_idx) const { - + if (!is_inside_tree()) { - + return 1.0; - + } if (data.parent_canvas_item) { return data.parent_canvas_item->get_item_rect().size[p_idx&1]; @@ -1100,21 +1100,21 @@ float Control::_get_parent_range(int p_idx) const { float Control::_get_range(int p_idx) const { - + p_idx&=1; float parent_range = _get_parent_range( p_idx ); float from = _a2s( data.margin[p_idx], data.anchor[p_idx], parent_range ); float to = _a2s( data.margin[p_idx+2], data.anchor[p_idx+2], parent_range ); - + return to-from; } float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { - + switch(p_anchor) { - - case ANCHOR_BEGIN: { + + case ANCHOR_BEGIN: { return p_val; } break; case ANCHOR_END: { @@ -1122,21 +1122,21 @@ float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { } break; case ANCHOR_RATIO: { return p_val/p_range; - } break; + } break; case ANCHOR_CENTER: { return (p_range/2)-p_val; } break; - } - + } + return 0; } float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { - + switch(p_anchor) { - - case ANCHOR_BEGIN: { + + case ANCHOR_BEGIN: { return Math::floor(p_val); } break; case ANCHOR_END: { @@ -1144,7 +1144,7 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { } break; case ANCHOR_RATIO: { return Math::floor(p_range*p_val); - } break; + } break; case ANCHOR_CENTER: { return Math::floor((p_range/2)-p_val); } break; @@ -1154,9 +1154,9 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { void Control::set_anchor(Margin p_margin,AnchorType p_anchor) { - + if (!is_inside_tree()) { - + data.anchor[p_margin]=p_anchor; } else { float pr = _get_parent_range(p_margin); @@ -1175,8 +1175,8 @@ void Control::set_anchor_and_margin(Margin p_margin,AnchorType p_anchor, float p Control::AnchorType Control::get_anchor(Margin p_margin) const { - - return data.anchor[p_margin]; + + return data.anchor[p_margin]; } @@ -1204,40 +1204,40 @@ void Control::set_margin(Margin p_margin,float p_value) { } void Control::set_begin(const Size2& p_point) { - + data.margin[0]=p_point.x; data.margin[1]=p_point.y; _size_changed(); } void Control::set_end(const Size2& p_point) { - + data.margin[2]=p_point.x; data.margin[3]=p_point.y; _size_changed(); } float Control::get_margin(Margin p_margin) const { - + return data.margin[p_margin]; } Size2 Control::get_begin() const { - + return Size2( data.margin[0], data.margin[1] ); } Size2 Control::get_end() const { - + return Size2( data.margin[2], data.margin[3] ); } Point2 Control::get_global_pos() const { - + return get_global_transform().get_origin(); } void Control::set_global_pos(const Point2& p_point) { - + Matrix32 inv; if (data.parent_canvas_item) { @@ -1264,10 +1264,10 @@ void Control::set_pos(const Size2& p_point) { Size2 size = Size2(MAX( min.width, ret.width),MAX( min.height, ret.height)); float w=size.x; float h=size.y; - + x=p_point.x; y=p_point.y; - + data.margin[0] = _s2a( x, data.anchor[0], pw ); data.margin[1] = _s2a( y, data.anchor[1], ph ); data.margin[2] = _s2a( x+w, data.anchor[2], pw ); @@ -1277,26 +1277,26 @@ void Control::set_pos(const Size2& p_point) { } void Control::set_size(const Size2& p_size) { - + Size2 new_size=p_size; Size2 min=get_combined_minimum_size(); if (new_size.x<min.x) new_size.x=min.x; if (new_size.y<min.y) new_size.y=min.y; - + float pw = _get_parent_range(0); float ph = _get_parent_range(1); - + float x = _a2s( data.margin[0], data.anchor[0], pw ); float y = _a2s( data.margin[1], data.anchor[1], ph ); - + float w=new_size.width; float h=new_size.height; - + data.margin[2] = _s2a( x+w, data.anchor[2], pw ); data.margin[3] = _s2a( y+h, data.anchor[3], ph ); - + _size_changed(); } @@ -1308,13 +1308,13 @@ Size2 Control::get_pos() const { } Size2 Control::get_size() const { - + return data.size_cache; } Rect2 Control::get_global_rect() const { - - return Rect2( get_global_pos(), get_size() ); + + return Rect2( get_global_pos(), get_size() ); } Rect2 Control::get_window_rect() const { @@ -1326,7 +1326,7 @@ Rect2 Control::get_window_rect() const { Rect2 Control::get_rect() const { - + return Rect2(get_pos(),get_size()); } @@ -1336,7 +1336,7 @@ Rect2 Control::get_item_rect() const { } void Control::set_area_as_parent_rect(int p_margin) { - + data.anchor[MARGIN_LEFT]=ANCHOR_BEGIN; data.anchor[MARGIN_TOP]=ANCHOR_BEGIN; data.anchor[MARGIN_RIGHT]=ANCHOR_END; @@ -1345,7 +1345,7 @@ void Control::set_area_as_parent_rect(int p_margin) { data.margin[i]=p_margin; _size_changed(); - + } void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon) { @@ -1354,7 +1354,7 @@ void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_ data.icon_override[p_name]=p_icon; notification(NOTIFICATION_THEME_CHANGED); update(); - + } void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { @@ -1406,7 +1406,7 @@ static Control *_next_control(Control *p_from) { if (p_from->is_set_as_toplevel()) return NULL; // can't go above - Control *parent = p_from->get_parent()?p_from->get_parent()->cast_to<Control>():NULL; + Control *parent = p_from->get_parent()?p_from->get_parent()->cast_to<Control>():NULL; if (!parent) { @@ -1432,10 +1432,10 @@ static Control *_next_control(Control *p_from) { Control *Control::find_next_valid_focus() const { Control *from = const_cast<Control*>(this); - + while(true) { - - + + // find next child Control *next_child=NULL; @@ -1494,7 +1494,7 @@ Control *Control::find_next_valid_focus() const { from = next_child; } - + return NULL; @@ -1610,7 +1610,7 @@ void Control::grab_focus() { get_viewport()->_gui_control_grab_focus(this); -} +} void Control::release_focus() { @@ -1630,7 +1630,7 @@ bool Control::is_toplevel_control() const { } void Control::show_modal(bool p_exclusive) { - + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.SI); @@ -1642,7 +1642,7 @@ void Control::show_modal(bool p_exclusive) { raise(); data.modal_exclusive=p_exclusive; data.MI=get_viewport()->_gui_show_modal(this); - + } void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { @@ -2135,7 +2135,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_theme","theme:Theme"),&Control::set_theme); ObjectTypeDB::bind_method(_MD("get_theme:Theme"),&Control::get_theme); - + ObjectTypeDB::bind_method(_MD("add_icon_override","name","texture:Texture"),&Control::add_icon_override); ObjectTypeDB::bind_method(_MD("add_shader_override","name","shader:Shader"),&Control::add_shader_override); ObjectTypeDB::bind_method(_MD("add_style_override","name","stylebox:StyleBox"),&Control::add_style_override); @@ -2150,7 +2150,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_constant","name","type"),&Control::get_constant,DEFVAL("")); - ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); + ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); ObjectTypeDB::bind_method(_MD("set_tooltip","tooltip"),&Control::set_tooltip); ObjectTypeDB::bind_method(_MD("get_tooltip","atpos"),&Control::get_tooltip,DEFVAL(Point2())); @@ -2214,7 +2214,7 @@ void Control::_bind_methods() { BIND_CONSTANT( ANCHOR_BEGIN ); BIND_CONSTANT( ANCHOR_END ); - BIND_CONSTANT( ANCHOR_RATIO ); + BIND_CONSTANT( ANCHOR_RATIO ); BIND_CONSTANT( ANCHOR_CENTER ); BIND_CONSTANT( FOCUS_NONE ); BIND_CONSTANT( FOCUS_CLICK ); @@ -2261,11 +2261,11 @@ void Control::_bind_methods() { ADD_SIGNAL( MethodInfo("minimum_size_changed") ); ADD_SIGNAL( MethodInfo("modal_close") ); - + } Control::Control() { - - data.parent=NULL; + + data.parent=NULL; data.ignore_mouse=false; data.stop_mouse=true; @@ -2297,7 +2297,7 @@ Control::Control() { - + } diff --git a/scene/gui/control.h b/scene/gui/control.h index 74d40b7579..851d8316fb 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -45,19 +45,19 @@ class Label; class Panel; class Control : public CanvasItem { - + OBJ_TYPE( Control, CanvasItem ); OBJ_CATEGORY("GUI Nodes"); public: - - enum AnchorType { + + enum AnchorType { ANCHOR_BEGIN, ANCHOR_END, ANCHOR_RATIO, ANCHOR_CENTER, }; - + enum FocusMode { FOCUS_NONE, FOCUS_CLICK, @@ -106,7 +106,7 @@ private: }; struct Data { - + Point2 pos_cache; Size2 size_cache; @@ -132,7 +132,7 @@ private: bool modal; bool modal_exclusive; Ref<Theme> theme; - Control *theme_owner; + Control *theme_owner; String tooltip; CursorShape default_cursor; @@ -153,7 +153,7 @@ private: HashMap<StringName, Color, StringNameHasher > color_override; HashMap<StringName, int, StringNameHasher > constant_override; } data; - + // used internally Control* _find_control_at_pos(CanvasItem* p_node,const Point2& p_pos,const Matrix32& p_xform,Matrix32& r_inv_xform); @@ -184,7 +184,7 @@ friend class Viewport; void _modal_stack_remove(); void _modal_set_prev_focus_owner(ObjectID p_prev); -protected: +protected: //virtual void _window_input_event(InputEvent p_event); @@ -194,15 +194,15 @@ protected: void _notification(int p_notification); - - static void _bind_methods(); - - //bind helpers - + + static void _bind_methods(); + + //bind helpers + public: enum { - + /* NOTIFICATION_DRAW=30, NOTIFICATION_VISIBILITY_CHANGED=38*/ NOTIFICATION_RESIZED=40, @@ -241,29 +241,29 @@ public: Control *get_parent_control() const; - + /* POSITIONING */ - + void set_anchor(Margin p_margin,AnchorType p_anchor); void set_anchor_and_margin(Margin p_margin,AnchorType p_anchor, float p_pos); - + AnchorType get_anchor(Margin p_margin) const; - + void set_margin(Margin p_margin,float p_value); - + void set_begin(const Point2& p_point); // helper void set_end(const Point2& p_point); // helper - - - + + + float get_margin(Margin p_margin) const; Point2 get_begin() const; Point2 get_end() const; - + void set_pos(const Point2& p_point); void set_size(const Size2& p_size); void set_global_pos(const Point2& p_point); - + Point2 get_pos() const; Point2 get_global_pos() const; Size2 get_size() const; @@ -277,9 +277,9 @@ public: void set_scale(const Vector2& p_scale); Vector2 get_scale() const; - + void set_area_as_parent_rect(int p_margin=0); - + void show_modal(bool p_exclusive=false); void set_theme(const Ref<Theme>& p_theme); @@ -297,7 +297,7 @@ public: void minimum_size_changed(); /* FOCUS */ - + void set_focus_mode(FocusMode p_focus_mode); FocusMode get_focus_mode() const; bool has_focus() const; @@ -319,7 +319,7 @@ public: bool is_stopping_mouse() const; /* SKINNING */ - + void add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon); void add_shader_override(const StringName& p_name, const Ref<Shader>& p_shader); void add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style); @@ -367,9 +367,9 @@ public: Control *get_root_parent_control() const; - Control(); + Control(); ~Control(); - + }; VARIANT_ENUM_CAST(Control::AnchorType); diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 9f08b6f845..d00dacd256 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -188,7 +188,7 @@ void AcceptDialog::_post_popup() { } void AcceptDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_MODAL_CLOSE) { cancel_pressed(); @@ -197,7 +197,7 @@ void AcceptDialog::_notification(int p_what) { - } + } } void AcceptDialog::_builtin_text_entered(const String& p_text) { @@ -206,7 +206,7 @@ void AcceptDialog::_builtin_text_entered(const String& p_text) { } void AcceptDialog::_ok_pressed() { - + if (hide_on_ok) hide(); ok_pressed(); @@ -214,7 +214,7 @@ void AcceptDialog::_ok_pressed() { } void AcceptDialog::_close_pressed() { - + cancel_pressed(); } @@ -223,7 +223,7 @@ String AcceptDialog::get_text() const { return label->get_text(); } void AcceptDialog::set_text(String p_text) { - + label->set_text(p_text); } @@ -291,7 +291,7 @@ Button* AcceptDialog::add_cancel(const String &p_cancel) { } void AcceptDialog::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_ok"),&AcceptDialog::_ok_pressed); ObjectTypeDB::bind_method(_MD("get_ok"),&AcceptDialog::get_ok); ObjectTypeDB::bind_method(_MD("get_label"),&AcceptDialog::get_label); @@ -321,11 +321,11 @@ void AcceptDialog::set_swap_ok_cancel(bool p_swap) { } AcceptDialog::AcceptDialog() { - + int margin = get_constant("margin","Dialogs"); int button_margin = get_constant("button_margin","Dialogs"); - - + + label = memnew( Label ); label->set_anchor(MARGIN_RIGHT,ANCHOR_END); label->set_anchor(MARGIN_BOTTOM,ANCHOR_END); @@ -345,8 +345,8 @@ AcceptDialog::AcceptDialog() { hbc->add_child(ok); hbc->add_spacer(); //add_child(ok); - - + + ok->connect("pressed", this,"_ok"); set_as_toplevel(true); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 7c06ded866..f256c49aee 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -142,7 +142,7 @@ public: class ConfirmationDialog : public AcceptDialog { - + OBJ_TYPE(ConfirmationDialog,AcceptDialog); Button *cancel; protected: diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 56b9260837..b8b8c99c39 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -51,7 +51,7 @@ void FileDialog::_notification(int p_what) { refresh->set_icon(get_icon("reload")); } - + if (p_what==NOTIFICATION_DRAW) { //RID ci = get_canvas_item(); @@ -117,13 +117,13 @@ Vector<String> FileDialog::get_selected_files() const { }; void FileDialog::update_dir() { - + dir->set_text(dir_access->get_current_dir()); } void FileDialog::_dir_entered(String p_dir) { - - + + dir_access->change_dir(p_dir); file->set_text(""); invalidate(); @@ -132,13 +132,13 @@ void FileDialog::_dir_entered(String p_dir) { void FileDialog::_file_entered(const String& p_file) { - _action_pressed(); + _action_pressed(); } void FileDialog::_save_confirm_pressed() { String f=dir_access->get_current_dir().plus_file(file->get_text()); emit_signal("file_selected",f); - hide(); + hide(); } void FileDialog::_post_popup() { @@ -158,7 +158,7 @@ void FileDialog::_post_popup() { } void FileDialog::_action_pressed() { - + if (mode==MODE_OPEN_FILES) { TreeItem *ti=tree->get_next_selected(NULL); @@ -180,7 +180,7 @@ void FileDialog::_action_pressed() { } String f=dir_access->get_current_dir().plus_file(file->get_text()); - + if (mode==MODE_OPEN_FILE && dir_access->file_exists(f)) { emit_signal("file_selected",f); hide(); @@ -202,7 +202,7 @@ void FileDialog::_action_pressed() { } if (mode==MODE_SAVE_FILE) { - + bool valid=false; if (filter->get_selected()==filter->get_item_count()-1) { @@ -263,7 +263,7 @@ void FileDialog::_action_pressed() { confirm_save->set_text("File Exists, Overwrite?"); confirm_save->popup_centered(Size2(200,80)); } else { - + emit_signal("file_selected",f); hide(); @@ -279,51 +279,51 @@ void FileDialog::_cancel_pressed() { } void FileDialog::_tree_selected() { - + TreeItem *ti=tree->get_selected(); if (!ti) return; Dictionary d=ti->get_metadata(0); - + if (!d["dir"]) { - + file->set_text(d["name"]); } - + } void FileDialog::_tree_dc_selected() { - + TreeItem *ti=tree->get_selected(); if (!ti) return; - + Dictionary d=ti->get_metadata(0); if (d["dir"]) { - + dir_access->change_dir(d["name"]); if (mode==MODE_OPEN_FILE || mode==MODE_OPEN_FILES || mode==MODE_OPEN_DIR) file->set_text(""); call_deferred("_update_file_list"); call_deferred("_update_dir"); } else { - + _action_pressed(); } } void FileDialog::update_file_list() { - + tree->clear(); dir_access->list_dir_begin(); - + TreeItem *root = tree->create_item(); Ref<Texture> folder = get_icon("folder"); List<String> files; List<String> dirs; - + bool isdir; bool ishidden; bool show_hidden = show_hidden_files; @@ -340,12 +340,12 @@ void FileDialog::update_file_list() { dirs.push_back(item); } } - + dirs.sort_custom<NoCaseComparator>(); files.sort_custom<NoCaseComparator>(); - + while(!dirs.empty()) { - + if (dirs.front()->get()!=".") { TreeItem *ti=tree->create_item(root); ti->set_text(0,dirs.front()->get()+"/"); @@ -356,23 +356,23 @@ void FileDialog::update_file_list() { ti->set_metadata(0,d); } dirs.pop_front(); - + } - + dirs.clear(); - + List<String> patterns; // build filter if (filter->get_selected()==filter->get_item_count()-1) { - - // match all + + // match all } else if (filters.size()>1 && filter->get_selected()==0) { // match all filters for (int i=0;i<filters.size();i++) { - + String f=filters[i].get_slice(";",0); for (int j=0;j<f.get_slice_count(",");j++) { - + patterns.push_back(f.get_slice(",",j).strip_edges()); } } @@ -380,34 +380,34 @@ void FileDialog::update_file_list() { int idx=filter->get_selected(); if (filters.size()>1) idx--; - + if (idx>=0 && idx<filters.size()) { - + String f=filters[idx].get_slice(";",0); for (int j=0;j<f.get_slice_count(",");j++) { - + patterns.push_back(f.get_slice(",",j).strip_edges()); - } + } } } String base_dir = dir_access->get_current_dir(); - - + + while(!files.empty()) { - + bool match=patterns.empty(); - + for(List<String>::Element *E=patterns.front();E;E=E->next()) { - + if (files.front()->get().matchn(E->get())) { - + match=true; break; } } - + if (match) { TreeItem *ti=tree->create_item(root); ti->set_text(0,files.front()->get()); @@ -426,35 +426,35 @@ void FileDialog::update_file_list() { d["name"]=files.front()->get(); d["dir"]=false; ti->set_metadata(0,d); - + if (file->get_text()==files.front()->get()) ti->select(0); } - + files.pop_front(); } - + if (tree->get_root() && tree->get_root()->get_children()) tree->get_root()->get_children()->select(0); - + files.clear(); - + } void FileDialog::_filter_selected(int) { - + update_file_list(); } void FileDialog::update_filters() { - + filter->clear(); - + if (filters.size()>1) { String all_filters; const int max_filters=5; - + for(int i=0;i<MIN( max_filters, filters.size()) ;i++) { String flt=filters[i].get_slice(";",0); if (i>0) @@ -464,11 +464,11 @@ void FileDialog::update_filters() { if (max_filters<filters.size()) all_filters+=", ..."; - + filter->add_item("All Recognized ( "+all_filters+" )"); } for(int i=0;i<filters.size();i++) { - + String flt=filters[i].get_slice(";",0).strip_edges(); String desc=filters[i].get_slice(";",1).strip_edges(); if (desc.length()) @@ -476,46 +476,46 @@ void FileDialog::update_filters() { else filter->add_item("( "+flt+" )"); } - + filter->add_item("All Files (*)"); - + } void FileDialog::clear_filters() { - + filters.clear(); update_filters(); invalidate(); } void FileDialog::add_filter(const String& p_filter) { - + filters.push_back(p_filter); update_filters(); invalidate(); - + } String FileDialog::get_current_dir() const { - - return dir->get_text(); + + return dir->get_text(); } String FileDialog::get_current_file() const { - + return file->get_text(); } String FileDialog::get_current_path() const { - + return dir->get_text().plus_file(file->get_text()); } void FileDialog::set_current_dir(const String& p_dir) { - + dir_access->change_dir(p_dir); update_dir(); invalidate(); - + } void FileDialog::set_current_file(const String& p_file) { - + file->set_text(p_file); update_dir(); invalidate(); @@ -525,18 +525,18 @@ void FileDialog::set_current_file(const String& p_file) { file->grab_focus(); } - + } void FileDialog::set_current_path(const String& p_path) { - + if (!p_path.size()) return; int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") ); if (pos==-1) { - + set_current_file(p_path); } else { - + String dir=p_path.substr(0,pos); String file=p_path.substr(pos+1,p_path.length()); set_current_dir(dir); @@ -546,10 +546,10 @@ void FileDialog::set_current_path(const String& p_path) { void FileDialog::set_mode(Mode p_mode) { - + mode=p_mode; switch(mode) { - + case MODE_OPEN_FILE: get_ok()->set_text("Open"); set_title("Open a File"); makedir->hide(); break; case MODE_OPEN_FILES: get_ok()->set_text("Open"); set_title("Open File(s)"); makedir->hide(); break; case MODE_SAVE_FILE: get_ok()->set_text("Save"); set_title("Save a File"); makedir->show(); break; @@ -565,7 +565,7 @@ void FileDialog::set_mode(Mode p_mode) { } FileDialog::Mode FileDialog::get_mode() const { - + return mode; } @@ -655,7 +655,7 @@ void FileDialog::_update_drives() { drives->show(); for(int i=0;i<dir_access->get_drive_count();i++) { - String d = dir_access->get_drive(i); + String d = dir_access->get_drive(i); drives->add_item(dir_access->get_drive(i)); } @@ -668,7 +668,7 @@ bool FileDialog::default_show_hidden_files=false; void FileDialog::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_unhandled_input"),&FileDialog::_unhandled_input); ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected); @@ -679,7 +679,7 @@ void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_cancel_pressed"),&FileDialog::_cancel_pressed); ObjectTypeDB::bind_method(_MD("_filter_selected"),&FileDialog::_filter_selected); ObjectTypeDB::bind_method(_MD("_save_confirm_pressed"),&FileDialog::_save_confirm_pressed); - + ObjectTypeDB::bind_method(_MD("clear_filters"),&FileDialog::clear_filters); ObjectTypeDB::bind_method(_MD("add_filter","filter"),&FileDialog::add_filter); ObjectTypeDB::bind_method(_MD("get_current_dir"),&FileDialog::get_current_dir); @@ -742,7 +742,7 @@ FileDialog::FileDialog() { mode=MODE_SAVE_FILE; set_title("Save a File"); - + dir = memnew(LineEdit); HBoxContainer *pathhb = memnew( HBoxContainer ); pathhb->add_child(dir); @@ -760,17 +760,17 @@ FileDialog::FileDialog() { makedir->set_text("Create Folder"); makedir->connect("pressed",this,"_make_dir"); pathhb->add_child(makedir); - + vbc->add_margin_child("Path:",pathhb); - + tree = memnew(Tree); tree->set_hide_root(true); vbc->add_margin_child("Directories & Files:",tree,true); - + file = memnew(LineEdit); //add_child(file); vbc->add_margin_child("File:",file); - + filter = memnew( OptionButton ); //add_child(filter); @@ -781,7 +781,7 @@ FileDialog::FileDialog() { access=ACCESS_RESOURCES; _update_drives(); - + connect("confirmed", this,"_action_pressed"); //cancel->connect("pressed", this,"_cancel_pressed"); tree->connect("cell_selected", this,"_tree_selected",varray(),CONNECT_DEFERRED); @@ -790,12 +790,12 @@ FileDialog::FileDialog() { file->connect("text_entered", this,"_file_entered"); filter->connect("item_selected", this,"_filter_selected"); - + confirm_save = memnew( ConfirmationDialog ); confirm_save->set_as_toplevel(true); add_child(confirm_save); - + confirm_save->connect("confirmed", this,"_save_confirm_pressed"); makedialog = memnew( ConfirmationDialog ); @@ -828,12 +828,12 @@ FileDialog::FileDialog() { invalidated=true; if (register_func) register_func(this); - + } FileDialog::~FileDialog() { - + if (unregister_func) unregister_func(this); memdelete(dir_access); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index b71a157fa7..2042adbc20 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -41,9 +41,9 @@ @author Juan Linietsky <reduzio@gmail.com> */ class FileDialog : public ConfirmationDialog { - + OBJ_TYPE( FileDialog, ConfirmationDialog ); - + public: enum Access { @@ -89,7 +89,7 @@ private: ConfirmationDialog *confirm_save; ToolButton *refresh; - + Vector<String> filters; @@ -97,13 +97,13 @@ private: bool show_hidden_files; bool invalidated; - + void update_dir(); void update_file_list(); void update_filters(); - + void _tree_selected(); - + void _select_drive(int p_idx); void _tree_dc_selected(); void _dir_entered(String p_dir); @@ -122,18 +122,18 @@ private: virtual void _post_popup(); protected: - + void _notification(int p_what); static void _bind_methods(); //bind helpers public: - + void clear_filters(); void add_filter(const String& p_filter); void set_enable_multiple_selection(bool p_enable); Vector<String> get_selected_files() const; - + String get_current_dir() const; String get_current_file() const; String get_current_path() const; @@ -156,8 +156,8 @@ public: static void set_default_show_hidden_files(bool p_show); void invalidate(); - - FileDialog(); + + FileDialog(); ~FileDialog(); }; diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index a189c10046..8a7721b9b5 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -118,7 +118,7 @@ public: void set_right_disconnects(bool p_enable); bool is_right_disconnects_enabled() const; - + Vector2 get_scroll_ofs() const; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 2a62ab30fc..3953ef06a5 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -36,20 +36,20 @@ void LineEdit::_input_event(InputEvent p_event) { switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b = p_event.mouse_button; if (b.button_index!=1) break; - + if (b.pressed) { - + set_cursor_at_pixel_pos(b.x); - + if (b.doubleclick) { - + selection.enabled=true; selection.begin=0; selection.end=text.length(); @@ -57,9 +57,9 @@ void LineEdit::_input_event(InputEvent p_event) { } selection.drag_attempt=false; - + if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled) { - + selection_clear(); selection.cursor_start=cursor_pos; selection.creating=true; @@ -67,13 +67,13 @@ void LineEdit::_input_event(InputEvent p_event) { selection.drag_attempt=true; } - + // if (!editable) // non_editable_clicked_signal.call(); update(); - + } else { - + if ( (!selection.creating) && (!selection.doubleclick)) { selection_clear(); } @@ -83,29 +83,29 @@ void LineEdit::_input_event(InputEvent p_event) { if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); } - - update(); + + update(); } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion& m=p_event.mouse_motion; - + if (m.button_mask&1) { - + if (selection.creating) { set_cursor_at_pixel_pos(m.x); selection_fill_at_cursor(); } } - + } break; case InputEvent::KEY: { - + const InputEventKey &k =p_event.key; - + if (!k.pressed) return; - unsigned int code = k.scancode; + unsigned int code = k.scancode; if (k.mod.command) { @@ -346,11 +346,11 @@ void LineEdit::_input_event(InputEvent p_event) { } - + return; - + } break; - + } } @@ -405,30 +405,30 @@ void LineEdit::drop_data(const Point2& p_point,const Variant& p_data){ void LineEdit::_notification(int p_what) { - + switch(p_what) { - + case NOTIFICATION_RESIZED: { - + set_cursor_pos( get_cursor_pos() ); - + } break; case NOTIFICATION_DRAW: { - + int width,height; - + Size2 size=get_size(); width=size.width; height=size.height; - + RID ci = get_canvas_item(); - + Ref<StyleBox> style = get_stylebox("normal"); if (!is_editable()) style=get_stylebox("read_only"); Ref<Font> font=get_font("font"); - + style->draw( ci, Rect2( Point2(), size ) ); if (has_focus()) { @@ -439,7 +439,7 @@ void LineEdit::_notification(int p_what) { int x_ofs=0; switch (align) { - + case ALIGN_FILL: case ALIGN_LEFT: { @@ -457,19 +457,19 @@ void LineEdit::_notification(int p_what) { int ofs_max=width-style->get_minimum_size().width; int char_ofs=window_pos; - + int y_area=height-style->get_minimum_size().height; int y_ofs=style->get_offset().y; - + int font_ascent=font->get_ascent(); - + Color selection_color=get_color("selection_color"); Color font_color=get_color("font_color"); Color font_color_selected=get_color("font_color_selected"); Color cursor_color=get_color("cursor_color"); - + while(true) { - + //end of string, break! if (char_ofs>=text.length()) break; @@ -477,32 +477,32 @@ void LineEdit::_notification(int p_what) { CharType cchar=pass?'*':text[char_ofs]; CharType next=pass?'*':text[char_ofs+1]; int char_width=font->get_char_size( cchar,next ).width; - + // end of widget, break! if ((x_ofs + char_width) > ofs_max) break; - - + + bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end; - + if (selected) VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, y_area)), selection_color); - + font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); - + if (char_ofs==cursor_pos && has_focus()) VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); - + x_ofs+=char_width; char_ofs++; } if (char_ofs==cursor_pos && has_focus()) //may be at the end VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( - Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); - + Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); + } break; case NOTIFICATION_FOCUS_ENTER: { @@ -521,15 +521,15 @@ void LineEdit::_notification(int p_what) { } void LineEdit::copy_text() { - + if(selection.enabled) { - + OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); } } void LineEdit::cut_text() { - + if(selection.enabled) { undo_text = text; OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); @@ -538,9 +538,9 @@ void LineEdit::cut_text() { } void LineEdit::paste_text() { - + String paste_buffer = OS::get_singleton()->get_clipboard(); - + if(paste_buffer != "") { if(selection.enabled) selection_delete(); @@ -550,28 +550,28 @@ void LineEdit::paste_text() { _change_notify("text"); } - + } void LineEdit::shift_selection_check_pre(bool p_shift) { - + if (!selection.old_shift && p_shift) { selection.cursor_start=cursor_pos; } if (!p_shift) selection_clear(); - + } void LineEdit::shift_selection_check_post(bool p_shift) { - + if (p_shift) selection_fill_at_cursor(); } void LineEdit::set_cursor_at_pixel_pos(int p_x) { - + Ref<Font> font = get_font("font"); int ofs = window_pos; Ref<StyleBox> style = get_stylebox("normal"); @@ -579,10 +579,10 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { Size2 size = get_size(); switch (align) { - + case ALIGN_FILL: case ALIGN_LEFT: { - + pixel_ofs = int(style->get_offset().x); } break; case ALIGN_CENTER: { @@ -597,30 +597,30 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { while (ofs<text.length()) { - + int char_w = 0; if (font != NULL) { char_w = font->get_char_size(text[ofs]).width; } pixel_ofs+=char_w; - + if (pixel_ofs > p_x) { //found what we look for - - + + if ( (pixel_ofs-p_x) < (char_w >> 1 ) ) { - + ofs+=1; } - + break; } - - + + ofs++; } - + set_cursor_pos( ofs ); - + /* int new_cursor_pos=p_x; int charwidth=draw_area->get_font_char_width(' ',0); @@ -631,29 +631,29 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { void LineEdit::delete_char() { - + if ((text.length()<=0) || (cursor_pos==0)) return; - + Ref<Font> font = get_font("font"); if (font != NULL) { cached_width -= font->get_char_size(text[cursor_pos - 1]).width; } - + text.erase( cursor_pos-1, 1 ); - + set_cursor_pos(get_cursor_pos()-1); - + if (cursor_pos==window_pos) { - + // set_window_pos(cursor_pos-get_window_length()); } - + emit_signal("text_changed",text); _change_notify("text"); } void LineEdit::set_text(String p_text) { - + clear_internal(); append_at_cursor(p_text); update(); @@ -662,86 +662,86 @@ void LineEdit::set_text(String p_text) { } void LineEdit::clear() { - + clear_internal(); } String LineEdit::get_text() const { - + return text; } void LineEdit::set_cursor_pos(int p_pos) { - + if (p_pos>(int)text.length()) p_pos=text.length(); - + if(p_pos<0) p_pos=0; - - - + + + cursor_pos=p_pos; - + // if (cursor_pos>(window_pos+get_window_length())) { // set_window_pos(cursor_pos-get_window_lengt//h()); // } - + if (!is_inside_tree()) { - + window_pos=cursor_pos; return; } - + Ref<StyleBox> style = get_stylebox("normal"); Ref<Font> font=get_font("font"); - + if (cursor_pos<window_pos) { /* Adjust window if cursor goes too much to the left */ set_window_pos(cursor_pos); } else if (cursor_pos>window_pos) { /* Adjust window if cursor goes too much to the right */ int window_width=get_size().width-style->get_minimum_size().width; - + if (window_width<0) return; int width_to_cursor=0; int wp=window_pos; - + if (font != NULL) { for (int i=window_pos;i<cursor_pos;i++) width_to_cursor+=font->get_char_size( text[i] ).width; - + while (width_to_cursor >= window_width && wp < text.length()) { width_to_cursor -= font->get_char_size(text[wp]).width; wp++; } } - + if (wp!=window_pos) set_window_pos( wp ); - + } update(); } int LineEdit::get_cursor_pos() const { - + return cursor_pos; } void LineEdit::set_window_pos(int p_pos) { - + window_pos=p_pos; if (window_pos<0) window_pos=0; } void LineEdit::append_at_cursor(String p_text) { - - + + if ( ( max_length <= 0 ) || (text.length()+p_text.length() <= max_length)) { - + undo_text = text; Ref<Font> font = get_font("font"); @@ -761,7 +761,7 @@ void LineEdit::append_at_cursor(String p_text) { } void LineEdit::clear_internal() { - + cached_width = 0; cursor_pos=0; window_pos=0; @@ -771,21 +771,21 @@ void LineEdit::clear_internal() { } Size2 LineEdit::get_minimum_size() const { - + Ref<StyleBox> style = get_stylebox("normal"); Ref<Font> font=get_font("font"); - + Size2 min=style->get_minimum_size(); min.height+=font->get_height(); min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x; - + return min; } /* selection */ void LineEdit::selection_clear() { - + selection.begin=0; selection.end=0; selection.cursor_start=0; @@ -798,9 +798,9 @@ void LineEdit::selection_clear() { void LineEdit::selection_delete() { - + if (selection.enabled) { - + undo_text = text; if (text.size() > 0) @@ -818,80 +818,80 @@ void LineEdit::selection_delete() { text.erase(selection.begin,selection.end-selection.begin); cursor_pos-=CLAMP( cursor_pos-selection.begin, 0, selection.end-selection.begin); - + if (cursor_pos>=text.length()) { - + cursor_pos=text.length(); } if (window_pos>cursor_pos) { - + window_pos=cursor_pos; } - + emit_signal("text_changed",text); _change_notify("text"); }; - + selection_clear(); } void LineEdit::set_max_length(int p_max_length) { - + ERR_FAIL_COND(p_max_length<0); max_length = p_max_length; set_text(text); } int LineEdit::get_max_length() const { - + return max_length; } void LineEdit::selection_fill_at_cursor() { - + int aux; - + selection.begin=cursor_pos; selection.end=selection.cursor_start; - + if (selection.end<selection.begin) { aux=selection.end; selection.end=selection.begin; selection.begin=aux; } - + selection.enabled=(selection.begin!=selection.end); } void LineEdit::select_all() { - + if (!text.length()) return; - + selection.begin=0; selection.end=text.length(); selection.enabled=true; update(); - + } void LineEdit::set_editable(bool p_editable) { - + editable=p_editable; update(); } bool LineEdit::is_editable() const { - + return editable; } void LineEdit::set_secret(bool p_secret) { - + pass=p_secret; update(); } bool LineEdit::is_secret() const { - + return pass; } @@ -928,24 +928,24 @@ bool LineEdit::is_text_field() const { } void LineEdit::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("set_align", "align"), &LineEdit::set_align); ObjectTypeDB::bind_method(_MD("get_align"), &LineEdit::get_align); ObjectTypeDB::bind_method(_MD("_input_event"),&LineEdit::_input_event); - ObjectTypeDB::bind_method(_MD("clear"),&LineEdit::clear); - ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all); + ObjectTypeDB::bind_method(_MD("clear"),&LineEdit::clear); + ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all); ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text); - ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); + ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos); - ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); + ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); ObjectTypeDB::bind_method(_MD("set_max_length","chars"),&LineEdit::set_max_length); - ObjectTypeDB::bind_method(_MD("get_max_length"),&LineEdit::get_max_length); + ObjectTypeDB::bind_method(_MD("get_max_length"),&LineEdit::get_max_length); ObjectTypeDB::bind_method(_MD("append_at_cursor","text"),&LineEdit::append_at_cursor); ObjectTypeDB::bind_method(_MD("set_editable","enabled"),&LineEdit::set_editable); - ObjectTypeDB::bind_method(_MD("is_editable"),&LineEdit::is_editable); + ObjectTypeDB::bind_method(_MD("is_editable"),&LineEdit::is_editable); ObjectTypeDB::bind_method(_MD("set_secret","enabled"),&LineEdit::set_secret); - ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret); + ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret); ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::select,DEFVAL(0),DEFVAL(-1)); ADD_SIGNAL( MethodInfo("text_changed", PropertyInfo( Variant::STRING, "text" )) ); @@ -964,25 +964,25 @@ void LineEdit::_bind_methods() { } LineEdit::LineEdit() { - + align = ALIGN_LEFT; cached_width = 0; cursor_pos=0; window_pos=0; max_length = 0; pass=false; - + selection_clear(); set_focus_mode( FOCUS_ALL ); editable=true; set_default_cursor_shape(CURSOR_IBEAM); set_stop_mouse(true); - - + + } LineEdit::~LineEdit() { - - + + } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index bf6459361a..207c6b115b 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class LineEdit : public Control { - + OBJ_TYPE( LineEdit, Control ); public: @@ -50,18 +50,18 @@ private: bool editable; bool pass; - + String undo_text; String text; - + int cursor_pos; int window_pos; int max_length; // 0 for no maximum int cached_width; - + struct Selection { - + int begin; int end; int cursor_start; @@ -71,41 +71,41 @@ private: bool doubleclick; bool drag_attempt; } selection; - + void shift_selection_check_pre(bool); void shift_selection_check_post(bool); - + void selection_clear(); void selection_fill_at_cursor(); void selection_delete(); void set_window_pos(int p_pos); - + void set_cursor_at_pixel_pos(int p_x); - + void clear_internal(); void changed_internal(); - + void copy_text(); void cut_text(); void paste_text(); - + void _input_event(InputEvent p_event); void _notification(int p_what); - -protected: - static void _bind_methods(); + +protected: + static void _bind_methods(); public: void set_align(Align p_align); Align get_align() const; - + virtual Variant get_drag_data(const Point2& p_point); virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; virtual void drop_data(const Point2& p_point,const Variant& p_data); - + void select_all(); - + void delete_char(); void set_text(String p_text); String get_text() const; @@ -115,11 +115,11 @@ public: int get_max_length() const; void append_at_cursor(String p_text); void clear(); - - + + void set_editable(bool p_editable); bool is_editable() const; - + void set_secret(bool p_secret); bool is_secret() const; @@ -130,7 +130,7 @@ public: virtual bool is_text_field() const; LineEdit(); ~LineEdit(); - + }; diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 26540843de..cb8806e2ef 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -76,18 +76,18 @@ void MenuButton::_unhandled_key_input(InputEvent p_event) { 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 ) ); - popup->set_size( Size2( size.width, 0) ); + popup->set_size( Size2( size.width, 0) ); popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size())); popup->popup(); popup->call_deferred("grab_click_focus"); popup->set_invalidate_click_until_motion(); - + } void MenuButton::_input_event(InputEvent p_event) { @@ -111,7 +111,7 @@ void MenuButton::_input_event(InputEvent p_event) { } PopupMenu *MenuButton::get_popup() { - + return popup; } @@ -136,7 +136,7 @@ void MenuButton::_bind_methods() { ADD_SIGNAL( MethodInfo("about_to_show") ); } MenuButton::MenuButton() { - + set_flat(true); set_focus_mode(FOCUS_NONE); diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 2df632811f..650e4aba5c 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -35,24 +35,24 @@ @author Juan Linietsky <reduzio@gmail.com> */ class MenuButton : public Button { - + OBJ_TYPE( MenuButton, Button ); bool clicked; PopupMenu *popup; - virtual void pressed(); + virtual void pressed(); void _unhandled_key_input(InputEvent p_event); Array _get_items() const; void _set_items(const Array& p_items); void _input_event(InputEvent p_event); -protected: - +protected: + - static void _bind_methods(); + static void _bind_methods(); public: - + PopupMenu *get_popup(); MenuButton(); ~MenuButton(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 5c8e5a7381..587a68ae37 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -55,7 +55,7 @@ void OptionButton::_notification(int p_what) { Ref<Texture> arrow = Control::get_icon("arrow"); Ref<StyleBox> normal = get_stylebox("normal" ); - Size2 size = get_size(); + Size2 size = get_size(); Point2 ofs( size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height-arrow->get_height())/2))); arrow->draw(ci,ofs); @@ -66,7 +66,7 @@ void OptionButton::_notification(int p_what) { void OptionButton::_selected(int p_which) { - + int selid = -1; for (int i=0;i<popup->get_item_count();i++) { @@ -89,39 +89,39 @@ 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_size( Size2( size.width, 0) ); - + popup->popup(); } void OptionButton::add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID) { - - popup->add_icon_check_item( p_icon, p_label, p_ID ); + + popup->add_icon_check_item( p_icon, p_label, p_ID ); if (popup->get_item_count()==1) select(0); } void OptionButton::add_item(const String& p_label,int p_ID) { - - popup->add_check_item( p_label, p_ID ); + + popup->add_check_item( p_label, p_ID ); if (popup->get_item_count()==1) - select(0); + select(0); } void OptionButton::set_item_text(int p_idx,const String& p_text) { - + popup->set_item_text(p_idx,p_text); - + } void OptionButton::set_item_icon(int p_idx,const Ref<Texture>& p_icon) { - + popup->set_item_icon(p_idx,p_icon); - + } void OptionButton::set_item_ID(int p_idx,int p_ID) { - + popup->set_item_ID(p_idx,p_ID); } @@ -136,17 +136,17 @@ void OptionButton::set_item_disabled(int p_idx,bool p_disabled) { } String OptionButton::get_item_text(int p_idx) const { - + return popup->get_item_text(p_idx); } Ref<Texture> OptionButton::get_item_icon(int p_idx) const { - + return popup->get_item_icon(p_idx); } int OptionButton::get_item_ID(int p_idx) const { - + return popup->get_item_ID(p_idx); } Variant OptionButton::get_item_metadata(int p_idx) const { @@ -161,17 +161,17 @@ bool OptionButton::is_item_disabled(int p_idx) const { int OptionButton::get_item_count() const { - + return popup->get_item_count(); } void OptionButton::add_separator() { - + popup->add_separator(); } void OptionButton::clear() { - + popup->clear(); set_text(""); current=-1; @@ -210,12 +210,12 @@ void OptionButton::_select_int(int p_which) { } void OptionButton::select(int p_idx) { - + _select(p_idx,false); } int OptionButton::get_selected() const { - + return current; } @@ -286,9 +286,9 @@ void OptionButton::get_translatable_strings(List<String> *p_strings) const { void OptionButton::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_selected"),&OptionButton::_selected); - + ObjectTypeDB::bind_method(_MD("add_item","label","id"),&OptionButton::add_item,DEFVAL(-1)); ObjectTypeDB::bind_method(_MD("add_icon_item","texture:Texture","label","id"),&OptionButton::add_icon_item); ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&OptionButton::set_item_text); @@ -305,7 +305,7 @@ void OptionButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_separator"),&OptionButton::add_separator); ObjectTypeDB::bind_method(_MD("clear"),&OptionButton::clear); ObjectTypeDB::bind_method(_MD("select","idx"),&OptionButton::select); - ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected); + ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected); ObjectTypeDB::bind_method(_MD("get_selected_ID"),&OptionButton::get_selected_ID); ObjectTypeDB::bind_method(_MD("get_selected_metadata"),&OptionButton::get_selected_metadata); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&OptionButton::remove_item); @@ -320,23 +320,23 @@ void OptionButton::_bind_methods() { } OptionButton::OptionButton() { - - + + popup = memnew( PopupMenu ); popup->hide(); popup->set_as_toplevel(true); add_child(popup); popup->connect("item_pressed", this,"_selected"); - + current=-1; set_text_align(ALIGN_LEFT); } OptionButton::~OptionButton() { - - + + } diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 34e2bdd384..70ebc66a46 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -35,12 +35,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class OptionButton : public Button { - + OBJ_TYPE( OptionButton, Button ); - + PopupMenu *popup; int current; - + void _selected(int p_which); void _select(int p_which,bool p_emit=false); void _select_int(int p_which); @@ -55,10 +55,10 @@ protected: void _notification(int p_what); static void _bind_methods(); public: - + void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1); void add_item(const String& p_label,int p_ID=-1); - + void set_item_text(int p_idx,const String& p_text); void set_item_icon(int p_idx,const Ref<Texture>& p_icon); void set_item_ID(int p_idx,int p_ID); @@ -73,11 +73,11 @@ public: int get_item_count() const; - + void add_separator(); - + void clear(); - + void select(int p_idx); int get_selected() const; int get_selected_ID() const; @@ -87,7 +87,7 @@ public: virtual void get_translatable_strings(List<String> *p_strings) const; - OptionButton(); + OptionButton(); ~OptionButton(); }; diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index d40daa972c..682ea5b92c 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -30,7 +30,7 @@ #include "print_string.h" void Panel::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); @@ -40,7 +40,7 @@ void Panel::_notification(int p_what) { } Panel::Panel() { - + set_stop_mouse(true); } diff --git a/scene/gui/panel.h b/scene/gui/panel.h index ee4bcd139e..efa9ebcaa0 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -34,13 +34,13 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Panel : public Control{ - + OBJ_TYPE(Panel,Control); protected: void _notification(int p_what); public: - Panel(); + Panel(); ~Panel(); }; diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 1f04985ec6..0d9a76937c 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -32,12 +32,12 @@ void Popup::_input_event(InputEvent p_event) { - + } void Popup::_notification(int p_what) { - + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { if (popped_up && !is_visible()) { popped_up=false; @@ -58,11 +58,11 @@ void Popup::_notification(int p_what) { } void Popup::_fix_size() { - + #if 0 Point2 pos = get_pos(); - Size2 size = get_size(); + Size2 size = get_size(); Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); #else @@ -75,7 +75,7 @@ void Popup::_fix_size() { pos.x=window_size.width-size.width; if (pos.x<0) pos.x=0; - + if (pos.y+size.height > window_size.height) pos.y=window_size.height-size.height; if (pos.y<0) @@ -179,7 +179,7 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) { } void Popup::popup_centered(const Size2& p_size) { - + Point2 window_size = get_viewport_rect().size; emit_signal("about_to_show"); @@ -203,9 +203,9 @@ void Popup::popup_centered(const Size2& p_size) { } void Popup::popup_centered_ratio(float p_screen_ratio) { - - - + + + emit_signal("about_to_show"); Rect2 rect; @@ -214,7 +214,7 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); set_size( rect.size ); - + show_modal(exclusive); _fix_size(); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 9c66e6d7bd..8afcdc01db 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -35,12 +35,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Popup : public Control { - + OBJ_TYPE( Popup, Control ); bool exclusive; bool popped_up; - + protected: virtual void _post_popup() {} @@ -48,14 +48,14 @@ protected: void _input_event(InputEvent p_event); void _notification(int p_what); void _fix_size(); - static void _bind_methods(); + static void _bind_methods(); public: enum { NOTIFICATION_POST_POPUP=80, NOTIFICATION_POPUP_HIDE=81 }; - + void set_exclusive(bool p_exclusive); bool is_exclusive() const; @@ -65,8 +65,8 @@ public: void set_as_minsize(); virtual void popup(); - - Popup(); + + Popup(); ~Popup(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index a93d8e524f..3329d24890 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -59,34 +59,34 @@ Size2 PopupMenu::get_minimum_size() const { int vseparation = get_constant("vseparation"); int hseparation = get_constant("hseparation"); - + Size2 minsize = get_stylebox("panel")->get_minimum_size(); Ref<Font> font = get_font("font"); - + float max_w=0; int font_h = font->get_height(); int check_w = get_icon("checked")->get_width(); int accel_max_w=0; - + for (int i=0;i<items.size();i++) { - + Size2 size; if (!items[i].icon.is_null()) { - + Size2 icon_size = items[i].icon->get_size(); size.height = MAX( icon_size.height, font_h ); size.width+=icon_size.width; size.width+=hseparation; } else { - + size.height=font_h; } - + if (items[i].checkable) { - + size.width+=check_w+hseparation; } - + size.width+=font->get_string_size(items[i].text).width; if (i>0) size.height+=vseparation; @@ -100,11 +100,11 @@ Size2 PopupMenu::get_minimum_size() const { minsize.height+=size.height; max_w = MAX( max_w, size.width ); - + } - + minsize.width+=max_w+accel_max_w; - + return minsize; } @@ -115,41 +115,41 @@ int PopupMenu::_get_mouse_over(const Point2& p_over) const { return -1; Ref<StyleBox> style = get_stylebox("panel"); - + Point2 ofs=style->get_offset(); - + if (ofs.y>p_over.y) return -1; - - - Ref<Font> font = get_font("font"); + + + Ref<Font> font = get_font("font"); int vseparation = get_constant("vseparation"); // int hseparation = get_constant("hseparation"); float font_h=font->get_height(); - + for (int i=0;i<items.size();i++) { - + if (i>0) ofs.y+=vseparation; float h; - + if (!items[i].icon.is_null()) { - + Size2 icon_size = items[i].icon->get_size(); h = MAX( icon_size.height, font_h ); } else { - + h=font_h; } - + ofs.y+=h; if (p_over.y < ofs.y) { return i; - } + } } - + return -1; } @@ -271,11 +271,11 @@ void PopupMenu::_input_event(const InputEvent &p_event) { } break; case InputEvent::MOUSE_BUTTON: { - - + + const InputEventMouseButton &b=p_event.mouse_button; if (b.pressed) - break; + break; switch(b.button_index) { @@ -347,11 +347,11 @@ void PopupMenu::_input_event(const InputEvent &p_event) { } break; } - + //update(); } break; case InputEvent::MOUSE_MOTION: { - + if (invalidated_click) { moved+=Vector2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); @@ -409,13 +409,13 @@ bool PopupMenu::has_point(const Point2& p_point) const { void PopupMenu::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_DRAW: { - + RID ci = get_canvas_item(); Size2 size=get_size(); - + Ref<StyleBox> style = get_stylebox("panel"); Ref<StyleBox> hover = get_stylebox("hover"); Ref<Font> font = get_font("font"); @@ -423,7 +423,7 @@ void PopupMenu::_notification(int p_what) { Ref<Texture> uncheck = get_icon("unchecked"); Ref<Texture> submenu= get_icon("submenu"); Ref<StyleBox> separator = get_stylebox("separator"); - + style->draw( ci, Rect2( Point2(), get_size() ) ); Point2 ofs=style->get_offset(); int vseparation = get_constant("vseparation"); @@ -433,36 +433,36 @@ void PopupMenu::_notification(int p_what) { Color font_color_accel = get_color("font_color_accel"); Color font_color_hover = get_color("font_color_hover"); float font_h=font->get_height(); - + for (int i=0;i<items.size();i++) { - + if (i>0) ofs.y+=vseparation; Point2 item_ofs=ofs; float h; Size2 icon_size; - + if (!items[i].icon.is_null()) { - + icon_size = items[i].icon->get_size(); h = MAX( icon_size.height, font_h ); } else { - + h=font_h; } - + if (i==mouse_over) { - + hover->draw(ci, Rect2( ofs+Point2(-hseparation,-vseparation), Size2( get_size().width - style->get_minimum_size().width + hseparation*2, h+vseparation*2 ) )); } - + if (items[i].separator) { - + int sep_h=separator->get_center_size().height+separator->get_minimum_size().height; separator->draw(ci, Rect2( ofs+Point2(0,Math::floor((h-sep_h)/2.0)), Size2( get_size().width - style->get_minimum_size().width , sep_h ) )); - + } - + if (items[i].checkable) { if (items[i].checked) @@ -499,16 +499,16 @@ void PopupMenu::_notification(int p_what) { items[i]._ofs_cache=ofs.y; ofs.y+=h; - + } - + } break; case NOTIFICATION_MOUSE_ENTER: { grab_focus(); } break; case NOTIFICATION_MOUSE_EXIT: { - + if (mouse_over>=0) { mouse_over=-1; update(); @@ -574,7 +574,7 @@ void PopupMenu::set_item_text(int p_idx,const String& p_text) { ERR_FAIL_INDEX(p_idx,items.size()); items[p_idx].text=XL_MESSAGE(p_text); - + update(); } @@ -597,8 +597,8 @@ void PopupMenu::set_item_checked(int p_idx,bool p_checked) { void PopupMenu::set_item_ID(int p_idx,int p_ID) { ERR_FAIL_INDEX(p_idx,items.size()); - items[p_idx].ID=p_ID; - + items[p_idx].ID=p_ID; + update(); } @@ -785,7 +785,7 @@ void PopupMenu::add_separator() { items.push_back(sep); update(); } - + void PopupMenu::clear() { items.clear(); @@ -888,7 +888,7 @@ void PopupMenu::clear_autohide_areas(){ void PopupMenu::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_input_event"),&PopupMenu::_input_event); + ObjectTypeDB::bind_method(_MD("_input_event"),&PopupMenu::_input_event); ObjectTypeDB::bind_method(_MD("add_icon_item","texture","label","id","accel"),&PopupMenu::add_icon_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_item","label","id","accel"),&PopupMenu::add_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_icon_check_item","texture","label","id","accel"),&PopupMenu::add_icon_check_item,DEFVAL(-1),DEFVAL(0)); @@ -916,7 +916,7 @@ void PopupMenu::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_item_ID","idx"),&PopupMenu::get_item_ID); ObjectTypeDB::bind_method(_MD("get_item_index","id"),&PopupMenu::get_item_index); ObjectTypeDB::bind_method(_MD("get_item_count"),&PopupMenu::get_item_count); - ObjectTypeDB::bind_method(_MD("add_separator"),&PopupMenu::add_separator); + ObjectTypeDB::bind_method(_MD("add_separator"),&PopupMenu::add_separator); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&PopupMenu::remove_item); ObjectTypeDB::bind_method(_MD("clear"),&PopupMenu::clear); @@ -930,7 +930,7 @@ void PopupMenu::_bind_methods() { ADD_SIGNAL( MethodInfo("item_pressed", PropertyInfo( Variant::INT,"ID") ) ); } - + void PopupMenu::set_invalidate_click_until_motion() { moved=Vector2(); @@ -941,7 +941,7 @@ PopupMenu::PopupMenu() { mouse_over=-1; - + set_focus_mode(FOCUS_ALL); set_as_toplevel(true); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 624f4f542a..72f8795067 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -37,7 +37,7 @@ class PopupMenu : public Popup { OBJ_TYPE(PopupMenu, Popup ); - + struct Item { Ref<Texture> icon; String text; @@ -45,16 +45,16 @@ class PopupMenu : public Popup { bool checkable; bool separator; bool disabled; - int ID; + int ID; Variant metadata; String submenu; String tooltip; uint32_t accel; int _ofs_cache; - + Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; } }; - + Timer *submenu_timer; List<Rect2> autohide_areas; @@ -64,7 +64,7 @@ class PopupMenu : public Popup { Rect2 parent_rect; String _get_accel_text(uint32_t p_accel) const; int _get_mouse_over(const Point2& p_over) const; - virtual Size2 get_minimum_size() const; + virtual Size2 get_minimum_size() const; void _input_event(const InputEvent &p_event); void _activate_submenu(int over); void _submenu_timeout(); @@ -79,11 +79,11 @@ protected: virtual bool has_point(const Point2& p_point) const; -friend class MenuButton; +friend class MenuButton; void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: - + void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0); @@ -92,7 +92,7 @@ public: void set_item_text(int p_idx,const String& p_text); void set_item_icon(int p_idx,const Ref<Texture>& p_icon); - void set_item_checked(int p_idx,bool p_checked); + void set_item_checked(int p_idx,bool p_checked); void set_item_ID(int p_idx,int p_ID); void set_item_accelerator(int p_idx,uint32_t p_accel); void set_item_metadata(int p_idx,const Variant& p_meta); @@ -110,7 +110,7 @@ public: uint32_t get_item_accelerator(int p_idx) const; Variant get_item_metadata(int p_idx) const; bool is_item_disabled(int p_idx) const; - String get_item_submenu(int p_ID) const; + String get_item_submenu(int p_ID) const; bool is_item_separator(int p_idx) const; bool is_item_checkable(int p_idx) const; String get_item_tooltip(int p_idx) const; @@ -121,9 +121,9 @@ public: void activate_item(int p_item); void remove_item(int p_idx); - + void add_separator(); - + void clear(); void set_parent_rect(const Rect2& p_rect); @@ -137,7 +137,7 @@ public: void set_invalidate_click_until_motion(); - PopupMenu(); + PopupMenu(); ~PopupMenu(); }; diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index ffcdf98519..b00fcfe42c 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -67,14 +67,14 @@ void Range::Shared::emit_changed(const char *p_what) { void Range::set_val(double p_val) { - + if(_rounded_values){ p_val = Math::round(p_val); } - + if (p_val>shared->max-shared->page) p_val=shared->max-shared->page; - + if (p_val<shared->min) p_val=shared->min; @@ -84,58 +84,58 @@ void Range::set_val(double p_val) { if (shared->val==p_val) return; - + shared->val=p_val; - + shared->emit_value_changed(); } void Range::set_min(double p_min) { - + shared->min=p_min; set_val(shared->val); - + shared->emit_changed("range/min"); } void Range::set_max(double p_max) { - + shared->max=p_max; set_val(shared->val); - + shared->emit_changed("range/max"); } void Range::set_step(double p_step) { - + shared->step=p_step; shared->emit_changed("range/step"); } void Range::set_page(double p_page) { - + shared->page=p_page; set_val(shared->val); - + shared->emit_changed("range/page"); } double Range::get_val() const { - + return shared->val; } double Range::get_min() const { - + return shared->min; } double Range::get_max() const { - + return shared->max; } double Range::get_step() const { - + return shared->step; } double Range::get_page() const { - + return shared->page; } diff --git a/scene/gui/range.h b/scene/gui/range.h index d96ecdfb0b..85c3687b7d 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Range : public Control { - + OBJ_TYPE( Range, Control ); @@ -57,15 +57,15 @@ class Range : public Control { void _value_changed_notify(); void _changed_notify(const char *p_what=""); -protected: +protected: virtual void _value_changed(double) {} static void _bind_methods(); - + bool _rounded_values; public: - + void set_val(double p_val); void set_min(double p_min); void set_max(double p_max); @@ -89,7 +89,7 @@ public: void share(Range *p_range); void unshare(); - Range(); + Range(); ~Range(); }; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index d4ac2652dc..98bc0b9434 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -237,7 +237,7 @@ if (m_height > line_height) {\ if (font.is_null()) font=p_base_font; - const CharType *c = text->text.c_str(); + const CharType *c = text->text.c_str(); const CharType *cf=c; int fh=font->get_height(); int ascent = font->get_ascent(); @@ -297,7 +297,7 @@ if (m_height > line_height) {\ fw+=cw; } - end++; + end++; } ENSURE_WIDTH(w); @@ -2058,7 +2058,7 @@ RichTextLabel::RichTextLabel() { scroll_active=true; scroll_w=0; - vscroll = memnew( VScrollBar ); + vscroll = memnew( VScrollBar ); add_child(vscroll); vscroll->set_drag_slave(String("..")); vscroll->set_step(1); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 0fd4286f38..d8365feb24 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -35,7 +35,7 @@ bool ScrollBar::focus_by_default=false; void ScrollBar::set_can_focus_by_default(bool p_can_focus) { - + focus_by_default=p_can_focus; } @@ -43,14 +43,14 @@ void ScrollBar::_input_event(InputEvent p_event) { switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b=p_event.mouse_button; accept_event(); if (b.button_index==5 && b.pressed) { - + //if (orientation==VERTICAL) // set_val( get_val() + get_page() / 4.0 ); //else @@ -58,16 +58,16 @@ void ScrollBar::_input_event(InputEvent p_event) { accept_event(); } - + if (b.button_index==4 && b.pressed) { - + //if (orientation==HORIZONTAL) // set_val( get_val() - get_page() / 4.0 ); //else set_val( get_val() - get_page() / 4.0 ); accept_event(); } - + if (b.button_index!=1) return; @@ -78,177 +78,177 @@ void ScrollBar::_input_event(InputEvent p_event) { double ofs = orientation==VERTICAL ? b.y : b.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double grabber_ofs = get_grabber_offset(); double grabber_size = get_grabber_size(); double total = orientation==VERTICAL ? get_size().height : get_size().width; - + if (ofs < decr_size ) { - + set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); break; } - + if (ofs > total-incr_size ) { - + set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); break; } - + ofs-=decr_size; - + if ( ofs < grabber_ofs ) { - + set_val( get_val() - get_page() ); break; - - } - + + } + ofs-=grabber_ofs; - + if (ofs < grabber_size ) { - + drag.active=true; drag.pos_at_click=grabber_ofs+ofs; - drag.value_at_click=get_unit_value(); + drag.value_at_click=get_unit_value(); update(); } else { - - + + set_val( get_val() + get_page() ); } - - + + } else { - + drag.active=false; update(); } - + } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion &m=p_event.mouse_motion; accept_event(); - + if (drag.active) { - + double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); ofs-=decr_size; - + double diff = (ofs-drag.pos_at_click) / get_area_size(); - set_unit_value( drag.value_at_click + diff ); + set_unit_value( drag.value_at_click + diff ); } else { - - + + double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double total = orientation==VERTICAL ? get_size().height : get_size().width; - + HiliteStatus new_hilite; - + if (ofs < decr_size ) { - + new_hilite=HILITE_DECR; - + } else if (ofs > total-incr_size ) { - + new_hilite=HILITE_INCR; - + } else { - + new_hilite=HILITE_RANGE; } - + if (new_hilite!=hilite) { - + hilite=new_hilite; update(); - + } - + } } break; case InputEvent::KEY: { - + const InputEventKey &k=p_event.key; - + if (!k.pressed) return; - + switch (k.scancode) { - + case KEY_LEFT: { - + if (orientation!=HORIZONTAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_RIGHT: { - + if (orientation!=HORIZONTAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_UP: { - + if (orientation!=VERTICAL) return; - + set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); - - + + } break; case KEY_DOWN: { - + if (orientation!=VERTICAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_HOME: { - + set_val( get_min() ); - + } break; case KEY_END: { - + set_val( get_max() ); - + } break; - + } break; - } + } } } void ScrollBar::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - + Ref<Texture> decr = hilite==HILITE_DECR ? get_icon("decrement_hilite") : get_icon("decrement"); Ref<Texture> incr = hilite==HILITE_INCR ? get_icon("increment_hilite") : get_icon("increment"); Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll"); Ref<StyleBox> grabber = (drag.active || hilite==HILITE_RANGE) ? get_stylebox("grabber_hilite") : get_stylebox("grabber"); - + Point2 ofs; - + VisualServer *vs = VisualServer::get_singleton(); vs->canvas_item_add_texture_rect( ci, Rect2( Point2(), decr->get_size()),decr->get_rid() ); @@ -266,33 +266,33 @@ void ScrollBar::_notification(int p_what) { area.height-=incr->get_height()+decr->get_height(); bg->draw(ci,Rect2(ofs,area)); - - if (orientation==HORIZONTAL) + + if (orientation==HORIZONTAL) ofs.width+=area.width; else ofs.height+=area.height; vs->canvas_item_add_texture_rect( ci, Rect2( ofs, decr->get_size()),incr->get_rid() ); Rect2 grabber_rect; - + if (orientation==HORIZONTAL) { - + grabber_rect.size.width=get_grabber_size(); grabber_rect.size.height=get_size().height; grabber_rect.pos.y=0; grabber_rect.pos.x=get_grabber_offset()+decr->get_width()+bg->get_margin( MARGIN_LEFT ); } else { - + grabber_rect.size.width=get_size().width; grabber_rect.size.height=get_grabber_size(); grabber_rect.pos.y=get_grabber_offset()+decr->get_height()+bg->get_margin( MARGIN_TOP ); - grabber_rect.pos.x=0; + grabber_rect.pos.x=0; } - + grabber->draw(ci,grabber_rect); - + } - + if (p_what==NOTIFICATION_ENTER_TREE) { @@ -405,48 +405,48 @@ void ScrollBar::_notification(int p_what) { } if (p_what==NOTIFICATION_MOUSE_EXIT) { - + hilite=HILITE_NONE; update(); } } double ScrollBar::get_grabber_min_size() const { - + Ref<StyleBox> grabber=get_stylebox("grabber"); Size2 gminsize=grabber->get_minimum_size()+grabber->get_center_size(); - return (orientation==VERTICAL)?gminsize.height:gminsize.width; + return (orientation==VERTICAL)?gminsize.height:gminsize.width; } double ScrollBar::get_grabber_size() const { - + float range = get_max()-get_min(); if (range<=0) return 0; - + float page = (get_page()>0)? get_page() : 0; // if (grabber_range < get_step()) // grabber_range=get_step(); - + double area_size=get_area_size(); double grabber_size = page / range * area_size; return grabber_size+get_grabber_min_size(); - -} + +} double ScrollBar::get_area_size() const { - + if (orientation==VERTICAL) { - + double area=get_size().height; area-=get_stylebox("scroll")->get_minimum_size().height; area-=get_icon("increment")->get_height(); area-=get_icon("decrement")->get_height(); area-=get_grabber_min_size(); return area; - + } else if (orientation==HORIZONTAL) { - + double area=get_size().width; area-=get_stylebox("scroll")->get_minimum_size().width; area-=get_icon("increment")->get_width(); @@ -454,38 +454,38 @@ double ScrollBar::get_area_size() const { area-=get_grabber_min_size(); return area; } else { - + return 0; } - + } double ScrollBar::get_area_offset() const { - + double ofs=0; - + if (orientation==VERTICAL) { - + ofs+=get_stylebox("hscroll")->get_margin( MARGIN_TOP ); ofs+=get_icon("decrement")->get_height(); - } - + } + if (orientation==HORIZONTAL) { - + ofs+=get_stylebox("hscroll")->get_margin( MARGIN_LEFT ); ofs+=get_icon("decrement")->get_width(); } - - return ofs; + + return ofs; } double ScrollBar::get_click_pos(const Point2& p_pos) const { - - + + float pos=(orientation==VERTICAL)?p_pos.y:p_pos.x; pos-=get_area_offset(); - + float area=get_area_size(); if (area==0) return 0; @@ -495,8 +495,8 @@ double ScrollBar::get_click_pos(const Point2& p_pos) const { } double ScrollBar::get_grabber_offset() const { - - + + return (get_area_size()) * get_unit_value(); } @@ -504,30 +504,30 @@ double ScrollBar::get_grabber_offset() const { Size2 ScrollBar::get_minimum_size() const { - + Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); Ref<StyleBox> bg = get_stylebox("scroll"); Size2 minsize; - + if (orientation==VERTICAL) { - + minsize.width=MAX(incr->get_size().width,(bg->get_minimum_size()+bg->get_center_size()).width); minsize.height+=incr->get_size().height; minsize.height+=decr->get_size().height; minsize.height+=bg->get_minimum_size().height; minsize.height+=get_grabber_min_size(); } - + if (orientation==HORIZONTAL) { - + minsize.height=MAX(incr->get_size().height,(bg->get_center_size()+bg->get_minimum_size()).height); minsize.width+=incr->get_size().width; minsize.width+=decr->get_size().width; minsize.width+=bg->get_minimum_size().width; minsize.width+=get_grabber_min_size(); } - + return minsize; } @@ -671,65 +671,65 @@ NodePath ScrollBar::get_drag_slave() const{ #if 0 void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) { - - // wheel! - + + // wheel! + if (b.button_index==BUTTON_WHEEL_UP && b.pressed) { - + if (orientation==VERTICAL) set_val( get_val() - get_page() / 4.0 ); else set_val( get_val() + get_page() / 4.0 ); - + } if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) { - + if (orientation==HORIZONTAL) set_val( get_val() - get_page() / 4.0 ); else set_val( get_val() + get_page() / 4.0 ); } - + if (b.button_index!=BUTTON_LEFT) return; - + if (b.pressed) { - + int ofs = orientation==VERTICAL ? p_pos.y : p_pos.x ; int grabber_ofs = get_grabber_offset(); int grabber_size = get_grabber_size(); - + if ( ofs < grabber_ofs ) { - + set_val( get_val() - get_page() ); - + } else if (ofs > grabber_ofs + grabber_size ) { - + set_val( get_val() + get_page() ); - + } else { - - + + drag.active=true; drag.pos_at_click=get_click_pos(p_pos); drag.value_at_click=get_unit_value(); } - - + + } else { - + drag.active=false; } - + } void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.button_index_mask) { - + if (!drag.active) return; - + double value_ofs=drag.value_at_click+(get_click_pos(p_pos)-drag.pos_at_click); - - + + value_ofs=value_ofs*( get_max() - get_min() ); if (value_ofs<get_min()) value_ofs=get_min(); @@ -737,64 +737,64 @@ void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.but value_ofs=get_max()-get_page(); if (get_val()==value_ofs) return; //dont bother if the value is the same - + set_val( value_ofs ); - + } bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b.pressed,bool p_repeat,int p_modifier_mask) { - + if (!b.pressed) return false; - + switch (p_scan_code) { - + case KEY_LEFT: { - + if (orientation!=HORIZONTAL) return false; set_val( get_val() - get_step() ); - + } break; case KEY_RIGHT: { - + if (orientation!=HORIZONTAL) return false; set_val( get_val() + get_step() ); - + } break; case KEY_UP: { - + if (orientation!=VERTICAL) return false; - + set_val( get_val() - get_step() ); - - + + } break; case KEY_DOWN: { - + if (orientation!=VERTICAL) return false; set_val( get_val() + get_step() ); - + } break; case KEY_HOME: { - + set_val( get_min() ); - + } break; case KEY_END: { - + set_val( get_max() ); - + } break; - + default: return false; - + } - + return true; } @@ -823,7 +823,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) hilite=HILITE_NONE; custom_step=-1; drag_slave=NULL; - + drag.active=false; drag_slave_speed=Vector2(); @@ -833,7 +833,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) if (focus_by_default) set_focus_mode( FOCUS_ALL ); - + } diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index a629ddc56c..c68db02b33 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -36,40 +36,40 @@ @author Juan Linietsky <reduzio@gmail.com> */ class ScrollBar : public Range { - + OBJ_TYPE( ScrollBar, Range ); - + enum HiliteStatus { HILITE_NONE, HILITE_DECR, HILITE_RANGE, - HILITE_INCR, + HILITE_INCR, }; - + static bool focus_by_default; - + Orientation orientation; Size2 size; float custom_step; - + HiliteStatus hilite; - + struct Drag { - + bool active; float pos_at_click; float value_at_click; } drag; - - + + double get_grabber_size() const; double get_grabber_min_size() const; double get_area_size() const; double get_area_offset() const; double get_click_pos(const Point2& p_pos) const; double get_grabber_offset() const; - - static void set_can_focus_by_default(bool p_can_focus); + + static void set_can_focus_by_default(bool p_can_focus); Node* drag_slave; NodePath drag_slave_path; @@ -86,12 +86,12 @@ class ScrollBar : public Range { void _drag_slave_exit(); void _drag_slave_input(const InputEvent& p_input); - + void _input_event(InputEvent p_event); -protected: +protected: void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: @@ -101,25 +101,25 @@ public: void set_drag_slave(const NodePath& p_path); NodePath get_drag_slave() const; - virtual Size2 get_minimum_size() const; - ScrollBar(Orientation p_orientation=VERTICAL); + virtual Size2 get_minimum_size() const; + ScrollBar(Orientation p_orientation=VERTICAL); ~ScrollBar(); }; class HScrollBar : public ScrollBar { - + OBJ_TYPE( HScrollBar, ScrollBar ); public: - + HScrollBar() : ScrollBar(HORIZONTAL) { set_v_size_flags(0); } }; class VScrollBar : public ScrollBar { - + OBJ_TYPE( VScrollBar, ScrollBar ); public: - + VScrollBar() : ScrollBar(VERTICAL) { set_h_size_flags(0); } }; diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 7ef9d4216b..f66f909517 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -231,13 +231,13 @@ void Slider::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&Slider::_input_event); ObjectTypeDB::bind_method(_MD("set_ticks","count"),&Slider::set_ticks); ObjectTypeDB::bind_method(_MD("get_ticks"),&Slider::get_ticks); - - ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"),&Slider::get_ticks_on_borders); + + ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"),&Slider::get_ticks_on_borders); ObjectTypeDB::bind_method(_MD("set_ticks_on_borders","ticks_on_border"),&Slider::set_ticks_on_borders); - + ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") ); - + } Slider::Slider(Orientation p_orientation) { diff --git a/scene/gui/slider.h b/scene/gui/slider.h index f85e6d1807..cf009b9a75 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -53,7 +53,7 @@ protected: void _notification(int p_what); static void _bind_methods(); bool ticks_on_borders; - + public: virtual Size2 get_minimum_size() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 91d0fc157e..1c6a97bab8 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "tab_container.h" - + #include "message_queue.h" @@ -209,7 +209,7 @@ void TabContainer::_notification(int p_what) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> incr_hl = get_icon("increment_hilite"); Ref<Texture> decr = get_icon("decrement"); - Ref<Texture> decr_hl = get_icon("decrement_hilite"); + Ref<Texture> decr_hl = get_icon("decrement_hilite"); Ref<Texture> menu = get_icon("menu"); Ref<Texture> menu_hl = get_icon("menu_hl"); Ref<Font> font = get_font("font"); diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index c3e75842c3..9692d08882 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -493,7 +493,7 @@ void Tabs::set_current_tab(int p_current) { ERR_FAIL_INDEX( p_current, get_tab_count() ); //printf("DEBUG %p: set_current_tab to %i\n", this, p_current); - current=p_current; + current=p_current; _change_notify("current_tab"); //emit_signal("tab_changed",current); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 96c3d28650..32f4be5d17 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -38,12 +38,12 @@ #define TAB_PIXELS static bool _is_text_char(CharType c) { - + return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; } static bool _is_symbol(CharType c) { - + return c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t'); } @@ -84,81 +84,81 @@ static CharType _get_right_pair_symbol(CharType c) { } void TextEdit::Text::set_font(const Ref<Font>& p_font) { - + font=p_font; } void TextEdit::Text::set_tab_size(int p_tab_size) { - + tab_size=p_tab_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 len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); - + //update width - + for(int i=0;i<len;i++) { if (str[i]=='\t') { - + int left = w%tab_w; if (left==0) w+=tab_w; else w+=tab_w-w%tab_w; // is right... - + } else { - + w+=font->get_char_size(str[i],str[i+1]).width; } } - - + + text[p_line].width_cache=w; - + //update regions - + text[p_line].region_info.clear(); - + for(int i=0;i<len;i++) { - + if (!_is_symbol(str[i])) continue; if (str[i]=='\\') { i++; //skip quoted anything continue; } - + int left=len-i; - + for(int j=0;j<color_regions->size();j++) { - + const ColorRegion& cr=color_regions->operator [](j); - + /* BEGIN */ - + int lr=cr.begin_key.length(); if (lr==0 || lr>left) continue; - + const CharType* kc = cr.begin_key.c_str(); - + bool match=true; - + for(int k=0;k<lr;k++) { if (kc[k]!=str[i+k]) { match=false; break; } } - + if (match) { - + ColorRegionInfo cri; cri.end=false; cri.region=j; @@ -166,26 +166,26 @@ void TextEdit::Text::_update_line_cache(int p_line) const { i+=lr-1; break; } - + /* END */ - + lr=cr.end_key.length(); if (lr==0 || lr>left) continue; - + kc = cr.end_key.c_str(); - + match=true; - + for(int k=0;k<lr;k++) { if (kc[k]!=str[i+k]) { match=false; break; } } - + if (match) { - + ColorRegionInfo cri; cri.end=true; cri.region=j; @@ -193,72 +193,72 @@ void TextEdit::Text::_update_line_cache(int p_line) const { i+=lr-1; break; } - + } } - - + + } const Map<int,TextEdit::Text::ColorRegionInfo>& TextEdit::Text::get_color_region_info(int p_line) { - + Map<int,ColorRegionInfo> *cri=NULL; ERR_FAIL_INDEX_V(p_line,text.size(),*cri); //enjoy your crash - + if (text[p_line].width_cache==-1) { _update_line_cache(p_line); } - + return text[p_line].region_info; } int TextEdit::Text::get_line_width(int p_line) const { - + ERR_FAIL_INDEX_V(p_line,text.size(),-1); - + if (text[p_line].width_cache==-1) { _update_line_cache(p_line); } - + return text[p_line].width_cache; } void TextEdit::Text::clear_caches() { - + for(int i=0;i<text.size();i++) text[i].width_cache=-1; - + } void TextEdit::Text::clear() { - - + + text.clear();; insert(0,""); } int TextEdit::Text::get_max_width() const { //quite some work.. but should be fast enough. - + int max = 0; - + for(int i=0;i<text.size();i++) max=MAX(max,get_line_width(i)); return max; - + } void TextEdit::Text::set(int p_line,const String& p_text) { - + ERR_FAIL_INDEX(p_line,text.size()); - + text[p_line].width_cache=-1; text[p_line].data=p_text; } void TextEdit::Text::insert(int p_at,const String& p_text) { - + Line line; line.marked=false; line.breakpoint=false; @@ -267,26 +267,26 @@ void TextEdit::Text::insert(int p_at,const String& p_text) { text.insert(p_at,line); } void TextEdit::Text::remove(int p_at) { - + text.remove(p_at); } void TextEdit::_update_scrollbars() { - - + + Size2 size = get_size(); Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - - - + + + v_scroll->set_begin( Point2(size.width - vmin.width, cache.style_normal->get_margin(MARGIN_TOP)) ); v_scroll->set_end( Point2(size.width, size.height - cache.style_normal->get_margin(MARGIN_TOP) - cache.style_normal->get_margin(MARGIN_BOTTOM)) ); - + h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); - - + + int hscroll_rows = ((hmin.height-1)/get_row_height())+1; int visible_rows = get_visible_rows(); int total_rows = text.size(); @@ -297,59 +297,59 @@ void TextEdit::_update_scrollbars() { int vscroll_pixels = v_scroll->get_combined_minimum_size().width; int visible_width = size.width - cache.style_normal->get_minimum_size().width; int total_width = text.get_max_width() + vmin.x; - + if (line_numbers) total_width += cache.line_number_w; - + bool use_hscroll=true; bool use_vscroll=true; - + if (total_rows <= visible_rows && total_width <= visible_width) { //thanks yessopie for this clever bit of logic use_hscroll=false; use_vscroll=false; - + } else { - + if (total_rows > visible_rows && total_width <= visible_width - vscroll_pixels) { //thanks yessopie for this clever bit of logic use_hscroll=false; } - + if (total_rows <= visible_rows - hscroll_rows && total_width > visible_width) { //thanks yessopie for this clever bit of logic use_vscroll=false; } } - + updating_scrolls=true; - + if (use_vscroll) { - + v_scroll->show(); v_scroll->set_max(total_rows); v_scroll->set_page(visible_rows); v_scroll->set_val(cursor.line_ofs); - + } else { cursor.line_ofs = 0; v_scroll->hide(); } - + if (use_hscroll) { - + h_scroll->show(); h_scroll->set_max(total_width); h_scroll->set_page(visible_width); h_scroll->set_val(cursor.x_ofs); - + } else { - + h_scroll->hide(); } - - - + + + updating_scrolls=false; } @@ -378,32 +378,32 @@ void TextEdit::_click_selection_held() { void TextEdit::_notification(int p_what) { - + switch(p_what) { case NOTIFICATION_ENTER_TREE: { - + _update_caches(); if (cursor_changed_dirty) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); if (text_changed_dirty) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); - + } break; case NOTIFICATION_RESIZED: { - + cache.size=get_size(); adjust_viewport_to_cursor(); - - + + } break; case NOTIFICATION_THEME_CHANGED: { - + _update_caches(); }; case NOTIFICATION_DRAW: { - + int line_number_char_count=0; - + { int lc=text.size()+1; cache.line_number_w=0; @@ -411,20 +411,20 @@ void TextEdit::_notification(int p_what) { cache.line_number_w+=1; lc/=10; }; - + if (line_numbers) { - + line_number_char_count=cache.line_number_w; cache.line_number_w=(cache.line_number_w+1)*cache.font->get_char_size('0').width; } else { cache.line_number_w=0; } - - + + } _update_scrollbars(); - - + + RID ci = get_canvas_item(); int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w; int xmargin_end=cache.size.width-cache.style_normal->get_margin(MARGIN_RIGHT); @@ -432,56 +432,56 @@ void TextEdit::_notification(int p_what) { cache.style_normal->draw(ci,Rect2(Point2(),cache.size)); if (has_focus()) cache.style_focus->draw(ci,Rect2(Point2(),cache.size)); - - + + int ascent=cache.font->get_ascent(); - + int visible_rows = get_visible_rows(); - + int tab_w = cache.font->get_char_size(' ').width*tab_size; - + Color color = cache.font_color; int in_region=-1; - + if (syntax_coloring) { - + if (custom_bg_color.a>0.01) { - + Point2i ofs = Point2i(cache.style_normal->get_offset())/2.0; VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(ofs, get_size()-cache.style_normal->get_minimum_size()+ofs),custom_bg_color); } //compute actual region to start (may be inside say, a comment). //slow in very large documments :( but ok for source! - + for(int i=0;i<cursor.line_ofs;i++) { - + const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(i); - + if (in_region>=0 && color_regions[in_region].line_only) { in_region=-1; //reset regions that end at end of line } - + for( const Map<int,Text::ColorRegionInfo>::Element* E= cri_map.front();E;E=E->next() ) { - + const Text::ColorRegionInfo &cri=E->get(); - + if (in_region==-1) { - + if (!cri.end) { - + in_region=cri.region; } } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise - + if (cri.end || color_regions[cri.region].eq) { - + in_region=-1; } } } } } - + int brace_open_match_line=-1; int brace_open_match_column=-1; bool brace_open_matching=false; @@ -490,15 +490,15 @@ void TextEdit::_notification(int p_what) { int brace_close_match_column=-1; bool brace_close_matching=false; bool brace_close_mismatch=false; - - + + if (brace_matching_enabled) { - + if (cursor.column<text[cursor.line].length()) { //check for open CharType c = text[cursor.line][cursor.column]; CharType closec=0; - + if (c=='[') { closec=']'; } else if (c=='{') { @@ -506,17 +506,17 @@ void TextEdit::_notification(int p_what) { } else if (c=='(') { closec=')'; } - + if (closec!=0) { - + int stack=1; - - + + for(int i=cursor.line;i<text.size();i++) { - + int from = i==cursor.line?cursor.column+1:0; for(int j=from;j<text[i].length();j++) { - + CharType cc = text[i][j]; //ignore any brackets inside a string if (cc== '"' || cc == '\'') { @@ -544,32 +544,32 @@ void TextEdit::_notification(int p_what) { stack++; else if (cc==closec) stack--; - + if (stack==0) { brace_open_match_line=i; brace_open_match_column=j; brace_open_matching=true; - + break; } } if (brace_open_match_line!=-1) break; } - + if (!brace_open_matching) brace_open_mismatch=true; - - + + } } - + if (cursor.column>0) { CharType c = text[cursor.line][cursor.column-1]; CharType closec=0; - - - + + + if (c==']') { closec='['; } else if (c=='}') { @@ -577,17 +577,17 @@ void TextEdit::_notification(int p_what) { } else if (c==')') { closec='('; } - + if (closec!=0) { - + int stack=1; - - + + for(int i=cursor.line;i>=0;i--) { - + int from = i==cursor.line?cursor.column-2:text[i].length()-1; for(int j=from;j>=0;j--) { - + CharType cc = text[i][j]; //ignore any brackets inside a string if (cc== '"' || cc == '\'') { @@ -616,49 +616,49 @@ void TextEdit::_notification(int p_what) { stack++; else if (cc==closec) stack--; - + if (stack==0) { brace_close_match_line=i; brace_close_match_column=j; brace_close_matching=true; - + break; } } if (brace_close_match_line!=-1) break; } - + if (!brace_close_matching) brace_close_mismatch=true; - - + + } - - + + } } - - + + int deregion=0; //force it to clear inrgion Point2 cursor_pos; - + for (int i=0;i<visible_rows;i++) { - + int line=i+cursor.line_ofs; - + if (line<0 || line>=(int)text.size()) continue; - + const String &str=text[line]; - + int char_margin=xmargin_beg-cursor.x_ofs; int char_ofs=0; int ofs_y=i*get_row_height()+cache.line_spacing/2; bool prev_is_char=false; bool in_keyword=false; Color keyword_color; - + if (cache.line_number_w) { Color fcol = cache.font_color; fcol.a*=0.4; @@ -666,190 +666,190 @@ void TextEdit::_notification(int p_what) { while (fc.length() < line_number_char_count) { fc="0"+fc; } - + cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT),ofs_y+cache.font->get_ascent()),fc,fcol); } - + const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(line); - - + + if (text.is_marked(line)) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.mark_color); } - + if (text.is_breakpoint(line)) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.breakpoint_color); } - - + + if (line==cursor.line) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.current_line_color); - + } for (int j=0;j<str.length();j++) { - + //look for keyword - + if (deregion>0) { deregion--; if (deregion==0) in_region=-1; } if (syntax_coloring && deregion==0) { - - + + color = cache.font_color; //reset //find keyword bool is_char = _is_text_char(str[j]); bool is_symbol=_is_symbol(str[j]); - + if (j==0 && in_region>=0 && color_regions[in_region].line_only) { in_region=-1; //reset regions that end at end of line } - + if (is_symbol && cri_map.has(j)) { - - + + const Text::ColorRegionInfo &cri=cri_map[j]; - + if (in_region==-1) { - + if (!cri.end) { - + in_region=cri.region; } } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise - + if (cri.end || color_regions[cri.region].eq) { - + deregion=color_regions[cri.region].eq?color_regions[cri.region].begin_key.length():color_regions[cri.region].end_key.length(); } } } - + if (!is_char) in_keyword=false; - + if (in_region==-1 && !in_keyword && is_char && !prev_is_char) { - + int to=j; while(to<str.length() && _is_text_char(str[to])) to++; - + uint32_t hash = String::hash(&str[j],to-j); StrRange range(&str[j],to-j); - + const Color *col=keywords.custom_getptr(range,hash); - + if (col) { - + in_keyword=true; keyword_color=*col; } } - - + + if (in_region>=0) color=color_regions[in_region].color; else if (in_keyword) color=keyword_color; else if (is_symbol) color=symbol_color; - + prev_is_char=is_char; - + } int char_w; - + //handle tabulator - - + + if (str[j]=='\t') { int left = char_ofs%tab_w; if (left==0) char_w=tab_w; else char_w=tab_w-char_ofs%tab_w; // is right... - + } else { char_w=cache.font->get_char_size(str[j],str[j+1]).width; } - + if ( (char_ofs+char_margin)<xmargin_beg) { char_ofs+=char_w; continue; } - + if ( (char_ofs+char_margin+char_w)>=xmargin_end) { if (syntax_coloring) continue; else break; } - + bool in_selection = (selection.active && line>=selection.from_line && line<=selection.to_line && (line>selection.from_line || j>=selection.from_column) && (line<selection.to_line || j<selection.to_column)); - - + + if (in_selection) { //inside selection! VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2i( char_ofs+char_margin, ofs_y ), Size2i(char_w,get_row_height())),cache.selection_color); } - - + + if (brace_matching_enabled) { if ( (brace_open_match_line==line && brace_open_match_column==j) || (cursor.column==j && cursor.line==line && (brace_open_matching||brace_open_mismatch))) { - + if (brace_open_mismatch) color=cache.brace_mismatch_color; cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color); - + } - + if ( (brace_close_match_line==line && brace_close_match_column==j) || (cursor.column==j+1 && cursor.line==line && (brace_close_matching||brace_close_mismatch))) { - - + + if (brace_close_mismatch) color=cache.brace_mismatch_color; cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color); - + } } - - + + if (str[j]>=32) cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),str[j],str[j+1],in_selection?cache.font_selected_color:color); - + else if (draw_tabs && str[j]=='\t') { int yofs= (get_row_height() - cache.tab_icon->get_height())/2; cache.tab_icon->draw(ci, Point2(char_ofs+char_margin,ofs_y+yofs),in_selection?cache.font_selected_color:color); } - - + + if (cursor.column==j && cursor.line==line) { - + cursor_pos = Point2i( char_ofs+char_margin, ofs_y ); VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color); - - + + } char_ofs+=char_w; - + } - + if (cursor.column==str.length() && cursor.line==line && (char_ofs+char_margin)>=xmargin_beg) { - + cursor_pos=Point2i( char_ofs+char_margin, ofs_y ); VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color); - + } } - + bool completion_below = false; if (completion_active) { // code completion box @@ -861,15 +861,15 @@ void TextEdit::_notification(int p_what) { existing.a=0.2; int scrollw = get_constant("completion_scroll_width"); Color scrollc = get_color("completion_scroll_color"); - - - + + + int lines = MIN(completion_options.size(),maxlines); int w=0; int h=lines*get_row_height(); int nofs = cache.font->get_string_size(completion_base).width; - - + + if (completion_options.size() < 50) { for(int i=0;i<completion_options.size();i++) { int w2=MIN(cache.font->get_string_size(completion_options[i]).x,cmax_width); @@ -879,40 +879,40 @@ void TextEdit::_notification(int p_what) { } else { w=cmax_width; } - + int th = h + csb->get_minimum_size().y; - + if (cursor_pos.y+get_row_height()+th > get_size().height) { completion_rect.pos.y=cursor_pos.y-th; } else { completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y; completion_below = true; } - + if (cursor_pos.x-nofs+w+scrollw > get_size().width) { completion_rect.pos.x=get_size().width-w-scrollw; } else { completion_rect.pos.x=cursor_pos.x-nofs; } - + completion_rect.size.width=w+2; completion_rect.size.height=h; if (completion_options.size()<=maxlines) scrollw=0; - + draw_style_box(csb,Rect2(completion_rect.pos-csb->get_offset(),completion_rect.size+csb->get_minimum_size()+Size2(scrollw,0))); - - + + int line_from = CLAMP(completion_index - lines/2, 0, completion_options.size() - lines); draw_style_box(csel,Rect2(Point2(completion_rect.pos.x,completion_rect.pos.y+(completion_index-line_from)*get_row_height()),Size2(completion_rect.size.width,get_row_height()))); - + draw_rect(Rect2(completion_rect.pos,Size2(nofs,completion_rect.size.height)),existing); - - - - + + + + for(int i=0;i<lines;i++) { - + int l = line_from + i; ERR_CONTINUE( l < 0 || l>= completion_options.size()); Color text_color = cache.font_color; @@ -923,16 +923,16 @@ void TextEdit::_notification(int p_what) { } draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],text_color,completion_rect.size.width); } - + if (scrollw) { //draw a small scroll rectangle to show a position in the options float r = maxlines / (float)completion_options.size(); float o = line_from / (float)completion_options.size(); draw_rect(Rect2(completion_rect.pos.x+completion_rect.size.width,completion_rect.pos.y+o*completion_rect.size.y,scrollw,completion_rect.size.y*r),scrollc); } - + completion_line_ofs=line_from; - + } // check to see if the hint should be drawn @@ -950,20 +950,20 @@ void TextEdit::_notification(int p_what) { show_hint = true; } } - + if (show_hint) { - + Ref<StyleBox> sb = get_stylebox("panel","TooltipPanel"); Ref<Font> font = cache.font; Color font_color = get_color("font_color","TooltipLabel"); - - + + int max_w=0; int sc = completion_hint.get_slice_count("\n"); int offset=0; int spacing=0; for(int i=0;i<sc;i++) { - + String l = completion_hint.get_slice("\n",i); int len = font->get_string_size(l).x; max_w = MAX(len,max_w); @@ -972,21 +972,21 @@ void TextEdit::_notification(int p_what) { } else { spacing+=cache.line_spacing; } - - + + } - - - + + + Size2 size = Size2(max_w,sc*font->get_height()+spacing); Size2 minsize = size+sb->get_minimum_size(); - - + + if (completion_hint_offset==-0xFFFF) { completion_hint_offset=cursor_pos.x-offset; } - - + + Point2 hint_ofs = Vector2(completion_hint_offset,cursor_pos.y) + callhint_offset; if (callhint_below) { @@ -997,18 +997,18 @@ void TextEdit::_notification(int p_what) { } draw_style_box(sb,Rect2(hint_ofs,minsize)); - + spacing=0; for(int i=0;i<sc;i++) { int begin=0; int end=0; String l = completion_hint.get_slice("\n",i); - + if (l.find(String::chr(0xFFFF))!=-1) { begin = font->get_string_size(l.substr(0,l.find(String::chr(0xFFFF)))).x; end = font->get_string_size(l.substr(0,l.rfind(String::chr(0xFFFF)))).x; } - + draw_string(font,hint_ofs+sb->get_offset()+Vector2(0,font->get_ascent()+font->get_height()*i+spacing),l.replace(String::chr(0xFFFF),""),font_color); if (end>0) { Vector2 b = hint_ofs+sb->get_offset()+Vector2(begin,font->get_height()+font->get_height()*i+spacing-1); @@ -1017,60 +1017,60 @@ void TextEdit::_notification(int p_what) { spacing+=cache.line_spacing; } } - - + + } break; case NOTIFICATION_FOCUS_ENTER: { - + if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); - + } break; case NOTIFICATION_FOCUS_EXIT: { - + if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->hide_virtual_keyboard(); - + } break; - + } } void TextEdit::_consume_pair_symbol(CharType ch) { - + int cursor_position_to_move = cursor_get_column() + 1; - + CharType ch_single[2] = {ch, 0}; CharType ch_single_pair[2] = {_get_right_pair_symbol(ch), 0}; CharType ch_pair[3] = {ch, _get_right_pair_symbol(ch), 0}; - + if(is_selection_active()) { - + int new_column,new_line; - + _begin_compex_operation(); _insert_text(get_selection_from_line(), get_selection_from_column(), ch_single, &new_line, &new_column); - + int to_col_offset = 0; if(get_selection_from_line() == get_selection_to_line()) to_col_offset = 1; - + _insert_text(get_selection_to_line(), get_selection_to_column() + to_col_offset, ch_single_pair, &new_line,&new_column); _end_compex_operation(); - + cursor_set_line(get_selection_to_line()); cursor_set_column(get_selection_to_column() + to_col_offset); - + deselect(); update(); return; } - + if( (ch == '\'' || ch == '"') && cursor_get_column() > 0 && _is_text_char(text[cursor.line][cursor_get_column() - 1]) @@ -1079,7 +1079,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) { cursor_set_column(cursor_position_to_move); return; } - + if(cursor_get_column() < text[cursor.line].length()) { if(_is_text_char(text[cursor.line][cursor_get_column()])) { insert_text_at_cursor(ch_single); @@ -1093,34 +1093,34 @@ void TextEdit::_consume_pair_symbol(CharType ch) { return; } } - - + + insert_text_at_cursor(ch_pair); cursor_set_column(cursor_position_to_move); return; - + } void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) { - + bool remove_right_symbol = false; - + if(cursor.column < text[cursor.line].length() && cursor.column > 0) { - + CharType left_char = text[cursor.line][cursor.column - 1]; CharType right_char = text[cursor.line][cursor.column]; - + if(right_char == _get_right_pair_symbol(left_char)) { remove_right_symbol = true; } - + } if(remove_right_symbol) { _remove_text(prev_line,prev_column,cursor.line,cursor.column + 1); } else { _remove_text(prev_line,prev_column,cursor.line,cursor.column); } - + } void TextEdit::backspace_at_cursor() { @@ -1129,7 +1129,7 @@ void TextEdit::backspace_at_cursor() { if (cursor.column==0 && cursor.line==0) return; - + int prev_line = cursor.column?cursor.line:cursor.line-1; int prev_column = cursor.column?(cursor.column-1):(text[cursor.line-1].length()); if(auto_brace_completion_enabled && @@ -1139,15 +1139,15 @@ void TextEdit::backspace_at_cursor() { } else { _remove_text(prev_line,prev_column,cursor.line,cursor.column); } - + cursor_set_line(prev_line); cursor_set_column(prev_column); - + } void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const { - + float rows=p_mouse.y; rows-=cache.style_normal->get_margin(MARGIN_TOP); rows/=get_row_height(); @@ -1157,56 +1157,56 @@ void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) co row=0; int col=0; - + if (row>=text.size()) { - + row=text.size()-1; col=text[row].size(); } else { - + col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w); col+=cursor.x_ofs; col=get_char_pos_for( col, get_line(row) ); } - + r_row=row; r_col=col; } void TextEdit::_input_event(const InputEvent& p_input_event) { - + switch(p_input_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &mb=p_input_event.mouse_button; - + if (completion_active && completion_rect.has_point(Point2(mb.x,mb.y))) { - + if (!mb.pressed) return; - + if (mb.button_index==BUTTON_WHEEL_UP) { if (completion_index>0) { completion_index--; completion_current=completion_options[completion_index]; update(); } - + } if (mb.button_index==BUTTON_WHEEL_DOWN) { - + if (completion_index<completion_options.size()-1) { completion_index++; completion_current=completion_options[completion_index]; update(); } } - + if (mb.button_index==BUTTON_LEFT) { - + completion_index=CLAMP(completion_line_ofs+(mb.y-completion_rect.pos.y)/get_row_height(),0,completion_options.size()-1); - + completion_current=completion_options[completion_index]; update(); if (mb.doubleclick) @@ -1217,7 +1217,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _cancel_completion(); _cancel_code_hint(); } - + if (mb.pressed) { if (mb.button_index==BUTTON_WHEEL_UP) { v_scroll->set_val( v_scroll->get_val() -3 ); @@ -1232,18 +1232,18 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { h_scroll->set_val( h_scroll->get_val() +3 ); } if (mb.button_index==BUTTON_LEFT) { - + int row,col; _get_mouse_pos(Point2i(mb.x,mb.y), row,col); - + int prev_col=cursor.column; int prev_line=cursor.line; - - - + + + cursor_set_line( row ); cursor_set_column( col ); - + if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) { if (!selection.active) { @@ -1298,99 +1298,99 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { - + } else { - + //if sel active and dblick last time < something - + //else selection.active=false; selection.selecting_mode=Selection::MODE_POINTER; selection.selecting_line=row; selection.selecting_column=col; } - - + + if (!mb.doubleclick && (OS::get_singleton()->get_ticks_msec()-last_dblclk)<600 && cursor.line==prev_line) { //tripleclick select line select(cursor.line,0,cursor.line,text[cursor.line].length()); selection.selecting_column=0; last_dblclk=0; - + } else if (mb.doubleclick && text[cursor.line].length()) { - + //doubleclick select world String s = text[cursor.line]; int beg=CLAMP(cursor.column,0,s.length()); int end=beg; - + if (s[beg]>32 || beg==s.length()) { - + bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this - + while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) { beg--; } while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) { end++; } - + if (end<s.length()) end+=1; - + select(cursor.line,beg,cursor.line,end); selection.selecting_column=beg; } - + last_dblclk = OS::get_singleton()->get_ticks_msec(); - + } - + update(); } } else { if (mb.button_index==BUTTON_LEFT) click_select_held->stop(); - + // notify to show soft keyboard notification(NOTIFICATION_FOCUS_ENTER); } - + } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion &mm=p_input_event.mouse_motion; - + if (mm.button_mask&BUTTON_MASK_LEFT) { - + if (selection.selecting_mode!=Selection::MODE_NONE) { int row,col; _get_mouse_pos(Point2i(mm.x,mm.y), row,col); - + select(selection.selecting_line,selection.selecting_column,row,col); - + cursor_set_line( row ); cursor_set_column( col ); update(); click_select_held->start(); - + } - + } - + } break; - + case InputEvent::KEY: { - + InputEventKey k=p_input_event.key; - + if (!k.pressed) return; - + if (completion_active) { if (readonly) break; @@ -1398,9 +1398,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool valid=true; if (k.mod.command || k.mod.meta) valid=false; - + if (valid) { - + if (!k.mod.alt) { if (k.scancode==KEY_UP) { @@ -1499,13 +1499,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { return; } } - + if (k.unicode>32) { - + if (cursor.column<text[cursor.line].length() && text[cursor.line][cursor.column]==k.unicode) { //same char, move ahead cursor_set_column(cursor.column+1); - + } else { //different char, go back const CharType chr[2] = {(CharType)k.unicode, 0}; @@ -1515,34 +1515,34 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _insert_text_at_cursor(chr); } } - + _update_completion_candidates(); accept_event(); - + return; } } - + _cancel_completion(); - + } - + /* TEST CONTROL FIRST!! */ - + // some remaps for duplicate functions.. if (k.mod.command && !k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) { - + k.scancode=KEY_C; } if (!k.mod.command && k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) { - + k.scancode=KEY_V; k.mod.command=true; k.mod.shift=false; } - + // stuff to do when selection is active.. - + if (selection.active) { if (readonly) @@ -1551,16 +1551,16 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool clear=false; bool unselect=false; bool dobreak=false; - + switch(k.scancode) { - + case KEY_TAB: { - + String txt = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); String prev_txt=txt; - + if (k.mod.shift) { - + for(int i=0;i<txt.length();i++) { if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/)) && (txt[i]=='\t' || txt[i]==' ')) { txt.remove(i); @@ -1568,21 +1568,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } } else { - + for(int i=0;i<txt.length();i++) { - + if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/))) { txt=txt.insert(i,"\t"); //i--; } } } - + if (txt!=prev_txt) { - + int sel_line=selection.from_line; int sel_column=selection.from_column; - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); _begin_compex_operation(); @@ -1596,10 +1596,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { selection.to_line=cursor.line; update(); } - + dobreak=true; accept_event(); - + } break; case KEY_X: case KEY_C: @@ -1624,21 +1624,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; unselect=true; break; - + default: if (k.unicode>=32 && !k.mod.command && !k.mod.alt && !k.mod.meta) clear=true; if (auto_brace_completion_enabled && _is_pair_left_symbol(k.unicode)) clear=false; } - + if (unselect) { selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); } if (clear) { - + selection.active=false; update(); _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); @@ -1649,15 +1649,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (dobreak) break; } - + selection.selecting_text=false; - + bool scancode_handled=true; - + // special scancode test... - + switch (k.scancode) { - + case KEY_ENTER: case KEY_RETURN: { @@ -1665,7 +1665,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; String ins="\n"; - + //keep indentation for(int i=0;i<text[cursor.line].length();i++) { if (text[cursor.line][i]=='\t') @@ -1697,37 +1697,37 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { cursor_set_column(text[cursor.line].length()); } } - + _insert_text_at_cursor(ins); _push_current_op(); if (first_line) { cursor_set_line(0); } - + } break; case KEY_ESCAPE: { if (completion_hint!="") { completion_hint=""; update(); - + } } break; case KEY_TAB: { - + if (readonly) break; - + if (selection.active) { - - + + } else { if (k.mod.shift) { - + int cc = cursor.column; if (cc>0 && cc<=text[cursor.line].length() && text[cursor.line][cursor.column-1]=='\t') { //simple unindent - + backspace_at_cursor(); } } else { @@ -1735,7 +1735,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _insert_text_at_cursor("\t"); } } - + } break; case KEY_BACKSPACE: { if (readonly) @@ -1803,15 +1803,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_left } case KEY_LEFT: { - + if (k.mod.shift) _pre_shift_selection(); - + #ifdef APPLE_STYLE_KEYS if (k.mod.command) { cursor_set_column(0); } else if (k.mod.alt) { - + #else if (k.mod.alt) { scancode_handled=false; @@ -1821,21 +1821,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool prev_char=false; int cc=cursor.column; while (cc>0) { - + bool ischar=_is_text_char(text[cursor.line][cc-1]); - + if (prev_char && !ischar) break; - + prev_char=ischar; cc--; - + } - + cursor_set_column(cc); - + } else if (cursor.column==0) { - + if (cursor.line>0) { cursor_set_line(cursor.line-1); cursor_set_column(text[cursor.line].length()); @@ -1843,10 +1843,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { cursor_set_column(cursor_get_column()-1); } - + if (k.mod.shift) _post_shift_selection(); - + } break; case KEY_KP_6: { if (k.unicode != 0) { @@ -1856,10 +1856,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_right } case KEY_RIGHT: { - + if (k.mod.shift) _pre_shift_selection(); - + #ifdef APPLE_STYLE_KEYS if (k.mod.command) { cursor_set_column(text[cursor.line].length()); @@ -1873,19 +1873,19 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool prev_char=false; int cc=cursor.column; while (cc<text[cursor.line].length()) { - + bool ischar=_is_text_char(text[cursor.line][cc]); - + if (prev_char && !ischar) break; prev_char=ischar; cc++; } - + cursor_set_column(cc); - + } else if (cursor.column==text[cursor.line].length()) { - + if (cursor.line<text.size()-1) { cursor_set_line(cursor.line+1); cursor_set_column(0); @@ -1893,10 +1893,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { cursor_set_column(cursor_get_column()+1); } - + if (k.mod.shift) _post_shift_selection(); - + } break; case KEY_KP_8: { if (k.unicode != 0) { @@ -1906,7 +1906,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_up } case KEY_UP: { - + if (k.mod.shift) _pre_shift_selection(); if (k.mod.alt) { @@ -1919,11 +1919,11 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { else #endif cursor_set_line(cursor_get_line()-1); - + if (k.mod.shift) _post_shift_selection(); _cancel_code_hint(); - + } break; case KEY_KP_2: { if (k.unicode != 0) { @@ -1933,7 +1933,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_down } case KEY_DOWN: { - + if (k.mod.shift) _pre_shift_selection(); if (k.mod.alt) { @@ -1946,22 +1946,22 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { else #endif cursor_set_line(cursor_get_line()+1); - + if (k.mod.shift) _post_shift_selection(); _cancel_code_hint(); - + } break; - + case KEY_DELETE: { - + if (readonly) break; int curline_len = text[cursor.line].length(); - + if (cursor.line==text.size()-1 && cursor.column==curline_len) break; //nothing to do - + int next_line=cursor.column<curline_len?cursor.line:cursor.line+1; int next_column; @@ -2029,24 +2029,24 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } #ifdef APPLE_STYLE_KEYS case KEY_HOME: { - - + + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(0); - + if (k.mod.shift) _post_shift_selection(); - + } break; #else case KEY_HOME: { - - + + if (k.mod.shift) _pre_shift_selection(); - + // compute whitespace symbols seq length int current_line_whitespace_len = 0; while(current_line_whitespace_len < text[cursor.line].length()) { @@ -2055,20 +2055,20 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; current_line_whitespace_len++; } - + if(cursor_get_column() == current_line_whitespace_len) cursor_set_column(0); else cursor_set_column(current_line_whitespace_len); - + if (k.mod.command) cursor_set_line(0); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; #endif case KEY_KP_1: { @@ -2092,20 +2092,20 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } break; #else case KEY_END: { - + if (k.mod.shift) _pre_shift_selection(); - + if (k.mod.command) cursor_set_line(text.size()-1); cursor_set_column(text[cursor.line].length()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; #endif case KEY_KP_9: { @@ -2116,19 +2116,19 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_pageup } case KEY_PAGEUP: { - + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(cursor_get_line()-get_visible_rows()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; case KEY_KP_3: { if (k.unicode != 0) { @@ -2138,75 +2138,75 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_pageup } case KEY_PAGEDOWN: { - + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(cursor_get_line()+get_visible_rows()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; case KEY_A: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + select_all(); - + } break; case KEY_X: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + if (!selection.active){ - + String clipboard = text[cursor.line]; OS::get_singleton()->set_clipboard(clipboard); cursor_set_line(cursor.line); cursor_set_column(0); _remove_text(cursor.line,0,cursor.line,text[cursor.line].length()); - + backspace_at_cursor(); update(); cursor_set_line(cursor.line+1); cut_copy_line = true; - + } else { - + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); cut_copy_line = false; } - + } break; case KEY_C: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + if (!selection.active){ String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length()); OS::get_singleton()->set_clipboard(clipboard); @@ -2219,32 +2219,32 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } break; case KEY_Z: { - + if (!k.mod.command) { scancode_handled=false; break; } - + if (k.mod.shift) redo(); else undo(); } break; case KEY_V: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + String clipboard = OS::get_singleton()->get_clipboard(); - + if (selection.active) { selection.active=false; _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + } else if (cut_copy_line) { @@ -2252,9 +2252,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { String ins="\n"; clipboard += ins; } - + _insert_text_at_cursor(clipboard); - + update(); } break; case KEY_SPACE: { @@ -2263,15 +2263,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { #else if (completion_enabled && k.mod.command) { #endif - + query_code_comple(); scancode_handled=true; } else { scancode_handled=false; } - + } break; - + case KEY_U:{ if (!k.mod.command || k.mod.shift) { scancode_handled=false; @@ -2294,40 +2294,40 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { update(); } break;} - + default: { - + scancode_handled=false; } break; - + } - + if (scancode_handled) accept_event(); /* if (!scancode_handled && !k.mod.command && !k.mod.alt) { - + if (k.unicode>=32) { - + if (readonly) break; - + accept_event(); } else { - + break; } } */ if (!scancode_handled && !k.mod.command) { //for german kbds - + if (k.unicode>=32) { - + if (readonly) break; - + const CharType chr[2] = {(CharType)k.unicode, 0}; - + if (completion_hint!="" && k.unicode==')') { completion_hint=""; } @@ -2336,27 +2336,27 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { _insert_text_at_cursor(chr); } - + accept_event(); } else { - + break; } } - + return; } break; - + } - + } void TextEdit::_pre_shift_selection() { - - + + if (!selection.active || selection.selecting_mode==Selection::MODE_NONE) { - + selection.selecting_line=cursor.line; selection.selecting_column=cursor.column; selection.active=true; @@ -2366,115 +2366,115 @@ void TextEdit::_pre_shift_selection() { } void TextEdit::_post_shift_selection() { - - + + if (selection.active && selection.selecting_mode==Selection::MODE_SHIFT) { - + select(selection.selecting_line,selection.selecting_column,cursor.line,cursor.column); update(); } - - + + selection.selecting_text=true; } /**** TEXT EDIT CORE API ****/ void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) { - + //save for undo... ERR_FAIL_INDEX(p_line,text.size()); ERR_FAIL_COND(p_char<0); - + /* STEP 1 add spaces if the char is greater than the end of the line */ while(p_char>text[p_line].length()) { - + text.set(p_line,text[p_line]+String::chr(' ')); } - + /* STEP 2 separate dest string in pre and post text */ - + String preinsert_text = text[p_line].substr(0,p_char); String postinsert_text = text[p_line].substr(p_char,text[p_line].size()); - + /* STEP 3 remove \r from source text and separate in substrings */ - + //buh bye \r and split Vector<String> substrings = p_text.replace("\r","").split("\n"); - - + + for(int i=0;i<substrings.size();i++) { //insert the substrings - + if (i==0) { - + text.set(p_line,preinsert_text+substrings[i]); } else { - + text.insert(p_line+i,substrings[i]); } - + if (i==substrings.size()-1){ - + text.set(p_line+i,text[p_line+i]+postinsert_text); } } - + r_end_line=p_line+substrings.size()-1; r_end_column=text[r_end_line].length()-postinsert_text.length(); - + if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); text_changed_dirty=true; } - + } String TextEdit::_base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const { - + ERR_FAIL_INDEX_V(p_from_line,text.size(),String()); ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,String()); ERR_FAIL_INDEX_V(p_to_line,text.size(),String()); ERR_FAIL_INDEX_V(p_to_column,text[p_to_line].length()+1,String()); ERR_FAIL_COND_V(p_to_line < p_from_line ,String()); // from > to ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column<p_from_column,String()); // from > to - + String ret; - + for(int i=p_from_line;i<=p_to_line;i++) { - + int begin = (i==p_from_line)?p_from_column:0; int end = (i==p_to_line)?p_to_column:text[i].length(); - + if (i>p_from_line) ret+="\n"; ret+=text[i].substr(begin,end-begin); } - + return ret; } void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) { - + ERR_FAIL_INDEX(p_from_line,text.size()); ERR_FAIL_INDEX(p_from_column,text[p_from_line].length()+1); ERR_FAIL_INDEX(p_to_line,text.size()); ERR_FAIL_INDEX(p_to_column,text[p_to_line].length()+1); ERR_FAIL_COND(p_to_line < p_from_line ); // from > to ERR_FAIL_COND(p_to_line == p_from_line && p_to_column<p_from_column); // from > to - - + + String pre_text = text[p_from_line].substr(0,p_from_column); String post_text = text[p_to_line].substr(p_to_column,text[p_to_line].length()); - + for(int i=p_from_line;i<p_to_line;i++) { - + text.remove(p_from_line+1); } - + text.set(p_from_line,pre_text+post_text); - + if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); @@ -2483,24 +2483,24 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_lin } void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) { - + if (!setting_text) idle_detect->start(); - + if (undo_enabled) { _clear_redo(); } - + int retline,retchar; _base_insert_text(p_line,p_char,p_text,retline,retchar); if (r_end_line) *r_end_line=retline; if (r_end_column) *r_end_column=retchar; - + if (!undo_enabled) return; - + /* UNDO!! */ TextOperation op; op.type=TextOperation::TYPE_INSERT; @@ -2512,12 +2512,12 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e op.version=++version; op.chain_forward=false; op.chain_backward=false; - + //see if it shold just be set as current op if (current_op.type!=op.type) { _push_current_op(); current_op=op; - + return; //set as current op, return } //see if it can be merged @@ -2527,30 +2527,30 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e return; //set as current op, return } //merge current op - + current_op.text+=p_text; current_op.to_column=retchar; current_op.to_line=retline; current_op.version=op.version; - + } void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) { - + if (!setting_text) idle_detect->start(); - + String text; if (undo_enabled) { _clear_redo(); text=_base_get_text(p_from_line,p_from_column,p_to_line,p_to_column); } - + _base_remove_text(p_from_line,p_from_column,p_to_line,p_to_column); - + if (!undo_enabled) return; - + /* UNDO!! */ TextOperation op; op.type=TextOperation::TYPE_REMOVE; @@ -2562,7 +2562,7 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int op.version=++version; op.chain_forward=false; op.chain_backward=false; - + //see if it shold just be set as current op if (current_op.type!=op.type) { _push_current_op(); @@ -2578,26 +2578,26 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int return; //update current op } if (current_op.from_line==p_from_line && current_op.from_column==p_from_column) { - + //current_op.text=text+current_op.text; //current_op.from_line=p_from_line; //current_op.from_column=p_from_column; //return; //update current op } - + _push_current_op(); current_op=op; - + } void TextEdit::_insert_text_at_cursor(const String& p_text) { - + int new_column,new_line; _insert_text(cursor.line,cursor.column,p_text,&new_line,&new_column); cursor_set_line(new_line); cursor_set_column(new_column); - + update(); } @@ -2605,144 +2605,144 @@ void TextEdit::_insert_text_at_cursor(const String& p_text) { int TextEdit::get_char_count() { - + int totalsize=0; - + for (int i=0;i<text.size();i++) { - + if (i>0) totalsize++; // incliude \n totalsize+=text[i].length(); } - + return totalsize; // omit last \n } Size2 TextEdit::get_minimum_size() { - + return cache.style_normal->get_minimum_size(); } int TextEdit::get_visible_rows() const { - + int total=cache.size.height; total-=cache.style_normal->get_minimum_size().height; total/=get_row_height(); return total; } void TextEdit::adjust_viewport_to_cursor() { - + if (cursor.line_ofs>cursor.line) cursor.line_ofs=cursor.line; - + int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w; if (v_scroll->is_visible()) visible_width-=v_scroll->get_combined_minimum_size().width; visible_width-=20; // give it a little more space - - + + //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line); - + int visible_rows = get_visible_rows(); if (h_scroll->is_visible()) visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height()); - + if (cursor.line>=(cursor.line_ofs+visible_rows)) cursor.line_ofs=cursor.line-visible_rows+1; if (cursor.line<cursor.line_ofs) cursor.line_ofs=cursor.line; - + int cursor_x = get_column_x_offset( cursor.column, text[cursor.line] ); - + if (cursor_x>(cursor.x_ofs+visible_width)) cursor.x_ofs=cursor_x-visible_width+1; - + if (cursor_x < cursor.x_ofs) cursor.x_ofs=cursor_x; - + update(); /* get_range()->set_max(text.size()); - + get_range()->set_page(get_visible_rows()); - + get_range()->set((int)cursor.line_ofs); */ - - + + } void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) { - + if (p_col<0) p_col=0; - + cursor.column=p_col; if (cursor.column > get_line( cursor.line ).length()) cursor.column=get_line( cursor.line ).length(); - + cursor.last_fit_x=get_column_x_offset(cursor.column,get_line(cursor.line)); - + if (p_adjust_viewport) adjust_viewport_to_cursor(); - + if (!cursor_changed_dirty) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); cursor_changed_dirty=true; } - + } void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport) { - + if (setting_row) return; - + setting_row=true; if (p_row<0) p_row=0; - - + + if (p_row>=(int)text.size()) p_row=(int)text.size()-1; - + cursor.line=p_row; cursor.column=get_char_pos_for( cursor.last_fit_x, get_line( cursor.line) ); - + if (p_adjust_viewport) adjust_viewport_to_cursor(); - + setting_row=false; - - + + if (!cursor_changed_dirty) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); cursor_changed_dirty=true; } - + } int TextEdit::cursor_get_column() const { - + return cursor.column; } int TextEdit::cursor_get_line() const { - + return cursor.line; } void TextEdit::_scroll_moved(double p_to_val) { - + if (updating_scrolls) return; - + if (h_scroll->is_visible()) cursor.x_ofs=h_scroll->get_val(); if (v_scroll->is_visible()) @@ -2755,87 +2755,87 @@ void TextEdit::_scroll_moved(double p_to_val) { int TextEdit::get_row_height() const { - + return cache.font->get_height()+cache.line_spacing; } 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; - + while (c<p_str.length()) { - + int w=0; - + if (p_str[c]=='\t') { - + int left = px%tab_w; if (left==0) w=tab_w; else w=tab_w-px%tab_w; // is right... - + } else { - + w=cache.font->get_char_size(p_str[c],p_str[c+1]).width; } - + if (p_px<(px+w/2)) break; px+=w; c++; } - + return c; } 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; - + for (int i=0;i<p_char;i++) { - + if (i>=p_str.length()) break; - + if (p_str[i]=='\t') { - + int left = px%tab_w; if (left==0) px+=tab_w; else px+=tab_w-px%tab_w; // is right... - + } else { px+=cache.font->get_char_size(p_str[i],p_str[i+1]).width; } } - + return px; - + } void TextEdit::insert_text_at_cursor(const String& p_text) { - + if (selection.active) { - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; - + } - + _insert_text_at_cursor(p_text); update(); - + } Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const { @@ -2847,7 +2847,7 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const { void TextEdit::set_text(String p_text){ - + setting_text=true; clear(); _insert_text_at_cursor(p_text); @@ -2861,7 +2861,7 @@ void TextEdit::set_text(String p_text){ cursor_set_column(0); update(); setting_text=false; - + //get_range()->set(0); }; @@ -2869,53 +2869,53 @@ String TextEdit::get_text() { String longthing; int len = text.size(); for (int i=0;i<len;i++) { - - + + longthing+=text[i]; if (i!=len-1) longthing+="\n"; } - + return longthing; - + }; String TextEdit::get_text_for_completion() { - + String longthing; int len = text.size(); for (int i=0;i<len;i++) { - + if (i==cursor.line) { longthing+=text[i].substr(0,cursor.column); longthing+=String::chr(0xFFFF); //not unicode, represents the cursor longthing+=text[i].substr(cursor.column,text[i].size()); } else { - + longthing+=text[i]; } - - + + if (i!=len-1) longthing+="\n"; } - + return longthing; - + }; String TextEdit::get_line(int line) const { - + if (line<0 || line>=text.size()) return ""; - + return text[line]; - + }; void TextEdit::_clear() { - + clear_undo_history(); text.clear(); cursor.column=0; @@ -2928,31 +2928,31 @@ void TextEdit::_clear() { void TextEdit::clear() { - + setting_text=true; _clear(); setting_text=false; - + }; void TextEdit::set_readonly(bool p_readonly) { - - + + readonly=p_readonly; } void TextEdit::set_wrap(bool p_wrap) { - + wrap=p_wrap; } void TextEdit::set_max_chars(int p_max_chars) { - + max_chars=p_max_chars; } void TextEdit::_update_caches() { - + cache.style_normal=get_stylebox("normal"); cache.style_focus=get_stylebox("focus"); cache.font=get_font("font"); @@ -2968,12 +2968,12 @@ void TextEdit::_update_caches() { cache.row_height = cache.font->get_height() + cache.line_spacing; cache.tab_icon=get_icon("tab"); text.set_font(cache.font); - + } void TextEdit::clear_colors() { - + keywords.clear(); color_regions.clear();; text.clear_caches(); @@ -2981,40 +2981,40 @@ void TextEdit::clear_colors() { } void TextEdit::set_custom_bg_color(const Color& p_color) { - + custom_bg_color=p_color; update(); } void TextEdit::add_keyword_color(const String& p_keyword,const Color& p_color) { - + keywords[p_keyword]=p_color; update(); - + } void TextEdit::add_color_region(const String& p_begin_key,const String& p_end_key,const Color &p_color,bool p_line_only) { - + color_regions.push_back(ColorRegion(p_begin_key,p_end_key,p_color,p_line_only)); text.clear_caches(); update(); - + } void TextEdit::set_symbol_color(const Color& p_color) { - + symbol_color=p_color; update(); } void TextEdit::set_syntax_coloring(bool p_enabled) { - + syntax_coloring=p_enabled; update(); } bool TextEdit::is_syntax_coloring_enabled() const { - + return syntax_coloring; } @@ -3023,28 +3023,28 @@ void TextEdit::set_auto_indent(bool p_auto_indent) { } void TextEdit::cut() { - + if (!selection.active) return; - + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); - + } void TextEdit::copy() { - + if (!selection.active) return; - + print_line("from line: "+itos(selection.from_line)); print_line("from column: "+itos(selection.from_column)); print_line("to line: "+itos(selection.to_line)); @@ -3052,29 +3052,29 @@ void TextEdit::copy() { String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + } void TextEdit::paste() { - + if (selection.active) { - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; - + } - + String clipboard = OS::get_singleton()->get_clipboard(); _insert_text_at_cursor(clipboard); update(); - + } void TextEdit::select_all() { - + if (text.size()==1 && text[0].length()==0) return; selection.active=true; @@ -3089,43 +3089,43 @@ void TextEdit::select_all() { cursor_set_line( selection.to_line, false ); cursor_set_column( selection.to_column, false ); update(); - + } void TextEdit::deselect() { - + selection.active=false; update(); } void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_column) { - + if (p_from_line>=text.size()) p_from_line=text.size()-1; if (p_from_column>=text[p_from_line].length()) p_from_column=text[p_from_line].length(); - + if (p_to_line>=text.size()) p_to_line=text.size()-1; if (p_to_column>=text[p_to_line].length()) p_to_column=text[p_to_line].length(); - + selection.from_line=p_from_line; selection.from_column=p_from_column; selection.to_line=p_to_line; selection.to_column=p_to_column; - + selection.active=true; - + if (selection.from_line==selection.to_line) { - + if (selection.from_column==selection.to_column) { - + selection.active=false; - + } else if (selection.from_column>selection.to_column) { - + selection.shiftclick_left = false; SWAP( selection.from_column, selection.to_column ); } else { @@ -3133,7 +3133,7 @@ void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_c selection.shiftclick_left = true; } } else if (selection.from_line>selection.to_line) { - + selection.shiftclick_left = false; SWAP( selection.from_line, selection.to_line ); SWAP( selection.from_column, selection.to_column ); @@ -3141,51 +3141,51 @@ void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_c selection.shiftclick_left = true; } - - + + update(); } bool TextEdit::is_selection_active() const { - + return selection.active; } int TextEdit::get_selection_from_line() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.from_line; - + } int TextEdit::get_selection_from_column() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.from_column; - + } int TextEdit::get_selection_to_line() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.to_line; - + } int TextEdit::get_selection_to_column() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.to_column; - + } String TextEdit::get_selection_text() const { - + if (!selection.active) return ""; - + return _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); - + } String TextEdit::get_word_under_cursor() const { - + int prev_cc = cursor.column; while(prev_cc >0) { bool is_char = _is_text_char(text[cursor.line][prev_cc-1]); @@ -3193,7 +3193,7 @@ String TextEdit::get_word_under_cursor() const { break; --prev_cc; } - + int next_cc = cursor.column; while(next_cc<text[cursor.line].length()) { bool is_char = _is_text_char(text[cursor.line][next_cc]); @@ -3207,7 +3207,7 @@ String TextEdit::get_word_under_cursor() const { } DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const { - + int col,line; if (search(p_key,p_search_flags,p_from_line,p_from_column,col,line)) { DVector<int> result; @@ -3215,46 +3215,46 @@ DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, result.set(0,line); result.set(1,col); return result; - + } else { - + return DVector<int>(); } } bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const { - + if (p_key.length()==0) return false; ERR_FAIL_INDEX_V(p_from_line,text.size(),false); ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,false); - + //search through the whole documment, but start by current line - + int line=-1; int pos=-1; - + line=p_from_line; - + for(int i=0;i<text.size()+1;i++) { //backwards is broken... //int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch - - + + if (line<0) { line=text.size()-1; } if (line==text.size()) { line=0; } - + String text_line = text[line]; int from_column=0; if (line==p_from_line) { - + if (i==text.size()) { //wrapped - + if (p_search_flags&SEARCH_BACKWARDS) { text_line=text_line.substr(from_column,text_line.length()); from_column=text_line.length(); @@ -3262,13 +3262,13 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li text_line=text_line.substr(0,from_column); from_column=0; } - + } else { - + from_column=p_from_column; } - - + + } else { //text_line=text_line.substr(0,p_from_column); //wrap around for missing begining. if (p_search_flags&SEARCH_BACKWARDS) @@ -3276,17 +3276,17 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li else from_column=0; } - + pos=-1; - + if (!(p_search_flags&SEARCH_BACKWARDS)) { - + pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.find(p_key,from_column):text_line.findn(p_key,from_column); } else { - + pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.rfind(p_key,from_column):text_line.rfindn(p_key,from_column); } - + if (pos!=-1 && (p_search_flags&SEARCH_WHOLE_WORDS)) { //validate for whole words if (pos>0 && _is_text_char(text_line[pos-1])) @@ -3294,66 +3294,66 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li else if (_is_text_char(text_line[pos+p_key.length()])) pos=-1; } - + if (pos!=-1) break; - + if (p_search_flags&SEARCH_BACKWARDS) line--; else line++; - + } - + if (pos==-1) { r_line=-1; r_column=-1; return false; } - + r_line=line; r_column=pos; - - + + return true; } void TextEdit::_cursor_changed_emit() { - + emit_signal("cursor_changed"); cursor_changed_dirty=false; } void TextEdit::_text_changed_emit() { - + emit_signal("text_changed"); text_changed_dirty=false; } void TextEdit::set_line_as_marked(int p_line,bool p_marked) { - + ERR_FAIL_INDEX(p_line,text.size()); text.set_marked(p_line,p_marked); update(); } bool TextEdit::is_line_set_as_breakpoint(int p_line) const { - + ERR_FAIL_INDEX_V(p_line,text.size(),false); return text.is_breakpoint(p_line); - + } void TextEdit::set_line_as_breakpoint(int p_line,bool p_breakpoint) { - - + + ERR_FAIL_INDEX(p_line,text.size()); text.set_breakpoint(p_line,p_breakpoint); update(); } void TextEdit::get_breakpoints(List<int> *p_breakpoints) const { - + for(int i=0;i<text.size();i++) { if (text.is_breakpoint(i)) p_breakpoints->push_back(i); @@ -3361,39 +3361,39 @@ void TextEdit::get_breakpoints(List<int> *p_breakpoints) const { } int TextEdit::get_line_count() const { - + return text.size(); } void TextEdit::_do_text_op(const TextOperation& p_op, bool p_reverse) { - + ERR_FAIL_COND(p_op.type==TextOperation::TYPE_NONE); - + bool insert = p_op.type==TextOperation::TYPE_INSERT; if (p_reverse) insert=!insert; - + if (insert) { - + int check_line; int check_column; _base_insert_text(p_op.from_line,p_op.from_column,p_op.text,check_line,check_column); ERR_FAIL_COND( check_line != p_op.to_line ); // BUG ERR_FAIL_COND( check_column != p_op.to_column ); // BUG } else { - + _base_remove_text(p_op.from_line,p_op.from_column,p_op.to_line,p_op.to_column); } - + } void TextEdit::_clear_redo() { - + if (undo_stack_pos==NULL) return; //nothing to clear - + _push_current_op(); - + while (undo_stack_pos) { List<TextOperation>::Element *elem = undo_stack_pos; undo_stack_pos=undo_stack_pos->next(); @@ -3403,21 +3403,21 @@ void TextEdit::_clear_redo() { void TextEdit::undo() { - + _push_current_op(); - + if (undo_stack_pos==NULL) { - + if (!undo_stack.size()) return; //nothing to undo - + undo_stack_pos=undo_stack.back(); - + } else if (undo_stack_pos==undo_stack.front()) return; // at the bottom of the undo stack else undo_stack_pos=undo_stack_pos->prev(); - + _do_text_op( undo_stack_pos->get(),true); if(undo_stack_pos->get().chain_backward) { do { @@ -3425,19 +3425,19 @@ void TextEdit::undo() { _do_text_op(undo_stack_pos->get(), true); } while(!undo_stack_pos->get().chain_forward); } - + cursor_set_line(undo_stack_pos->get().from_line); cursor_set_column(undo_stack_pos->get().from_column); update(); } void TextEdit::redo() { - + _push_current_op(); - + if (undo_stack_pos==NULL) return; //nothing to do. - + _do_text_op(undo_stack_pos->get(), false); if(undo_stack_pos->get().chain_forward) { do { @@ -3452,12 +3452,12 @@ void TextEdit::redo() { } void TextEdit::clear_undo_history() { - + saved_version=0; current_op.type=TextOperation::TYPE_NONE; undo_stack_pos=NULL; undo_stack.clear(); - + } void TextEdit::_begin_compex_operation() { @@ -3466,42 +3466,42 @@ void TextEdit::_begin_compex_operation() { } void TextEdit::_end_compex_operation() { - + _push_current_op(); ERR_FAIL_COND(undo_stack.size() == 0); - + if(undo_stack.back()->get().chain_forward) { undo_stack.back()->get().chain_forward=false; return; } - + undo_stack.back()->get().chain_backward=true; } void TextEdit::_push_current_op() { - + if (current_op.type==TextOperation::TYPE_NONE) return; // do nothing - + if(next_operation_is_complex) { current_op.chain_forward=true; next_operation_is_complex=false; } - + undo_stack.push_back(current_op); current_op.type=TextOperation::TYPE_NONE; current_op.text=""; current_op.chain_forward=false; - + } void TextEdit::set_draw_tabs(bool p_draw) { - + draw_tabs=p_draw; } bool TextEdit::is_drawing_tabs() const{ - + return draw_tabs; } @@ -3509,35 +3509,35 @@ uint32_t TextEdit::get_version() const { return current_op.version; } uint32_t TextEdit::get_saved_version() const { - + return saved_version; } void TextEdit::tag_saved_version() { - + saved_version=get_version(); } int TextEdit::get_v_scroll() const { - + return v_scroll->get_val(); } void TextEdit::set_v_scroll(int p_scroll) { - + v_scroll->set_val(p_scroll); cursor.line_ofs=p_scroll; } int TextEdit::get_h_scroll() const { - + return h_scroll->get_val(); } void TextEdit::set_h_scroll(int p_scroll) { - + h_scroll->set_val(p_scroll); } void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) { - + completion_prefixes.clear(); completion_enabled=p_enabled; for(int i=0;i<p_prefixes.size();i++) @@ -3545,7 +3545,7 @@ void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) { } void TextEdit::_confirm_completion() { - + String remaining=completion_current.substr(completion_base.length(),completion_current.length()-completion_base.length()); String l = text[cursor.line]; bool same=true; @@ -3557,7 +3557,7 @@ void TextEdit::_confirm_completion() { break; } } - + if (same) cursor_set_column(cursor.column+remaining.length()); else { @@ -3567,7 +3567,7 @@ void TextEdit::_confirm_completion() { cursor.column--; } } - + _cancel_completion(); } @@ -3578,27 +3578,27 @@ void TextEdit::_cancel_code_hint() { } void TextEdit::_cancel_completion() { - + if (!completion_active) return; - + completion_active=false; update(); - + } static bool _is_completable(CharType c) { - + return !_is_symbol(c) || c=='"' || c=='\''; } void TextEdit::_update_completion_candidates() { - + String l = text[cursor.line]; int cofs = CLAMP(cursor.column,0,l.length()); - - + + String s; //look for keywords first @@ -3654,15 +3654,15 @@ void TextEdit::_update_completion_candidates() { } } - + update(); - + if (cancel || (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1]))))) { //none to complete, cancel _cancel_completion(); return; } - + completion_options.clear(); completion_index=0; completion_base=s; @@ -3675,7 +3675,7 @@ void TextEdit::_update_completion_candidates() { if (max<ci_match) continue; for(int j=0;j<max;j++) { - + if (j>=completion_strings[i].length()) break; if (completion_current[j]!=completion_strings[i][j]) @@ -3686,21 +3686,21 @@ void TextEdit::_update_completion_candidates() { ci_match=m; completion_index=completion_options.size()-1; } - + } } - - - + + + if (completion_options.size()==0) { //no options to complete, cancel _cancel_completion(); return; - + } - + completion_current=completion_options[completion_index]; - + #if 0 // even there's only one option, user still get the chance to choose using it or not if (completion_options.size()==1) { //one option to complete, just complete it automagically @@ -3708,22 +3708,22 @@ void TextEdit::_update_completion_candidates() { // insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length())); _cancel_completion(); return; - + } #endif if (completion_options.size()==1 && s==completion_options[0]) _cancel_completion(); - + completion_enabled=true; } void TextEdit::query_code_comple() { - + String l = text[cursor.line]; int ofs = CLAMP(cursor.column,0,l.length()); - + bool inquote=false; int c=ofs-1; @@ -3735,20 +3735,20 @@ void TextEdit::query_code_comple() { if (ofs>0 && (inquote || _is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1])))) emit_signal("request_completion"); - + } void TextEdit::set_code_hint(const String& p_hint) { - + completion_hint=p_hint; completion_hint_offset=-0xFFFF; update(); } void TextEdit::code_complete(const Vector<String> &p_strings) { - - + + completion_strings=p_strings; completion_active=true; completion_current=""; @@ -3759,7 +3759,7 @@ void TextEdit::code_complete(const Vector<String> &p_strings) { String TextEdit::get_tooltip(const Point2& p_pos) const { - + if (!tooltip_obj) return Control::get_tooltip(p_pos); int row,col; @@ -3770,34 +3770,34 @@ String TextEdit::get_tooltip(const Point2& p_pos) const { return Control::get_tooltip(p_pos); int beg=CLAMP(col,0,s.length()); int end=beg; - - + + if (s[beg]>32 || beg==s.length()) { - + bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this - + while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) { beg--; } while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) { end++; } - + if (end<s.length()) end+=1; - + String tt = tooltip_obj->call(tooltip_func,s.substr(beg,end-beg),tooltip_ud); - + return tt; - + } - + return Control::get_tooltip(p_pos); - + } void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName& p_function,const Variant& p_udata) { - + tooltip_obj=p_obj; tooltip_func=p_function; tooltip_ud=p_udata; @@ -3822,7 +3822,7 @@ void TextEdit::insert_at(const String &p_text, int at) } void TextEdit::set_show_line_numbers(bool p_show) { - + line_numbers=p_show; update(); } @@ -3832,48 +3832,48 @@ bool TextEdit::is_text_field() const { return true; } void TextEdit::_bind_methods() { - - + + ObjectTypeDB::bind_method(_MD("_input_event"),&TextEdit::_input_event); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&TextEdit::_scroll_moved); ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit); ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op); ObjectTypeDB::bind_method(_MD("_click_selection_held"),&TextEdit::_click_selection_held); - + BIND_CONSTANT( SEARCH_MATCH_CASE ); BIND_CONSTANT( SEARCH_WHOLE_WORDS ); BIND_CONSTANT( SEARCH_BACKWARDS ); - + /* ObjectTypeDB::bind_method(_MD("delete_char"),&TextEdit::delete_char); ObjectTypeDB::bind_method(_MD("delete_line"),&TextEdit::delete_line); */ - + ObjectTypeDB::bind_method(_MD("set_text","text"),&TextEdit::set_text); ObjectTypeDB::bind_method(_MD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor); - + ObjectTypeDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count); ObjectTypeDB::bind_method(_MD("get_text"),&TextEdit::get_text); ObjectTypeDB::bind_method(_MD("get_line","line"),&TextEdit::get_line); - + ObjectTypeDB::bind_method(_MD("cursor_set_column","column","adjust_viewport"),&TextEdit::cursor_set_column,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("cursor_set_line","line","adjust_viewport"),&TextEdit::cursor_set_line,DEFVAL(false)); - + ObjectTypeDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column); ObjectTypeDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line); - - + + ObjectTypeDB::bind_method(_MD("set_readonly","enable"),&TextEdit::set_readonly); ObjectTypeDB::bind_method(_MD("set_wrap","enable"),&TextEdit::set_wrap); ObjectTypeDB::bind_method(_MD("set_max_chars","amount"),&TextEdit::set_max_chars); - + ObjectTypeDB::bind_method(_MD("cut"),&TextEdit::cut); ObjectTypeDB::bind_method(_MD("copy"),&TextEdit::copy); ObjectTypeDB::bind_method(_MD("paste"),&TextEdit::paste); ObjectTypeDB::bind_method(_MD("select_all"),&TextEdit::select_all); ObjectTypeDB::bind_method(_MD("select","from_line","from_column","to_line","to_column"),&TextEdit::select); - + ObjectTypeDB::bind_method(_MD("is_selection_active"),&TextEdit::is_selection_active); ObjectTypeDB::bind_method(_MD("get_selection_from_line"),&TextEdit::get_selection_from_line); ObjectTypeDB::bind_method(_MD("get_selection_from_column"),&TextEdit::get_selection_from_column); @@ -3882,30 +3882,30 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text); ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); - + ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo); ObjectTypeDB::bind_method(_MD("redo"),&TextEdit::redo); ObjectTypeDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history); - + ObjectTypeDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring); ObjectTypeDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled); - - + + ObjectTypeDB::bind_method(_MD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color); ObjectTypeDB::bind_method(_MD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("set_symbol_color","color"),&TextEdit::set_symbol_color); ObjectTypeDB::bind_method(_MD("set_custom_bg_color","color"),&TextEdit::set_custom_bg_color); ObjectTypeDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors); - - + + ADD_SIGNAL(MethodInfo("cursor_changed")); ADD_SIGNAL(MethodInfo("text_changed")); ADD_SIGNAL(MethodInfo("request_completion")); - + } TextEdit::TextEdit() { - + readonly=false; setting_row=false; draw_tabs=false; @@ -3925,29 +3925,29 @@ TextEdit::TextEdit() { // text.insert(1,"Mongolia.."); // text.insert(2,"PAIS GENEROSO!!"); text.set_color_regions(&color_regions); - + h_scroll = memnew( HScrollBar ); v_scroll = memnew( VScrollBar ); - + add_child(h_scroll); add_child(v_scroll); - + updating_scrolls=false; selection.active=false; - + h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); - + cursor_changed_dirty=false; text_changed_dirty=false; - + selection.selecting_mode=Selection::MODE_NONE; selection.selecting_line=0; selection.selecting_column=0; selection.selecting_text=false; selection.active=false; syntax_coloring=false; - + custom_bg_color=Color(0,0,0,0); idle_detect = memnew( Timer ); add_child(idle_detect); @@ -3959,7 +3959,7 @@ TextEdit::TextEdit() { add_child(click_select_held); click_select_held->set_wait_time(0.05); click_select_held->connect("timeout", this,"_click_selection_held"); - + #if 0 syntax_coloring=true; keywords["void"]=Color(0.3,0.0,0.1); @@ -3969,15 +3969,15 @@ TextEdit::TextEdit() { keywords["extends"]=Color(0.3,0.0,0.1); keywords["constructor"]=Color(0.3,0.0,0.1); symbol_color=Color(0.1,0.0,0.3,1.0); - + color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4))); color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4))); color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7))); color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8))); color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2))); - + #endif - + current_op.type=TextOperation::TYPE_NONE; undo_enabled=true; undo_stack_pos=NULL; @@ -3986,7 +3986,7 @@ TextEdit::TextEdit() { current_op.version=0; version=0; saved_version=0; - + completion_enabled=false; completion_active=false; completion_line_ofs=0; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 8d0efc406a..2eff8e89c7 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -128,7 +128,7 @@ class TextEdit : public Control { 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; - int get_max_width() const; + int get_max_width() const; const Map<int,ColorRegionInfo>& get_color_region_info(int p_line); void set(int p_line,const String& p_string); void set_marked(int p_line,bool p_marked) { text[p_line].marked=p_marked; } @@ -210,7 +210,7 @@ class TextEdit : public Control { bool text_changed_dirty; bool undo_enabled; bool line_numbers; - + bool scroll_past_end_of_file_enabled; bool auto_brace_completion_enabled; bool brace_matching_enabled; @@ -229,7 +229,7 @@ class TextEdit : public Control { Object *tooltip_obj; StringName tooltip_func; Variant tooltip_ud; - + bool next_operation_is_complex; bool callhint_below; @@ -258,13 +258,13 @@ class TextEdit : public Control { void _update_caches(); void _cursor_changed_emit(); void _text_changed_emit(); - + void _begin_compex_operation(); void _end_compex_operation(); void _push_current_op(); /* super internal api, undo/redo builds on it */ - + void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column); String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const; void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); @@ -282,16 +282,16 @@ class TextEdit : public Control { protected: virtual String get_tooltip(const Point2& p_pos) const; - + void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL); void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); void _insert_text_at_cursor(const String& p_text); void _input_event(const InputEvent& p_input); void _notification(int p_what); - + void _consume_pair_symbol(CharType ch); void _consume_backspace_for_pair_symbol(int prev_line, int prev_column); - + static void _bind_methods(); @@ -304,7 +304,7 @@ public: SEARCH_WHOLE_WORDS=2, SEARCH_BACKWARDS=4 }; - + virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const; //void delete_char(); @@ -322,7 +322,7 @@ public: String get_line(int line) const; void set_line(int line, String new_text); void backspace_at_cursor(); - + inline void set_scroll_pass_end_of_file(bool p_enabled) { scroll_past_end_of_file_enabled = p_enabled; update(); @@ -402,7 +402,7 @@ public: void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata); - void set_completion(bool p_enabled,const Vector<String>& p_prefixes); + void set_completion(bool p_enabled,const Vector<String>& p_prefixes); void code_complete(const Vector<String> &p_strings); void set_code_hint(const String& p_hint); void query_code_comple(); diff --git a/scene/gui/texture_frame.h b/scene/gui/texture_frame.h index f6fe6ae89d..e1f0de92df 100644 --- a/scene/gui/texture_frame.h +++ b/scene/gui/texture_frame.h @@ -42,7 +42,7 @@ class TextureFrame : public Control { Ref<Texture> texture; protected: - void _notification(int p_what); + void _notification(int p_what); virtual Size2 get_minimum_size() const; static void _bind_methods(); diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index e05d35a81d..923a35031c 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -195,7 +195,7 @@ void TextureProgress::_notification(int p_what){ draw_texture_rect_region(progress,Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)),Rect2(Point2(),Size2(s.x*get_unit_value(),s.y))); } - + } if (over.is_valid()) draw_texture(over,Point2()); @@ -269,10 +269,10 @@ void TextureProgress::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_radial_initial_angle","mode"),&TextureProgress::set_radial_initial_angle); ObjectTypeDB::bind_method(_MD("get_radial_initial_angle"), &TextureProgress::get_radial_initial_angle); - + ObjectTypeDB::bind_method(_MD("set_radial_center_offset","mode"),&TextureProgress::set_radial_center_offset); ObjectTypeDB::bind_method(_MD("get_radial_center_offset"), &TextureProgress::get_radial_center_offset); - + ObjectTypeDB::bind_method(_MD("set_fill_degrees","mode"),&TextureProgress::set_fill_degrees); ObjectTypeDB::bind_method(_MD("get_fill_degrees"), &TextureProgress::get_fill_degrees); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 05b1e8bcea..f793bbe3c6 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2164,7 +2164,7 @@ void Tree::_input_event(InputEvent p_event) { float diff_y = -b.relative_y; diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y); diff_y*=0.1; - range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); + range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); popup_edited_item->set_range(popup_edited_item_col,range_drag_base); item_edited(popup_edited_item_col,popup_edited_item); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index e5c95b4d66..421cfc47bc 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -46,22 +46,22 @@ class TreeItem : public Object { OBJ_TYPE(TreeItem,Object); public: - + enum TreeCellMode { - + CELL_MODE_STRING, ///< just a string CELL_MODE_CHECK, ///< string + check CELL_MODE_RANGE, ///< Contains a range CELL_MODE_ICON, ///< Contains a icon, not editable CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button }; - + private: friend class Tree; - - + + struct Cell { - + TreeCellMode mode; Ref<Texture> icon; @@ -92,9 +92,9 @@ friend class Tree; }; Vector< Button > buttons; - + Cell() { - + custom_draw_obj=0; mode=TreeItem::CELL_MODE_STRING; min=0; @@ -116,30 +116,30 @@ friend class Tree; void draw_icon(const RID& p_where, const Point2& p_pos, const Size2& p_size=Size2()) const; }; - + Vector<Cell> cells; - + bool collapsed; // wont show childs - + TreeItem *parent; // parent item TreeItem *next; // next in list TreeItem *childs; //child items Tree *tree; //tree (for reference) - + TreeItem(Tree *p_tree); - + void _changed_notify(int p_cell); void _changed_notify(); void _cell_selected(int p_cell); void _cell_deselected(int p_cell); protected: - + static void _bind_methods(); //bind helpers - Dictionary _get_range_config( int p_column ) { + Dictionary _get_range_config( int p_column ) { Dictionary d; double min,max,step; get_range_config(p_column,min,max,step); @@ -152,18 +152,18 @@ protected: } void _remove_child(Object *p_child) { remove_child( p_child->cast_to<TreeItem>() ); } public: - + /* cell mode */ void set_cell_mode( int p_column, TreeCellMode p_mode ); TreeCellMode get_cell_mode( int p_column ) const; - + /* check mode */ void set_checked(int p_column,bool p_checked); bool is_checked(int p_column) const; - + void set_text(int p_column,String p_text); String get_text(int p_column) const; - + void set_icon(int p_column,const Ref<Texture>& p_icon); Ref<Texture> get_icon(int p_column) const; @@ -183,22 +183,22 @@ public: void set_button(int p_column,int p_idx,const Ref<Texture>& p_button); /* range works for mode number or mode combo */ - + void set_range(int p_column,double p_value); double get_range(int p_column) const; - + void set_range_config(int p_column,double p_min,double p_max,double p_step,bool p_exp=false); void get_range_config(int p_column,double& r_min,double& r_max,double &r_step) const; bool is_range_exponential(int p_column) const; - + void set_metadata(int p_column,const Variant& p_meta); Variant get_metadata(int p_column) const; - + void set_custom_draw(int p_column,Object *p_object,const StringName& p_callback); - + void set_collapsed(bool p_collapsed); bool is_collapsed(); - + TreeItem *get_prev(); TreeItem *get_next(); TreeItem *get_parent(); @@ -206,20 +206,20 @@ public: TreeItem *get_prev_visible(); TreeItem *get_next_visible(); - + void remove_child(TreeItem *p_item); - + void set_selectable(int p_column,bool p_selectable); bool is_selectable(int p_column) const; - + bool is_selected(int p_column); void select(int p_column); void deselect(int p_column); void set_as_cursor(int p_column); - + void set_editable(int p_column,bool p_editable); bool is_editable(int p_column); - + void set_custom_color(int p_column,const Color& p_color); void clear_custom_color(int p_column); @@ -237,7 +237,7 @@ public: void move_to_bottom(); ~TreeItem(); - + }; @@ -245,18 +245,18 @@ VARIANT_ENUM_CAST( TreeItem::TreeCellMode ); class Tree : public Control { - + OBJ_TYPE( Tree, Control ); -public: +public: enum SelectMode { SELECT_SINGLE, SELECT_ROW, SELECT_MULTI }; - -private: -friend class TreeItem; - + +private: +friend class TreeItem; + TreeItem *root; TreeItem *popup_edited_item; TreeItem *selected_item; @@ -287,7 +287,7 @@ friend class TreeItem; int blocked; struct ColumnInfo { - + int min_width; bool expand; String title; @@ -320,21 +320,21 @@ friend class TreeItem; void value_editor_changed(double p_value); void popup_select(int p_option); - + void _input_event(InputEvent p_event); void _notification(int p_what); - + Size2 get_minimum_size() const; - + void item_edited(int p_column,TreeItem *p_item); void item_changed(int p_column,TreeItem *p_item); void item_selected(int p_column,TreeItem *p_item); void item_deselected(int p_column,TreeItem *p_item); - + void propagate_set_columns(TreeItem *p_item); - + struct Cache { - + Ref<Font> font; Ref<Font> tb_font; Ref<StyleBox> bg; @@ -354,14 +354,14 @@ friend class TreeItem; Ref<Texture> arrow; Ref<Texture> select_arrow; Ref<Texture> updown; - + Color font_color; Color font_color_selected; Color guide_color; int hseparation; int vseparation; int item_margin; - int guide_width; + int guide_width; int button_margin; Point2 offset; @@ -381,14 +381,14 @@ friend class TreeItem; int hover_index; } cache; - - + + int _get_title_button_height() const; void _scroll_moved(float p_value); HScrollBar *h_scroll; VScrollBar *v_scroll; - + Size2 get_internal_min_size() const; void update_cache(); void update_scrollbars(); @@ -423,10 +423,10 @@ friend class TreeItem; protected: static void _bind_methods(); - + //bind helpers Object* _create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>() ); } - TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); } + TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); } Rect2 _get_item_rect(Object *p_item,int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(),p_column ); } public: @@ -434,21 +434,21 @@ public: void clear(); - TreeItem* create_item(TreeItem *p_parent=0); + TreeItem* create_item(TreeItem *p_parent=0); TreeItem* get_root(); TreeItem* get_last_item(); void set_column_min_width(int p_column,int p_min_width); - void set_column_expand(int p_column,bool p_expand); + void set_column_expand(int p_column,bool p_expand); int get_column_width(int p_column) const; - + void set_hide_root(bool p_eanbled); TreeItem *get_next_selected( TreeItem* p_item); TreeItem *get_selected() const; int get_selected_column() const; int get_pressed_button() const; void set_select_mode(SelectMode p_mode); - + void set_columns(int p_columns); int get_columns() const; @@ -462,11 +462,11 @@ public: int get_edited_column() const; void ensure_cursor_is_visible(); - + Rect2 get_custom_popup_rect() const; int get_item_offset(TreeItem *p_item) const; - Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const; + Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const; bool edit_selected(); TreeItem* search_item_text(const String& p_find,int *r_col=NULL,bool p_selectable=false); @@ -484,7 +484,7 @@ public: Tree(); - ~Tree(); + ~Tree(); }; diff --git a/scene/io/resource_format_image.cpp b/scene/io/resource_format_image.cpp index c80975dbfe..6174d134a3 100644 --- a/scene/io/resource_format_image.cpp +++ b/scene/io/resource_format_image.cpp @@ -32,7 +32,7 @@ #include "globals.h" #include "os/os.h" RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_original_path, Error *r_error) { - + if (r_error) *r_error=ERR_CANT_OPEN; @@ -45,31 +45,31 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); if (err) { - + ERR_FAIL_COND_V( err, RES() ); } - + String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); for(int i=0;i<6;i++) { - + String file = f->get_line().strip_edges(); Image image; - + Error err = ImageLoader::load_image(base_path+file,&image); - + if (err) { - + memdelete(f); ERR_FAIL_COND_V( err, RES() ); } - + if (i==0) { - + //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); } - + static const CubeMap::Side cube_side[6]= { CubeMap::SIDE_LEFT, CubeMap::SIDE_RIGHT, @@ -78,10 +78,10 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin CubeMap::SIDE_FRONT, CubeMap::SIDE_BACK }; - + cubemap->set_side(cube_side[i],image); } - + memdelete(f); cubemap->set_name(p_path.get_file()); @@ -89,9 +89,9 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin *r_error=OK; return cubemap; - + } else { - // simple image + // simple image ImageTexture* ptr = memnew(ImageTexture); Ref<ImageTexture> texture( ptr ); @@ -115,7 +115,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin ERR_EXPLAIN("Failed loading image: "+p_path); - ERR_FAIL_COND_V(err, RES()); + ERR_FAIL_COND_V(err, RES()); if (r_error) *r_error=ERR_FILE_CORRUPT; @@ -134,8 +134,8 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin } #endif #endif - - + + uint32_t flags=0; FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ); @@ -186,7 +186,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin if (flags_found["tolinear"]) flags|=Texture::FLAG_CONVERT_TO_LINEAR; } - + if (flags_found.has("mirroredrepeat")) { if (flags_found["mirroredrepeat"]) flags|=Texture::FLAG_MIRRORED_REPEAT; @@ -210,7 +210,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin return RES( texture ); } - + } @@ -220,7 +220,7 @@ bool ResourceFormatLoaderImage::handles_type(const String& p_type) const { } void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const { - + ImageLoader::get_recognized_extensions(p_extensions); p_extensions->push_back("cube"); } diff --git a/scene/main/misc.h b/scene/main/misc.h index 1c5bc7208e..d5db8c3247 100644 --- a/scene/main/misc.h +++ b/scene/main/misc.h @@ -37,7 +37,7 @@ class Misc : public Node { OBJ_TYPE( Misc, Node ); public: - Misc(); + Misc(); ~Misc(); }; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 450578a241..b90edb38b2 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -41,7 +41,7 @@ VARIANT_ENUM_CAST(Node::PauseMode); void Node::_notification(int p_notification) { - + switch(p_notification) { case NOTIFICATION_PROCESS: { @@ -114,21 +114,21 @@ void Node::_notification(int p_notification) { case NOTIFICATION_PREDELETE: { set_owner(NULL); - + while ( data.owned.size() ) { - - data.owned.front()->get()->set_owner(NULL); + + data.owned.front()->get()->set_owner(NULL); } if (data.parent) { - + data.parent->remove_child(this); } // kill children as cleanly as possible while( data.children.size() ) { - - Node *child = data.children[0]; + + Node *child = data.children[0]; remove_child(child); memdelete( child ); } @@ -161,7 +161,7 @@ void Node::_propagate_enter_tree() { data.depth=1; } - + data.viewport = cast_to<Viewport>(); if (!data.viewport) data.viewport = data.parent->data.viewport; @@ -191,10 +191,10 @@ void Node::_propagate_enter_tree() { //block while adding children for (int i=0;i<data.children.size();i++) { - + if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree data.children[i]->_propagate_enter_tree(); - } + } data.blocked--; @@ -279,15 +279,15 @@ void Node::_propagate_exit_tree() { -void Node::move_child(Node *p_child,int p_pos) { - +void Node::move_child(Node *p_child,int p_pos) { + ERR_FAIL_NULL(p_child); ERR_EXPLAIN("Invalid new child position: "+itos(p_pos)); ERR_FAIL_INDEX( p_pos, data.children.size()+1 ); ERR_EXPLAIN("child is not a child of this node."); ERR_FAIL_COND(p_child->data.parent!=this); ERR_FAIL_COND(data.blocked>0); - + data.children.remove( p_child->data.pos ); data.children.insert( p_pos, p_child ); @@ -298,7 +298,7 @@ void Node::move_child(Node *p_child,int p_pos) { data.blocked++; //new pos first for (int i=0;i<data.children.size();i++) { - + data.children[i]->data.pos=i; } // notification second @@ -313,17 +313,17 @@ void Node::move_child(Node *p_child,int p_pos) { } void Node::raise() { - + if (!data.parent) return; - + data.parent->move_child(this,data.parent->data.children.size()-1); } void Node::add_child_notify(Node *p_child) { - - // to be used when not wanted + + // to be used when not wanted } /* @@ -340,26 +340,26 @@ void Node::remove_and_delete_child(Node *p_child) { void Node::remove_child_notify(Node *p_child) { - // to be used when not wanted + // to be used when not wanted } void Node::move_child_notify(Node *p_child) { - // to be used when not wanted + // to be used when not wanted } void Node::set_fixed_process(bool p_process) { - + if (data.fixed_process==p_process) return; data.fixed_process=p_process; - + if (data.fixed_process) add_to_group("fixed_process",false); else remove_from_group("fixed_process"); - + data.fixed_process=p_process; _change_notify("fixed_process"); } @@ -437,7 +437,7 @@ bool Node::can_process() const { float Node::get_fixed_process_delta_time() const { - + if (data.tree) return data.tree->get_fixed_process_time(); else @@ -469,7 +469,7 @@ float Node::get_process_delta_time() const { } bool Node::is_fixed_processing() const { - + return data.fixed_process; } @@ -541,7 +541,7 @@ bool Node::is_processing_unhandled_key_input() const { StringName Node::get_name() const { - + return data.name; } @@ -552,14 +552,14 @@ void Node::_set_name_nocheck(const StringName& p_name) { } void Node::set_name(const String& p_name) { - + String name=p_name.replace(":","").replace("/","").replace("@",""); ERR_FAIL_COND(name==""); data.name=name; - + if (data.parent) { - + data.parent->_validate_child_name(this); } @@ -741,12 +741,12 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_COND( p_child->data.parent ); ERR_EXPLAIN("Can't add child while a notification is happening"); ERR_FAIL_COND( data.blocked > 0 ); - + /* Validate name */ _validate_child_name(p_child,p_legible_unique_name); _add_child_nocheck(p_child,p_child->data.name); - + } @@ -791,36 +791,36 @@ void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); ERR_FAIL_COND( data.blocked > 0 ); - + int idx=-1; for (int i=0;i<data.children.size();i++) { - + if (data.children[i]==p_child) { - + idx=i; break; } } - + ERR_FAIL_COND( idx==-1 ); //ERR_FAIL_COND( p_child->data.blocked > 0 ); - + //if (data.scene) { does not matter - + p_child->_set_tree(NULL); //} - - remove_child_notify(p_child); + + remove_child_notify(p_child); p_child->notification(NOTIFICATION_UNPARENTED); - + data.children.remove(idx); - + for (int i=idx;i<data.children.size();i++) { - + data.children[i]->data.pos=i; } - + p_child->data.parent=NULL; p_child->data.pos=-1; @@ -828,17 +828,17 @@ void Node::remove_child(Node *p_child) { // validate owner p_child->_propagate_validate_owner(); - + } int Node::get_child_count() const { - - return data.children.size(); + + return data.children.size(); } Node *Node::get_child(int p_index) const { - + ERR_FAIL_INDEX_V( p_index, data.children.size(), NULL ); - + return data.children[p_index]; } @@ -862,10 +862,10 @@ Node *Node::_get_node(const NodePath& p_path) const { ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); ERR_FAIL_V(NULL); } - - Node *current=NULL; + + Node *current=NULL; Node *root=NULL; - + if (!p_path.is_absolute()) { current=const_cast<Node*>(this); //start from this } else { @@ -874,42 +874,42 @@ Node *Node::_get_node(const NodePath& p_path) const { while (root->data.parent) root=root->data.parent; //start from root } - + for(int i=0;i<p_path.get_name_count();i++) { - - - StringName name = p_path.get_name(i); + + + StringName name = p_path.get_name(i); Node *next = NULL; - + if (name==SceneStringNames::get_singleton()->dot) { // . - + next=current; - + } else if (name==SceneStringNames::get_singleton()->doubledot) { // .. - + if (current==NULL || !current->data.parent) return NULL; - + next=current->data.parent; } else if (current==NULL) { - + if (name==root->get_name()) next=root; - + } else { - + next=NULL; - + for(int j=0;j<current->data.children.size();j++) { - + Node *child = current->data.children[j]; if ( child->data.name == name ) { - + next = child; break; - } + } } if (next == NULL) { return NULL; @@ -917,7 +917,7 @@ Node *Node::_get_node(const NodePath& p_path) const { } current=next; } - + return current; } @@ -969,12 +969,12 @@ bool Node::is_a_parent_of(const Node *p_node) const { ERR_FAIL_NULL_V(p_node,false); Node *p=p_node->data.parent; while(p) { - + if (p==this) return true; p=p->data.parent; } - + return false; } @@ -983,25 +983,25 @@ bool Node::is_greater_than(const Node *p_node) const { ERR_FAIL_NULL_V(p_node,false); ERR_FAIL_COND_V( !data.inside_tree, false ); ERR_FAIL_COND_V( !p_node->data.inside_tree, false ); - + ERR_FAIL_COND_V( data.depth<0, false); ERR_FAIL_COND_V( p_node->data.depth<0, false); #ifdef NO_ALLOCA - + Vector<int> this_stack; Vector<int> that_stack; this_stack.resize(data.depth); that_stack.resize(p_node->data.depth); #else - + int *this_stack=(int*)alloca(sizeof(int)*data.depth); int *that_stack=(int*)alloca(sizeof(int)*p_node->data.depth); - + #endif - + const Node *n = this; - + int idx=data.depth-1; while(n) { ERR_FAIL_INDEX_V(idx, data.depth,false); @@ -1014,15 +1014,15 @@ bool Node::is_greater_than(const Node *p_node) const { while(n) { ERR_FAIL_INDEX_V(idx, p_node->data.depth,false); that_stack[idx--]=n->data.pos; - + n=n->data.parent; } ERR_FAIL_COND_V(idx!=-1,false); idx=0; - + bool res; while(true) { - + // using -2 since out-of-tree or nonroot nodes have -1 int this_idx = (idx >= data.depth)? -2 : this_stack[idx]; int that_idx = (idx >= p_node->data.depth)? -2 : that_stack[idx]; @@ -1039,7 +1039,7 @@ bool Node::is_greater_than(const Node *p_node) const { } idx++; } - + return res; } @@ -1063,39 +1063,39 @@ void Node::_set_owner_nocheck(Node* p_owner) { } void Node::set_owner(Node *p_owner) { - + if (data.owner) { - + data.owner->data.owned.erase( data.OW ); data.OW=NULL; data.owner=NULL; } - + ERR_FAIL_COND(p_owner==this); - + if (!p_owner) return; - + Node *check=this->get_parent(); bool owner_valid=false; - + while(check) { - + if (check==p_owner) { owner_valid=true; break; } - + check=check->data.parent; } - + ERR_FAIL_COND(!owner_valid); _set_owner_nocheck(p_owner); } Node *Node::get_owner() const { - - return data.owner; + + return data.owner; } NodePath Node::get_path_to(const Node *p_node) const { @@ -1104,68 +1104,68 @@ NodePath Node::get_path_to(const Node *p_node) const { if (this==p_node) return NodePath("."); - + Set<const Node*> visited; - + const Node *n=this; - + while(n) { - + visited.insert(n); n=n->data.parent; } const Node *common_parent=p_node; - + while(common_parent) { - + if (visited.has(common_parent)) break; common_parent=common_parent->data.parent; } - + ERR_FAIL_COND_V(!common_parent,NodePath()); //nodes not in the same tree - + visited.clear(); - + Vector<StringName> path; - + n=p_node; - + while(n!=common_parent) { - + path.push_back( n->get_name() ); n=n->data.parent; } - + n=this; - StringName up=String(".."); - + StringName up=String(".."); + while(n!=common_parent) { - + path.push_back( up ); n=n->data.parent; } - + path.invert(); - - return NodePath(path,false); + + return NodePath(path,false); } NodePath Node::get_path() const { - + ERR_FAIL_COND_V(!is_inside_tree(),NodePath()); const Node *n = this; - + Vector<StringName> path; - + while(n) { path.push_back(n->get_name()); n=n->data.parent; - } - + } + path.invert(); - + return NodePath( path, true ); } @@ -1175,36 +1175,36 @@ bool Node::is_in_group(const StringName& p_identifier) const { } void Node::add_to_group(const StringName& p_identifier,bool p_persistent) { - + ERR_FAIL_COND(!p_identifier.operator String().length()); - + if (data.grouped.has(p_identifier)) return; - + GroupData gd; - + if (data.tree) data.tree->add_to_group(p_identifier,this); - gd.persistent=p_persistent; - + gd.persistent=p_persistent; + data.grouped[p_identifier]=gd; } void Node::remove_from_group(const StringName& p_identifier) { - + ERR_FAIL_COND(!data.grouped.has(p_identifier) ); - + GroupData *g=data.grouped.getptr(p_identifier); - + ERR_FAIL_COND(!g); - + if (data.tree) data.tree->remove_from_group(p_identifier,this); - data.grouped.erase(p_identifier); + data.grouped.erase(p_identifier); } @@ -1223,15 +1223,15 @@ Array Node::_get_groups() const { void Node::get_groups(List<GroupInfo> *p_groups) const { const StringName *K=NULL; - + while ((K=data.grouped.next(K))) { - + GroupInfo gi; gi.name=*K; gi.persistent=data.grouped[*K].persistent; p_groups->push_back(gi); } - + } @@ -1249,13 +1249,13 @@ void Node::print_tree() { void Node::_propagate_reverse_notification(int p_notification) { - - data.blocked++; + + data.blocked++; for (int i=data.children.size()-1;i>=0;i--) { - - data.children[i]->_propagate_reverse_notification(p_notification); + + data.children[i]->_propagate_reverse_notification(p_notification); } - + notification(p_notification,true); data.blocked--; } @@ -1281,75 +1281,75 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) } void Node::propagate_notification(int p_notification) { - - data.blocked++; + + data.blocked++; notification(p_notification); - + for (int i=0;i<data.children.size();i++) { - - data.children[i]->propagate_notification(p_notification); + + data.children[i]->propagate_notification(p_notification); } - data.blocked--; + data.blocked--; } -void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) { +void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) { if (get_owner()==p_owner) set_owner(p_by_owner); - + data.blocked++; - for (int i=0;i<data.children.size();i++) + for (int i=0;i<data.children.size();i++) data.children[i]->_propagate_replace_owner(p_owner,p_by_owner); - data.blocked--; + data.blocked--; } int Node::get_index() const { - + return data.pos; } void Node::remove_and_skip() { - + ERR_FAIL_COND(!data.parent); - + Node *new_owner=get_owner(); - + List<Node*> children; - + while(true) { - + bool clear=true; for (int i=0;i<data.children.size();i++) { if (!data.children[i]->get_owner()) continue; - + remove_child(data.children[i]); data.children[i]->_propagate_replace_owner(this,NULL); - children.push_back(data.children[i]); + children.push_back(data.children[i]); clear=false; break; } - + if (clear) break; } - + while(!children.empty()) { - + Node *c=children.front()->get(); data.parent->add_child(c); - c->_propagate_replace_owner(NULL,new_owner); + c->_propagate_replace_owner(NULL,new_owner); children.pop_front(); } - + data.parent->remove_child(this); } void Node::set_filename(const String& p_filename) { - + data.filename=p_filename; } String Node::get_filename() const { - + return data.filename; } @@ -2117,7 +2117,7 @@ void Node::_bind_methods() { Node::Node() { - + data.pos=-1; data.depth=-1; data.blocked=0; @@ -2141,12 +2141,12 @@ Node::Node() { } Node::~Node() { - + data.grouped.clear(); data.owned.clear(); data.children.clear(); - + ERR_FAIL_COND(data.parent); ERR_FAIL_COND(data.children.size()); diff --git a/scene/main/node.h b/scene/main/node.h index 4d05dd381c..5c6147d644 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -43,7 +43,7 @@ class Node : public Object { OBJ_TYPE( Node, Object ); OBJ_CATEGORY("Nodes"); - + public: enum PauseMode { @@ -59,16 +59,16 @@ public: bool operator()(const Node* p_a, const Node* p_b) const { return p_b->is_greater_than(p_a); } }; -private: - +private: + struct GroupData { - - bool persistent; + + bool persistent; GroupData() { persistent=false; } }; - + struct Data { - + String filename; Ref<SceneState> instance_state; Ref<SceneState> inherited_state; @@ -90,11 +90,11 @@ private: Viewport *viewport; - + HashMap< StringName, GroupData,StringNameHasher> grouped; List<Node*>::Element *OW; // owned element List<Node*> owned; - + PauseMode pause_mode; Node *pause_owner; // variables used to properly sort the node when processing, ignored otherwise @@ -112,10 +112,10 @@ private: } data; - - void _print_tree(const Node *p_node); - + + void _print_tree(const Node *p_node); + virtual bool _use_builtin_script() const { return true; } Node *_get_node(const NodePath& p_path) const; Node *_get_child_by_name(const StringName& p_name) const; @@ -124,7 +124,7 @@ private: void _validate_child_name(Node *p_name, bool p_force_human_readable=false); - void _propagate_reverse_notification(int p_notification); + void _propagate_reverse_notification(int p_notification); void _propagate_deferred_notification(int p_notification, bool p_reverse); void _propagate_enter_tree(); void _propagate_ready(); @@ -147,15 +147,15 @@ protected: void _block() { data.blocked++; } void _unblock() { data.blocked--; } - void _notification(int p_notification); - + void _notification(int p_notification); + virtual void add_child_notify(Node *p_child); virtual void remove_child_notify(Node *p_child); virtual void move_child_notify(Node *p_child); //void remove_and_delete_child(Node *p_child); - - void _propagate_replace_owner(Node *p_owner,Node* p_by_owner); - + + void _propagate_replace_owner(Node *p_owner,Node* p_by_owner); + static void _bind_methods(); friend class SceneState; @@ -181,15 +181,15 @@ public: NOTIFICATION_UNPARENTED=19, NOTIFICATION_INSTANCED=20, }; - - /* NODE/TREE */ - + + /* NODE/TREE */ + StringName get_name() const; void set_name(const String& p_name); - + void add_child(Node *p_child,bool p_legible_unique_name=false); void remove_child(Node *p_child); - + int get_child_count() const; Node *get_child(int p_index) const; bool has_node(const NodePath& p_path) const; @@ -197,43 +197,43 @@ public: Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const; bool has_node_and_resource(const NodePath& p_path) const; Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const; - + Node *get_parent() const; _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; } _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; } - + bool is_a_parent_of(const Node *p_node) const; bool is_greater_than(const Node *p_node) const; - + NodePath get_path() const; NodePath get_path_to(const Node *p_node) const; - + void add_to_group(const StringName& p_identifier,bool p_persistent=false); void remove_from_group(const StringName& p_identifier); bool is_in_group(const StringName& p_identifier) const; - + struct GroupInfo { - + StringName name; bool persistent; }; - + void get_groups(List<GroupInfo> *p_groups) const; - + void move_child(Node *p_child,int p_pos); void raise(); - + void set_owner(Node *p_owner); Node *get_owner() const; void get_owned_by(Node *p_by,List<Node*> *p_owned); - + void remove_and_skip(); int get_index() const; - + void print_tree(); - + void set_filename(const String& p_filename); String get_filename() const; @@ -242,9 +242,9 @@ public: /* NOTIFICATIONS */ - + void propagate_notification(int p_notification); - + /* PROCESSING */ void set_fixed_process(bool p_process); float get_fixed_process_delta_time() const; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 8e2d6aa669..cc103b5115 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -211,7 +211,7 @@ void SceneTree::call_group(uint32_t p_call_flags,const StringName& p_group,const else nodes[i]->call(p_function,VARIANT_ARG_PASS); } else - MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); + MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); } } @@ -433,7 +433,7 @@ void SceneTree::input_event( const InputEvent& p_event ) { ScriptDebugger::get_singleton()->request_quit(); } - _flush_ugc(); + _flush_ugc(); root_lock--; MessageQueue::get_singleton()->flush(); //small little hack diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index c6fc124345..b6a015c9ed 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -76,7 +76,7 @@ private: struct Group { Vector<Node*> nodes; - uint64_t last_tree_version; + uint64_t last_tree_version; Group() { last_tree_version=0; }; }; diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index a118bc9782..73458e03c0 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -111,7 +111,7 @@ bool Timer::has_autostart() const { } void Timer::start() { - time_left=wait_time; + time_left=wait_time; _set_process(true); } @@ -154,7 +154,7 @@ Timer::TimerProcessMode Timer::get_timer_process_mode() const{ } -void Timer::_set_process(bool p_process, bool p_force) +void Timer::_set_process(bool p_process, bool p_force) { switch (timer_process_mode) { case TIMER_PROCESS_FIXED: set_fixed_process(p_process); break; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 550bae6306..2c94d2e093 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -318,10 +318,10 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) { } void Viewport::_notification(int p_what) { - + switch( p_what ) { - + case NOTIFICATION_ENTER_TREE: { if (get_parent()) { @@ -696,8 +696,8 @@ void Viewport::_notification(int p_what) { } RID Viewport::get_viewport() const { - - return viewport; + + return viewport; } void Viewport::set_rect(const Rect2& p_rect) { @@ -715,12 +715,12 @@ Rect2 Viewport::get_visible_rect() const { Rect2 r; - + if (rect.pos==Vector2() && rect.size==Size2()) { - + r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) ); } else { - + r=Rect2( rect.pos , rect.size ); } @@ -733,7 +733,7 @@ Rect2 Viewport::get_visible_rect() const { } Rect2 Viewport::get_rect() const { - + return rect; } @@ -1335,7 +1335,7 @@ void Viewport::_vp_input(const InputEvent& p_ev) { //they are converted to viewport coordinates - InputEvent ev = p_ev; + InputEvent ev = p_ev; _make_input_local(ev); input(ev); @@ -2240,7 +2240,7 @@ void Viewport::input(const InputEvent& p_event) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(input_group,"_input",p_event); + get_tree()->_call_input_pause(input_group,"_input",p_event); _gui_input_event(p_event); //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } @@ -2409,10 +2409,10 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_render_target_vflip","enable"), &Viewport::set_render_target_vflip); ObjectTypeDB::bind_method(_MD("get_render_target_vflip"), &Viewport::get_render_target_vflip); - + ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame","enable"), &Viewport::set_render_target_clear_on_new_frame); ObjectTypeDB::bind_method(_MD("get_render_target_clear_on_new_frame"), &Viewport::get_render_target_clear_on_new_frame); - + ObjectTypeDB::bind_method(_MD("render_target_clear"), &Viewport::render_target_clear); ObjectTypeDB::bind_method(_MD("set_render_target_filter","enable"), &Viewport::set_render_target_filter); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 5bf7418ee9..afabd499a9 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -270,7 +270,7 @@ friend class Camera; void _camera_make_next_current(Camera* p_exclude); -protected: +protected: void _notification(int p_what); static void _bind_methods(); public: @@ -284,7 +284,7 @@ public: void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; - void set_rect(const Rect2& p_rect); + void set_rect(const Rect2& p_rect); Rect2 get_rect() const; Rect2 get_visible_rect() const; RID get_viewport() const; @@ -362,7 +362,7 @@ public: bool gui_has_modal_stack() const; - Viewport(); + Viewport(); ~Viewport(); }; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 6fa6085bb3..9930aa07f6 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -432,7 +432,7 @@ void register_scene_types() { ObjectTypeDB::register_type<ConeTwistJoint>(); ObjectTypeDB::register_type<Generic6DOFJoint>(); - //scenariofx + //scenariofx OS::get_singleton()->yield(); //may take time to init @@ -629,9 +629,9 @@ void register_scene_types() { } void unregister_scene_types() { - + clear_default_theme(); - + memdelete( resource_loader_image ); memdelete( resource_loader_wav ); #ifdef TOOLS_ENABLED diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index e8bd6c14ad..f7d5ddc744 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -41,33 +41,33 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) { else if (name=="step") set_step(p_value); else if (name.begins_with("tracks/")) { - + int track=name.get_slicec('/',1).to_int(); String what=name.get_slicec('/',2); if (tracks.size()==track && what=="type") { - + String type=p_value; - + if (type=="transform") { - + add_track(TYPE_TRANSFORM); } else if (type=="value") { - + add_track(TYPE_VALUE); } else if (type=="method") { - + add_track(TYPE_METHOD); } else { - + return false; } - + return true; } - + ERR_FAIL_INDEX_V( track, tracks.size(),false ); - + if (what=="path") track_set_path(track,p_value); else if (what=="interp") @@ -261,10 +261,10 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { String what=name.get_slicec('/',2); ERR_FAIL_INDEX_V( track, tracks.size(), false ); if (what=="type") { - - + + switch (track_get_type(track)) { - + case TYPE_TRANSFORM: r_ret= "transform"; break; case TYPE_VALUE: r_ret= "value";break; case TYPE_METHOD: r_ret= "method";break; @@ -281,7 +281,7 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { if (track_get_type(track)==TYPE_TRANSFORM) { DVector<real_t> keys; - int kk=track_get_key_count(track); + int kk=track_get_key_count(track); keys.resize(kk*12); DVector<real_t>::Write w = keys.write(); @@ -406,7 +406,7 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { return false; } else return false; - + return true; } @@ -415,11 +415,11 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { void Animation::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL, "length", PROPERTY_HINT_RANGE, "0.001,99999,0.001")); - p_list->push_back( PropertyInfo( Variant::BOOL, "loop" )); + p_list->push_back( PropertyInfo( Variant::BOOL, "loop" )); p_list->push_back( PropertyInfo( Variant::REAL, "step", PROPERTY_HINT_RANGE, "0,4096,0.001" )); for (int i=0;i<tracks.size();i++) { - + p_list->push_back( PropertyInfo( Variant::STRING, "tracks/"+itos(i)+"/type", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::NODE_PATH, "tracks/"+itos(i)+"/path", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::INT, "tracks/"+itos(i)+"/interp", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); @@ -433,24 +433,24 @@ int Animation::add_track(TrackType p_type,int p_at_pos) { p_at_pos=tracks.size(); switch( p_type ) { - + case TYPE_TRANSFORM: { - + TransformTrack *tt = memnew( TransformTrack ); tracks.insert( p_at_pos,tt ); } break; case TYPE_VALUE: { - + tracks.insert( p_at_pos,memnew( ValueTrack ) ); - + } break; case TYPE_METHOD: { - + tracks.insert( p_at_pos,memnew( MethodTrack ) ); - + } break; default: { - + ERR_PRINT("Unknown track type"); } } @@ -462,29 +462,29 @@ void Animation::remove_track(int p_track) { ERR_FAIL_INDEX(p_track, tracks.size()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); _clear(tt->transforms); - + } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); _clear(vt->values); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); _clear(mt->methods); - - } break; - } - + + } break; + } + memdelete( t ); tracks.remove(p_track); emit_changed(); @@ -548,30 +548,30 @@ template<class T> int Animation::_insert_pos(float p_time, T& p_keys) { // simple, linear time inset that should be fast enough in reality. - + int idx=p_keys.size(); - + while(true) { - - + + if (idx==0 || p_keys[idx-1].time < p_time) { //condition for insertion. p_keys.insert(idx,T()); return idx; } else if (p_keys[idx-1].time == p_time) { - + // condition for replacing. return idx-1; - } - + } + idx--; } - + } */ template<class T, class V> int Animation::_insert(float p_time, T& p_keys, const V& p_value) { - + int idx=p_keys.size(); while(true) { @@ -597,7 +597,7 @@ int Animation::_insert(float p_time, T& p_keys, const V& p_value) { template<class T> void Animation::_clear(T& p_keys) { - + p_keys.clear(); } @@ -727,11 +727,11 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant& p_val ERR_FAIL_INDEX(p_track, tracks.size()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + Dictionary d = p_value; Vector3 loc; if (d.has("loc")) @@ -750,36 +750,36 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant& p_val } break; case TYPE_VALUE: { - + ValueTrack * vt = static_cast<ValueTrack*>(t); - + TKey<Variant> k; k.time=p_time; k.transition=p_transition; k.value=p_value; _insert( p_time, vt->values, k ); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); - + ERR_FAIL_COND( p_value.get_type() != Variant::DICTIONARY ); - + Dictionary d=p_value; ERR_FAIL_COND(!d.has("method") || d["method"].get_type()!=Variant::STRING); ERR_FAIL_COND(!d.has("args") || !d["args"].is_array()); MethodKey k; - + k.time=p_time; k.transition=p_transition; k.method=d["method"]; k.params=d["args"]; _insert( p_time, mt->methods, k ); - - } break; + + } break; } @@ -790,27 +790,27 @@ int Animation::track_get_key_count(int p_track) const { ERR_FAIL_INDEX_V(p_track, tracks.size(),-1); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); return tt->transforms.size(); } break; case TYPE_VALUE: { - + ValueTrack * vt = static_cast<ValueTrack*>(t); return vt->values.size(); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); return mt->methods.size(); - } break; + } break; } - + ERR_FAIL_V(-1); } @@ -818,11 +818,11 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), Variant()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, tt->transforms.size(), Variant() ); @@ -834,25 +834,25 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { return d; } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, vt->values.size(), Variant() ); return vt->values[p_key_idx].value; } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, mt->methods.size(), Variant() ); Dictionary d; d["method"]=mt->methods[p_key_idx].method; d["args"]=mt->methods[p_key_idx].params; - return d; - - } break; + return d; + + } break; } - + ERR_FAIL_V(Variant()); } @@ -860,33 +860,33 @@ float Animation::track_get_key_time(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, tt->transforms.size(), -1 ); return tt->transforms[p_key_idx].time; } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, vt->values.size(), -1 ); return vt->values[p_key_idx].time; - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, mt->methods.size(), -1 ); return mt->methods[p_key_idx].time; - - - } break; + + + } break; } - + ERR_FAIL_V(-1); } @@ -1004,19 +1004,19 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx,float p_tran template<class K> int Animation::_find( const Vector<K>& p_keys, float p_time) const { - + int len=p_keys.size(); if (len==0) return -2; - + int low = 0; int high = len -1; int middle; - + const K* keys =&p_keys[0]; - + while( low <= high ) { - + middle = ( low + high ) / 2; if( p_time == keys[ middle ].time ) { //match @@ -1029,7 +1029,7 @@ int Animation::_find( const Vector<K>& p_keys, float p_time) const { if (keys[middle].time>p_time) middle--; - + return middle; } @@ -1197,58 +1197,58 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter int len=_find( p_keys, length )+1; // try to find last key (there may be more past the end) - if (len<=0) { + if (len<=0) { // (-1 or -2 returned originally) (plus one above) // meaning no keys, or only key time is larger than length if (p_ok) *p_ok=false; return T(); } else if (len==1) { // one key found (0+1), return it - + if (p_ok) *p_ok=true; return p_keys[0].value; } - + int idx=_find(p_keys, p_time); - + ERR_FAIL_COND_V( idx==-2, T()); - + if (p_ok) *p_ok=true; int next=0; - float c=0; + float c=0; // prepare for all cases of interpolation - + if (loop) { // loop if (idx>=0) { - + if ((idx+1) < len) { - + next=idx+1; float delta=p_keys[next].time - p_keys[idx].time; float from=p_time-p_keys[idx].time; if (Math::absf(delta)>CMP_EPSILON) c=from/delta; - else + else c=0; - + } else { - + next=0; float delta=(length - p_keys[idx].time) + p_keys[next].time; float from=p_time-p_keys[idx].time; - + if (Math::absf(delta)>CMP_EPSILON) - c=from/delta; - else + c=from/delta; + else c=0; - + } - + } else { // on loop, behind first key idx=len-1; @@ -1258,47 +1258,47 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter endtime=0; float delta=endtime + p_keys[next].time; float from=endtime+p_time; - + if (Math::absf(delta)>CMP_EPSILON) - c=from/delta; - else + c=from/delta; + else c=0; - } - - } else { // no loop + } + + } else { // no loop if (idx>=0) { - + if ((idx+1) < len) { - + next=idx+1; float delta=p_keys[next].time - p_keys[idx].time; float from=p_time - p_keys[idx].time; - + if (Math::absf(delta)>CMP_EPSILON) c=from/delta; else c=0; - + } else { - + next=idx; } - + } else if (idx<0) { - + idx=next=0; - } - + } + } - + float tr = p_keys[idx].transition; if (tr==0 || idx==next) { // don't interpolate if not needed return p_keys[idx].value; } - + if (tr!=1.0) { c = Math::ease(c,tr); @@ -1331,7 +1331,7 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter // do a barrel roll - + } @@ -1340,7 +1340,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 ERR_FAIL_INDEX_V(p_track, tracks.size(),ERR_INVALID_PARAMETER); Track *t=tracks[p_track]; ERR_FAIL_COND_V(t->type!=TYPE_TRANSFORM,ERR_INVALID_PARAMETER); - + TransformTrack * tt = static_cast<TransformTrack*>(t); bool ok; @@ -1368,7 +1368,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { ERR_FAIL_INDEX_V(p_track, tracks.size(),0); Track *t=tracks[p_track]; ERR_FAIL_COND_V(t->type!=TYPE_VALUE, Variant()); - ValueTrack * vt = static_cast<ValueTrack*>(t); + ValueTrack * vt = static_cast<ValueTrack*>(t); bool ok; @@ -1377,7 +1377,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { if (ok) { - + return res; } @@ -1426,15 +1426,15 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d float from_time=p_time-p_delta; float to_time=p_time; - + if (from_time>to_time) SWAP(from_time,to_time); - + if (loop) { - - from_time=Math::fposmod(from_time,length); - to_time=Math::fposmod(to_time,length); - + + from_time=Math::fposmod(from_time,length); + to_time=Math::fposmod(to_time,length); + if (from_time>to_time) { // handle loop by splitting _value_track_get_key_indices_in_range(vt,length-from_time,length,p_indices); @@ -1442,12 +1442,12 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d return; } } else { - + if (from_time<0) from_time=0; if (from_time>length) from_time=length; - + if (to_time<0) to_time=0; if (to_time>length) @@ -1455,10 +1455,10 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d } - + _value_track_get_key_indices_in_range(vt,from_time,to_time,p_indices); - + } void Animation::value_track_set_continuous(int p_track, bool p_continuous) { @@ -1519,19 +1519,19 @@ void Animation::_method_track_get_key_indices_in_range(const MethodTrack * mt, f void Animation::method_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const { ERR_FAIL_INDEX(p_track, tracks.size()); - Track *t=tracks[p_track]; + Track *t=tracks[p_track]; ERR_FAIL_COND( t->type != TYPE_METHOD ); MethodTrack * mt = static_cast<MethodTrack*>(t); float from_time=p_time-p_delta; float to_time=p_time; - + if (from_time>to_time) SWAP(from_time,to_time); - + if (loop) { - + if (from_time > length || from_time < 0) from_time=Math::fposmod(from_time,length); @@ -1545,19 +1545,19 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ return; } } else { - + if (from_time<0) from_time=0; if (from_time>length) from_time=length; - + if (to_time<0) to_time=0; if (to_time>length) to_time=length; - + } - + _method_track_get_key_indices_in_range(mt,from_time,to_time,p_indices); @@ -1569,9 +1569,9 @@ Vector<Variant> Animation::method_track_get_params(int p_track,int p_key_idx) co ERR_FAIL_COND_V( t->type != TYPE_METHOD, Vector<Variant>() ); MethodTrack * pm = static_cast<MethodTrack*>(t); - + ERR_FAIL_INDEX_V( p_key_idx, pm->methods.size(), Vector<Variant>() ); - + const MethodKey& mk=pm->methods[p_key_idx]; return mk.params; @@ -1583,9 +1583,9 @@ StringName Animation::method_track_get_name(int p_track,int p_key_idx) const { ERR_FAIL_COND_V( t->type != TYPE_METHOD, StringName() ); MethodTrack * pm = static_cast<MethodTrack*>(t); - + ERR_FAIL_INDEX_V( p_key_idx, pm->methods.size(), StringName() ); - + return pm->methods[ p_key_idx ].method; } @@ -1600,7 +1600,7 @@ void Animation::set_length(float p_length) { float Animation::get_length() const { return length; -} +} void Animation::set_loop(bool p_enabled) { @@ -1678,16 +1678,16 @@ void Animation::_bind_methods() { ObjectTypeDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate); ObjectTypeDB::bind_method(_MD("value_track_set_continuous","idx","continuous"),&Animation::value_track_set_continuous); ObjectTypeDB::bind_method(_MD("value_track_is_continuous","idx"),&Animation::value_track_is_continuous); - + ObjectTypeDB::bind_method(_MD("value_track_get_key_indices","idx","time_sec","delta"),&Animation::_value_track_get_key_indices); ObjectTypeDB::bind_method(_MD("method_track_get_key_indices","idx","time_sec","delta"),&Animation::_method_track_get_key_indices); ObjectTypeDB::bind_method(_MD("method_track_get_name","idx","key_idx"),&Animation::method_track_get_name); ObjectTypeDB::bind_method(_MD("method_track_get_params","idx","key_idx"),&Animation::method_track_get_params); - + ObjectTypeDB::bind_method(_MD("set_length","time_sec"),&Animation::set_length); ObjectTypeDB::bind_method(_MD("get_length"),&Animation::get_length); - + ObjectTypeDB::bind_method(_MD("set_loop","enabled"),&Animation::set_loop); ObjectTypeDB::bind_method(_MD("has_loop"),&Animation::has_loop); @@ -1699,7 +1699,7 @@ void Animation::_bind_methods() { BIND_CONSTANT( TYPE_VALUE ); BIND_CONSTANT( TYPE_TRANSFORM ); BIND_CONSTANT( TYPE_METHOD ); - + BIND_CONSTANT( INTERPOLATION_NEAREST ); BIND_CONSTANT( INTERPOLATION_LINEAR ); BIND_CONSTANT( INTERPOLATION_CUBIC ); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 405b8b6a05..1f2d9b80ab 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -61,7 +61,7 @@ public: private: struct Track { - + TrackType type; InterpolationType interpolation; NodePath path; // path to something @@ -70,20 +70,20 @@ private: }; struct Key { - + float transition; - float time; // time in secs + float time; // time in secs Key() { transition=1; } }; - + // transform key holds either Vector3 or Quaternion template<class T> struct TKey : public Key { - + float time; T value; }; - + struct TransformKey { @@ -93,45 +93,45 @@ private: }; /* TRANSFORM TRACK */ - + struct TransformTrack : public Track { Vector< TKey<TransformKey> > transforms; - + TransformTrack() { type=TYPE_TRANSFORM; } }; - + /* PROPERTY VALUE TRACK */ struct ValueTrack : public Track { bool continuous; Vector< TKey<Variant> > values; - + ValueTrack() { type=TYPE_VALUE; continuous=true; } }; /* METHOD TRACK */ - + struct MethodKey : public Key { - + StringName method; Vector<Variant> params; }; - + struct MethodTrack : public Track { - + Vector< MethodKey > methods; MethodTrack() { type=TYPE_METHOD; } - }; - + }; + Vector<Track*> tracks; /* template<class T> int _insert_pos(float p_time, T& p_keys);*/ - + template<class T> void _clear(T& p_keys); @@ -140,7 +140,7 @@ private: template<class K> inline int _find( const Vector<K>& p_keys, float p_time) const; - + _FORCE_INLINE_ Animation::TransformKey _interpolate( const Animation::TransformKey& p_a, const Animation::TransformKey& p_b, float p_c) const; _FORCE_INLINE_ Vector3 _interpolate( const Vector3& p_a, const Vector3& p_b, float p_c) const; @@ -163,9 +163,9 @@ private: float length; float step; bool loop; - + // bind helpers -private: +private: Array _transform_track_interpolate(int p_track, float p_time) const { Vector3 loc; @@ -180,25 +180,25 @@ private: } DVector<int> _value_track_get_key_indices(int p_track, float p_time, float p_delta) const { - + List<int> idxs; value_track_get_key_indices(p_track,p_time,p_delta,&idxs); DVector<int> idxr; - + for (List<int>::Element *E=idxs.front();E;E=E->next()) { - + idxr.push_back(E->get()); } return idxr; } DVector<int> _method_track_get_key_indices(int p_track, float p_time, float p_delta) const { - + List<int> idxs; method_track_get_key_indices(p_track,p_time,p_delta,&idxs); DVector<int> idxr; - + for (List<int>::Element *E=idxs.front();E;E=E->next()) { - + idxr.push_back(E->get()); } return idxr; @@ -207,28 +207,28 @@ private: bool _transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm); void _transform_track_optimize(int p_idx, float p_allowed_err=0.05, float p_alowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125); -protected: +protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - - static void _bind_methods(); - + + static void _bind_methods(); + public: - + int add_track(TrackType p_type,int p_at_pos=-1); void remove_track(int p_track); int get_track_count() const; TrackType track_get_type(int p_track) const; - + void track_set_path(int p_track,const NodePath& p_path); NodePath track_get_path(int p_track) const; int find_track(const NodePath& p_path) const; // transform - + void track_move_up(int p_track); void track_move_down(int p_track); @@ -248,9 +248,9 @@ public: void track_set_interpolation_type(int p_track,InterpolationType p_interp); InterpolationType track_get_interpolation_type(int p_track) const; - + Error transform_track_interpolate(int p_track, float p_time, Vector3 * r_loc, Quat *r_rot, Vector3 *r_scale) const; - + Variant value_track_interpolate(int p_track, float p_time) const; void value_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const; void value_track_set_continuous(int p_track, bool p_continuous); @@ -259,11 +259,11 @@ public: void method_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const; Vector<Variant> method_track_get_params(int p_track,int p_key_idx) const; StringName method_track_get_name(int p_track,int p_key_idx) const; - + void set_length(float p_length); float get_length() const; - + void set_loop(bool p_enabled); bool has_loop() const; @@ -274,7 +274,7 @@ public: void optimize(float p_allowed_linear_err=0.05,float p_allowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125); - Animation(); + Animation(); ~Animation(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index ea0dbc43e3..7158d067cf 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -558,10 +558,10 @@ void make_default_theme() { t->set_constant("close_v_ofs","WindowDialog", 20 ); t->set_constant("titlebar_height","WindowDialog", 18 ); t->set_constant("title_height","WindowDialog", 20 ); - - + + // File Dialog - + t->set_icon("reload","FileDialog",make_icon( icon_reload_png )); @@ -784,7 +784,7 @@ void make_default_theme() { t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) ); t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) ); - + t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, "")); t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, "")); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 4620bf567a..a72cc6a47f 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -51,7 +51,7 @@ public: enum BGParam { BG_PARAM_CANVAS_MAX_LAYER=VS::ENV_BG_PARAM_CANVAS_MAX_LAYER, - BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, + BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, BG_PARAM_TEXTURE=VS::ENV_BG_PARAM_TEXTURE, BG_PARAM_CUBEMAP=VS::ENV_BG_PARAM_CUBEMAP, BG_PARAM_ENERGY=VS::ENV_BG_PARAM_ENERGY, diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 0aae6fd978..ef5b7a3eb0 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -272,24 +272,24 @@ Error Font::create_from_fnt(const String& p_string) { void Font::set_height(float p_height) { - + height=p_height; } float Font::get_height() const{ - + return height; } void Font::set_ascent(float p_ascent){ - + ascent=p_ascent; } float Font::get_ascent() const { - + return ascent; } float Font::get_descent() const { - + return height-ascent; } @@ -349,7 +349,7 @@ void Font::add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, con c.v_align=p_align.y; c.advance=p_advance; c.h_align=p_align.x; - + char_map[p_char]=c; } @@ -411,7 +411,7 @@ bool Font::is_distance_field_hint() const{ void Font::clear() { - + height=1; ascent=0; char_map.clear(); @@ -423,14 +423,14 @@ void Font::clear() { Size2 Font::get_string_size(const String& p_string) const { float w=0; - + int l = p_string.length(); if (l==0) return Size2(0,height); const CharType *sptr = &p_string[0]; for (int i=0;i<l;i++) { - + w+=get_char_size(sptr[i],sptr[i+1]).width; } @@ -461,9 +461,9 @@ 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 { - + Vector2 ofs; - + for (int i=0;i<p_text.length();i++) { int width = get_char_size(p_text[i]).width; @@ -476,15 +476,15 @@ void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, co } float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate) const { - + const Character * c = char_map.getptr(p_char); - + 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; cpos.y-=ascent; @@ -492,7 +492,7 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ ERR_FAIL_COND_V( c->texture_idx<-1 || c->texture_idx>=textures.size(),0); if (c->texture_idx!=-1) VisualServer::get_singleton()->canvas_item_add_texture_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), textures[c->texture_idx]->get_rid(),c->rect, p_modulate ); - + return get_char_size(p_char,p_next).width; } @@ -561,16 +561,16 @@ void Font::_bind_methods() { } Font::Font() { - + clear(); - + } Font::~Font() { - + clear(); } diff --git a/scene/resources/font.h b/scene/resources/font.h index 61f0352992..03b1ec5191 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -36,21 +36,21 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Font : public Resource { - + OBJ_TYPE( Font, Resource ); RES_BASE_EXTENSION("fnt"); - + Vector< Ref<Texture> > textures; public: struct Character { - + int texture_idx; Rect2 rect; float v_align; float h_align; float advance; - + Character() { texture_idx=0; v_align=0; } }; @@ -69,10 +69,10 @@ public: private: - + HashMap< CharType, Character > char_map; Map<KerningPairKey,int> kerning_map; - + float height; float ascent; bool distance_field_hint; @@ -86,20 +86,20 @@ private: Ref<Font> fallback; protected: - + static void _bind_methods(); public: Error create_from_fnt(const String& p_file); - + void set_height(float p_height); float get_height() const; - + void set_ascent(float p_ascent); - float get_ascent() const; + float get_ascent() const; float get_descent() const; - + void add_texture(const Ref<Texture>& p_texture); void add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, const Size2& p_align, float p_advance=-1); @@ -116,7 +116,7 @@ public: 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; @@ -125,11 +125,11 @@ public: void set_distance_field_hint(bool p_distance_field); bool is_distance_field_hint() const; - + void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const; float draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next=0,const Color& p_modulate=Color(1,1,1)) const; - + Font(); ~Font(); }; diff --git a/scene/resources/material.h b/scene/resources/material.h index 96b33ce129..dbd05c466f 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -41,7 +41,7 @@ class Material : public Resource { - OBJ_TYPE(Material,Resource); + OBJ_TYPE(Material,Resource); RES_BASE_EXTENSION("mtl"); OBJ_SAVE_TYPE( Material ); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 9537fa269f..09c0a21f53 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -126,7 +126,7 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) { add_custom_surface(p_value); return true; - } + } //create Dictionary d=p_value; @@ -223,7 +223,7 @@ void Mesh::_get_property_list( List<PropertyInfo> *p_list) const { } for (int i=0;i<surfaces.size();i++) { - + p_list->push_back( PropertyInfo( Variant::DICTIONARY,"surfaces/"+itos(i), PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR ) ); p_list->push_back( PropertyInfo( Variant::STRING,"surface_"+itos(i+1)+"/name", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ) ); p_list->push_back( PropertyInfo( Variant::OBJECT,"surface_"+itos(i+1)+"/material", PROPERTY_HINT_RESOURCE_TYPE,"Material",PROPERTY_USAGE_EDITOR ) ); @@ -238,9 +238,9 @@ void Mesh::_recompute_aabb() { // regenerate AABB aabb=AABB(); - + for (int i=0;i<surfaces.size();i++) { - + if (i==0) aabb=surfaces[i].aabb; else @@ -383,7 +383,7 @@ void Mesh::surface_remove(int p_idx) { ERR_FAIL_INDEX(p_idx, surfaces.size() ); VisualServer::get_singleton()->mesh_remove_surface(mesh,p_idx); surfaces.remove(p_idx); - + triangle_mesh=Ref<TriangleMesh>(); _recompute_aabb(); _change_notify(); @@ -472,14 +472,14 @@ void Mesh::add_surface_from_mesh_data(const Geometry::MeshData& p_mesh_data) { VisualServer::get_singleton()->mesh_add_surface_from_mesh_data( mesh, p_mesh_data ); AABB aabb; for (int i=0;i<p_mesh_data.vertices.size();i++) { - + if (i==0) aabb.pos=p_mesh_data.vertices[i]; else aabb.expand_to(p_mesh_data.vertices[i]); } - + Surface s; s.aabb=aabb; if (surfaces.size()==0) @@ -524,60 +524,60 @@ DVector<Face3> Mesh::get_faces() const { return DVector<Face3>(); /* for (int i=0;i<surfaces.size();i++) { - + if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES ) continue; - + DVector<int> indices; DVector<Vector3> vertices; - + vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX); - + int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); bool has_indices; - + if (len>0) { - + indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX); has_indices=true; - + } else { - + len=vertices.size(); has_indices=false; } - + if (len<=0) continue; - + DVector<int>::Read indicesr = indices.read(); const int *indicesptr = indicesr.ptr(); - + DVector<Vector3>::Read verticesr = vertices.read(); const Vector3 *verticesptr = verticesr.ptr(); - + int old_faces=faces.size(); int new_faces=old_faces+(len/3); - + faces.resize(new_faces); - + DVector<Face3>::Write facesw = faces.write(); Face3 *facesptr=facesw.ptr(); - - + + for (int i=0;i<len/3;i++) { - + Face3 face; - + for (int j=0;j<3;j++) { - + int idx=i*3+j; face.vertex[j] = has_indices ? verticesptr[ indicesptr[ idx ] ] : verticesptr[idx]; } - + facesptr[i+old_faces]=face; } - + } */ @@ -993,17 +993,17 @@ void Mesh::_bind_methods() { BIND_CONSTANT( NO_INDEX_ARRAY ); BIND_CONSTANT( ARRAY_WEIGHTS_SIZE ); - + BIND_CONSTANT( ARRAY_VERTEX ); BIND_CONSTANT( ARRAY_NORMAL ); BIND_CONSTANT( ARRAY_TANGENT ); BIND_CONSTANT( ARRAY_COLOR ); - BIND_CONSTANT( ARRAY_TEX_UV ); + BIND_CONSTANT( ARRAY_TEX_UV ); BIND_CONSTANT( ARRAY_TEX_UV2 ); BIND_CONSTANT( ARRAY_BONES ); BIND_CONSTANT( ARRAY_WEIGHTS ); BIND_CONSTANT( ARRAY_INDEX ); - + BIND_CONSTANT( ARRAY_FORMAT_VERTEX ); BIND_CONSTANT( ARRAY_FORMAT_NORMAL ); BIND_CONSTANT( ARRAY_FORMAT_TANGENT ); @@ -1013,7 +1013,7 @@ void Mesh::_bind_methods() { BIND_CONSTANT( ARRAY_FORMAT_BONES ); BIND_CONSTANT( ARRAY_FORMAT_WEIGHTS ); BIND_CONSTANT( ARRAY_FORMAT_INDEX ); - + BIND_CONSTANT( PRIMITIVE_POINTS ); BIND_CONSTANT( PRIMITIVE_LINES ); BIND_CONSTANT( PRIMITIVE_LINE_STRIP ); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index e0d9bdf7a8..dc1d97a49e 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -43,9 +43,9 @@ class Mesh : public Resource { RES_BASE_EXTENSION("msh"); public: - + enum { - + NO_INDEX_ARRAY=VisualServer::NO_INDEX_ARRAY, ARRAY_WEIGHTS_SIZE=VisualServer::ARRAY_WEIGHTS_SIZE }; @@ -63,8 +63,8 @@ public: ARRAY_INDEX=VisualServer::ARRAY_INDEX, ARRAY_MAX=VisualServer::ARRAY_MAX - }; - + }; + enum ArrayFormat { /* ARRAY FORMAT FLAGS */ ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory @@ -77,8 +77,8 @@ public: ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS, ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX, - }; - + }; + enum PrimitiveType { PRIMITIVE_POINTS=VisualServer::PRIMITIVE_POINTS, PRIMITIVE_LINES=VisualServer::PRIMITIVE_LINES, @@ -87,7 +87,7 @@ public: PRIMITIVE_TRIANGLES=VisualServer::PRIMITIVE_TRIANGLES, PRIMITIVE_TRIANGLE_STRIP=VisualServer::PRIMITIVE_TRIANGLE_STRIP, PRIMITIVE_TRIANGLE_FAN=VisualServer::PRIMITIVE_TRIANGLE_FAN, - }; + }; enum MorphTargetMode { @@ -95,7 +95,7 @@ public: MORPH_MODE_RELATIVE=VS::MORPH_MODE_RELATIVE, }; -private: +private: struct Surface { String name; AABB aabb; @@ -111,16 +111,16 @@ private: mutable Ref<TriangleMesh> triangle_mesh; - + void _recompute_aabb(); protected: - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static void _bind_methods(); - + public: void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alphasort=false); @@ -174,7 +174,7 @@ public: DVector<Face3> get_faces() const; Ref<TriangleMesh> generate_triangle_mesh() const; Mesh(); - + ~Mesh(); }; diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 8643e96303..76bb1c585f 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -103,7 +103,7 @@ void MeshLibrary::create_item(int p_item) { void MeshLibrary::set_item_name(int p_item,const String& p_name) { ERR_FAIL_COND(!item_map.has(p_item)); - item_map[p_item].name=p_name; + item_map[p_item].name=p_name; emit_changed(); _change_notify(); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index 9a468d5555..bf0107d7a9 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -56,7 +56,7 @@ protected: void _get_property_list( List<PropertyInfo> *p_list) const; static void _bind_methods(); -public: +public: void create_item(int p_item); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index a9010e79a2..ef04c68e8e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -646,7 +646,7 @@ https://github.com/godotengine/godot/issues/3127 } // Save the right type. If this node was created by an instance - // then flag that the node should not be created but reused + // then flag that the node should not be created but reused if (pack_state_stack.empty()) { //this node is not part of an instancing process, so save the type nd.type=_nm_get_string(p_node->get_type(),name_map); @@ -963,7 +963,7 @@ Ref<SceneState> SceneState::_get_base_scene_state() const { int SceneState::find_node_by_path(const NodePath& p_node) const { - if (!node_path_cache.has(p_node)) { + if (!node_path_cache.has(p_node)) { if (_get_base_scene_state().is_valid()) { int idx = _get_base_scene_state()->find_node_by_path(p_node); if (idx>=0) { @@ -1275,7 +1275,7 @@ Dictionary SceneState::get_bundled_scene() const { rnode_paths.resize(node_paths.size()); for(int i=0;i<node_paths.size();i++) { rnode_paths[i]=node_paths[i]; - } + } d["node_paths"]=rnode_paths; Array reditable_instances; diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index 6a26cc472c..6bde508d72 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -66,7 +66,7 @@ class SceneState : public Reference { }; Vector<Property> properties; - Vector<int> groups; + Vector<int> groups; }; diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index e8cdec66df..1a7dc56e40 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -545,7 +545,7 @@ Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const { closest_point=closest; } } - + ERR_FAIL_COND_V(closest_dist==1e20,Vector2()); return closest_point; diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index 2cbe3e949d..b23dbd0bac 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -61,7 +61,7 @@ public: bool is_point_inside(const Vector2& p_point) const; Vector2 get_closest_point(const Vector2& p_point) const; - Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const; + Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const; Rect2 get_bounds() const; diff --git a/scene/resources/room.cpp b/scene/resources/room.cpp index 0f9eb85244..4024e2f45c 100644 --- a/scene/resources/room.cpp +++ b/scene/resources/room.cpp @@ -48,7 +48,7 @@ BSP_Tree RoomBounds::get_bounds() const { } void RoomBounds::set_geometry_hint(const DVector<Face3>& p_geometry_hint) { - + geometry_hint=p_geometry_hint; } diff --git a/scene/resources/room.h b/scene/resources/room.h index c5aaea311e..a9f159cd46 100644 --- a/scene/resources/room.h +++ b/scene/resources/room.h @@ -38,8 +38,8 @@ class RoomBounds : public Resource { OBJ_TYPE( RoomBounds, Resource ); RES_BASE_EXTENSION("room"); - - RID area; + + RID area; DVector<Face3> geometry_hint; void _regenerate_bsp(); @@ -54,10 +54,10 @@ public: void set_bounds( const BSP_Tree& p_bounds ); BSP_Tree get_bounds() const; - + void set_geometry_hint(const DVector<Face3>& geometry_hint); const DVector<Face3>& get_geometry_hint() const; - + RoomBounds(); ~RoomBounds(); diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 6bd5f520d2..f9f7f7807d 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -1144,7 +1144,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re if (packed_scene->get_state()->is_node_instance_placeholder(i)) continue; - Ref<PackedScene> instance=packed_scene->get_state()->get_node_instance(i); + Ref<PackedScene> instance=packed_scene->get_state()->get_node_instance(i); if (instance.is_valid() && !external_resources.has(instance)) { int index = external_resources.size(); external_resources[instance]=index; diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 71a775ee24..75e38f9701 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -37,7 +37,7 @@ void StyleBox::set_default_margin(Margin p_margin, float p_value) { margin[p_margin]=p_value; emit_changed(); - + } float StyleBox::get_default_margin(Margin p_margin) const{ @@ -59,7 +59,7 @@ Size2 StyleBox::get_minimum_size() const { Point2 StyleBox::get_offset() const { - + return Point2( get_margin( MARGIN_LEFT), get_margin( MARGIN_TOP) ); } @@ -94,33 +94,33 @@ void StyleBox::_bind_methods() { } StyleBox::StyleBox() { - + for (int i=0;i<4;i++) { - + margin[i]=-1; } } void StyleBoxTexture::set_texture(RES p_texture) { - + texture=p_texture; emit_changed(); } RES StyleBoxTexture::get_texture() const { - + return texture; } void StyleBoxTexture::set_margin_size(Margin p_margin,float p_size) { - + margin[p_margin]=p_size; emit_changed(); } float StyleBoxTexture::get_margin_size(Margin p_margin) const { - + return margin[p_margin]; } @@ -142,14 +142,14 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const { } void StyleBoxTexture::set_draw_center(bool p_draw) { - + draw_center=p_draw; emit_changed(); } bool StyleBoxTexture::get_draw_center() const { - + return draw_center; } @@ -204,18 +204,18 @@ void StyleBoxTexture::_bind_methods() { } StyleBoxTexture::StyleBoxTexture() { - - + + for (int i=0;i<4;i++) { margin[i]=0; expand_margin[i]=0; } draw_center=true; - + } StyleBoxTexture::~StyleBoxTexture() { - - + + } //////////////// diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index d0466ed5f1..02d79bc2ac 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -36,60 +36,60 @@ @author Juan Linietsky <reduzio@gmail.com> */ class StyleBox : public Resource { - + OBJ_TYPE( StyleBox, Resource ); RES_BASE_EXTENSION("sbx"); OBJ_SAVE_TYPE( StyleBox ); float margin[4]; - -protected: - + +protected: + virtual float get_style_margin(Margin p_margin) const=0; static void _bind_methods(); public: - + virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const; - + void set_default_margin(Margin p_margin, float p_value); float get_default_margin(Margin p_margin) const; float get_margin(Margin p_margin) const; virtual Size2 get_center_size() const; - + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const=0; - + Size2 get_minimum_size() const; Point2 get_offset() const; - + StyleBox(); }; class StyleBoxEmpty : public StyleBox { - + OBJ_TYPE( StyleBoxEmpty, StyleBox ); virtual float get_style_margin(Margin p_margin) const { return 0; } -public: - +public: + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {} StyleBoxEmpty() {} - + }; class StyleBoxTexture : public StyleBox { - + OBJ_TYPE( StyleBoxTexture, StyleBox ); - + float expand_margin[4]; float margin[4]; Ref<Texture> texture; bool draw_center; - -protected: - + +protected: + virtual float get_style_margin(Margin p_margin) const; static void _bind_methods(); - + public: void set_expand_margin_size(Margin p_expand_margin,float p_size); @@ -105,12 +105,12 @@ public: bool get_draw_center() const; virtual Size2 get_center_size() const; - + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const; - - StyleBoxTexture(); + + StyleBoxTexture(); ~StyleBoxTexture(); - + }; class StyleBoxFlat : public StyleBox { diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index bf5070fd7d..e3a02420c7 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -324,7 +324,7 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) { w=DVector<Color>::Write(); a[i]=array; - } break; + } break; case Mesh::ARRAY_FORMAT_BONES: case Mesh::ARRAY_FORMAT_WEIGHTS: { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 28754480f1..1893bfe524 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -163,7 +163,7 @@ bool ImageTexture::_get(const StringName& p_name,Variant &r_ret) const { r_ret= lossy_storage_quality; else return false; - + return true; } @@ -171,8 +171,8 @@ bool ImageTexture::_get(const StringName& p_name,Variant &r_ret) const { void ImageTexture::_get_property_list( List<PropertyInfo> *p_list) const { - - + + PropertyHint img_hint=PROPERTY_HINT_NONE; if (storage==STORAGE_COMPRESS_LOSSY) { img_hint=PROPERTY_HINT_IMAGE_COMPRESS_LOSSY; @@ -207,16 +207,16 @@ void ImageTexture::_reload_hook(const RID& p_hook) { } void ImageTexture::create(int p_width, int p_height,Image::Format p_format,uint32_t p_flags) { - + flags=p_flags; VisualServer::get_singleton()->texture_allocate(texture,p_width, p_height, p_format, p_flags); format=p_format; w=p_width; h=p_height; - + } void ImageTexture::create_from_image(const Image& p_image, uint32_t p_flags) { - + flags=p_flags; w=p_image.get_width(); h=p_image.get_height(); @@ -228,7 +228,7 @@ void ImageTexture::create_from_image(const Image& p_image, uint32_t p_flags) { } void ImageTexture::set_flags(uint32_t p_flags) { - + /* uint32_t cube = flags & FLAG_CUBEMAP; @@ -238,11 +238,11 @@ void ImageTexture::set_flags(uint32_t p_flags) { flags=p_flags|cube; */ flags=p_flags; VisualServer::get_singleton()->texture_set_flags(texture,p_flags); - + } uint32_t ImageTexture::get_flags() const { - + return ImageTexture::flags; } @@ -252,7 +252,7 @@ Image::Format ImageTexture::get_format() const { } void ImageTexture::load(const String& p_path) { - + Image img; img.load(p_path); create_from_image(img); @@ -260,7 +260,7 @@ void ImageTexture::load(const String& p_path) { } void ImageTexture::set_data(const Image& p_image) { - + VisualServer::get_singleton()->texture_set_data(texture,p_image); VisualServer::get_singleton()->texture_set_reload_hook(texture,0,StringName()); //hook is erased if data is changed _change_notify(); @@ -282,23 +282,23 @@ void ImageTexture::_resource_path_changed() { } Image ImageTexture::get_data() const { - + return VisualServer::get_singleton()->texture_get_data(texture); } int ImageTexture::get_width() const { - - return w; + + return w; } int ImageTexture::get_height() const { - + return h; } RID ImageTexture::get_rid() const { - + return texture; } @@ -458,13 +458,13 @@ ImageTexture::ImageTexture() { texture = VisualServer::get_singleton()->texture_create(); storage = STORAGE_RAW; lossy_storage_quality=0.7; - + } ImageTexture::~ImageTexture() { - + VisualServer::get_singleton()->free( texture ); } diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 2627b9480a..103b425cd8 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -84,7 +84,7 @@ VARIANT_ENUM_CAST( Texture::Flags ); class ImageTexture : public Texture { - + OBJ_TYPE( ImageTexture, Texture ); RES_BASE_EXTENSION("tex"); public: @@ -97,12 +97,12 @@ private: RID texture; Image::Format format; uint32_t flags; - int w,h; + int w,h; Storage storage; Size2 size_override; float lossy_storage_quality; -protected: +protected: virtual bool can_reload_from_file(); virtual void reload_from_file(); @@ -117,24 +117,24 @@ protected: void _set_data(Dictionary p_data); public: - + void create(int p_width, int p_height,Image::Format p_format,uint32_t p_flags=FLAGS_DEFAULT); void create_from_image(const Image& p_image, uint32_t p_flags=FLAGS_DEFAULT); - + void set_flags(uint32_t p_flags); uint32_t get_flags() const; Image::Format get_format() const; void load(const String& p_path); void set_data(const Image& p_image); Image get_data() const; - + int get_width() const; int get_height() const; - + virtual RID get_rid() const; - + bool has_alpha() const; virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; virtual void draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 685b2e07e1..74e59b09c3 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -104,67 +104,67 @@ bool Theme::_get(const StringName& p_name,Variant &r_ret) const { } void Theme::_get_property_list( List<PropertyInfo> *p_list) const { - + List<PropertyInfo> list; const StringName *key=NULL; - + while((key=icon_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=icon_map[*key].next(key2))) { list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/icons/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture" ) ); } } - + key=NULL; - + while((key=style_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=style_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/styles/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox" ) ); } } - + key=NULL; - + while((key=font_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=font_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/fonts/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Font" ) ); } } - + key=NULL; - + while((key=color_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=color_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::COLOR, String()+*key+"/colors/"+*key2 ) ); } } - + key=NULL; - + while((key=constant_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=constant_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::INT, String()+*key+"/constants/"+*key2 ) ); } } @@ -173,12 +173,12 @@ void Theme::_get_property_list( List<PropertyInfo> *p_list) const { for(List<PropertyInfo>::Element *E=list.front();E;E=E->next()) { p_list->push_back(E->get()); } - + } Ref<Theme> Theme::get_default() { - - return default_theme; + + return default_theme; } @@ -193,7 +193,7 @@ Ref<Font> Theme::get_default_theme_font() const { } void Theme::set_default(const Ref<Theme>& p_default) { - + default_theme=p_default; } @@ -221,7 +221,7 @@ void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref bool new_value=!icon_map.has(p_type) || !icon_map[p_type].has(p_name); - icon_map[p_type][p_name]=p_icon; + icon_map[p_type][p_name]=p_icon; if (new_value) { _change_notify(); @@ -229,7 +229,7 @@ void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref } } Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type) const { - + if (icon_map.has(p_type) && icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()) { return icon_map[p_type][p_name]; @@ -239,7 +239,7 @@ Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type) } bool Theme::has_icon(const StringName& p_name,const StringName& p_type) const { - + return (icon_map.has(p_type) && icon_map[p_type].has(p_name)); } @@ -266,13 +266,13 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { p_list->push_back(*key); } - + } void Theme::set_shader(const StringName &p_name,const StringName &p_type,const Ref<Shader>& p_shader) { bool new_value=!shader_map.has(p_type) || !shader_map[p_type].has(p_name); - shader_map[p_type][p_name]=p_shader; + shader_map[p_type][p_name]=p_shader; if (new_value) { _change_notify(); @@ -311,7 +311,7 @@ void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) p_list->push_back(*key); } - + } @@ -331,7 +331,7 @@ void Theme::set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox> Theme::get_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (style_map.has(p_type) && style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()) { return style_map[p_type][p_name]; @@ -341,7 +341,7 @@ Ref<StyleBox> Theme::get_stylebox(const StringName& p_name,const StringName& p_t } bool Theme::has_stylebox(const StringName& p_name,const StringName& p_type) const { - + return (style_map.has(p_type) && style_map[p_type].has(p_name) ); } @@ -384,18 +384,18 @@ void Theme::set_font(const StringName& p_name,const StringName& p_type,const Ref } } Ref<Font> Theme::get_font(const StringName& p_name,const StringName& p_type) const { - + if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) - return font_map[p_type][p_name]; + return font_map[p_type][p_name]; else if (default_theme_font.is_valid()) return default_theme_font; else return default_font; - + } bool Theme::has_font(const StringName& p_name,const StringName& p_type) const { - + return (font_map.has(p_type) && font_map[p_type].has(p_name)); } @@ -425,7 +425,7 @@ void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { } void Theme::set_color(const StringName& p_name,const StringName& p_type,const Color& p_color) { - + bool new_value=!color_map.has(p_type) || !color_map[p_type].has(p_name); color_map[p_type][p_name]=p_color; @@ -440,16 +440,16 @@ void Theme::set_color(const StringName& p_name,const StringName& p_type,const Co Color Theme::get_color(const StringName& p_name,const StringName& p_type) const { - + if (color_map.has(p_type) && color_map[p_type].has(p_name)) - return color_map[p_type][p_name]; + return color_map[p_type][p_name]; else return Color(); - + } bool Theme::has_color(const StringName& p_name,const StringName& p_type) const { - + return (color_map.has(p_type) && color_map[p_type].has(p_name)); } @@ -479,7 +479,7 @@ void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { } void Theme::set_constant(const StringName& p_name,const StringName& p_type,int p_constant) { - + bool new_value=!constant_map.has(p_type) || !constant_map[p_type].has(p_name); constant_map[p_type][p_name]=p_constant; @@ -490,17 +490,17 @@ void Theme::set_constant(const StringName& p_name,const StringName& p_type,int p } int Theme::get_constant(const StringName& p_name,const StringName& p_type) const { - + if (constant_map.has(p_type) && constant_map[p_type].has(p_name)) - return constant_map[p_type][p_name]; + return constant_map[p_type][p_name]; else { return 0; } - + } bool Theme::has_constant(const StringName& p_name,const StringName& p_type) const { - + return (constant_map.has(p_type) && constant_map[p_type].has(p_name)); } @@ -635,8 +635,8 @@ void Theme::_bind_methods() { } Theme::Theme() { - - + + } diff --git a/scene/resources/theme.h b/scene/resources/theme.h index 180f55381d..36630087f6 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -40,12 +40,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Theme : public Resource { - + OBJ_TYPE( Theme, Resource ); RES_BASE_EXTENSION("thm"); - + static Ref<Theme> default_theme; - + HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map; HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map; HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map; @@ -56,7 +56,7 @@ protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static Ref<Texture> default_icon; static Ref<StyleBox> default_style; static Ref<Font> default_font; @@ -72,10 +72,10 @@ protected: static void _bind_methods(); public: - + static Ref<Theme> get_default(); static void set_default(const Ref<Theme>& p_default); - + static void set_default_icon( const Ref<Texture>& p_icon ); static void set_default_style( const Ref<StyleBox>& p_default_style); static void set_default_font( const Ref<Font>& p_default_font ); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 6f71287750..bf01929191 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -344,13 +344,13 @@ Array TileSet::_tile_get_shapes(int p_id) const{ } Array TileSet::_get_tiles_ids() const{ - + Array arr; for (Map<int, Data>::Element *E = tile_map.front(); E; E = E->next()) { - arr.push_back(E->key()); + arr.push_back(E->key()); } - + return arr; } diff --git a/scene/resources/volume.cpp b/scene/resources/volume.cpp index 8eb96cb4ad..8e056158cb 100644 --- a/scene/resources/volume.cpp +++ b/scene/resources/volume.cpp @@ -33,10 +33,10 @@ void Volume::_set(const String& p_name, const Variant& p_value) { if (p_name.begins_with("shapes/")) { - + int idx=p_name.get_slice("/",1).to_int()-1; ERR_FAIL_COND( idx != get_shape_count() ); - + Dictionary shape = p_value; ERR_FAIL_COND( !shape.has("type") || !shape.has("data")); String type = shape["type"]; @@ -44,7 +44,7 @@ void Volume::_set(const String& p_name, const Variant& p_value) { Transform transform; if (shape.has("transform")) transform=shape["transform"]; - + if (type=="plane") add_shape(SHAPE_PLANE,data,transform); else if (type=="sphere") @@ -59,7 +59,7 @@ void Volume::_set(const String& p_name, const Variant& p_value) { add_shape(SHAPE_CONVEX_POLYGON,data,transform); else if (type=="concave_polygon") add_shape(SHAPE_CONCAVE_POLYGON,data,transform); - else { + else { ERR_FAIL(); } } @@ -68,14 +68,14 @@ void Volume::_set(const String& p_name, const Variant& p_value) { Variant Volume::_get(const String& p_name) const { if (p_name.begins_with("shapes/")) { - + int idx=p_name.get_slice("/",1).to_int()-1; ERR_FAIL_INDEX_V( idx, get_shape_count(), Variant() ); - + Dictionary shape; - + switch( get_shape_type(idx) ) { - + case SHAPE_PLANE: shape["type"]="plane"; break; case SHAPE_SPHERE: shape["type"]="sphere"; break; case SHAPE_BOX: shape["type"]="box"; break; @@ -83,15 +83,15 @@ Variant Volume::_get(const String& p_name) const { case SHAPE_CAPSULE: shape["type"]="capsule"; break; case SHAPE_CONVEX_POLYGON: shape["type"]="convex_polygon"; break; case SHAPE_CONCAVE_POLYGON: shape["type"]="concave_polygon"; break; - + } - + shape["transform"]=get_shape_transform(idx); shape["data"]=get_shape(idx); return shape; } - + return Variant(); } @@ -99,8 +99,8 @@ void Volume::_get_property_list( List<PropertyInfo> *p_list) const { int count=get_shape_count(); for(int i=0;i<count;i++) { - - p_list->push_back( PropertyInfo( Variant::DICTIONARY, "shapes/"+itos(i+1)) ); + + p_list->push_back( PropertyInfo( Variant::DICTIONARY, "shapes/"+itos(i+1)) ); } } @@ -118,7 +118,7 @@ void Volume::add_shape(ShapeType p_shape_type, const Variant& p_data, const Tran void Volume::add_plane_shape(const Plane& p_plane,const Transform& p_transform) { add_shape(SHAPE_PLANE, p_plane, p_transform ); -} +} void Volume::add_sphere_shape(float p_radius,const Transform& p_transform) { @@ -140,7 +140,7 @@ void Volume::add_cylinder_shape(float p_radius, float p_height,const Transform& void Volume::add_capsule_shape(float p_radius, float p_height,const Transform& p_transform) { Dictionary d; - d["radius"]=p_radius; + d["radius"]=p_radius; d["height"]=p_height; add_shape(SHAPE_CAPSULE,d,p_transform); @@ -179,7 +179,7 @@ void Volume::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_shape_type","shape_idx"),&Volume::get_shape_type); ObjectTypeDB::bind_method(_MD("get_shape_transform","shape_idx"),&Volume::get_shape_transform); ObjectTypeDB::bind_method(_MD("get_shape","shape_idx"),&Volume::get_shape); - + BIND_CONSTANT( SHAPE_PLANE ); BIND_CONSTANT( SHAPE_SPHERE ); BIND_CONSTANT( SHAPE_BOX ); @@ -198,7 +198,7 @@ RID Volume::get_rid() { Volume::Volume() { volume= PhysicsServer::get_singleton()->volume_create(); - + } diff --git a/scene/resources/volume.h b/scene/resources/volume.h index be3cbddbbd..f03e48f1d9 100644 --- a/scene/resources/volume.h +++ b/scene/resources/volume.h @@ -38,16 +38,16 @@ */ class Volume : public Resource { - OBJ_TYPE( Volume, Resource ); + OBJ_TYPE( Volume, Resource ); RID volume; - + protected: - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - - static void _bind_methods(); + + static void _bind_methods(); public: enum ShapeType { @@ -59,22 +59,22 @@ public: SHAPE_CONVEX_POLYGON = PhysicsServer::SHAPE_CONVEX_POLYGON, ///< array of planes:"planes" SHAPE_CONCAVE_POLYGON = PhysicsServer::SHAPE_CONCAVE_POLYGON, ///< vector3 array:"triangles" }; - + void add_shape(ShapeType p_shape_type, const Variant& p_data, const Transform& p_transform=Transform ()); - + void add_plane_shape(const Plane& p_plane,const Transform& p_transform); void add_sphere_shape(float p_radius,const Transform& p_transform); void add_box_shape(const Vector3& p_half_extents,const Transform& p_transform); void add_cylinder_shape(float p_radius, float p_height,const Transform& p_transform); void add_capsule_shape(float p_radius, float p_height,const Transform& p_transform); - + int get_shape_count() const; ShapeType get_shape_type(int p_shape) const; Transform get_shape_transform(int p_shape) const; Variant get_shape(int p_shape) const; virtual RID get_rid(); - + Volume(); ~Volume(); |