Skip to content

Commit

Permalink
Fix inventory context menu and mouse position (#44)
Browse files Browse the repository at this point in the history
See #3

Co-authored-by: Alexander Batalov <[email protected]>
  • Loading branch information
JanSimek and alexbatalov authored Jun 12, 2022
1 parent 8c2b9c7 commit 7872d4d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/inventory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2995,7 +2995,7 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)

int x;
int y;
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
mouseGetPosition(&x, &y);

int actionMenuItemsLength;
const int* actionMenuItems;
Expand Down Expand Up @@ -3043,9 +3043,15 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)
}

const InventoryWindowDescription* windowDescription = &(gInventoryWindowDescriptions[inventoryWindowType]);

Rect windowRect;
windowGetRect(gInventoryWindow, &windowRect);
int inventoryWindowX = windowRect.left;
int inventoryWindowY = windowRect.top;

gameMouseRenderActionMenuItems(x, y, actionMenuItems, actionMenuItemsLength,
windowDescription->width + windowDescription->x,
windowDescription->height + windowDescription->y);
windowDescription->width + inventoryWindowX,
windowDescription->height + inventoryWindowY);

InventoryCursorData* cursorData = &(gInventoryCursorData[INVENTORY_WINDOW_CURSOR_MENU]);

Expand All @@ -3054,8 +3060,8 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)
artGetRotationOffsets(cursorData->frm, 0, &offsetX, &offsetY);

Rect rect;
rect.left = x - windowDescription->x - cursorData->width / 2 + offsetX;
rect.top = y - windowDescription->y - cursorData->height + 1 + offsetY;
rect.left = x - inventoryWindowX - cursorData->width / 2 + offsetX;
rect.top = y - inventoryWindowY - cursorData->height + 1 + offsetY;
rect.right = rect.left + cursorData->width - 1;
rect.bottom = rect.top + cursorData->height - 1;

Expand Down Expand Up @@ -3090,7 +3096,7 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)

int x;
int y;
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
mouseGetPosition(&x, &y);
if (y - previousMouseY > 10 || previousMouseY - y > 10) {
if (y >= previousMouseY || menuItemIndex <= 0) {
if (previousMouseY < y && menuItemIndex < actionMenuItemsLength - 1) {
Expand Down

0 comments on commit 7872d4d

Please sign in to comment.