Ticket #3957: word-wrapping.diff
File word-wrapping.diff, 2.9 KB (added by , 17 years ago) |
---|
-
engines/drascula/graphics.cpp
302 302 } 303 303 304 304 void DrasculaEngine::centerText(const char *message, int textX, int textY) { 305 char bb[200], m2[200], m1[200], mb[10][50];305 char bb[200], m2[200], nextLine[200], centered_text[10][50]; 306 306 char m3[200]; 307 int h, fil, textX3, textX2, textX1, conta_f = 0, ya= 0;307 int i, nextLineWidth, maxLineWidth, numLines = 0; 308 308 309 strcpy(m1, " "); 309 for (i = 0; i < 10; i++) 310 centered_text[i][0] = '\0'; 311 312 textX = CLIP<int>(textX, 60, 255); 313 maxLineWidth = (textX <= 160) ? 2 * textX : 2 * (315 - textX); 314 nextLineWidth = strlen(message) * CHAR_WIDTH; 315 316 strcpy(nextLine, message); 310 317 strcpy(m2, " "); 311 318 strcpy(m3, " "); 312 319 strcpy(bb, " "); 313 320 314 for (h = 0; h < 10; h++)315 strcpy(mb[h], " ");321 while (true) { 322 bool emergency = false; 316 323 317 if (textX > 160)318 ya = 1;324 strcpy(bb, nextLine); 325 scumm_strrev(bb); 319 326 320 strcpy(m1, message); 321 textX = CLIP<int>(textX, 60, 255); 327 // If the next line is still too long, remove a word from it. 322 328 323 textX1 = textX; 329 if (nextLineWidth >= maxLineWidth) { 330 char *ptr = strrchr(nextLine, ' '); 324 331 325 if (ya == 1) 326 textX1 = 315 - textX; 327 328 textX2 = (strlen(m1) / 2) * CHAR_WIDTH; 329 330 while (true) { 331 strcpy(bb, m1); 332 scumm_strrev(bb); 333 334 if (textX1 < textX2) { 335 strcpy(m3, strrchr(m1, ' ')); 336 strcpy(m1, strstr(bb, " ")); 337 scumm_strrev(m1); 338 m1[strlen(m1) - 1] = '\0'; 339 strcat(m3, m2); 340 strcpy(m2, m3); 332 if (ptr) { 333 strcpy(m3, ptr); 334 strcpy(nextLine, strchr(bb, ' ')); 335 scumm_strrev(nextLine); 336 nextLine[strlen(nextLine) - 1] = '\0'; 337 strcat(m3, m2); 338 strcpy(m2, m3); 339 } else 340 emergency = true; 341 341 }; 342 342 343 textX2 = (strlen(m1) / 2) * CHAR_WIDTH;343 nextLineWidth = strlen(nextLine) * CHAR_WIDTH; 344 344 345 if (textX1 < textX2)346 continue;345 // If the next line is now of appropriate length, add it to the 346 // centered lines. 347 347 348 strcpy(mb[conta_f], m1); 348 if (emergency || nextLineWidth < maxLineWidth) { 349 strcpy(centered_text[numLines++], nextLine); 349 350 350 if (!strcmp(m2, "")) 351 break; 351 int len = strlen(m2); 352 352 353 scumm_strrev(m2); 354 m2[strlen(m2) - 1] = '\0'; 355 scumm_strrev(m2); 356 strcpy(m1, m2); 357 strcpy(m2, ""); 358 conta_f++; 353 if (len > 0) { 354 scumm_strrev(m2); 355 m2[len - 1] = '\0'; 356 scumm_strrev(m2); 357 strcpy(nextLine, m2); 358 *m2 = '\0'; 359 } else 360 break; 361 } 359 362 } 360 363 361 fil = textY - (((conta_f + 3) * CHAR_HEIGHT));364 int y = textY - (((numLines + 2) * CHAR_HEIGHT)); 362 365 363 for ( h = 0; h < conta_f + 1; h++) {364 textX3 = strlen(mb[h]) / 2;365 print_abc( mb[h], ((textX) - textX3 * CHAR_WIDTH) - 1, fil);366 fil = fil + CHAR_HEIGHT + 2;366 for (i = 0; i < numLines; i++) { 367 int x = (strlen(centered_text[i]) / 2) * CHAR_WIDTH; 368 print_abc(centered_text[i], textX - x - 1, y); 369 y += (CHAR_HEIGHT + 2); 367 370 } 368 371 } 369 372