/** * \brief * * \return */ void GuiMultiTextBox::renderText() { // clean up previous contents if(fontData != NULL) { for(int i=0; i<numLines; i++) { if(fontData[i]) s_font_uninit(fontData[i]); fontData[i] = NULL; } s_free(fontData); fontData = NULL; } numLines = 0; std::list<std::string>::iterator it = fontWords.begin(); while(true) { std::string textLine; if(it != fontWords.end()) textLine = it->c_str(); else break; s_font_t** newFontData = (s_font_t**)s_realloc(fontData, sizeof(s_font_t*) * (numLines + 1)); if (newFontData == NULL) return; fontData = newFontData; fontData[numLines] = NULL; s_font_t* font; if(s_font_init(&font, (char*)fontName.c_str())) { return; } s_font_set_size(font, fontSize); s_font_set_rgb(font, fontColor.red, fontColor.green, fontColor.blue); std::string textTest; while(it != fontWords.end()) { if(!textTest.empty()) textTest += " "; textTest += it->c_str(); s_font_set_str(font, (char*)textTest.c_str()); s_font_get_glyph(font); // the text does not fit anymore if(font->glyph.img->w > drawArea.w) break; textLine = textTest; it ++; } s_font_set_str(font, (char*)textLine.c_str()); s_font_get_glyph(font); fontData[numLines ++] = font; } }
static int draw_single_box (s_surface_t *wsurface, s_rect_t *rect, osk_char_t c[4], int colors[2], image_bin_t *image_bin) { int i; int r; int g; int b; int fh; int x = 0; int y = 0; char *tbuf; s_image_t *img; s_font_t *font; s_surface_t *surface; if (s_surface_create(&surface, rect->w, rect->h, wsurface->bitsperpixel)) { return -1; } s_fillbox(surface, 0, 0, rect->w, rect->h, colors[0]); s_image_init(&img); image_load(img, image_bin->width, image_bin->height, (unsigned char *) image_bin->pixel_data); s_image_get_buf(surface, img); tbuf = (char *) s_malloc(sizeof(char) * (rect->w - 2) * (rect->h - 2) * surface->bytesperpixel); s_scalebox(surface, img->w, img->h, img->buf, rect->w - 2, rect->h - 2, tbuf); s_putbox(surface, 1, 1, rect->w - 2, rect->h - 2, tbuf); s_free(tbuf); s_image_uninit(img); fh = rect->h / 3; for (i = 0; i < 4; i++) { s_font_init(&font, "veramono.ttf"); s_font_set_str(font, c[i].name); s_colorrgb(wsurface, colors[1], &r, &g, &b); s_font_set_rgb(font, r, g, b); if (strlen(c[i].name) > 1) { s_font_set_size(font, fh - 5); } else { s_font_set_size(font, fh); } s_font_get_glyph(font); s_image_get_handler(font->glyph.img); font->glyph.img->handler->x = 0; font->glyph.img->handler->y = 0; font->glyph.img->handler->w = font->glyph.img->w; font->glyph.img->handler->h = font->glyph.img->h; switch (i) { case 0: x = 5; y = (rect->h - fh) / 2; break; case 1: x = (rect->w - font->glyph.img->handler->w) / 2; y = 2; break; case 2: x = rect->w - font->glyph.img->handler->w - 3; y = (rect->h - fh) / 2; break; case 3: y = rect->h - fh - 7; x = (rect->w - font->glyph.img->handler->w) / 2; break; } s_putboxpartrgba(surface, x, y + fh - font->glyph.yMax, font->glyph.img->handler->w, font->glyph.img->handler->h, font->glyph.img->w, font->glyph.img->h, font->glyph.img->rgba, font->glyph.img->handler->x, font->glyph.img->handler->y); s_font_uninit(font); } s_putbox(wsurface, rect->x, rect->y, rect->w, rect->h, surface->vbuf); s_surface_destroy(surface); return 0; }