mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
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.
This commit is contained in:
parent
545d0b144f
commit
7240cad9c5
3 changed files with 108 additions and 2 deletions
|
@ -160,6 +160,34 @@ gst_navigation_send_mouse_event (GstNavigation * navigation, const char *event,
|
||||||
"pointer_y", G_TYPE_DOUBLE, y, NULL));
|
"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:
|
* gst_navigation_send_command:
|
||||||
* @navigation: The navigation interface instance
|
* @navigation: The navigation interface instance
|
||||||
|
@ -730,6 +758,8 @@ gst_navigation_event_get_type (GstEvent * event)
|
||||||
return GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE;
|
return GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE;
|
||||||
else if (g_str_equal (e_type, "mouse-move"))
|
else if (g_str_equal (e_type, "mouse-move"))
|
||||||
return GST_NAVIGATION_EVENT_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"))
|
else if (g_str_equal (e_type, "key-press"))
|
||||||
return GST_NAVIGATION_EVENT_KEY_PRESS;
|
return GST_NAVIGATION_EVENT_KEY_PRESS;
|
||||||
else if (g_str_equal (e_type, "key-release"))
|
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;
|
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:
|
* gst_navigation_event_parse_command:
|
||||||
* @event: A #GstEvent to inspect.
|
* @event: A #GstEvent to inspect.
|
||||||
|
|
|
@ -141,7 +141,7 @@ typedef enum {
|
||||||
* @GST_NAVIGATION_QUERY_COMMANDS: command query
|
* @GST_NAVIGATION_QUERY_COMMANDS: command query
|
||||||
* @GST_NAVIGATION_QUERY_ANGLES: viewing angle query
|
* @GST_NAVIGATION_QUERY_ANGLES: viewing angle query
|
||||||
*
|
*
|
||||||
* Tyoes of navigation interface queries.
|
* Types of navigation interface queries.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -260,6 +260,9 @@ gboolean gst_navigation_message_parse_event (GstMessage *message
|
||||||
* event.
|
* event.
|
||||||
* @GST_NAVIGATION_EVENT_COMMAND: A navigation command event. Use
|
* @GST_NAVIGATION_EVENT_COMMAND: A navigation command event. Use
|
||||||
* gst_navigation_event_parse_command() to extract the details from the event.
|
* 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
|
* Enum values for the various events that an element implementing the
|
||||||
* GstNavigation interface might send up the pipeline.
|
* 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_PRESS = 3,
|
||||||
GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE = 4,
|
GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE = 4,
|
||||||
GST_NAVIGATION_EVENT_MOUSE_MOVE = 5,
|
GST_NAVIGATION_EVENT_MOUSE_MOVE = 5,
|
||||||
GST_NAVIGATION_EVENT_COMMAND = 6
|
GST_NAVIGATION_EVENT_COMMAND = 6,
|
||||||
|
GST_NAVIGATION_EVENT_MOUSE_SCROLL = 7
|
||||||
} GstNavigationEventType;
|
} GstNavigationEventType;
|
||||||
|
|
||||||
GST_VIDEO_API
|
GST_VIDEO_API
|
||||||
|
@ -289,6 +293,11 @@ GST_VIDEO_API
|
||||||
gboolean gst_navigation_event_parse_mouse_move_event (GstEvent *event,
|
gboolean gst_navigation_event_parse_mouse_move_event (GstEvent *event,
|
||||||
gdouble *x, gdouble *y);
|
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
|
GST_VIDEO_API
|
||||||
gboolean gst_navigation_event_parse_command (GstEvent *event,
|
gboolean gst_navigation_event_parse_command (GstEvent *event,
|
||||||
GstNavigationCommand *command);
|
GstNavigationCommand *command);
|
||||||
|
@ -307,6 +316,10 @@ GST_VIDEO_API
|
||||||
void gst_navigation_send_mouse_event (GstNavigation *navigation,
|
void gst_navigation_send_mouse_event (GstNavigation *navigation,
|
||||||
const char *event, int button, double x, double y);
|
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
|
GST_VIDEO_API
|
||||||
void gst_navigation_send_command (GstNavigation *navigation,
|
void gst_navigation_send_command (GstNavigation *navigation,
|
||||||
GstNavigationCommand command);
|
GstNavigationCommand command);
|
||||||
|
|
|
@ -42,6 +42,7 @@ struct TestElement
|
||||||
GstNavigationEventType sent_type;
|
GstNavigationEventType sent_type;
|
||||||
const gchar *sent_key;
|
const gchar *sent_key;
|
||||||
gdouble sent_x, sent_y;
|
gdouble sent_x, sent_y;
|
||||||
|
gdouble sent_delta_x, sent_delta_y;
|
||||||
gint sent_button;
|
gint sent_button;
|
||||||
GstNavigationCommand sent_command;
|
GstNavigationCommand sent_command;
|
||||||
};
|
};
|
||||||
|
@ -127,6 +128,16 @@ nav_send_event (GstNavigation * navigation, GstStructure * structure)
|
||||||
fail_unless (y == self->sent_y);
|
fail_unless (y == self->sent_y);
|
||||||
break;
|
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:{
|
case GST_NAVIGATION_EVENT_COMMAND:{
|
||||||
GstNavigationCommand cmd;
|
GstNavigationCommand cmd;
|
||||||
fail_unless (gst_navigation_event_parse_command (event, &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",
|
gst_navigation_send_mouse_event (GST_NAVIGATION (test_element), "mouse-move",
|
||||||
0, 50, 100);
|
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_type = GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS;
|
||||||
test_element->sent_x = 10;
|
test_element->sent_x = 10;
|
||||||
test_element->sent_y = 20;
|
test_element->sent_y = 20;
|
||||||
|
|
Loading…
Reference in a new issue