X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Ftext.c;h=c7d8499b42f12d25949562d0c2d0a13af2ceb347;hb=40f85093a4a5f80c37d7a9847f5b10c230c76690;hp=4c3f30ff143b2434cf66cc4f9d6dd135c6f69d56;hpb=14d7691c65ca4a466ce9b9448153e8fbe8351a81;p=rocksndiamonds.git diff --git a/src/libgame/text.c b/src/libgame/text.c index 4c3f30ff..c7d8499b 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -59,6 +59,20 @@ int getFontHeight(int font_nr) return gfx.font_bitmap_info[font_bitmap_id].height; } +int getFontDrawOffsetX(int font_nr) +{ + int font_bitmap_id = gfx.select_font_function(font_nr); + + return gfx.font_bitmap_info[font_bitmap_id].draw_xoffset; +} + +int getFontDrawOffsetY(int font_nr) +{ + int font_bitmap_id = gfx.select_font_function(font_nr); + + return gfx.font_bitmap_info[font_bitmap_id].draw_yoffset; +} + int getTextWidth(char *text, int font_nr) { return (text != NULL ? strlen(text) * getFontWidth(font_nr) : 0); @@ -87,10 +101,12 @@ void getFontCharSource(int font_nr, char c, Bitmap **bitmap, int *x, int *y) int font_bitmap_id = gfx.select_font_function(font_nr); struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id]; int font_pos = getFontCharPosition(font_nr, c); + int offset_x = (font->offset_x != 0 ? font->offset_x : font->width); + int offset_y = (font->offset_y != 0 ? font->offset_y : font->height); *bitmap = font->bitmap; - *x = font->src_x + (font_pos % font->num_chars_per_line) * font->width; - *y = font->src_y + (font_pos / font->num_chars_per_line) * font->height; + *x = font->src_x + (font_pos % font->num_chars_per_line) * offset_x; + *y = font->src_y + (font_pos / font->num_chars_per_line) * offset_y; } @@ -118,7 +134,7 @@ int maxWordLengthInString(char *text) /* simple text drawing functions */ /* ========================================================================= */ -void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) +void DrawInitText(char *text, int ypos, int font_nr) { LimitScreenUpdates(TRUE); @@ -141,22 +157,6 @@ void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) } } -void DrawInitText(char *text, int ypos, int font_nr) -{ - // DrawInitTextExt(text, ypos, font_nr, TRUE); - DrawInitTextExt(text, ypos, font_nr, FALSE); -} - -void DrawInitTextAlways(char *text, int ypos, int font_nr) -{ - DrawInitTextExt(text, ypos, font_nr, TRUE); -} - -void DrawInitTextIfNeeded(char *text, int ypos, int font_nr) -{ - DrawInitTextExt(text, ypos, font_nr, FALSE); -} - void DrawTextF(int x, int y, int font_nr, char *format, ...) { char buffer[MAX_OUTPUT_LINESIZE + 1]; @@ -199,11 +199,6 @@ void DrawTextSCentered(int y, int font_nr, char *text) gfx.sy + y, text, font_nr); } -void DrawTextCentered(int y, int font_nr, char *text) -{ - DrawText((gfx.sxsize - getTextWidth(text, font_nr)) / 2, y, text, font_nr); -} - void DrawTextSAligned(int x, int y, char *text, int font_nr, int align) { DrawText(gfx.sx + ALIGNED_XPOS(x, getTextWidth(text, font_nr), align), @@ -464,18 +459,17 @@ static boolean getCheckedTokenValueFromString(char *string, char **token, static void DrawTextBuffer_Flush(int x, int y, char *buffer, int font_nr, int line_length, int cut_length, - int line_spacing, int mask_mode, - boolean centered, int current_line) + int mask_mode, boolean centered, + int current_ypos) { int buffer_len = strlen(buffer); int font_width = getFontWidth(font_nr); - int font_height = getFontHeight(font_nr); int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0); int offset_xsize = (centered ? font_width * (line_length - buffer_len) / 2 : 0); int final_cut_length = MAX(0, cut_length - offset_chars); int xx = x + offset_xsize; - int yy = y + current_line * (font_height + line_spacing); + int yy = y + current_ypos; buffer[final_cut_length] = '\0'; @@ -492,7 +486,11 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, { char buffer[line_length + 1]; int buffer_len; + int font_height = getFontHeight(font_nr); + int line_height = font_height + line_spacing; int current_line = 0; + int current_ypos = 0; + int max_ysize = max_lines * line_height; if (text_buffer == NULL || *text_buffer == '\0') return 0; @@ -506,7 +504,7 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, buffer[0] = '\0'; buffer_len = 0; - while (*text_buffer && current_line < max_lines) + while (*text_buffer && current_ypos < max_ysize) { char line[MAX_LINE_LEN + 1]; char *line_ptr; @@ -533,11 +531,11 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, if (getCheckedTokenValueFromString(line + 1, &token, &value)) { /* if found, flush the current buffer, if non-empty */ - if (buffer_len > 0 && current_line < max_lines) + if (buffer_len > 0 && current_ypos < max_ysize) { DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length, - line_spacing, mask_mode, centered, current_line); - + mask_mode, centered, current_ypos); + current_ypos += line_height; current_line++; buffer[0] = '\0'; @@ -552,6 +550,10 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, centered = get_boolean_from_string(value); else if (strEqual(token, ".parse_comments")) parse_comments = get_boolean_from_string(value); + + // if font has changed, depending values need to be updated as well + font_height = getFontHeight(font_nr); + line_height = font_height + line_spacing; } continue; @@ -572,7 +574,7 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, line_ptr = line; - while (*line_ptr && current_line < max_lines) + while (*line_ptr && current_ypos < max_ysize) { boolean buffer_filled; @@ -603,7 +605,8 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, if (buffer_filled) { DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length, - line_spacing, mask_mode, centered, current_line); + mask_mode, centered, current_ypos); + current_ypos += line_height; current_line++; last_line_was_empty = (buffer_len == 0); @@ -614,10 +617,11 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, } } - if (buffer_len > 0 && current_line < max_lines) + if (buffer_len > 0 && current_ypos < max_ysize) { DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length, - line_spacing, mask_mode, centered, current_line); + mask_mode, centered, current_ypos); + current_ypos += line_height; current_line++; }