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

@ -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,9 +211,9 @@ 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);
@ -365,7 +364,8 @@ void Label::regenerate_word_cache() {
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;
@ -378,12 +378,13 @@ 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);
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;
@ -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,25 +411,48 @@ 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) {
@ -441,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)

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;