Make credits fullscreen

See #3, #215
This commit is contained in:
Alexander Batalov 2023-01-02 13:09:03 +03:00
parent 6224af6178
commit 812079004c
1 changed files with 47 additions and 54 deletions

View File

@ -22,8 +22,6 @@
namespace fallout { namespace fallout {
#define CREDITS_WINDOW_WIDTH (640)
#define CREDITS_WINDOW_HEIGHT (480)
#define CREDITS_WINDOW_SCROLLING_DELAY (38) #define CREDITS_WINDOW_SCROLLING_DELAY (38)
static bool creditsFileParseNextLine(char* dest, int* font, int* color); static bool creditsFileParseNextLine(char* dest, int* font, int* color);
@ -78,39 +76,35 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
mouseShowCursor(); mouseShowCursor();
} }
int creditsWindowX = (screenGetWidth() - CREDITS_WINDOW_WIDTH) / 2; int windowWidth = screenGetWidth();
int creditsWindowY = (screenGetHeight() - CREDITS_WINDOW_HEIGHT) / 2; int windowHeight = screenGetHeight();
int window = windowCreate(creditsWindowX, creditsWindowY, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_HEIGHT, _colorTable[0], 20); int window = windowCreate(0, 0, windowWidth, windowHeight, _colorTable[0], 20);
soundContinueAll(); soundContinueAll();
if (window != -1) { if (window != -1) {
unsigned char* windowBuffer = windowGetBuffer(window); unsigned char* windowBuffer = windowGetBuffer(window);
if (windowBuffer != NULL) { if (windowBuffer != NULL) {
unsigned char* backgroundBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT); unsigned char* backgroundBuffer = (unsigned char*)internal_malloc(windowWidth * windowHeight);
if (backgroundBuffer) { if (backgroundBuffer) {
soundContinueAll(); soundContinueAll();
memset(backgroundBuffer, _colorTable[0], CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT); memset(backgroundBuffer, _colorTable[0], windowWidth * windowHeight);
if (backgroundFid != -1) { if (backgroundFid != -1) {
CacheEntry* backgroundFrmHandle; FrmImage backgroundFrmImage;
Art* frm = artLock(backgroundFid, &backgroundFrmHandle); if (backgroundFrmImage.lock(backgroundFid)) {
if (frm != NULL) { blitBufferToBuffer(backgroundFrmImage.getData(),
int width = artGetWidth(frm, 0, 0); backgroundFrmImage.getWidth(),
int height = artGetHeight(frm, 0, 0); backgroundFrmImage.getHeight(),
unsigned char* backgroundFrmData = artGetFrameData(frm, 0, 0); backgroundFrmImage.getWidth(),
blitBufferToBuffer(backgroundFrmData, backgroundBuffer + windowWidth * ((windowHeight - backgroundFrmImage.getHeight()) / 2) + (windowWidth - backgroundFrmImage.getWidth()) / 2,
width, windowWidth);
height, backgroundFrmImage.unlock();
width,
backgroundBuffer + CREDITS_WINDOW_WIDTH * ((CREDITS_WINDOW_HEIGHT - height) / 2) + (CREDITS_WINDOW_WIDTH - width) / 2,
CREDITS_WINDOW_WIDTH);
artUnlock(backgroundFrmHandle);
} }
} }
unsigned char* intermediateBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT); unsigned char* intermediateBuffer = (unsigned char*)internal_malloc(windowWidth * windowHeight);
if (intermediateBuffer != NULL) { if (intermediateBuffer != NULL) {
memset(intermediateBuffer, 0, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT); memset(intermediateBuffer, 0, windowWidth * windowHeight);
fontSetCurrent(gCreditsWindowTitleFont); fontSetCurrent(gCreditsWindowTitleFont);
int titleFontLineHeight = fontGetLineHeight(); int titleFontLineHeight = fontGetLineHeight();
@ -119,21 +113,20 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
int nameFontLineHeight = fontGetLineHeight(); int nameFontLineHeight = fontGetLineHeight();
int lineHeight = nameFontLineHeight + (titleFontLineHeight >= nameFontLineHeight ? titleFontLineHeight - nameFontLineHeight : 0); int lineHeight = nameFontLineHeight + (titleFontLineHeight >= nameFontLineHeight ? titleFontLineHeight - nameFontLineHeight : 0);
int stringBufferSize = CREDITS_WINDOW_WIDTH * lineHeight; int stringBufferSize = windowWidth * lineHeight;
unsigned char* stringBuffer = (unsigned char*)internal_malloc(stringBufferSize); unsigned char* stringBuffer = (unsigned char*)internal_malloc(stringBufferSize);
if (stringBuffer != NULL) { if (stringBuffer != NULL) {
blitBufferToBuffer(backgroundBuffer, blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH, windowWidth,
CREDITS_WINDOW_HEIGHT, windowHeight,
CREDITS_WINDOW_WIDTH, windowWidth,
windowBuffer, windowBuffer,
CREDITS_WINDOW_WIDTH); windowWidth);
windowRefresh(window); windowRefresh(window);
paletteFadeTo(_cmap); paletteFadeTo(_cmap);
unsigned char* v40 = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH;
char str[260]; char str[260];
int font; int font;
int color; int color;
@ -142,15 +135,15 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
while (creditsFileParseNextLine(str, &font, &color)) { while (creditsFileParseNextLine(str, &font, &color)) {
fontSetCurrent(font); fontSetCurrent(font);
int v19 = fontGetStringWidth(str); int stringWidth = fontGetStringWidth(str);
if (v19 >= CREDITS_WINDOW_WIDTH) { if (stringWidth >= windowWidth) {
continue; continue;
} }
memset(stringBuffer, 0, stringBufferSize); memset(stringBuffer, 0, stringBufferSize);
fontDrawText(stringBuffer, str, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH, color); fontDrawText(stringBuffer, str, windowWidth, windowWidth, color);
unsigned char* dest = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH + (CREDITS_WINDOW_WIDTH - v19) / 2; unsigned char* dest = intermediateBuffer + windowWidth * windowHeight - windowWidth + (windowWidth - stringWidth) / 2;
unsigned char* src = stringBuffer; unsigned char* src = stringBuffer;
for (int index = 0; index < lineHeight; index++) { for (int index = 0; index < lineHeight; index++) {
sharedFpsLimiter.mark(); sharedFpsLimiter.mark();
@ -160,22 +153,22 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
break; break;
} }
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH); memmove(intermediateBuffer, intermediateBuffer + windowWidth, windowWidth * windowHeight - windowWidth);
memcpy(dest, src, v19); memcpy(dest, src, stringWidth);
blitBufferToBuffer(backgroundBuffer, blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH, windowWidth,
CREDITS_WINDOW_HEIGHT, windowHeight,
CREDITS_WINDOW_WIDTH, windowWidth,
windowBuffer, windowBuffer,
CREDITS_WINDOW_WIDTH); windowWidth);
blitBufferToBufferTrans(intermediateBuffer, blitBufferToBufferTrans(intermediateBuffer,
CREDITS_WINDOW_WIDTH, windowWidth,
CREDITS_WINDOW_HEIGHT, windowHeight,
CREDITS_WINDOW_WIDTH, windowWidth,
windowBuffer, windowBuffer,
CREDITS_WINDOW_WIDTH); windowWidth);
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
} }
@ -184,7 +177,7 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
windowRefresh(window); windowRefresh(window);
src += CREDITS_WINDOW_WIDTH; src += windowWidth;
sharedFpsLimiter.throttle(); sharedFpsLimiter.throttle();
renderPresent(); renderPresent();
@ -196,29 +189,29 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
} }
if (!stop) { if (!stop) {
for (int index = 0; index < CREDITS_WINDOW_HEIGHT; index++) { for (int index = 0; index < windowHeight; index++) {
sharedFpsLimiter.mark(); sharedFpsLimiter.mark();
if (inputGetInput() != -1) { if (inputGetInput() != -1) {
break; break;
} }
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH); memmove(intermediateBuffer, intermediateBuffer + windowWidth, windowWidth * windowHeight - windowWidth);
memset(intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH, 0, CREDITS_WINDOW_WIDTH); memset(intermediateBuffer + windowWidth * windowHeight - windowWidth, 0, windowWidth);
blitBufferToBuffer(backgroundBuffer, blitBufferToBuffer(backgroundBuffer,
CREDITS_WINDOW_WIDTH, windowWidth,
CREDITS_WINDOW_HEIGHT, windowHeight,
CREDITS_WINDOW_WIDTH, windowWidth,
windowBuffer, windowBuffer,
CREDITS_WINDOW_WIDTH); windowWidth);
blitBufferToBufferTrans(intermediateBuffer, blitBufferToBufferTrans(intermediateBuffer,
CREDITS_WINDOW_WIDTH, windowWidth,
CREDITS_WINDOW_HEIGHT, windowHeight,
CREDITS_WINDOW_WIDTH, windowWidth,
windowBuffer, windowBuffer,
CREDITS_WINDOW_WIDTH); windowWidth);
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
} }