From fdaa2920eb21fff3320a17e9239e04dfadecdb00 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 18 Apr 2015 14:38:54 -0300 Subject: Updated copyright year in all headers --- scene/gui/label.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 892e4c9bc7..6afff81fde 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ -- cgit v1.2.3 From 1a6012aff57498a476982f8dd918b5898da6e1f1 Mon Sep 17 00:00:00 2001 From: Gen Date: Tue, 28 Apr 2015 23:06:34 +0800 Subject: Update label.cpp --- scene/gui/label.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 6afff81fde..951df155d5 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -170,7 +170,7 @@ void Label::_notification(int p_what) { while(to && to->char_pos>=0) { taken+=to->pixel_width; - if (to!=from) { + if (to!=from && to->space_insert) { spaces++; } to=to->next; @@ -212,15 +212,15 @@ void Label::_notification(int p_what) { ERR_PRINT("BUG"); return; } - if (from!=wc) { + if (from!=wc && from->space_insert) { /* spacing */ x_ofs+=space_w; if (can_fill && align==ALIGN_FILL && spaces) { - + x_ofs+=int((size.width-(taken+space_w*spaces))/spaces); } - - + + } @@ -411,6 +411,38 @@ void Label::regenerate_word_cache() { } + }else if ((current < 65||current >90) && (current<97||current>122)) { + if (current_word_size>0) { + + WordCache *wc = memnew( WordCache ); + if (word_cache) { + last->next=wc; + } else { + word_cache=wc; + } + last=wc; + + wc->pixel_width=current_word_size; + wc->char_pos=word_pos; + wc->word_len=i-word_pos; + current_word_size=0; + } + WordCache *wc = memnew( WordCache ); + if (word_cache) { + last->next=wc; + } else { + word_cache=wc; + } + last=wc; + + wc->pixel_width=font->get_char_size(current).width; + wc->char_pos=i; + wc->word_len=1; + wc->space_insert = false; + current_word_size=0; + word_pos = i+1; + line_width+=wc->pixel_width; + total_char_cache++; } else { if (current_word_size==0) { -- cgit v1.2.3 From ad358562e5ab2c0fdb916acba7cf3118802de21f Mon Sep 17 00:00:00 2001 From: Gen Date: Wed, 29 Apr 2015 16:34:25 +0800 Subject: record the number of space before a words. --- scene/gui/label.cpp | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 951df155d5..e5226ca9b3 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -170,8 +170,8 @@ void Label::_notification(int p_what) { while(to && to->char_pos>=0) { taken+=to->pixel_width; - if (to!=from && to->space_insert) { - spaces++; + if (to!=from && to->space_count) { + spaces+=to->space_count; } to=to->next; } @@ -212,9 +212,9 @@ void Label::_notification(int p_what) { ERR_PRINT("BUG"); return; } - if (from!=wc && from->space_insert) { + if (from!=wc && from->space_count) { /* spacing */ - x_ofs+=space_w; + x_ofs+=space_w*from->space_count; if (can_fill && align==ALIGN_FILL && spaces) { x_ofs+=int((size.width-(taken+space_w*spaces))/spaces); @@ -366,6 +366,8 @@ void Label::regenerate_word_cache() { int word_pos=0; int line_width=0; int last_width=0; + int space_count=0; + int space_width=font->get_char_size(' ').width; line_count=1; total_char_cache=0; @@ -383,7 +385,6 @@ void Label::regenerate_word_cache() { if (current<33) { if (current_word_size>0) { - WordCache *wc = memnew( WordCache ); if (word_cache) { last->next=wc; @@ -395,7 +396,9 @@ void Label::regenerate_word_cache() { wc->pixel_width=current_word_size; wc->char_pos=word_pos; wc->word_len=i-word_pos; + wc->space_count = space_count; current_word_size=0; + space_count=0; } @@ -408,10 +411,16 @@ void Label::regenerate_word_cache() { if (i 0) { + space_count++; + line_width+=space_width; + }else { + space_count=0; + } } - }else if ((current < 65||current >90) && (current<97||current>122)) { + }else if ((current < 65||current >90) && (current<97||current>122) && (current<48||current>57)) { if (current_word_size>0) { WordCache *wc = memnew( WordCache ); @@ -425,7 +434,9 @@ void Label::regenerate_word_cache() { wc->pixel_width=current_word_size; wc->char_pos=word_pos; wc->word_len=i-word_pos; + wc->space_count = space_count; current_word_size=0; + space_count=0; } WordCache *wc = memnew( WordCache ); if (word_cache) { @@ -438,16 +449,14 @@ void Label::regenerate_word_cache() { wc->pixel_width=font->get_char_size(current).width; wc->char_pos=i; wc->word_len=1; - wc->space_insert = false; + wc->space_count=space_count; current_word_size=0; - word_pos = i+1; - line_width+=wc->pixel_width; + space_count=0; total_char_cache++; + line_width+=wc->pixel_width; } else { - + // latin characters if (current_word_size==0) { - if (line_width>0) // add a space before the new word if a word existed before - line_width+=font->get_char_size(' ').width; word_pos=i; } @@ -457,9 +466,10 @@ void Label::regenerate_word_cache() { total_char_cache++; } - + + print_line(itos(line_width)); if ((autowrap && line_width>=width && last_widthnext=wc; @@ -467,14 +477,14 @@ void Label::regenerate_word_cache() { word_cache=wc; } last=wc; - + wc->pixel_width=0; wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE; line_width=current_word_size; line_count++; - + } last_width=line_width; -- cgit v1.2.3 From 02d672753f18eb3dbae1f5479861b84a1912a5db Mon Sep 17 00:00:00 2001 From: Gen Date: Wed, 29 Apr 2015 23:43:39 +0800 Subject: space is only skipped when autowrap. --- scene/gui/label.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e5226ca9b3..83b36daff4 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -212,7 +212,7 @@ void Label::_notification(int p_what) { ERR_PRINT("BUG"); return; } - if (from!=wc && from->space_count) { + if (from->space_count) { /* spacing */ x_ofs+=space_w*from->space_count; if (can_fill && align==ALIGN_FILL && spaces) { @@ -411,7 +411,7 @@ void Label::regenerate_word_cache() { if (i 0) { + if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) { space_count++; line_width+=space_width; }else { @@ -467,7 +467,6 @@ void Label::regenerate_word_cache() { } - print_line(itos(line_width)); if ((autowrap && line_width>=width && last_width Date: Thu, 30 Apr 2015 00:03:19 +0800 Subject: Update label.cpp --- scene/gui/label.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 83b36daff4..4069fbb553 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -437,6 +437,25 @@ void Label::regenerate_word_cache() { wc->space_count = space_count; current_word_size=0; space_count=0; + } + float current_width = font->get_char_size(current).width; + if ((autowrap && line_width+current_width>=width && last_widthnext=wc; + } else { + word_cache=wc; + } + last=wc; + + wc->pixel_width=0; + wc->char_pos=WordCache::CHAR_WRAPLINE; + + line_width=0; + line_count++; + + } WordCache *wc = memnew( WordCache ); if (word_cache) { @@ -446,7 +465,7 @@ void Label::regenerate_word_cache() { } last=wc; - wc->pixel_width=font->get_char_size(current).width; + wc->pixel_width=current_width; wc->char_pos=i; wc->word_len=1; wc->space_count=space_count; -- cgit v1.2.3 From c322eddffb6ac9abc709cfdc7bdc4466bdb7b80a Mon Sep 17 00:00:00 2001 From: Gen Date: Thu, 30 Apr 2015 12:47:05 +0800 Subject: fixed a autowrap bug when word is too length. --- scene/gui/label.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 4069fbb553..38e7435aeb 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -99,7 +99,7 @@ void Label::_notification(int p_what) { int chars_total=0; int vbegin=0,vsep=0; - + if (lines_total && lines_total < lines_visible) { @@ -136,10 +136,9 @@ void Label::_notification(int p_what) { if (!wc) return; - + int c = 0; int line=0; while(wc) { - /* handle lines not meant to be drawn quickly */ if (line>line_to) break; @@ -253,7 +252,7 @@ void Label::_notification(int p_what) { } for (int i=0;iword_len;i++) { - + if (visible_chars < 0 || chars_total=width && last_width=width && last && last->char_pos >= 0) || insert_newline) { WordCache *wc = memnew( WordCache ); if (word_cache) { @@ -525,7 +524,7 @@ void Label::regenerate_word_cache() { set_max(line_count); word_cache_dirty=false; - + } -- cgit v1.2.3 From 0bc5b7a1464b442a9e54cd05c9720d1d53693ee1 Mon Sep 17 00:00:00 2001 From: Gen Date: Fri, 1 May 2015 18:47:34 +0800 Subject: Optimize the code. --- scene/gui/label.cpp | 97 +++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 66 deletions(-) (limited to 'scene/gui/label.cpp') diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 38e7435aeb..1751d335ee 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -360,11 +360,10 @@ void Label::regenerate_word_cache() { int width=autowrap?get_size().width:get_longest_line_width(); Ref font = get_font("font"); - + int current_word_size=0; int word_pos=0; int line_width=0; - int last_width=0; int space_count=0; int space_width=font->get_char_size(' ').width; line_count=1; @@ -375,14 +374,16 @@ void Label::regenerate_word_cache() { for (int i=0;i=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); bool insert_newline=false; - + int char_width; + if (current<33) { - + if (current_word_size>0) { WordCache *wc = memnew( WordCache ); if (word_cache) { @@ -391,16 +392,16 @@ void Label::regenerate_word_cache() { word_cache=wc; } last=wc; - + wc->pixel_width=current_word_size; wc->char_pos=word_pos; wc->word_len=i-word_pos; wc->space_count = space_count; current_word_size=0; space_count=0; - + } - + if (current=='\n') { insert_newline=true; @@ -419,73 +420,39 @@ void Label::regenerate_word_cache() { } - }else if ((current < 65||current >90) && (current<97||current>122) && (current<48||current>57)) { - if (current_word_size>0) { - - WordCache *wc = memnew( WordCache ); - if (word_cache) { - last->next=wc; - } else { - word_cache=wc; - } - last=wc; - - wc->pixel_width=current_word_size; - wc->char_pos=word_pos; - wc->word_len=i-word_pos; - wc->space_count = space_count; - current_word_size=0; - space_count=0; - } - float current_width = font->get_char_size(current).width; - if ((autowrap && line_width+current_width>=width && last_widthnext=wc; - } else { - word_cache=wc; - } - last=wc; - - wc->pixel_width=0; - wc->char_pos=WordCache::CHAR_WRAPLINE; - - line_width=0; - line_count++; - - - } - WordCache *wc = memnew( WordCache ); - if (word_cache) { - last->next=wc; - } else { - word_cache=wc; - } - last=wc; - - wc->pixel_width=current_width; - wc->char_pos=i; - wc->word_len=1; - wc->space_count=space_count; - current_word_size=0; - space_count=0; - total_char_cache++; - line_width+=wc->pixel_width; } else { // latin characters if (current_word_size==0) { word_pos=i; } - int char_width=font->get_char_size(current).width; + 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) || insert_newline) { + if ((autowrap && line_width>=width && (last && last->char_pos >= 0 || not_latin)) || insert_newline) { + if (not_latin) { + if (current_word_size>0) { + WordCache *wc = memnew( WordCache ); + if (word_cache) { + last->next=wc; + } else { + word_cache=wc; + } + last=wc; + + wc->pixel_width=current_word_size-char_width; + wc->char_pos=word_pos; + wc->word_len=i-word_pos; + wc->space_count = space_count; + current_word_size=char_width; + space_count=0; + word_pos=i; + } + } WordCache *wc = memnew( WordCache ); if (word_cache) { @@ -500,12 +467,10 @@ void Label::regenerate_word_cache() { line_width=current_word_size; line_count++; - + space_count=0; } - last_width=line_width; - } //total_char_cache -= line_count + 1; // do not count new lines (including the first one) -- cgit v1.2.3