diff options
Diffstat (limited to 'scene')
63 files changed, 3114 insertions, 224 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 312b04d414..e350a34013 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -149,11 +149,11 @@ void AnimatedSprite::_notification(int p_what) { Size2i s; s = texture->get_size(); - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; - Rect2i dst_rect(ofs,s); + Rect2 dst_rect(ofs,s); if (hflip) dst_rect.size.x=-dst_rect.size.x; @@ -284,7 +284,7 @@ Rect2 AnimatedSprite::get_item_rect() const { return Node2D::get_item_rect(); Size2i s = t->get_size(); - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; @@ -329,7 +329,7 @@ void AnimatedSprite::_bind_methods() { ADD_SIGNAL(MethodInfo("frame_changed")); ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "frames",PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), _SCS("set_sprite_frames"),_SCS("get_sprite_frames")); - ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered")); ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h")); diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 827256c2fa..f9e79e25bc 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -52,6 +52,17 @@ bool Area2D::is_gravity_a_point() const{ return gravity_is_point; } +void Area2D::set_gravity_distance_scale(real_t p_scale){ + + gravity_distance_scale=p_scale; + Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale); + +} + +real_t Area2D::get_gravity_distance_scale() const{ + return gravity_distance_scale; +} + void Area2D::set_gravity_vector(const Vector2& p_vec){ gravity_vec=p_vec; @@ -535,6 +546,39 @@ uint32_t Area2D::get_layer_mask() const { return layer_mask; } +void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_collision_mask(mask); + +} + +bool Area2D::get_collision_mask_bit(int p_bit) const{ + + return get_collision_mask()&(1<<p_bit); +} + + +void Area2D::set_layer_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_layer_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_layer_mask(mask); + +} + +bool Area2D::get_layer_mask_bit(int p_bit) const{ + + return get_layer_mask()&(1<<p_bit); +} + void Area2D::_bind_methods() { @@ -550,6 +594,9 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area2D::set_gravity_is_point); ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area2D::is_gravity_a_point); + ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area2D::set_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area2D::get_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area2D::set_gravity_vector); ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area2D::get_gravity_vector); @@ -571,6 +618,12 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_layer_mask","layer_mask"),&Area2D::set_layer_mask); ObjectTypeDB::bind_method(_MD("get_layer_mask"),&Area2D::get_layer_mask); + ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&Area2D::set_collision_mask_bit); + ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&Area2D::get_collision_mask_bit); + + ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&Area2D::set_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&Area2D::get_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled); @@ -600,6 +653,7 @@ void Area2D::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp")); @@ -618,6 +672,7 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea set_gravity(98);; set_gravity_vector(Vector2(0,1)); gravity_is_point=false; + gravity_distance_scale=0; linear_damp=0.1; angular_damp=1; locked=false; diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 0c064f54cd..f5a88390e7 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -49,6 +49,7 @@ private: Vector2 gravity_vec; real_t gravity; bool gravity_is_point; + real_t gravity_distance_scale; real_t linear_damp; real_t angular_damp; uint32_t collision_mask; @@ -132,6 +133,9 @@ public: void set_gravity_is_point(bool p_enabled); bool is_gravity_a_point() const; + void set_gravity_distance_scale(real_t p_scale); + real_t get_gravity_distance_scale() const; + void set_gravity_vector(const Vector2& p_vec); Vector2 get_gravity_vector() const; @@ -159,6 +163,12 @@ public: void set_layer_mask(uint32_t p_mask); uint32_t get_layer_mask() const; + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + + void set_layer_mask_bit(int p_bit, bool p_value); + bool get_layer_mask_bit(int p_bit) const; + Array get_overlapping_bodies() const; //function for script Array get_overlapping_areas() const; //function for script diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 70b88a6611..49683da226 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -81,43 +81,47 @@ Matrix32 Camera2D::get_camera_transform() { if (!first) { - if (centered) { + if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) { - if (h_drag_enabled) { - camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT])); - camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT])); - } else { + if (h_drag_enabled) { + camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT])); + camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT])); + } else { - if (h_ofs<0) { - camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; - } else { - camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; - } - } + if (h_ofs<0) { + camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; + } else { + camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; + } + } + + if (v_drag_enabled) { - if (v_drag_enabled) { + camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM])); + camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP])); - camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM])); - camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP])); + } else { - } else { + if (v_ofs<0) { + camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; + } else { + camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; + } + } - if (v_ofs<0) { - camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; - } else { - camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; - } - } + } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){ + camera_pos=new_camera_pos; } + if (smoothing>0.0) { float c = smoothing*get_fixed_process_delta_time(); smoothed_camera_pos = ((new_camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos; ret_camera_pos=smoothed_camera_pos; -// camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; + // camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; } else { ret_camera_pos=smoothed_camera_pos=camera_pos; @@ -132,7 +136,7 @@ Matrix32 Camera2D::get_camera_transform() { } - Point2 screen_offset = (centered ? (screen_size * 0.5 * zoom) : Point2()); + Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2()); float angle = get_global_transform().get_rotation(); if(rotating){ @@ -267,15 +271,15 @@ Vector2 Camera2D::get_offset() const{ return offset; } -void Camera2D::set_centered(bool p_centered){ +void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode){ - centered=p_centered; + anchor_mode=p_anchor_mode; _update_scroll(); } -bool Camera2D::is_centered() const { +Camera2D::AnchorMode Camera2D::get_anchor_mode() const { - return centered; + return anchor_mode; } void Camera2D::set_rotating(bool p_rotating){ @@ -439,8 +443,8 @@ void Camera2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_offset","offset"),&Camera2D::set_offset); ObjectTypeDB::bind_method(_MD("get_offset"),&Camera2D::get_offset); - ObjectTypeDB::bind_method(_MD("set_centered","centered"),&Camera2D::set_centered); - ObjectTypeDB::bind_method(_MD("is_centered"),&Camera2D::is_centered); + ObjectTypeDB::bind_method(_MD("set_anchor_mode","anchor_mode"),&Camera2D::set_anchor_mode); + ObjectTypeDB::bind_method(_MD("get_anchor_mode"),&Camera2D::get_anchor_mode); ObjectTypeDB::bind_method(_MD("set_rotating","rotating"),&Camera2D::set_rotating); ObjectTypeDB::bind_method(_MD("is_rotating"),&Camera2D::is_rotating); @@ -487,7 +491,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"centered"),_SCS("set_centered"),_SCS("is_centered")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"anchor_mode",PROPERTY_HINT_ENUM,"Fixed TopLeft,Drag Center"),_SCS("set_anchor_mode"),_SCS("get_anchor_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"rotating"),_SCS("set_rotating"),_SCS("is_rotating")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"current"),_SCS("_set_current"),_SCS("is_current")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing"),_SCS("set_follow_smoothing"),_SCS("get_follow_smoothing") ); @@ -507,6 +511,8 @@ void Camera2D::_bind_methods() { ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin/bottom",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drag_margin"),_SCS("get_drag_margin"),MARGIN_BOTTOM); + BIND_CONSTANT( ANCHOR_MODE_DRAG_CENTER ); + BIND_CONSTANT( ANCHOR_MODE_FIXED_TOP_LEFT ); } @@ -514,7 +520,7 @@ Camera2D::Camera2D() { - centered=true; + anchor_mode=ANCHOR_MODE_DRAG_CENTER; rotating=false; current=false; limit[MARGIN_LEFT]=-10000000; diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 8975a2584b..79d84f48d0 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -36,6 +36,12 @@ class Camera2D : public Node2D { OBJ_TYPE( Camera2D, Node2D ); +public: + + enum AnchorMode { + ANCHOR_MODE_FIXED_TOP_LEFT, + ANCHOR_MODE_DRAG_CENTER + }; protected: Point2 camera_pos; @@ -49,7 +55,7 @@ protected: RID canvas; Vector2 offset; Vector2 zoom; - bool centered; + AnchorMode anchor_mode; bool rotating; bool current; float smoothing; @@ -77,8 +83,8 @@ public: void set_offset(const Vector2& p_offset); Vector2 get_offset() const; - void set_centered(bool p_centered); - bool is_centered() const; + void set_anchor_mode(AnchorMode p_anchor_mode); + AnchorMode get_anchor_mode() const; void set_rotating(bool p_rotating); bool is_rotating() const; @@ -120,4 +126,6 @@ public: Camera2D(); }; +VARIANT_ENUM_CAST(Camera2D::AnchorMode); + #endif // CAMERA_2D_H diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 9b2cdf4ea2..6a1ea0728d 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -288,6 +288,7 @@ void CanvasItem::show() { if (is_visible()) { _propagate_visibility_changed(true); } + _change_notify("visibility/visible"); } @@ -305,6 +306,7 @@ void CanvasItem::hide() { if (propagate) _propagate_visibility_changed(false); + _change_notify("visibility/visible"); } diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index 5a02501816..5db0e0a9fc 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -91,9 +91,13 @@ void Navigation2D::_navpoly_link(int p_id) { } else { if (C->get().B!=NULL) { - print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); + ConnectionPending pending; + pending.polygon=&p; + pending.edge=j; + p.edges[j].P=C->get().pending.push_back(pending); + continue; + //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); } - ERR_CONTINUE(C->get().B!=NULL); //wut C->get().B=&p; C->get().B_edge=j; @@ -133,7 +137,12 @@ void Navigation2D::_navpoly_unlink(int p_id) { EdgeKey ek(edges[i].point,edges[next].point); Map<EdgeKey,Connection>::Element *C=connections.find(ek); ERR_CONTINUE(!C); - if (C->get().B) { + + if (edges[i].P) { + C->get().pending.erase(edges[i].P); + edges[i].P=NULL; + + } else if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; @@ -149,6 +158,20 @@ void Navigation2D::_navpoly_unlink(int p_id) { C->get().B=NULL; C->get().B_edge=-1; + if (C->get().pending.size()) { + //reconnect if something is pending + ConnectionPending cp = C->get().pending.front()->get(); + C->get().pending.pop_front(); + + C->get().B=cp.polygon; + C->get().B_edge=cp.edge; + C->get().A->edges[C->get().A_edge].C=cp.polygon; + C->get().A->edges[C->get().A_edge].C_edge=cp.edge; + cp.polygon->edges[cp.edge].C=C->get().A; + cp.polygon->edges[cp.edge].C_edge=C->get().A_edge; + cp.polygon->edges[cp.edge].P=NULL; + } + } else { connections.erase(C); //erase diff --git a/scene/2d/navigation2d.h b/scene/2d/navigation2d.h index 829b0f544b..231f1e8c63 100644 --- a/scene/2d/navigation2d.h +++ b/scene/2d/navigation2d.h @@ -41,7 +41,13 @@ class Navigation2D : public Node2D { struct NavMesh; + struct Polygon; + struct ConnectionPending { + + Polygon *polygon; + int edge; + }; struct Polygon { @@ -49,7 +55,8 @@ class Navigation2D : public Node2D { Point point; Polygon *C; //connection int C_edge; - Edge() { C=NULL; C_edge=-1; } + List<ConnectionPending>::Element *P; + Edge() { C=NULL; C_edge=-1; P=NULL; } }; Vector<Edge> edges; @@ -72,6 +79,9 @@ class Navigation2D : public Node2D { int A_edge; Polygon *B; int B_edge; + + List<ConnectionPending> pending; + Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;} }; diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 39d747c436..f0b7c2be60 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -503,19 +503,6 @@ void Particles2D::_notification(int p_what) { if (!local_space) invxform=get_global_transform().affine_inverse(); - int col_count=0; - float last=-1; - ColorPhase cphase[MAX_COLOR_PHASES]; - - for(int i=0;i<color_phase_count;i++) { - - if (color_phases[i].pos<=last) - break; - cphase[i]=color_phases[i]; - col_count++; - } - - int start_particle = (int)(time * (float)particle_count / lifetime); for (int id=0;id<particle_count;++id) { @@ -537,32 +524,14 @@ void Particles2D::_notification(int p_what) { uint32_t rand_seed=p.seed*(i+1); - - int cpos=0; - - while(cpos<col_count) { - - if (cphase[cpos].pos > ptime) - break; - cpos++; - } - - cpos--; - Color color; - //could be faster.. - if (cpos==-1) - color=Color(1,1,1,1); - else { - if (cpos==col_count-1) - color=cphase[cpos].color; - else { - float diff = (cphase[cpos+1].pos-cphase[cpos].pos); - if (diff>0) - color=cphase[cpos].color.linear_interpolate(cphase[cpos+1].color, (ptime - cphase[cpos].pos) / diff ); - else - color=cphase[cpos+1].color; - } + + if(color_ramp.is_valid()) + { + color = color_ramp->get_color_at_offset(ptime); + } else + { + color = default_color; } @@ -813,6 +782,27 @@ Ref<Texture> Particles2D::get_texture() const { return texture; } +void Particles2D::set_color(const Color& p_color) { + + default_color = p_color; +} + +Color Particles2D::get_color() const { + + return default_color; +} + + +void Particles2D::set_color_ramp(const Ref<ColorRamp>& p_color_ramp) { + + color_ramp=p_color_ramp; +} + +Ref<ColorRamp> Particles2D::get_color_ramp() const { + + return color_ramp; +} + void Particles2D::set_emissor_offset(const Point2& p_offset) { emissor_offset=p_offset; @@ -834,40 +824,76 @@ bool Particles2D::is_using_local_space() const { return local_space; } - +//Deprecated. Converts color phases to color ramp void Particles2D::set_color_phases(int p_phases) { - ERR_FAIL_INDEX(p_phases,MAX_COLOR_PHASES+1); - color_phase_count=p_phases; + //Create color ramp if we have 2 or more phases. + //Otherwise first phase phase will be assigned to default color. + if(p_phases > 1 && color_ramp.is_null()) + { + color_ramp = Ref<ColorRamp>(memnew (ColorRamp())); + } + if(color_ramp.is_valid()) + { + color_ramp->get_points().resize(p_phases); + } } +//Deprecated. int Particles2D::get_color_phases() const { - return color_phase_count; + if(color_ramp.is_valid()) + { + return color_ramp->get_points_count(); + } + return 0; } +//Deprecated. Converts color phases to color ramp void Particles2D::set_color_phase_color(int p_phase,const Color& p_color) { ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES); - color_phases[p_phase].color=p_color; - + if(color_ramp.is_valid()) + { + if(color_ramp->get_points_count() > p_phase) + color_ramp->set_color(p_phase, p_color); + } else + { + if(p_phase == 0) + default_color = p_color; + } } + +//Deprecated. Color Particles2D::get_color_phase_color(int p_phase) const { ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,Color()); - return color_phases[p_phase].color; + if(color_ramp.is_valid()) + { + return color_ramp->get_color(p_phase); + } + return Color(0,0,0,1); } +//Deprecated. Converts color phases to color ramp void Particles2D::set_color_phase_pos(int p_phase,float p_pos) { ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES); ERR_FAIL_COND(p_pos<0.0 || p_pos>1.0); - color_phases[p_phase].pos=p_pos; - + if(color_ramp.is_valid() && color_ramp->get_points_count() > p_phase) + { + return color_ramp->set_offset(p_phase, p_pos); + } } + +//Deprecated. float Particles2D::get_color_phase_pos(int p_phase) const { ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,0); - return color_phases[p_phase].pos; + if(color_ramp.is_valid()) + { + return color_ramp->get_offset(p_phase); + } + return 0; } void Particles2D::set_emission_half_extents(const Vector2& p_extents) { @@ -997,6 +1023,12 @@ void Particles2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_texture:Texture","texture"),&Particles2D::set_texture); ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&Particles2D::get_texture); + ObjectTypeDB::bind_method(_MD("set_color","color"),&Particles2D::set_color); + ObjectTypeDB::bind_method(_MD("get_color"),&Particles2D::get_color); + + ObjectTypeDB::bind_method(_MD("set_color_ramp:ColorRamp","color_ramp"),&Particles2D::set_color_ramp); + ObjectTypeDB::bind_method(_MD("get_color_ramp:ColorRamp"),&Particles2D::get_color_ramp); + ObjectTypeDB::bind_method(_MD("set_emissor_offset","offset"),&Particles2D::set_emissor_offset); ObjectTypeDB::bind_method(_MD("get_emissor_offset"),&Particles2D::get_emissor_offset); @@ -1055,7 +1087,6 @@ void Particles2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT,"config/v_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_v_frames"),_SCS("get_v_frames")); - for(int i=0;i<PARAM_MAX;i++) { ADD_PROPERTYI(PropertyInfo(Variant::REAL,_particlesframe_property_names[i],PROPERTY_HINT_RANGE,_particlesframe_property_ranges[i]),_SCS("set_param"),_SCS("get_param"),i); } @@ -1064,14 +1095,17 @@ void Particles2D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL,_particlesframe_property_rnames[i],PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_randomness"),_SCS("get_randomness"),i); } - ADD_PROPERTY( PropertyInfo( Variant::INT, "color_phases/count",PROPERTY_HINT_RANGE,"0,4,1"), _SCS("set_color_phases"), _SCS("get_color_phases")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "color_phases/count",PROPERTY_HINT_RANGE,"0,4,1", 0), _SCS("set_color_phases"), _SCS("get_color_phases")); + //Backward compatibility. They will be converted to color ramp for(int i=0;i<MAX_COLOR_PHASES;i++) { String phase="phase_"+itos(i)+"/"; - ADD_PROPERTYI( PropertyInfo( Variant::REAL, phase+"pos", PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_color_phase_pos"),_SCS("get_color_phase_pos"),i ); - ADD_PROPERTYI( PropertyInfo( Variant::COLOR, phase+"color"),_SCS("set_color_phase_color"),_SCS("get_color_phase_color"),i ); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, phase+"pos", PROPERTY_HINT_RANGE,"0,1,0.01", 0),_SCS("set_color_phase_pos"),_SCS("get_color_phase_pos"),i ); + ADD_PROPERTYI( PropertyInfo( Variant::COLOR, phase+"color", PROPERTY_HINT_NONE, "", 0),_SCS("set_color_phase_color"),_SCS("get_color_phase_color"),i ); } + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color/color"),_SCS("set_color"),_SCS("get_color")); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"color/color_ramp",PROPERTY_HINT_RESOURCE_TYPE,"ColorRamp"),_SCS("set_color_ramp"),_SCS("get_color_ramp")); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2_ARRAY,"emission_points",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_emission_points"),_SCS("get_emission_points")); @@ -1097,8 +1131,6 @@ void Particles2D::_bind_methods() { } - - Particles2D::Particles2D() { for(int i=0;i<PARAM_MAX;i++) { @@ -1118,6 +1150,7 @@ Particles2D::Particles2D() { set_param(PARAM_FINAL_SIZE,1.0); set_param(PARAM_ANIM_SPEED_SCALE,1.0); + set_color(Color(1,1,1,1)); time=0; lifetime=2; @@ -1129,17 +1162,6 @@ Particles2D::Particles2D() { preprocess=0; time_scale=1.0; - color_phase_count=1; - - set_color_phase_pos(0,0.0); - set_color_phase_pos(1,1.0); - set_color_phase_pos(2,1.0); - set_color_phase_pos(3,1.0); - - set_color_phase_color(0,Color(1,1,1)); - set_color_phase_color(1,Color(0,0,0)); - set_color_phase_color(2,Color(0,0,0)); - set_color_phase_color(3,Color(0,0,0)); flip_h=false; flip_v=false; diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h index 90b5a188a6..4ee0fcf8da 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/particles_2d.h @@ -31,6 +31,7 @@ #include "scene/2d/node_2d.h" #include "scene/resources/texture.h" +#include "scene/resources/color_ramp.h" class Particles2D; class ParticleAttractor2D : public Node2D { @@ -125,11 +126,6 @@ private: }; Vector<Particle> particles; - int color_phase_count; - struct ColorPhase { - Color color; - float pos; - } color_phases[MAX_COLOR_PHASES]; struct AttractorCache { @@ -161,6 +157,9 @@ private: Ref<Texture> texture; + //If no color ramp is set then default color is used. Created as simple alternative to color_ramp. + Color default_color; + Ref<ColorRamp> color_ramp; void testee(int a, int b, int c, int d, int e); void _process_particles(float p_delta); @@ -230,6 +229,12 @@ public: void set_texture(const Ref<Texture>& p_texture); Ref<Texture> get_texture() const; + void set_color(const Color& p_color); + Color get_color() const; + + void set_color_ramp(const Ref<ColorRamp>& p_texture); + Ref<ColorRamp> get_color_ramp() const; + void set_emissor_offset(const Point2& p_offset); Point2 get_emissor_offset() const; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 3d2917d843..c30921eb69 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -85,6 +85,14 @@ void PhysicsBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask); ObjectTypeDB::bind_method(_MD("set_collision_mask","mask"),&PhysicsBody2D::set_collision_mask); ObjectTypeDB::bind_method(_MD("get_collision_mask"),&PhysicsBody2D::get_collision_mask); + + + ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&PhysicsBody2D::set_collision_mask_bit); + ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&PhysicsBody2D::get_collision_mask_bit); + + ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&PhysicsBody2D::set_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&PhysicsBody2D::get_layer_mask_bit); + ObjectTypeDB::bind_method(_MD("_set_layers","mask"),&PhysicsBody2D::_set_layers); ObjectTypeDB::bind_method(_MD("_get_layers"),&PhysicsBody2D::_get_layers); ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction); @@ -122,6 +130,37 @@ uint32_t PhysicsBody2D::get_collision_mask() const { return collision_mask; } +void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_collision_mask(mask); + +} +bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const{ + + return get_collision_mask()&(1<<p_bit); +} + + +void PhysicsBody2D::set_layer_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_layer_mask(); + if (p_value) + mask|=1<<p_bit; + else + mask&=~(1<<p_bit); + set_layer_mask(mask); + +} + +bool PhysicsBody2D::get_layer_mask_bit(int p_bit) const{ + + return get_layer_mask()&(1<<p_bit); +} PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) { diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 03f95959b6..b70fdd59cf 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -61,6 +61,13 @@ public: void set_collision_mask(uint32_t p_mask); uint32_t get_collision_mask() const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + + void set_layer_mask_bit(int p_bit, bool p_value); + bool get_layer_mask_bit(int p_bit) const; + void add_collision_exception_with(Node* p_node); //must be physicsbody void remove_collision_exception_with(Node* p_node); diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 0c0a0d7822..0485033691 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -82,7 +82,7 @@ void Sprite::_notification(int p_what) { } - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; @@ -265,7 +265,7 @@ Rect2 Sprite::get_item_rect() const { s=s/Point2(hframes,vframes); } - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; @@ -320,7 +320,7 @@ void Sprite::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v")); ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes"), _SCS("set_vframes"),_SCS("get_vframes")); ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes"), _SCS("set_hframes"),_SCS("get_hframes")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region")); ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); @@ -413,11 +413,11 @@ void ViewportSprite::_notification(int p_what) { src_rect.size=s; - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; - Rect2i dst_rect(ofs,s); + Rect2 dst_rect(ofs,s); texture->draw_rect_region(ci,dst_rect,src_rect,modulate); } break; @@ -505,7 +505,7 @@ Rect2 ViewportSprite::get_item_rect() const { Size2i s; s = texture->get_size(); - Point2i ofs=offset; + Point2 ofs=offset; if (centered) ofs-=s/2; diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index ea4b1fc7b0..dc72c9a267 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -155,6 +155,11 @@ void VisibilityEnabler2D::_screen_enter() { _change_node_state(E->key(),true); } + if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent()) + get_parent()->set_fixed_process(true); + if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) + get_parent()->set_process(true); + visible=true; } @@ -165,6 +170,11 @@ void VisibilityEnabler2D::_screen_exit(){ _change_node_state(E->key(),false); } + if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent()) + get_parent()->set_fixed_process(false); + if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) + get_parent()->set_process(false); + visible=false; } @@ -235,6 +245,12 @@ void VisibilityEnabler2D::_notification(int p_what){ _find_nodes(from); + if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent()) + get_parent()->set_fixed_process(false); + if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) + get_parent()->set_process(false); + + } if (p_what==NOTIFICATION_EXIT_TREE) { @@ -317,10 +333,14 @@ void VisibilityEnabler2D::_bind_methods(){ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_animations"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_ANIMATIONS ); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/freeze_bodies"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_FREEZE_BODIES); ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_particles"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_PARTICLES); + ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_PROCESS); + ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/fixed_process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_FIXED_PROCESS); BIND_CONSTANT( ENABLER_FREEZE_BODIES ); BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS ); BIND_CONSTANT( ENABLER_PAUSE_PARTICLES ); + BIND_CONSTANT( ENABLER_PARENT_PROCESS ); + BIND_CONSTANT( ENABLER_PARENT_FIXED_PROCESS ); BIND_CONSTANT( ENABLER_MAX); } @@ -341,6 +361,8 @@ VisibilityEnabler2D::VisibilityEnabler2D() { for(int i=0;i<ENABLER_MAX;i++) enabler[i]=true; + enabler[ENABLER_PARENT_PROCESS]=false; + enabler[ENABLER_PARENT_FIXED_PROCESS]=false; visible=false; diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h index ce68724630..1f7e4c6d45 100644 --- a/scene/2d/visibility_notifier_2d.h +++ b/scene/2d/visibility_notifier_2d.h @@ -74,6 +74,8 @@ public: ENABLER_PAUSE_ANIMATIONS, ENABLER_FREEZE_BODIES, ENABLER_PAUSE_PARTICLES, + ENABLER_PARENT_PROCESS, + ENABLER_PARENT_FIXED_PROCESS, ENABLER_MAX }; diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index d49ffff729..a00946a07a 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -52,6 +52,17 @@ bool Area::is_gravity_a_point() const{ return gravity_is_point; } +void Area::set_gravity_distance_scale(real_t p_scale){ + + gravity_distance_scale=p_scale; + PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale); + +} + +real_t Area::get_gravity_distance_scale() const{ + return gravity_distance_scale; +} + void Area::set_gravity_vector(const Vector3& p_vec){ gravity_vec=p_vec; @@ -214,27 +225,56 @@ void Area::_clear_monitoring() { } ERR_FAIL_COND(locked); - Map<ObjectID,BodyState> bmcopy = body_map; - body_map.clear(); - //disconnect all monitored stuff + { + Map<ObjectID,BodyState> bmcopy = body_map; + body_map.clear(); + //disconnect all monitored stuff - for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) { + for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) { - Object *obj = ObjectDB::get_instance(E->key()); - Node *node = obj ? obj->cast_to<Node>() : NULL; - ERR_CONTINUE(!node); - if (!E->get().in_tree) - continue; + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; + + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + } - for(int i=0;i<E->get().shapes.size();i++) { + emit_signal(SceneStringNames::get_singleton()->body_exit,obj); - emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); } - emit_signal(SceneStringNames::get_singleton()->body_exit,obj); + } + + { + + Map<ObjectID,AreaState> bmcopy = area_map; + area_map.clear(); + //disconnect all monitored stuff + + for (Map<ObjectID,AreaState>::Element *E=bmcopy.front();E;E=E->next()) { + + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; - node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + } } } @@ -260,10 +300,127 @@ void Area::set_enable_monitoring(bool p_enable) { if (monitoring) { PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),this,"_body_inout"); + PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,"_area_inout"); } else { PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName()); + PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName()); _clear_monitoring(); + + } +} + + +void Area::_area_enter_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_FAIL_COND(!node); + + Map<ObjectID,AreaState>::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(E->get().in_tree); + + E->get().in_tree=true; + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area::_area_exit_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to<Node>() : NULL; + ERR_FAIL_COND(!node); + Map<ObjectID,AreaState>::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(!E->get().in_tree); + E->get().in_tree=false; + emit_signal(SceneStringNames::get_singleton()->area_exit,node); + for(int i=0;i<E->get().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) { + + + bool area_in = p_status==PhysicsServer::AREA_BODY_ADDED; + ObjectID objid=p_instance; + + Object *obj = ObjectDB::get_instance(objid); + Node *node = obj ? obj->cast_to<Node>() : NULL; + + Map<ObjectID,AreaState>::Element *E=area_map.find(objid); + + ERR_FAIL_COND(!area_in && !E); + + locked=true; + + if (area_in) { + if (!E) { + + E = area_map.insert(objid,AreaState()); + E->get().rc=0; + E->get().in_tree=node && node->is_inside_tree(); + if (node) { + node->connect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid)); + if (E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + + } + } + + } + E->get().rc++; + if (node) + E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape)); + + + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,objid,node,p_area_shape,p_self_shape); + } + + } else { + + E->get().rc--; + + if (node) + E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape)); + + bool eraseit=false; + + if (E->get().rc==0) { + + if (node) { + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + if (E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + } + + } + + eraseit=true; + + } + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,objid,obj,p_area_shape,p_self_shape); + } + + if (eraseit) + area_map.erase(E); + } + + locked=false; + + } bool Area::is_monitoring_enabled() const { @@ -291,17 +448,85 @@ Array Area::get_overlapping_bodies() const { return ret; } +void Area::set_monitorable(bool p_enable) { + + if (locked) { + ERR_EXPLAIN("This function can't be used during the in/out signal."); + } + ERR_FAIL_COND(locked); + + if (p_enable==monitorable) + return; + + monitorable=p_enable; + + PhysicsServer::get_singleton()->area_set_monitorable(get_rid(),monitorable); +} + +bool Area::is_monitorable() const { + + return monitorable; +} + + +Array Area::get_overlapping_areas() const { + + ERR_FAIL_COND_V(!monitoring,Array()); + Array ret; + ret.resize(area_map.size()); + int idx=0; + for (const Map<ObjectID,AreaState>::Element *E=area_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} + +bool Area::overlaps_area(Node* p_area) const { + + ERR_FAIL_NULL_V(p_area,false); + const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + + + +} + +bool Area::overlaps_body(Node* p_body) const{ + + ERR_FAIL_NULL_V(p_body,false); + const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + +} + void Area::_bind_methods() { ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area::_body_enter_tree); ObjectTypeDB::bind_method(_MD("_body_exit_tree","id"),&Area::_body_exit_tree); + ObjectTypeDB::bind_method(_MD("_area_enter_tree","id"),&Area::_area_enter_tree); + ObjectTypeDB::bind_method(_MD("_area_exit_tree","id"),&Area::_area_exit_tree); + ObjectTypeDB::bind_method(_MD("set_space_override_mode","enable"),&Area::set_space_override_mode); ObjectTypeDB::bind_method(_MD("get_space_override_mode"),&Area::get_space_override_mode); ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area::set_gravity_is_point); ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area::is_gravity_a_point); + ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area::set_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area::get_gravity_distance_scale); + ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area::set_gravity_vector); ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area::get_gravity_vector); @@ -314,13 +539,21 @@ void Area::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area::set_priority); ObjectTypeDB::bind_method(_MD("get_priority"),&Area::get_priority); + ObjectTypeDB::bind_method(_MD("set_monitorable","enable"),&Area::set_monitorable); + ObjectTypeDB::bind_method(_MD("is_monitorable"),&Area::is_monitorable); + ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area::is_monitoring_enabled); ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area::get_overlapping_bodies); + ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area::get_overlapping_areas); + + ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody","body"),&Area::overlaps_body); + ObjectTypeDB::bind_method(_MD("overlaps_area:Area","area"),&Area::overlaps_area); ObjectTypeDB::bind_method(_MD("_body_inout"),&Area::_body_inout); + ObjectTypeDB::bind_method(_MD("_area_inout"),&Area::_area_inout); ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); @@ -328,13 +561,20 @@ void Area::_bind_methods() { ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body"))); ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body"))); + ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_exit_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); + ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area"))); + ADD_PROPERTY( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density")); ADD_PROPERTY( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable")); } @@ -345,11 +585,13 @@ Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),tru locked=false; set_gravity_vector(Vector3(0,-1,0)); gravity_is_point=false; + gravity_distance_scale=0; density=0.1; priority=0; monitoring=false; set_ray_pickable(false); set_enable_monitoring(true); + set_monitorable(true); } diff --git a/scene/3d/area.h b/scene/3d/area.h index 493c71c595..fa7500c47c 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -49,9 +49,11 @@ private: Vector3 gravity_vec; real_t gravity; bool gravity_is_point; + real_t gravity_distance_scale; real_t density; int priority; bool monitoring; + bool monitorable; bool locked; @@ -83,6 +85,36 @@ private: }; Map<ObjectID,BodyState> body_map; + + + void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape); + + void _area_enter_tree(ObjectID p_id); + void _area_exit_tree(ObjectID p_id); + + struct AreaShapePair { + + int area_shape; + int self_shape; + bool operator<(const AreaShapePair& p_sp) const { + if (area_shape==p_sp.area_shape) + return self_shape < p_sp.self_shape; + else + return area_shape < p_sp.area_shape; + } + + AreaShapePair() {} + AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; } + }; + + struct AreaState { + + int rc; + bool in_tree; + VSet<AreaShapePair> shapes; + }; + + Map<ObjectID,AreaState> area_map; void _clear_monitoring(); @@ -98,6 +130,9 @@ public: void set_gravity_is_point(bool p_enabled); bool is_gravity_a_point() const; + void set_gravity_distance_scale(real_t p_scale); + real_t get_gravity_distance_scale() const; + void set_gravity_vector(const Vector3& p_vec); Vector3 get_gravity_vector() const; @@ -113,7 +148,14 @@ public: void set_enable_monitoring(bool p_enable); bool is_monitoring_enabled() const; + void set_monitorable(bool p_enable); + bool is_monitorable() const; + Array get_overlapping_bodies() const; + Array get_overlapping_areas() const; //function for script + + bool overlaps_area(Node* p_area) const; + bool overlaps_body(Node* p_body) const; Area(); diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 48820706dd..bfa8add09c 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -85,9 +85,14 @@ void Navigation::_navmesh_link(int p_id) { } else { if (C->get().B!=NULL) { - print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); + ConnectionPending pending; + pending.polygon=&p; + pending.edge=j; + p.edges[j].P=C->get().pending.push_back(pending); + continue; + //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); } - ERR_CONTINUE(C->get().B!=NULL); //wut + //ERR_CONTINUE(C->get().B!=NULL); //wut C->get().B=&p; C->get().B_edge=j; @@ -126,8 +131,13 @@ void Navigation::_navmesh_unlink(int p_id) { EdgeKey ek(edges[i].point,edges[next].point); Map<EdgeKey,Connection>::Element *C=connections.find(ek); + ERR_CONTINUE(!C); - if (C->get().B) { + + if (edges[i].P) { + C->get().pending.erase(edges[i].P); + edges[i].P=NULL; + } else if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; @@ -143,6 +153,20 @@ void Navigation::_navmesh_unlink(int p_id) { C->get().B=NULL; C->get().B_edge=-1; + if (C->get().pending.size()) { + //reconnect if something is pending + ConnectionPending cp = C->get().pending.front()->get(); + C->get().pending.pop_front(); + + C->get().B=cp.polygon; + C->get().B_edge=cp.edge; + C->get().A->edges[C->get().A_edge].C=cp.polygon; + C->get().A->edges[C->get().A_edge].C_edge=cp.edge; + cp.polygon->edges[cp.edge].C=C->get().A; + cp.polygon->edges[cp.edge].C_edge=C->get().A_edge; + cp.polygon->edges[cp.edge].P=NULL; + } + } else { connections.erase(C); //erase diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 0f7f67571f..f8434aaf72 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -42,6 +42,13 @@ class Navigation : public Spatial { struct NavMesh; + struct Polygon; + + struct ConnectionPending { + + Polygon *polygon; + int edge; + }; struct Polygon { @@ -50,7 +57,8 @@ class Navigation : public Spatial { Point point; Polygon *C; //connection int C_edge; - Edge() { C=NULL; C_edge=-1; } + List<ConnectionPending>::Element *P; + Edge() { C=NULL; C_edge=-1; P=NULL; } }; Vector<Edge> edges; @@ -72,6 +80,9 @@ class Navigation : public Spatial { int A_edge; Polygon *B; int B_edge; + + List<ConnectionPending> pending; + Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;} }; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 9c69520a85..c672d0e94f 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -626,10 +626,11 @@ void Spatial::rotate_z(float p_radians){ void Spatial::translate(const Vector3& p_offset){ Transform t =get_transform(); - t.origin+=p_offset; + t.translate(p_offset); set_transform(t); } + void Spatial::scale(const Vector3& p_ratio){ Transform t =get_transform(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 4952f742df..e9da95f3fb 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -580,7 +580,7 @@ void Sprite3D::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes"), _SCS("set_vframes"),_SCS("get_vframes")); ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes"), _SCS("set_hframes"),_SCS("get_hframes")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region")); ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); @@ -727,7 +727,7 @@ void AnimatedSprite3D::_bind_methods(){ ObjectTypeDB::bind_method(_MD("get_frame"),&AnimatedSprite3D::get_frame); ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), _SCS("set_sprite_frames"),_SCS("get_sprite_frames")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame")); ADD_SIGNAL(MethodInfo("frame_changed")); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 51afe6b3fc..74ae2c0d55 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -223,7 +223,7 @@ void AnimationPlayer::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - stop_all(); + //stop_all(); clear_caches(); } break; } @@ -295,7 +295,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { 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 (unexisting bone) + // broken track (nonexistent bone) p_anim->node_cache[i]->skeleton=NULL; p_anim->node_cache[i]->spatial=NULL; printf("bone is %ls\n", String(bone_name).c_str()); @@ -967,14 +967,16 @@ String AnimationPlayer::get_current_animation() const { } -void AnimationPlayer::stop() { +void AnimationPlayer::stop(bool p_reset) { Playback &c=playback; c.blend.clear(); - c.current.from=NULL; + if (p_reset) { + c.current.from=NULL; + } _set_process(false); queued.clear(); - playing = false; + playing = false; } void AnimationPlayer::stop_all() { @@ -1211,7 +1213,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_default_blend_time"),&AnimationPlayer::get_default_blend_time); ObjectTypeDB::bind_method(_MD("play","name","custom_blend","custom_speed","from_end"),&AnimationPlayer::play,DEFVAL(""),DEFVAL(-1),DEFVAL(1.0),DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("stop"),&AnimationPlayer::stop); + ObjectTypeDB::bind_method(_MD("stop","reset"),&AnimationPlayer::stop,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("stop_all"),&AnimationPlayer::stop_all); ObjectTypeDB::bind_method(_MD("is_playing"),&AnimationPlayer::is_playing); ObjectTypeDB::bind_method(_MD("set_current_animation","anim"),&AnimationPlayer::set_current_animation); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 8d7d6d04e0..3fddc283ae 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -260,7 +260,7 @@ public: void play(const StringName& p_name=StringName(),float p_custom_blend=-1,float p_custom_scale=1.0,bool p_from_end=false); void queue(const StringName& p_name); void clear_queue(); - void stop(); + void stop(bool p_reset=true); bool is_playing() const; String get_current_animation() const; void set_current_animation(const String& p_anim); diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index dff2377766..8b6f433c9c 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -148,6 +148,7 @@ void BaseButton::_input_event(InputEvent p_event) { update(); } } break; + case InputEvent::ACTION: case InputEvent::JOYSTICK_BUTTON: case InputEvent::KEY: { diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 5b837d699c..b465db5c80 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -97,6 +97,13 @@ void Button::_notification(int p_what) { } break; } + + if (has_focus()) { + + Ref<StyleBox> style = get_stylebox("focus"); + style->draw(ci,Rect2(Point2(),size)); + } + Ref<StyleBox> style = get_stylebox("normal" ); Ref<Font> font=get_font("font"); Ref<Texture> _icon; @@ -134,11 +141,7 @@ void Button::_notification(int p_what) { _icon->draw(ci,Point2(style->get_offset().x, Math::floor( (size.height-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } - if (has_focus()) { - Ref<StyleBox> style = get_stylebox("focus"); - style->draw(ci,Rect2(Point2(),size)); - } } } diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp new file mode 100644 index 0000000000..14a48fe3d3 --- /dev/null +++ b/scene/gui/color_ramp_edit.cpp @@ -0,0 +1,422 @@ +#include "color_ramp_edit.h" +#include "os/keyboard.h" + +ColorRampEdit::ColorRampEdit(){ + grabbed=-1; + grabbing=false; + set_focus_mode(FOCUS_ALL); + + popup = memnew( PopupPanel ); + picker = memnew( ColorPicker ); + popup->add_child(picker); + popup->set_child_rect(picker); + add_child(popup); + + checker = Ref<ImageTexture>(memnew( ImageTexture )); + checker->create_from_image( Image(checker_bg_png),ImageTexture::FLAG_REPEAT ); +} + +int ColorRampEdit::_get_point_from_pos(int x) { + int result = -1; + int total_w = get_size().width-get_size().height-3; + for(int i=0;i<points.size();i++) { + //Check if we clicked at point + if (ABS(x-points[i].offset*total_w+1)<(POINT_WIDTH/2+1)) { + result=i; + } + } + return result; +} + +void ColorRampEdit::_show_color_picker() { + if (grabbed==-1) + return; + Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + picker->set_color(points[grabbed].color); + popup->set_pos(get_global_pos()-Vector2(ms.width-get_size().width,ms.height)); + popup->set_size(ms); + popup->popup(); +} + +ColorRampEdit::~ColorRampEdit() { + +} + +void ColorRampEdit::_input_event(const InputEvent& p_event) { + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + grabbing=false; + update(); + emit_signal("ramp_changed"); + accept_event(); + } + + //Show color picker on double click. + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.doubleclick && p_event.mouse_button.pressed) { + grabbed=_get_point_from_pos(p_event.mouse_button.x); + _show_color_picker(); + accept_event(); + } + + //Delete point on right click + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==2 && p_event.mouse_button.pressed) { + grabbed=_get_point_from_pos(p_event.mouse_button.x); + if(grabbed != -1) + { + points.remove(grabbed); + grabbed=-1; + grabbing=false; + update(); + emit_signal("ramp_changed"); + accept_event(); + } + } + + //Hold alt key to duplicate selected color + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed && p_event.key.mod.alt ) { + + int x = p_event.mouse_button.x; + grabbed=_get_point_from_pos(x); + + if( grabbed != -1 ) { + int total_w = get_size().width-get_size().height-3; + ColorRamp::Point newPoint = points[grabbed]; + newPoint.offset=CLAMP(x/float(total_w),0,1); + + points.push_back(newPoint); + points.sort(); + for(int i=0;i<points.size();++i) { + if (points[i].offset==newPoint.offset) { + grabbed=i; + break; + } + } + + emit_signal("ramp_changed"); + update(); + } + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + + update(); + int x = p_event.mouse_button.x; + int total_w = get_size().width-get_size().height-3; + + //Check if color selector was clicked. + if (x>total_w+3) { + _show_color_picker(); + return; + } + + grabbing=true; + + grabbed=_get_point_from_pos(x); + //grab or select + if (grabbed!=-1) { + return; + } + + //insert + ColorRamp::Point newPoint; + newPoint.offset=CLAMP(x/float(total_w),0,1); + + ColorRamp::Point prev; + ColorRamp::Point next; + + int pos=-1; + for(int i=0;i<points.size();i++) { + if (points[i].offset<newPoint.offset) + pos=i; + } + + if (pos==-1) { + + prev.color=Color(0,0,0); + prev.offset=0; + if (points.size()) { + next=points[0]; + } else { + next.color=Color(1,1,1); + next.offset=1.0; + } + } else { + + if (pos==points.size()-1) { + next.color=Color(1,1,1); + next.offset=1.0; + } else { + next=points[pos+1]; + } + prev=points[pos]; + + } + + newPoint.color=prev.color.linear_interpolate(next.color,(newPoint.offset-prev.offset)/(next.offset-prev.offset)); + + points.push_back(newPoint); + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==newPoint.offset) { + grabbed=i; + break; + } + } + + emit_signal("ramp_changed"); + + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) { + + if (grabbing) { + grabbing=false; + emit_signal("ramp_changed"); + } + update(); + } + + if (p_event.type==InputEvent::MOUSE_MOTION && grabbing) { + + int total_w = get_size().width-get_size().height-3; + + 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; + float smallest_ofs = snap_treshhold; + bool founded = false; + int nearest_point; + for(int i=0;i<points.size();++i) { + if (i != grabbed) { + float temp_ofs = ABS(points[i].offset - newofs); + if (temp_ofs < smallest_ofs) { + smallest_ofs = temp_ofs; + nearest_point = i; + if (founded) + break; + founded = true; + } + } + } + if (founded) { + if (points[nearest_point].offset < newofs) + newofs = points[nearest_point].offset+0.00001; + else + newofs = points[nearest_point].offset-0.00001; + newofs = CLAMP(newofs,0,1); + } + } + + bool valid=true; + for(int i=0;i<points.size();i++) { + + if (points[i].offset==newofs && i!=grabbed) { + valid=false; + } + } + + if (!valid) + return; + + points[grabbed].offset=newofs; + + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==newofs) { + grabbed=i; + break; + } + } + + emit_signal("ramp_changed"); + + update(); + } +} + +void ColorRampEdit::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + picker->connect("color_changed",this,"_color_changed"); + } + if (p_what==NOTIFICATION_DRAW) { + + int w = get_size().x; + int h = get_size().y; + + if (w == 0 || h == 0) + return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size + + int total_w = get_size().width-get_size().height-3; + + //Draw checker pattern for ramp + _draw_checker(0,0, total_w, h); + + //Draw color ramp + ColorRamp::Point prev; + prev.offset=0; + if(points.size() == 0) + prev.color=Color(0,0,0); //Draw black rectangle if we have no points + else + prev.color = points[0].color; //Extend color of first point to the beginning. + + for(int i=-1;i<points.size();i++) { + + ColorRamp::Point next; + //If there is no next point + if (i+1 == points.size()) { + if(points.size() == 0) + next.color=Color(0,0,0); //Draw black rectangle if we have no points + else + next.color=points[i].color; //Extend color of last point to the end. + next.offset=1; + } else { + next=points[i+1]; + } + + if (prev.offset==next.offset) { + prev=next; + continue; + } + + Vector<Vector2> points; + Vector<Color> colors; + points.push_back(Vector2(prev.offset*total_w,h)); + points.push_back(Vector2(prev.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,h)); + colors.push_back(prev.color); + colors.push_back(prev.color); + colors.push_back(next.color); + colors.push_back(next.color); + draw_primitive(points,colors,Vector<Point2>()); + prev=next; + } + + //Draw point markers + for(int i=0;i<points.size();i++) { + + Color col = i==grabbed?Color(1,0.0,0.0,0.9):points[i].color.contrasted(); + col.a = 0.9; + + draw_line(Vector2(points[i].offset*total_w,0),Vector2(points[i].offset*total_w,h/2),col); + draw_rect(Rect2(points[i].offset*total_w-POINT_WIDTH/2, h/2, POINT_WIDTH, h/2), Color(0.6, 0.6, 0.6, i==grabbed?0.9:0.4)); + draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),col); + draw_line(Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col); + draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),col); + draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col); + + } + + + //Draw "button" for color selector + _draw_checker(total_w+3,0, h, h); + if (grabbed!=-1) { + //Draw with selection color + draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color); + } else { + //if no color selected draw grey color with 'X' on top. + draw_rect(Rect2(total_w+3,0,h,h), Color(0.5, 0.5, 0.5, 1)); + draw_line(Vector2(total_w+3,0),Vector2(total_w+3+h,h),Color(1,1,1,0.6)); + draw_line(Vector2(total_w+3,h),Vector2(total_w+3+h,0),Color(1,1,1,0.6)); + } + + //Draw borders around color ramp if in focus + if (has_focus()) { + + draw_line(Vector2(-1,-1),Vector2(total_w+1,-1),Color(1,1,1,0.6)); + draw_line(Vector2(total_w+1,-1),Vector2(total_w+1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(total_w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6)); + } + + } +} + +void ColorRampEdit::_draw_checker(int x, int y, int w, int h) { + //Draw it with polygon to insert UVs for scale + Vector<Vector2> backPoints; + backPoints.push_back(Vector2(x, y)); + backPoints.push_back(Vector2(x, y+h)); + backPoints.push_back(Vector2(x+w, y+h)); + backPoints.push_back(Vector2(x+w, y)); + Vector<Color> colorPoints; + colorPoints.push_back(Color(1, 1, 1, 1)); + colorPoints.push_back(Color(1, 1, 1, 1)); + colorPoints.push_back(Color(1, 1, 1, 1)); + colorPoints.push_back(Color(1, 1, 1, 1)); + Vector<Vector2> uvPoints; + //Draw checker pattern pixel-perfect and scale it by 2. + uvPoints.push_back(Vector2(x, y)); + uvPoints.push_back(Vector2(x, y+h*.5f/checker->get_height())); + uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y+h*.5f/checker->get_height())); + uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y)); + draw_polygon(backPoints, colorPoints, uvPoints, checker); +} + +Size2 ColorRampEdit::get_minimum_size() const { + + return Vector2(0,16); +} + +void ColorRampEdit::_color_changed(const Color& p_color) { + + if (grabbed==-1) + return; + points[grabbed].color=p_color; + update(); + emit_signal("ramp_changed"); + +} + +void ColorRampEdit::set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors) { + + ERR_FAIL_COND(p_offsets.size()!=p_colors.size()); + points.clear(); + for(int i=0;i<p_offsets.size();i++) { + ColorRamp::Point p; + p.offset=p_offsets[i]; + p.color=p_colors[i]; + points.push_back(p); + } + + points.sort(); + update(); +} + +Vector<float> ColorRampEdit::get_offsets() const { + Vector<float> ret; + for(int i=0;i<points.size();i++) + ret.push_back(points[i].offset); + return ret; +} + +Vector<Color> ColorRampEdit::get_colors() const { + Vector<Color> ret; + for(int i=0;i<points.size();i++) + ret.push_back(points[i].color); + return ret; +} + +void ColorRampEdit::set_points(Vector<ColorRamp::Point>& p_points) { + if(points.size() != p_points.size()) + grabbed = -1; + points.clear(); + points = p_points; +} + +Vector<ColorRamp::Point>& ColorRampEdit::get_points() { + return points; +} + +void ColorRampEdit::_bind_methods() { + ObjectTypeDB::bind_method(_MD("_input_event"),&ColorRampEdit::_input_event); + ObjectTypeDB::bind_method(_MD("_color_changed"),&ColorRampEdit::_color_changed); + ADD_SIGNAL(MethodInfo("ramp_changed")); +} diff --git a/scene/gui/color_ramp_edit.h b/scene/gui/color_ramp_edit.h new file mode 100644 index 0000000000..91292eed0d --- /dev/null +++ b/scene/gui/color_ramp_edit.h @@ -0,0 +1,52 @@ +#ifndef SCENE_GUI_COLOR_RAMP_EDIT_H_ +#define SCENE_GUI_COLOR_RAMP_EDIT_H_ + +#include "scene/gui/popup.h" +#include "scene/gui/color_picker.h" +#include "scene/resources/color_ramp.h" +#include "scene/resources/default_theme/theme_data.h" + +#define POINT_WIDTH 8 + +class ColorRampEdit : public Control { + + OBJ_TYPE(ColorRampEdit,Control); + + PopupPanel *popup; + ColorPicker *picker; + + Ref<ImageTexture> checker; + + bool grabbing; + int grabbed; + Vector<ColorRamp::Point> points; + + void _draw_checker(int x, int y, int w, int h); + void _color_changed(const Color& p_color); + int _get_point_from_pos(int x); + void _show_color_picker(); + +protected: + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); + +public: + void set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors); + Vector<float> get_offsets() const; + Vector<Color> get_colors() const; + void set_points(Vector<ColorRamp::Point>& p_points); + Vector<ColorRamp::Point>& get_points(); + virtual Size2 get_minimum_size() const; + + ColorRampEdit(); + virtual ~ColorRampEdit(); +}; + +/*class ColorRampEditPanel : public Panel +{ + OBJ_TYPE(ColorRampEditPanel, Panel ); +};*/ + + +#endif /* SCENE_GUI_COLOR_RAMP_EDIT_H_ */ diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 22559c238c..2367c03e99 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -548,15 +548,18 @@ void Control::_notification(int p_notification) { Control * parent = get_parent()->cast_to<Control>(); //make children reference them theme - if (parent && data.theme.is_null() && parent->data.theme_owner) + + if (parent && data.theme.is_null() && parent->data.theme_owner) { _propagate_theme_changed(parent->data.theme_owner); + } } break; case NOTIFICATION_UNPARENTED: { //make children unreference the theme - if (data.theme.is_null() && data.theme_owner) + if (data.theme.is_null() && data.theme_owner) { _propagate_theme_changed(NULL); + } } break; case NOTIFICATION_MOVED_IN_PARENT: { diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 13cf87ac2b..c53de6568a 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -608,18 +608,12 @@ void FileDialog::_update_drives() { drives->clear(); drives->show(); - int current=-1; - String abspath = dir_access->get_current_dir(); - for(int i=0;i<dir_access->get_drive_count();i++) { - String d = dir_access->get_drive(i); - if (abspath.begins_with(d)) - current=i; + String d = dir_access->get_drive(i); drives->add_item(dir_access->get_drive(i)); } - if (current!=-1) - drives->select(current); + drives->select(dir_access->get_current_drive()); } } diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 214d874675..105f66f368 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -40,7 +40,8 @@ void GridContainer::_notification(int p_what) { Set<int> col_expanded; Set<int> row_expanded; - int sep=get_constant("separation"); + int hsep=get_constant("hseparation"); + int vsep=get_constant("vseparation"); int idx=0; int max_row=0; @@ -97,8 +98,8 @@ void GridContainer::_notification(int p_what) { expand_rows++; } - ms.height+=sep*max_row; - ms.width+=sep*max_col; + ms.height+=vsep*max_row; + ms.width+=hsep*max_col; int row_expand = expand_rows?(size.y-ms.y)/expand_rows:0; int col_expand = expand_cols?(size.x-ms.x)/expand_cols:0; @@ -119,7 +120,7 @@ void GridContainer::_notification(int p_what) { if (col==0) { col_ofs=0; if (row>0 && row_minh.has(row-1)) - row_ofs+=row_minh[row-1]+sep+(row_expanded.has(row-1)?row_expand:0); + row_ofs+=row_minh[row-1]+vsep+(row_expanded.has(row-1)?row_expand:0); } Size2 s; @@ -140,7 +141,7 @@ void GridContainer::_notification(int p_what) { //print_line("col: "+itos(col)+" row: "+itos(row)+" rect: "+Rect2(p,s)); if (col_minw.has(col)) { - col_ofs+=col_minw[col]+sep+(col_expanded.has(col)?col_expand:0); + col_ofs+=col_minw[col]+hsep+(col_expanded.has(col)?col_expand:0); } idx++; @@ -178,7 +179,8 @@ Size2 GridContainer::get_minimum_size() const { Map<int,int> col_minw; Map<int,int> row_minh; - int sep=get_constant("separation"); + int hsep=get_constant("hseparation"); + int vsep=get_constant("vseparation"); int idx=0; int max_row=0; @@ -216,8 +218,8 @@ Size2 GridContainer::get_minimum_size() const { ms.height+=E->get(); } - ms.height+=sep*max_row; - ms.width+=sep*max_col; + ms.height+=vsep*max_row; + ms.width+=hsep*max_col; return ms; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp new file mode 100644 index 0000000000..c29f6625d3 --- /dev/null +++ b/scene/gui/item_list.cpp @@ -0,0 +1,1104 @@ +#include "item_list.h" +#include "os/os.h" +#include "globals.h" + + +void ItemList::add_item(const String& p_item,const Ref<Texture>& p_texture,bool p_selectable) { + + Item item; + item.icon=p_texture; + item.text=p_item; + item.selectable=p_selectable; + item.selected=false; + item.disabled=false; + item.custom_bg=Color(0,0,0,0); + items.push_back(item); + + update(); + shape_changed=true; + +} + +void ItemList::add_icon_item(const Ref<Texture>& p_item,bool p_selectable){ + + Item item; + item.icon=p_item; + //item.text=p_item; + item.selectable=p_selectable; + item.selected=false; + item.disabled=false; + item.custom_bg=Color(0,0,0,0); + items.push_back(item); + + update(); + shape_changed=true; + +} + +void ItemList::set_item_text(int p_idx,const String& p_text){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].text=p_text; + update(); + shape_changed=true; + +} + +String ItemList::get_item_text(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),String()); + return items[p_idx].text; + +} + +void ItemList::set_item_tooltip(int p_idx,const String& p_tooltip){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].tooltip=p_tooltip; + update(); + shape_changed=true; + +} + +String ItemList::get_item_tooltip(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),String()); + return items[p_idx].tooltip; + +} + +void ItemList::set_item_icon(int p_idx,const Ref<Texture>& p_icon){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].icon=p_icon; + update(); + shape_changed=true; + + +} +Ref<Texture> ItemList::get_item_icon(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Ref<Texture>()); + + return items[p_idx].icon; + +} + +void ItemList::set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color) { + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].custom_bg=p_custom_bg_color; + +} + +Color ItemList::get_item_custom_bg_color(int p_idx) const { + + ERR_FAIL_INDEX_V(p_idx,items.size(),Color()); + + return items[p_idx].custom_bg; + +} + + + +void ItemList::set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].tag_icon=p_tag_icon; + update(); + shape_changed=true; + + +} +Ref<Texture> ItemList::get_item_tag_icon(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Ref<Texture>()); + + return items[p_idx].tag_icon; + +} + +void ItemList::set_item_selectable(int p_idx,bool p_selectable){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].selectable=p_selectable; + + +} + + +bool ItemList::is_item_selectable(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + return items[p_idx].selectable; +} + +void ItemList::set_item_disabled(int p_idx,bool p_disabled){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].disabled=p_disabled; + + +} + + +bool ItemList::is_item_disabled(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + return items[p_idx].disabled; +} + + +void ItemList::set_item_metadata(int p_idx,const Variant& p_metadata){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].metadata=p_metadata; + update(); + shape_changed=true; + +} + +Variant ItemList::get_item_metadata(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),Variant()); + return items[p_idx].metadata; + +} +void ItemList::select(int p_idx,bool p_single){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + if (p_single || select_mode==SELECT_SINGLE) { + + if (!items[p_idx].selectable) { + return; + } + + for(int i=0;i<items.size();i++) { + items[i].selected=p_idx==i; + } + + current=p_idx; + } else { + + if (items[p_idx].selectable) { + items[p_idx].selected=true; + } + } + update(); + +} +void ItemList::unselect(int p_idx){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + if (select_mode!=SELECT_MULTI) { + items[p_idx].selected=false; + current=-1; + } else { + items[p_idx].selected=false; + } + update(); + +} +bool ItemList::is_selected(int p_idx) const{ + + ERR_FAIL_INDEX_V(p_idx,items.size(),false); + + return items[p_idx].selected; + +} + +void ItemList::set_current(int p_current) { + ERR_FAIL_INDEX(p_current,items.size()); + + if (select_mode==SELECT_SINGLE) + select(p_current,true); + else { + current=p_current; + update(); + } +} + +int ItemList::get_current() const { + + return current; +} + + +int ItemList::get_item_count() const{ + + return items.size(); +} +void ItemList::remove_item(int p_idx){ + + ERR_FAIL_INDEX(p_idx,items.size()); + + items.remove(p_idx); + update(); + shape_changed=true; + +} + +void ItemList::clear(){ + + items.clear(); + current=-1; + update(); + +} + +void ItemList::set_fixed_column_width(int p_size){ + + ERR_FAIL_COND(p_size<0); + fixed_column_width=p_size; + update(); + shape_changed=true; + +} +int ItemList::get_fixed_column_width() const{ + + return fixed_column_width; +} + +void ItemList::set_max_text_lines(int p_lines){ + + ERR_FAIL_COND(p_lines<1); + max_text_lines=p_lines; + update(); + shape_changed=true; + +} +int ItemList::get_max_text_lines() const{ + + return max_text_lines; +} + +void ItemList::set_max_columns(int p_amount){ + + ERR_FAIL_COND(p_amount<0); + max_columns=p_amount; + update(); +} +int ItemList::get_max_columns() const{ + + return max_columns; +} + +void ItemList::set_select_mode(SelectMode p_mode) { + + select_mode=p_mode; + update(); +} + +ItemList::SelectMode ItemList::get_select_mode() const { + + return select_mode; +} + +void ItemList::set_icon_mode(IconMode p_mode){ + + icon_mode=p_mode; + update(); + shape_changed=true; + +} +ItemList::IconMode ItemList::get_icon_mode() const{ + + return icon_mode; +} + +void ItemList::set_min_icon_size(const Size2& p_size) { + + min_icon_size=p_size; + update(); +} + +Size2 ItemList::get_min_icon_size() const { + + return min_icon_size; +} + + + +void ItemList::_input_event(const InputEvent& p_event) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) { + + const InputEventMouseButton &mb = p_event.mouse_button; + + search_string=""; //any mousepress cancels + Vector2 pos(mb.x,mb.y); + Ref<StyleBox> bg = get_stylebox("bg"); + pos-=bg->get_offset(); + pos.y+=scroll_bar->get_val(); + + int closest = -1; + int closest_dist=0x7FFFFFFF; + + for(int i=0;i<items.size();i++) { + + Rect2 rc = items[i].rect_cache; + if (i%current_columns==current_columns-1) { + rc.size.width=get_size().width; //not right but works + } + + if (rc.has_point(pos)) { + closest=i; + break; + } + + float dist = rc.distance_to(pos); + if (dist<closest_dist) { + closest=i; + closest_dist=dist; + } + } + + if (closest!=-1) { + + int i = closest; + + if (select_mode==SELECT_MULTI && items[i].selected && mb.mod.command) { + unselect(i); + emit_signal("multi_selected",i,false); + } else if (select_mode==SELECT_MULTI && mb.mod.shift && current>=0 && current<items.size() && current!=i) { + + int from = current; + int to = i; + if (i<current) { + SWAP(from,to); + } + for(int j=from;j<=to;j++) { + bool selected = !items[j].selected; + select(j,false); + if (selected) + emit_signal("multi_selected",i,true); + } + } else { + bool selected = !items[i].selected; + select(i,select_mode==SELECT_SINGLE || !mb.mod.command); + if (selected) { + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",i); + } else + emit_signal("multi_selected",i,true); + } + + if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) { + + emit_signal("item_activated",i); + + } + + + } + + + return; + } + } + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_WHEEL_UP && p_event.mouse_button.pressed) { + + scroll_bar->set_val( scroll_bar->get_val()-scroll_bar->get_page()/8 ); + + } + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_WHEEL_DOWN && p_event.mouse_button.pressed) { + + scroll_bar->set_val( scroll_bar->get_val()+scroll_bar->get_page()/8 ); + + } + + if (p_event.is_pressed() && items.size()>0) { + if (p_event.is_action("ui_up")) { + + if (search_string!="") { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + + if (diff<int(Globals::get_singleton()->get("gui/incr_search_max_interval_msec"))*2) { + + for(int i=current-1;i>=0;i--) { + + if (items[i].text.begins_with(search_string)) { + + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + + + break; + } + } + accept_event(); + return; + } + } + + if (current>=current_columns) { + set_current(current-current_columns); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + } + } else if (p_event.is_action("ui_down")) { + + if (search_string!="") { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + + if (diff<int(Globals::get_singleton()->get("gui/incr_search_max_interval_msec"))*2) { + + for(int i=current+1;i<items.size();i++) { + + if (items[i].text.begins_with(search_string)) { + + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + break; + } + } + accept_event(); + return; + } + } + + if (current<items.size()-current_columns) { + set_current(current+current_columns); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_page_up")) { + + search_string=""; //any mousepress cancels + + for(int i=4;i>0;i--) { + if (current-current_columns*i >=0 ) { + set_current( current- current_columns*i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + break; + } + } + } else if (p_event.is_action("ui_page_down")) { + + search_string=""; //any mousepress cancels + + for(int i=4;i>0;i--) { + if (current+current_columns*i < items.size() ) { + set_current( current+ current_columns*i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + break; + } + } + } else if (p_event.is_action("ui_left")) { + + search_string=""; //any mousepress cancels + + if (current%current_columns!=0) { + set_current(current-1); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_right")) { + + search_string=""; //any mousepress cancels + + if (current%current_columns!=(current_columns-1)) { + set_current(current+1); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + accept_event(); + + } + } else if (p_event.is_action("ui_cancel")) { + search_string=""; + } else if (p_event.is_action("ui_select")) { + + + if (select_mode==SELECT_MULTI && current>=0 && current<items.size()) { + if (items[current].selectable && !items[current].selected) { + select(current,false); + emit_signal("multi_selected",current,true); + } else if (items[current].selected) { + unselect(current); + emit_signal("multi_selected",current,false); + } + } + } else if (p_event.is_action("ui_accept")) { + search_string=""; //any mousepress cance + + if (current>=0 && current<items.size()) { + emit_signal("item_activated",current); + } + } else if (p_event.type==InputEvent::KEY) { + + if (p_event.key.unicode) { + + uint64_t now = OS::get_singleton()->get_ticks_msec(); + uint64_t diff = now-search_time_msec; + uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/incr_search_max_interval_msec",2000)); + search_time_msec = now; + + if (diff>max_interval) { + search_string=""; + } + + search_string+=String::chr(p_event.key.unicode); + for(int i=0;i<items.size();i++) { + if (items[i].text.begins_with(search_string)) { + set_current(i); + ensure_current_is_visible(); + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",current); + } + break; + } + } + + } + + } + } + + + + +} + +void ItemList::ensure_current_is_visible() { + + if (current>=0 && current <=items.size()) { + + Rect2 r = items[current].rect_cache; + int from = scroll_bar->get_val(); + int to = from + scroll_bar->get_page(); + + if (r.pos.y < from) { + scroll_bar->set_val(r.pos.y); + } else if (r.pos.y+r.size.y > to) { + scroll_bar->set_val(r.pos.y+r.size.y - (to-from)); + } + } +} + +void ItemList::_notification(int p_what) { + + if (p_what==NOTIFICATION_RESIZED) { + shape_changed=true; + update(); + } + + if (p_what==NOTIFICATION_DRAW) { + + VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + Ref<StyleBox> bg = get_stylebox("bg"); + + int mw = scroll_bar->get_minimum_size().x; + scroll_bar->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,mw+bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,bg->get_margin(MARGIN_TOP)); + scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,bg->get_margin(MARGIN_BOTTOM)); + + + Size2 size = get_size(); + + float page = size.height-bg->get_minimum_size().height; + int width = size.width - mw - bg->get_minimum_size().width; + scroll_bar->set_page(page); + + draw_style_box(bg,Rect2(Point2(),size)); + + int hseparation = get_constant("hseparation"); + int vseparation = get_constant("vseparation"); + int icon_margin = get_constant("icon_margin"); + int line_separation = get_constant("line_separation"); + + Ref<StyleBox> sbsel = has_focus()?get_stylebox("selected_focus"):get_stylebox("selected"); + Ref<StyleBox> cursor = has_focus()?get_stylebox("cursor"):get_stylebox("cursor_unfocused"); + + Ref<Font> font = get_font("font"); + Color guide_color = get_color("guide_color"); + Color font_color = get_color("font_color"); + Color font_color_selected = get_color("font_color_selected"); + int font_height = font->get_height(); + Vector<int> line_size_cache; + Vector<int> line_limit_cache; + + if (max_text_lines) { + line_size_cache.resize(max_text_lines); + line_limit_cache.resize(max_text_lines); + } + + if (has_focus()) { + VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),true); + draw_style_box(get_stylebox("bg_focus"),Rect2(Point2(),size)); + VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),false); + } + + if (shape_changed) { + + //1- compute item minimum sizes + for(int i=0;i<items.size();i++) { + + Size2 minsize; + if (items[i].icon.is_valid()) { + minsize=items[i].icon->get_size(); + if (min_icon_size.x!=0) + minsize.x = MAX(minsize.x,min_icon_size.x); + if (min_icon_size.y!=0) + minsize.y = MAX(minsize.y,min_icon_size.y); + + if (items[i].text!="") { + if (icon_mode==ICON_MODE_TOP) { + minsize.y+=icon_margin; + } else { + minsize.x+=icon_margin; + } + } + } + + if (items[i].text!="") { + + Size2 s = font->get_string_size(items[i].text); + //s.width=MIN(s.width,fixed_column_width); + + + + if (icon_mode==ICON_MODE_TOP) { + minsize.x=MAX(minsize.x,s.width); + if (max_text_lines>0) { + minsize.y+=(font_height+line_separation)*max_text_lines; + } else { + minsize.y+=s.height; + } + + } else { + minsize.y=MAX(minsize.y,s.height); + minsize.x+=s.width; + } + } + + + + items[i].rect_cache.size=minsize; + if (fixed_column_width>0) + items[i].rect_cache.size.x=fixed_column_width; + + } + + int fit_size = size.x - bg->get_minimum_size().width - mw; + + //2-attempt best fit + current_columns = 0x7FFFFFFF; + if (max_columns>0) + current_columns=max_columns; + + + while(true) { + //repeat util all fits + //print_line("try with "+itos(current_columns)); + bool all_fit=true; + Vector2 ofs; + int col=0; + int max_h=0; + separators.clear();; + for(int i=0;i<items.size();i++) { + + if (current_columns>1 && items[i].rect_cache.size.width+ofs.x > fit_size) { + //went past + current_columns=MAX(col,1); + all_fit=false; + break; + } + + items[i].rect_cache.pos=ofs; + max_h=MAX(max_h,items[i].rect_cache.size.y); + ofs.x+=items[i].rect_cache.size.x; + //print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x)); + if (col>0) + ofs.x+=hseparation; + col++; + if (col==current_columns) { + + if (i<items.size()-1) + separators.push_back(ofs.y+max_h+vseparation/2); + ofs.x=0; + ofs.y+=max_h+vseparation; + col=0; + max_h=0; + } + } + + if (all_fit) { + float max = MAX(page,ofs.y+max_h); + scroll_bar->set_max(max); + //print_line("max: "+rtos(max)+" page "+rtos(page)); + if (max<=page) { + scroll_bar->set_val(0); + scroll_bar->hide(); + } else { + scroll_bar->show(); + } + break; + } + } + + + shape_changed=false; + } + + + + Vector2 base_ofs = bg->get_offset(); + base_ofs.y-=int(scroll_bar->get_val()); + + Rect2 clip(Point2(),size-bg->get_minimum_size()+Vector2(0,scroll_bar->get_val())); + + for(int i=0;i<items.size();i++) { + + + Rect2 rcache = items[i].rect_cache; + + if (!clip.intersects(rcache)) + continue; + + + if (current_columns==1) { + rcache.size.width = width-rcache.pos.x; + } + if (items[i].custom_bg.a>0.001) { + Rect2 r=rcache; + r.pos+=base_ofs; + draw_rect(r,items[i].custom_bg); + } + if (items[i].selected) { + Rect2 r=rcache; + r.pos+=base_ofs; + + r.pos.x-=sbsel->get_margin(MARGIN_LEFT); + r.size.x+=sbsel->get_margin(MARGIN_LEFT)+sbsel->get_margin(MARGIN_RIGHT); + r.pos.y-=sbsel->get_margin(MARGIN_TOP); + r.size.y+=sbsel->get_margin(MARGIN_TOP)+sbsel->get_margin(MARGIN_BOTTOM); + + draw_style_box(sbsel,r); + + } + + + Vector2 text_ofs; + if (items[i].icon.is_valid()) { + + Vector2 icon_ofs; + if (min_icon_size!=Vector2()) { + icon_ofs = (min_icon_size - items[i].icon->get_size())/2; + } + + if (icon_mode==ICON_MODE_TOP) { + draw_texture(items[i].icon,icon_ofs+items[i].rect_cache.pos+Vector2(items[i].rect_cache.size.width/2-items[i].icon->get_width()/2,0).floor()+base_ofs); + text_ofs.y = MAX(items[i].icon->get_height(),min_icon_size.y)+icon_margin; + } else { + draw_texture(items[i].icon,icon_ofs+items[i].rect_cache.pos+Vector2(0,items[i].rect_cache.size.height/2-items[i].icon->get_height()/2).floor()+base_ofs); + text_ofs.x = MAX(items[i].icon->get_width(),min_icon_size.x)+icon_margin; + } + } + + if (items[i].tag_icon.is_valid()) { + + draw_texture(items[i].tag_icon,items[i].rect_cache.pos+base_ofs); + } + + if (items[i].text!="") { + + int max_len=-1; + + Vector2 size = font->get_string_size(items[i].text); + if (fixed_column_width) + max_len=fixed_column_width; + else + max_len=size.x; + + if (icon_mode==ICON_MODE_TOP && max_text_lines>0) { + + int ss = items[i].text.length(); + float ofs=0; + int line=0; + for(int j=0;j<=ss;j++) { + + int cs = j<ss?font->get_char_size(items[i].text[j],items[i].text[j+1]).x:0; + if (ofs+cs>max_len || j==ss) { + line_limit_cache[line]=j; + line_size_cache[line]=ofs; + line++; + ofs=0; + if (line>=max_text_lines) + break; + } else { + ofs+=cs; + } + + } + + line=0; + ofs=0; + + text_ofs.y+=font->get_ascent(); + text_ofs=text_ofs.floor(); + text_ofs+=base_ofs; + text_ofs+=items[i].rect_cache.pos; + + for(int j=0;j<ss;j++) { + + if (j==line_limit_cache[line]) { + line++; + ofs=0; + if (line>=max_text_lines) + break; + } + ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],items[i].selected?font_color_selected:font_color); + } + + //special multiline mode + } else { + + if (fixed_column_width>0) + size.x=MIN(size.x,fixed_column_width); + + if (icon_mode==ICON_MODE_TOP) { + text_ofs.x+=(items[i].rect_cache.size.width-size.x)/2; + } else { + text_ofs.y+=(items[i].rect_cache.size.height-size.y)/2; + } + + text_ofs.y+=font->get_ascent(); + text_ofs=text_ofs.floor(); + text_ofs+=base_ofs; + text_ofs+=items[i].rect_cache.pos; + + draw_string(font,text_ofs,items[i].text,items[i].selected?font_color_selected:font_color,max_len+1); + } + + + } + + if (select_mode==SELECT_MULTI && i==current) { + + Rect2 r=rcache; + r.pos+=base_ofs; + draw_style_box(cursor,r); + + } + } + + for(int i=0;i<separators.size();i++) { + draw_line(Vector2(bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),Vector2(size.width-bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),guide_color); + } + + } +} + +void ItemList::_scroll_changed(double) { + update(); +} + + +String ItemList::get_tooltip(const Point2& p_pos) const { + + Vector2 pos=p_pos; + Ref<StyleBox> bg = get_stylebox("bg"); + pos-=bg->get_offset(); + pos.y+=scroll_bar->get_val(); + + int closest = -1; + int closest_dist=0x7FFFFFFF; + + for(int i=0;i<items.size();i++) { + + Rect2 rc = items[i].rect_cache; + if (i%current_columns==current_columns-1) { + rc.size.width=get_size().width; //not right but works + } + + if (rc.has_point(pos)) { + closest=i; + break; + } + + float dist = rc.distance_to(pos); + if (dist<closest_dist) { + closest=i; + closest_dist=dist; + } + } + + if (closest!=-1) { + if (items[closest].tooltip!="") { + return items[closest].tooltip; + } + if (items[closest].text!="") { + return items[closest].text; + } + } + + return Control::get_tooltip(p_pos); + + +} + +void ItemList::sort_items_by_text() { + items.sort(); + update(); + if (select_mode==SELECT_SINGLE) { + for(int i=0;i<items.size();i++) { + if (items[i].selected) { + select(i); + return; + } + } + } +} + +int ItemList::find_metadata(const Variant& p_metadata) const { + + for(int i=0;i<items.size();i++) { + if (items[i].metadata==p_metadata) { + return i; + } + } + + return -1; + +} + +void ItemList::_bind_methods(){ + + ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Ref<Texture>()),DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("add_icon_item","icon:Texture","selectable"),&ItemList::add_icon_item,DEFVAL(true)); + + ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&ItemList::set_item_text); + ObjectTypeDB::bind_method(_MD("get_item_text","idx"),&ItemList::get_item_text); + + ObjectTypeDB::bind_method(_MD("set_item_icon","idx","icon:Texture"),&ItemList::set_item_icon); + ObjectTypeDB::bind_method(_MD("get_item_icon:Tedture","idx"),&ItemList::get_item_icon); + + ObjectTypeDB::bind_method(_MD("set_item_selectable","idx","selectable"),&ItemList::set_item_selectable); + ObjectTypeDB::bind_method(_MD("is_item_selectable","idx"),&ItemList::is_item_selectable); + + ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&ItemList::set_item_disabled); + ObjectTypeDB::bind_method(_MD("is_item_disabled","idx"),&ItemList::is_item_disabled); + + ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&ItemList::set_item_metadata); + ObjectTypeDB::bind_method(_MD("get_item_metadata","idx"),&ItemList::get_item_metadata); + + ObjectTypeDB::bind_method(_MD("set_item_custom_bg_color","idx","custom_bg_color"),&ItemList::set_item_custom_bg_color); + ObjectTypeDB::bind_method(_MD("get_item_custom_bg_color","idx"),&ItemList::get_item_custom_bg_color); + + ObjectTypeDB::bind_method(_MD("set_item_tooltip","idx","tooltip"),&ItemList::set_item_tooltip); + ObjectTypeDB::bind_method(_MD("get_item_tooltip","idx"),&ItemList::get_item_tooltip); + + ObjectTypeDB::bind_method(_MD("select","idx","single"),&ItemList::select,DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("unselect","idx"),&ItemList::unselect); + ObjectTypeDB::bind_method(_MD("is_selected","idx"),&ItemList::is_selected); + + ObjectTypeDB::bind_method(_MD("get_item_count"),&ItemList::get_item_count); + ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item); + + ObjectTypeDB::bind_method(_MD("clear"),&ItemList::clear); + ObjectTypeDB::bind_method(_MD("sort_items_by_text"),&ItemList::clear); + + ObjectTypeDB::bind_method(_MD("set_fixed_column_width","width"),&ItemList::set_fixed_column_width); + ObjectTypeDB::bind_method(_MD("get_fixed_column_width"),&ItemList::get_fixed_column_width); + + ObjectTypeDB::bind_method(_MD("set_max_text_lines","lines"),&ItemList::set_max_text_lines); + ObjectTypeDB::bind_method(_MD("get_max_text_lines"),&ItemList::get_max_text_lines); + + ObjectTypeDB::bind_method(_MD("set_max_columns","amount"),&ItemList::set_max_columns); + ObjectTypeDB::bind_method(_MD("get_max_columns"),&ItemList::get_max_columns); + + ObjectTypeDB::bind_method(_MD("set_select_mode","mode"),&ItemList::set_select_mode); + ObjectTypeDB::bind_method(_MD("get_select_mode"),&ItemList::get_select_mode); + + ObjectTypeDB::bind_method(_MD("set_icon_mode","mode"),&ItemList::set_icon_mode); + ObjectTypeDB::bind_method(_MD("get_icon_mode"),&ItemList::get_icon_mode); + + ObjectTypeDB::bind_method(_MD("set_min_icon_size","size"),&ItemList::set_min_icon_size); + ObjectTypeDB::bind_method(_MD("get_min_icon_size"),&ItemList::get_min_icon_size); + + ObjectTypeDB::bind_method(_MD("ensure_current_is_visible"),&ItemList::ensure_current_is_visible); + + ObjectTypeDB::bind_method(_MD("_scroll_changed"),&ItemList::_scroll_changed); + ObjectTypeDB::bind_method(_MD("_input_event"),&ItemList::_input_event); + + BIND_CONSTANT( ICON_MODE_TOP ); + BIND_CONSTANT( ICON_MODE_LEFT ); + BIND_CONSTANT( SELECT_SINGLE ); + BIND_CONSTANT( SELECT_MULTI ); + + ADD_SIGNAL( MethodInfo("item_selected",PropertyInfo(Variant::INT,"index"))); + ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::BOOL,"selected"))); + ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index"))); +} + + + +ItemList::ItemList() { + + current=-1; + + select_mode=SELECT_SINGLE; + icon_mode=ICON_MODE_LEFT; + + fixed_column_width=0; + max_text_lines=1; + max_columns=1; + + scroll_bar = memnew( VScrollBar ); + add_child(scroll_bar); + + shape_changed=true; + scroll_bar->connect("value_changed",this,"_scroll_changed"); + + set_focus_mode(FOCUS_ALL); + current_columns=1; + search_time_msec=0; + +} + +ItemList::~ItemList() { + +} + diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h new file mode 100644 index 0000000000..237079c428 --- /dev/null +++ b/scene/gui/item_list.h @@ -0,0 +1,141 @@ +#ifndef ITEMLIST_H +#define ITEMLIST_H + +#include "scene/gui/control.h" +#include "scene/gui/scroll_bar.h" + +class ItemList : public Control { + + OBJ_TYPE( ItemList, Control ); +public: + + enum IconMode { + ICON_MODE_TOP, + ICON_MODE_LEFT + }; + + enum SelectMode { + SELECT_SINGLE, + SELECT_MULTI + }; +private: + struct Item { + + Ref<Texture> icon; + Ref<Texture> tag_icon; + String text; + bool selectable; + bool selected; + bool disabled; + Variant metadata; + String tooltip; + Color custom_bg; + + + Rect2 rect_cache; + + bool operator<(const Item& p_another) const { return text<p_another.text; } + }; + + int current; + + bool shape_changed; + + Vector<Item> items; + Vector<int> separators; + + SelectMode select_mode; + IconMode icon_mode; + VScrollBar *scroll_bar; + + uint64_t search_time_msec; + String search_string; + + int current_columns; + int fixed_column_width; + int max_text_lines; + int max_columns; + Size2 min_icon_size; + + void _scroll_changed(double); + void _input_event(const InputEvent& p_event); +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + void add_item(const String& p_item,const Ref<Texture>& p_texture=Ref<Texture>(),bool p_selectable=true); + void add_icon_item(const Ref<Texture>& p_item,bool p_selectable=true); + + void set_item_text(int p_idx,const String& p_text); + String get_item_text(int p_idx) const; + + void set_item_icon(int p_idx,const Ref<Texture>& p_icon); + Ref<Texture> get_item_icon(int p_idx) const; + + void set_item_selectable(int p_idx,bool p_selectable); + bool is_item_selectable(int p_idx) const; + + void set_item_disabled(int p_idx,bool p_disabled); + bool is_item_disabled(int p_idx) const; + + void set_item_metadata(int p_idx,const Variant& p_metadata); + Variant get_item_metadata(int p_idx) const; + + void set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon); + Ref<Texture> get_item_tag_icon(int p_idx) const; + + void set_item_tooltip(int p_idx,const String& p_tooltip); + String get_item_tooltip(int p_idx) const; + + void set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color); + Color get_item_custom_bg_color(int p_idx) const; + + void select(int p_idx,bool p_single=true); + void unselect(int p_idx); + bool is_selected(int p_idx) const; + + void set_current(int p_current); + int get_current() const; + + + int get_item_count() const; + void remove_item(int p_idx); + + void clear(); + + void set_fixed_column_width(int p_size); + int get_fixed_column_width() const; + + void set_max_text_lines(int p_amount); + int get_max_text_lines() const; + + void set_max_columns(int p_amount); + int get_max_columns() const; + + void set_select_mode(SelectMode p_mode); + SelectMode get_select_mode() const; + + void set_icon_mode(IconMode p_mode); + IconMode get_icon_mode() const; + + void set_min_icon_size(const Size2& p_size); + Size2 get_min_icon_size() const; + + void ensure_current_is_visible(); + + void sort_items_by_text(); + int find_metadata(const Variant& p_metadata) const; + + virtual String get_tooltip(const Point2& p_pos) const; + + ItemList(); + ~ItemList(); +}; + +VARIANT_ENUM_CAST(ItemList::SelectMode); +VARIANT_ENUM_CAST(ItemList::IconMode); + + +#endif // ITEMLIST_H diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index dac21275dc..27d0f568a2 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -378,7 +378,11 @@ void Label::regenerate_word_cache() { if (uppercase) current=String::char_uppercase(current); - bool not_latin = current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); + // ranges taken from http://www.unicodemap.org/ + // if your language is not well supported, consider helping improve + // the unicode support in Godot. + bool separatable = (current>=0x2E08 && current<=0xFAFF) || (current>=0xFE30 && current<=0xFE4F); + //current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); bool insert_newline=false; int char_width; @@ -433,8 +437,8 @@ void Label::regenerate_word_cache() { } - if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || not_latin)) || insert_newline) { - if (not_latin) { + if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) { + if (separatable) { if (current_word_size>0) { WordCache *wc = memnew( WordCache ); if (word_cache) { diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index c73af74426..5ce7e2e0d3 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -84,6 +84,48 @@ void Popup::_fix_size() { } +void Popup::set_as_minsize() { + + Size2 total_minsize; + + for(int i=0;i<get_child_count();i++) { + + Control *c=get_child(i)->cast_to<Control>(); + if (!c) + continue; + if (c->is_hidden()) + continue; + + Size2 minsize = c->get_combined_minimum_size(); + + for(int j=0;j<2;j++) { + + Margin m_beg = Margin(0+j); + Margin m_end = Margin(2+j); + + float margin_begin = c->get_margin(m_beg); + float margin_end = c->get_margin(m_end); + AnchorType anchor_begin = c->get_anchor(m_beg); + AnchorType anchor_end = c->get_anchor(m_end); + + if (anchor_begin == ANCHOR_BEGIN) + minsize[j]+=margin_begin; + if (anchor_end == ANCHOR_END) + minsize[j]+=margin_end; + + } + + print_line(String(c->get_type())+": "+minsize); + + total_minsize.width = MAX( total_minsize.width, minsize.width ); + total_minsize.height = MAX( total_minsize.height, minsize.height ); + } + + set_size(total_minsize); + +} + + void Popup::popup_centered_minsize(const Size2& p_minsize) { diff --git a/scene/gui/popup.h b/scene/gui/popup.h index c2de6c8cf7..6c72a3c82b 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -62,6 +62,7 @@ public: void popup_centered_ratio(float p_screen_ratio=0.75); void popup_centered(const Size2& p_size=Size2()); void popup_centered_minsize(const Size2& p_minsize=Size2()); + void set_as_minsize(); virtual void popup(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 6b2e5aea78..7a607786ee 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -58,7 +58,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item* p_item) { } -void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside) { +void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) { RID ci; if (r_outside) @@ -80,6 +80,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p int line=0; int spaces=0; + if (p_mode!=PROCESS_CACHE) { ERR_FAIL_INDEX(line,l.offset_caches.size()); @@ -89,6 +90,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p if (p_mode==PROCESS_CACHE) { l.offset_caches.clear(); l.height_caches.clear(); + l.char_count=0; } int wofs=margin; @@ -216,6 +218,8 @@ if (m_height > line_height) {\ underline=true; } + } else if (p_mode==PROCESS_CACHE) { + l.char_count+=text->text.length(); } rchar=0; @@ -326,18 +330,23 @@ if (m_height > line_height) {\ } } - int cw; + int cw=0; + + bool visible = visible_characters<0 || p_char_count<visible_characters; if (selected) { cw = font->get_char_size(c[i],c[i+1]).x; draw_rect(Rect2(pofs,y,cw,lh),selection_bg); - font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); + if (visible) + font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); } else { - cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); + if (visible) + cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); } + p_char_count++; if (c[i]=='\t') { cw=tab_size*font->get_char_size(' ').width; } @@ -371,6 +380,8 @@ if (m_height > line_height) {\ lh=0; if (p_mode!=PROCESS_CACHE) lh = line<l.height_caches.size()?l.height_caches[line]:1; + else + l.char_count+=1; //images count as chars too ItemImage *img = static_cast<ItemImage*>(it); @@ -383,9 +394,12 @@ if (m_height > line_height) {\ ENSURE_WIDTH( img->image->get_width() ); - if (p_mode==PROCESS_DRAW) { + bool visible = visible_characters<0 || p_char_count<visible_characters; + + if (p_mode==PROCESS_DRAW && visible) { img->image->draw(ci,Point2(wofs,y+lh-font->get_descent()-img->image->get_height())); } + p_char_count++; ADVANCE( img->image->get_width() ); CHECK_HEIGHT( (img->image->get_height()+font->get_descent()) ); @@ -556,11 +570,13 @@ void RichTextLabel::_notification(int p_what) { //todo, change to binary search int from_line = 0; + int total_chars = 0; while (from_line<lines.size()) { if (lines[from_line].height_accum_cache>=ofs) break; from_line++; + total_chars+=lines[from_line].char_count; } if (from_line>=lines.size()) @@ -572,7 +588,8 @@ void RichTextLabel::_notification(int p_what) { while (y<size.height && from_line<lines.size()) { - _process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color); + _process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars); + total_chars+=lines[from_line].char_count; from_line++; } } @@ -1673,6 +1690,8 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_scroll_follow","follow"),&RichTextLabel::set_scroll_follow); ObjectTypeDB::bind_method(_MD("is_scroll_following"),&RichTextLabel::is_scroll_following); + ObjectTypeDB::bind_method(_MD("get_v_scroll"),&RichTextLabel::get_v_scroll); + ObjectTypeDB::bind_method(_MD("set_tab_size","spaces"),&RichTextLabel::set_tab_size); ObjectTypeDB::bind_method(_MD("get_tab_size"),&RichTextLabel::get_tab_size); @@ -1686,11 +1705,17 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_bbcode","text"),&RichTextLabel::set_bbcode); ObjectTypeDB::bind_method(_MD("get_bbcode"),&RichTextLabel::get_bbcode); + ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&RichTextLabel::set_visible_characters); + ObjectTypeDB::bind_method(_MD("get_visible_characters"),&RichTextLabel::get_visible_characters); + + ObjectTypeDB::bind_method(_MD("get_total_character_count"),&RichTextLabel::get_total_character_count); + ObjectTypeDB::bind_method(_MD("set_use_bbcode","enable"),&RichTextLabel::set_use_bbcode); ObjectTypeDB::bind_method(_MD("is_using_bbcode"),&RichTextLabel::is_using_bbcode); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"bbcode/enabled"),_SCS("set_use_bbcode"),_SCS("is_using_bbcode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"bbcode/bbcode",PROPERTY_HINT_MULTILINE_TEXT),_SCS("set_bbcode"),_SCS("get_bbcode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"visible_characters",PROPERTY_HINT_RANGE,"-1,128000,1"),_SCS("set_visible_characters"),_SCS("get_visible_characters")); ADD_SIGNAL( MethodInfo("meta_clicked",PropertyInfo(Variant::NIL,"meta"))); @@ -1717,6 +1742,27 @@ void RichTextLabel::_bind_methods() { } + +void RichTextLabel::set_visible_characters(int p_visible) { + + visible_characters=p_visible; + update(); +} + +int RichTextLabel::get_visible_characters() const { + + return visible_characters; +} +int RichTextLabel::get_total_character_count() const { + + int tc=0; + for(int i=0;i<lines.size();i++) + tc+=lines[i].char_count; + + return tc; +} + + RichTextLabel::RichTextLabel() { @@ -1754,6 +1800,8 @@ RichTextLabel::RichTextLabel() { selection.active=false; selection.enabled=false; + visible_characters=-1; + } RichTextLabel::~RichTextLabel() { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 7172e8e500..eaa8d5d60a 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -171,8 +171,9 @@ private: Vector<int> space_caches; int height_cache; int height_accum_cache; + int char_count; - Line() { from=NULL; } + Line() { from=NULL; char_count=0; } }; @@ -223,10 +224,10 @@ private: Selection selection; + int visible_characters; - - void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); + void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0); void _find_click(const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL); @@ -246,6 +247,8 @@ private: bool use_bbcode; String bbcode; + + protected: void _notification(int p_what); @@ -304,6 +307,10 @@ public: void set_bbcode(const String& p_bbcode); String get_bbcode() const; + void set_visible_characters(int p_visible); + int get_visible_characters() const; + int get_total_character_count() const; + RichTextLabel(); ~RichTextLabel(); }; diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index d02c833be9..d7ee7a6b86 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -345,6 +345,7 @@ void SplitContainer::_input_event(const InputEvent& p_event) { expand_ofs=drag_ofs+((vertical?mm.y:mm.x)-drag_from); queue_sort(); + emit_signal("dragged",get_split_offset()); } } @@ -431,11 +432,13 @@ void SplitContainer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_dragger_visible","visible"),&SplitContainer::set_dragger_visible); ObjectTypeDB::bind_method(_MD("is_dragger_visible"),&SplitContainer::is_dragger_visible); + ADD_SIGNAL( MethodInfo("dragged",PropertyInfo(Variant::INT,"offset"))); ADD_PROPERTY( PropertyInfo(Variant::INT,"split/offset"),_SCS("set_split_offset"),_SCS("get_split_offset")); ADD_PROPERTY( PropertyInfo(Variant::INT,"split/collapsed"),_SCS("set_collapsed"),_SCS("is_collapsed")); ADD_PROPERTY( PropertyInfo(Variant::INT,"split/dragger_visible"),_SCS("set_dragger_visible"),_SCS("is_dragger_visible")); + } SplitContainer::SplitContainer(bool p_vertical) { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1db4998a27..3ed182c017 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -88,7 +88,22 @@ void TabContainer::_input_event(const InputEvent& p_event) { Ref<Font> font = get_font("font"); Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); + Ref<Texture> menu = get_icon("menu"); + Ref<Texture> menu_hl = get_icon("menu_hl"); + if (popup && pos.x>get_size().width-menu->get_width()) { + + + emit_signal("pre_popup_pressed"); + Vector2 pp_pos = get_global_pos(); + pp_pos.x+=get_size().width; + pp_pos.x-=popup->get_size().width; + pp_pos.y+=menu->get_height(); + + popup->set_global_pos( pp_pos ); + popup->popup();; + return; + } pos.x-=tabs_ofs_cache; int idx=0; @@ -116,17 +131,17 @@ void TabContainer::_input_event(const InputEvent& p_event) { String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name()); int tab_width=font->get_string_size(s).width; - if (c->has_meta("_tab_icon")) { - Ref<Texture> icon = c->get_meta("_tab_icon"); - if (icon.is_valid()) { - tab_width+=icon->get_width(); - if (s!="") - tab_width+=get_constant("hseparation"); + if (c->has_meta("_tab_icon")) { + Ref<Texture> icon = c->get_meta("_tab_icon"); + if (icon.is_valid()) { + tab_width+=icon->get_width(); + if (s!="") + tab_width+=get_constant("hseparation"); - } - } + } + } - if (idx==current) { + if (idx==current) { tab_width+=tab_fg->get_minimum_size().width; } else { @@ -163,7 +178,7 @@ void TabContainer::_input_event(const InputEvent& p_event) { if (found!=-1) { - set_current_tab(found); + set_current_tab(found); } } @@ -194,7 +209,9 @@ 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"); Color color_fg = get_color("font_color_fg"); Color color_bg = get_color("font_color_bg"); @@ -209,6 +226,7 @@ void TabContainer::_notification(int p_what) { Size2 top_size = Size2( size.width, top_margin ); + int w=0; int idx=0; for(int i=0;i<get_child_count();i++) { @@ -227,7 +245,7 @@ void TabContainer::_notification(int p_what) { if (icon.is_valid()) { w+=icon->get_width(); if (s!="") - w+=get_constant("hseparation"); + w+=get_constant("hseparation"); } } @@ -245,14 +263,18 @@ void TabContainer::_notification(int p_what) { int ofs; int limit=get_size().width; + if (popup) { + top_size.width-=menu->get_width(); + limit-=menu->get_width(); + } - if (w<=get_size().width) { + if (w<=limit) { switch(align) { case ALIGN_LEFT: ofs = side_margin; break; - case ALIGN_CENTER: ofs = (int(top_size.width) - w)/2; break; - case ALIGN_RIGHT: ofs = int(top_size.width) - w - side_margin; break; + case ALIGN_CENTER: ofs = (int(limit) - w)/2; break; + case ALIGN_RIGHT: ofs = int(limit) - w - side_margin; break; }; tab_display_ofs=0; @@ -364,6 +386,15 @@ void TabContainer::_notification(int p_what) { incr->draw(ci,Point2(limit+incr->get_width(),vofs),Color(1,1,1,notdone?1.0:0.5)); } + if (popup) { + int from = get_size().width-menu->get_width(); + + if (mouse_x_cache > from) + menu_hl->draw(get_canvas_item(),Size2(from,0)); + else + menu->draw(get_canvas_item(),Size2(from,0)); + } + panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height)); } break; @@ -465,6 +496,48 @@ int TabContainer::get_current_tab() const { return current; } +Control* TabContainer::get_tab_control(int p_idx) const { + + int idx=0; + + + for(int i=0;i<get_child_count();i++) { + + Control *c = get_child(i)->cast_to<Control>(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; + if (idx==p_idx) { + return c; + + } + idx++; + } + + return NULL; +} +Control* TabContainer::get_current_tab_control() const { + + int idx=0; + + + for(int i=0;i<get_child_count();i++) { + + Control *c = get_child(i)->cast_to<Control>(); + if (!c) + continue; + if (c->is_set_as_toplevel()) + continue; + if (idx==current) { + return c; + + } + idx++; + } + + return NULL; +} void TabContainer::remove_child_notify(Node *p_child) { @@ -635,12 +708,25 @@ Size2 TabContainer::get_minimum_size() const { return ms; } +void TabContainer::set_popup(Node *p_popup) { + ERR_FAIL_NULL(p_popup); + popup=p_popup->cast_to<Popup>(); + update(); +} + +Popup* TabContainer::get_popup() const { + return popup; +} + + void TabContainer::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&TabContainer::_input_event); ObjectTypeDB::bind_method(_MD("get_tab_count"),&TabContainer::get_tab_count); ObjectTypeDB::bind_method(_MD("set_current_tab","tab_idx"),&TabContainer::set_current_tab); ObjectTypeDB::bind_method(_MD("get_current_tab"),&TabContainer::get_current_tab); + ObjectTypeDB::bind_method(_MD("get_current_tab_control:Control"),&TabContainer::get_current_tab_control); + ObjectTypeDB::bind_method(_MD("get_tab_control:Control","idx"),&TabContainer::get_tab_control); ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&TabContainer::set_tab_align); ObjectTypeDB::bind_method(_MD("get_tab_align"),&TabContainer::get_tab_align); ObjectTypeDB::bind_method(_MD("set_tabs_visible","visible"),&TabContainer::set_tabs_visible); @@ -649,10 +735,13 @@ void TabContainer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_tab_title","tab_idx"),&TabContainer::get_tab_title); ObjectTypeDB::bind_method(_MD("set_tab_icon","tab_idx","icon:Texture"),&TabContainer::set_tab_icon); ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&TabContainer::get_tab_icon); + ObjectTypeDB::bind_method(_MD("set_popup","popup:Popup"),&TabContainer::set_popup); + ObjectTypeDB::bind_method(_MD("get_popup:Popup"),&TabContainer::get_popup); ObjectTypeDB::bind_method(_MD("_child_renamed_callback"),&TabContainer::_child_renamed_callback); ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab"))); + ADD_SIGNAL(MethodInfo("pre_popup_pressed")); ADD_PROPERTY( PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM,"Left,Center,Right"), _SCS("set_tab_align"), _SCS("get_tab_align") ); ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") ); @@ -669,5 +758,6 @@ TabContainer::TabContainer() { mouse_x_cache=0; align=ALIGN_CENTER; tabs_visible=true; + popup=NULL; } diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 43314b026d..602d248b46 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -31,7 +31,7 @@ #include "scene/gui/control.h" - +#include "scene/gui/popup.h" class TabContainer : public Control { OBJ_TYPE( TabContainer, Control ); @@ -55,6 +55,8 @@ private: TabAlign align; Control *_get_tab(int idx) const; int _get_top_margin() const; + Popup *popup; + protected: @@ -85,10 +87,17 @@ public: void set_current_tab(int p_current); int get_current_tab() const; + Control* get_tab_control(int p_idx) const; + Control* get_current_tab_control() const; + virtual Size2 get_minimum_size() const; virtual void get_translatable_strings(List<String> *p_strings) const; + void set_popup(Node *p_popup); + Popup* get_popup() const; + + TabContainer(); }; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 37369a7e6c..40a6e20c37 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -77,8 +77,8 @@ void Tabs::_input_event(const InputEvent& p_event) { for(int i=0;i<tabs.size();i++) { int ofs=tabs[i].ofs_cache; - - if (pos.x < ofs) { + int size = tabs[i].ofs_cache; + if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) { found=i; break; @@ -89,6 +89,7 @@ void Tabs::_input_event(const InputEvent& p_event) { if (found!=-1) { set_current_tab(found); + emit_signal("tab_changed",found); } } @@ -117,8 +118,22 @@ void Tabs::_notification(int p_what) { int w=0; + int mw = get_minimum_size().width; + + if (tab_align==ALIGN_CENTER) { + w=(get_size().width-mw)/2; + } else if (tab_align==ALIGN_RIGHT) { + w=get_size().width-mw; + + } + + if (w<0) { + w=0; + } + for(int i=0;i<tabs.size();i++) { + tabs[i].ofs_cache=w; String s = tabs[i].text; int lsize=0; @@ -171,7 +186,7 @@ void Tabs::_notification(int p_what) { w+=slen+sb->get_margin(MARGIN_RIGHT); - tabs[i].ofs_cache=w; + tabs[i].size_cache=w-tabs[i].ofs_cache; } @@ -195,7 +210,7 @@ void Tabs::set_current_tab(int p_current) { current=p_current; _change_notify("current_tab"); - emit_signal("tab_changed",current); + //emit_signal("tab_changed",current); update(); } @@ -249,6 +264,12 @@ void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) { } +void Tabs::clear_tabs() { + tabs.clear(); + current=0; + update(); +} + void Tabs::remove_tab(int p_idx) { ERR_FAIL_INDEX(p_idx,tabs.size()); @@ -263,8 +284,19 @@ void Tabs::remove_tab(int p_idx) { if (current>=tabs.size()) current=tabs.size()-1; - emit_signal("tab_changed",current); + //emit_signal("tab_changed",current); + +} + +void Tabs::set_tab_align(TabAlign p_align) { + + tab_align=p_align; + update(); +} + +Tabs::TabAlign Tabs::get_tab_align() const { + return tab_align; } @@ -280,15 +312,21 @@ void Tabs::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&Tabs::get_tab_icon); ObjectTypeDB::bind_method(_MD("remove_tab","tab_idx"),&Tabs::remove_tab); ObjectTypeDB::bind_method(_MD("add_tab","title","icon:Texture"),&Tabs::add_tab); + ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&Tabs::set_tab_align); + ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align); ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab"))); ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") ); + BIND_CONSTANT( ALIGN_LEFT ); + BIND_CONSTANT( ALIGN_CENTER ); + BIND_CONSTANT( ALIGN_RIGHT ); } Tabs::Tabs() { current=0; + tab_align=ALIGN_CENTER; } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 4a969928ff..8d4d0123f8 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -34,6 +34,14 @@ class Tabs : public Control { OBJ_TYPE( Tabs, Control ); +public: + + enum TabAlign { + + ALIGN_LEFT, + ALIGN_CENTER, + ALIGN_RIGHT + }; private: @@ -42,12 +50,14 @@ private: String text; Ref<Texture> icon; int ofs_cache; + int size_cache; }; Vector<Tab> tabs; int current; Control *_get_tab(int idx) const; int _get_top_margin() const; + TabAlign tab_align; protected: @@ -65,16 +75,22 @@ public: void set_tab_icon(int p_tab,const Ref<Texture>& p_icon); Ref<Texture> get_tab_icon(int p_tab) const; + void set_tab_align(TabAlign p_align); + TabAlign get_tab_align() const; + int get_tab_count() const; void set_current_tab(int p_current); int get_current_tab() const; void remove_tab(int p_idx); + void clear_tabs(); + Size2 get_minimum_size() const; Tabs(); }; +VARIANT_ENUM_CAST(Tabs::TabAlign); #endif // TABS_H diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index db8fbf7a63..c497bc5363 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1893,7 +1893,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { selection.from_line=0; selection.from_column=0; selection.to_line=text.size()-1; - selection.to_column=text[selection.to_line].size(); + selection.to_column=text[selection.to_line].length(); selection.selecting_mode=Selection::MODE_NONE; update(); @@ -2778,6 +2778,11 @@ 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)); + print_line("to column: "+itos(selection.to_column)); + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); @@ -2809,7 +2814,7 @@ void TextEdit::select_all() { selection.from_line=0; selection.from_column=0; selection.to_line=text.size()-1; - selection.to_column=text[selection.to_line].size(); + selection.to_column=text[selection.to_line].length(); selection.selecting_mode=Selection::MODE_NONE; update(); @@ -3596,6 +3601,10 @@ TextEdit::TextEdit() { set_focus_mode(FOCUS_ALL); _update_caches(); cache.size=Size2(1,1); + cache.row_height=1; + cache.line_spacing=1; + cache.line_number_w=1; + tab_size=4; text.set_tab_size(tab_size); text.clear(); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index f03827f542..8ddddd0630 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -454,6 +454,8 @@ public: void set_cursor_can_exit_tree(bool p_enable); bool can_cursor_exit_tree() const; + VScrollBar *get_vscroll_bar() { return v_scroll; } + Tree(); ~Tree(); diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index a37d3b0638..7c90a4b3cd 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -146,18 +146,28 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_ } int frames=chunksize; + frames/=format_channels; frames/=(format_bits>>3); - + /*print_line("chunksize: "+itos(chunksize)); + print_line("channels: "+itos(format_channels)); + print_line("bits: "+itos(format_bits)); +*/ sample->create( (format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16, (format_channels==2)?true:false, frames ); sample->set_mix_rate( format_freq ); + int len=frames; + if (format_channels==2) + len*=2; + if (format_bits>8) + len*=2; + DVector<uint8_t> data; - data.resize(chunksize); + data.resize(len); DVector<uint8_t>::Write dataw = data.write(); void * data_ptr = dataw.ptr(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5c60b9fbff..b7fa5c8301 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -641,6 +641,7 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { p_child->data.pos=data.children.size(); data.children.push_back( p_child ); p_child->data.parent=this; + p_child->notification(NOTIFICATION_PARENTED); if (data.tree) { p_child->_set_tree(data.tree); @@ -649,7 +650,6 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { /* Notify */ //recognize childs created in this node constructor p_child->data.parent_owned=data.in_constructor; - p_child->notification(NOTIFICATION_PARENTED); add_child_notify(p_child); @@ -840,6 +840,28 @@ bool Node::has_node(const NodePath& p_path) const { return _get_node(p_path)!=NULL; } + +Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const { + + Node * const*cptr = data.children.ptr(); + int ccount = data.children.size(); + for(int i=0;i<ccount;i++) { + if (p_owned && !cptr[i]->data.owner) + continue; + if (cptr[i]->data.name.operator String().match(p_mask)) + return cptr[i]; + + if (!p_recursive) + continue; + + Node* ret = cptr[i]->find_node(p_mask,true,p_owned); + if (ret) + return ret; + } + return NULL; + +} + Node *Node::get_parent() const { return data.parent; @@ -1794,6 +1816,16 @@ void Node::get_argument_options(const StringName& p_function,int p_idx,List<Stri Object::get_argument_options(p_function,p_idx,r_options); } + +void Node::clear_internal_tree_resource_paths() { + + clear_internal_resource_paths(); + for(int i=0;i<data.children.size();i++) { + data.children[i]->clear_internal_tree_resource_paths(); + } + +} + void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name); @@ -1807,6 +1839,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node); ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node); ObjectTypeDB::bind_method(_MD("get_parent:Parent"),&Node::get_parent); + ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::get_node,DEFVAL(true),DEFVAL(true)); ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource); ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource); diff --git a/scene/main/node.h b/scene/main/node.h index be32c4e726..be91c6e1bb 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -114,6 +114,7 @@ private: Node *_get_node(const NodePath& p_path) const; + void _validate_child_name(Node *p_name); void _propagate_reverse_notification(int p_notification); @@ -186,6 +187,7 @@ public: Node *get_child(int p_index) const; bool has_node(const NodePath& p_path) const; Node *get_node(const NodePath& p_path) const; + 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; @@ -288,6 +290,8 @@ public: void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + void clear_internal_tree_resource_paths(); + _FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; } /* CANVAS */ diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 584b40337f..1664a9bea1 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -1108,6 +1108,9 @@ void SceneTree::_bind_methods() { ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) ); ADD_SIGNAL( MethodInfo("screen_resized") ); + ADD_SIGNAL( MethodInfo("idle_frame")); + ADD_SIGNAL( MethodInfo("fixed_frame")); + BIND_CONSTANT( GROUP_CALL_DEFAULT ); BIND_CONSTANT( GROUP_CALL_REVERSE ); BIND_CONSTANT( GROUP_CALL_REALTIME ); @@ -1166,8 +1169,7 @@ SceneTree::SceneTree() { edited_scene_root=NULL; #endif - ADD_SIGNAL( MethodInfo("idle_frame")); - ADD_SIGNAL( MethodInfo("fixed_frame")); + } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 687410d192..717ed93b16 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -66,6 +66,7 @@ #include "scene/gui/file_dialog.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" +#include "scene/gui/item_list.h" #include "scene/gui/text_edit.h" #include "scene/gui/texture_button.h" #include "scene/gui/separator.h" @@ -170,6 +171,7 @@ #include "scene/resources/audio_stream.h" #include "scene/resources/gibberish_stream.h" #include "scene/resources/bit_mask.h" +#include "scene/resources/color_ramp.h" #include "scene/scene_string_names.h" @@ -327,7 +329,7 @@ void register_scene_types() { ObjectTypeDB::register_type<HButtonArray>(); ObjectTypeDB::register_type<VButtonArray>(); ObjectTypeDB::register_type<TextureProgress>(); - + ObjectTypeDB::register_type<ItemList>(); #ifndef ADVANCED_GUI_DISABLED @@ -335,6 +337,7 @@ void register_scene_types() { ObjectTypeDB::register_type<LineEdit>(); ObjectTypeDB::register_type<PopupMenu>(); ObjectTypeDB::register_type<Tree>(); + ObjectTypeDB::register_type<TextEdit>(); ObjectTypeDB::register_virtual_type<TreeItem>(); @@ -565,6 +568,7 @@ void register_scene_types() { ObjectTypeDB::register_type<PolygonPathFinder>(); ObjectTypeDB::register_type<BitMap>(); + ObjectTypeDB::register_type<ColorRamp>(); OS::get_singleton()->yield(); //may take time to init diff --git a/scene/resources/audio_stream_resampled.cpp b/scene/resources/audio_stream_resampled.cpp index 506b34fbf6..6317780bd3 100644 --- a/scene/resources/audio_stream_resampled.cpp +++ b/scene/resources/audio_stream_resampled.cpp @@ -230,6 +230,51 @@ bool AudioStreamResampled::mix(int32_t *p_dest, int p_frames) { case 4: read=_resample<4>(p_dest,todo,increment); break; case 6: read=_resample<6>(p_dest,todo,increment); break; } +#if 1 + //end of stream, fadeout + int remaining = p_frames-todo; + if (remaining && todo>0) { + + //print_line("fadeout"); + for(int c=0;c<channels;c++) { + + for(int i=0;i<todo;i++) { + + int32_t samp = p_dest[i*channels+c]>>8; + uint32_t mul = (todo-i) * 256 /todo; + //print_line("mul: "+itos(i)+" "+itos(mul)); + p_dest[i*channels+c]=samp*mul; + } + + } + + } + +#else + int remaining = p_frames-todo; + if (remaining && todo>0) { + + + for(int c=0;c<channels;c++) { + + int32_t from = p_dest[(todo-1)*channels+c]>>8; + + for(int i=0;i<remaining;i++) { + + uint32_t mul = (remaining-i) * 256 /remaining; + p_dest[(todo+i)*channels+c]=from*mul; + } + + } + + } +#endif + + //zero out what remains there to avoid glitches + for(int i=todo*channels;i<int(p_frames)*channels;i++) { + + p_dest[i]=0; + } if (read>rb_todo) read=rb_todo; @@ -316,6 +361,16 @@ AudioStreamResampled::AudioStreamResampled() { rb=NULL; offset=0; read_buf=NULL; + rb_read_pos=0; + rb_write_pos=0; + + rb_bits=0; + rb_len=0; + rb_mask=0; + read_buff_len=0; + channels=0; + mix_rate=0; + } AudioStreamResampled::~AudioStreamResampled() { diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp new file mode 100644 index 0000000000..97d3fafd58 --- /dev/null +++ b/scene/resources/color_ramp.cpp @@ -0,0 +1,117 @@ +/* + * color_ramp.h + */ + +#include "color_ramp.h" + +//setter and getter names for property serialization +#define COLOR_RAMP_GET_OFFSETS "get_offsets" +#define COLOR_RAMP_GET_COLORS "get_colors" +#define COLOR_RAMP_SET_OFFSETS "set_offsets" +#define COLOR_RAMP_SET_COLORS "set_colors" + +ColorRamp::ColorRamp() { + //Set initial color ramp transition from black to white + points.resize(2); + points[0].color = Color(0,0,0,1); + points[0].offset = 0; + points[1].color = Color(1,1,1,1); + points[1].offset = 1; + is_sorted = true; +} + +ColorRamp::~ColorRamp() { + +} + +void ColorRamp::_bind_methods() { + + ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_OFFSETS,"offsets"),&ColorRamp::set_offsets); + ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_OFFSETS),&ColorRamp::get_offsets); + + ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_COLORS,"colors"),&ColorRamp::set_colors); + ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_COLORS),&ColorRamp::get_colors); + + ADD_PROPERTY( PropertyInfo(Variant::REAL,"offsets"),_SCS(COLOR_RAMP_SET_OFFSETS),_SCS(COLOR_RAMP_GET_OFFSETS) ); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"colors"),_SCS(COLOR_RAMP_SET_COLORS),_SCS(COLOR_RAMP_GET_COLORS) ); +} + +Vector<float> ColorRamp::get_offsets() const { + Vector<float> offsets; + offsets.resize(points.size()); + for(int i = 0; i < points.size(); i++) + { + offsets[i] = points[i].offset; + } + return offsets; +} + +Vector<Color> ColorRamp::get_colors() const { + Vector<Color> colors; + colors.resize(points.size()); + for(int i = 0; i < points.size(); i++) + { + colors[i] = points[i].color; + } + return colors; +} + +void ColorRamp::set_offsets(const Vector<float>& p_offsets) { + points.resize(p_offsets.size()); + for(int i = 0; i < points.size(); i++) + { + points[i].offset = p_offsets[i]; + } + is_sorted = false; +} + +void ColorRamp::set_colors(const Vector<Color>& p_colors) { + if(points.size()<p_colors.size()) + is_sorted = false; + points.resize(p_colors.size()); + for(int i = 0; i < points.size(); i++) + { + points[i].color = p_colors[i]; + } +} + +Vector<ColorRamp::Point>& ColorRamp::get_points() { + return points; +} + +void ColorRamp::set_points(Vector<ColorRamp::Point>& p_points) { + points = p_points; + is_sorted = false; +} + +void ColorRamp::set_offset(int pos, const float offset) { + if(points.size() <= pos) + points.resize(pos + 1); + points[pos].offset = offset; + is_sorted = false; +} + +float ColorRamp::get_offset(int pos) const { + if(points.size() > pos) + return points[pos].offset; + return 0; //TODO: Maybe throw some error instead? +} + +void ColorRamp::set_color(int pos, const Color& color) { + if(points.size() <= pos) + { + points.resize(pos + 1); + is_sorted = false; + } + points[pos].color = color; +} + +Color ColorRamp::get_color(int pos) const { + if(points.size() > pos) + return points[pos].color; + return Color(0,0,0,1); //TODO: Maybe throw some error instead? +} + +int ColorRamp::get_points_count() const { + return points.size(); +} diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h new file mode 100644 index 0000000000..8f6ba2c3e5 --- /dev/null +++ b/scene/resources/color_ramp.h @@ -0,0 +1,98 @@ +/* + * color_ramp.h + */ + +#ifndef SCENE_RESOURCES_COLOR_RAMP_H_ +#define SCENE_RESOURCES_COLOR_RAMP_H_ + +#include "resource.h" + +class ColorRamp: public Resource { + OBJ_TYPE( ColorRamp, Resource ); + OBJ_SAVE_TYPE( ColorRamp ); + +public: + struct Point { + + float offset; + Color color; + bool operator<(const Point& p_ponit) const { + return offset<p_ponit.offset; + } + }; + +private: + Vector<Point> points; + bool is_sorted; + +protected: + static void _bind_methods(); + +public: + ColorRamp(); + virtual ~ColorRamp(); + + void set_points(Vector<Point>& points); + Vector<Point>& get_points(); + + void set_offset(int pos, const float offset); + float get_offset(int pos) const; + + void set_color(int pos, const Color& color); + Color get_color(int pos) const; + + void set_offsets(const Vector<float>& offsets); + Vector<float> get_offsets() const; + + void set_colors(const Vector<Color>& colors); + Vector<Color> get_colors() const; + + _FORCE_INLINE_ Color get_color_at_offset(float p_offset) { + + if (points.empty()) + return Color(0,0,0,1); + + if(!is_sorted) + { + points.sort(); + is_sorted = true; + } + + //binary search + int low = 0; + int high = points.size() -1; + int middle; + + while( low <= high ) + { + middle = ( low + high ) / 2; + Point& point = points[middle]; + if( point.offset > p_offset ) { + high = middle - 1; //search low end of array + } else if ( point.offset < p_offset) { + low = middle + 1; //search high end of array + } else { + return point.color; + } + } + + //return interpolated value + if (points[middle].offset>p_offset) + { + middle--; + } + int first=middle; + int second=middle+1; + if(second>=points.size()) + return points[points.size()-1].color; + if(first<0) + return points[0].color; + Point& pointFirst = points[first]; + Point& pointSecond = points[second]; + return pointFirst.color.linear_interpolate(pointSecond.color, (p_offset-pointFirst.offset)/(pointSecond.offset - pointFirst.offset)); + } + + int get_points_count() const; +}; + +#endif /* SCENE_RESOURCES_COLOR_RAMP_H_ */ diff --git a/scene/resources/default_theme/checker_bg.png b/scene/resources/default_theme/checker_bg.png Binary files differnew file mode 100644 index 0000000000..0674f9da26 --- /dev/null +++ b/scene/resources/default_theme/checker_bg.png diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 2fddafc07b..9a9048e3e5 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -574,7 +574,7 @@ void make_default_theme() { // Tree Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0); - Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); + Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) ); t->set_stylebox("bg_focus","Tree", focus ); @@ -605,12 +605,31 @@ void make_default_theme() { t->set_color("guide_color","Tree", Color(0,0,0,0.1) ); t->set_constant("hseparation","Tree",4); - t->set_constant("vseparation","Tree",2); + t->set_constant("vseparation","Tree",4); t->set_constant("guide_width","Tree",2); t->set_constant("item_margin","Tree",12); t->set_constant("button_margin","Tree",4); + // ItemList + Ref<StyleBoxTexture> item_selected = make_stylebox( selection_png,4,4,4,4,8,2,8,2); + Ref<StyleBoxTexture> item_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,2,8,2); + + t->set_stylebox("bg","ItemList", make_stylebox( tree_bg_png,4,4,4,5) ); + t->set_stylebox("bg_focus","ItemList", focus ); + t->set_constant("hseparation","ItemList",4); + t->set_constant("vseparation","ItemList",2); + t->set_constant("icon_margin","ItemList",4); + t->set_constant("line_separation","ItemList",2); + t->set_font("font","ItemList", default_font ); + t->set_color("font_color","ItemList", control_font_color_low ); + t->set_color("font_color_selected","ItemList", control_font_color_pressed ); + t->set_color("guide_color","ItemList", Color(0,0,0,0.1) ); + t->set_stylebox("selected","ItemList", item_selected_oof ); + t->set_stylebox("selected_focus","ItemList", item_selected ); + t->set_stylebox("cursor","ItemList", focus ); + t->set_stylebox("cursor_unfocused","ItemList", focus ); + // TextEdit @@ -636,6 +655,8 @@ void make_default_theme() { t->set_icon("increment_hilite","TabContainer",make_icon( scroll_button_right_hl_png)); t->set_icon("decrement","TabContainer",make_icon( scroll_button_left_png)); t->set_icon("decrement_hilite","TabContainer",make_icon( scroll_button_left_hl_png)); + t->set_icon("menu","TabContainer",make_icon( tab_menu_png)); + t->set_icon("menu_hilite","TabContainer",make_icon( tab_menu_hl_png)); t->set_font("font","TabContainer", default_font ); @@ -692,7 +713,6 @@ void make_default_theme() { // FileDialog t->set_icon("folder","FileDialog",make_icon(icon_folder_png)); - t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7)); @@ -754,7 +774,8 @@ void make_default_theme() { t->set_constant("separation","HBoxContainer",4); t->set_constant("separation","VBoxContainer",4); t->set_constant("margin","MarginContainer",8); - t->set_constant("separation","GridContainer",4); + t->set_constant("hseparation","GridContainer",4); + t->set_constant("vseparation","GridContainer",4); t->set_constant("separation","HSplitContainer",12); t->set_constant("separation","VSplitContainer",12); t->set_constant("autohide","HSplitContainer",1); diff --git a/scene/resources/default_theme/selection.png b/scene/resources/default_theme/selection.png Binary files differindex 074c7a4d80..3b1c810c40 100644 --- a/scene/resources/default_theme/selection.png +++ b/scene/resources/default_theme/selection.png diff --git a/scene/resources/default_theme/selection_oof.png b/scene/resources/default_theme/selection_oof.png Binary files differindex 17ec977bd6..e8680128cd 100644 --- a/scene/resources/default_theme/selection_oof.png +++ b/scene/resources/default_theme/selection_oof.png diff --git a/scene/resources/default_theme/tab_menu.png b/scene/resources/default_theme/tab_menu.png Binary files differnew file mode 100644 index 0000000000..c5659da11b --- /dev/null +++ b/scene/resources/default_theme/tab_menu.png diff --git a/scene/resources/default_theme/tab_menu_hl.png b/scene/resources/default_theme/tab_menu_hl.png Binary files differnew file mode 100644 index 0000000000..6f68502c07 --- /dev/null +++ b/scene/resources/default_theme/tab_menu_hl.png diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index 78e210239d..03d851e749 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -49,6 +49,11 @@ static const unsigned char checked_png[]={ }; +static const unsigned char checker_bg_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x8,0x8,0x6,0x0,0x0,0x0,0xc4,0xf,0xbe,0x8b,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xe,0xc4,0x0,0x0,0xe,0xc4,0x1,0x95,0x2b,0xe,0x1b,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0x14,0xd,0x1c,0x1b,0x52,0x41,0x72,0xa4,0x0,0x0,0x0,0x24,0x49,0x44,0x41,0x54,0x28,0x53,0x63,0xfc,0xf,0x4,0xc,0x48,0xa0,0xa1,0xa1,0x1,0xca,0x82,0x0,0x26,0x28,0x8d,0x13,0x50,0xae,0x80,0xb1,0xbe,0xbe,0x7e,0x60,0xdd,0xc0,0xc0,0x0,0x0,0x78,0x11,0x9,0x87,0x2b,0xa,0xe1,0x69,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char close_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x73,0x0,0x29,0x0,0x7c,0x29,0x1e,0x61,0x18,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdd,0x9,0x19,0x1,0x14,0x3,0xf4,0x10,0x33,0xed,0x0,0x0,0x1,0x53,0x49,0x44,0x41,0x54,0x38,0xcb,0xcd,0x92,0xbd,0x4e,0x5b,0x41,0x10,0x85,0xbf,0xd9,0x9d,0xfd,0xb9,0xd7,0xb2,0xb9,0x81,0x8e,0x26,0xf4,0x69,0x53,0x50,0x44,0xa2,0x74,0x3,0xd,0xd,0x48,0x48,0xf4,0x3c,0x16,0x8f,0xc1,0x23,0xf0,0x0,0xf4,0x8e,0x90,0x11,0x96,0x25,0xa2,0x10,0x45,0x4a,0x9c,0x6b,0x4f,0xa,0xf6,0x4a,0xe6,0xc6,0x4e,0xb,0x47,0x5a,0xed,0xee,0x9c,0xd9,0xd1,0x99,0xb3,0x3,0x6f,0xd,0xd9,0x70,0xd7,0x72,0xfe,0xd3,0xe3,0x42,0xd9,0x5b,0xc0,0xba,0xa0,0xef,0x3d,0xfe,0xe0,0x9c,0x3b,0x35,0xb3,0x21,0xf0,0x1d,0xf8,0x5d,0xe2,0xd,0xf0,0xd9,0x39,0xf7,0xc5,0xcc,0xee,0x81,0x5f,0x9b,0xd4,0x4,0xe7,0xdc,0x65,0xd3,0x34,0x3f,0x53,0x4a,0x73,0xe0,0x18,0xd8,0x2b,0xeb,0x78,0x38,0x1c,0x3e,0xe5,0x9c,0x7f,0x38,0xe7,0x2e,0xd7,0xd4,0xfc,0x23,0xf1,0x30,0xc6,0x38,0x4b,0x29,0x59,0x8,0xe1,0x1e,0xb8,0x0,0x2e,0xea,0xba,0x7e,0xa8,0xaa,0xca,0x42,0x8,0x33,0xe0,0x70,0x5b,0x1,0x80,0x1d,0x60,0xac,0xaa,0x93,0x9c,0xb3,0xa9,0xea,0x63,0x8c,0x71,0x36,0x18,0xc,0x4c,0x55,0x27,0xc0,0xb8,0xe4,0xfc,0xd7,0xd4,0x5d,0xe0,0x5c,0x55,0xa7,0x39,0x67,0xcb,0x39,0x9b,0xf7,0x7e,0xa,0x9c,0x17,0xee,0x95,0xf1,0xba,0xa5,0x90,0x17,0x11,0x6f,0xf6,0x62,0xb6,0x88,0xb8,0x9e,0xe1,0x5b,0xd1,0x0,0x27,0x75,0x5d,0x3f,0x14,0xd9,0xd3,0x4e,0x49,0xf1,0xe4,0xa4,0xe4,0x6c,0x44,0x10,0x91,0xa3,0xd1,0x68,0xf4,0x54,0x55,0x55,0xd7,0xf3,0x19,0x70,0xa6,0xaa,0x93,0x94,0x92,0xc5,0x18,0xe7,0x22,0x72,0xb4,0x6e,0xe2,0xab,0x16,0xbc,0xf7,0x7,0x8b,0xc5,0x42,0x97,0xcb,0xe5,0xbc,0x6d,0xdb,0x2b,0xe0,0x16,0xa0,0x6d,0xdb,0x67,0xe7,0xdc,0xb5,0x88,0x24,0x11,0xd9,0xef,0x5a,0xeb,0x4f,0x62,0x37,0x48,0xe3,0xd5,0x6a,0xf5,0x15,0xb8,0x3,0x9e,0xb,0x37,0x2,0x3e,0x89,0xc8,0x47,0x33,0xbb,0x1,0xbe,0xad,0x4f,0x63,0xff,0x17,0xc2,0x16,0x73,0xb5,0x70,0xc2,0xbb,0xc2,0x5f,0x47,0xa5,0x56,0x8a,0x30,0xdd,0x7d,0xae,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -335,12 +340,12 @@ static const unsigned char scroll_grabber_hl_png[]={ static const unsigned char selection_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0x11,0x12,0x2a,0x16,0x85,0x48,0x8b,0x13,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xba,0x49,0x44,0x41,0x54,0x38,0x8d,0xed,0x93,0x31,0xa,0xc2,0x50,0x10,0x44,0xdf,0x97,0xbf,0x8a,0x3f,0x45,0xd0,0x52,0xbb,0xfc,0x63,0x88,0x88,0xa7,0xd0,0x23,0x9a,0x63,0x84,0x90,0x63,0x24,0x9d,0x9d,0x60,0x95,0x2f,0xb2,0x21,0x5a,0x18,0xb4,0x52,0x3,0x69,0x2c,0x9c,0x6e,0x8b,0x99,0xd9,0x59,0x76,0xc,0x30,0x6,0xa6,0xc0,0x4,0x18,0xd1,0xf,0x2d,0x70,0x5,0x2e,0xb6,0x23,0x2f,0x81,0x19,0x20,0x3d,0x5,0x14,0x38,0x3,0x47,0xdb,0x39,0xcf,0xd7,0xab,0xcd,0xc2,0x27,0xfe,0x20,0x22,0xe6,0x23,0x53,0xf5,0x56,0x56,0xe5,0x3e,0x2f,0x32,0x3,0x9c,0x6c,0xb7,0xb6,0xf5,0x89,0x4f,0x43,0x8,0xd4,0x21,0x7c,0xb4,0x8e,0x9c,0x33,0x3e,0xf1,0x69,0x5e,0x64,0x5b,0x60,0xf4,0xcc,0x2c,0x22,0x5f,0xc9,0x0,0x75,0x8,0x88,0xbc,0x92,0xf6,0x3d,0xda,0x5b,0xfc,0x5,0x7e,0x4a,0x40,0x55,0x89,0x9c,0xfb,0x4a,0x88,0x9c,0x43,0x55,0x9f,0xb3,0xe5,0x51,0x8c,0xa6,0xac,0xca,0x9d,0x4f,0xfc,0x21,0x8e,0xe3,0x5e,0xaf,0xc,0x34,0x40,0x6b,0x80,0x98,0x1,0x65,0x32,0xc,0xac,0xf3,0x1d,0x55,0xc6,0x3e,0x2,0xe2,0x2e,0xc9,0xc8,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x15,0x0,0x15,0x0,0x17,0xc8,0x7d,0x47,0xd1,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x6,0x14,0x14,0x31,0x1a,0x5f,0x97,0xc4,0x56,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x0,0xa3,0x49,0x44,0x41,0x54,0x38,0xcb,0xed,0x93,0xbd,0xa,0xc2,0x40,0x10,0x84,0xbf,0xbb,0x6c,0x72,0x8,0x1,0x51,0x4b,0xdf,0x23,0xc9,0xfb,0x57,0x12,0x9f,0x43,0xb0,0x10,0x2c,0x14,0xe4,0x92,0xcb,0xc5,0x66,0x3,0x36,0x26,0x7,0x69,0x2c,0x9c,0x6e,0x60,0x67,0xf6,0x87,0x1d,0x3,0x14,0xc0,0x6,0x70,0x80,0x25,0xd,0x11,0xf0,0xc0,0x4b,0x54,0x7c,0x4,0x76,0x40,0x9e,0x68,0xd0,0x3,0x77,0xe0,0x22,0xda,0x79,0x3f,0xf4,0x63,0x4b,0xa0,0x56,0x3e,0x7,0x8f,0x70,0xce,0x72,0x53,0x1,0x37,0xd1,0xb1,0x85,0x40,0xc3,0xc8,0xc3,0x47,0xae,0x73,0x6a,0x67,0x29,0x9,0x34,0xaa,0xb3,0x9f,0x3b,0x17,0x3e,0xf2,0x5c,0x9a,0x5d,0x6b,0x8a,0x89,0xa7,0x1e,0xed,0x2b,0xfe,0x6,0xbf,0x66,0xd0,0x39,0x4b,0xb9,0x24,0xd0,0x9a,0x6e,0xe2,0xa2,0xc1,0x8,0x8,0x2d,0x81,0xda,0x65,0x1c,0x12,0x5e,0xf9,0x4,0x54,0x40,0x34,0xc0,0x76,0x4d,0x98,0xcc,0xda,0x38,0xbf,0x1,0xae,0x5a,0x2a,0xba,0xb8,0xa1,0xb8,0x4f,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; static const unsigned char selection_oof_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x4c,0x0,0x4a,0x0,0x4e,0x88,0x29,0x6a,0xb6,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0x10,0x15,0x32,0x22,0x9b,0x14,0x96,0x1f,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xba,0x49,0x44,0x41,0x54,0x38,0x8d,0xed,0xd3,0xb1,0x4e,0xc3,0x40,0x10,0x84,0xe1,0xef,0xc2,0x4a,0x9c,0x90,0xb,0x6a,0x9f,0xe0,0x9,0x2,0xbc,0x58,0xc2,0xcb,0xc0,0x8b,0x85,0xa4,0xa6,0x41,0x4e,0x4d,0x41,0x71,0x91,0xe,0x99,0x2,0xd7,0x76,0xa4,0x34,0x14,0x6c,0xb9,0xda,0xf9,0x47,0x2b,0xcd,0x24,0xdc,0xe0,0x16,0x1d,0xae,0x90,0xcc,0xcf,0x88,0x6f,0x7c,0xe1,0x33,0x26,0xf1,0x23,0xee,0x90,0xcf,0x4,0x54,0x7c,0xe0,0x2d,0x26,0xe7,0xfb,0x87,0xf5,0xd3,0xba,0xf4,0x65,0x13,0x11,0xb3,0x80,0xd6,0xda,0x38,0x1c,0x87,0xd7,0xfd,0x61,0x97,0xf0,0x1e,0x8,0x5c,0x97,0xbe,0x6c,0x6b,0xad,0x6a,0xad,0xb3,0xf6,0x39,0xe7,0x54,0xfa,0xb2,0xdd,0x1f,0x76,0xcf,0x88,0xd5,0xb4,0x4f,0x11,0xb1,0x28,0x86,0x5a,0xab,0x88,0x60,0x7a,0x75,0x35,0x7f,0xbe,0x3c,0xff,0x80,0xbf,0x4,0x18,0x5b,0x6b,0x72,0xce,0x8b,0x82,0x9c,0xb3,0xd6,0x1a,0xbf,0x91,0x16,0x68,0x38,0xd,0xc7,0xe1,0xa5,0xf4,0x65,0xd3,0x75,0xdd,0x59,0x51,0xc6,0x9,0x2d,0xa1,0x77,0x41,0x99,0x92,0xb,0xeb,0xfc,0x3,0xd0,0xc5,0x44,0x36,0x1d,0x79,0x84,0xde,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x15,0x0,0x15,0x0,0x17,0xc8,0x7d,0x47,0xd1,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x6,0x14,0x14,0x32,0x15,0xe4,0x5,0x8a,0x4,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x0,0xa5,0x49,0x44,0x41,0x54,0x38,0xcb,0xed,0xd3,0x41,0x6a,0x2,0x51,0x10,0x4,0xd0,0xf7,0xe7,0xff,0xc1,0x30,0x4,0xe2,0x5a,0x18,0x4f,0x10,0x2,0x9e,0x29,0xe7,0xca,0x99,0x4,0xc9,0xda,0xcd,0x5c,0x20,0x8b,0x20,0x8a,0xfe,0x8c,0x9b,0x76,0xeb,0x8,0xb3,0xc9,0xc2,0x82,0xde,0x34,0x55,0xd5,0x34,0x54,0x25,0x74,0x58,0xe2,0x15,0x19,0xc9,0x7d,0x8c,0xa8,0xf8,0xc5,0x4f,0x9,0xf1,0x7,0x7a,0xbc,0x3c,0x68,0x70,0xc4,0x80,0x5d,0x89,0xcb,0x6b,0xef,0xcd,0x57,0xdd,0xd6,0x1e,0xed,0x84,0xc1,0x39,0x6f,0xf2,0xe0,0xfb,0xef,0x13,0xfb,0x82,0x82,0x45,0x88,0xf,0x31,0xf7,0xd0,0xd5,0x6d,0xed,0x73,0x9b,0x16,0x28,0x4d,0x2c,0x53,0x5c,0x9e,0x12,0xb,0x4e,0x7b,0x7b,0xb5,0x31,0x13,0x4f,0x83,0xff,0x64,0x30,0xe2,0x1c,0xbd,0x98,0x42,0x17,0xdc,0x51,0xa4,0xf0,0x82,0x53,0xde,0xe4,0x21,0xd2,0xf8,0xf6,0x50,0x94,0x39,0xe1,0x92,0xb0,0x9a,0x53,0xa6,0x34,0xb7,0xce,0x57,0x8f,0xdf,0x31,0x5b,0x17,0xde,0x59,0x7e,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -374,6 +379,16 @@ static const unsigned char tab_current_png[]={ }; +static const unsigned char tab_menu_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x6,0xd,0x3,0x2c,0x7,0xf7,0x85,0x69,0x73,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x0,0x54,0x49,0x44,0x41,0x54,0x38,0xcb,0xed,0x92,0xb1,0xd,0xc0,0x20,0x10,0x3,0x8f,0xec,0x63,0x65,0xff,0x2d,0x40,0x1e,0xe8,0xd3,0x50,0x24,0xd1,0x83,0x48,0x97,0x2,0xb7,0xb6,0x4f,0xd6,0xeb,0x61,0xeb,0x67,0xb2,0x5d,0xbe,0x66,0x4a,0x12,0x88,0x19,0x40,0xd2,0xa3,0x73,0x24,0x99,0x6,0x64,0x90,0xe8,0x1e,0xd3,0x5,0x7d,0x45,0x3,0x74,0xf3,0x3,0xb0,0xa4,0x73,0x9,0xf0,0x82,0x30,0x2a,0xaf,0x1c,0xb5,0xda,0xae,0xfb,0xbd,0xe6,0xba,0x0,0x22,0x30,0x1e,0x2c,0xd7,0x21,0xa8,0x0,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + +static const unsigned char tab_menu_hl_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x6,0xd,0x3,0x2c,0x15,0x4,0x3c,0x18,0x3b,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x0,0x58,0x49,0x44,0x41,0x54,0x38,0xcb,0x63,0x60,0x18,0x5,0x83,0xc,0xbc,0x7c,0xf9,0x92,0x91,0x54,0x35,0x8c,0x58,0x14,0xfc,0xc7,0x67,0x80,0xb8,0xb8,0x38,0x8a,0x1e,0x26,0x2c,0x6a,0x2e,0x32,0x30,0x30,0x60,0x33,0xe4,0x3f,0x54,0x8e,0x1,0xaf,0xb,0xa0,0xae,0xb8,0xc8,0xc0,0xc0,0xa0,0x8b,0x24,0xff,0x9f,0x81,0x81,0xe1,0xb2,0xb8,0xb8,0xb8,0x3e,0x51,0x6,0xa0,0x19,0xc2,0x80,0x4b,0x33,0x31,0x81,0x7a,0xe1,0xe5,0xcb,0x97,0x17,0x46,0x93,0x17,0x7e,0x0,0x0,0xa,0x9a,0x1f,0x34,0xff,0x99,0xf7,0x75,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char toggle_off_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x20,0x8,0x6,0x0,0x0,0x0,0xa2,0x9d,0x7e,0x84,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x26,0x0,0x26,0x0,0x26,0x59,0xf,0xde,0x74,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0x14,0x17,0x2,0x16,0xe9,0x0,0x17,0x60,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x2,0x45,0x49,0x44,0x41,0x54,0x68,0x81,0xed,0x99,0x5f,0x4f,0xd3,0x50,0x18,0x87,0x9f,0xb3,0x96,0xb5,0xcc,0x3a,0xa6,0xac,0x6d,0xa,0x91,0x84,0x5b,0x8d,0x7e,0x21,0x60,0x2c,0x5c,0x1a,0x63,0xe2,0x27,0x31,0x31,0xc6,0x4b,0x32,0xa7,0x7e,0x20,0x84,0x6b,0x6f,0xc,0x90,0x6d,0x32,0xca,0x6c,0xb0,0x24,0x75,0xc7,0x8b,0xba,0xb9,0x35,0xdd,0x84,0xec,0xe0,0x26,0xed,0x73,0xd7,0xf7,0xed,0xce,0x7b,0x7e,0xbf,0xbe,0x67,0x7f,0xde,0x41,0x4e,0x4e,0xa6,0x11,0x89,0xeb,0x12,0x50,0x1,0x2c,0x40,0x4b,0xc9,0xff,0xaf,0x48,0xe0,0x27,0x10,0x0,0x3e,0x70,0x39,0x48,0xe8,0x89,0x1b,0x2b,0xc0,0x33,0xe0,0x11,0x60,0x72,0xb7,0xc,0x8,0x81,0xaf,0xc0,0x67,0xa6,0x18,0x60,0x1,0x1b,0x4f,0x1e,0x3f,0x7d,0x6d,0x57,0xed,0x65,0x40,0x48,0x64,0xfc,0x72,0x95,0x8,0x10,0x8,0x74,0x5d,0x67,0x69,0x49,0x47,0xd3,0x92,0xdb,0x50,0x4b,0x14,0x45,0xf2,0xf8,0xe4,0xf8,0xc7,0xe1,0xd1,0xc1,0x2b,0xe0,0xcb,0x68,0x2e,0x59,0x59,0x7,0xc,0xbb,0x6a,0x97,0xce,0xba,0x67,0x4,0x41,0x80,0xec,0xf7,0x91,0x8a,0x1d,0x10,0x8,0x44,0xa1,0x80,0x51,0x2c,0x52,0x2a,0xdd,0xa3,0x58,0x2c,0x2a,0x5d,0x3f,0x89,0x69,0x9a,0x62,0x7d,0x6d,0xbd,0x74,0x78,0x74,0x60,0x90,0xd0,0x9c,0x66,0xbd,0x0,0x8,0x82,0xef,0x54,0x2a,0xf,0x70,0x6c,0x7,0xa1,0xf8,0x24,0x48,0x24,0xed,0x4e,0x1b,0xdf,0x3f,0xc7,0x30,0x4c,0xa5,0x6b,0xa7,0x11,0x86,0x21,0x96,0x65,0x41,0xca,0x91,0x4e,0xed,0x3d,0x29,0x25,0xb2,0x2f,0x71,0x1d,0x97,0x30,0xc,0x39,0x6d,0x9d,0x2a,0xdd,0x90,0xe7,0x7a,0xb8,0x8e,0xcb,0x79,0xb7,0xab,0xbc,0xbb,0x6e,0x4a,0x61,0x52,0x62,0x70,0xf6,0x55,0x8b,0x87,0xdf,0x6b,0x4a,0xe6,0x2e,0x1e,0xa6,0x18,0x90,0x15,0x32,0x6f,0xc0,0xed,0x7e,0xfe,0xcc,0x80,0x65,0x59,0xd4,0xf7,0x6a,0x63,0xb1,0xc6,0x7e,0x93,0x20,0x8,0x78,0xf1,0xf2,0xf9,0x58,0xfc,0xed,0x9b,0x77,0xa9,0xb1,0xeb,0xb0,0xb0,0x6,0xc,0xc4,0x7f,0x78,0xff,0x9,0x80,0x9d,0xdd,0x2d,0xea,0x7b,0xb5,0xa1,0xb0,0x34,0x81,0xd7,0x15,0x3d,0xca,0xc2,0x1a,0x0,0xd0,0x6c,0x7c,0xa4,0xd7,0xeb,0x1,0xb1,0x11,0x3b,0xbb,0x5b,0xc3,0xdc,0xe8,0x13,0x1f,0x8,0x4f,0x8b,0xfd,0x8d,0x85,0x36,0x60,0x1a,0xaa,0x3a,0x60,0xa1,0xdf,0x4,0x6b,0xf5,0x6d,0xca,0xe5,0x32,0xe5,0x72,0x79,0xec,0xe9,0xab,0x24,0x69,0x80,0x9,0xac,0xdc,0x4a,0xa5,0x1b,0xd2,0xd8,0x6f,0x2,0xb1,0x9,0xb5,0xfa,0xf6,0x58,0x6c,0x6,0x56,0x88,0x35,0xe,0x49,0x1e,0x81,0x10,0xb8,0x98,0xb5,0x8a,0xa,0x82,0x20,0x98,0xd8,0xd2,0x33,0xb4,0xff,0x5,0xb1,0xc6,0x21,0xb,0x7d,0x4,0xfe,0x5,0xb9,0x1,0xf3,0xde,0xc0,0xbc,0x99,0x68,0x80,0x88,0xa7,0x16,0x78,0xae,0xa7,0xbc,0xa8,0xe7,0x7a,0xc3,0xa1,0xc8,0xbc,0x49,0xfd,0x1e,0x20,0x84,0x40,0x14,0x4,0xad,0x76,0xb,0xc7,0x76,0xd8,0xdc,0xd8,0x54,0x5a,0x54,0x22,0x69,0xb5,0x5b,0x88,0x82,0x98,0xbb,0x9,0x69,0x6,0x48,0x0,0xcb,0xba,0x8f,0xef,0xfb,0xb7,0xf2,0x9b,0xfd,0xcf,0x44,0xc8,0x40,0xd3,0x34,0xa5,0x6b,0xa7,0x61,0x9a,0x26,0x51,0x14,0x41,0xca,0x70,0x2f,0x69,0x40,0x4,0x5c,0x75,0xbe,0x75,0x2e,0xed,0xaa,0xbd,0xbc,0xfa,0x70,0xf5,0x4e,0xcd,0x4,0x81,0x2b,0x62,0x8d,0xa3,0x5b,0x19,0x63,0x8d,0x6c,0x4c,0x85,0x4f,0x6,0x89,0xcc,0xff,0x2f,0x90,0x93,0x93,0x93,0x6d,0x7e,0x1,0x6b,0xe,0xc1,0xdb,0xd6,0xe0,0xc4,0xba,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index a598c69089..2d93113b40 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -510,6 +510,7 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ void Font::_bind_methods() { + ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); ObjectTypeDB::bind_method(_MD("set_height","px"),&Font::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Font::get_height); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 862669ecd8..90598ee789 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -36,7 +36,7 @@ Shader::Mode Shader::get_mode() const { - return (Mode)VisualServer::get_singleton()->shader_get_mode(shader); + return mode; } void Shader::set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs,int p_light_ofs) { @@ -203,6 +203,7 @@ void Shader::_bind_methods() { Shader::Shader(Mode p_mode) { + mode=p_mode; shader = VisualServer::get_singleton()->shader_create(VS::ShaderMode(p_mode)); params_cache_dirty=true; } diff --git a/scene/resources/shader.h b/scene/resources/shader.h index c5ef3777f7..b805cbec96 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -37,8 +37,18 @@ class Shader : public Resource { OBJ_TYPE(Shader,Resource); OBJ_SAVE_TYPE( Shader ); RES_BASE_EXTENSION("shd"); - RID shader; +public: + enum Mode { + + MODE_MATERIAL, + MODE_CANVAS_ITEM, + MODE_POST_PROCESS, + MODE_MAX + }; +private: + RID shader; + Mode mode; Dictionary _get_code(); void _set_code(const Dictionary& p_string); @@ -55,15 +65,10 @@ class Shader : public Resource { protected: + static void _bind_methods(); public: - enum Mode { - MODE_MATERIAL, - MODE_CANVAS_ITEM, - MODE_POST_PROCESS, - MODE_MAX - }; //void set_mode(Mode p_mode); Mode get_mode() const; diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 24d5978856..a0766ff317 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1301,7 +1301,7 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT","",SLOT_TYPE_VEC,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPECULAR","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION","",SLOT_TYPE_VEC,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_OUT}, |