godot/scene/gui/label.cpp

724 lines
18 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* label.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
2014-02-10 02:10:30 +01:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "label.h"
#include "print_string.h"
#include "globals.h"
#include "translation.h"
void Label::set_autowrap(bool p_autowrap) {
2014-02-10 02:10:30 +01:00
autowrap=p_autowrap;
word_cache_dirty=true;
minimum_size_changed();
update();
2014-02-10 02:10:30 +01:00
}
bool Label::has_autowrap() const {
2014-02-10 02:10:30 +01:00
return autowrap;
}
void Label::set_uppercase(bool p_uppercase) {
uppercase=p_uppercase;
word_cache_dirty=true;
minimum_size_changed();
update();
2014-02-10 02:10:30 +01:00
}
bool Label::is_uppercase() const {
return uppercase;
}
int Label::get_line_height() const {
return get_font("font")->get_height();
}
void Label::_notification(int p_what) {
2014-02-10 02:10:30 +01:00
if (p_what==NOTIFICATION_DRAW) {
if (clip || autowrap)
2014-02-10 02:10:30 +01:00
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
if (word_cache_dirty)
regenerate_word_cache();
2014-02-10 02:10:30 +01:00
RID ci = get_canvas_item();
2014-02-10 02:10:30 +01:00
Size2 string_size;
Size2 size=get_size();
Ref<Font> font = get_font("font");
Color font_color = get_color("font_color");
Color font_color_shadow = get_color("font_color_shadow");
2016-11-03 12:29:25 +01:00
bool use_outline = get_constant("shadow_as_outline");
2014-02-10 02:10:30 +01:00
Point2 shadow_ofs(get_constant("shadow_offset_x"),get_constant("shadow_offset_y"));
int line_spacing = get_constant("line_spacing");
2014-02-10 02:10:30 +01:00
2015-03-21 04:43:33 +01:00
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()+line_spacing;
int lines_visible = (size.y+line_spacing)/font_h;
2014-02-10 02:10:30 +01:00
int space_w=font->get_char_size(' ').width;
int chars_total=0;
int vbegin=0,vsep=0;
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) {
2014-02-10 02:10:30 +01:00
switch(valign) {
case VALIGN_TOP: {
//nothing
} break;
case VALIGN_CENTER: {
2016-11-07 12:15:21 +01:00
vbegin=(size.y - (lines_visible * font_h - line_spacing)) / 2;
2014-02-10 02:10:30 +01:00
vsep=0;
2014-02-10 02:10:30 +01:00
} break;
case VALIGN_BOTTOM: {
2016-11-07 12:15:21 +01:00
vbegin=size.y - (lines_visible * font_h - line_spacing);
2014-02-10 02:10:30 +01:00
vsep=0;
} break;
case VALIGN_FILL: {
vbegin=0;
if (lines_visible>1) {
2016-11-07 12:15:21 +01:00
vsep=(size.y - (lines_visible * font_h - line_spacing)) / (lines_visible - 1);
2014-02-10 02:10:30 +01:00
} else {
vsep=0;
}
} break;
}
}
2014-02-10 02:10:30 +01:00
WordCache *wc = word_cache;
if (!wc)
return;
2014-02-10 02:10:30 +01:00
int line=0;
int line_to=lines_skipped + (lines_visible>0?lines_visible:1);
2014-02-10 02:10:30 +01:00
while(wc) {
/* handle lines not meant to be drawn quickly */
if (line>=line_to)
2014-02-10 02:10:30 +01:00
break;
if (line<lines_skipped) {
2014-02-10 02:10:30 +01:00
while (wc && wc->char_pos>=0)
wc=wc->next;
if (wc)
wc=wc->next;
line++;
continue;
}
2014-02-10 02:10:30 +01:00
/* handle lines normally */
2014-02-10 02:10:30 +01:00
if (wc->char_pos<0) {
//empty line
wc=wc->next;
line++;
continue;
}
2014-02-10 02:10:30 +01:00
WordCache *from=wc;
WordCache *to=wc;
2014-02-10 02:10:30 +01:00
int taken=0;
int spaces=0;
while(to && to->char_pos>=0) {
2014-02-10 02:10:30 +01:00
taken+=to->pixel_width;
if (to!=from && to->space_count) {
spaces+=to->space_count;
2014-02-10 02:10:30 +01:00
}
to=to->next;
}
2014-02-10 02:10:30 +01:00
bool can_fill = to && to->char_pos==WordCache::CHAR_WRAPLINE;
float x_ofs=0;
2014-02-10 02:10:30 +01:00
switch (align) {
2014-02-10 02:10:30 +01:00
case ALIGN_FILL:
case ALIGN_LEFT: {
x_ofs=0;
} break;
case ALIGN_CENTER: {
x_ofs=int(size.width-(taken+spaces*space_w))/2;;
} break;
case ALIGN_RIGHT: {
x_ofs=int(size.width-(taken+spaces*space_w));
} break;
}
int y_ofs=(line-lines_skipped)*font_h + font->get_ascent();
2014-02-10 02:10:30 +01:00
y_ofs+=vbegin + line*vsep;
2014-02-10 02:10:30 +01:00
while(from!=to) {
2014-02-10 02:10:30 +01:00
// draw a word
int pos = from->char_pos;
if (from->char_pos<0) {
2014-02-10 02:10:30 +01:00
ERR_PRINT("BUG");
return;
}
2015-04-29 17:43:39 +02:00
if (from->space_count) {
2014-02-10 02:10:30 +01:00
/* spacing */
x_ofs+=space_w*from->space_count;
2014-02-10 02:10:30 +01:00
if (can_fill && align==ALIGN_FILL && spaces) {
2015-04-28 17:06:34 +02:00
2014-02-10 02:10:30 +01:00
x_ofs+=int((size.width-(taken+space_w*spaces))/spaces);
}
2015-04-28 17:06:34 +02:00
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
if (font_color_shadow.a>0) {
2014-02-10 02:10:30 +01:00
int chars_total_shadow = chars_total; //save chars drawn
float x_ofs_shadow=x_ofs;
for (int i=0;i<from->word_len;i++) {
2014-02-10 02:10:30 +01:00
if (visible_chars < 0 || chars_total_shadow<visible_chars) {
CharType c = text[i+pos];
CharType n = text[i+pos+1];
if (uppercase) {
c=String::char_uppercase(c);
n=String::char_uppercase(c);
}
float move=font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+shadow_ofs, c, n,font_color_shadow );
2016-11-03 12:29:25 +01:00
if (use_outline) {
2014-02-10 02:10:30 +01:00
font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(-shadow_ofs.x,shadow_ofs.y), c, n,font_color_shadow );
font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(shadow_ofs.x,-shadow_ofs.y), c, n,font_color_shadow );
font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(-shadow_ofs.x,-shadow_ofs.y), c, n,font_color_shadow );
}
x_ofs_shadow+=move;
chars_total_shadow++;
}
}
2014-02-10 02:10:30 +01:00
}
for (int i=0;i<from->word_len;i++) {
2014-02-10 02:10:30 +01:00
if (visible_chars < 0 || chars_total<visible_chars) {
CharType c = text[i+pos];
CharType n = text[i+pos+1];
if (uppercase) {
c=String::char_uppercase(c);
n=String::char_uppercase(c);
}
x_ofs+=font->draw_char(ci,Point2( x_ofs, y_ofs ), c, n, font_color );
chars_total++;
}
}
from=from->next;
}
2014-02-10 02:10:30 +01:00
wc=to?to->next:0;
line++;
}
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
if (p_what==NOTIFICATION_THEME_CHANGED) {
word_cache_dirty=true;
update();
}
if (p_what==NOTIFICATION_RESIZED) {
2014-02-10 02:10:30 +01:00
word_cache_dirty=true;
}
2014-02-10 02:10:30 +01:00
}
Size2 Label::get_minimum_size() const {
2014-02-10 02:10:30 +01:00
if (autowrap)
return Size2(1,1);
else {
2014-02-10 02:10:30 +01:00
// don't want to mutable everything
if(word_cache_dirty)
2014-02-10 02:10:30 +01:00
const_cast<Label*>(this)->regenerate_word_cache();
2014-02-10 02:10:30 +01:00
Size2 ms=minsize;
if (clip)
ms.width=1;
return ms;
}
2014-02-10 02:10:30 +01:00
}
int Label::get_longest_line_width() const {
2014-02-10 02:10:30 +01:00
Ref<Font> font = get_font("font");
int max_line_width=0;
int line_width=0;
for (int i=0;i<text.size();i++) {
CharType current=text[i];
2014-02-10 02:10:30 +01:00
if (uppercase)
current=String::char_uppercase(current);
if (current<32) {
2014-02-10 02:10:30 +01:00
if (current=='\n') {
2014-02-10 02:10:30 +01:00
if (line_width>max_line_width)
max_line_width=line_width;
line_width=0;
}
} else {
int char_width=font->get_char_size(current,text[i+1]).width;
line_width+=char_width;
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
}
if (line_width>max_line_width)
max_line_width=line_width;
2014-02-10 02:10:30 +01:00
return max_line_width;
}
int Label::get_line_count() const {
if (!is_inside_tree())
2014-02-10 02:10:30 +01:00
return 1;
if (word_cache_dirty)
const_cast<Label*>(this)->regenerate_word_cache();
return line_count;
}
int Label::get_visible_line_count() const {
int line_spacing = get_constant("line_spacing");
int font_h = get_font("font")->get_height()+line_spacing;
int lines_visible = (get_size().y+line_spacing)/font_h;
if (lines_visible > line_count)
lines_visible = line_count;
if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
lines_visible = max_lines_visible;
return lines_visible;
}
2014-02-10 02:10:30 +01:00
void Label::regenerate_word_cache() {
2014-02-10 02:10:30 +01:00
while (word_cache) {
2014-02-10 02:10:30 +01:00
WordCache *current=word_cache;
word_cache=current->next;
memdelete( current );
}
2014-02-10 02:10:30 +01:00
int width=autowrap?get_size().width:get_longest_line_width();
Ref<Font> font = get_font("font");
2015-05-01 12:47:34 +02:00
2014-02-10 02:10:30 +01:00
int current_word_size=0;
int word_pos=0;
int line_width=0;
int space_count=0;
int space_width=font->get_char_size(' ').width;
int line_spacing = get_constant("line_spacing");
2014-02-10 02:10:30 +01:00
line_count=1;
total_char_cache=0;
2014-02-10 02:10:30 +01:00
WordCache *last=NULL;
2014-02-10 02:10:30 +01:00
for (int i=0;i<text.size()+1;i++) {
2014-02-10 02:10:30 +01:00
CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works
2015-05-01 12:47:34 +02:00
2014-02-10 02:10:30 +01:00
if (uppercase)
current=String::char_uppercase(current);
// 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);
2014-02-10 02:10:30 +01:00
bool insert_newline=false;
2015-05-01 12:47:34 +02:00
int char_width;
2014-02-10 02:10:30 +01:00
if (current<33) {
2015-05-01 12:47:34 +02:00
2014-02-10 02:10:30 +01:00
if (current_word_size>0) {
WordCache *wc = memnew( WordCache );
if (word_cache) {
last->next=wc;
} else {
word_cache=wc;
}
last=wc;
2015-05-01 12:47:34 +02:00
2014-02-10 02:10:30 +01:00
wc->pixel_width=current_word_size;
wc->char_pos=word_pos;
wc->word_len=i-word_pos;
wc->space_count = space_count;
2014-02-10 02:10:30 +01:00
current_word_size=0;
space_count=0;
2015-05-01 12:47:34 +02:00
2014-02-10 02:10:30 +01:00
}
2015-05-01 12:47:34 +02:00
Huge Amount of BugFix -=-=-=-=-=-=-=-=-=-=- -Fixes to Collada Exporter (avoid crash situtions) -Fixed to Collada Importer (Fixed Animation Optimizer Bugs) -Fixes to RigidBody/RigidBody2D body_enter/body_exit, was buggy -Fixed ability for RigidBody/RigidBody2D to get contacts reported and bodyin/out in Kinematic mode. -Added proper trigger support for 3D Physics shapes -Changed proper value for Z-Offset in OmniLight -Fixed spot attenuation bug in SpotLight -Fixed some 3D and 2D spatial soudn bugs related to distance attenuation. -Fixed bugs in EventPlayer (channels were muted by default) -Fix in ButtonGroup (get nodes in group are now returned in order) -Fixed Linear->SRGB Conversion, previous algo sucked, new algo works OK -Changed SRGB->Linear conversion to use hardware if supported, improves texture quality a lot -Fixed options for Y-Fov and X-Fov in camera, should be more intuitive. -Fixed bugs related to viewports and transparency Huge Amount of New Stuff: -=-=-=-=-=-=-=-==-=-=-=- -Ability to manually advance an AnimationPlayer that is inactive (with advance() function) -More work in WinRT platform -Added XY normalmap support, imports on this format by default. Reduces normlmap size and enables much nice compression using LATC -Added Anisotropic filter support to textures, can be specified on import -Added support for Non-Square, Isometric and Hexagonal tilemaps in TileMap. -Added Isometric Dungeon demo. -Added simple hexagonal map demo. -Added Truck-Town demo. Shows how most types of joints and vehicles are used. Please somebody make a nicer town, this one is too hardcore. -Added an Object-Picking API to both RigidBody and Area! (and relevant demo)
2014-10-03 05:10:51 +02:00
2014-02-10 02:10:30 +01:00
if (current=='\n') {
insert_newline=true;
} else {
total_char_cache++;
}
if (i<text.length() && text[i] == ' ') {
total_char_cache--; // do not count spaces
2015-04-29 17:43:39 +02:00
if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
space_count++;
line_width+=space_width;
}else {
space_count=0;
}
}
2014-02-10 02:10:30 +01:00
} else {
// latin characters
2014-02-10 02:10:30 +01:00
if (current_word_size==0) {
word_pos=i;
}
char_width=font->get_char_size(current,text[i+1]).width;
2014-02-10 02:10:30 +01:00
current_word_size+=char_width;
line_width+=char_width;
total_char_cache++;
2014-02-10 02:10:30 +01:00
}
if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) {
if (separatable) {
2015-05-01 12:47:34 +02:00
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;
}
}
2014-02-10 02:10:30 +01:00
WordCache *wc = memnew( WordCache );
if (word_cache) {
last->next=wc;
} else {
word_cache=wc;
}
last=wc;
2014-02-10 02:10:30 +01:00
wc->pixel_width=0;
wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;
line_width=current_word_size;
line_count++;
2015-05-01 12:47:34 +02:00
space_count=0;
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
if (!autowrap) {
minsize.width=width;
if (max_lines_visible > 0 && line_count > max_lines_visible) {
2016-06-10 02:57:38 +02:00
minsize.height=(font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
} else {
2016-06-10 02:57:38 +02:00
minsize.height=(font->get_height() * line_count)+(line_spacing * (line_count - 1));
}
2014-02-10 02:10:30 +01:00
}
2014-02-10 02:10:30 +01:00
word_cache_dirty=false;
2014-02-10 02:10:30 +01:00
}
void Label::set_align(Align p_align) {
ERR_FAIL_INDEX(p_align,4);
align=p_align;
update();
}
Label::Align Label::get_align() const{
2014-02-10 02:10:30 +01:00
return align;
}
void Label::set_valign(VAlign p_align) {
ERR_FAIL_INDEX(p_align,4);
valign=p_align;
update();
}
Label::VAlign Label::get_valign() const{
return valign;
}
void Label::set_text(const String& p_string) {
2014-02-10 02:10:30 +01:00
String str = XL_MESSAGE(p_string);
if (text==str)
return;
2014-02-10 02:10:30 +01:00
text=str;
word_cache_dirty=true;
if (percent_visible<1)
visible_chars=get_total_character_count()*percent_visible;
2014-02-10 02:10:30 +01:00
update();
if (!autowrap) {
minimum_size_changed();
}
2014-02-10 02:10:30 +01:00
}
void Label::set_clip_text(bool p_clip) {
clip=p_clip;
update();
minimum_size_changed();
}
bool Label::is_clipping_text() const {
return clip;
}
String Label::get_text() const {
2014-02-10 02:10:30 +01:00
return text;
}
2014-02-10 02:10:30 +01:00
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;
}
2014-02-10 02:10:30 +01:00
update();
}
int Label::get_visible_characters() const {
return visible_chars;
}
2014-02-10 02:10:30 +01:00
void Label::set_percent_visible(float 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();
2014-02-10 02:10:30 +01:00
}
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;
}
2014-02-10 02:10:30 +01:00
int Label::get_total_character_count() const {
if (word_cache_dirty)
const_cast<Label*>(this)->regenerate_word_cache();
return total_char_cache;
}
void Label::_bind_methods() {
ClassDB::bind_method(_MD("set_align","align"),&Label::set_align);
ClassDB::bind_method(_MD("get_align"),&Label::get_align);
ClassDB::bind_method(_MD("set_valign","valign"),&Label::set_valign);
ClassDB::bind_method(_MD("get_valign"),&Label::get_valign);
ClassDB::bind_method(_MD("set_text","text"),&Label::set_text);
ClassDB::bind_method(_MD("get_text"),&Label::get_text);
ClassDB::bind_method(_MD("set_autowrap","enable"),&Label::set_autowrap);
ClassDB::bind_method(_MD("has_autowrap"),&Label::has_autowrap);
ClassDB::bind_method(_MD("set_clip_text","enable"),&Label::set_clip_text);
ClassDB::bind_method(_MD("is_clipping_text"),&Label::is_clipping_text);
ClassDB::bind_method(_MD("set_uppercase","enable"),&Label::set_uppercase);
ClassDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase);
ClassDB::bind_method(_MD("get_line_height"),&Label::get_line_height);
ClassDB::bind_method(_MD("get_line_count"),&Label::get_line_count);
ClassDB::bind_method(_MD("get_visible_line_count"),&Label::get_visible_line_count);
ClassDB::bind_method(_MD("get_total_character_count"),&Label::get_total_character_count);
ClassDB::bind_method(_MD("set_visible_characters","amount"),&Label::set_visible_characters);
ClassDB::bind_method(_MD("get_visible_characters"),&Label::get_visible_characters);
ClassDB::bind_method(_MD("set_percent_visible","percent_visible"),&Label::set_percent_visible);
ClassDB::bind_method(_MD("get_percent_visible"),&Label::get_percent_visible);
ClassDB::bind_method(_MD("set_lines_skipped","lines_skipped"),&Label::set_lines_skipped);
ClassDB::bind_method(_MD("get_lines_skipped"),&Label::get_lines_skipped);
ClassDB::bind_method(_MD("set_max_lines_visible","lines_visible"),&Label::set_max_lines_visible);
ClassDB::bind_method(_MD("get_max_lines_visible"),&Label::get_max_lines_visible);
2014-02-10 02:10:30 +01:00
BIND_CONSTANT( ALIGN_LEFT );
BIND_CONSTANT( ALIGN_CENTER );
BIND_CONSTANT( ALIGN_RIGHT );
BIND_CONSTANT( ALIGN_FILL );
BIND_CONSTANT( VALIGN_TOP );
BIND_CONSTANT( VALIGN_CENTER );
BIND_CONSTANT( VALIGN_BOTTOM );
BIND_CONSTANT( VALIGN_FILL );
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text",PROPERTY_HINT_MULTILINE_TEXT,"",PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_text"),_SCS("get_text") );
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") );
2014-02-10 02:10:30 +01:00
}
Label::Label(const String &p_text) {
2014-02-10 02:10:30 +01:00
align=ALIGN_LEFT;
valign=VALIGN_TOP;
text="";
word_cache=NULL;
word_cache_dirty=true;
2014-02-10 02:10:30 +01:00
autowrap=false;
line_count=0;
set_v_size_flags(0);
clip=false;
set_mouse_filter(MOUSE_FILTER_IGNORE);
2014-02-10 02:10:30 +01:00
total_char_cache=0;
visible_chars=-1;
percent_visible=1;
lines_skipped=0;
max_lines_visible=-1;
2014-02-10 02:10:30 +01:00
set_text(p_text);
uppercase=false;
}
Label::~Label() {
2014-02-10 02:10:30 +01:00
while (word_cache) {
2014-02-10 02:10:30 +01:00
WordCache *current=word_cache;
word_cache=current->next;
memdelete( current );
}
2014-02-10 02:10:30 +01:00
}