From 1fe397ed7173aacd6376468b2b50ef55e99b69b9 Mon Sep 17 00:00:00 2001 From: "Hj. Malthaner" <62077919+Varkalandar@users.noreply.github> Date: Mon, 13 Feb 2023 23:39:14 +0100 Subject: [PATCH] NEW: Routines to draw proper bold text. --- src/simutrans/display/display.cc | 249 ++++++++++++++ src/simutrans/display/display.h | 24 ++ src/simutrans/display/simgraph.h | 23 +- src/simutrans/display/simgraph16.cc | 318 +++--------------- src/simutrans/ground/grund.cc | 1 + src/simutrans/gui/banner.cc | 1 + src/simutrans/gui/components/gui_button.cc | 1 + src/simutrans/gui/components/gui_chart.cc | 1 + .../gui/components/gui_fixedwidth_textarea.cc | 5 +- src/simutrans/gui/components/gui_flowtext.cc | 1 + .../gui/components/gui_image_list.cc | 1 + src/simutrans/gui/components/gui_label.cc | 9 +- .../gui/components/gui_scrolled_list.cc | 7 +- src/simutrans/gui/components/gui_tab_panel.cc | 1 + src/simutrans/gui/components/gui_textarea.cc | 7 +- src/simutrans/gui/components/gui_textinput.cc | 9 +- src/simutrans/gui/minimap.cc | 1 + src/simutrans/gui/pakselector.cc | 6 +- src/simutrans/gui/simwin.cc | 3 +- src/simutrans/gui/vehiclelist_frame.cc | 1 + src/simutrans/player/simplay.cc | 3 +- src/simutrans/simloadingscreen.cc | 1 + src/simutrans/simticker.cc | 1 + src/simutrans/tool/simtool.cc | 1 + src/simutrans/vehicle/vehicle.cc | 1 + 25 files changed, 367 insertions(+), 309 deletions(-) diff --git a/src/simutrans/display/display.cc b/src/simutrans/display/display.cc index 8750fee32..93f13119c 100644 --- a/src/simutrans/display/display.cc +++ b/src/simutrans/display/display.cc @@ -9,9 +9,13 @@ * simgraph??.cc */ +#include #include "simgraph.h" #include "display.h" +#include "../sys/simsys.h" +#include "../dataobj/translator.h" + void display_bevel_box(scr_rect area, PIXVAL top, PIXVAL left, PIXVAL right, PIXVAL bottom, @@ -23,3 +27,248 @@ void display_bevel_box(scr_rect area, display_fillbox_wh_clip_rgb(area.x, area.y, area.w, 1, top, dirty); display_fillbox_wh_clip_rgb(area.x+1, area.y+area.h-1, area.w-1, 1, bottom, dirty); } + + +static PIXVAL handle_color_sequences(utf32 code, PIXVAL default_color) +{ + PIXVAL color; + + if(code == 'd') { + color = default_color; + } else { + color = get_system_color(255, 255, 255); + } + + return color; +} + + +/** + * len parameter added - use -1 for previous behaviour. + * completely renovated for unicode and 10 bit width and variable height + */ +int display_text_proportional_len_clip_rgb(scr_coord_val x, scr_coord_val y, + const char* txt, control_alignment_t flags, + const PIXVAL default_color, bool dirty, + sint32 len, sint32 spacing CLIP_NUM_DEF) +{ + PIXVAL color = default_color; + + if (len < 0) { + // don't know len yet + len = 0x7FFF; + } + + // adapt x-coordinate for alignment + switch (flags & ( ALIGN_LEFT | ALIGN_CENTER_H | ALIGN_RIGHT) ) { + case ALIGN_LEFT: + // nothing to do + break; + + case ALIGN_CENTER_H: + x -= display_calc_proportional_string_len_width(txt, len, spacing) / 2; + break; + + case ALIGN_RIGHT: + x -= display_calc_proportional_string_len_width(txt, len, spacing); + break; + } + + + // store the initial x (for dirty marking) + const scr_coord_val x0 = x; + + // big loop, draw char by char + utf8_decoder_t decoder((utf8 const*)txt); + size_t iTextPos = 0; // pointer on text position + + while (iTextPos < (size_t)len && decoder.has_next()) { + // decode char + utf32 c = decoder.next(); + iTextPos = decoder.get_position() - (utf8 const*)txt; + + if(c == '\n') { + // stop at linebreak + break; + } + + if(c == '\t') { + int tabsize = BASE_TAB_WIDTH * LINESPACE / 11; + // advance to next tab stop + int p = (x - x0) % tabsize; + x = x - p + tabsize; + continue; // nothing to see + } + + if(c == '\e') { + if(decoder.has_next()) { + utf32 c2 = decoder.next(); + color = handle_color_sequences(c2, default_color); + } + continue; // nothing to see + } + + const int gw = display_glyph(x, y, c, flags, color); + x += gw + spacing; + } + + if( dirty ) { + // here, because only now we know the length also for ALIGN_LEFT text + mark_rect_dirty_clip( x0, y, x - 1, y + LINESPACE - 1 CLIP_NUM_PAR); + } + + // warning: actual len might be longer, due to clipping! + return x - x0; +} + + +/// Displays a string which is abbreviated by the (language specific) ellipsis character if too wide +/// If enough space is given then it just displays the full string +void display_proportional_ellipsis_rgb( scr_rect r, const char *text, int align, const PIXVAL color, const bool dirty, bool shadowed, PIXVAL shadow_color) +{ + const scr_coord_val ellipsis_width = translator::get_lang()->ellipsis_width; + const scr_coord_val max_screen_width = r.w; + size_t max_idx = 0; + + uint8 byte_length = 0; + uint8 pixel_width = 0; + scr_coord_val current_offset = 0; + + if( align & ALIGN_CENTER_V ) { + r.y += (r.h - LINESPACE)/2; + align &= ~ALIGN_CENTER_V; + } + + const char *tmp_text = text; + while( get_next_char_with_metrics(tmp_text, byte_length, pixel_width) && max_screen_width >= (current_offset+ellipsis_width+pixel_width) ) { + current_offset += pixel_width; + max_idx += byte_length; + } + size_t max_idx_before_ellipsis = max_idx; + scr_coord_val max_offset_before_ellipsis = current_offset; + + // now check if the text would fit completely + if( ellipsis_width && pixel_width > 0 ) { + // only when while above failed because of exceeding length + current_offset += pixel_width; + max_idx += byte_length; + // check the rest ... + while( get_next_char_with_metrics(tmp_text, byte_length, pixel_width) && max_screen_width >= (current_offset+pixel_width) ) { + current_offset += pixel_width; + max_idx += byte_length; + } + // if it does not fit + if( max_screen_width < (current_offset+pixel_width) ) { + scr_coord_val w = 0; + // since we know the length already, we try to center the text with the remaining pixels of the last character + if( align & ALIGN_CENTER_H ) { + w = (max_screen_width-max_offset_before_ellipsis-ellipsis_width)/2; + } + if (shadowed) { + display_text_proportional_len_clip_rgb( r.x+w+1, r.y+1, text, ALIGN_LEFT | DT_CLIP, shadow_color, dirty, max_idx_before_ellipsis CLIP_NUM_DEFAULT); + } + w += display_text_proportional_len_clip_rgb( r.x+w, r.y, text, ALIGN_LEFT | DT_CLIP, color, dirty, max_idx_before_ellipsis CLIP_NUM_DEFAULT); + + if (shadowed) { + display_text_proportional_len_clip_rgb( r.x+w+1, r.y+1, translator::translate("..."), ALIGN_LEFT | DT_CLIP, shadow_color, dirty, -1 CLIP_NUM_DEFAULT); + } + + display_text_proportional_len_clip_rgb( r.x+w, r.y, translator::translate("..."), ALIGN_LEFT | DT_CLIP, color, dirty, -1 CLIP_NUM_DEFAULT); + return; + } + else { + // if this fits, end of string + max_idx += byte_length; + current_offset += pixel_width; + } + } + switch (align & ALIGN_RIGHT) { + case ALIGN_CENTER_H: + r.x += (max_screen_width - current_offset)/2; + break; + case ALIGN_RIGHT: + r.x += max_screen_width - current_offset; + default: ; + } + if (shadowed) { + display_text_proportional_len_clip_rgb( r.x+1, r.y+1, text, ALIGN_LEFT | DT_CLIP, shadow_color, dirty, -1 CLIP_NUM_DEFAULT); + } + display_text_proportional_len_clip_rgb( r.x, r.y, text, ALIGN_LEFT | DT_CLIP, color, dirty, -1 CLIP_NUM_DEFAULT); +} + + +/** + * display text in 3d box with clipping + */ +void display_ddd_proportional_clip(scr_coord_val xpos, scr_coord_val ypos, FLAGGED_PIXVAL ddd_color, FLAGGED_PIXVAL text_color, const char *text, int dirty CLIP_NUM_DEF) +{ + const int vpadding = LINESPACE / 7; + const int hpadding = LINESPACE / 4; + + scr_coord_val width = proportional_string_width(text); + + PIXVAL lighter = display_blend_colors(ddd_color, color_idx_to_rgb(COL_WHITE), 25); + PIXVAL darker = display_blend_colors(ddd_color, color_idx_to_rgb(COL_BLACK), 25); + + display_fillbox_wh_clip_rgb( xpos+1, ypos - vpadding + 1, width+2*hpadding-2, LINESPACE+2*vpadding-1, ddd_color, dirty CLIP_NUM_PAR); + + display_fillbox_wh_clip_rgb( xpos, ypos - vpadding, width + 2*hpadding - 2, 1, lighter, dirty ); + display_fillbox_wh_clip_rgb( xpos, ypos + LINESPACE + vpadding, width + 2*hpadding - 2, 1, darker, dirty ); + + display_vline_wh_clip_rgb( xpos, ypos - vpadding, LINESPACE + vpadding * 2, lighter, dirty ); + display_vline_wh_clip_rgb( xpos + width + 2*hpadding - 2, ypos - vpadding, LINESPACE + vpadding * 2, darker, dirty ); + + display_text_proportional_len_clip_rgb( xpos+hpadding, ypos+1, text, ALIGN_LEFT | DT_CLIP, text_color, dirty, -1, 0); +} + + +/** + * Draw multiline text + */ +int display_multiline_text_rgb(scr_coord_val x, scr_coord_val y, const char *buf, PIXVAL color) +{ + int max_px_len = 0; + if (buf != NULL && *buf != '\0') { + const char *next; + + do { + next = strchr(buf, '\n'); + const int px_len = display_text_proportional_len_clip_rgb( + x, y, buf, + ALIGN_LEFT | DT_CLIP, color, true, + next != NULL ? (int)(size_t)(next - buf) : -1, + 0); + + if( px_len>max_px_len ) { + max_px_len = px_len; + } + y += LINESPACE; + } while ((void)(buf = (next ? next+1 : NULL)), buf != NULL); + } + return max_px_len; +} + + +void display_outline_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len) +{ + const int flags = ALIGN_LEFT | DT_CLIP; + display_text_proportional_len_clip_rgb(xpos - 1, ypos , text, flags, shadow_color, dirty, len, 0 CLIP_NUM_DEFAULT); + display_text_proportional_len_clip_rgb(xpos + 1, ypos + 2, text, flags, shadow_color, dirty, len, 0 CLIP_NUM_DEFAULT); + display_text_proportional_len_clip_rgb(xpos, ypos + 1, text, flags, text_color, dirty, len, 0 CLIP_NUM_DEFAULT); +} + + +void display_shadow_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len) +{ + const int flags = ALIGN_LEFT | DT_CLIP; + display_text_proportional_len_clip_rgb(xpos + 1, ypos + 1 + (12 - LINESPACE) / 2, text, flags, shadow_color, dirty, len, 0 CLIP_NUM_DEFAULT); + display_text_proportional_len_clip_rgb(xpos, ypos + (12 - LINESPACE) / 2, text, flags, text_color, dirty, len, 0 CLIP_NUM_DEFAULT); +} + +int display_text_bold(scr_coord_val xpos, scr_coord_val ypos, PIXVAL color, const char *text, int dirty, sint32 len) +{ + const int flags = ALIGN_LEFT | DT_CLIP; + display_text_proportional_len_clip_rgb(xpos, ypos, text, flags, color, dirty, len, 1 CLIP_NUM_DEFAULT); + int width = display_text_proportional_len_clip_rgb(xpos+1, ypos, text, flags, color, dirty, len, 1 CLIP_NUM_DEFAULT); + return width + 1; +} diff --git a/src/simutrans/display/display.h b/src/simutrans/display/display.h index 9a569cf03..4e22c1995 100644 --- a/src/simutrans/display/display.h +++ b/src/simutrans/display/display.h @@ -30,5 +30,29 @@ void display_bevel_box(scr_rect area, bool dirty); + +int display_text_proportional_len_clip_rgb(scr_coord_val x, scr_coord_val y, const char* txt, control_alignment_t flags, const PIXVAL color, bool dirty, sint32 len, sint32 spacing CLIP_NUM_DEF CLIP_NUM_DEFAULT_ZERO); +/* macro are for compatibility */ +#define display_proportional_rgb( x, y, txt, align, color, dirty) display_text_proportional_len_clip_rgb( x, y, txt, align, color, dirty, -1, 0 ) +#define display_proportional_clip_rgb( x, y, txt, align, color, dirty) display_text_proportional_len_clip_rgb( x, y, txt, align | DT_CLIP, color, dirty, -1, 0 ) + + +/// Display a string that is abbreviated by the (language specific) ellipsis character if too wide +/// If enough space is given, it just display the full string +void display_proportional_ellipsis_rgb( scr_rect r, const char *text, int align, const PIXVAL color, const bool dirty, bool shadowed = false, PIXVAL shadow_color = 0 ); + + +/** + * display text in 3d box with clipping + */ +void display_ddd_proportional_clip(scr_coord_val xpos, scr_coord_val ypos, FLAGGED_PIXVAL ddd_farbe, FLAGGED_PIXVAL text_farbe, const char *text, int dirty CLIP_NUM_DEF CLIP_NUM_DEFAULT_ZERO); + + +int display_multiline_text_rgb(scr_coord_val x, scr_coord_val y, const char *inbuf, PIXVAL color); + +void display_outline_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len=-1); +void display_shadow_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len=-1); +int display_text_bold(scr_coord_val xpos, scr_coord_val ypos, PIXVAL color, const char *text, int dirty, sint32 len=-1); + #endif /* SIM_DISPLAY_H */ diff --git a/src/simutrans/display/simgraph.h b/src/simutrans/display/simgraph.h index b557cbc25..dd3c21474 100644 --- a/src/simutrans/display/simgraph.h +++ b/src/simutrans/display/simgraph.h @@ -28,6 +28,7 @@ extern int default_font_linespace; # define LINESPACE 1 #endif +#define BASE_TAB_WIDTH (40) /** * Alignment enum to align controls against each other. @@ -259,8 +260,6 @@ void display_show_load_pointer(int loading); void display_array_wh(scr_coord_val xp, scr_coord_val yp, scr_coord_val w, scr_coord_val h, const PIXVAL *arr); // compound painting routines -void display_outline_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len=-1); -void display_shadow_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len=-1); void display_ddd_box_rgb(scr_coord_val x1, scr_coord_val y1, scr_coord_val w, scr_coord_val h, PIXVAL tl_color, PIXVAL rd_color, bool dirty); void display_ddd_box_clip_rgb(scr_coord_val x1, scr_coord_val y1, scr_coord_val w, scr_coord_val h, PIXVAL tl_color, PIXVAL rd_color); @@ -304,11 +303,11 @@ utf32 get_prev_char_with_metrics(const char* &text, const char *const text_start size_t display_fit_proportional( const char *text, scr_coord_val max_width, scr_coord_val ellipsis_width=0 ); /* routines for string len (macros for compatibility with old calls) */ -#define proportional_string_width(text) display_calc_proportional_string_len_width(text, 0x7FFF) -#define proportional_string_len_width(text, len) display_calc_proportional_string_len_width(text, len) +#define proportional_string_width(text) display_calc_proportional_string_len_width(text, 0x7FFF, 0) +#define proportional_string_len_width(text, len) display_calc_proportional_string_len_width(text, len, 0) // length of a string in pixel -int display_calc_proportional_string_len_width(const char* text, size_t len); +int display_calc_proportional_string_len_width(const char* text, size_t len, int spacing); // box which will contain the multi (or single) line of text void display_calc_proportional_multiline_string_len_width( int &xw, int &yh, const char *text, size_t len ); @@ -319,21 +318,9 @@ void display_calc_proportional_multiline_string_len_width( int &xw, int &yh, con */ // #ifdef MULTI_THREAD -int display_text_proportional_len_clip_rgb(scr_coord_val x, scr_coord_val y, const char* txt, control_alignment_t flags, const PIXVAL color, bool dirty, sint32 len CLIP_NUM_DEF CLIP_NUM_DEFAULT_ZERO); -/* macro are for compatibility */ -#define display_proportional_rgb( x, y, txt, align, color, dirty) display_text_proportional_len_clip_rgb( x, y, txt, align, color, dirty, -1 ) -#define display_proportional_clip_rgb( x, y, txt, align, color, dirty) display_text_proportional_len_clip_rgb( x, y, txt, align | DT_CLIP, color, dirty, -1 ) +int display_glyph(scr_coord_val x, scr_coord_val y, utf32 c, control_alignment_t flags, PIXVAL default_color CLIP_NUM_DEF CLIP_NUM_DEFAULT_ZERO); -/// Display a string that is abbreviated by the (language specific) ellipsis character if too wide -/// If enough space is given, it just display the full string -void display_proportional_ellipsis_rgb( scr_rect r, const char *text, int align, const PIXVAL color, const bool dirty, bool shadowed = false, PIXVAL shadow_color = 0 ); - -void display_ddd_proportional_clip(scr_coord_val xpos, scr_coord_val ypos, FLAGGED_PIXVAL ddd_farbe, FLAGGED_PIXVAL text_farbe, const char *text, int dirty CLIP_NUM_DEF CLIP_NUM_DEFAULT_ZERO); - - -int display_multiline_text_rgb(scr_coord_val x, scr_coord_val y, const char *inbuf, PIXVAL color); - // line drawing primitives void display_direct_line_rgb(const scr_coord_val x, const scr_coord_val y, const scr_coord_val xx, const scr_coord_val yy, const PIXVAL color); void display_direct_line_dotted_rgb(const scr_coord_val x, const scr_coord_val y, const scr_coord_val xx, const scr_coord_val yy, const scr_coord_val draw, const scr_coord_val dontDraw, const PIXVAL color); diff --git a/src/simutrans/display/simgraph16.cc b/src/simutrans/display/simgraph16.cc index d4d0bff95..fca836d62 100644 --- a/src/simutrans/display/simgraph16.cc +++ b/src/simutrans/display/simgraph16.cc @@ -19,7 +19,6 @@ #include "../simdebug.h" #include "../descriptor/image.h" #include "../dataobj/environment.h" -#include "../dataobj/translator.h" #include "../utils/unicode.h" #include "../simticker.h" #include "../utils/simstring.h" @@ -4651,7 +4650,7 @@ utf32 get_prev_char_with_metrics(const char* &text, const char *const text_start /* proportional_string_width with a text of a given length * extended for universal font routines with unicode support */ -int display_calc_proportional_string_len_width(const char *text, size_t len) +int display_calc_proportional_string_len_width(const char *text, size_t len, int spacing) { const font_t* const fnt = &default_font; unsigned int width = 0; @@ -4664,7 +4663,7 @@ int display_calc_proportional_string_len_width(const char *text, size_t len) text = reinterpret_cast(p); if(iUnicode == '\t') { - int tabsize = 40 * LINESPACE / 11; + int tabsize = BASE_TAB_WIDTH * LINESPACE / 11; // advance to next tab stop int p = width % tabsize; width = (width - p) + tabsize; @@ -4675,7 +4674,7 @@ int display_calc_proportional_string_len_width(const char *text, size_t len) if( iUnicode == UNICODE_NUL || iUnicode == '\n') { return width; } - width += fnt->get_glyph_advance(iUnicode); + width += fnt->get_glyph_advance(iUnicode) + spacing; } return width; @@ -4718,28 +4717,17 @@ void display_calc_proportional_multiline_string_len_width(int &xw, int &yh, cons } - -static PIXVAL handle_color_sequences(utf32 code, PIXVAL default_color) +int display_glyph(scr_coord_val x, scr_coord_val y, utf32 c, control_alignment_t flags, PIXVAL default_color CLIP_NUM_DEF) { - PIXVAL color; - - if(code == 'd') { - color = default_color; - } else { - color = get_system_color(255, 255, 255); + const font_t *const fnt = &default_font; + PIXVAL color = default_color; + + // print unknown character? + if(!fnt->is_valid_glyph(c)) { + // nothing to see here, move on + return 0; } - return color; -} - - -/** - * len parameter added - use -1 for previous behaviour. - * completely renovated for unicode and 10 bit width and variable height - */ -int display_text_proportional_len_clip_rgb(scr_coord_val x, scr_coord_val y, const char* txt, control_alignment_t flags, const PIXVAL default_color, bool dirty, sint32 len CLIP_NUM_DEF) -{ - PIXVAL color = default_color; scr_coord_val cL, cR, cT, cB; // TAKE CARE: Clipping area may be larger than actual screen size @@ -4756,196 +4744,54 @@ int display_text_proportional_len_clip_rgb(scr_coord_val x, scr_coord_val y, con cB = disp_height; } - if (len < 0) { - // don't know len yet - len = 0x7FFF; - } - - // adapt x-coordinate for alignment - switch (flags & ( ALIGN_LEFT | ALIGN_CENTER_H | ALIGN_RIGHT) ) { - case ALIGN_LEFT: - // nothing to do - break; - - case ALIGN_CENTER_H: - x -= display_calc_proportional_string_len_width(txt, len) / 2; - break; - - case ALIGN_RIGHT: - x -= display_calc_proportional_string_len_width(txt, len); - break; - } - // still something to display? - const font_t *const fnt = &default_font; if (x >= cR || y >= cB || y + fnt->get_linespace() <= cT) { // nothing to display return 0; - } - - // store the initial x (for dirty marking) - const scr_coord_val x0 = x; - - // big loop, draw char by char - utf8_decoder_t decoder((utf8 const*)txt); - size_t iTextPos = 0; // pointer on text position - - while (iTextPos < (size_t)len && decoder.has_next()) { - // decode char - utf32 c = decoder.next(); - iTextPos = decoder.get_position() - (utf8 const*)txt; - - if(c == '\n') { - // stop at linebreak - break; - } - - if(c == '\t') { - int tabsize = 40 * LINESPACE / 11; - // advance to next tab stop - int p = (x - x0) % tabsize; - x = x - p + tabsize; - continue; // nothing to see - } - - if(c == '\e') { - if(decoder.has_next()) { - utf32 c2 = decoder.next(); - color = handle_color_sequences(c2, default_color); - } - continue; // nothing to see - } - - // print unknown character? - else if(!fnt->is_valid_glyph(c)) { - c = 0; - } - - // get the data from the font - const int glyph_width = fnt->get_glyph_width(c); - const int glyph_height = fnt->get_glyph_height(c); - const int glyph_top = fnt->get_glyph_top(c); - const uint8 *p = fnt->get_glyph_bitmap(c); - - int screen_pos = (y + glyph_top) * disp_width + x; - - // glyph x clipping - int g_left = max(cL - x, 0); - int g_right = x + glyph_width < cR ? glyph_width : cR - x; - - // all visible rows - for (int h = 0; h < glyph_height; h++) { - const int line = y + h + glyph_top; - if(line >= cT && line < cB) { - - PIXVAL* dst = textur + screen_pos; + } + - // all columns - for(int gx=g_left; gx 90) { - // opaque - new_color = color; - } else { - // partially transparent -> blend it - PIXVAL old_color = *dst; - new_color = display_blend_colors(old_color, color, alpha); - } - - *dst++ = new_color; + // get the data from the font + const int glyph_width = fnt->get_glyph_width(c); + const int glyph_height = fnt->get_glyph_height(c); + const int glyph_top = fnt->get_glyph_top(c); + const uint8 *p = fnt->get_glyph_bitmap(c); + + int screen_pos = (y + glyph_top) * disp_width + x; + + // glyph x clipping + int g_left = max(cL - x, 0); + int g_right = x + glyph_width < cR ? glyph_width : cR - x; + + // all visible rows + for (int h = 0; h < glyph_height; h++) { + const int line = y + h + glyph_top; + if(line >= cT && line < cB) { + + PIXVAL* dst = textur + screen_pos; + + // all columns + for(int gx=g_left; gx 90) { + // opaque + new_color = color; + } else { + // partially transparent -> blend it + PIXVAL old_color = *dst; + new_color = display_blend_colors(old_color, color, alpha); } - screen_pos += disp_width; - } - } - - x += fnt->get_glyph_advance(c); - } - - if( dirty ) { - // here, because only now we know the length also for ALIGN_LEFT text - mark_rect_dirty_clip( x0, y, x - 1, y + LINESPACE - 1 CLIP_NUM_PAR); - } - - // warning: actual len might be longer, due to clipping! - return x - x0; -} - - -/// Displays a string which is abbreviated by the (language specific) ellipsis character if too wide -/// If enough space is given then it just displays the full string -void display_proportional_ellipsis_rgb( scr_rect r, const char *text, int align, const PIXVAL color, const bool dirty, bool shadowed, PIXVAL shadow_color) -{ - const scr_coord_val ellipsis_width = translator::get_lang()->ellipsis_width; - const scr_coord_val max_screen_width = r.w; - size_t max_idx = 0; - - uint8 byte_length = 0; - uint8 pixel_width = 0; - scr_coord_val current_offset = 0; - - if( align & ALIGN_CENTER_V ) { - r.y += (r.h - LINESPACE)/2; - align &= ~ALIGN_CENTER_V; - } - - const char *tmp_text = text; - while( get_next_char_with_metrics(tmp_text, byte_length, pixel_width) && max_screen_width >= (current_offset+ellipsis_width+pixel_width) ) { - current_offset += pixel_width; - max_idx += byte_length; - } - size_t max_idx_before_ellipsis = max_idx; - scr_coord_val max_offset_before_ellipsis = current_offset; - // now check if the text would fit completely - if( ellipsis_width && pixel_width > 0 ) { - // only when while above failed because of exceeding length - current_offset += pixel_width; - max_idx += byte_length; - // check the rest ... - while( get_next_char_with_metrics(tmp_text, byte_length, pixel_width) && max_screen_width >= (current_offset+pixel_width) ) { - current_offset += pixel_width; - max_idx += byte_length; - } - // if it does not fit - if( max_screen_width < (current_offset+pixel_width) ) { - scr_coord_val w = 0; - // since we know the length already, we try to center the text with the remaining pixels of the last character - if( align & ALIGN_CENTER_H ) { - w = (max_screen_width-max_offset_before_ellipsis-ellipsis_width)/2; - } - if (shadowed) { - display_text_proportional_len_clip_rgb( r.x+w+1, r.y+1, text, ALIGN_LEFT | DT_CLIP, shadow_color, dirty, max_idx_before_ellipsis CLIP_NUM_DEFAULT); - } - w += display_text_proportional_len_clip_rgb( r.x+w, r.y, text, ALIGN_LEFT | DT_CLIP, color, dirty, max_idx_before_ellipsis CLIP_NUM_DEFAULT); - - if (shadowed) { - display_text_proportional_len_clip_rgb( r.x+w+1, r.y+1, translator::translate("..."), ALIGN_LEFT | DT_CLIP, shadow_color, dirty, -1 CLIP_NUM_DEFAULT); + *dst++ = new_color; } - - display_text_proportional_len_clip_rgb( r.x+w, r.y, translator::translate("..."), ALIGN_LEFT | DT_CLIP, color, dirty, -1 CLIP_NUM_DEFAULT); - return; + screen_pos += disp_width; } - else { - // if this fits, end of string - max_idx += byte_length; - current_offset += pixel_width; - } - } - switch (align & ALIGN_RIGHT) { - case ALIGN_CENTER_H: - r.x += (max_screen_width - current_offset)/2; - break; - case ALIGN_RIGHT: - r.x += max_screen_width - current_offset; - default: ; } - if (shadowed) { - display_text_proportional_len_clip_rgb( r.x+1, r.y+1, text, ALIGN_LEFT | DT_CLIP, shadow_color, dirty, -1 CLIP_NUM_DEFAULT); - } - display_text_proportional_len_clip_rgb( r.x, r.y, text, ALIGN_LEFT | DT_CLIP, color, dirty, -1 CLIP_NUM_DEFAULT); + + return fnt->get_glyph_advance(c); } @@ -4964,23 +4810,6 @@ void display_ddd_box_rgb(scr_coord_val x1, scr_coord_val y1, scr_coord_val w, sc } -void display_outline_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len) -{ - const int flags = ALIGN_LEFT | DT_CLIP; - display_text_proportional_len_clip_rgb(xpos - 1, ypos , text, flags, shadow_color, dirty, len CLIP_NUM_DEFAULT); - display_text_proportional_len_clip_rgb(xpos + 1, ypos + 2, text, flags, shadow_color, dirty, len CLIP_NUM_DEFAULT); - display_text_proportional_len_clip_rgb(xpos, ypos + 1, text, flags, text_color, dirty, len CLIP_NUM_DEFAULT); -} - - -void display_shadow_proportional_rgb(scr_coord_val xpos, scr_coord_val ypos, PIXVAL text_color, PIXVAL shadow_color, const char *text, int dirty, sint32 len) -{ - const int flags = ALIGN_LEFT | DT_CLIP; - display_text_proportional_len_clip_rgb(xpos + 1, ypos + 1 + (12 - LINESPACE) / 2, text, flags, shadow_color, dirty, len CLIP_NUM_DEFAULT); - display_text_proportional_len_clip_rgb(xpos, ypos + (12 - LINESPACE) / 2, text, flags, text_color, dirty, len CLIP_NUM_DEFAULT); -} - - /** * Draw shaded rectangle using direct color values */ @@ -4996,57 +4825,6 @@ void display_ddd_box_clip_rgb(scr_coord_val x1, scr_coord_val y1, scr_coord_val } -/** - * display text in 3d box with clipping - */ -void display_ddd_proportional_clip(scr_coord_val xpos, scr_coord_val ypos, FLAGGED_PIXVAL ddd_color, FLAGGED_PIXVAL text_color, const char *text, int dirty CLIP_NUM_DEF) -{ - const int vpadding = LINESPACE / 7; - const int hpadding = LINESPACE / 4; - - scr_coord_val width = proportional_string_width(text); - - PIXVAL lighter = display_blend_colors(ddd_color, color_idx_to_rgb(COL_WHITE), 25); - PIXVAL darker = display_blend_colors(ddd_color, color_idx_to_rgb(COL_BLACK), 25); - - display_fillbox_wh_clip_rgb( xpos+1, ypos - vpadding + 1, width+2*hpadding-2, LINESPACE+2*vpadding-1, ddd_color, dirty CLIP_NUM_PAR); - - display_fillbox_wh_clip_rgb( xpos, ypos - vpadding, width + 2*hpadding - 2, 1, lighter, dirty ); - display_fillbox_wh_clip_rgb( xpos, ypos + LINESPACE + vpadding, width + 2*hpadding - 2, 1, darker, dirty ); - - display_vline_wh_clip_rgb( xpos, ypos - vpadding, LINESPACE + vpadding * 2, lighter, dirty ); - display_vline_wh_clip_rgb( xpos + width + 2*hpadding - 2, ypos - vpadding, LINESPACE + vpadding * 2, darker, dirty ); - - display_text_proportional_len_clip_rgb( xpos+hpadding, ypos+1, text, ALIGN_LEFT | DT_CLIP, text_color, dirty, -1); -} - - -/** - * Draw multiline text - */ -int display_multiline_text_rgb(scr_coord_val x, scr_coord_val y, const char *buf, PIXVAL color) -{ - int max_px_len = 0; - if (buf != NULL && *buf != '\0') { - const char *next; - - do { - next = strchr(buf, '\n'); - const int px_len = display_text_proportional_len_clip_rgb( - x, y, buf, - ALIGN_LEFT | DT_CLIP, color, true, - next != NULL ? (int)(size_t)(next - buf) : -1 - ); - if( px_len>max_px_len ) { - max_px_len = px_len; - } - y += LINESPACE; - } while ((void)(buf = (next ? next+1 : NULL)), buf != NULL); - } - return max_px_len; -} - - /** * draw line from x,y to xx,yy **/ diff --git a/src/simutrans/ground/grund.cc b/src/simutrans/ground/grund.cc index 07f27e4e4..84012e692 100644 --- a/src/simutrans/ground/grund.cc +++ b/src/simutrans/ground/grund.cc @@ -11,6 +11,7 @@ #include "../simskin.h" #include "../obj/depot.h" #include "../display/simgraph.h" +#include "../display/display.h" #include "../display/viewport.h" #include "../simhalt.h" #include "../display/simimg.h" diff --git a/src/simutrans/gui/banner.cc b/src/simutrans/gui/banner.cc index debdfab62..971209e31 100644 --- a/src/simutrans/gui/banner.cc +++ b/src/simutrans/gui/banner.cc @@ -11,6 +11,7 @@ #include "../sys/simsys.h" #include "../simversion.h" #include "../display/simgraph.h" +#include "../display/display.h" #include "../macros.h" #include "../descriptor/skin_desc.h" #include "../dataobj/environment.h" diff --git a/src/simutrans/gui/components/gui_button.cc b/src/simutrans/gui/components/gui_button.cc index 6a6f26a13..acc9c5f82 100644 --- a/src/simutrans/gui/components/gui_button.cc +++ b/src/simutrans/gui/components/gui_button.cc @@ -11,6 +11,7 @@ #include "../../simcolor.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../simevent.h" #include "../simwin.h" diff --git a/src/simutrans/gui/components/gui_chart.cc b/src/simutrans/gui/components/gui_chart.cc index 9e99d0d1c..2ef78068f 100644 --- a/src/simutrans/gui/components/gui_chart.cc +++ b/src/simutrans/gui/components/gui_chart.cc @@ -13,6 +13,7 @@ #include "../../utils/simstring.h" #include "../../dataobj/environment.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../gui_theme.h" static char tooltip[64]; diff --git a/src/simutrans/gui/components/gui_fixedwidth_textarea.cc b/src/simutrans/gui/components/gui_fixedwidth_textarea.cc index fb7fd35d5..89f3bf190 100644 --- a/src/simutrans/gui/components/gui_fixedwidth_textarea.cc +++ b/src/simutrans/gui/components/gui_fixedwidth_textarea.cc @@ -9,6 +9,7 @@ #include "gui_fixedwidth_textarea.h" #include "../../dataobj/translator.h" #include "../../utils/cbuffer.h" +#include "../../display/display.h" @@ -95,7 +96,7 @@ scr_size gui_fixedwidth_textarea_t::calc_display_text(const scr_coord offset, co next = strchr(buf, '\n'); const size_t len = next ? next - buf : 99999; // we are in the image area - const int px_len = display_calc_proportional_string_len_width(buf, len) + reserved_area.w; + const int px_len = display_calc_proportional_string_len_width(buf, len, 0) + reserved_area.w; if (px_len > x_size) { x_size = px_len; @@ -161,7 +162,7 @@ scr_size gui_fixedwidth_textarea_t::calc_display_text(const scr_coord offset, co // start of new line or end of text if(draw && (line_end-line_start)!=0) { - display_text_proportional_len_clip_rgb( offset.x, offset.y+y, (const char *)line_start, ALIGN_LEFT | DT_CLIP, SYSCOL_TEXT, true, (size_t)(line_end - line_start) ); + display_text_proportional_len_clip_rgb(offset.x, offset.y+y, (const char *)line_start, ALIGN_LEFT | DT_CLIP, SYSCOL_TEXT, true, (size_t)(line_end - line_start), 0); } y += LINESPACE; // back to start of new line diff --git a/src/simutrans/gui/components/gui_flowtext.cc b/src/simutrans/gui/components/gui_flowtext.cc index 5972f8422..5531dd1dd 100644 --- a/src/simutrans/gui/components/gui_flowtext.cc +++ b/src/simutrans/gui/components/gui_flowtext.cc @@ -8,6 +8,7 @@ #include "../../simcolor.h" #include "../../simevent.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../utils/simstring.h" #include "../gui_theme.h" diff --git a/src/simutrans/gui/components/gui_image_list.cc b/src/simutrans/gui/components/gui_image_list.cc index 84dc9a6a1..dfb52c72e 100644 --- a/src/simutrans/gui/components/gui_image_list.cc +++ b/src/simutrans/gui/components/gui_image_list.cc @@ -6,6 +6,7 @@ #include "../../simdebug.h" #include "gui_image_list.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../simevent.h" #include "../../simcolor.h" diff --git a/src/simutrans/gui/components/gui_label.cc b/src/simutrans/gui/components/gui_label.cc index 4a10b4139..8a03de066 100644 --- a/src/simutrans/gui/components/gui_label.cc +++ b/src/simutrans/gui/components/gui_label.cc @@ -8,6 +8,7 @@ #include "../../dataobj/translator.h" #include "../../utils/simstring.h" #include "../simwin.h" +#include "../../display/display.h" /* * just displays a text, will be auto-translated @@ -38,7 +39,7 @@ gui_label_t::gui_label_t(const char* text, PIXVAL color_, align_t align_) : scr_size gui_label_t::get_min_size() const { - const scr_coord_val dynamic_width = text ? display_calc_proportional_string_len_width(text,strlen(text)) : D_BUTTON_WIDTH; + const scr_coord_val dynamic_width = text ? display_calc_proportional_string_len_width(text, strlen(text), 0) : D_BUTTON_WIDTH; return scr_size(max(dynamic_width, fixed_min_width), max(D_LABEL_HEIGHT, fixed_min_height) ); } @@ -64,7 +65,7 @@ void gui_label_t::set_text_pointer(const char *text_par, bool autosize) text = text_par; if (autosize && text && *text != '\0') { - set_size( scr_size( display_calc_proportional_string_len_width(text,strlen(text)),size.h ) ); + set_size(scr_size(display_calc_proportional_string_len_width(text, strlen(text), 0), size.h)); } } @@ -98,9 +99,9 @@ void gui_label_t::draw(scr_coord offset) display_proportional_clip_rgb(right.x, right.y, separator, ALIGN_LEFT, color, true); if( separator!=text ) { if (shadowed) { - display_text_proportional_len_clip_rgb(right.x+1, right.y+1, text, ALIGN_RIGHT | DT_CLIP, color_shadow, true, separator - text); + display_text_proportional_len_clip_rgb(right.x+1, right.y+1, text, ALIGN_RIGHT | DT_CLIP, color_shadow, true, separator - text, 0); } - display_text_proportional_len_clip_rgb(right.x, right.y, text, ALIGN_RIGHT | DT_CLIP, color, true, separator-text ); + display_text_proportional_len_clip_rgb(right.x, right.y, text, ALIGN_RIGHT | DT_CLIP, color, true, separator-text, 0); } } else { diff --git a/src/simutrans/gui/components/gui_scrolled_list.cc b/src/simutrans/gui/components/gui_scrolled_list.cc index 52f41a21c..3ef4a7f26 100644 --- a/src/simutrans/gui/components/gui_scrolled_list.cc +++ b/src/simutrans/gui/components/gui_scrolled_list.cc @@ -13,6 +13,7 @@ #include "../simwin.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../descriptor/skin_desc.h" #include "../../simskin.h" @@ -43,7 +44,7 @@ scr_size gui_scrolled_list_t::const_text_scrollitem_t::get_min_size() const { if (!is_editable()) { const char* text = get_text(); - return scr_size(2*D_H_SPACE + (text ? display_calc_proportional_string_len_width(text,strlen(text)) : D_BUTTON_WIDTH), LINESPACE); + return scr_size(2*D_H_SPACE + (text ? display_calc_proportional_string_len_width(text, strlen(text), 0) : D_BUTTON_WIDTH), LINESPACE); } else { return scr_size(D_BUTTON_WIDTH, LINESPACE); @@ -68,11 +69,11 @@ void gui_scrolled_list_t::const_text_scrollitem_t::draw(scr_coord pos) if(selected) { // selected element display_fillbox_wh_clip_rgb( pos.x+D_H_SPACE/2, pos.y-1, get_size().w-D_H_SPACE, get_size().h + 1, (focused ? SYSCOL_LIST_BACKGROUND_SELECTED_F : SYSCOL_LIST_BACKGROUND_SELECTED_NF), true); - display_proportional_clip_rgb( pos.x+D_H_SPACE, pos.y, get_text(), ALIGN_LEFT, (focused ? SYSCOL_LIST_TEXT_SELECTED_FOCUS : SYSCOL_LIST_TEXT_SELECTED_NOFOCUS), true); + display_proportional_clip_rgb(pos.x+D_H_SPACE, pos.y, get_text(), ALIGN_LEFT, (focused ? SYSCOL_LIST_TEXT_SELECTED_FOCUS : SYSCOL_LIST_TEXT_SELECTED_NOFOCUS), true); } else { // normal text - display_proportional_clip_rgb( pos.x+D_H_SPACE, pos.y, get_text(), ALIGN_LEFT, get_color(), true); + display_proportional_clip_rgb(pos.x+D_H_SPACE, pos.y, get_text(), ALIGN_LEFT, get_color(), true); } } diff --git a/src/simutrans/gui/components/gui_tab_panel.cc b/src/simutrans/gui/components/gui_tab_panel.cc index f1ddea77f..7ee65ac72 100644 --- a/src/simutrans/gui/components/gui_tab_panel.cc +++ b/src/simutrans/gui/components/gui_tab_panel.cc @@ -9,6 +9,7 @@ #include "../../simevent.h" #include "../../dataobj/environment.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../simcolor.h" #include "../simwin.h" #include "../../world/simworld.h" diff --git a/src/simutrans/gui/components/gui_textarea.cc b/src/simutrans/gui/components/gui_textarea.cc index 5440caa74..d0ce664ab 100644 --- a/src/simutrans/gui/components/gui_textarea.cc +++ b/src/simutrans/gui/components/gui_textarea.cc @@ -7,6 +7,7 @@ #include "gui_textarea.h" #include "../../display/simgraph.h" +#include "../../display/display.h" #include "../../simdebug.h" #include "../../simcolor.h" #include "../../simskin.h" @@ -61,7 +62,7 @@ scr_size gui_textarea_t::calc_size() const do { next = strchr(buf, '\n'); const size_t len = next ? next-buf : 99999; - const int px_len = display_calc_proportional_string_len_width(buf, len); + const int px_len = display_calc_proportional_string_len_width(buf, len, 0); if( px_len > x_size ) { x_size = px_len; @@ -104,11 +105,11 @@ void gui_textarea_t::draw(scr_coord offset) int px_len; if ( -LINESPACE <= draw_y && draw_y <= display_get_height() + LINESPACE) { // draw when in screen area - px_len = display_text_proportional_len_clip_rgb(x, draw_y, buf, ALIGN_LEFT | DT_CLIP, SYSCOL_TEXT, true, len); + px_len = display_text_proportional_len_clip_rgb(x, draw_y, buf, ALIGN_LEFT | DT_CLIP, SYSCOL_TEXT, true, len, 0); } else { // track required length when out of screen area - px_len = display_calc_proportional_string_len_width(buf, len); + px_len = display_calc_proportional_string_len_width(buf, len, 0); } if(px_len>x_size) { x_size = px_len; diff --git a/src/simutrans/gui/components/gui_textinput.cc b/src/simutrans/gui/components/gui_textinput.cc index 482f11622..14acf9254 100644 --- a/src/simutrans/gui/components/gui_textinput.cc +++ b/src/simutrans/gui/components/gui_textinput.cc @@ -10,6 +10,7 @@ #include "../../dataobj/translator.h" #include "../../utils/simstring.h" #include "../../sys/simsys.h" +#include "../../display/display.h" gui_textinput_t::gui_textinput_t() : @@ -579,7 +580,7 @@ void gui_textinput_t::display_with_cursor(scr_coord offset, bool cursor_active, const int y_offset = pos.y+offset.y+D_GET_CENTER_ALIGN_OFFSET(LINESPACE,size.h); // display text (before composition) - display_text_proportional_len_clip_rgb(x_base_offset, y_offset, text, ALIGN_LEFT | DT_CLIP, textcol, true, head_cursor_pos); + display_text_proportional_len_clip_rgb(x_base_offset, y_offset, text, ALIGN_LEFT | DT_CLIP, textcol, true, head_cursor_pos, 0); int x_offset = proportional_string_len_width(text, head_cursor_pos); // IME text to display? @@ -596,7 +597,7 @@ void gui_textinput_t::display_with_cursor(scr_coord offset, bool cursor_active, int start_offset = proportional_string_len_width(composition.get_str(), composition_target_start); int highlight_width = proportional_string_len_width(composition.get_str()+composition_target_start, composition_target_length); display_fillbox_wh_clip_rgb(x_base_offset+x_offset+start_offset, y_offset, highlight_width, LINESPACE, SYSCOL_EDIT_BACKGROUND_SELECTED, true); - display_text_proportional_len_clip_rgb(x_base_offset+x_offset+start_offset, y_offset, composition.get_str()+composition_target_start, ALIGN_LEFT|DT_CLIP, SYSCOL_EDIT_TEXT_SELECTED, false, composition_target_length); + display_text_proportional_len_clip_rgb(x_base_offset+x_offset+start_offset, y_offset, composition.get_str()+composition_target_start, ALIGN_LEFT|DT_CLIP, SYSCOL_EDIT_TEXT_SELECTED, false, composition_target_length, 0); x_offset += composition_width; } @@ -612,7 +613,7 @@ void gui_textinput_t::display_with_cursor(scr_coord offset, bool cursor_active, const scr_coord_val start_offset = proportional_string_len_width(text, start_pos); const scr_coord_val highlight_width = proportional_string_len_width(text+start_pos, end_pos-start_pos); display_fillbox_wh_clip_rgb(x_base_offset+start_offset, y_offset, highlight_width, LINESPACE, SYSCOL_EDIT_BACKGROUND_SELECTED, true); - display_text_proportional_len_clip_rgb(x_base_offset+start_offset, y_offset, text+start_pos, ALIGN_LEFT|DT_CLIP, SYSCOL_EDIT_TEXT_SELECTED, false, end_pos-start_pos); + display_text_proportional_len_clip_rgb(x_base_offset+start_offset, y_offset, text+start_pos, ALIGN_LEFT|DT_CLIP, SYSCOL_EDIT_TEXT_SELECTED, false, end_pos-start_pos, 0); } // display blinking cursor @@ -652,7 +653,7 @@ bool gui_hidden_textinput_t::infowin_event(const event_t *ev) } // acting on release causes unwanted recalculations of cursor position for long strings and (cursor_offset>0) // moreover, only (click) or (release) event happened inside textinput, the other one could lie outside - sint16 asterix_width = display_calc_proportional_string_len_width("*",1); + sint16 asterix_width = display_calc_proportional_string_len_width("*", 1, 0); head_cursor_pos = 0; if ( text ) { head_cursor_pos = min( strlen(text), ev->cx/asterix_width ); diff --git a/src/simutrans/gui/minimap.cc b/src/simutrans/gui/minimap.cc index 20992bf0c..b264f76cd 100644 --- a/src/simutrans/gui/minimap.cc +++ b/src/simutrans/gui/minimap.cc @@ -31,6 +31,7 @@ #include "../utils/cbuffer.h" #include "../display/scr_coord.h" #include "../display/simgraph.h" +#include "../display/display.h" #include "../display/viewport.h" #include "../utils/simrandom.h" #include "../player/simplay.h" diff --git a/src/simutrans/gui/pakselector.cc b/src/simutrans/gui/pakselector.cc index d20d8ce4f..07edc60fb 100644 --- a/src/simutrans/gui/pakselector.cc +++ b/src/simutrans/gui/pakselector.cc @@ -141,7 +141,7 @@ void pak_set_panel_t::draw_logo(const scr_coord_val xpos, const scr_coord_val yp pak_name = entry.info; } - scr_coord_val pak_name_width = display_calc_proportional_string_len_width(pak_name, strlen(pak_name)); + scr_coord_val pak_name_width = display_calc_proportional_string_len_width(pak_name, strlen(pak_name), 0); display_proportional_clip_rgb(xpos + (256 - pak_name_width)/2, ypos + 256 + 8, pak_name, ALIGN_LEFT, gui_theme_t::gui_highlight_color, false); @@ -395,10 +395,10 @@ void pakselector_t::draw(scr_coord pos, scr_size size) display_vline_wh_clip_rgb(pos.x, pos.y, size.h, gui_theme_t::gui_highlight_color, true); const char * title = translator::translate("Choose a Graphics Set For Playing"); - const scr_coord_val title_width = display_calc_proportional_string_len_width(title, strlen(title)); + const scr_coord_val title_width = display_calc_proportional_string_len_width(title, strlen(title), 1); display_fillbox_wh_rgb(pos.x + (size.w - title_width) / 2 - 40, pos.y + 14, title_width + 80, LINESPACE+25, 0xFFFF, true); - display_proportional_rgb(pos.x + (size.w - title_width) / 2, pos.y + LINESPACE + 14, title, ALIGN_LEFT, 0x0000, false); + display_text_bold(pos.x + (size.w - title_width) / 2, pos.y + LINESPACE + 14, 0x0000, title, false); } diff --git a/src/simutrans/gui/simwin.cc b/src/simutrans/gui/simwin.cc index e0a6a4736..042d1f8f8 100644 --- a/src/simutrans/gui/simwin.cc +++ b/src/simutrans/gui/simwin.cc @@ -10,6 +10,7 @@ #include "../simcolor.h" #include "../simevent.h" #include "../display/simgraph.h" +#include "../display/display.h" #include "../display/viewport.h" #include "../tool/simmenu.h" #include "../simskin.h" @@ -393,7 +394,7 @@ static void win_draw_window_title(const scr_coord pos, const scr_size size, text_color = env_t::bottom_window_text_color; } - int titlewidth = display_proportional_clip_rgb(pos.x + left, pos.y + top, text, ALIGN_LEFT, text_color, false); + int titlewidth = display_text_bold(pos.x + left, pos.y + top, text_color, text, false); // if the object has a world position, show the coordinates flags.gotopos = (welt_pos != koord3d::invalid); diff --git a/src/simutrans/gui/vehiclelist_frame.cc b/src/simutrans/gui/vehiclelist_frame.cc index ff3715e42..fdf6dd5a7 100644 --- a/src/simutrans/gui/vehiclelist_frame.cc +++ b/src/simutrans/gui/vehiclelist_frame.cc @@ -14,6 +14,7 @@ #include "../world/simworld.h" #include "../display/simgraph.h" +#include "../display/display.h" #include "../dataobj/translator.h" diff --git a/src/simutrans/player/simplay.cc b/src/simutrans/player/simplay.cc index e604ef6f6..fee1d6ff9 100644 --- a/src/simutrans/player/simplay.cc +++ b/src/simutrans/player/simplay.cc @@ -20,6 +20,7 @@ #include "../gui/simwin.h" #include "../world/simworld.h" #include "../display/viewport.h" +#include "../display/display.h" #include "../builder/brueckenbauer.h" #include "../builder/hausbauer.h" @@ -220,7 +221,7 @@ void player_t::display_messages() for(income_message_t* const m : messages) { - const scr_coord scr_pos = vp->get_screen_coord(koord3d(m->pos,welt->lookup_hgt(m->pos)),koord(0,m->alter >> 4)) + scr_coord((get_tile_raster_width()-display_calc_proportional_string_len_width(m->str, 0x7FFF))/2,0); + const scr_coord scr_pos = vp->get_screen_coord(koord3d(m->pos,welt->lookup_hgt(m->pos)),koord(0,m->alter >> 4)) + scr_coord((get_tile_raster_width()-display_calc_proportional_string_len_width(m->str, 0x7FFF, 0))/2,0); display_shadow_proportional_rgb( scr_pos.x, scr_pos.y, PLAYER_FLAG|color_idx_to_rgb(player_color_1+3), color_idx_to_rgb(COL_BLACK), m->str, true); if( m->pos.x < 3 || m->pos.y < 3 ) { diff --git a/src/simutrans/simloadingscreen.cc b/src/simutrans/simloadingscreen.cc index ed2427e6f..3c96f95e9 100644 --- a/src/simutrans/simloadingscreen.cc +++ b/src/simutrans/simloadingscreen.cc @@ -10,6 +10,7 @@ #include "descriptor/skin_desc.h" #include "simskin.h" #include "display/simgraph.h" +#include "display/display.h" #include "simevent.h" #include "dataobj/environment.h" #include "simticker.h" diff --git a/src/simutrans/simticker.cc b/src/simutrans/simticker.cc index 31eb17a07..e68ecb4d5 100644 --- a/src/simutrans/simticker.cc +++ b/src/simutrans/simticker.cc @@ -7,6 +7,7 @@ #include "dataobj/environment.h" #include "simticker.h" #include "display/simgraph.h" +#include "display/display.h" #include "simcolor.h" #include "tpl/slist_tpl.h" #include "utils/simstring.h" diff --git a/src/simutrans/tool/simtool.cc b/src/simutrans/tool/simtool.cc index d35f8a0ef..39b28e2e1 100644 --- a/src/simutrans/tool/simtool.cc +++ b/src/simutrans/tool/simtool.cc @@ -27,6 +27,7 @@ #include "../obj/depot.h" #include "../simfab.h" #include "../display/simimg.h" +#include "../display/display.h" #include "../simintr.h" #include "../simhalt.h" #include "../simskin.h" diff --git a/src/simutrans/vehicle/vehicle.cc b/src/simutrans/vehicle/vehicle.cc index e0e8cb063..e5131c38f 100644 --- a/src/simutrans/vehicle/vehicle.cc +++ b/src/simutrans/vehicle/vehicle.cc @@ -23,6 +23,7 @@ #include "../builder/vehikelbauer.h" #include "../obj/zeiger.h" #include "../utils/simstring.h" +#include "../display/display.h" #include