Skip to content

Commit

Permalink
Fix pipboy position
Browse files Browse the repository at this point in the history
See #3
  • Loading branch information
alexbatalov committed May 20, 2022
1 parent 6c4927b commit 73d624a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4618,3 +4618,14 @@ int screenGetHeight()
// TODO: Make it on par with _yres.
return rectGetHeight(&_scr_size);
}

void mouseGetPositionInWindow(int win, int* x, int* y)
{
mouseGetPosition(x, y);

Window* window = windowGetWindow(win);
if (window != NULL) {
*x -= window->rect.left;
*y -= window->rect.top;
}
}
1 change: 1 addition & 0 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,5 +636,6 @@ bool _vcr_load_record(STRUCT_51E2F0* ptr, File* stream);

int screenGetWidth();
int screenGetHeight();
void mouseGetPositionInWindow(int win, int* x, int* y);

#endif /* CORE_H */
14 changes: 8 additions & 6 deletions src/pipboy.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int pipboyOpen(bool forceRest)
return -1;
}

mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
gPipboyLastEventTimestamp = _get_time();

while (true) {
Expand All @@ -231,7 +231,7 @@ int pipboyOpen(bool forceRest)
forceRest = false;
}

mouseGetPosition(&gPipboyMouseX, &gPipboyMouseY);
mouseGetPositionInWindow(gPipboyWindow, &gPipboyMouseX, &gPipboyMouseY);

if (keyCode != -1 || gPipboyMouseX != gPipboyPreviousMouseX || gPipboyMouseY != gPipboyPreviousMouseY) {
gPipboyLastEventTimestamp = _get_time();
Expand All @@ -242,7 +242,7 @@ int pipboyOpen(bool forceRest)
pipboyRenderScreensaver();

gPipboyLastEventTimestamp = _get_time();
mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
}
}

Expand Down Expand Up @@ -341,7 +341,9 @@ int pipboyWindowInit(bool forceRest)
return -1;
}

gPipboyWindow = windowCreate(0, 0, PIPBOY_WINDOW_WIDTH, PIPBOY_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x10);
int pipboyWindowX = (screenGetWidth() - PIPBOY_WINDOW_WIDTH) / 2;
int pipboyWindowY = (screenGetHeight() - PIPBOY_WINDOW_HEIGHT) / 2;
gPipboyWindow = windowCreate(pipboyWindowX, pipboyWindowY, PIPBOY_WINDOW_WIDTH, PIPBOY_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x10);
if (gPipboyWindow == -1) {
debugPrint("\n** Error opening pipboy window! **\n");
for (int index = 0; index < PIPBOY_FRM_COUNT; index++) {
Expand Down Expand Up @@ -2001,7 +2003,7 @@ int pipboyRenderScreensaver()
{
PipboyBomb bombs[PIPBOY_BOMB_COUNT];

mouseGetPosition(&gPipboyPreviousMouseX, &gPipboyPreviousMouseY);
mouseGetPositionInWindow(gPipboyWindow, &gPipboyPreviousMouseX, &gPipboyPreviousMouseY);

for (int index = 0; index < PIPBOY_BOMB_COUNT; index += 1) {
bombs[index].field_10 = 0;
Expand Down Expand Up @@ -2032,7 +2034,7 @@ int pipboyRenderScreensaver()
while (true) {
unsigned int time = _get_time();

mouseGetPosition(&gPipboyMouseX, &gPipboyMouseY);
mouseGetPositionInWindow(gPipboyWindow, &gPipboyMouseX, &gPipboyMouseY);
if (_get_input() != -1 || gPipboyPreviousMouseX != gPipboyMouseX || gPipboyPreviousMouseY != gPipboyMouseY) {
break;
}
Expand Down

0 comments on commit 73d624a

Please sign in to comment.