Add MOUSE_MODE_CONFINED_HIDDEN to MouseMode enum
This commit is contained in:
parent
97d7c7c295
commit
0d6e2d1090
10 changed files with 43 additions and 26 deletions
|
@ -45,7 +45,7 @@ Input *Input::get_singleton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::set_mouse_mode(MouseMode p_mode) {
|
void Input::set_mouse_mode(MouseMode p_mode) {
|
||||||
ERR_FAIL_INDEX((int)p_mode, 4);
|
ERR_FAIL_INDEX((int)p_mode, 5);
|
||||||
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
|
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ void Input::_bind_methods() {
|
||||||
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
|
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
|
||||||
BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
|
BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
|
||||||
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
|
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
|
||||||
|
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED_HIDDEN);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(CURSOR_ARROW);
|
BIND_ENUM_CONSTANT(CURSOR_ARROW);
|
||||||
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
|
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
|
||||||
|
|
|
@ -48,7 +48,8 @@ public:
|
||||||
MOUSE_MODE_VISIBLE,
|
MOUSE_MODE_VISIBLE,
|
||||||
MOUSE_MODE_HIDDEN,
|
MOUSE_MODE_HIDDEN,
|
||||||
MOUSE_MODE_CAPTURED,
|
MOUSE_MODE_CAPTURED,
|
||||||
MOUSE_MODE_CONFINED
|
MOUSE_MODE_CONFINED,
|
||||||
|
MOUSE_MODE_CONFINED_HIDDEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef CursorShape
|
#undef CursorShape
|
||||||
|
|
|
@ -166,7 +166,8 @@ public:
|
||||||
MOUSE_MODE_VISIBLE,
|
MOUSE_MODE_VISIBLE,
|
||||||
MOUSE_MODE_HIDDEN,
|
MOUSE_MODE_HIDDEN,
|
||||||
MOUSE_MODE_CAPTURED,
|
MOUSE_MODE_CAPTURED,
|
||||||
MOUSE_MODE_CONFINED
|
MOUSE_MODE_CONFINED,
|
||||||
|
MOUSE_MODE_CONFINED_HIDDEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void set_mouse_mode(MouseMode p_mode);
|
virtual void set_mouse_mode(MouseMode p_mode);
|
||||||
|
|
|
@ -426,7 +426,10 @@
|
||||||
[b]Note:[/b] If you want to process the mouse's movement in this mode, you need to use [member InputEventMouseMotion.relative].
|
[b]Note:[/b] If you want to process the mouse's movement in this mode, you need to use [member InputEventMouseMotion.relative].
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="MOUSE_MODE_CONFINED" value="3" enum="MouseMode">
|
<constant name="MOUSE_MODE_CONFINED" value="3" enum="MouseMode">
|
||||||
Makes the mouse cursor visible but confines it to the game window.
|
Confines the mouse cursor to the game window, and make it visible.
|
||||||
|
</constant>
|
||||||
|
<constant name="MOUSE_MODE_CONFINED_HIDDEN" value="4" enum="MouseMode">
|
||||||
|
Confines the mouse cursor to the game window, and make it hidden.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="CURSOR_ARROW" value="0" enum="CursorShape">
|
<constant name="CURSOR_ARROW" value="0" enum="CursorShape">
|
||||||
Arrow cursor. Standard, default pointing cursor.
|
Arrow cursor. Standard, default pointing cursor.
|
||||||
|
|
|
@ -449,9 +449,10 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) {
|
void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) {
|
||||||
ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform.");
|
ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform.");
|
||||||
if (p_mode == get_mouse_mode())
|
if (p_mode == get_mouse_mode()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (p_mode == MOUSE_MODE_VISIBLE) {
|
if (p_mode == MOUSE_MODE_VISIBLE) {
|
||||||
godot_js_display_cursor_set_visible(1);
|
godot_js_display_cursor_set_visible(1);
|
||||||
|
|
|
@ -759,7 +759,7 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OS_OSX::singleton->mouse_mode == OS::MOUSE_MODE_CONFINED) {
|
if (OS_OSX::singleton->mouse_mode == OS::MOUSE_MODE_CONFINED || OS_OSX::singleton->mouse_mode == OS::MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
// Discard late events
|
// Discard late events
|
||||||
if (([event timestamp]) < OS_OSX::singleton->last_warp) {
|
if (([event timestamp]) < OS_OSX::singleton->last_warp) {
|
||||||
return;
|
return;
|
||||||
|
@ -2189,7 +2189,7 @@ void OS_OSX::warp_mouse_position(const Point2 &p_to) {
|
||||||
CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
|
CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
|
||||||
CGAssociateMouseAndMouseCursorPosition(false);
|
CGAssociateMouseAndMouseCursorPosition(false);
|
||||||
CGWarpMouseCursorPosition(lMouseWarpPos);
|
CGWarpMouseCursorPosition(lMouseWarpPos);
|
||||||
if (mouse_mode != MOUSE_MODE_CONFINED) {
|
if (mouse_mode != MOUSE_MODE_CONFINED && mouse_mode != MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3469,7 +3469,12 @@ void OS_OSX::set_mouse_mode(MouseMode p_mode) {
|
||||||
} else if (p_mode == MOUSE_MODE_CONFINED) {
|
} else if (p_mode == MOUSE_MODE_CONFINED) {
|
||||||
CGDisplayShowCursor(kCGDirectMainDisplay);
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||||
CGAssociateMouseAndMouseCursorPosition(false);
|
CGAssociateMouseAndMouseCursorPosition(false);
|
||||||
} else {
|
} else if (p_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
|
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
|
||||||
|
CGDisplayHideCursor(kCGDirectMainDisplay);
|
||||||
|
}
|
||||||
|
CGAssociateMouseAndMouseCursorPosition(false);
|
||||||
|
} else { // MOUSE_MODE_VISIBLE
|
||||||
CGDisplayShowCursor(kCGDirectMainDisplay);
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,8 +342,9 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co
|
||||||
os->input_event(screen_drag);
|
os->input_event(screen_drag);
|
||||||
} else {
|
} else {
|
||||||
// In case the mouse grabbed, MouseMoved will handle this
|
// In case the mouse grabbed, MouseMoved will handle this
|
||||||
if (os->get_mouse_mode() == OS::MouseMode::MOUSE_MODE_CAPTURED)
|
if (os->get_mouse_mode() == OS::MouseMode::MOUSE_MODE_CAPTURED) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseMotion> mouse_motion;
|
Ref<InputEventMouseMotion> mouse_motion;
|
||||||
mouse_motion.instance();
|
mouse_motion.instance();
|
||||||
|
@ -360,8 +361,9 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co
|
||||||
|
|
||||||
void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) {
|
void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) {
|
||||||
// In case the mouse isn't grabbed, PointerMoved will handle this
|
// In case the mouse isn't grabbed, PointerMoved will handle this
|
||||||
if (os->get_mouse_mode() != OS::MouseMode::MOUSE_MODE_CAPTURED)
|
if (os->get_mouse_mode() != OS::MouseMode::MOUSE_MODE_CAPTURED) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Windows::Foundation::Point pos;
|
Windows::Foundation::Point pos;
|
||||||
pos.X = last_mouse_pos.X + args->MouseDelta.X;
|
pos.X = last_mouse_pos.X + args->MouseDelta.X;
|
||||||
|
|
|
@ -435,14 +435,12 @@ void OS_UWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, Gyrom
|
||||||
void OS_UWP::set_mouse_mode(MouseMode p_mode) {
|
void OS_UWP::set_mouse_mode(MouseMode p_mode) {
|
||||||
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) {
|
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) {
|
||||||
CoreWindow::GetForCurrentThread()->SetPointerCapture();
|
CoreWindow::GetForCurrentThread()->SetPointerCapture();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
CoreWindow::GetForCurrentThread()->ReleasePointerCapture();
|
CoreWindow::GetForCurrentThread()->ReleasePointerCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_HIDDEN) {
|
if (p_mode == MouseMode::MOUSE_MODE_HIDDEN || p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
|
CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,8 +497,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
ScreenToClient(hWnd, &coords);
|
ScreenToClient(hWnd, &coords);
|
||||||
|
|
||||||
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
||||||
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED)
|
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseMotion> mm;
|
Ref<InputEventMouseMotion> mm;
|
||||||
mm.instance();
|
mm.instance();
|
||||||
|
@ -628,8 +629,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
||||||
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED)
|
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseMotion> mm;
|
Ref<InputEventMouseMotion> mm;
|
||||||
mm.instance();
|
mm.instance();
|
||||||
|
@ -730,8 +732,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
||||||
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED)
|
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseMotion> mm;
|
Ref<InputEventMouseMotion> mm;
|
||||||
mm.instance();
|
mm.instance();
|
||||||
|
@ -1111,7 +1114,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
} break;
|
} break;
|
||||||
case WM_SETCURSOR: {
|
case WM_SETCURSOR: {
|
||||||
if (LOWORD(lParam) == HTCLIENT) {
|
if (LOWORD(lParam) == HTCLIENT) {
|
||||||
if (window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) {
|
if (window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN)) {
|
||||||
//Hide the cursor
|
//Hide the cursor
|
||||||
if (hCursor == NULL) {
|
if (hCursor == NULL) {
|
||||||
hCursor = SetCursor(NULL);
|
hCursor = SetCursor(NULL);
|
||||||
|
@ -1810,7 +1813,8 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) {
|
void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) {
|
||||||
if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_CONFINED) {
|
if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
|
// Mouse is grabbed (captured or confined).
|
||||||
RECT clipRect;
|
RECT clipRect;
|
||||||
GetClientRect(hWnd, &clipRect);
|
GetClientRect(hWnd, &clipRect);
|
||||||
ClientToScreen(hWnd, (POINT *)&clipRect.left);
|
ClientToScreen(hWnd, (POINT *)&clipRect.left);
|
||||||
|
@ -1824,11 +1828,12 @@ void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) {
|
||||||
SetCapture(hWnd);
|
SetCapture(hWnd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Mouse is free to move around (not captured or confined).
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
ClipCursor(NULL);
|
ClipCursor(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN) {
|
if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN || p_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
if (hCursor == NULL) {
|
if (hCursor == NULL) {
|
||||||
hCursor = SetCursor(NULL);
|
hCursor = SetCursor(NULL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2058,7 +2063,7 @@ void OS_Windows::set_window_position(const Point2 &p_position) {
|
||||||
MoveWindow(hWnd, p_position.x, p_position.y, r.right - r.left, r.bottom - r.top, TRUE);
|
MoveWindow(hWnd, p_position.x, p_position.y, r.right - r.left, r.bottom - r.top, TRUE);
|
||||||
|
|
||||||
// Don't let the mouse leave the window when moved
|
// Don't let the mouse leave the window when moved
|
||||||
if (mouse_mode == MOUSE_MODE_CONFINED) {
|
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
RECT rect;
|
RECT rect;
|
||||||
GetClientRect(hWnd, &rect);
|
GetClientRect(hWnd, &rect);
|
||||||
ClientToScreen(hWnd, (POINT *)&rect.left);
|
ClientToScreen(hWnd, (POINT *)&rect.left);
|
||||||
|
@ -2139,7 +2144,7 @@ void OS_Windows::set_window_size(const Size2 p_size) {
|
||||||
MoveWindow(hWnd, rect.left, rect.top, w, h, TRUE);
|
MoveWindow(hWnd, rect.left, rect.top, w, h, TRUE);
|
||||||
|
|
||||||
// Don't let the mouse leave the window when resizing to a smaller resolution
|
// Don't let the mouse leave the window when resizing to a smaller resolution
|
||||||
if (mouse_mode == MOUSE_MODE_CONFINED) {
|
if (mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
RECT crect;
|
RECT crect;
|
||||||
GetClientRect(hWnd, &crect);
|
GetClientRect(hWnd, &crect);
|
||||||
ClientToScreen(hWnd, (POINT *)&crect.left);
|
ClientToScreen(hWnd, (POINT *)&crect.left);
|
||||||
|
|
|
@ -924,7 +924,7 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
XUngrabPointer(x11_display, CurrentTime);
|
XUngrabPointer(x11_display, CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,7 +939,7 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) {
|
||||||
|
|
||||||
mouse_mode = p_mode;
|
mouse_mode = p_mode;
|
||||||
|
|
||||||
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) {
|
||||||
//flush pending motion events
|
//flush pending motion events
|
||||||
flush_mouse_motion();
|
flush_mouse_motion();
|
||||||
|
|
||||||
|
@ -2525,7 +2525,7 @@ void OS_X11::process_xevents() {
|
||||||
do_mouse_warp = false;
|
do_mouse_warp = false;
|
||||||
|
|
||||||
// Is the current mouse mode one where it needs to be grabbed.
|
// Is the current mouse mode one where it needs to be grabbed.
|
||||||
bool mouse_mode_grab = mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED;
|
bool mouse_mode_grab = mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN;
|
||||||
|
|
||||||
xi.pressure = 0;
|
xi.pressure = 0;
|
||||||
xi.tilt = Vector2();
|
xi.tilt = Vector2();
|
||||||
|
@ -2760,7 +2760,7 @@ void OS_X11::process_xevents() {
|
||||||
// Show and update the cursor if confined and the window regained focus.
|
// Show and update the cursor if confined and the window regained focus.
|
||||||
if (mouse_mode == MOUSE_MODE_CONFINED) {
|
if (mouse_mode == MOUSE_MODE_CONFINED) {
|
||||||
XUndefineCursor(x11_display, x11_window);
|
XUndefineCursor(x11_display, x11_window);
|
||||||
} else if (mouse_mode == MOUSE_MODE_CAPTURED) { // or re-hide it in captured mode
|
} else if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED_HIDDEN) { // or re-hide it in captured mode
|
||||||
XDefineCursor(x11_display, x11_window, null_cursor);
|
XDefineCursor(x11_display, x11_window, null_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue