Skip to content

Commit

Permalink
MouseHandler: Fix offscreen on window enter (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
badosu authored Nov 6, 2022
1 parent 78c6077 commit 7cadbfc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
7 changes: 5 additions & 2 deletions rts/Game/UI/GuiHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3452,8 +3452,8 @@ void CGuiHandler::DrawMapStuff(bool onMiniMap)
glDisable(GL_ALPHA_TEST);
}

float3 tracePos = camera->GetPos();
float3 traceDir = mouse->dir;
float3 tracePos;
float3 traceDir;

// setup for minimap proxying
const bool minimapInput = (activeReceiver != this && !mouse->offscreen && GetReceiverAt(mouse->lastx, mouse->lasty) == minimap);
Expand All @@ -3469,6 +3469,9 @@ void CGuiHandler::DrawMapStuff(bool onMiniMap)
if (miniMapMarker && minimap->FullProxy() && !onMiniMap && !minimap->GetMinimized()) {
DrawMiniMapMarker(tracePos);
}
} else {
tracePos = camera->GetPos();
traceDir = mouse->dir;
}


Expand Down
5 changes: 5 additions & 0 deletions rts/Game/UI/MouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ void CMouseHandler::ReloadCursors()
activeCursorIdx = defCursorIt->second;
}

void CMouseHandler::WindowEnter()
{
offscreen = false;
}

void CMouseHandler::WindowLeave()
{
offscreen = true;
Expand Down
1 change: 1 addition & 0 deletions rts/Game/UI/MouseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CMouseHandler
void MouseMove(int x, int y, int dx, int dy);
void MouseWheel(float delta);
void WindowLeave();
void WindowEnter();

bool AssignMouseCursor(const std::string& cmdName,
const std::string& fileName,
Expand Down
29 changes: 17 additions & 12 deletions rts/System/Input/MouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,23 @@ bool IMouseInput::HandleSDLMouseEvent(const SDL_Event& event)

} break;
case SDL_WINDOWEVENT: {
if (event.window.event == SDL_WINDOWEVENT_LEAVE) {
// mouse left window; set pos internally to view center-pixel to prevent endless scrolling
mousepos = {
globalRendering->viewPosX + (globalRendering->viewSizeX >> 1),
globalRendering->viewWindowOffsetY + (globalRendering->viewSizeY >> 1)
};

if (mouse != nullptr)
mouse->WindowLeave();

} break;
}
switch (event.window.event) {
case SDL_WINDOWEVENT_ENTER: {
if (mouse != nullptr)
mouse->WindowEnter();
} break;
case SDL_WINDOWEVENT_LEAVE: {
// mouse left window; set pos internally to view center-pixel to prevent endless scrolling
mousepos = {
globalRendering->viewPosX + (globalRendering->viewSizeX >> 1),
globalRendering->viewWindowOffsetY + (globalRendering->viewSizeY >> 1)
};

if (mouse != nullptr)
mouse->WindowLeave();
} break;
}
} break;
}

return false;
Expand Down

0 comments on commit 7cadbfc

Please sign in to comment.