From c38afa2070b4784304ec96e696bf778ec16b109b Mon Sep 17 00:00:00 2001 From: Vivienne Watermeier Date: Mon, 31 Jan 2022 13:01:10 +0100 Subject: [PATCH] navigation: add more constructors for navigation events Part-of: --- .../gst-libs/gst/video/navigation.c | 140 ++++++++++++++++++ .../gst-libs/gst/video/navigation.h | 24 +++ subprojects/gstreamer/gst/gstevent.c | 3 +- 3 files changed, 166 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c index 95481686c9..c2300a4ba9 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c @@ -745,6 +745,146 @@ gst_navigation_event_get_type (GstEvent * event) return GST_NAVIGATION_EVENT_INVALID; } +/** + * gst_navigation_event_new_key_press: + * @key: A string identifying the key press. + * + * Create a new navigation event for the given key press. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_key_press (const gchar * key) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "key-press", "key", G_TYPE_STRING, key, + NULL)); +} + +/** + * gst_navigation_event_new_key_release: + * @key: A string identifying the released key. + * + * Create a new navigation event for the given key release. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_key_release (const gchar * key) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "key-release", "key", G_TYPE_STRING, key, + NULL)); +} + +/** + * gst_navigation_event_new_mouse_button_press: + * @button: The number of the pressed mouse button. + * @x: The x coordinate of the mouse cursor. + * @y: The y coordinate of the mouse cursor. + * + * Create a new navigation event for the given key mouse button press. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_mouse_button_press (gint button, gdouble x, gdouble y) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "mouse-button-press", + "button", G_TYPE_INT, button, "pointer_x", G_TYPE_DOUBLE, x, + "pointer_y", G_TYPE_DOUBLE, y, NULL)); +} + +/** + * gst_navigation_event_new_mouse_button_release: + * @button: The number of the released mouse button. + * @x: The x coordinate of the mouse cursor. + * @y: The y coordinate of the mouse cursor. + * + * Create a new navigation event for the given key mouse button release. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_mouse_button_release (gint button, gdouble x, + gdouble y) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "mouse-button-release", + "button", G_TYPE_INT, button, "pointer_x", G_TYPE_DOUBLE, x, + "pointer_y", G_TYPE_DOUBLE, y, NULL)); +} + +/** + * gst_navigation_event_new_mouse_move: + * @x: The x coordinate of the mouse cursor. + * @y: The y coordinate of the mouse cursor. + * + * Create a new navigation event for the new mouse location. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_mouse_move (gdouble x, gdouble y) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "mouse-move", + "pointer_x", G_TYPE_DOUBLE, x, "pointer_y", G_TYPE_DOUBLE, y, NULL)); +} + +/** + * gst_navigation_event_new_mouse_scroll: + * @x: The x coordinate of the mouse cursor. + * @y: The y coordinate of the mouse cursor. + * @delta_x: The x component of the scroll movement. + * @delta_y: The y component of the scroll movement. + * + * Create a new navigation event for the mouse scroll. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_mouse_scroll (gdouble x, gdouble y, gdouble delta_x, + gdouble delta_y) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "mouse-scroll", + "pointer_x", G_TYPE_DOUBLE, x, "pointer_y", G_TYPE_DOUBLE, y, + "delta_pointer_x", G_TYPE_DOUBLE, delta_x, + "delta_pointer_y", G_TYPE_DOUBLE, delta_y, NULL)); +} + +/** + * gst_navigation_event_new_command: + * @command: The navigation command to use. + * + * Create a new navigation event given navigation command.. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 1.22 + */ +GstEvent * +gst_navigation_event_new_command (GstNavigationCommand command) +{ + return gst_event_new_navigation (gst_structure_new (GST_NAVIGATION_EVENT_NAME, + "event", G_TYPE_STRING, "command", + "command-code", G_TYPE_UINT, (guint) command, NULL)); +} + /** * gst_navigation_event_parse_key_event: * @event: A #GstEvent to inspect. diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h index 6bd61a5991..79d3ea6e69 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.h @@ -290,6 +290,30 @@ typedef enum { GST_VIDEO_API GstNavigationEventType gst_navigation_event_get_type (GstEvent *event); +GST_VIDEO_API +GstEvent* gst_navigation_event_new_key_press (const gchar * key) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_key_release (const gchar * key) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_mouse_button_press (gint button, gdouble x, + gdouble y) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_mouse_button_release (gint button, gdouble x, + gdouble y) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_mouse_move (gdouble x, gdouble y) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_mouse_scroll (gdouble x, gdouble y, + gdouble delta_x, gdouble delta_y) G_GNUC_MALLOC; + +GST_VIDEO_API +GstEvent* gst_navigation_event_new_command (GstNavigationCommand command) G_GNUC_MALLOC; + GST_VIDEO_API gboolean gst_navigation_event_parse_key_event (GstEvent *event, const gchar **key); diff --git a/subprojects/gstreamer/gst/gstevent.c b/subprojects/gstreamer/gst/gstevent.c index 225ed3bf54..c5bf474737 100644 --- a/subprojects/gstreamer/gst/gstevent.c +++ b/subprojects/gstreamer/gst/gstevent.c @@ -1492,7 +1492,8 @@ gst_event_parse_seek_trickmode_interval (GstEvent * event, /** * gst_event_new_navigation: * @structure: (transfer full): description of the event. The event will take - * ownership of the structure. + * ownership of the structure. See #GstNavigation for more specific + * constructors. * * Create a new navigation event from the given description. *