Skip to content

Commit ba018f4

Browse files
committed
temp: tentative bugfix for large string word-wrap (more testing needed).
1 parent e8b8679 commit ba018f4

File tree

1 file changed

+20
-1
lines changed
  • ENIGMAsystem/SHELL/Graphics_Systems/General

1 file changed

+20
-1
lines changed

ENIGMAsystem/SHELL/Graphics_Systems/General/GSfont.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,40 @@ void draw_text_sprite(gs_scalar x, gs_scalar y, variant vstr, int sep, int lineW
354354
//Now, simply draw each letter via sub-images, accounting for the width if required.
355355
int offX = 0;
356356
int offY = 0;
357+
char prev_c = '\0'; //Most recent character drawn.
357358
for (size_t i=0; i<str.length(); i++) {
358-
//Draw, update.
359+
//Fetch the next character to be drawn.
359360
char c = str[i];
361+
362+
//A line break can occur here if we are starting a new word that won't fit.
363+
if (prev_c==' ' && c!= ' ') {
364+
size_t word_len = str.find(' ',i);
365+
if (word_len != string::npos) {
366+
if (offX + w*(word_len-i) > lineWidth) {
367+
offX = 0;
368+
offY += sep;
369+
}
370+
}
371+
}
372+
373+
//Draw, update.
360374
int subIndex = c - firstChar;
361375
draw_sprite_stretched(sprite, subIndex, x+offX, y+offY, w, h);
362376
offX += w;
363377

364378
//Wrap if we've passed a wrappable character. Note that, contrary to GM5's documentation,
365379
//line-wrapping for text_sprites does NOT occur after hyphens. Only spaces break the line.
380+
//Note: This wrap and the previous wrap cannot trigger at the same time, as one relies on
381+
// c being ' ' and the other, the reverse.
366382
if (lineWidth!=-1 && c==' ') {
367383
if (offX+w > lineWidth) {
368384
offX = 0;
369385
offY += sep;
370386
}
371387
}
388+
389+
//Next
390+
prev_c = c;
372391
}
373392
}
374393

0 commit comments

Comments
 (0)