Refactor artLockFrameData with FrmImage

This commit is contained in:
Alexander Batalov 2022-09-24 19:41:25 +03:00
parent db63d8a085
commit 443070226f
1 changed files with 162 additions and 198 deletions

View File

@ -195,81 +195,67 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
: DIALOG_TYPE_MEDIUM; : DIALOG_TYPE_MEDIUM;
} }
CacheEntry* backgroundHandle; FrmImage backgroundFrmImage;
int backgroundWidth; int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, gDialogBoxBackgroundFrmIds[dialogType], 0, 0, 0);
int backgroundHeight; if (!backgroundFrmImage.lock(backgroundFid)) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gDialogBoxBackgroundFrmIds[dialogType], 0, 0, 0);
unsigned char* background = artLockFrameDataReturningSize(fid, &backgroundHandle, &backgroundWidth, &backgroundHeight);
if (background == NULL) {
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
return -1; return -1;
} }
// Maintain original position in original resolution, otherwise center it. // Maintain original position in original resolution, otherwise center it.
if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundWidth) / 2; if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundFrmImage.getWidth()) / 2;
if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundHeight) / 2; if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundFrmImage.getHeight()) / 2;
int win = windowCreate(x, y, backgroundWidth, backgroundHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04); int win = windowCreate(x,
y,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getHeight(),
256,
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
if (win == -1) { if (win == -1) {
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
return -1; return -1;
} }
unsigned char* windowBuf = windowGetBuffer(win); unsigned char* windowBuf = windowGetBuffer(win);
memcpy(windowBuf, background, backgroundWidth * backgroundHeight); memcpy(windowBuf, backgroundFrmImage.getData(), backgroundFrmImage.getWidth() * backgroundFrmImage.getHeight());
CacheEntry* doneBoxHandle = NULL; FrmImage doneBoxFrmImage;
unsigned char* doneBox = NULL; FrmImage buttonNormalFrmImage;
int doneBoxWidth; FrmImage buttonPressedFrmImage;
int doneBoxHeight;
CacheEntry* downButtonHandle = NULL;
unsigned char* downButton = NULL;
int downButtonWidth;
int downButtonHeight;
CacheEntry* upButtonHandle = NULL;
unsigned char* upButton = NULL;
if ((flags & DIALOG_BOX_0x20) == 0) { if ((flags & DIALOG_BOX_0x20) == 0) {
int doneBoxFid = buildFid(OBJ_TYPE_INTERFACE, 209, 0, 0, 0); int doneBoxFid = buildFid(OBJ_TYPE_INTERFACE, 209, 0, 0, 0);
doneBox = artLockFrameDataReturningSize(doneBoxFid, &doneBoxHandle, &doneBoxWidth, &doneBoxHeight); if (!doneBoxFrmImage.lock(doneBoxFid)) {
if (doneBox == NULL) {
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
int downButtonFid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0); int pressedFid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
downButton = artLockFrameDataReturningSize(downButtonFid, &downButtonHandle, &downButtonWidth, &downButtonHeight); if (!buttonPressedFrmImage.lock(pressedFid)) {
if (downButton == NULL) {
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
int upButtonFid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0); int normalFid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
upButton = artLockFrameData(upButtonFid, 0, 0, &upButtonHandle); if (!buttonNormalFrmImage.lock(normalFid)) {
if (upButton == NULL) {
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
int v27 = hasTwoButtons ? _doneX[dialogType] : (backgroundWidth - doneBoxWidth) / 2; int v27 = hasTwoButtons
blitBufferToBuffer(doneBox, doneBoxWidth, doneBoxHeight, doneBoxWidth, windowBuf + backgroundWidth * _doneY[dialogType] + v27, backgroundWidth); ? _doneX[dialogType]
: (backgroundFrmImage.getWidth() - doneBoxFrmImage.getWidth()) / 2;
blitBufferToBuffer(doneBoxFrmImage.getData(),
doneBoxFrmImage.getWidth(),
doneBoxFrmImage.getHeight(),
doneBoxFrmImage.getWidth(),
windowBuf + backgroundFrmImage.getWidth() * _doneY[dialogType] + v27,
backgroundFrmImage.getWidth());
if (!messageListInit(&messageList)) { if (!messageListInit(&messageList)) {
artUnlock(upButtonHandle);
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
@ -279,10 +265,6 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG"); sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG");
if (!messageListLoad(&messageList, path)) { if (!messageListLoad(&messageList, path)) {
artUnlock(upButtonHandle);
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
// FIXME: Window is not removed. // FIXME: Window is not removed.
return -1; return -1;
@ -294,10 +276,26 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
// 101 - YES // 101 - YES
messageListItem.num = (flags & DIALOG_BOX_YES_NO) == 0 ? 100 : 101; messageListItem.num = (flags & DIALOG_BOX_YES_NO) == 0 ? 100 : 101;
if (messageListGetItem(&messageList, &messageListItem)) { if (messageListGetItem(&messageList, &messageListItem)) {
fontDrawText(windowBuf + backgroundWidth * (_doneY[dialogType] + 3) + v27 + 35, messageListItem.text, backgroundWidth, backgroundWidth, _colorTable[18979]); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * (_doneY[dialogType] + 3) + v27 + 35,
messageListItem.text,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
_colorTable[18979]);
} }
int btn = buttonCreate(win, v27 + 13, _doneY[dialogType] + 4, downButtonWidth, downButtonHeight, -1, -1, -1, 500, upButton, downButton, NULL, BUTTON_FLAG_TRANSPARENT); int btn = buttonCreate(win,
v27 + 13,
_doneY[dialogType] + 4,
buttonPressedFrmImage.getWidth(),
buttonPressedFrmImage.getHeight(),
-1,
-1,
-1,
500,
buttonNormalFrmImage.getData(),
buttonPressedFrmImage.getData(),
NULL,
BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release);
} }
@ -313,61 +311,58 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
fontSetCurrent(103); fontSetCurrent(103);
blitBufferToBufferTrans(doneBox, blitBufferToBufferTrans(doneBoxFrmImage.getData(),
doneBoxWidth, doneBoxFrmImage.getWidth(),
doneBoxHeight, doneBoxFrmImage.getHeight(),
doneBoxWidth, doneBoxFrmImage.getWidth(),
windowBuf + backgroundWidth * _doneY[dialogType] + _doneX[dialogType] + doneBoxWidth + 24, windowBuf + backgroundFrmImage.getWidth() * _doneY[dialogType] + _doneX[dialogType] + doneBoxFrmImage.getWidth() + 24,
backgroundWidth); backgroundFrmImage.getWidth());
fontDrawText(windowBuf + backgroundWidth * (_doneY[dialogType] + 3) + _doneX[dialogType] + doneBoxWidth + 59, fontDrawText(windowBuf + backgroundFrmImage.getWidth() * (_doneY[dialogType] + 3) + _doneX[dialogType] + doneBoxFrmImage.getWidth() + 59,
a8, backgroundWidth, backgroundWidth, _colorTable[18979]); a8,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
_colorTable[18979]);
int btn = buttonCreate(win, int btn = buttonCreate(win,
doneBoxWidth + _doneX[dialogType] + 37, doneBoxFrmImage.getWidth() + _doneX[dialogType] + 37,
_doneY[dialogType] + 4, _doneY[dialogType] + 4,
downButtonWidth, buttonPressedFrmImage.getWidth(),
downButtonHeight, buttonPressedFrmImage.getHeight(),
-1, -1, -1, 501, upButton, downButton, 0, BUTTON_FLAG_TRANSPARENT); -1,
-1,
-1,
501,
buttonNormalFrmImage.getData(),
buttonPressedFrmImage.getData(),
0,
BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release);
} }
} else { } else {
int doneBoxFid = buildFid(OBJ_TYPE_INTERFACE, 209, 0, 0, 0); int doneBoxFid = buildFid(OBJ_TYPE_INTERFACE, 209, 0, 0, 0);
unsigned char* doneBox = artLockFrameDataReturningSize(doneBoxFid, &doneBoxHandle, &doneBoxWidth, &doneBoxHeight); if (!doneBoxFrmImage.lock(doneBoxFid)) {
if (doneBox == NULL) {
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
int downButtonFid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0); int pressedFid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0);
unsigned char* downButton = artLockFrameDataReturningSize(downButtonFid, &downButtonHandle, &downButtonWidth, &downButtonHeight); if (!buttonPressedFrmImage.lock(pressedFid)) {
if (downButton == NULL) {
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
int upButtonFid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0); int normalFid = buildFid(OBJ_TYPE_INTERFACE, 8, 0, 0, 0);
unsigned char* upButton = artLockFrameData(upButtonFid, 0, 0, &upButtonHandle); if (!buttonNormalFrmImage.lock(normalFid)) {
if (upButton == NULL) {
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
if (!messageListInit(&messageList)) { if (!messageListInit(&messageList)) {
artUnlock(upButtonHandle);
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
@ -377,38 +372,34 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG"); sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG");
if (!messageListLoad(&messageList, path)) { if (!messageListLoad(&messageList, path)) {
artUnlock(upButtonHandle);
artUnlock(downButtonHandle);
artUnlock(doneBoxHandle);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
windowDestroy(win); windowDestroy(win);
return -1; return -1;
} }
blitBufferToBufferTrans(doneBox, blitBufferToBufferTrans(doneBoxFrmImage.getData(),
doneBoxWidth, doneBoxFrmImage.getWidth(),
doneBoxHeight, doneBoxFrmImage.getHeight(),
doneBoxWidth, doneBoxFrmImage.getWidth(),
windowBuf + backgroundWidth * _doneY[dialogType] + _doneX[dialogType], windowBuf + backgroundFrmImage.getWidth() * _doneY[dialogType] + _doneX[dialogType],
backgroundWidth); backgroundFrmImage.getWidth());
fontSetCurrent(103); fontSetCurrent(103);
fontDrawText(windowBuf + backgroundWidth * (_doneY[dialogType] + 3) + _doneX[dialogType] + 35, fontDrawText(windowBuf + backgroundFrmImage.getWidth() * (_doneY[dialogType] + 3) + _doneX[dialogType] + 35,
a8, backgroundWidth, backgroundWidth, _colorTable[18979]); a8, backgroundFrmImage.getWidth(), backgroundFrmImage.getWidth(), _colorTable[18979]);
int btn = buttonCreate(win, int btn = buttonCreate(win,
_doneX[dialogType] + 13, _doneX[dialogType] + 13,
_doneY[dialogType] + 4, _doneY[dialogType] + 4,
downButtonWidth, buttonPressedFrmImage.getWidth(),
downButtonHeight, buttonPressedFrmImage.getHeight(),
-1, -1,
-1, -1,
-1, -1,
501, 501,
upButton, buttonNormalFrmImage.getData(),
downButton, buttonPressedFrmImage.getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
@ -430,28 +421,44 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
if (hasTitle) { if (hasTitle) {
if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) { if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) {
fontDrawText(windowBuf + backgroundWidth * v23 + _xtable[dialogType], title, backgroundWidth, backgroundWidth, titleColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + _xtable[dialogType],
title,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
titleColor);
} else { } else {
int length = fontGetStringWidth(title); int length = fontGetStringWidth(title);
fontDrawText(windowBuf + backgroundWidth * v23 + (backgroundWidth - length) / 2, title, backgroundWidth, backgroundWidth, titleColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + (backgroundFrmImage.getWidth() - length) / 2,
title,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
titleColor);
} }
v23 += fontGetLineHeight(); v23 += fontGetLineHeight();
} }
for (int v94 = 0; v94 < bodyLength; v94++) { for (int v94 = 0; v94 < bodyLength; v94++) {
int len = fontGetStringWidth(body[v94]); int len = fontGetStringWidth(body[v94]);
if (len <= backgroundWidth - 26) { if (len <= backgroundFrmImage.getWidth() - 26) {
if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) { if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) {
fontDrawText(windowBuf + backgroundWidth * v23 + _xtable[dialogType], body[v94], backgroundWidth, backgroundWidth, bodyColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + _xtable[dialogType],
body[v94],
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
bodyColor);
} else { } else {
int length = fontGetStringWidth(body[v94]); int length = fontGetStringWidth(body[v94]);
fontDrawText(windowBuf + backgroundWidth * v23 + (backgroundWidth - length) / 2, body[v94], backgroundWidth, backgroundWidth, bodyColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + (backgroundFrmImage.getWidth() - length) / 2,
body[v94],
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
bodyColor);
} }
v23 += fontGetLineHeight(); v23 += fontGetLineHeight();
} else { } else {
short beginnings[WORD_WRAP_MAX_COUNT]; short beginnings[WORD_WRAP_MAX_COUNT];
short count; short count;
if (wordWrap(body[v94], backgroundWidth - 26, beginnings, &count) != 0) { if (wordWrap(body[v94], backgroundFrmImage.getWidth() - 26, beginnings, &count) != 0) {
debugPrint("\nError: dialog_out"); debugPrint("\nError: dialog_out");
} }
@ -466,10 +473,18 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
string[v51] = '\0'; string[v51] = '\0';
if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) { if ((flags & DIALOG_BOX_NO_HORIZONTAL_CENTERING) != 0) {
fontDrawText(windowBuf + backgroundWidth * v23 + _xtable[dialogType], string, backgroundWidth, backgroundWidth, bodyColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + _xtable[dialogType],
string,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
bodyColor);
} else { } else {
int length = fontGetStringWidth(string); int length = fontGetStringWidth(string);
fontDrawText(windowBuf + backgroundWidth * v23 + (backgroundWidth - length) / 2, string, backgroundWidth, backgroundWidth, bodyColor); fontDrawText(windowBuf + backgroundFrmImage.getWidth() * v23 + (backgroundFrmImage.getWidth() - length) / 2,
string,
backgroundFrmImage.getWidth(),
backgroundFrmImage.getWidth(),
bodyColor);
} }
v23 += fontGetLineHeight(); v23 += fontGetLineHeight();
} }
@ -505,13 +520,9 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
} }
windowDestroy(win); windowDestroy(win);
artUnlock(backgroundHandle);
fontSetCurrent(savedFont); fontSetCurrent(savedFont);
if (v86) { if (v86) {
artUnlock(doneBoxHandle);
artUnlock(downButtonHandle);
artUnlock(upButtonHandle);
messageListFree(&messageList); messageListFree(&messageList);
} }
@ -538,48 +549,34 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
} }
} }
unsigned char* frmBuffers[FILE_DIALOG_FRM_COUNT]; FrmImage frmImages[FILE_DIALOG_FRM_COUNT];
CacheEntry* frmHandles[FILE_DIALOG_FRM_COUNT];
Size frmSizes[FILE_DIALOG_FRM_COUNT];
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) { for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gLoadFileDialogFrmIds[index], 0, 0, 0); int fid = buildFid(OBJ_TYPE_INTERFACE, gLoadFileDialogFrmIds[index], 0, 0, 0);
frmBuffers[index] = artLockFrameDataReturningSize(fid, &(frmHandles[index]), &(frmSizes[index].width), &(frmSizes[index].height)); if (!frmImages[index].lock(fid)) {
if (frmBuffers[index] == NULL) {
while (--index >= 0) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
} }
int backgroundWidth = frmSizes[FILE_DIALOG_FRM_BACKGROUND].width; int backgroundWidth = frmImages[FILE_DIALOG_FRM_BACKGROUND].getWidth();
int backgroundHeight = frmSizes[FILE_DIALOG_FRM_BACKGROUND].height; int backgroundHeight = frmImages[FILE_DIALOG_FRM_BACKGROUND].getHeight();
// Maintain original position in original resolution, otherwise center it. // Maintain original position in original resolution, otherwise center it.
if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundWidth) / 2; if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundWidth) / 2;
if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundHeight) / 2; if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundHeight) / 2;
int win = windowCreate(x, y, backgroundWidth, backgroundHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04); int win = windowCreate(x, y, backgroundWidth, backgroundHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
if (win == -1) { if (win == -1) {
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
unsigned char* windowBuffer = windowGetBuffer(win); unsigned char* windowBuffer = windowGetBuffer(win);
memcpy(windowBuffer, frmBuffers[FILE_DIALOG_FRM_BACKGROUND], backgroundWidth * backgroundHeight); memcpy(windowBuffer, frmImages[FILE_DIALOG_FRM_BACKGROUND].getData(), backgroundWidth * backgroundHeight);
MessageList messageList; MessageList messageList;
MessageListItem messageListItem; MessageListItem messageListItem;
if (!messageListInit(&messageList)) { if (!messageListInit(&messageList)) {
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
@ -588,11 +585,6 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
if (!messageListLoad(&messageList, path)) { if (!messageListLoad(&messageList, path)) {
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
@ -609,14 +601,14 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
int doneBtn = buttonCreate(win, int doneBtn = buttonCreate(win,
LOAD_FILE_DIALOG_DONE_BUTTON_X, LOAD_FILE_DIALOG_DONE_BUTTON_X,
LOAD_FILE_DIALOG_DONE_BUTTON_Y, LOAD_FILE_DIALOG_DONE_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].width, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].height, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getHeight(),
-1, -1,
-1, -1,
-1, -1,
500, 500,
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (doneBtn != -1) { if (doneBtn != -1) {
@ -626,14 +618,14 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
int cancelBtn = buttonCreate(win, int cancelBtn = buttonCreate(win,
LOAD_FILE_DIALOG_CANCEL_BUTTON_X, LOAD_FILE_DIALOG_CANCEL_BUTTON_X,
LOAD_FILE_DIALOG_CANCEL_BUTTON_Y, LOAD_FILE_DIALOG_CANCEL_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].width, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].height, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getHeight(),
-1, -1,
-1, -1,
-1, -1,
501, 501,
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (cancelBtn != -1) { if (cancelBtn != -1) {
@ -643,14 +635,14 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
int scrollUpBtn = buttonCreate(win, int scrollUpBtn = buttonCreate(win,
FILE_DIALOG_SCROLL_BUTTON_X, FILE_DIALOG_SCROLL_BUTTON_X,
FILE_DIALOG_SCROLL_BUTTON_Y, FILE_DIALOG_SCROLL_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].width, frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].height, frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getHeight(),
-1, -1,
505, 505,
506, 506,
505, 505,
frmBuffers[FILE_DIALOG_FRM_SCROLL_UP_ARROW_NORMAL], frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED], frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (scrollUpBtn != -1) { if (scrollUpBtn != -1) {
@ -659,15 +651,15 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
int scrollDownButton = buttonCreate(win, int scrollDownButton = buttonCreate(win,
FILE_DIALOG_SCROLL_BUTTON_X, FILE_DIALOG_SCROLL_BUTTON_X,
FILE_DIALOG_SCROLL_BUTTON_Y + frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].height, FILE_DIALOG_SCROLL_BUTTON_Y + frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getHeight(),
frmSizes[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].width, frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].height, frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getHeight(),
-1, -1,
503, 503,
504, 504,
503, 503,
frmBuffers[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_NORMAL], frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED], frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (scrollUpBtn != -1) { if (scrollUpBtn != -1) {
@ -890,10 +882,6 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
messageListFree(&messageList); messageListFree(&messageList);
fontSetCurrent(oldFont); fontSetCurrent(oldFont);
@ -920,48 +908,34 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
} }
} }
unsigned char* frmBuffers[FILE_DIALOG_FRM_COUNT]; FrmImage frmImages[FILE_DIALOG_FRM_COUNT];
CacheEntry* frmHandles[FILE_DIALOG_FRM_COUNT];
Size frmSizes[FILE_DIALOG_FRM_COUNT];
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) { for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gSaveFileDialogFrmIds[index], 0, 0, 0); int fid = buildFid(OBJ_TYPE_INTERFACE, gSaveFileDialogFrmIds[index], 0, 0, 0);
frmBuffers[index] = artLockFrameDataReturningSize(fid, &(frmHandles[index]), &(frmSizes[index].width), &(frmSizes[index].height)); if (!frmImages[index].lock(fid)) {
if (frmBuffers[index] == NULL) {
while (--index >= 0) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
} }
int backgroundWidth = frmSizes[FILE_DIALOG_FRM_BACKGROUND].width; int backgroundWidth = frmImages[FILE_DIALOG_FRM_BACKGROUND].getWidth();
int backgroundHeight = frmSizes[FILE_DIALOG_FRM_BACKGROUND].height; int backgroundHeight = frmImages[FILE_DIALOG_FRM_BACKGROUND].getHeight();
// Maintain original position in original resolution, otherwise center it. // Maintain original position in original resolution, otherwise center it.
if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundWidth) / 2; if (screenGetWidth() != 640) x = (screenGetWidth() - backgroundWidth) / 2;
if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundHeight) / 2; if (screenGetHeight() != 480) y = (screenGetHeight() - backgroundHeight) / 2;
int win = windowCreate(x, y, backgroundWidth, backgroundHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04); int win = windowCreate(x, y, backgroundWidth, backgroundHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
if (win == -1) { if (win == -1) {
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
unsigned char* windowBuffer = windowGetBuffer(win); unsigned char* windowBuffer = windowGetBuffer(win);
memcpy(windowBuffer, frmBuffers[FILE_DIALOG_FRM_BACKGROUND], backgroundWidth * backgroundHeight); memcpy(windowBuffer, frmImages[FILE_DIALOG_FRM_BACKGROUND].getData(), backgroundWidth * backgroundHeight);
MessageList messageList; MessageList messageList;
MessageListItem messageListItem; MessageListItem messageListItem;
if (!messageListInit(&messageList)) { if (!messageListInit(&messageList)) {
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
@ -970,11 +944,6 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
if (!messageListLoad(&messageList, path)) { if (!messageListLoad(&messageList, path)) {
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
return -1; return -1;
} }
@ -991,14 +960,14 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
int doneBtn = buttonCreate(win, int doneBtn = buttonCreate(win,
SAVE_FILE_DIALOG_DONE_BUTTON_X, SAVE_FILE_DIALOG_DONE_BUTTON_X,
SAVE_FILE_DIALOG_DONE_BUTTON_Y, SAVE_FILE_DIALOG_DONE_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].width, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].height, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getHeight(),
-1, -1,
-1, -1,
-1, -1,
500, 500,
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (doneBtn != -1) { if (doneBtn != -1) {
@ -1008,14 +977,14 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
int cancelBtn = buttonCreate(win, int cancelBtn = buttonCreate(win,
SAVE_FILE_DIALOG_CANCEL_BUTTON_X, SAVE_FILE_DIALOG_CANCEL_BUTTON_X,
SAVE_FILE_DIALOG_CANCEL_BUTTON_Y, SAVE_FILE_DIALOG_CANCEL_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].width, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].height, frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getHeight(),
-1, -1,
-1, -1,
-1, -1,
501, 501,
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED], frmImages[FILE_DIALOG_FRM_LITTLE_RED_BUTTON_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (cancelBtn != -1) { if (cancelBtn != -1) {
@ -1025,14 +994,14 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
int scrollUpBtn = buttonCreate(win, int scrollUpBtn = buttonCreate(win,
FILE_DIALOG_SCROLL_BUTTON_X, FILE_DIALOG_SCROLL_BUTTON_X,
FILE_DIALOG_SCROLL_BUTTON_Y, FILE_DIALOG_SCROLL_BUTTON_Y,
frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].width, frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].height, frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getHeight(),
-1, -1,
505, 505,
506, 506,
505, 505,
frmBuffers[FILE_DIALOG_FRM_SCROLL_UP_ARROW_NORMAL], frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED], frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (scrollUpBtn != -1) { if (scrollUpBtn != -1) {
@ -1041,15 +1010,15 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
int scrollDownButton = buttonCreate(win, int scrollDownButton = buttonCreate(win,
FILE_DIALOG_SCROLL_BUTTON_X, FILE_DIALOG_SCROLL_BUTTON_X,
FILE_DIALOG_SCROLL_BUTTON_Y + frmSizes[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].height, FILE_DIALOG_SCROLL_BUTTON_Y + frmImages[FILE_DIALOG_FRM_SCROLL_UP_ARROW_PRESSED].getHeight(),
frmSizes[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].width, frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getWidth(),
frmSizes[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].height, frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getHeight(),
-1, -1,
503, 503,
504, 504,
503, 503,
frmBuffers[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_NORMAL], frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_NORMAL].getData(),
frmBuffers[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED], frmImages[FILE_DIALOG_FRM_SCROLL_DOWN_ARROW_PRESSED].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (scrollUpBtn != -1) { if (scrollUpBtn != -1) {
@ -1376,11 +1345,6 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
} }
windowDestroy(win); windowDestroy(win);
for (int index = 0; index < FILE_DIALOG_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
messageListFree(&messageList); messageListFree(&messageList);
fontSetCurrent(oldFont); fontSetCurrent(oldFont);