Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MouseHandler: Fix offscreen on window enter #488

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small optimization I found while debugging proxied events

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