diff -r 93785a7bda56 -r 1a786201465f ui/motif/graphics.c --- a/ui/motif/graphics.c Sun Nov 29 20:03:06 2015 +0100 +++ b/ui/motif/graphics.c Sun Nov 29 21:43:03 2015 +0100 @@ -96,6 +96,7 @@ /* -------------------- text layout functions -------------------- */ UiTextLayout* ui_text(UiGraphics *g) { UiTextLayout *text = malloc(sizeof(UiTextLayout)); + memset(text, 0, sizeof(UiTextLayout)); text->text = NULL; text->length = 0; text->widget = ((UiXlibGraphics*)g)->widget; @@ -134,25 +135,34 @@ } void ui_text_setstring(UiTextLayout *layout, char *str) { - layout->text = str; - layout->length = strlen(str); + ui_text_setstringl(layout, str, strlen(str)); } void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { layout->text = str; layout->length = len; + layout->changed = 1; } void ui_text_setfont(UiTextLayout *layout, char *font, int size) { create_default_fontset(layout);//TODO + layout->changed = 1; } void ui_text_getsize(UiTextLayout *layout, int *width, int *height) { - // TODO + if(layout->changed) { + XRectangle ext, lext; + XmbTextExtents(layout->fontset, layout->text, layout->length, &ext, &lext); + layout->width = ext.width; + layout->height = ext.height; + layout->changed = 0; + } + *width = layout->width; + *height = layout->height; } void ui_text_setwidth(UiTextLayout *layout, int width) { - // TODO + layout->maxwidth = width; } @@ -180,13 +190,26 @@ void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text) { UiXlibGraphics *gr = (UiXlibGraphics*)g; + int width, height; + ui_text_getsize(text, &width, &height); + if(text->maxwidth > 0) { + XRectangle clip; + clip.x = x; + clip.y = y; + clip.width = text->maxwidth; + clip.height = height; + XSetClipRectangles(gr->display, gr->gc, 0, 0, &clip, 1, Unsorted); + } + XmbDrawString( gr->display, XtWindow(gr->widget), text->fontset, gr->gc, x, - y, + y + height, text->text, text->length); + + XSetClipMask(gr->display, gr->gc, None); }