diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 2 | ||||
-rw-r--r-- | scene/2d/collision_shape_2d.cpp | 4 | ||||
-rw-r--r-- | scene/2d/sample_player_2d.cpp | 2 | ||||
-rw-r--r-- | scene/2d/sprite.cpp | 1 | ||||
-rw-r--r-- | scene/3d/skeleton.cpp | 99 | ||||
-rw-r--r-- | scene/3d/skeleton.h | 8 | ||||
-rw-r--r-- | scene/audio/sample_player.cpp | 40 | ||||
-rw-r--r-- | scene/audio/sample_player.h | 8 | ||||
-rw-r--r-- | scene/audio/stream_player.cpp | 6 | ||||
-rw-r--r-- | scene/audio/stream_player.h | 2 | ||||
-rw-r--r-- | scene/gui/base_button.cpp | 10 | ||||
-rw-r--r-- | scene/gui/box_container.cpp | 36 | ||||
-rw-r--r-- | scene/gui/box_container.h | 17 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 2 | ||||
-rw-r--r-- | scene/gui/label.cpp | 275 | ||||
-rw-r--r-- | scene/gui/label.h | 40 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 13 | ||||
-rw-r--r-- | scene/main/timer.cpp | 5 | ||||
-rw-r--r-- | scene/resources/rectangle_shape_2d.cpp | 2 |
19 files changed, 387 insertions, 185 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 49229ba500..357aaa225b 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -265,7 +265,7 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) { CanvasItem *c=get_child(i)->cast_to<CanvasItem>(); - if (c && c->hidden!=p_visible) //should the toplevels stop propagation? i think so but.. + if (c && !c->hidden) //should the toplevels stop propagation? i think so but.. c->_propagate_visibility_changed(p_visible); } diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index cd89e914fb..85751fc735 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -113,6 +113,10 @@ void CollisionShape2D::_notification(int p_what) { break; } + if (!shape.is_valid()) { + break; + } + rect=Rect2(); diff --git a/scene/2d/sample_player_2d.cpp b/scene/2d/sample_player_2d.cpp index bb37475944..ec17ffc55e 100644 --- a/scene/2d/sample_player_2d.cpp +++ b/scene/2d/sample_player_2d.cpp @@ -214,7 +214,7 @@ void SamplePlayer2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer2D::set_sample_library); ObjectTypeDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer2D::get_sample_library); - ObjectTypeDB::bind_method(_MD("set_polyphony","voices"),&SamplePlayer2D::set_polyphony); + ObjectTypeDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer2D::set_polyphony); ObjectTypeDB::bind_method(_MD("get_polyphony"),&SamplePlayer2D::get_polyphony); ObjectTypeDB::bind_method(_MD("play","sample","voice"),&SamplePlayer2D::play,DEFVAL(NEXT_VOICE)); diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 6705cebf37..87697fc073 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -189,6 +189,7 @@ void Sprite::set_region_rect(const Rect2& p_region_rect) { if (region && changed) { update(); item_rect_changed(); + _change_notify("region_rect"); } } diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 9df29f70ec..4712ba308a 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -187,30 +187,59 @@ void Skeleton::_notification(int p_what) { Bone &b=bonesptr[i]; - if (b.enabled) { + if (b.disable_rest) { + if (b.enabled) { - Transform pose=b.pose; - if (b.custom_pose_enable) { + Transform pose=b.pose; + if (b.custom_pose_enable) { - pose = b.custom_pose * pose; - } + pose = b.custom_pose * pose; + } + + if (b.parent>=0) { + + b.pose_global=bonesptr[b.parent].pose_global * pose; + } else { - if (b.parent>=0) { - - b.pose_global=bonesptr[b.parent].pose_global * (b.rest * pose); + b.pose_global=pose; + } } else { - - b.pose_global=b.rest * pose; + + if (b.parent>=0) { + + b.pose_global=bonesptr[b.parent].pose_global; + } else { + + b.pose_global=Transform(); + } } + } else { - - if (b.parent>=0) { - - b.pose_global=bonesptr[b.parent].pose_global * b.rest; + if (b.enabled) { + + Transform pose=b.pose; + if (b.custom_pose_enable) { + + pose = b.custom_pose * pose; + } + + if (b.parent>=0) { + + b.pose_global=bonesptr[b.parent].pose_global * (b.rest * pose); + } else { + + b.pose_global=b.rest * pose; + } } else { - - b.pose_global=b.rest; - } + + if (b.parent>=0) { + + b.pose_global=bonesptr[b.parent].pose_global * b.rest; + } else { + + b.pose_global=b.rest; + } + } } vs->skeleton_bone_set_transform( skeleton, i, b.pose_global * b.rest_global_inverse ); @@ -315,6 +344,37 @@ void Skeleton::set_bone_parent(int p_bone, int p_parent) { _make_dirty(); } +void Skeleton::unparent_bone_and_rest(int p_bone) { + + ERR_FAIL_INDEX( p_bone, bones.size() ); + + int parent=bones[p_bone].parent; + while(parent>=0) { + bones[p_bone].rest = bones[parent].rest * bones[p_bone].rest; + parent=bones[parent].parent; + } + + bones[p_bone].parent=-1; + bones[p_bone].rest_global_inverse=bones[p_bone].rest.affine_inverse(); //same thing + + _make_dirty(); + +} + +void Skeleton::set_bone_disable_rest(int p_bone, bool p_disable) { + + ERR_FAIL_INDEX( p_bone, bones.size() ); + bones[p_bone].disable_rest=p_disable; + +} + +bool Skeleton::is_bone_rest_disabled(int p_bone) const { + + ERR_FAIL_INDEX_V( p_bone, bones.size(), false ); + return bones[p_bone].disable_rest; +} + + int Skeleton::get_bone_parent(int p_bone) const { ERR_FAIL_INDEX_V( p_bone, bones.size(), -1 ); @@ -522,9 +582,14 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_bone_count"),&Skeleton::get_bone_count); + ObjectTypeDB::bind_method(_MD("unparent_bone_and_rest","bone_idx"),&Skeleton::unparent_bone_and_rest); + ObjectTypeDB::bind_method(_MD("get_bone_rest","bone_idx"),&Skeleton::get_bone_rest); ObjectTypeDB::bind_method(_MD("set_bone_rest","bone_idx","rest"),&Skeleton::set_bone_rest); + ObjectTypeDB::bind_method(_MD("set_bone_disable_rest","bone_idx","disable"),&Skeleton::set_bone_disable_rest); + ObjectTypeDB::bind_method(_MD("is_bone_rest_disabled","bone_idx"),&Skeleton::is_bone_rest_disabled); + ObjectTypeDB::bind_method(_MD("bind_child_node_to_bone","bone_idx","node:Node"),&Skeleton::bind_child_node_to_bone); ObjectTypeDB::bind_method(_MD("unbind_child_node_from_bone","bone_idx","node:Node"),&Skeleton::unbind_child_node_from_bone); ObjectTypeDB::bind_method(_MD("get_bound_child_nodes_to_bone","bone_idx"),&Skeleton::_get_bound_child_nodes_to_bone); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index b7f84f44c9..6678722d12 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -46,6 +46,7 @@ class Skeleton : public Spatial { bool enabled; int parent; + bool disable_rest; Transform rest; Transform rest_global_inverse; @@ -57,7 +58,7 @@ class Skeleton : public Spatial { List<uint32_t> nodes_bound; - Bone() { parent=-1; enabled=true; custom_pose_enable=false; } + Bone() { parent=-1; enabled=true; custom_pose_enable=false; disable_rest=false; } }; bool rest_global_inverse_dirty; @@ -111,6 +112,11 @@ public: void set_bone_parent(int p_bone, int p_parent); int get_bone_parent(int p_bone) const; + void unparent_bone_and_rest(int p_idx); + + void set_bone_disable_rest(int p_bone, bool p_disable); + bool is_bone_rest_disabled(int p_bone) const; + int get_bone_count() const; void set_bone_rest(int p_bone, const Transform& p_rest); diff --git a/scene/audio/sample_player.cpp b/scene/audio/sample_player.cpp index b93f7e7ddd..7c0a926324 100644 --- a/scene/audio/sample_player.cpp +++ b/scene/audio/sample_player.cpp @@ -48,8 +48,8 @@ bool SamplePlayer::_set(const StringName& p_name, const Variant& p_value) { } } else if (name=="config/samples") set_sample_library(p_value); - else if (name=="config/voices") - set_voice_count(p_value); + else if (name=="config/polyphony") + set_polyphony(p_value); else if (name.begins_with("default/")) { String what=name.right(8); @@ -95,14 +95,14 @@ bool SamplePlayer::_get(const StringName& p_name,Variant &r_ret) const { if (name=="play/play") { r_ret=played_back; - } else if (name=="config/voices") { - r_ret= get_voice_count(); + } else if (name=="config/polyphony") { + r_ret= get_polyphony(); } else if (name=="config/samples") { r_ret= get_sample_library(); } else if (name.begins_with("default/")) { - String what=name.get_slicec('/',1); + String what=name.right(8); if (what=="volume_db") r_ret= get_default_volume_db(); @@ -153,7 +153,7 @@ void SamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const { } p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR)); - p_list->push_back( PropertyInfo( Variant::INT, "config/voices", PROPERTY_HINT_RANGE, "1,256,1")); + p_list->push_back( PropertyInfo( Variant::INT, "config/polyphony", PROPERTY_HINT_RANGE, "1,256,1")); p_list->push_back( PropertyInfo( Variant::OBJECT, "config/samples", PROPERTY_HINT_RESOURCE_TYPE, "SampleLibrary")); p_list->push_back( PropertyInfo( Variant::REAL, "default/volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01")); p_list->push_back( PropertyInfo( Variant::REAL, "default/pitch_scale", PROPERTY_HINT_RANGE, "0.01,48,0.01")); @@ -164,7 +164,7 @@ void SamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/cutoff", PROPERTY_HINT_RANGE, "20,16384.0,0.01")); p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/resonance", PROPERTY_HINT_RANGE, "0,4,0.01")); p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/gain", PROPERTY_HINT_RANGE, "0,2,0.01")); - p_list->push_back( PropertyInfo( Variant::INT, "default/reverb_room", PROPERTY_HINT_ENUM, "Small,Medimum,Large,Hall")); + p_list->push_back( PropertyInfo( Variant::INT, "default/reverb_room", PROPERTY_HINT_ENUM, "Small,Medium,Large,Hall")); p_list->push_back( PropertyInfo( Variant::REAL, "default/reverb_send", PROPERTY_HINT_RANGE, "0,1,0.01")); p_list->push_back( PropertyInfo( Variant::REAL, "default/chorus_send", PROPERTY_HINT_RANGE, "0,1,0.01")); @@ -203,14 +203,14 @@ SamplePlayer::Voice::~Voice() { } -void SamplePlayer::set_voice_count(int p_voice_count) { +void SamplePlayer::set_polyphony(int p_voice_count) { ERR_FAIL_COND( p_voice_count <1 || p_voice_count >0xFFFE ); voices.resize(p_voice_count); } -int SamplePlayer::get_voice_count() const { +int SamplePlayer::get_polyphony() const { return voices.size(); } @@ -460,9 +460,9 @@ float SamplePlayer::get_chorus(VoiceID p_voice) const { return v.chorus_send; } -float SamplePlayer::get_reverb_room(VoiceID p_voice) const { +SamplePlayer::ReverbRoomType SamplePlayer::get_reverb_room(VoiceID p_voice) const { - _GET_VOICE_V(0); + _GET_VOICE_V(REVERB_SMALL); return v.reverb_room; } @@ -591,7 +591,7 @@ float SamplePlayer::get_default_chorus() const { return _default.chorus_send; } -float SamplePlayer::get_default_reverb_room() const { +SamplePlayer::ReverbRoomType SamplePlayer::get_default_reverb_room() const { return _default.reverb_room; } @@ -606,8 +606,8 @@ void SamplePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer::set_sample_library ); ObjectTypeDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer::get_sample_library ); - ObjectTypeDB::bind_method(_MD("set_voice_count","max_voices"),&SamplePlayer::set_voice_count ); - ObjectTypeDB::bind_method(_MD("get_voice_count"),&SamplePlayer::get_voice_count ); + ObjectTypeDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer::set_polyphony ); + ObjectTypeDB::bind_method(_MD("get_polyphony"),&SamplePlayer::get_polyphony ); ObjectTypeDB::bind_method(_MD("play","name","unique"),&SamplePlayer::play, DEFVAL(false) ); ObjectTypeDB::bind_method(_MD("stop","voice"),&SamplePlayer::stop ); @@ -615,8 +615,8 @@ void SamplePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_mix_rate","voice","hz"),&SamplePlayer::set_mix_rate ); ObjectTypeDB::bind_method(_MD("set_pitch_scale","voice","ratio"),&SamplePlayer::set_pitch_scale ); - ObjectTypeDB::bind_method(_MD("set_volume","voice","nrg"),&SamplePlayer::set_volume ); - ObjectTypeDB::bind_method(_MD("set_volume_db","voice","nrg"),&SamplePlayer::set_volume_db ); + ObjectTypeDB::bind_method(_MD("set_volume","voice","volume"),&SamplePlayer::set_volume ); + ObjectTypeDB::bind_method(_MD("set_volume_db","voice","db"),&SamplePlayer::set_volume_db ); ObjectTypeDB::bind_method(_MD("set_pan","voice","pan","depth","height"),&SamplePlayer::set_pan,DEFVAL(0),DEFVAL(0) ); ObjectTypeDB::bind_method(_MD("set_filter","voice","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_filter,DEFVAL(0) ); ObjectTypeDB::bind_method(_MD("set_chorus","voice","send"),&SamplePlayer::set_chorus ); @@ -638,8 +638,8 @@ void SamplePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_reverb","voice"),&SamplePlayer::get_reverb ); ObjectTypeDB::bind_method(_MD("set_default_pitch_scale","ratio"),&SamplePlayer::set_default_pitch_scale ); - ObjectTypeDB::bind_method(_MD("set_default_volume","nrg"),&SamplePlayer::set_default_volume ); - ObjectTypeDB::bind_method(_MD("set_default_volume_db","db"),&SamplePlayer::set_default_volume ); + ObjectTypeDB::bind_method(_MD("set_default_volume","volume"),&SamplePlayer::set_default_volume ); + ObjectTypeDB::bind_method(_MD("set_default_volume_db","db"),&SamplePlayer::set_default_volume_db ); ObjectTypeDB::bind_method(_MD("set_default_pan","pan","depth","height"),&SamplePlayer::set_default_pan,DEFVAL(0),DEFVAL(0) ); ObjectTypeDB::bind_method(_MD("set_default_filter","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_default_filter,DEFVAL(0) ); ObjectTypeDB::bind_method(_MD("set_default_chorus","send"),&SamplePlayer::set_default_chorus ); @@ -647,7 +647,7 @@ void SamplePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_default_pitch_scale"),&SamplePlayer::get_default_pitch_scale ); ObjectTypeDB::bind_method(_MD("get_default_volume"),&SamplePlayer::get_default_volume ); - ObjectTypeDB::bind_method(_MD("get_default_volume_db"),&SamplePlayer::get_default_volume ); + ObjectTypeDB::bind_method(_MD("get_default_volume_db"),&SamplePlayer::get_default_volume_db ); ObjectTypeDB::bind_method(_MD("get_default_pan"),&SamplePlayer::get_default_pan ); ObjectTypeDB::bind_method(_MD("get_default_pan_depth"),&SamplePlayer::get_default_pan_depth ); ObjectTypeDB::bind_method(_MD("get_default_pan_height"),&SamplePlayer::get_default_pan_height ); @@ -677,6 +677,8 @@ void SamplePlayer::_bind_methods() { BIND_CONSTANT( REVERB_LARGE ); BIND_CONSTANT( REVERB_HALL ); + BIND_CONSTANT( INVALID_VOICE_ID ); + } diff --git a/scene/audio/sample_player.h b/scene/audio/sample_player.h index 53e085b8d8..75a01aff86 100644 --- a/scene/audio/sample_player.h +++ b/scene/audio/sample_player.h @@ -130,8 +130,8 @@ public: void set_sample_library(const Ref<SampleLibrary>& p_library); Ref<SampleLibrary> get_sample_library() const; - void set_voice_count(int p_voice_count); - int get_voice_count() const; + void set_polyphony(int p_voice_count); + int get_polyphony() const; VoiceID play(const String& p_name,bool unique=false); void stop(VoiceID p_voice); @@ -161,7 +161,7 @@ public: float get_filter_resonance(VoiceID p_voice) const; float get_filter_gain(VoiceID p_voice) const; float get_chorus(VoiceID p_voice) const; - float get_reverb_room(VoiceID p_voice) const; + ReverbRoomType get_reverb_room(VoiceID p_voice) const; float get_reverb(VoiceID p_voice) const; @@ -185,7 +185,7 @@ public: float get_default_filter_resonance() const; float get_default_filter_gain() const; float get_default_chorus() const; - float get_default_reverb_room() const; + ReverbRoomType get_default_reverb_room() const; float get_default_reverb() const; SamplePlayer(); diff --git a/scene/audio/stream_player.cpp b/scene/audio/stream_player.cpp index c4e1ccc9b6..0ee9d76611 100644 --- a/scene/audio/stream_player.cpp +++ b/scene/audio/stream_player.cpp @@ -67,7 +67,7 @@ bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { void StreamPlayer::sp_update() { - _THREAD_SAFE_METHOD_ + //_THREAD_SAFE_METHOD_ if (!paused && resampler.is_ready() && playback.is_valid()) { if (!playback->is_playing()) { @@ -144,7 +144,7 @@ void StreamPlayer::play(float p_from_offset) { if (playback->is_playing()) stop(); - _THREAD_SAFE_METHOD_ + //_THREAD_SAFE_METHOD_ playback->play(p_from_offset); //feed the ringbuffer as long as no update callback is going on sp_update(); @@ -162,7 +162,7 @@ void StreamPlayer::stop() { if (playback.is_null()) return; - _THREAD_SAFE_METHOD_ + //_THREAD_SAFE_METHOD_ AudioServer::get_singleton()->stream_set_active(stream_rid,false); playback->stop(); //set_idle_process(false); diff --git a/scene/audio/stream_player.h b/scene/audio/stream_player.h index b5aa943067..be090f50e1 100644 --- a/scene/audio/stream_player.h +++ b/scene/audio/stream_player.h @@ -37,7 +37,7 @@ class StreamPlayer : public Node { OBJ_TYPE(StreamPlayer,Node); - _THREAD_SAFE_CLASS_ + //_THREAD_SAFE_CLASS_ struct InternalStream : public AudioServer::AudioStream { StreamPlayer *player; diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 965e7f399d..0c63a3bc74 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -255,6 +255,16 @@ void BaseButton::_notification(int p_what) { group->_remove_button(this); } + if (p_what==NOTIFICATION_VISIBILITY_CHANGED && !is_visible()) { + + if (!toggle_mode) { + status.pressed = false; + } + status.hovering = false; + status.press_attempt = false; + status.pressing_inside = false; + status.pressing_button = 0; + } } void BaseButton::pressed() { diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 6489cbccd5..b63b3de530 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -99,8 +99,10 @@ void BoxContainer::_resort() { elements exist */ + bool has_stretched = false; while(stretch_ratio_total>0) { // first of all, dont even be here if no stretchable objects exist + has_stretched = true; bool refit_successful=true; //assume refit-test will go well for(int i=0;i<get_child_count();i++) { @@ -143,6 +145,18 @@ void BoxContainer::_resort() { int ofs=0; + if (!has_stretched) { + switch (align) { + case ALIGN_BEGIN: + break; + case ALIGN_CENTER: + ofs = stretch_diff / 2; + break; + case ALIGN_END: + ofs = stretch_diff; + break; + } + } first=true; int idx=0; @@ -254,6 +268,15 @@ void BoxContainer::_notification(int p_what) { } } +void BoxContainer::set_alignment(AlignMode p_align) { + align = p_align; + _resort(); +} + +BoxContainer::AlignMode BoxContainer::get_alignment() const { + return align; +} + void BoxContainer::add_spacer(bool p_begin) { Control *c = memnew( Control ); @@ -270,10 +293,23 @@ void BoxContainer::add_spacer(bool p_begin) { BoxContainer::BoxContainer(bool p_vertical) { vertical=p_vertical; + align = ALIGN_BEGIN; // set_ignore_mouse(true); set_stop_mouse(false); } +void BoxContainer::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("get_alignment"),&BoxContainer::get_alignment); + ObjectTypeDB::bind_method(_MD("set_alignment","alignment"),&BoxContainer::set_alignment); + + BIND_CONSTANT( ALIGN_BEGIN ); + BIND_CONSTANT( ALIGN_CENTER ); + BIND_CONSTANT( ALIGN_END ); + + ADD_PROPERTY( PropertyInfo(Variant::INT,"alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), _SCS("set_alignment"),_SCS("get_alignment") ); + +} MarginContainer* VBoxContainer::add_margin_child(const String& p_label,Control *p_control,bool p_expand) { diff --git a/scene/gui/box_container.h b/scene/gui/box_container.h index d461b4aebe..c357814baf 100644 --- a/scene/gui/box_container.h +++ b/scene/gui/box_container.h @@ -35,16 +35,31 @@ class BoxContainer : public Container { OBJ_TYPE(BoxContainer,Container); +public: + + enum AlignMode { + ALIGN_BEGIN, + ALIGN_CENTER, + ALIGN_END + }; + +private: bool vertical; + AlignMode align; void _resort(); protected: void _notification(int p_what); + + static void _bind_methods(); public: void add_spacer(bool p_begin=false); + void set_alignment(AlignMode p_align); + AlignMode get_alignment() const; + virtual Size2 get_minimum_size() const; BoxContainer(bool p_vertical=false); @@ -73,4 +88,6 @@ public: VBoxContainer() : BoxContainer(true) {} }; +VARIANT_ENUM_CAST(BoxContainer::AlignMode); + #endif // BOX_CONTAINER_H diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index b7b2f061ea..40fade840c 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1025,7 +1025,7 @@ void ItemList::_bind_methods(){ 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("get_item_icon:Texture","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); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e7af4fa349..002e49cbcf 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -33,15 +33,15 @@ void Label::set_autowrap(bool p_autowrap) { - + autowrap=p_autowrap; word_cache_dirty=true; minimum_size_changed(); - - + update(); + } bool Label::has_autowrap() const { - + return autowrap; } @@ -51,6 +51,7 @@ void Label::set_uppercase(bool p_uppercase) { uppercase=p_uppercase; word_cache_dirty=true; minimum_size_changed(); + update(); } bool Label::is_uppercase() const { @@ -66,19 +67,18 @@ int Label::get_line_height() const { void Label::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - - if (clip && !autowrap) - VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + if (clip || autowrap) + VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); if (word_cache_dirty) regenerate_word_cache(); - + RID ci = get_canvas_item(); - + Size2 string_size; Size2 size=get_size(); @@ -91,38 +91,43 @@ void Label::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(),font.is_valid() && font->is_distance_field_hint()); int font_h = font->get_height(); - int line_from=(int)get_val(); // + p_exposed.pos.y / font_h; int lines_visible = size.y/font_h; - int line_to=(int)get_val() + lines_visible; //p_exposed.pos.y+p_exposed.size.height / font_h; int space_w=font->get_char_size(' ').width; - int lines_total = get_max(); int chars_total=0; int vbegin=0,vsep=0; - - if (lines_total && lines_total < lines_visible) { + if (lines_visible > line_count) { + lines_visible = line_count; + + } + + if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { + lines_visible = max_lines_visible; + + } + + if (lines_visible > 0) { switch(valign) { case VALIGN_TOP: { - //nothing } break; case VALIGN_CENTER: { - - vbegin=(lines_visible-lines_total) * font_h / 2; + vbegin=(size.y - lines_visible * font_h) / 2; vsep=0; + } break; case VALIGN_BOTTOM: { - vbegin=(lines_visible-lines_total) * font_h; + vbegin=size.y - lines_visible * font_h; vsep=0; } break; case VALIGN_FILL: { vbegin=0; - if (lines_total>1) { - vsep=(lines_visible-lines_total) * font_h / (lines_total-1); + if (lines_visible>1) { + vsep=(size.y - lines_visible * font_h) / (lines_visible - 1); } else { vsep=0; } @@ -130,20 +135,21 @@ void Label::_notification(int p_what) { } break; } } - - + + WordCache *wc = word_cache; if (!wc) return; - + int c = 0; int line=0; + int line_to=lines_skipped + (lines_visible>0?lines_visible:1); while(wc) { /* handle lines not meant to be drawn quickly */ - if (line>line_to) + if (line>=line_to) break; - if (line<line_from) { - + if (line<lines_skipped) { + while (wc && wc->char_pos>=0) wc=wc->next; if (wc) @@ -151,36 +157,36 @@ void Label::_notification(int p_what) { line++; continue; } - + /* handle lines normally */ - + if (wc->char_pos<0) { //empty line wc=wc->next; line++; continue; } - + WordCache *from=wc; WordCache *to=wc; - + int taken=0; int spaces=0; while(to && to->char_pos>=0) { - + taken+=to->pixel_width; if (to!=from && to->space_count) { spaces+=to->space_count; } to=to->next; } - + bool can_fill = to && to->char_pos==WordCache::CHAR_WRAPLINE; float x_ofs=0; - + switch (align) { - + case ALIGN_FILL: case ALIGN_LEFT: { @@ -198,16 +204,16 @@ void Label::_notification(int p_what) { } break; } - - int y_ofs=(line-(int)get_val())*font_h + font->get_ascent(); + + int y_ofs=(line-lines_skipped)*font_h + font->get_ascent(); y_ofs+=vbegin + line*vsep; - + while(from!=to) { - + // draw a word int pos = from->char_pos; if (from->char_pos<0) { - + ERR_PRINT("BUG"); return; } @@ -221,15 +227,15 @@ void Label::_notification(int p_what) { } - - - + + + if (font_color_shadow.a>0) { - + int chars_total_shadow = chars_total; //save chars drawn float x_ofs_shadow=x_ofs; for (int i=0;i<from->word_len;i++) { - + if (visible_chars < 0 || chars_total_shadow<visible_chars) { CharType c = text[i+pos]; CharType n = text[i+pos+1]; @@ -249,7 +255,7 @@ void Label::_notification(int p_what) { } } - + } for (int i=0;i<from->word_len;i++) { @@ -268,73 +274,73 @@ void Label::_notification(int p_what) { } from=from->next; } - + wc=to?to->next:0; line++; - - } + + } } - + if (p_what==NOTIFICATION_THEME_CHANGED) { word_cache_dirty=true; update(); } if (p_what==NOTIFICATION_RESIZED) { - + word_cache_dirty=true; } - + } Size2 Label::get_minimum_size() const { - + if (autowrap) return Size2(1,1); else { - + // don't want to mutable everything - if(word_cache_dirty) + if(word_cache_dirty) const_cast<Label*>(this)->regenerate_word_cache(); - + Size2 ms=minsize; if (clip) ms.width=1; return ms; - } + } } int Label::get_longest_line_width() const { - + Ref<Font> font = get_font("font"); int max_line_width=0; int line_width=0; - - for (int i=0;i<text.size()+1;i++) { - - CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works + + for (int i=0;i<text.size();i++) { + + CharType current=text[i]; if (uppercase) current=String::char_uppercase(current); if (current<32) { - + if (current=='\n') { - + if (line_width>max_line_width) max_line_width=line_width; line_width=0; } } else { - + int char_width=font->get_char_size(current).width; - line_width+=char_width; + line_width+=char_width; } - + } if (line_width>max_line_width) max_line_width=line_width; - + return max_line_width; } @@ -349,15 +355,15 @@ int Label::get_line_count() const { } void Label::regenerate_word_cache() { - + while (word_cache) { - + WordCache *current=word_cache; word_cache=current->next; memdelete( current ); } - - + + int width=autowrap?get_size().width:get_longest_line_width(); Ref<Font> font = get_font("font"); @@ -368,11 +374,11 @@ void Label::regenerate_word_cache() { int space_width=font->get_char_size(' ').width; line_count=1; total_char_cache=0; - + WordCache *last=NULL; - + for (int i=0;i<text.size()+1;i++) { - + CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works if (uppercase) @@ -429,12 +435,12 @@ void Label::regenerate_word_cache() { if (current_word_size==0) { word_pos=i; } - + char_width=font->get_char_size(current).width; current_word_size+=char_width; line_width+=char_width; total_char_cache++; - + } if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) { @@ -474,29 +480,22 @@ void Label::regenerate_word_cache() { space_count=0; } - + } - - //total_char_cache -= line_count + 1; // do not count new lines (including the first one) - + if (!autowrap) { - minsize.width=width; - minsize.height=font->get_height()*line_count; - set_page( line_count ); - - } else { - - set_page( get_size().height / font->get_height() ); + if (max_lines_visible > 0 && line_count > max_lines_visible) { + minsize.height=font->get_height()*max_lines_visible; + } else { + minsize.height=font->get_height()*line_count; + } } - - set_max(line_count); - + word_cache_dirty=false; } - void Label::set_align(Align p_align) { ERR_FAIL_INDEX(p_align,4); @@ -505,7 +504,7 @@ void Label::set_align(Align p_align) { } Label::Align Label::get_align() const{ - + return align; } @@ -522,24 +521,23 @@ Label::VAlign Label::get_valign() const{ } void Label::set_text(const String& p_string) { - + String str = XL_MESSAGE(p_string); if (text==str) return; - + text=str; word_cache_dirty=true; + if (percent_visible<1) + visible_chars=get_total_character_count()*percent_visible; update(); - if (!autowrap) - minimum_size_changed(); - + minimum_size_changed(); + } void Label::set_clip_text(bool p_clip) { - if (clip==p_clip) - return; clip=p_clip; update(); minimum_size_changed(); @@ -551,23 +549,39 @@ bool Label::is_clipping_text() const { } String Label::get_text() const { - + return text; } void Label::set_visible_characters(int p_amount) { visible_chars=p_amount; + if (get_total_character_count() > 0) { + percent_visible=(float)p_amount/(float)total_char_cache; + } update(); } +int Label::get_visible_characters() const { + + return visible_chars; +} + void Label::set_percent_visible(float p_percent) { - if (p_percent<0) - set_visible_characters(-1); - else - set_visible_characters(get_total_character_count()*p_percent); - percent_visible=p_percent; + if (p_percent<0 || p_percent>=1) { + + visible_chars=-1; + percent_visible=1; + + } else { + + visible_chars=get_total_character_count()*p_percent; + percent_visible=p_percent; + + } + update(); + } float Label::get_percent_visible() const{ @@ -575,6 +589,27 @@ float Label::get_percent_visible() const{ return percent_visible; } +void Label::set_lines_skipped(int p_lines) { + + lines_skipped=p_lines; + update(); +} + +int Label::get_lines_skipped() const{ + + return lines_skipped; +} + +void Label::set_max_lines_visible(int p_lines) { + + max_lines_visible=p_lines; + update(); +} + +int Label::get_max_lines_visible() const{ + + return max_lines_visible; +} int Label::get_total_character_count() const { @@ -585,7 +620,7 @@ int Label::get_total_character_count() const { } void Label::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("set_align","align"),&Label::set_align); ObjectTypeDB::bind_method(_MD("get_align"),&Label::get_align); ObjectTypeDB::bind_method(_MD("set_valign","valign"),&Label::set_valign); @@ -594,14 +629,21 @@ void Label::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_text"),&Label::get_text); ObjectTypeDB::bind_method(_MD("set_autowrap","enable"),&Label::set_autowrap); ObjectTypeDB::bind_method(_MD("has_autowrap"),&Label::has_autowrap); + ObjectTypeDB::bind_method(_MD("set_clip_text","enable"),&Label::set_clip_text); + ObjectTypeDB::bind_method(_MD("is_clipping_text"),&Label::is_clipping_text); ObjectTypeDB::bind_method(_MD("set_uppercase","enable"),&Label::set_uppercase); ObjectTypeDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase); ObjectTypeDB::bind_method(_MD("get_line_height"),&Label::get_line_height); ObjectTypeDB::bind_method(_MD("get_line_count"),&Label::get_line_count); ObjectTypeDB::bind_method(_MD("get_total_character_count"),&Label::get_total_character_count); - ObjectTypeDB::bind_method(_MD("set_visible_characters"),&Label::set_visible_characters); + ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&Label::set_visible_characters); + ObjectTypeDB::bind_method(_MD("get_visible_characters"),&Label::get_visible_characters); ObjectTypeDB::bind_method(_MD("set_percent_visible","percent_visible"),&Label::set_percent_visible); ObjectTypeDB::bind_method(_MD("get_percent_visible"),&Label::get_percent_visible); + ObjectTypeDB::bind_method(_MD("set_lines_skipped","lines_skipped"),&Label::set_lines_skipped); + ObjectTypeDB::bind_method(_MD("get_lines_skipped"),&Label::get_lines_skipped); + ObjectTypeDB::bind_method(_MD("set_max_lines_visible","lines_visible"),&Label::set_max_lines_visible); + ObjectTypeDB::bind_method(_MD("get_max_lines_visible"),&Label::get_max_lines_visible); BIND_CONSTANT( ALIGN_LEFT ); BIND_CONSTANT( ALIGN_CENTER ); @@ -617,18 +659,21 @@ void Label::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "align", PROPERTY_HINT_ENUM,"Left,Center,Right,Fill" ),_SCS("set_align"),_SCS("get_align") ); ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "valign", PROPERTY_HINT_ENUM,"Top,Center,Bottom,Fill" ),_SCS("set_valign"),_SCS("get_valign") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "autowrap"),_SCS("set_autowrap"),_SCS("has_autowrap") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "clip_text"),_SCS("set_clip_text"),_SCS("is_clipping_text") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "uppercase"),_SCS("set_uppercase"),_SCS("is_uppercase") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_percent_visible"),_SCS("get_percent_visible") ); + ADD_PROPERTY( PropertyInfo( Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE,"0,999,1"),_SCS("set_lines_skipped"),_SCS("get_lines_skipped") ); + ADD_PROPERTY( PropertyInfo( Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE,"-1,999,1"),_SCS("set_max_lines_visible"),_SCS("get_max_lines_visible") ); } Label::Label(const String &p_text) { - + align=ALIGN_LEFT; valign=VALIGN_TOP; text=""; word_cache=NULL; - word_cache_dirty=true; + word_cache_dirty=true; autowrap=false; line_count=0; set_v_size_flags(0); @@ -636,20 +681,22 @@ Label::Label(const String &p_text) { set_ignore_mouse(true); total_char_cache=0; visible_chars=-1; - percent_visible=-1; + percent_visible=1; + lines_skipped=0; + max_lines_visible=-1; set_text(p_text); uppercase=false; } Label::~Label() { - + while (word_cache) { - + WordCache *current=word_cache; word_cache=current->next; memdelete( current ); - } + } } diff --git a/scene/gui/label.h b/scene/gui/label.h index 81e3ab5676..4ea9f5d377 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -29,17 +29,17 @@ #ifndef LABEL_H #define LABEL_H -#include "scene/gui/range.h" +#include "scene/gui/control.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class Label : public Range { - - OBJ_TYPE( Label, Range ); -public: - +class Label : public Control { + + OBJ_TYPE( Label, Control ); +public: + enum Align { - + ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, @@ -63,11 +63,11 @@ private: Size2 minsize; int line_count; bool uppercase; - + int get_longest_line_width() const; - + struct WordCache { - + enum { CHAR_NEWLINE=-1, CHAR_WRAPLINE=-2 @@ -78,23 +78,25 @@ private: int space_count; WordCache *next; WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; space_count=0;} - }; - + }; + bool word_cache_dirty; void regenerate_word_cache(); float percent_visible; - + WordCache *word_cache; int total_char_cache; int visible_chars; -protected: + int lines_skipped; + int max_lines_visible; +protected: void _notification(int p_what); static void _bind_methods(); // bind helpers public: - + virtual Size2 get_minimum_size() const; void set_align(Align p_align); @@ -105,7 +107,7 @@ public: void set_text(const String& p_string); String get_text() const; - + void set_autowrap(bool p_autowrap); bool has_autowrap() const; @@ -113,6 +115,7 @@ public: bool is_uppercase() const; void set_visible_characters(int p_amount); + int get_visible_characters() const; int get_total_character_count() const; void set_clip_text(bool p_clip); @@ -121,6 +124,11 @@ public: void set_percent_visible(float p_percent); float get_percent_visible() const; + void set_lines_skipped(int p_lines); + int get_lines_skipped() const; + + void set_max_lines_visible(int p_lines); + int get_max_lines_visible() const; int get_line_height() const; int get_line_count() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1759f3eb04..b5fdde30cd 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -94,9 +94,9 @@ void TextEdit::Text::set_tab_size(int p_tab_size) { void TextEdit::Text::_update_line_cache(int p_line) const { - int w =0; - int tab_w=font->get_char_size(' ').width; - + int w = 0; + int tab_w=font->get_char_size(' ').width*tab_size; + int len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); @@ -292,7 +292,10 @@ void TextEdit::_update_scrollbars() { int vscroll_pixels = v_scroll->get_combined_minimum_size().width; int visible_width = size.width - cache.style_normal->get_minimum_size().width; - int total_width = text.get_max_width(); + int total_width = text.get_max_width() + vmin.x; + + if (line_numbers) + total_width += cache.line_number_w; bool use_hscroll=true; bool use_vscroll=true; @@ -322,7 +325,6 @@ void TextEdit::_update_scrollbars() { v_scroll->show(); v_scroll->set_max(total_rows); v_scroll->set_page(visible_rows); - v_scroll->set_val(cursor.line_ofs); } else { @@ -336,6 +338,7 @@ void TextEdit::_update_scrollbars() { h_scroll->set_max(total_width); h_scroll->set_page(visible_width); h_scroll->set_val(cursor.x_ofs); + } else { h_scroll->hide(); diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 3a80382a40..1bd22a9db1 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -182,11 +182,14 @@ void Timer::_bind_methods() { ADD_SIGNAL( MethodInfo("timeout") ); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode")); + ADD_PROPERTY( PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode") ); ADD_PROPERTY( PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01" ), _SCS("set_wait_time"), _SCS("get_wait_time") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "one_shot" ), _SCS("set_one_shot"), _SCS("is_one_shot") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autostart" ), _SCS("set_autostart"), _SCS("has_autostart") ); + BIND_CONSTANT( TIMER_PROCESS_FIXED ); + BIND_CONSTANT( TIMER_PROCESS_IDLE ); + } Timer::Timer() { diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp index 9a32b013c1..7903d88736 100644 --- a/scene/resources/rectangle_shape_2d.cpp +++ b/scene/resources/rectangle_shape_2d.cpp @@ -57,7 +57,7 @@ void RectangleShape2D::draw(const RID& p_to_rid,const Color& p_color) { Rect2 RectangleShape2D::get_rect() const { - Rect2(-extents,extents*2.0); + return Rect2(-extents,extents*2.0); } |