Merge pull request #1755 from dbsGen/master

Fixed some bugs in Label.
This commit is contained in:
Juan Linietsky 2015-05-03 22:55:58 -03:00
commit d6d29f6d79
2 changed files with 58 additions and 33 deletions

View file

@ -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;
@ -170,8 +169,8 @@ void Label::_notification(int p_what) {
while(to && to->char_pos>=0) {
taken+=to->pixel_width;
if (to!=from) {
spaces++;
if (to!=from && to->space_count) {
spaces+=to->space_count;
}
to=to->next;
}
@ -212,15 +211,15 @@ void Label::_notification(int p_what) {
ERR_PRINT("BUG");
return;
}
if (from!=wc) {
if (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);
}
}
@ -253,7 +252,7 @@ void Label::_notification(int p_what) {
}
for (int i=0;i<from->word_len;i++) {
if (visible_chars < 0 || chars_total<visible_chars) {
CharType c = text[i+pos];
CharType n = text[i+pos+1];
@ -361,11 +360,12 @@ void Label::regenerate_word_cache() {
int width=autowrap?get_size().width:get_longest_line_width();
Ref<Font> 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;
total_char_cache=0;
@ -374,16 +374,17 @@ void Label::regenerate_word_cache() {
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)
current=String::char_uppercase(current);
bool not_latin = current>=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) {
last->next=wc;
@ -391,14 +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;
@ -408,26 +411,49 @@ void Label::regenerate_word_cache() {
if (i<text.length() && text[i] == ' ') {
total_char_cache--; // do not count spaces
if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
space_count++;
line_width+=space_width;
}else {
space_count=0;
}
}
} 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;
}
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_width<width) || 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) {
last->next=wc;
@ -435,18 +461,16 @@ 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++;
space_count=0;
}
last_width=line_width;
}
//total_char_cache -= line_count + 1; // do not count new lines (including the first one)
@ -465,7 +489,7 @@ void Label::regenerate_word_cache() {
set_max(line_count);
word_cache_dirty=false;
}

View file

@ -75,8 +75,9 @@ private:
int char_pos; // if -1, then newline
int word_len;
int pixel_width;
int space_count;
WordCache *next;
WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; }
WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; space_count=0;}
};
bool word_cache_dirty;