comparison src/gfx.cpp @ 13619:640e42736ee8 draft

(svn r18143) -Codechange: allow stripping/ignoring of SETX(Y) during DrawString
author rubidium <rubidium@openttd.org>
date Tue, 17 Nov 2009 15:25:40 +0000
parents 1f81064e4b37
children 45f5842637c2
comparison
equal deleted inserted replaced
13618:7bfaf85c544c 13619:640e42736ee8
325 325
326 /** Truncate a given string to a maximum width if neccessary. 326 /** Truncate a given string to a maximum width if neccessary.
327 * If the string is truncated, add three dots ('...') to show this. 327 * If the string is truncated, add three dots ('...') to show this.
328 * @param *str string that is checked and possibly truncated 328 * @param *str string that is checked and possibly truncated
329 * @param maxw maximum width in pixels of the string 329 * @param maxw maximum width in pixels of the string
330 * @param ignore_setxy whether to ignore SETX(Y) or not
330 * @return new width of (truncated) string 331 * @return new width of (truncated) string
331 */ 332 */
332 static int TruncateString(char *str, int maxw) 333 static int TruncateString(char *str, int maxw, bool ignore_setxy)
333 { 334 {
334 int w = 0; 335 int w = 0;
335 FontSize size = _cur_fontsize; 336 FontSize size = _cur_fontsize;
336 int ddd, ddd_w; 337 int ddd, ddd_w;
337 338
351 *ddd_pos = '\0'; 352 *ddd_pos = '\0';
352 return ddd_w; 353 return ddd_w;
353 } 354 }
354 } else { 355 } else {
355 if (c == SCC_SETX) { 356 if (c == SCC_SETX) {
356 w = *str; 357 if (!ignore_setxy) w = *str;
357 str++; 358 str++;
358 } else if (c == SCC_SETXY) { 359 } else if (c == SCC_SETXY) {
359 w = *str; 360 if (!ignore_setxy) w = *str;
360 str += 2; 361 str += 2;
361 } else if (c == SCC_TINYFONT) { 362 } else if (c == SCC_TINYFONT) {
362 size = FS_SMALL; 363 size = FS_SMALL;
363 ddd = GetCharacterWidth(size, '.') * 3; 364 ddd = GetCharacterWidth(size, '.') * 3;
364 } else if (c == SCC_BIGFONT) { 365 } else if (c == SCC_BIGFONT) {
444 445
445 int initial_left = left; 446 int initial_left = left;
446 int initial_right = right; 447 int initial_right = right;
447 int initial_top = top; 448 int initial_top = top;
448 449
449 if (truncate) TruncateString(str, right - left + 1); 450 if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP);
450 451
451 /* 452 /*
452 * To support SETX and SETXY properly with RTL languages we have to 453 * To support SETX and SETXY properly with RTL languages we have to
453 * calculate the offsets from the right. To do this we need to split 454 * calculate the offsets from the right. To do this we need to split
454 * the string and draw the parts separated by SETX(Y). 455 * the string and draw the parts separated by SETX(Y).
475 *p = '\0'; 476 *p = '\0';
476 break; 477 break;
477 } 478 }
478 if (c != SCC_SETX && c != SCC_SETXY) { 479 if (c != SCC_SETX && c != SCC_SETXY) {
479 loc += len; 480 loc += len;
481 continue;
482 }
483
484 if (align & SA_STRIP) {
485 /* We do not want to keep the SETX(Y)!. It was already copied, so
486 * remove it and undo the incrementing of the pointer! */
487 *p-- = '\0';
488 loc += len + (c == SCC_SETXY ? 2 : 1);
480 continue; 489 continue;
481 } 490 }
482 491
483 if ((align & SA_MASK) != SA_LEFT) { 492 if ((align & SA_MASK) != SA_LEFT) {
484 DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment..."); 493 DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");