Started migrating to the new blitText, plus a small fix

The fix is simpl to make blitTextInPlace center text to the
screen rather than the text creation doing it. That way you don't
get weird behavior with screen_blitText (which already handles centering).
This commit is contained in:
Julie Marchant 2019-05-30 18:33:31 -04:00
parent 0ac42df374
commit ba248f8264
6 changed files with 21 additions and 21 deletions

View File

@ -1826,24 +1826,24 @@ static void game_doHud()
fontColor = FONT_YELLOW; fontColor = FONT_YELLOW;
else else
fontColor = FONT_WHITE; fontColor = FONT_WHITE;
screen_blitTextInPlace(TS_TIME_T); screen_blitText(TS_TIME_T, screen->w / 2 - 140, 20);
sprintf(text, "%.2d:%.2d", engine.minutes, engine.seconds); sprintf(text, "%.2d:%.2d", engine.minutes, engine.seconds);
gfx_createTextObject(TS_TIME, text, screen->w / 2 + 10, 21, fontColor); gfx_createTextObject(TS_TIME, text, 0, 0, fontColor);
screen_blitTextInPlace(TS_TIME); screen_blitText(TS_TIME, screen->w / 2 + 10, 21);
} }
if (game.area != MISN_INTERCEPTION) if (game.area != MISN_INTERCEPTION)
{ {
screen_blitTextInPlace(TS_OBJECTIVES_T); screen_blitText(TS_OBJECTIVES_T, screen->w - 250, 20);
sprintf(text, "%d", (mission.remainingObjectives1 + mission.remainingObjectives2)); sprintf(text, "%d", (mission.remainingObjectives1 + mission.remainingObjectives2));
gfx_createTextObject(TS_OBJECTIVES, text, screen->w - 55, 21, FONT_WHITE); gfx_createTextObject(TS_OBJECTIVES, text, 0, 0, FONT_WHITE);
screen_blitTextInPlace(TS_OBJECTIVES); screen_blitText(TS_OBJECTIVES, screen->w - 55, 21);
} }
screen_blitTextInPlace(TS_CASH_T); // cash screen_blitText(TS_CASH_T, 25, 20);
sprintf(text, "%.6d", game.cash); sprintf(text, "%.6d", game.cash);
gfx_createTextObject(TS_CASH, text, 90, 21, FONT_WHITE); gfx_createTextObject(TS_CASH, text, 0, 0, FONT_WHITE);
screen_blitTextInPlace(TS_CASH); screen_blitText(TS_CASH, 90, 21);
if (game.difficulty == DIFFICULTY_ORIGINAL) if (game.difficulty == DIFFICULTY_ORIGINAL)
{ {
@ -1972,8 +1972,7 @@ static void game_doHud()
{ {
if (gfx_textSprites[i].life > 0) if (gfx_textSprites[i].life > 0)
{ {
gfx_textSprites[i].y = screen->h - 75 - (i * 20); screen_blitText(i, -1, screen->h - 75 - (i * 20));
screen_blitTextInPlace(i);
gfx_textSprites[i].life--; gfx_textSprites[i].life--;
if (gfx_textSprites[i].life == 0) if (gfx_textSprites[i].life == 0)

View File

@ -361,8 +361,6 @@ void gfx_createTextObject(int index, const char *inString, int x, int y, int fon
{ {
gfx_textSprites[index].x = x; gfx_textSprites[index].x = x;
gfx_textSprites[index].y = y; gfx_textSprites[index].y = y;
if (x == -1)
gfx_textSprites[index].x = (screen->w - gfx_textSprites[index].image->w) / 2;
return; return;
} }
@ -375,8 +373,6 @@ void gfx_createTextObject(int index, const char *inString, int x, int y, int fon
SDL_FreeSurface(gfx_textSprites[index].image); SDL_FreeSurface(gfx_textSprites[index].image);
} }
gfx_textSprites[index].image = gfx_createTextSurface(inString, fontColor); gfx_textSprites[index].image = gfx_createTextSurface(inString, fontColor);
if (x == -1)
gfx_textSprites[index].x = (screen->w - gfx_textSprites[index].image->w) / 2;
} }
SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue) SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue)

View File

@ -33,7 +33,7 @@ void info_clearLines()
// from a to b // from a to b
void info_copyLine(int a, int b) void info_copyLine(int a, int b)
{ {
gfx_createTextObject(b, gfx_textSprites[a].text, -1, 0, gfx_textSprites[a].fontColor); gfx_createTextObject(b, gfx_textSprites[a].text, 0, 0, gfx_textSprites[a].fontColor);
gfx_textSprites[b].life = gfx_textSprites[a].life; gfx_textSprites[b].life = gfx_textSprites[a].life;
} }
@ -65,6 +65,6 @@ void info_setLine(const char *in, int color)
} }
} }
gfx_createTextObject(index, in, -1, 0, color); gfx_createTextObject(index, in, 0, 0, color);
gfx_textSprites[index].life = 240; gfx_textSprites[index].life = 240;
} }

