I want to do the following:
1. A user presses CTRL+F10 and the mouse cursor moved to the center of GLCanvas
2. The cursor gets transparent while it gets moved inside GLCanvas
3. When the user moves the cursor outside of GLCanvas (e.g. outside the right border of GLCanvas),
I want to restrict it to the border, so the user is not able to go outside until he does step 4
4. If the user presses CTRL+F10 again the mouse cursor gets displayed again and the area
of movement is no more restricted
I have managed to do step 1,2 and 4, but I have a problem of doing step 3. This is because when
the cursor gets moved right outside of GLCanvas it doesn't get locked to the border. To determine
if the cursor is inside GLCanvas I have handled the events as follows:
Code: Select all
Bind(wxEVT_ENTER_WINDOW, &GLCanvas::OnEnterWnd, this);
Bind(wxEVT_LEAVE_WINDOW, &GLCanvas::OnLeaveWnd, this);
Code: Select all
void GLCanvas::OnEnterWnd(wxMouseEvent & event)
{
if (mbMousePointerHidded)
{
wxPoint mouseScreenPos = wxGetMousePosition(); // Gets the mouse in screen coordinates
int mouseX = mouseScreenPos.x - GetScreenPosition().x; // Gets the x-mouse position relative to widget
int mouseY = mouseScreenPos.y - GetScreenPosition().y; // Gets the y-mouse position relative to widget
wxPoint sceneArea = GetScreenPosition();
int sceneAreaScreenCoordX = sceneArea.x + GetRect().width;
int sceneAreaScreenCoordY = sceneArea.y + GetRect().height;
// Locks the mouse to the GLCanvas scene
if (mouseScreenPos.x > sceneAreaScreenCoordX) {
WarpPointer(sceneAreaScreenCoordX, mouseY);
}
}
}
I have read that it doesn't work on MacOS and I want to keep platform-independent.
Can someone help, please?