Commit 7240cad9 authored by Philippe Normand's avatar Philippe Normand 🥑

navigation: Mouse scroll events support

This patch introduces a new API to send and parse mouse scroll events. Mouse
event coordinates are sent relative to the display space of the related output
area. This is usually the size in pixels of the window associated with the
element implementing the GstNavigation interface.
parent 545d0b14
......@@ -160,6 +160,34 @@ gst_navigation_send_mouse_event (GstNavigation * navigation, const char *event,
"pointer_y", G_TYPE_DOUBLE, y, NULL));
}
/**
* gst_navigation_send_mouse_scroll_event:
* @navigation: The navigation interface instance
* @x: The x coordinate of the mouse event.
* @y: The y coordinate of the mouse event.
* @delta_x: The delta_x coordinate of the mouse event.
* @delta_y: The delta_y coordinate of the mouse event.
*
* Sends a mouse scroll event to the navigation interface. Mouse event coordinates
* are sent relative to the display space of the related output area. This is
* usually the size in pixels of the window associated with the element
* implementing the #GstNavigation interface.
*
* Since: 1.18
*/
void
gst_navigation_send_mouse_scroll_event (GstNavigation * navigation,
double x, double y, double delta_x, double delta_y)
{
gst_navigation_send_event (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_send_command:
* @navigation: The navigation interface instance
......@@ -730,6 +758,8 @@ gst_navigation_event_get_type (GstEvent * event)
return GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE;
else if (g_str_equal (e_type, "mouse-move"))
return GST_NAVIGATION_EVENT_MOUSE_MOVE;
else if (g_str_equal (e_type, "mouse-scroll"))
return GST_NAVIGATION_EVENT_MOUSE_SCROLL;
else if (g_str_equal (e_type, "key-press"))
return GST_NAVIGATION_EVENT_KEY_PRESS;
else if (g_str_equal (e_type, "key-release"))
......@@ -843,6 +873,50 @@ gst_navigation_event_parse_mouse_move_event (GstEvent * event, gdouble * x,
return ret;
}
/**
* gst_navigation_event_parse_mouse_scroll_event:
* @event: A #GstEvent to inspect.
* @x: (out) (optional): Pointer to a gdouble to receive the x coordinate of the
* mouse movement.
* @y: (out) (optional): Pointer to a gdouble to receive the y coordinate of the
* mouse movement.
* @delta_x: (out) (optional): Pointer to a gdouble to receive the delta_x coordinate of the
* mouse movement.
* @delta_y: (out) (optional): Pointer to a gdouble to receive the delta_y coordinate of the
* mouse movement.
*
* Inspect a #GstNavigation mouse scroll event and extract the coordinates
* of the event.
*
* Returns: TRUE if all coordinates could be extracted, otherwise FALSE.
*
* Since: 1.18
*/
gboolean
gst_navigation_event_parse_mouse_scroll_event (GstEvent * event,
gdouble * x, gdouble * y, gdouble * delta_x, gdouble * delta_y)
{
const GstStructure *s;
gboolean ret = TRUE;
g_return_val_if_fail (GST_NAVIGATION_EVENT_HAS_TYPE (event, MOUSE_SCROLL),
FALSE);
s = gst_event_get_structure (event);
if (x)
ret &= gst_structure_get_double (s, "pointer_x", x);
if (y)
ret &= gst_structure_get_double (s, "pointer_y", y);
if (delta_x)
ret &= gst_structure_get_double (s, "delta_pointer_x", delta_x);
if (delta_y)
ret &= gst_structure_get_double (s, "delta_pointer_y", delta_y);
WARN_IF_FAIL (ret, "Couldn't extract positions from mouse scroll event");
return ret;
}
/**
* gst_navigation_event_parse_command:
* @event: A #GstEvent to inspect.
......
......@@ -141,7 +141,7 @@ typedef enum {
* @GST_NAVIGATION_QUERY_COMMANDS: command query
* @GST_NAVIGATION_QUERY_ANGLES: viewing angle query
*
* Tyoes of navigation interface queries.
* Types of navigation interface queries.
*/
typedef enum
{
......@@ -260,6 +260,9 @@ gboolean gst_navigation_message_parse_event (GstMessage *message
* event.
* @GST_NAVIGATION_EVENT_COMMAND: A navigation command event. Use
* gst_navigation_event_parse_command() to extract the details from the event.
* @GST_NAVIGATION_EVENT_MOUSE_SCROLL: A mouse scroll event. Use
* gst_navigation_event_parse_mouse_scroll_event() to extract the details from
* the event.
*
* Enum values for the various events that an element implementing the
* GstNavigation interface might send up the pipeline.
......@@ -271,7 +274,8 @@ typedef enum {
GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS = 3,
GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE = 4,
GST_NAVIGATION_EVENT_MOUSE_MOVE = 5,
GST_NAVIGATION_EVENT_COMMAND = 6
GST_NAVIGATION_EVENT_COMMAND = 6,
GST_NAVIGATION_EVENT_MOUSE_SCROLL = 7
} GstNavigationEventType;
GST_VIDEO_API
......@@ -289,6 +293,11 @@ GST_VIDEO_API
gboolean gst_navigation_event_parse_mouse_move_event (GstEvent *event,
gdouble *x, gdouble *y);
GST_VIDEO_API
gboolean gst_navigation_event_parse_mouse_scroll_event (GstEvent *event,
gdouble *x, gdouble *y,
gdouble *delta_x, gdouble *delta_y);
GST_VIDEO_API
gboolean gst_navigation_event_parse_command (GstEvent *event,
GstNavigationCommand *command);
......@@ -307,6 +316,10 @@ GST_VIDEO_API
void gst_navigation_send_mouse_event (GstNavigation *navigation,
const char *event, int button, double x, double y);
GST_VIDEO_API
void gst_navigation_send_mouse_scroll_event (GstNavigation *navigation,
double x, double y, double delta_x, double delta_y);
GST_VIDEO_API
void gst_navigation_send_command (GstNavigation *navigation,
GstNavigationCommand command);
......
......@@ -42,6 +42,7 @@ struct TestElement
GstNavigationEventType sent_type;
const gchar *sent_key;
gdouble sent_x, sent_y;
gdouble sent_delta_x, sent_delta_y;
gint sent_button;
GstNavigationCommand sent_command;
};
......@@ -127,6 +128,16 @@ nav_send_event (GstNavigation * navigation, GstStructure * structure)
fail_unless (y == self->sent_y);
break;
}
case GST_NAVIGATION_EVENT_MOUSE_SCROLL:{
gdouble x, y, delta_x, delta_y;
fail_unless (gst_navigation_event_parse_mouse_scroll_event (event, &x, &y,
&delta_x, &delta_y));
fail_unless (x == self->sent_x);
fail_unless (y == self->sent_y);
fail_unless (delta_x == self->sent_delta_x);
fail_unless (delta_y == self->sent_delta_y);
break;
}
case GST_NAVIGATION_EVENT_COMMAND:{
GstNavigationCommand cmd;
fail_unless (gst_navigation_event_parse_command (event, &cmd));
......@@ -172,6 +183,14 @@ GST_START_TEST (test_events)
gst_navigation_send_mouse_event (GST_NAVIGATION (test_element), "mouse-move",
0, 50, 100);
test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_SCROLL;
test_element->sent_x = 60;
test_element->sent_y = 120;
test_element->sent_delta_x = 2;
test_element->sent_delta_y = 3;
gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (test_element),
60, 120, 2, 3);
test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS;
test_element->sent_x = 10;
test_element->sent_y = 20;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment