From: Holger Schemel Date: Sat, 11 Jun 2022 10:32:42 +0000 (+0200) Subject: fixed bug with broken text area content when editing envelope text X-Git-Tag: 4.3.2.2~11 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=e567cb7fd1d4e5b41778326253f736f6f30f14c5;p=rocksndiamonds.git fixed bug with broken text area content when editing envelope text --- diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index a8d3e55c..fcfd235e 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -423,9 +423,9 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->height - 2 * border_y); // gadget text value - DrawTextBuffer(gi->x + border_x, gi->y + border_y, gi->textarea.value, - font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, - BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); + DrawTextArea(gi->x + border_x, gi->y + border_y, gi->textarea.value, + font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, + BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' '); diff --git a/src/libgame/text.c b/src/libgame/text.c index eb36ab22..e198c810 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -506,10 +506,11 @@ static void DrawTextBuffer_Flush(int x, int y, char *buffer, int font_nr, DrawText(xx, yy, buffer, font_nr); } -int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, - int line_length, int cut_length, int max_lines, - int line_spacing, int mask_mode, boolean autowrap, - boolean centered, boolean parse_comments) +static int DrawTextBufferExt(int x, int y, char *text_buffer, int font_nr, + int line_length, int cut_length, int max_lines, + int line_spacing, int mask_mode, boolean autowrap, + boolean centered, boolean parse_comments, + boolean is_text_area) { char buffer[line_length + 1]; int buffer_len; @@ -541,8 +542,16 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, // copy next line from text buffer to line buffer (nearly fgets() style) for (i = 0; i < num_line_chars && *text_buffer; i++) + { if ((line[i] = *text_buffer++) == '\n') + { + // in text areas, 'line_length' sized lines cause additional empty line + if (i == line_length && is_text_area) + text_buffer--; + break; + } + } line[i] = '\0'; // prevent 'num_line_chars' sized lines to cause additional empty line @@ -655,6 +664,28 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, return current_line; } +int DrawTextArea(int x, int y, char *text_buffer, int font_nr, + int line_length, int cut_length, int max_lines, + int line_spacing, int mask_mode, boolean autowrap, + boolean centered, boolean parse_comments) +{ + return DrawTextBufferExt(x, y, text_buffer, font_nr, + line_length, cut_length, max_lines, + line_spacing, mask_mode, autowrap, + centered, parse_comments, TRUE); +} + +int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, + int line_length, int cut_length, int max_lines, + int line_spacing, int mask_mode, boolean autowrap, + boolean centered, boolean parse_comments) +{ + return DrawTextBufferExt(x, y, text_buffer, font_nr, + line_length, cut_length, max_lines, + line_spacing, mask_mode, autowrap, + centered, parse_comments, FALSE); +} + int DrawTextBufferS(int x, int y, char *text_buffer, int font_nr, int line_length, int cut_length, int max_lines, int line_spacing, int mask_mode, boolean autowrap, diff --git a/src/libgame/text.h b/src/libgame/text.h index ff73c714..fff639f6 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -105,6 +105,8 @@ void DrawText(int, int, char *, int); void DrawTextExt(DrawBuffer *, int, int, char *, int, int); char *GetTextBufferFromFile(char *, int); +int DrawTextArea(int, int, char *, int, int, int, int, int, int, + boolean, boolean, boolean); int DrawTextBuffer(int, int, char *, int, int, int, int, int, int, boolean, boolean, boolean); int DrawTextBufferS(int, int, char *, int, int, int, int, int, int, diff --git a/src/tools.c b/src/tools.c index f3f6a33b..bb6668d1 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2925,11 +2925,11 @@ static void AnimateEnvelope(int envelope_nr, int anim_mode, int action) for (xx = 0; xx < xsize; xx++) DrawEnvelopeBackground(graphic, sx, sy, xx, yy, xsize, ysize, font_nr); - DrawTextBuffer(sx + font_width, sy + font_height, - level.envelope[envelope_nr].text, font_nr, max_xsize, - xsize - 2, ysize - 2, 0, mask_mode, - level.envelope[envelope_nr].autowrap, - level.envelope[envelope_nr].centered, FALSE); + DrawTextArea(sx + font_width, sy + font_height, + level.envelope[envelope_nr].text, font_nr, max_xsize, + xsize - 2, ysize - 2, 0, mask_mode, + level.envelope[envelope_nr].autowrap, + level.envelope[envelope_nr].centered, FALSE); redraw_mask |= REDRAW_FIELD; BackToFront();