Connect notifications from Container to Viewport

mouse enter+exit
This commit is contained in:
Markus Sauermann 2022-02-15 22:14:39 +01:00
parent 98b97d34df
commit 415042ac89
8 changed files with 37 additions and 2 deletions

View File

@ -853,6 +853,14 @@
</constant> </constant>
<constant name="NOTIFICATION_WM_SIZE_CHANGED" value="1008"> <constant name="NOTIFICATION_WM_SIZE_CHANGED" value="1008">
</constant> </constant>
<constant name="NOTIFICATION_WM_DPI_CHANGE" value="1009">
</constant>
<constant name="NOTIFICATION_VP_MOUSE_ENTER" value="1010">
Notification received when the mouse enters the viewport.
</constant>
<constant name="NOTIFICATION_VP_MOUSE_EXIT" value="1011">
Notification received when the mouse leaves the viewport.
</constant>
<constant name="NOTIFICATION_OS_MEMORY_WARNING" value="2009"> <constant name="NOTIFICATION_OS_MEMORY_WARNING" value="2009">
Notification received from the OS when the application is exceeding its allocated memory. Notification received from the OS when the application is exceeding its allocated memory.
Specific to the iOS platform. Specific to the iOS platform.

View File

@ -6,6 +6,7 @@
<description> <description>
A [Container] node that holds a [SubViewport], automatically setting its size. A [Container] node that holds a [SubViewport], automatically setting its size.
[b]Note:[/b] Changing a SubViewportContainer's [member Control.rect_scale] will cause its contents to appear distorted. To change its visual size without causing distortion, adjust the node's margins instead (if it's not already in a container). [b]Note:[/b] Changing a SubViewportContainer's [member Control.rect_scale] will cause its contents to appear distorted. To change its visual size without causing distortion, adjust the node's margins instead (if it's not already in a container).
[b]Note:[/b] The SubViewportContainer forwards mouse-enter and mouse-exit notifications to its sub-viewports.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@ -148,6 +148,24 @@ void SubViewportContainer::_notification(int p_what) {
} }
} }
} break; } break;
case NOTIFICATION_MOUSE_ENTER: {
_notify_viewports(NOTIFICATION_VP_MOUSE_ENTER);
} break;
case NOTIFICATION_MOUSE_EXIT: {
_notify_viewports(NOTIFICATION_VP_MOUSE_EXIT);
} break;
}
}
void SubViewportContainer::_notify_viewports(int p_notification) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c) {
continue;
}
c->notification(p_notification);
} }
} }

View File

@ -38,6 +38,7 @@ class SubViewportContainer : public Container {
bool stretch = false; bool stretch = false;
int shrink = 1; int shrink = 1;
void _notify_viewports(int p_notification);
protected: protected:
void _notification(int p_what); void _notification(int p_what);

View File

@ -2845,6 +2845,9 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_CLOSE_REQUEST); BIND_CONSTANT(NOTIFICATION_WM_CLOSE_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST); BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_SIZE_CHANGED); BIND_CONSTANT(NOTIFICATION_WM_SIZE_CHANGED);
BIND_CONSTANT(NOTIFICATION_WM_DPI_CHANGE);
BIND_CONSTANT(NOTIFICATION_VP_MOUSE_ENTER);
BIND_CONSTANT(NOTIFICATION_VP_MOUSE_EXIT);
BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING);
BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED); BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED);
BIND_CONSTANT(NOTIFICATION_WM_ABOUT); BIND_CONSTANT(NOTIFICATION_WM_ABOUT);

View File

@ -268,6 +268,8 @@ public:
NOTIFICATION_WM_GO_BACK_REQUEST = 1007, NOTIFICATION_WM_GO_BACK_REQUEST = 1007,
NOTIFICATION_WM_SIZE_CHANGED = 1008, NOTIFICATION_WM_SIZE_CHANGED = 1008,
NOTIFICATION_WM_DPI_CHANGE = 1009, NOTIFICATION_WM_DPI_CHANGE = 1009,
NOTIFICATION_VP_MOUSE_ENTER = 1010,
NOTIFICATION_VP_MOUSE_EXIT = 1011,
NOTIFICATION_OS_MEMORY_WARNING = MainLoop::NOTIFICATION_OS_MEMORY_WARNING, NOTIFICATION_OS_MEMORY_WARNING = MainLoop::NOTIFICATION_OS_MEMORY_WARNING,
NOTIFICATION_TRANSLATION_CHANGED = MainLoop::NOTIFICATION_TRANSLATION_CHANGED, NOTIFICATION_TRANSLATION_CHANGED = MainLoop::NOTIFICATION_TRANSLATION_CHANGED,

View File

@ -496,11 +496,11 @@ void Viewport::_notification(int p_what) {
#endif // _3D_DISABLED #endif // _3D_DISABLED
} break; } break;
case NOTIFICATION_WM_MOUSE_ENTER: { case NOTIFICATION_VP_MOUSE_ENTER: {
gui.mouse_in_window = true; gui.mouse_in_window = true;
} break; } break;
case NOTIFICATION_WM_MOUSE_EXIT: { case NOTIFICATION_VP_MOUSE_EXIT: {
gui.mouse_in_window = false; gui.mouse_in_window = false;
_drop_physics_mouseover(); _drop_physics_mouseover();
_drop_mouse_over(); _drop_mouse_over();

View File

@ -340,9 +340,11 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: { case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: {
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER); _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
emit_signal(SNAME("mouse_entered")); emit_signal(SNAME("mouse_entered"));
notification(NOTIFICATION_VP_MOUSE_ENTER);
DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape
} break; } break;
case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: { case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: {
notification(NOTIFICATION_VP_MOUSE_EXIT);
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT); _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT);
emit_signal(SNAME("mouse_exited")); emit_signal(SNAME("mouse_exited"));
} break; } break;