00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00040 #include "omicron/internal.h"
00041 #include "omicron/render.h"
00042 #include "omicron/image.h"
00043 #include "omicron/gui.h"
00044
00045 uilabel_c::uilabel_c()
00046 {
00047 classname = "label";
00048 fnt = gv.gui->get_font(UIF_FONT8);
00049
00050 set_wordwrap(true);
00051 }
00052
00053 uilabel_c::~uilabel_c()
00054 {
00055 AssertThis;
00056 }
00057
00058 void uilabel_c::paint()
00059 {
00060 AssertThis;
00061
00062 uiobject_c::paint();
00063
00064 AssertReturn2(text, strlen(text));
00065
00066 char *buf = new char[strlen(text)+2];
00067 char *p = buf;
00068 char *p1 = buf;
00069 ushort y = 0;
00070 color_t c = disabled ? gv.gui->get_color(UIC_DISABLED) :
00071 gv.gui->get_color(UIC_TEXT);
00072
00073 ushort linelen = 0;
00074
00075 memset(buf, 0, strlen(text)+2);
00076 strcpy(buf, text);
00077
00078 if (wordwrap)
00079 {
00080 while(*p)
00081 {
00082 p++;
00083
00084 while(*p1 == '\n') { p1++; y+=fnt->height; };
00085
00086 if ((*p == 0 || *p == '\n'))
00087 {
00088 char oldchar = *p;
00089
00090 *p = 0;
00091
00092 do
00093 {
00094 linelen = gv.renderer->get_string_pixelwidth(p1, fnt);
00095 if (linelen >= width)
00096 {
00097 char *p2 = strrchr(p1, ' ');
00098 if (p2)
00099 {
00100 *p = oldchar;
00101 p = p2;
00102 *p = 0;
00103 oldchar = ' ';
00104 linelen = gv.renderer->get_string_pixelwidth(p1, fnt);
00105 }
00106 else
00107 {
00108 linelen = 0;
00109 }
00110 }
00111 } while(linelen>=width);
00112
00113 img->draw_string(0, y, p1, fnt, c);
00114 y += fnt->height;
00115
00116 p1 = ++p;
00117 }
00118 }
00119 }
00120 else
00121 {
00122 img->draw_string(0, 0, buf, fnt, c);
00123 }
00124
00125 SafeArrayDelete(buf);
00126 }