diff --git a/src/dbox.cc b/src/dbox.cc index f30b358..86d0fdc 100644 --- a/src/dbox.cc +++ b/src/dbox.cc @@ -286,6 +286,11 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i _colorTable[18979]); } + Rect offset; + offset.top = -5; + offset.bottom = 5; + offset.left = -18; + offset.right = 82; int btn = buttonCreate(win, v27 + 13, _doneY[dialogType] + 4, @@ -298,7 +303,8 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i buttonNormalFrmImage.getData(), buttonPressedFrmImage.getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } @@ -327,6 +333,11 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i backgroundFrmImage.getWidth(), _colorTable[18979]); + Rect offset; + offset.top = -5; + offset.bottom = 5; + offset.left = -17; + offset.right = 82; int btn = buttonCreate(win, doneBoxFrmImage.getWidth() + _doneX[dialogType] + 37, _doneY[dialogType] + 4, @@ -339,7 +350,8 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i buttonNormalFrmImage.getData(), buttonPressedFrmImage.getData(), 0, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } diff --git a/src/game_dialog.cc b/src/game_dialog.cc index b14066f..ae998df 100644 --- a/src/game_dialog.cc +++ b/src/game_dialog.cc @@ -3183,13 +3183,19 @@ int _gdialog_barter_create_win() backgroundFrmImage.unlock(); + + Rect offset; + offset.top = -7; + offset.bottom = 7; + offset.left = -18; + offset.right = 18; // TRADE - _gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 41, 163, 14, 14, -1, -1, -1, KEY_LOWERCASE_M, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT); + _gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 41, 163, 14, 14, -1, -1, -1, KEY_LOWERCASE_M, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT, offset); if (_gdialog_buttons[0] != -1) { buttonSetCallbacks(_gdialog_buttons[0], _gsound_med_butt_press, _gsound_med_butt_release); // TALK - _gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 584, 162, 14, 14, -1, -1, -1, KEY_LOWERCASE_T, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT); + _gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 584, 162, 14, 14, -1, -1, -1, KEY_LOWERCASE_T, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT, offset); if (_gdialog_buttons[1] != -1) { buttonSetCallbacks(_gdialog_buttons[1], _gsound_med_butt_press, _gsound_med_butt_release); @@ -4306,8 +4312,14 @@ int _gdialog_window_create() _gdialog_scroll_subwin(gGameDialogWindow, 1, backgroundFrmData, v10, 0, _dialogue_subwin_len, 0); } + + Rect offset; + offset.top = -7; + offset.bottom = 7; + offset.left = -18; + offset.right = 18; // BARTER/TRADE - _gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, -1, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + _gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, -1, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT, offset); if (_gdialog_buttons[0] != -1) { buttonSetMouseCallbacks(_gdialog_buttons[0], NULL, NULL, NULL, gameDialogBarterButtonUpMouseUp); buttonSetCallbacks(_gdialog_buttons[0], _gsound_med_butt_press, _gsound_med_butt_release); diff --git a/src/inventory.cc b/src/inventory.cc index e2f4d9e..61b0099 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -999,6 +999,12 @@ static bool _setup_inventory(int inventoryWindowType) fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0); _inventoryFrmImages[1].lock(fid); + Rect offset; + offset.top = -7; + offset.bottom= 7; + offset.left = -95; + offset.right = 20; + if (_inventoryFrmImages[0].isLocked() && _inventoryFrmImages[1].isLocked()) { btn = -1; switch (inventoryWindowType) { @@ -1016,7 +1022,8 @@ static bool _setup_inventory(int inventoryWindowType) _inventoryFrmImages[0].getData(), _inventoryFrmImages[1].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); break; case INVENTORY_WINDOW_TYPE_USE_ITEM_ON: // Cancel button @@ -1032,7 +1039,8 @@ static bool _setup_inventory(int inventoryWindowType) _inventoryFrmImages[0].getData(), _inventoryFrmImages[1].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); break; case INVENTORY_WINDOW_TYPE_LOOT: // Done button @@ -1048,7 +1056,8 @@ static bool _setup_inventory(int inventoryWindowType) _inventoryFrmImages[0].getData(), _inventoryFrmImages[1].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); break; } @@ -5854,7 +5863,13 @@ static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item) fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0); _moveFrmImages[5].lock(fid); + Rect offset; + if (_moveFrmImages[4].isLocked() && _moveFrmImages[5].isLocked()) { + offset.top = -1; + offset.bottom = 1; + offset.left = -80; + offset.right = 10; // Done btn = buttonCreate(_mt_wid, 98, @@ -5868,11 +5883,16 @@ static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item) _moveFrmImages[4].getData(), _moveFrmImages[5].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } - + + offset.top = -1; + offset.bottom = 1; + offset.left = -10; + offset.right = 80; // Cancel btn = buttonCreate(_mt_wid, 148, @@ -5886,7 +5906,8 @@ static int inventoryQuantityWindowInit(int inventoryWindowType, Object* item) _moveFrmImages[4].getData(), _moveFrmImages[5].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } diff --git a/src/loadsave.cc b/src/loadsave.cc index a23c01f..99b8ae4 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -1404,6 +1404,12 @@ static int lsgWindowInit(int windowType) int btn; + Rect offset; + offset.top = -5; + offset.bottom = 5; + offset.left = -12; + offset.right = 72; + btn = buttonCreate(gLoadSaveWindow, 391, 349, @@ -1416,7 +1422,8 @@ static int lsgWindowInit(int windowType) _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_NORMAL].getData(), _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_PRESSED].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } @@ -1433,7 +1440,8 @@ static int lsgWindowInit(int windowType) _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_NORMAL].getData(), _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_PRESSED].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn != -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } @@ -2123,6 +2131,12 @@ static int _GetComment(int a1) int btn; // DONE + Rect offset; + offset.top = -5; + offset.bottom = 5; + offset.left = -15; + offset.right = 87; + btn = buttonCreate(window, 34, 58, @@ -2135,7 +2149,8 @@ static int _GetComment(int a1) _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_NORMAL].getData(), _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_PRESSED].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn == -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } @@ -2153,7 +2168,8 @@ static int _GetComment(int a1) _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_NORMAL].getData(), _loadsaveFrmImages[LOAD_SAVE_FRM_RED_BUTTON_PRESSED].getData(), NULL, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (btn == -1) { buttonSetCallbacks(btn, _gsound_red_butt_press, _gsound_red_butt_release); } diff --git a/src/main.cc b/src/main.cc index 027006e..de0e5c5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -889,6 +889,12 @@ static int mainMenuWindowInit() offsetX = offsetY = 0; configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MAIN_MENU_OFFSET_X_KEY, &offsetX); configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MAIN_MENU_OFFSET_Y_KEY, &offsetY); + + Rect offset; + offset.top = -2; + offset.bottom = 3; + offset.left = -1; + offset.right = 150; for (int index = 0; index < MAIN_MENU_BUTTON_COUNT; index++) { gMainMenuButtons[index] = buttonCreate(gMainMenuWindow, @@ -903,7 +909,8 @@ static int mainMenuWindowInit() _mainMenuButtonNormalFrmImage.getData(), _mainMenuButtonPressedFrmImage.getData(), 0, - BUTTON_FLAG_TRANSPARENT); + BUTTON_FLAG_TRANSPARENT, + offset); if (gMainMenuButtons[index] == -1) { // NOTE: Uninline. return main_menu_fatal_error(); diff --git a/src/window_manager.cc b/src/window_manager.cc index acc073b..3a9fcdd 100644 --- a/src/window_manager.cc +++ b/src/window_manager.cc @@ -1355,6 +1355,39 @@ bool showMesageBox(const char* text) return true; } +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,Rect offset) +{ + Window* window = windowGetWindow(win); + + if (!gWindowSystemInitialized) { + return -1; + } + + if (window == NULL) { + return -1; + } + + if (up == NULL && (dn != NULL || hover != NULL)) { + return -1; + } + + Button* button = buttonCreateInternal(win, x, y, width, height, mouseEnterEventCode, mouseExitEventCode, mouseDownEventCode, mouseUpEventCode, flags | BUTTON_FLAG_0x010000, up, dn, hover); + if (button == NULL) { + return -1; + } + + button->clickRect.left += offset.left; + button->clickRect.right += offset.right; + button->clickRect.top += offset.top; + button->clickRect.bottom += offset.bottom; + + button->ignoreMask = true; + + _button_draw(button, window, button->mouseUpImage, 0, NULL, 0); + + return button->id; +} + // 0x4D8260 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) { @@ -1377,6 +1410,8 @@ int buttonCreate(int win, int x, int y, int width, int height, int mouseEnterEve return -1; } + button->ignoreMask = false; + _button_draw(button, window, button->mouseUpImage, 0, NULL, 0); return button->id; @@ -1657,10 +1692,17 @@ Button* buttonCreateInternal(int win, int x, int y, int width, int height, int m button->id = buttonId; button->flags = flags; + button->rect.left = x; button->rect.top = y; button->rect.right = x + width - 1; button->rect.bottom = y + height - 1; + + button->clickRect.left = x; + button->clickRect.top = y; + button->clickRect.right = x + width - 1; + button->clickRect.bottom = y + height - 1; + button->mouseEnterEventCode = mouseEnterEventCode; button->mouseExitEventCode = mouseExitEventCode; button->lefMouseDownEventCode = mouseDownEventCode; @@ -1731,10 +1773,10 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr) field_38 = window->field_38; if (field_34 != NULL) { - rectCopy(&v58, &(field_34->rect)); + rectCopy(&v58, &(field_34->clickRect)); rectOffset(&v58, window->rect.left, window->rect.top); } else if (field_38 != NULL) { - rectCopy(&v58, &(field_38->rect)); + rectCopy(&v58, &(field_38->clickRect)); rectOffset(&v58, window->rect.left, window->rect.top); } @@ -1747,7 +1789,7 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr) Button* touchButton = window->buttonListHead; while (touchButton != NULL && gTouch) { if (!(touchButton->flags & BUTTON_FLAG_DISABLED)) { - if (xx > touchButton->rect.left && xx < touchButton->rect.right && yy > touchButton->rect.top && yy < touchButton->rect.bottom) { + if (xx > touchButton->clickRect.left && xx < touchButton->clickRect.right && yy > touchButton->clickRect.top && yy < touchButton->clickRect.bottom) { _win_button_press_and_release(touchButton->id); } @@ -1859,7 +1901,8 @@ int _GNW_check_buttons(Window* window, int* keyCodePtr) while (button != NULL) { if (!(button->flags & BUTTON_FLAG_DISABLED)) { - rectCopy(&v58, &(button->rect)); + button->mask = NULL; + rectCopy(&v58, &(button->clickRect)); rectOffset(&v58, window->rect.left, window->rect.top); if (_button_under_mouse(button, &v58)) { if (!(button->flags & BUTTON_FLAG_DISABLED)) { @@ -2087,7 +2130,7 @@ bool _button_under_mouse(Button* button, Rect* rect) return false; } - if (button->mask == NULL) { + if (button->mask == NULL || button->ignoreMask) { return true; } diff --git a/src/window_manager.h b/src/window_manager.h index 9d7f33a..f61842c 100644 --- a/src/window_manager.h +++ b/src/window_manager.h @@ -111,6 +111,8 @@ typedef struct Button { int id; int flags; Rect rect; + Rect clickRect; + bool ignoreMask; int mouseEnterEventCode; int mouseExitEventCode; int lefMouseDownEventCode; @@ -180,6 +182,7 @@ int _GNW_check_menu_bars(int a1); void programWindowSetTitle(const char* title); 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,Rect offset); 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_image(int btn, unsigned char* up, unsigned char* down, unsigned char* hover, int a5);