View File

@ -1060,9 +1060,9 @@ void mission_showStartScreen()
gfx_createTextObject(TS_TARGET_SID, "Sid", screen->w * 11 / 16 + 27, screen->h - 50, FONT_WHITE); gfx_createTextObject(TS_TARGET_SID, "Sid", screen->w * 11 / 16 + 27, screen->h - 50, FONT_WHITE);
gfx_createTextObject(TS_TARGET_PHOEBE, "Phoebe", screen->w * 11 / 16, screen->h - 50, FONT_WHITE); gfx_createTextObject(TS_TARGET_PHOEBE, "Phoebe", screen->w * 11 / 16, screen->h - 50, FONT_WHITE);
gfx_createTextObject(TS_TARGET_KLINE, "Kline", screen->w * 11 / 16 + 9, screen->h - 50, FONT_WHITE); gfx_createTextObject(TS_TARGET_KLINE, "Kline", screen->w * 11 / 16 + 9, screen->h - 50, FONT_WHITE);
gfx_createTextObject(TS_CASH_T, "Cash: $", 25, 20, FONT_WHITE); gfx_createTextObject(TS_CASH_T, "Cash: $", 0, 0, FONT_WHITE);
gfx_createTextObject(TS_OBJECTIVES_T, "Objectives Remaining:", screen->w - 250, 20, FONT_WHITE); gfx_createTextObject(TS_OBJECTIVES_T, "Objectives Remaining:", 0, 0, FONT_WHITE);
gfx_createTextObject(TS_TIME_T, "Time Remaining - ", screen->w / 2 - 140, 20, FONT_WHITE); gfx_createTextObject(TS_TIME_T, "Time Remaining - ", 0, 0, FONT_WHITE);
gfx_createTextObject(TS_POWER, "Power", screen->w / 32, screen->h - 30, FONT_WHITE); gfx_createTextObject(TS_POWER, "Power", screen->w / 32, screen->h - 30, FONT_WHITE);
gfx_createTextObject(TS_OUTPUT, "Output", screen->w * 5 / 16, screen->h - 30, FONT_WHITE); gfx_createTextObject(TS_OUTPUT, "Output", screen->w * 5 / 16, screen->h - 30, FONT_WHITE);
gfx_createTextObject(TS_COOLER, "Cooler", screen->w * 97 / 160, screen->h - 30, FONT_WHITE); gfx_createTextObject(TS_COOLER, "Cooler", screen->w * 97 / 160, screen->h - 30, FONT_WHITE);

View File

@ -48,7 +48,11 @@ void screen_blitText(int i, int x, int y)
// Legacy function; will be removed later // Legacy function; will be removed later
void screen_blitTextInPlace(int i) void screen_blitTextInPlace(int i)
{ {
screen_blit(gfx_textSprites[i].image, (int)gfx_textSprites[i].x, (int)gfx_textSprites[i].y); int x = gfx_textSprites[i].x;
if (x == -1)
x = (screen->w - gfx_textSprites[i].image->w) / 2;
screen_blit(gfx_textSprites[i].image, x, (int)gfx_textSprites[i].y);
} }
int screen_renderString(const char *in, int x, int y, int fontColor) int screen_renderString(const char *in, int x, int y, int fontColor)

View File

@ -30,6 +30,7 @@ extern LinkedRect *screen_bufferHead;
extern LinkedRect *screen_bufferTail; extern LinkedRect *screen_bufferTail;
void screen_blit(SDL_Surface *image, int x, int y); void screen_blit(SDL_Surface *image, int x, int y);
void screen_blitText(int i, int x, int y);
void screen_blitTextInPlace(int i); void screen_blitTextInPlace(int i);
int screen_renderString(const char *in, int x, int y, int fontColor); int screen_renderString(const char *in, int x, int y, int fontColor);
void screen_drawBackground(); void screen_drawBackground();