struct label* creer_label(const char* text, int x, int y, enum Align align, enum FontSize size) { struct label* label = gosh_alloc(*label); label->surface = text_surface(text, size); label->x = x; label->y = y; label->w = label->surface->w; label->h = label->surface->h; label->align = align; label->couleur = get_color(); label->visible = true; return label; }
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size, const SDL_Color& colour, const std::string& text, int x, int y, bool use_tooltips, int style) { if (gui_surface.null()) { text_surface const &u = text_cache::find(text_surface(text, size, colour, style)); SDL_Rect res = {0, 0, u.width(), u.height()}; return res; } if(area.w == 0) { // no place to draw SDL_Rect res = {0,0,0,0}; return res; } const std::string etext = make_text_ellipsis(text, size, area.w); // for the main current use, we already parsed markup surface surface(render_text(etext,size,colour,style,false)); if(surface == NULL) { SDL_Rect res = {0,0,0,0}; return res; } SDL_Rect dest; if(x!=-1) { dest.x = x; #ifdef HAVE_FRIBIDI // Oron -- Conditional, until all draw_text_line calls have fixed area parameter if(getenv("NO_RTL") == NULL) { bool is_rtl = text_cache::find(text_surface(text, size, colour, style)).is_rtl(); if(is_rtl) dest.x = area.x + area.w - surface->w - (x - area.x); } #endif } else dest.x = (area.w/2)-(surface->w/2); if(y!=-1) dest.y = y; else dest.y = (area.h/2)-(surface->h/2); dest.w = surface->w; dest.h = surface->h; if(line_width(text, size) > area.w) { tooltips::add_tooltip(dest,text); } if(dest.x + dest.w > area.x + area.w) { dest.w = area.x + area.w - dest.x; } if(dest.y + dest.h > area.y + area.h) { dest.h = area.y + area.h - dest.y; } if(gui_surface != NULL) { SDL_Rect src = dest; src.x = 0; src.y = 0; SDL_BlitSurface(surface,&src,gui_surface,&dest); } if(use_tooltips) { tooltips::add_tooltip(dest,text); } return dest; }
void Dialog::drawText() { // Black SDL_Color color = {0x33, 0x33, 0x33}; TTF_Font* font = ResourceLoader::GetInstance()->getFont("Vera.ttf", 17); Uint16 margin = 10; // Determine the maximum number of lines which can be displayed in this // Dialog box.. Uint16 fontHeight = TTF_FontHeight(font); Uint16 maxLines = (this->getHeight() - margin)/ fontHeight; // Stick a space on the end of the renderable text so that we can easily // count the number of words in the string. std::string remainingText = this->text; // Render Each Line Onto the Dialog Box. Uint16 lineNum = 0; while (lineNum < maxLines && remainingText != "") { // Get the next line of output and chop it off the remaining text. Uint16 maxWidth = this->getWidth() - margin; std::string line = this->getNextLine(remainingText, font, maxWidth); // Build the text surface containing the given string. std::unique_ptr<SDL_Surface, SDLSurfaceDeleter> text_surface( TTF_RenderText_Solid( font , line.c_str() , color ) , SDLSurfaceDeleter() ); // If the surface is not created successfully. if (text_surface == nullptr) { LOG(INFO) << this->text.c_str(); LOG(ERROR) << "Error creating text: " << TTF_GetError(); exit(1); } else { // Create a destination rectangle based on the created text surface and // the position parameter. SDL_Rect r; r.w = text_surface->w; r.h = text_surface->h; r.x = margin; r.y = lineNum * fontHeight + margin; // Blit the text to the screen. SDL_BlitSurface(text_surface.get(), NULL, getTempSurf().get(), &r); } lineNum++; } // TODO: // This method needs to return whatever it decided not to display due to // wrapping constraints. }