Improve button functions readability

This commit is contained in:
Alexander Batalov 2023-04-11 09:01:14 +03:00
parent e23b39abaa
commit 6d1273d325
4 changed files with 243 additions and 247 deletions

View File

@ -25,8 +25,8 @@ namespace fallout {
#define MAX_WINDOW_COUNT (50) #define MAX_WINDOW_COUNT (50)
// The maximum number of radio groups. // The maximum number of button groups.
#define RADIO_GROUP_LIST_CAPACITY (64) #define BUTTON_GROUP_LIST_CAPACITY (64)
static void windowFree(int win); static void windowFree(int win);
static void _win_buffering(bool a1); static void _win_buffering(bool a1);
@ -39,13 +39,13 @@ static int paletteOpenFileImpl(const char* path, int flags);
static int paletteReadFileImpl(int fd, void* buf, size_t count); static int paletteReadFileImpl(int fd, void* buf, size_t count);
static int paletteCloseFileImpl(int fd); static int paletteCloseFileImpl(int fd);
static Button* buttonCreateInternal(int win, int x, int y, int width, int height, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, int flags, unsigned char* up, unsigned char* dn, unsigned char* hover); static Button* buttonCreateInternal(int win, int x, int y, int width, int height, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, int flags, unsigned char* up, unsigned char* dn, unsigned char* hover);
static int _GNW_check_buttons(Window* window, int* out_a2); static int _GNW_check_buttons(Window* window, int* keyCodePtr);
static bool _button_under_mouse(Button* button, Rect* rect); static bool _button_under_mouse(Button* button, Rect* rect);
static void buttonFree(Button* ptr); static void buttonFree(Button* ptr);
static int button_new_id(); static int button_new_id();
static int _win_group_check_buttons(int a1, int* a2, int a3, void (*a4)(int)); static int _win_group_check_buttons(int buttonCount, int* btns, int maxChecked, RadioButtonCallback* func);
static int _button_check_group(Button* button); static int _button_check_group(Button* button);
static void _button_draw(Button* button, Window* window, unsigned char* data, int a4, Rect* a5, int a6); static void _button_draw(Button* button, Window* window, unsigned char* data, bool draw, Rect* bound, bool sound);
static void _GNW_button_refresh(Window* window, Rect* rect); static void _GNW_button_refresh(Window* window, Rect* rect);
// 0x50FA30 // 0x50FA30
@ -112,7 +112,7 @@ static int _doing_refresh_all;
static void* _GNW_texture; static void* _GNW_texture;
// 0x6ADF40 // 0x6ADF40
static RadioGroup gRadioGroups[RADIO_GROUP_LIST_CAPACITY]; static ButtonGroup gButtonGroups[BUTTON_GROUP_LIST_CAPACITY];
// 0x4D5C30 // 0x4D5C30
int windowManagerInit(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3) int windowManagerInit(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3)
@ -504,15 +504,12 @@ void windowDrawBorder(int win)
} }
// 0x4D684C // 0x4D684C
void windowDrawText(int win, const char* str, int a3, int x, int y, int a6) void windowDrawText(int win, const char* str, int width, int x, int y, int color)
{ {
int v7;
int v14;
unsigned char* buf; unsigned char* buf;
int v27; int textColor;
Window* window = windowGetWindow(win); Window* window = windowGetWindow(win);
v7 = a3;
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return; return;
@ -522,52 +519,51 @@ void windowDrawText(int win, const char* str, int a3, int x, int y, int a6)
return; return;
} }
if (a3 == 0) { if (width == 0) {
if (a6 & 0x040000) { if (color & 0x040000) {
v7 = fontGetMonospacedStringWidth(str); width = fontGetMonospacedStringWidth(str);
} else { } else {
v7 = fontGetStringWidth(str); width = fontGetStringWidth(str);
} }
} }
if (v7 + x > window->width) { if (width + x > window->width) {
if (!(a6 & 0x04000000)) { if (!(color & 0x04000000)) {
return; return;
} }
v7 = window->width - x; width = window->width - x;
} }
buf = window->buffer + x + y * window->width; buf = window->buffer + x + y * window->width;
v14 = fontGetLineHeight(); if (fontGetLineHeight() + y > window->height) {
if (v14 + y > window->height) {
return; return;
} }
if (!(a6 & 0x02000000)) { if (!(color & 0x02000000)) {
if (window->color == 256 && _GNW_texture != NULL) { if (window->color == 256 && _GNW_texture != NULL) {
_buf_texture(buf, v7, fontGetLineHeight(), window->width, _GNW_texture, window->tx + x, window->ty + y); _buf_texture(buf, width, fontGetLineHeight(), window->width, _GNW_texture, window->tx + x, window->ty + y);
} else { } else {
bufferFill(buf, v7, fontGetLineHeight(), window->width, window->color); bufferFill(buf, width, fontGetLineHeight(), window->width, window->color);
} }
} }
if (a6 & 0xFF00) { if (color & 0xFF00) {
int t = (a6 & 0xFF00) >> 8; int t = (color & 0xFF00) >> 8;
v27 = (a6 & ~0xFFFF) | _colorTable[_GNW_wcolor[t]]; textColor = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[t]];
} else { } else {
v27 = a6; textColor = color;
} }
fontDrawText(buf, str, v7, window->width, v27); fontDrawText(buf, str, width, window->width, textColor);
if (a6 & 0x01000000) { if (color & 0x01000000) {
// TODO: Check. // TODO: Check.
Rect rect; Rect rect;
rect.left = window->rect.left + x; rect.left = window->rect.left + x;
rect.top = window->rect.top + y; rect.top = window->rect.top + y;
rect.right = rect.left + v7; rect.right = rect.left + width;
rect.bottom = rect.top + fontGetLineHeight(); rect.bottom = rect.top + fontGetLineHeight();
_GNW_win_refresh(window, &rect, NULL); _GNW_win_refresh(window, &rect, NULL);
} }
@ -628,7 +624,7 @@ void windowDrawRect(int win, int left, int top, int right, int bottom, int color
} }
// 0x4D6CC8 // 0x4D6CC8
void windowFill(int win, int x, int y, int width, int height, int a6) void windowFill(int win, int x, int y, int width, int height, int color)
{ {
Window* window = windowGetWindow(win); Window* window = windowGetWindow(win);
@ -640,19 +636,19 @@ void windowFill(int win, int x, int y, int width, int height, int a6)
return; return;
} }
if (a6 == 256) { if (color == 256) {
if (_GNW_texture != NULL) { if (_GNW_texture != NULL) {
_buf_texture(window->buffer + window->width * y + x, width, height, window->width, _GNW_texture, x + window->tx, y + window->ty); _buf_texture(window->buffer + window->width * y + x, width, height, window->width, _GNW_texture, x + window->tx, y + window->ty);
} else { } else {
a6 = _colorTable[_GNW_wcolor[0]] & 0xFF; color = _colorTable[_GNW_wcolor[0]] & 0xFF;
} }
} else if ((a6 & 0xFF00) != 0) { } else if ((color & 0xFF00) != 0) {
int v1 = (a6 & 0xFF00) >> 8; int v1 = (color & 0xFF00) >> 8;
a6 = (a6 & ~0xFFFF) | _colorTable[_GNW_wcolor[v1]]; color = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[v1]];
} }
if (a6 < 256) { if (color < 256) {
bufferFill(window->buffer + window->width * y + x, width, height, window->width, a6); bufferFill(window->buffer + window->width * y + x, width, height, window->width, color);
} }
} }
@ -1367,12 +1363,12 @@ int buttonCreate(int win, int x, int y, int width, int height, int mouseEnterEve
return -1; return -1;
} }
Button* button = buttonCreateInternal(win, x, y, width, height, mouseEnterEventCode, mouseExitEventCode, mouseDownEventCode, mouseUpEventCode, flags | BUTTON_FLAG_0x010000, up, dn, hover); Button* button = buttonCreateInternal(win, x, y, width, height, mouseEnterEventCode, mouseExitEventCode, mouseDownEventCode, mouseUpEventCode, flags | BUTTON_FLAG_GRAPHIC, up, dn, hover);
if (button == NULL) { if (button == NULL) {
return -1; return -1;
} }
_button_draw(button, window, button->normalImage, 0, NULL, 0); _button_draw(button, window, button->normalImage, false, NULL, false);
return button->id; return button->id;
} }
@ -1469,7 +1465,7 @@ int _win_register_text_button(int win, int x, int y, int mouseEnterEventCode, in
return -1; return -1;
} }
_button_draw(button, window, button->normalImage, 0, NULL, 0); _button_draw(button, window, button->normalImage, false, NULL, false);
return button->id; return button->id;
} }
@ -1494,7 +1490,7 @@ int _win_register_button_disable(int btn, unsigned char* up, unsigned char* down
} }
// 0x4D86A8 // 0x4D86A8
int _win_register_button_image(int btn, unsigned char* up, unsigned char* down, unsigned char* hover, int a5) int _win_register_button_image(int btn, unsigned char* up, unsigned char* down, unsigned char* hover, bool draw)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
@ -1510,7 +1506,7 @@ int _win_register_button_image(int btn, unsigned char* up, unsigned char* down,
return -1; return -1;
} }
if (!(button->flags & BUTTON_FLAG_0x010000)) { if (!(button->flags & BUTTON_FLAG_GRAPHIC)) {
return -1; return -1;
} }
@ -1527,7 +1523,7 @@ int _win_register_button_image(int btn, unsigned char* up, unsigned char* down,
button->pressedImage = down; button->pressedImage = down;
button->hoverImage = hover; button->hoverImage = hover;
_button_draw(button, window, button->currentImage, a5, NULL, 0); _button_draw(button, window, button->currentImage, draw, NULL, false);
return 0; return 0;
} }
@ -1590,7 +1586,7 @@ int buttonSetRightMouseCallbacks(int btn, int rightMouseDownEventCode, int right
// These callbacks can be triggered several times during tracking if mouse leaves button's rectangle without releasing mouse buttons. // These callbacks can be triggered several times during tracking if mouse leaves button's rectangle without releasing mouse buttons.
// //
// 0x4D87F8 // 0x4D87F8
int buttonSetCallbacks(int btn, ButtonCallback* onPressed, ButtonCallback* onUnpressed) int buttonSetCallbacks(int btn, ButtonCallback* pressSoundFunc, ButtonCallback* releaseSoundFunc)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
@ -1601,8 +1597,8 @@ int buttonSetCallbacks(int btn, ButtonCallback* onPressed, ButtonCallback* onUnp
return -1; return -1;
} }
button->onPressed = onPressed; button->pressSoundFunc = pressSoundFunc;
button->onUnpressed = onUnpressed; button->releaseSoundFunc = releaseSoundFunc;
return 0; return 0;
} }
@ -1676,9 +1672,9 @@ Button* buttonCreateInternal(int win, int x, int y, int width, int height, int m
button->leftMouseUpProc = NULL; button->leftMouseUpProc = NULL;
button->rightMouseDownProc = NULL; button->rightMouseDownProc = NULL;
button->rightMouseUpProc = NULL; button->rightMouseUpProc = NULL;
button->onPressed = NULL; button->pressSoundFunc = NULL;
button->onUnpressed = NULL; button->releaseSoundFunc = NULL;
button->radioGroup = NULL; button->buttonGroup = NULL;
button->prev = NULL; button->prev = NULL;
button->next = window->buttonListHead; button->next = window->buttonListHead;
@ -1702,7 +1698,7 @@ bool _win_button_down(int btn)
return false; return false;
} }
if ((button->flags & BUTTON_FLAG_0x01) != 0 && (button->flags & BUTTON_FLAG_0x020000) != 0) { if ((button->flags & BUTTON_FLAG_0x01) != 0 && (button->flags & BUTTON_FLAG_CHECKED) != 0) {
return true; return true;
} }
@ -1751,10 +1747,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
*keyCodePtr = prevHoveredButton->mouseExitEventCode; *keyCodePtr = prevHoveredButton->mouseExitEventCode;
} }
if ((prevHoveredButton->flags & BUTTON_FLAG_0x01) && (prevHoveredButton->flags & BUTTON_FLAG_0x020000)) { if ((prevHoveredButton->flags & BUTTON_FLAG_0x01) && (prevHoveredButton->flags & BUTTON_FLAG_CHECKED)) {
_button_draw(prevHoveredButton, window, prevHoveredButton->pressedImage, 1, NULL, 1); _button_draw(prevHoveredButton, window, prevHoveredButton->pressedImage, true, NULL, true);
} else { } else {
_button_draw(prevHoveredButton, window, prevHoveredButton->normalImage, 1, NULL, 1); _button_draw(prevHoveredButton, window, prevHoveredButton->normalImage, true, NULL, true);
} }
window->hoveredButton = NULL; window->hoveredButton = NULL;
@ -1778,10 +1774,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
*keyCodePtr = prevClickedButton->mouseEnterEventCode; *keyCodePtr = prevClickedButton->mouseEnterEventCode;
} }
if ((prevClickedButton->flags & BUTTON_FLAG_0x01) && (prevClickedButton->flags & BUTTON_FLAG_0x020000)) { if ((prevClickedButton->flags & BUTTON_FLAG_0x01) && (prevClickedButton->flags & BUTTON_FLAG_CHECKED)) {
_button_draw(prevClickedButton, window, prevClickedButton->pressedImage, 1, NULL, 1); _button_draw(prevClickedButton, window, prevClickedButton->pressedImage, true, NULL, true);
} else { } else {
_button_draw(prevClickedButton, window, prevClickedButton->normalImage, 1, NULL, 1); _button_draw(prevClickedButton, window, prevClickedButton->normalImage, true, NULL, true);
} }
window->hoveredButton = prevClickedButton; window->hoveredButton = prevClickedButton;
@ -1812,10 +1808,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
*keyCodePtr = v28->mouseExitEventCode; *keyCodePtr = v28->mouseExitEventCode;
} }
if ((v28->flags & BUTTON_FLAG_0x01) && (v28->flags & BUTTON_FLAG_0x020000)) { if ((v28->flags & BUTTON_FLAG_0x01) && (v28->flags & BUTTON_FLAG_CHECKED)) {
_button_draw(v28, v26, v28->pressedImage, 1, NULL, 1); _button_draw(v28, v26, v28->pressedImage, true, NULL, true);
} else { } else {
_button_draw(v28, v26, v28->normalImage, 1, NULL, 1); _button_draw(v28, v26, v28->normalImage, true, NULL, true);
} }
v26->clickedButton = NULL; v26->clickedButton = NULL;
@ -1857,10 +1853,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
if ((button->flags & BUTTON_FLAG_0x01) != 0) { if ((button->flags & BUTTON_FLAG_0x01) != 0) {
if ((button->flags & BUTTON_FLAG_0x02) != 0) { if ((button->flags & BUTTON_FLAG_0x02) != 0) {
if ((button->flags & BUTTON_FLAG_0x020000) != 0) { if ((button->flags & BUTTON_FLAG_CHECKED) != 0) {
if (!(button->flags & BUTTON_FLAG_0x04)) { if (!(button->flags & BUTTON_FLAG_0x04)) {
if (button->radioGroup != NULL) { if (button->buttonGroup != NULL) {
button->radioGroup->field_4--; button->buttonGroup->currChecked--;
} }
if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_DOWN) != 0) { if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_DOWN) != 0) {
@ -1871,7 +1867,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
cb = button->rightMouseUpProc; cb = button->rightMouseUpProc;
} }
button->flags &= ~BUTTON_FLAG_0x020000; button->flags &= ~BUTTON_FLAG_CHECKED;
} }
} else { } else {
if (_button_check_group(button) == -1) { if (_button_check_group(button) == -1) {
@ -1887,7 +1883,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
cb = button->rightMouseDownProc; cb = button->rightMouseDownProc;
} }
button->flags |= BUTTON_FLAG_0x020000; button->flags |= BUTTON_FLAG_CHECKED;
} }
} }
} else { } else {
@ -1905,7 +1901,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
} }
} }
_button_draw(button, window, button->pressedImage, 1, NULL, 1); _button_draw(button, window, button->pressedImage, true, NULL, true);
break; break;
} }
@ -1916,10 +1912,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
if (v49->flags & BUTTON_FLAG_0x01) { if (v49->flags & BUTTON_FLAG_0x01) {
if (!(v49->flags & BUTTON_FLAG_0x02)) { if (!(v49->flags & BUTTON_FLAG_0x02)) {
if (v49->flags & BUTTON_FLAG_0x020000) { if (v49->flags & BUTTON_FLAG_CHECKED) {
if (!(v49->flags & BUTTON_FLAG_0x04)) { if (!(v49->flags & BUTTON_FLAG_0x04)) {
if (v49->radioGroup != NULL) { if (v49->buttonGroup != NULL) {
v49->radioGroup->field_4--; v49->buttonGroup->currChecked--;
} }
if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_UP) != 0) { if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_UP) != 0) {
@ -1930,12 +1926,12 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
cb = button->rightMouseUpProc; cb = button->rightMouseUpProc;
} }
button->flags &= ~BUTTON_FLAG_0x020000; button->flags &= ~BUTTON_FLAG_CHECKED;
} }
} else { } else {
if (_button_check_group(v49) == -1) { if (_button_check_group(v49) == -1) {
button = NULL; button = NULL;
_button_draw(v49, window, v49->normalImage, 1, NULL, 1); _button_draw(v49, window, v49->normalImage, true, NULL, true);
break; break;
} }
@ -1947,13 +1943,13 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
cb = v49->rightMouseDownProc; cb = v49->rightMouseDownProc;
} }
v49->flags |= BUTTON_FLAG_0x020000; v49->flags |= BUTTON_FLAG_CHECKED;
} }
} }
} else { } else {
if (v49->flags & BUTTON_FLAG_0x020000) { if (v49->flags & BUTTON_FLAG_CHECKED) {
if (v49->radioGroup != NULL) { if (v49->buttonGroup != NULL) {
v49->radioGroup->field_4--; v49->buttonGroup->currChecked--;
} }
} }
@ -1967,9 +1963,9 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
} }
if (button->hoverImage != NULL) { if (button->hoverImage != NULL) {
_button_draw(button, window, button->hoverImage, 1, NULL, 1); _button_draw(button, window, button->hoverImage, true, NULL, true);
} else { } else {
_button_draw(button, window, button->normalImage, 1, NULL, 1); _button_draw(button, window, button->normalImage, true, NULL, true);
} }
break; break;
} }
@ -1982,7 +1978,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
cb = button->mouseEnterProc; cb = button->mouseEnterProc;
} }
_button_draw(button, window, button->hoverImage, 1, NULL, 1); _button_draw(button, window, button->hoverImage, true, NULL, true);
} }
break; break;
} }
@ -1995,7 +1991,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
&& (mouseEvent & MOUSE_EVENT_ANY_BUTTON_DOWN) != 0 && (mouseEvent & MOUSE_EVENT_ANY_BUTTON_DOWN) != 0
&& (mouseEvent & MOUSE_EVENT_ANY_BUTTON_REPEAT) == 0) { && (mouseEvent & MOUSE_EVENT_ANY_BUTTON_REPEAT) == 0) {
_win_drag(window->id); _win_drag(window->id);
_button_draw(button, window, button->normalImage, 1, NULL, 1); _button_draw(button, window, button->normalImage, true, NULL, true);
} }
} else if ((window->flags & WINDOW_FLAG_0x80) != 0) { } else if ((window->flags & WINDOW_FLAG_0x80) != 0) {
v25 |= mouseEvent << 8; v25 |= mouseEvent << 8;
@ -2023,13 +2019,13 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr)
*keyCodePtr = prevHoveredButton->mouseExitEventCode; *keyCodePtr = prevHoveredButton->mouseExitEventCode;
unsigned char* data; unsigned char* data;
if ((prevHoveredButton->flags & BUTTON_FLAG_0x01) && (prevHoveredButton->flags & BUTTON_FLAG_0x020000)) { if ((prevHoveredButton->flags & BUTTON_FLAG_0x01) && (prevHoveredButton->flags & BUTTON_FLAG_CHECKED)) {
data = prevHoveredButton->pressedImage; data = prevHoveredButton->pressedImage;
} else { } else {
data = prevHoveredButton->normalImage; data = prevHoveredButton->normalImage;
} }
_button_draw(prevHoveredButton, window, data, 1, NULL, 1); _button_draw(prevHoveredButton, window, data, true, NULL, true);
window->hoveredButton = NULL; window->hoveredButton = NULL;
} }
@ -2142,7 +2138,7 @@ int buttonDestroy(int btn)
// 0x4D9374 // 0x4D9374
void buttonFree(Button* button) void buttonFree(Button* button)
{ {
if ((button->flags & BUTTON_FLAG_0x010000) == 0) { if ((button->flags & BUTTON_FLAG_GRAPHIC) == 0) {
if (button->normalImage != NULL) { if (button->normalImage != NULL) {
internal_free(button->normalImage); internal_free(button->normalImage);
} }
@ -2168,15 +2164,15 @@ void buttonFree(Button* button)
} }
} }
RadioGroup* radioGroup = button->radioGroup; ButtonGroup* buttonGroup = button->buttonGroup;
if (radioGroup != NULL) { if (buttonGroup != NULL) {
for (int index = 0; index < radioGroup->buttonsLength; index++) { for (int index = 0; index < buttonGroup->buttonsLength; index++) {
if (button == radioGroup->buttons[index]) { if (button == buttonGroup->buttons[index]) {
for (; index < radioGroup->buttonsLength - 1; index++) { for (; index < buttonGroup->buttonsLength - 1; index++) {
radioGroup->buttons[index] = radioGroup->buttons[index + 1]; buttonGroup->buttons[index] = buttonGroup->buttons[index + 1];
} }
radioGroup->buttonsLength--; buttonGroup->buttonsLength--;
break; break;
} }
@ -2216,7 +2212,7 @@ int buttonEnable(int btn)
if ((button->flags & BUTTON_FLAG_DISABLED) != 0) { if ((button->flags & BUTTON_FLAG_DISABLED) != 0) {
button->flags &= ~BUTTON_FLAG_DISABLED; button->flags &= ~BUTTON_FLAG_DISABLED;
_button_draw(button, window, button->currentImage, 1, NULL, 0); _button_draw(button, window, button->currentImage, true, NULL, false);
} }
return 0; return 0;
@ -2238,7 +2234,7 @@ int buttonDisable(int btn)
if ((button->flags & BUTTON_FLAG_DISABLED) == 0) { if ((button->flags & BUTTON_FLAG_DISABLED) == 0) {
button->flags |= BUTTON_FLAG_DISABLED; button->flags |= BUTTON_FLAG_DISABLED;
_button_draw(button, window, button->currentImage, 1, NULL, 0); _button_draw(button, window, button->currentImage, true, NULL, false);
if (button == window->hoveredButton) { if (button == window->hoveredButton) {
if (window->hoveredButton->mouseExitEventCode != -1) { if (window->hoveredButton->mouseExitEventCode != -1) {
@ -2252,7 +2248,7 @@ int buttonDisable(int btn)
} }
// 0x4D9554 // 0x4D9554
int _win_set_button_rest_state(int btn, bool a2, int a3) int _win_set_button_rest_state(int btn, bool checked, int flags)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
@ -2267,30 +2263,30 @@ int _win_set_button_rest_state(int btn, bool a2, int a3)
if ((button->flags & BUTTON_FLAG_0x01) != 0) { if ((button->flags & BUTTON_FLAG_0x01) != 0) {
int keyCode = -1; int keyCode = -1;
if ((button->flags & BUTTON_FLAG_0x020000) != 0) { if ((button->flags & BUTTON_FLAG_CHECKED) != 0) {
if (!a2) { if (!checked) {
button->flags &= ~BUTTON_FLAG_0x020000; button->flags &= ~BUTTON_FLAG_CHECKED;
if ((a3 & 0x02) == 0) { if ((flags & 0x02) == 0) {
_button_draw(button, window, button->normalImage, 1, NULL, 0); _button_draw(button, window, button->normalImage, true, NULL, false);
} }
if (button->radioGroup != NULL) { if (button->buttonGroup != NULL) {
button->radioGroup->field_4--; button->buttonGroup->currChecked--;
} }
keyCode = button->leftMouseUpEventCode; keyCode = button->leftMouseUpEventCode;
} }
} else { } else {
if (a2) { if (checked) {
button->flags |= BUTTON_FLAG_0x020000; button->flags |= BUTTON_FLAG_CHECKED;
if ((a3 & 0x02) == 0) { if ((flags & 0x02) == 0) {
_button_draw(button, window, button->pressedImage, 1, NULL, 0); _button_draw(button, window, button->pressedImage, true, NULL, false);
} }
if (button->radioGroup != NULL) { if (button->buttonGroup != NULL) {
button->radioGroup->field_4++; button->buttonGroup->currChecked++;
} }
keyCode = button->lefMouseDownEventCode; keyCode = button->lefMouseDownEventCode;
@ -2298,7 +2294,7 @@ int _win_set_button_rest_state(int btn, bool a2, int a3)
} }
if (keyCode != -1) { if (keyCode != -1) {
if ((a3 & 0x01) != 0) { if ((flags & 0x01) != 0) {
enqueueInputEvent(keyCode); enqueueInputEvent(keyCode);
} }
} }
@ -2308,20 +2304,20 @@ int _win_set_button_rest_state(int btn, bool a2, int a3)
} }
// 0x4D962C // 0x4D962C
int _win_group_check_buttons(int buttonCount, int* btns, int a3, void (*a4)(int)) int _win_group_check_buttons(int buttonCount, int* btns, int maxChecked, RadioButtonCallback* func)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
} }
if (buttonCount >= RADIO_GROUP_BUTTON_LIST_CAPACITY) { if (buttonCount >= BUTTON_GROUP_BUTTON_LIST_CAPACITY) {
return -1; return -1;
} }
for (int groupIndex = 0; groupIndex < RADIO_GROUP_LIST_CAPACITY; groupIndex++) { for (int groupIndex = 0; groupIndex < BUTTON_GROUP_LIST_CAPACITY; groupIndex++) {
RadioGroup* radioGroup = &(gRadioGroups[groupIndex]); ButtonGroup* buttonGroup = &(gButtonGroups[groupIndex]);
if (radioGroup->buttonsLength == 0) { if (buttonGroup->buttonsLength == 0) {
radioGroup->field_4 = 0; buttonGroup->currChecked = 0;
for (int buttonIndex = 0; buttonIndex < buttonCount; buttonIndex++) { for (int buttonIndex = 0; buttonIndex < buttonCount; buttonIndex++) {
Button* button = buttonGetButton(btns[buttonIndex], NULL); Button* button = buttonGetButton(btns[buttonIndex], NULL);
@ -2329,18 +2325,18 @@ int _win_group_check_buttons(int buttonCount, int* btns, int a3, void (*a4)(int)
return -1; return -1;
} }
radioGroup->buttons[buttonIndex] = button; buttonGroup->buttons[buttonIndex] = button;
button->radioGroup = radioGroup; button->buttonGroup = buttonGroup;
if ((button->flags & BUTTON_FLAG_0x020000) != 0) { if ((button->flags & BUTTON_FLAG_CHECKED) != 0) {
radioGroup->field_4++; buttonGroup->currChecked++;
} }
} }
radioGroup->buttonsLength = buttonCount; buttonGroup->buttonsLength = buttonCount;
radioGroup->field_0 = a3; buttonGroup->maxChecked = maxChecked;
radioGroup->field_8 = a4; buttonGroup->func = func;
return 0; return 0;
} }
} }
@ -2360,11 +2356,11 @@ int _win_group_radio_buttons(int count, int* btns)
} }
Button* button = buttonGetButton(btns[0], NULL); Button* button = buttonGetButton(btns[0], NULL);
RadioGroup* radioGroup = button->radioGroup; ButtonGroup* buttonGroup = button->buttonGroup;
for (int index = 0; index < radioGroup->buttonsLength; index++) { for (int index = 0; index < buttonGroup->buttonsLength; index++) {
Button* v1 = radioGroup->buttons[index]; Button* v1 = buttonGroup->buttons[index];
v1->flags |= BUTTON_FLAG_0x040000; v1->flags |= BUTTON_FLAG_RADIO;
} }
return 0; return 0;
@ -2373,20 +2369,20 @@ int _win_group_radio_buttons(int count, int* btns)
// 0x4D9744 // 0x4D9744
int _button_check_group(Button* button) int _button_check_group(Button* button)
{ {
if (button->radioGroup == NULL) { if (button->buttonGroup == NULL) {
return 0; return 0;
} }
if ((button->flags & BUTTON_FLAG_0x040000) != 0) { if ((button->flags & BUTTON_FLAG_RADIO) != 0) {
if (button->radioGroup->field_4 > 0) { if (button->buttonGroup->currChecked > 0) {
for (int index = 0; index < button->radioGroup->buttonsLength; index++) { for (int index = 0; index < button->buttonGroup->buttonsLength; index++) {
Button* v1 = button->radioGroup->buttons[index]; Button* v1 = button->buttonGroup->buttons[index];
if ((v1->flags & BUTTON_FLAG_0x020000) != 0) { if ((v1->flags & BUTTON_FLAG_CHECKED) != 0) {
v1->flags &= ~BUTTON_FLAG_0x020000; v1->flags &= ~BUTTON_FLAG_CHECKED;
Window* window; Window* window;
buttonGetButton(v1->id, &window); buttonGetButton(v1->id, &window);
_button_draw(v1, window, v1->normalImage, 1, NULL, 1); _button_draw(v1, window, v1->normalImage, true, NULL, true);
if (v1->leftMouseUpProc != NULL) { if (v1->leftMouseUpProc != NULL) {
v1->leftMouseUpProc(v1->id, v1->leftMouseUpEventCode); v1->leftMouseUpProc(v1->id, v1->leftMouseUpEventCode);
@ -2395,30 +2391,30 @@ int _button_check_group(Button* button)
} }
} }
if ((button->flags & BUTTON_FLAG_0x020000) == 0) { if ((button->flags & BUTTON_FLAG_CHECKED) == 0) {
button->radioGroup->field_4++; button->buttonGroup->currChecked++;
} }
return 0; return 0;
} }
if (button->radioGroup->field_4 < button->radioGroup->field_0) { if (button->buttonGroup->currChecked < button->buttonGroup->maxChecked) {
if ((button->flags & BUTTON_FLAG_0x020000) == 0) { if ((button->flags & BUTTON_FLAG_CHECKED) == 0) {
button->radioGroup->field_4++; button->buttonGroup->currChecked++;
} }
return 0; return 0;
} }
if (button->radioGroup->field_8 != NULL) { if (button->buttonGroup->func != NULL) {
button->radioGroup->field_8(button->id); button->buttonGroup->func(button->id);
} }
return -1; return -1;
} }
// 0x4D9808 // 0x4D9808
void _button_draw(Button* button, Window* window, unsigned char* data, int a4, Rect* a5, int a6) void _button_draw(Button* button, Window* window, unsigned char* data, bool draw, Rect* bound, bool sound)
{ {
unsigned char* previousImage = NULL; unsigned char* previousImage = NULL;
if (data != NULL) { if (data != NULL) {
@ -2427,8 +2423,8 @@ void _button_draw(Button* button, Window* window, unsigned char* data, int a4, R
rectOffset(&v2, window->rect.left, window->rect.top); rectOffset(&v2, window->rect.left, window->rect.top);
Rect v3; Rect v3;
if (a5 != NULL) { if (bound != NULL) {
if (rectIntersection(&v2, a5, &v2) == -1) { if (rectIntersection(&v2, bound, &v2) == -1) {
return; return;
} }
@ -2438,7 +2434,7 @@ void _button_draw(Button* button, Window* window, unsigned char* data, int a4, R
rectCopy(&v3, &(button->rect)); rectCopy(&v3, &(button->rect));
} }
if (data == button->normalImage && (button->flags & BUTTON_FLAG_0x020000)) { if (data == button->normalImage && (button->flags & BUTTON_FLAG_CHECKED)) {
data = button->pressedImage; data = button->pressedImage;
} }
@ -2461,7 +2457,7 @@ void _button_draw(Button* button, Window* window, unsigned char* data, int a4, R
} }
if (data) { if (data) {
if (a4 == 0) { if (!draw) {
int width = button->rect.right - button->rect.left + 1; int width = button->rect.right - button->rect.left + 1;
if ((button->flags & BUTTON_FLAG_TRANSPARENT) != 0) { if ((button->flags & BUTTON_FLAG_TRANSPARENT) != 0) {
blitBufferToBufferTrans( blitBufferToBufferTrans(
@ -2485,18 +2481,18 @@ void _button_draw(Button* button, Window* window, unsigned char* data, int a4, R
previousImage = button->currentImage; previousImage = button->currentImage;
button->currentImage = data; button->currentImage = data;
if (a4 != 0) { if (draw) {
_GNW_win_refresh(window, &v2, 0); _GNW_win_refresh(window, &v2, 0);
} }
} }
} }
if (a6) { if (sound) {
if (previousImage != data) { if (previousImage != data) {
if (data == button->pressedImage && button->onPressed != NULL) { if (data == button->pressedImage && button->pressSoundFunc != NULL) {
button->onPressed(button->id, button->lefMouseDownEventCode); button->pressSoundFunc(button->id, button->lefMouseDownEventCode);
} else if (data == button->normalImage && button->onUnpressed != NULL) { } else if (data == button->normalImage && button->releaseSoundFunc != NULL) {
button->onUnpressed(button->id, button->leftMouseUpEventCode); button->releaseSoundFunc(button->id, button->leftMouseUpEventCode);
} }
} }
} }
@ -2513,7 +2509,7 @@ void _GNW_button_refresh(Window* window, Rect* rect)
} }
while (button != NULL) { while (button != NULL) {
_button_draw(button, window, button->currentImage, 0, rect, 0); _button_draw(button, window, button->currentImage, false, rect, false);
button = button->prev; button = button->prev;
} }
} }
@ -2531,7 +2527,7 @@ int _win_button_press_and_release(int btn)
return -1; return -1;
} }
_button_draw(button, window, button->pressedImage, 1, NULL, 1); _button_draw(button, window, button->pressedImage, true, NULL, true);
if (button->leftMouseDownProc != NULL) { if (button->leftMouseDownProc != NULL) {
button->leftMouseDownProc(btn, button->lefMouseDownEventCode); button->leftMouseDownProc(btn, button->lefMouseDownEventCode);
@ -2545,7 +2541,7 @@ int _win_button_press_and_release(int btn)
} }
} }
_button_draw(button, window, button->normalImage, 1, NULL, 1); _button_draw(button, window, button->normalImage, true, NULL, true);
if (button->leftMouseUpProc != NULL) { if (button->leftMouseUpProc != NULL) {
button->leftMouseUpProc(btn, button->leftMouseUpEventCode); button->leftMouseUpProc(btn, button->leftMouseUpEventCode);

View File

@ -8,7 +8,7 @@
namespace fallout { namespace fallout {
// The maximum number of buttons in one radio group. // The maximum number of buttons in one radio group.
#define RADIO_GROUP_BUTTON_LIST_CAPACITY (64) #define BUTTON_GROUP_BUTTON_LIST_CAPACITY (64)
typedef enum WindowManagerErr { typedef enum WindowManagerErr {
WINDOW_MANAGER_OK = 0, WINDOW_MANAGER_OK = 0,
@ -55,9 +55,9 @@ typedef enum ButtonFlags {
BUTTON_FLAG_0x10 = 0x10, BUTTON_FLAG_0x10 = 0x10,
BUTTON_FLAG_TRANSPARENT = 0x20, BUTTON_FLAG_TRANSPARENT = 0x20,
BUTTON_FLAG_0x40 = 0x40, BUTTON_FLAG_0x40 = 0x40,
BUTTON_FLAG_0x010000 = 0x010000, BUTTON_FLAG_GRAPHIC = 0x010000,
BUTTON_FLAG_0x020000 = 0x020000, BUTTON_FLAG_CHECKED = 0x020000,
BUTTON_FLAG_0x040000 = 0x040000, BUTTON_FLAG_RADIO = 0x040000,
BUTTON_FLAG_RIGHT_MOUSE_BUTTON_CONFIGURED = 0x080000, BUTTON_FLAG_RIGHT_MOUSE_BUTTON_CONFIGURED = 0x080000,
} ButtonFlags; } ButtonFlags;
@ -66,8 +66,8 @@ typedef struct MenuPulldown {
int keyCode; int keyCode;
int itemsLength; int itemsLength;
char** items; char** items;
int field_1C; int foregroundColor;
int field_20; int backgroundColor;
} MenuPulldown; } MenuPulldown;
typedef struct MenuBar { typedef struct MenuBar {
@ -75,14 +75,14 @@ typedef struct MenuBar {
Rect rect; Rect rect;
int pulldownsLength; int pulldownsLength;
MenuPulldown pulldowns[15]; MenuPulldown pulldowns[15];
int borderColor; int foregroundColor;
int backgroundColor; int backgroundColor;
} MenuBar; } MenuBar;
typedef void WindowBlitProc(unsigned char* src, int width, int height, int srcPitch, unsigned char* dest, int destPitch); typedef void WindowBlitProc(unsigned char* src, int width, int height, int srcPitch, unsigned char* dest, int destPitch);
typedef struct Button Button; typedef struct Button Button;
typedef struct RadioGroup RadioGroup; typedef struct ButtonGroup ButtonGroup;
typedef struct Window { typedef struct Window {
int id; int id;
@ -102,6 +102,7 @@ typedef struct Window {
} Window; } Window;
typedef void ButtonCallback(int btn, int keyCode); typedef void ButtonCallback(int btn, int keyCode);
typedef void RadioButtonCallback(int btn);
typedef struct Button { typedef struct Button {
int id; int id;
@ -127,20 +128,20 @@ typedef struct Button {
ButtonCallback* leftMouseUpProc; ButtonCallback* leftMouseUpProc;
ButtonCallback* rightMouseDownProc; ButtonCallback* rightMouseDownProc;
ButtonCallback* rightMouseUpProc; ButtonCallback* rightMouseUpProc;
ButtonCallback* onPressed; ButtonCallback* pressSoundFunc;
ButtonCallback* onUnpressed; ButtonCallback* releaseSoundFunc;
RadioGroup* radioGroup; ButtonGroup* buttonGroup;
Button* prev; Button* prev;
Button* next; Button* next;
} Button; } Button;
typedef struct RadioGroup { typedef struct ButtonGroup {
int field_0; int maxChecked;
int field_4; int currChecked;
void (*field_8)(int); RadioButtonCallback* func;
int buttonsLength; int buttonsLength;
Button* buttons[RADIO_GROUP_BUTTON_LIST_CAPACITY]; Button* buttons[BUTTON_GROUP_BUTTON_LIST_CAPACITY];
} RadioGroup; } ButtonGroup;
typedef int(VideoSystemInitProc)(); typedef int(VideoSystemInitProc)();
typedef void(VideoSystemExitProc)(); typedef void(VideoSystemExitProc)();
@ -157,7 +158,7 @@ void windowDrawText(int win, const char* str, int a3, int x, int y, int a6);
void _win_text(int win, char** fileNameList, int fileNameListLength, int maxWidth, int x, int y, int flags); void _win_text(int win, char** fileNameList, int fileNameListLength, int maxWidth, int x, int y, int flags);
void windowDrawLine(int win, int left, int top, int right, int bottom, int color); void windowDrawLine(int win, int left, int top, int right, int bottom, int color);
void windowDrawRect(int win, int left, int top, int right, int bottom, int color); void windowDrawRect(int win, int left, int top, int right, int bottom, int color);
void windowFill(int win, int x, int y, int width, int height, int a6); void windowFill(int win, int x, int y, int width, int height, int color);
void windowShow(int win); void windowShow(int win);
void windowHide(int win); void windowHide(int win);
void windowRefresh(int win); void windowRefresh(int win);
@ -178,10 +179,10 @@ bool showMesageBox(const char* str);
int buttonCreate(int win, int x, int y, int width, int height, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, unsigned char* up, unsigned char* dn, unsigned char* hover, int flags); int buttonCreate(int win, int x, int y, int width, int height, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, unsigned char* up, unsigned char* dn, unsigned char* hover, int flags);
int _win_register_text_button(int win, int x, int y, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, const char* title, int flags); int _win_register_text_button(int win, int x, int y, int mouseEnterEventCode, int mouseExitEventCode, int mouseDownEventCode, int mouseUpEventCode, const char* title, int flags);
int _win_register_button_disable(int btn, unsigned char* up, unsigned char* down, unsigned char* hover); int _win_register_button_disable(int btn, unsigned char* up, unsigned char* down, unsigned char* hover);
int _win_register_button_image(int btn, unsigned char* up, unsigned char* down, unsigned char* hover, int a5); int _win_register_button_image(int btn, unsigned char* up, unsigned char* down, unsigned char* hover, bool draw);
int buttonSetMouseCallbacks(int btn, ButtonCallback* mouseEnterProc, ButtonCallback* mouseExitProc, ButtonCallback* mouseDownProc, ButtonCallback* mouseUpProc); int buttonSetMouseCallbacks(int btn, ButtonCallback* mouseEnterProc, ButtonCallback* mouseExitProc, ButtonCallback* mouseDownProc, ButtonCallback* mouseUpProc);
int buttonSetRightMouseCallbacks(int btn, int rightMouseDownEventCode, int rightMouseUpEventCode, ButtonCallback* rightMouseDownProc, ButtonCallback* rightMouseUpProc); int buttonSetRightMouseCallbacks(int btn, int rightMouseDownEventCode, int rightMouseUpEventCode, ButtonCallback* rightMouseDownProc, ButtonCallback* rightMouseUpProc);
int buttonSetCallbacks(int btn, ButtonCallback* onPressed, ButtonCallback* onUnpressed); int buttonSetCallbacks(int btn, ButtonCallback* pressSoundFunc, ButtonCallback* releaseSoundFunc);
int buttonSetMask(int btn, unsigned char* mask); int buttonSetMask(int btn, unsigned char* mask);
bool _win_button_down(int btn); bool _win_button_down(int btn);
int buttonGetWindowId(int btn); int buttonGetWindowId(int btn);
@ -189,8 +190,8 @@ int _win_last_button_winID();
int buttonDestroy(int btn); int buttonDestroy(int btn);
int buttonEnable(int btn); int buttonEnable(int btn);
int buttonDisable(int btn); int buttonDisable(int btn);
int _win_set_button_rest_state(int btn, bool a2, int a3); int _win_set_button_rest_state(int btn, bool checked, int flags);
int _win_group_radio_buttons(int a1, int* a2); int _win_group_radio_buttons(int buttonCount, int* btns);
int _win_button_press_and_release(int btn); int _win_button_press_and_release(int btn);
} // namespace fallout } // namespace fallout

View File

@ -79,13 +79,13 @@ static int _currx;
char gProgramWindowTitle[256]; char gProgramWindowTitle[256];
// 0x4DA6C0 // 0x4DA6C0
int _win_list_select(const char* title, char** fileList, int fileListLength, ListSelectionHandler* callback, int x, int y, int a7) int _win_list_select(const char* title, char** fileList, int fileListLength, ListSelectionHandler* callback, int x, int y, int color)
{ {
return _win_list_select_at(title, fileList, fileListLength, callback, x, y, a7, 0); return _win_list_select_at(title, fileList, fileListLength, callback, x, y, color, 0);
} }
// 0x4DA70C // 0x4DA70C
int _win_list_select_at(const char* title, char** items, int itemsLength, ListSelectionHandler* callback, int x, int y, int a7, int a8) int _win_list_select_at(const char* title, char** items, int itemsLength, ListSelectionHandler* callback, int x, int y, int color, int start)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
@ -170,8 +170,8 @@ int _win_list_select_at(const char* title, char** items, int itemsLength, ListSe
windowWidth, windowWidth,
_colorTable[_GNW_wcolor[0]]); _colorTable[_GNW_wcolor[0]]);
int scrollOffset = a8; int scrollOffset = start;
if (a8 < 0 || a8 >= itemsLength) { if (start < 0 || start >= itemsLength) {
scrollOffset = 0; scrollOffset = 0;
} }
@ -189,14 +189,13 @@ int _win_list_select_at(const char* title, char** items, int itemsLength, ListSe
selectedItemIndex = 0; selectedItemIndex = 0;
} }
char** itemsTO = items + a8;
_win_text(win, _win_text(win,
items + a8, items + start,
itemsLength < listViewCapacity ? itemsLength : listViewCapacity, itemsLength < listViewCapacity ? itemsLength : listViewCapacity,
listViewWidth, listViewWidth,
listViewX, listViewX,
listViewY, listViewY,
a7 | 0x2000000); color | 0x2000000);
_lighten_buf(listViewBuffer + windowWidth * selectedItemIndex * fontGetLineHeight(), _lighten_buf(listViewBuffer + windowWidth * selectedItemIndex * fontGetLineHeight(),
listViewWidth, listViewWidth,
@ -452,7 +451,7 @@ int _win_list_select_at(const char* title, char** items, int itemsLength, ListSe
listViewWidth, listViewWidth,
listViewX, listViewX,
listViewY, listViewY,
a7 | 0x2000000); color | 0x2000000);
_lighten_buf(listViewBuffer + windowWidth * selectedItemIndex * fontGetLineHeight(), _lighten_buf(listViewBuffer + windowWidth * selectedItemIndex * fontGetLineHeight(),
listViewWidth, listViewWidth,
@ -500,19 +499,19 @@ int _win_list_select_at(const char* title, char** items, int itemsLength, ListSe
windowWidth, windowWidth,
_colorTable[_GNW_wcolor[0]]); _colorTable[_GNW_wcolor[0]]);
int color; int textColor;
if ((a7 & 0xFF00) != 0) { if ((color & 0xFF00) != 0) {
int colorIndex = (a7 & 0xFF) - 1; int colorIndex = (color & 0xFF) - 1;
color = (a7 & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]]; textColor = (color & ~0xFFFF) | _colorTable[_GNW_wcolor[colorIndex]];
} else { } else {
color = a7; textColor = color;
} }
fontDrawText(listViewBuffer + windowWidth * previousSelectedItemIndex * fontGetLineHeight(), fontDrawText(listViewBuffer + windowWidth * previousSelectedItemIndex * fontGetLineHeight(),
items[scrollOffset + previousSelectedItemIndex], items[scrollOffset + previousSelectedItemIndex],
windowWidth, windowWidth,
windowWidth, windowWidth,
color); textColor);
_GNW_win_refresh(window, &itemRect, NULL); _GNW_win_refresh(window, &itemRect, NULL);
} }
@ -619,7 +618,7 @@ int _win_get_str(char* dest, int length, const char* title, int x, int y)
} }
// 0x4DBA98 // 0x4DBA98
int _win_msg(const char* string, int x, int y, int flags) int _win_msg(const char* string, int x, int y, int color)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
@ -644,16 +643,16 @@ int _win_msg(const char* string, int x, int y, int flags)
Window* window = windowGetWindow(win); Window* window = windowGetWindow(win);
unsigned char* windowBuffer = window->buffer; unsigned char* windowBuffer = window->buffer;
int color; int textColor;
if ((flags & 0xFF00) != 0) { if ((color & 0xFF00) != 0) {
int index = (flags & 0xFF) - 1; int index = (color & 0xFF) - 1;
color = _colorTable[_GNW_wcolor[index]]; textColor = _colorTable[_GNW_wcolor[index]];
color |= flags & ~0xFFFF; textColor |= color & ~0xFFFF;
} else { } else {
color = flags; textColor = color;
} }
fontDrawText(windowBuffer + windowWidth * 8 + 16, string, windowWidth, windowWidth, color); fontDrawText(windowBuffer + windowWidth * 8 + 16, string, windowWidth, windowWidth, textColor);
_win_register_text_button(win, _win_register_text_button(win,
windowWidth / 2 - 32, windowWidth / 2 - 32,
@ -679,23 +678,23 @@ int _win_msg(const char* string, int x, int y, int flags)
} }
// 0x4DBBC4 // 0x4DBBC4
int _win_pull_down(char** items, int itemsLength, int x, int y, int a5) int _win_pull_down(char** items, int itemsLength, int x, int y, int color)
{ {
if (!gWindowSystemInitialized) { if (!gWindowSystemInitialized) {
return -1; return -1;
} }
Rect rect; Rect rect;
int win = _create_pull_down(items, itemsLength, x, y, a5, _colorTable[_GNW_wcolor[0]], &rect); int win = _create_pull_down(items, itemsLength, x, y, color, _colorTable[_GNW_wcolor[0]], &rect);
if (win == -1) { if (win == -1) {
return -1; return -1;
} }
return sub_4DBD04(win, &rect, items, itemsLength, a5, _colorTable[_GNW_wcolor[0]], NULL, -1); return process_pull_down(win, &rect, items, itemsLength, color, _colorTable[_GNW_wcolor[0]], NULL, -1);
} }
// 0x4DBC34 // 0x4DBC34
int _create_pull_down(char** stringList, int stringListLength, int x, int y, int a5, int a6, Rect* rect) int _create_pull_down(char** stringList, int stringListLength, int x, int y, int foregroundColor, int backgroundColor, Rect* rect)
{ {
int windowHeight = stringListLength * fontGetLineHeight() + 16; int windowHeight = stringListLength * fontGetLineHeight() + 16;
int windowWidth = _win_width_needed(stringList, stringListLength) + 4; int windowWidth = _win_width_needed(stringList, stringListLength) + 4;
@ -703,14 +702,14 @@ int _create_pull_down(char** stringList, int stringListLength, int x, int y, int
return -1; return -1;
} }
int win = windowCreate(x, y, windowWidth, windowHeight, a6, WINDOW_MODAL | WINDOW_MOVE_ON_TOP); int win = windowCreate(x, y, windowWidth, windowHeight, backgroundColor, WINDOW_MODAL | WINDOW_MOVE_ON_TOP);
if (win == -1) { if (win == -1) {
return -1; return -1;
} }
_win_text(win, stringList, stringListLength, windowWidth - 4, 2, 8, a5); _win_text(win, stringList, stringListLength, windowWidth - 4, 2, 8, foregroundColor);
windowDrawRect(win, 0, 0, windowWidth - 1, windowHeight - 1, _colorTable[0]); windowDrawRect(win, 0, 0, windowWidth - 1, windowHeight - 1, _colorTable[0]);
windowDrawRect(win, 1, 1, windowWidth - 2, windowHeight - 2, a5); windowDrawRect(win, 1, 1, windowWidth - 2, windowHeight - 2, foregroundColor);
windowRefresh(win); windowRefresh(win);
windowGetRect(win, rect); windowGetRect(win, rect);
@ -841,7 +840,7 @@ void _win_debug_delete(int btn, int keyCode)
} }
// 0x4DC674 // 0x4DC674
int _win_register_menu_bar(int win, int x, int y, int width, int height, int borderColor, int backgroundColor) int _win_register_menu_bar(int win, int x, int y, int width, int height, int foregroundColor, int backgroundColor)
{ {
Window* window = windowGetWindow(win); Window* window = windowGetWindow(win);
@ -878,17 +877,17 @@ int _win_register_menu_bar(int win, int x, int y, int width, int height, int bor
menuBar->rect.right = right - 1; menuBar->rect.right = right - 1;
menuBar->rect.bottom = bottom - 1; menuBar->rect.bottom = bottom - 1;
menuBar->pulldownsLength = 0; menuBar->pulldownsLength = 0;
menuBar->borderColor = borderColor; menuBar->foregroundColor = foregroundColor;
menuBar->backgroundColor = backgroundColor; menuBar->backgroundColor = backgroundColor;
windowFill(win, x, y, width, height, backgroundColor); windowFill(win, x, y, width, height, backgroundColor);
windowDrawRect(win, x, y, right - 1, bottom - 1, borderColor); windowDrawRect(win, x, y, right - 1, bottom - 1, foregroundColor);
return 0; return 0;
} }
// 0x4DC768 // 0x4DC768
int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int itemsLength, char** items, int a7, int a8) int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int itemsLength, char** items, int foregroundColor, int backgroundColor)
{ {
Window* window = windowGetWindow(win); Window* window = windowGetWindow(win);
@ -928,7 +927,7 @@ int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int it
return -1; return -1;
} }
windowDrawText(win, title, 0, titleX, titleY, window->menuBar->borderColor | 0x2000000); windowDrawText(win, title, 0, titleX, titleY, window->menuBar->foregroundColor | 0x2000000);
MenuPulldown* pulldown = &(window->menuBar->pulldowns[window->menuBar->pulldownsLength]); MenuPulldown* pulldown = &(window->menuBar->pulldowns[window->menuBar->pulldownsLength]);
pulldown->rect.left = titleX; pulldown->rect.left = titleX;
@ -938,8 +937,8 @@ int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int it
pulldown->keyCode = keyCode; pulldown->keyCode = keyCode;
pulldown->itemsLength = itemsLength; pulldown->itemsLength = itemsLength;
pulldown->items = items; pulldown->items = items;
pulldown->field_1C = a7; pulldown->foregroundColor = foregroundColor;
pulldown->field_20 = a8; pulldown->backgroundColor = backgroundColor;
window->menuBar->pulldownsLength++; window->menuBar->pulldownsLength++;
@ -1120,7 +1119,7 @@ int _win_input_str(int win, char* dest, int maxLength, int x, int y, int textCol
} }
// 0x4DBD04 // 0x4DBD04
int sub_4DBD04(int win, Rect* rect, char** items, int itemsLength, int a5, int a6, MenuBar* menuBar, int pulldownIndex) int process_pull_down(int win, Rect* rect, char** items, int itemsLength, int foregroundColor, int backgroundColor, MenuBar* menuBar, int pulldownIndex)
{ {
// TODO: Incomplete. // TODO: Incomplete.
return -1; return -1;
@ -1143,15 +1142,15 @@ int _GNW_process_menu(MenuBar* menuBar, int pulldownIndex)
pulldown->itemsLength, pulldown->itemsLength,
pulldown->rect.left, pulldown->rect.left,
menuBar->rect.bottom + 1, menuBar->rect.bottom + 1,
pulldown->field_1C, pulldown->foregroundColor,
pulldown->field_20, pulldown->backgroundColor,
&rect); &rect);
if (win == -1) { if (win == -1) {
_curr_menu = NULL; _curr_menu = NULL;
return -1; return -1;
} }
keyCode = sub_4DBD04(win, &rect, pulldown->items, pulldown->itemsLength, pulldown->field_1C, pulldown->field_20, menuBar, pulldownIndex); keyCode = process_pull_down(win, &rect, pulldown->items, pulldown->itemsLength, pulldown->foregroundColor, pulldown->backgroundColor, menuBar, pulldownIndex);
if (keyCode < -1) { if (keyCode < -1) {
pulldownIndex = -2 - keyCode; pulldownIndex = -2 - keyCode;
} }
@ -1168,20 +1167,20 @@ int _GNW_process_menu(MenuBar* menuBar, int pulldownIndex)
return keyCode; return keyCode;
} }
// Calculates max length of string needed to represent a1 or a2. // Calculates max length of string needed to represent `value` or `value2`.
// //
// 0x4DD03C // 0x4DD03C
size_t _calc_max_field_chars_wcursor(int a1, int a2) size_t _calc_max_field_chars_wcursor(int value1, int value2)
{ {
char* str = (char*)internal_malloc(17); char* str = (char*)internal_malloc(17);
if (str == NULL) { if (str == NULL) {
return -1; return -1;
} }
snprintf(str, 17, "%d", a1); snprintf(str, 17, "%d", value1);
size_t len1 = strlen(str); size_t len1 = strlen(str);
snprintf(str, 17, "%d", a2); snprintf(str, 17, "%d", value2);
size_t len2 = strlen(str); size_t len2 = strlen(str);
internal_free(str); internal_free(str);
@ -1272,7 +1271,7 @@ void _tm_kill_msg()
} }
// 0x4DD744 // 0x4DD744
void _tm_kill_out_of_order(int a1) void _tm_kill_out_of_order(int queueIndex)
{ {
int v7; int v7;
int v6; int v6;
@ -1281,16 +1280,16 @@ void _tm_kill_out_of_order(int a1)
return; return;
} }
if (!_tm_index_active(a1)) { if (!_tm_index_active(queueIndex)) {
return; return;
} }
windowDestroy(_tm_queue[a1].field_4); windowDestroy(_tm_queue[queueIndex].field_4);
_tm_location[_tm_queue[a1].field_8].field_0 = 0; _tm_location[_tm_queue[queueIndex].field_8].field_0 = 0;
if (a1 != _tm_kill) { if (queueIndex != _tm_kill) {
v6 = a1; v6 = queueIndex;
do { do {
v7 = v6 - 1; v7 = v6 - 1;
if (v7 < 0) { if (v7 < 0) {
@ -1317,35 +1316,35 @@ void _tm_kill_out_of_order(int a1)
void _tm_click_response(int btn) void _tm_click_response(int btn)
{ {
int win; int win;
int v3; int queueIndex;
if (_tm_kill == -1) { if (_tm_kill == -1) {
return; return;
} }
win = buttonGetWindowId(btn); win = buttonGetWindowId(btn);
v3 = _tm_kill; queueIndex = _tm_kill;
while (win != _tm_queue[v3].field_4) { while (win != _tm_queue[queueIndex].field_4) {
v3++; queueIndex++;
if (v3 == 5) { if (queueIndex == 5) {
v3 = 0; queueIndex = 0;
} }
if (v3 == _tm_kill || !_tm_index_active(v3)) if (queueIndex == _tm_kill || !_tm_index_active(queueIndex))
return; return;
} }
_tm_kill_out_of_order(v3); _tm_kill_out_of_order(queueIndex);
} }
// 0x4DD870 // 0x4DD870
int _tm_index_active(int a1) int _tm_index_active(int queueIndex)
{ {
if (_tm_kill != _tm_add) { if (_tm_kill != _tm_add) {
if (_tm_kill >= _tm_add) { if (_tm_kill >= _tm_add) {
if (a1 >= _tm_add && a1 < _tm_kill) if (queueIndex >= _tm_add && queueIndex < _tm_kill)
return 0; return 0;
} else if (a1 < _tm_kill || a1 >= _tm_add) { } else if (queueIndex < _tm_kill || queueIndex >= _tm_add) {
return 0; return 0;
} }
} }

View File

@ -13,30 +13,30 @@ typedef void(ListSelectionHandler)(char** items, int index);
extern char gProgramWindowTitle[256]; extern char gProgramWindowTitle[256];
int _win_list_select(const char* title, char** fileList, int fileListLength, ListSelectionHandler* callback, int x, int y, int a7); int _win_list_select(const char* title, char** fileList, int fileListLength, ListSelectionHandler* callback, int x, int y, int color);
int _win_list_select_at(const char* title, char** items, int itemsLength, ListSelectionHandler* callback, int x, int y, int a7, int a8); int _win_list_select_at(const char* title, char** items, int itemsLength, ListSelectionHandler* callback, int x, int y, int color, int start);
int _win_get_str(char* dest, int length, const char* title, int x, int y); int _win_get_str(char* dest, int length, const char* title, int x, int y);
int _win_msg(const char* string, int x, int y, int flags); int _win_msg(const char* string, int x, int y, int color);
int _win_pull_down(char** items, int itemsLength, int x, int y, int a5); int _win_pull_down(char** items, int itemsLength, int x, int y, int color);
int _create_pull_down(char** stringList, int stringListLength, int x, int y, int a5, int a6, Rect* rect); int _create_pull_down(char** stringList, int stringListLength, int x, int y, int foregroundColor, int backgroundColor, Rect* rect);
int _win_debug(char* string); int _win_debug(char* string);
void _win_debug_delete(int btn, int keyCode); void _win_debug_delete(int btn, int keyCode);
int _win_register_menu_bar(int win, int x, int y, int width, int height, int borderColor, int backgroundColor); int _win_register_menu_bar(int win, int x, int y, int width, int height, int foregroundColor, int backgroundColor);
int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int itemsLength, char** items, int a7, int a8); int _win_register_menu_pulldown(int win, int x, char* title, int keyCode, int itemsLength, char** items, int foregroundColor, int backgroundColor);
void _win_delete_menu_bar(int win); void _win_delete_menu_bar(int win);
int _find_first_letter(int ch, char** stringList, int stringListLength); int _find_first_letter(int ch, char** stringList, int stringListLength);
int _win_width_needed(char** fileNameList, int fileNameListLength); int _win_width_needed(char** fileNameList, int fileNameListLength);
int _win_input_str(int win, char* dest, int maxLength, int x, int y, int textColor, int backgroundColor); int _win_input_str(int win, char* dest, int maxLength, int x, int y, int textColor, int backgroundColor);
int sub_4DBD04(int win, Rect* rect, char** items, int itemsLength, int a5, int a6, MenuBar* menuBar, int pulldownIndex); int process_pull_down(int win, Rect* rect, char** items, int itemsLength, int a5, int a6, MenuBar* menuBar, int pulldownIndex);
int _GNW_process_menu(MenuBar* menuBar, int pulldownIndex); int _GNW_process_menu(MenuBar* menuBar, int pulldownIndex);
size_t _calc_max_field_chars_wcursor(int a1, int a2); size_t _calc_max_field_chars_wcursor(int value1, int value2);
void _GNW_intr_init(); void _GNW_intr_init();
void _GNW_intr_exit(); void _GNW_intr_exit();
void _tm_watch_msgs(); void _tm_watch_msgs();
void _tm_kill_msg(); void _tm_kill_msg();
void _tm_kill_out_of_order(int a1); void _tm_kill_out_of_order(int queueIndex);
void _tm_click_response(int btn); void _tm_click_response(int btn);
int _tm_index_active(int a1); int _tm_index_active(int queueIndex);
} // namespace fallout } // namespace fallout