[vlc-commits] display: add/use vout_display_TranslateMouseState()

Rémi Denis-Courmont git at videolan.org
Mon Dec 31 17:40:16 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec 30 20:40:37 2018 +0200| [9e1021fba1c6ac0da5851ec4244b0f65f45435f0] | committer: Rémi Denis-Courmont

display: add/use vout_display_TranslateMouseState()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9e1021fba1c6ac0da5851ec4244b0f65f45435f0
---

 include/vlc_vout_display.h      |  9 +++++++++
 src/video_output/display.c      | 23 +++++++++++++++++++++++
 src/video_output/video_output.c | 17 +----------------
 3 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index c740f210c0..c0d44dd33d 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -416,6 +416,15 @@ typedef struct {
  */
 VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg);
 
+/**
+ * Translates mouse state.
+ *
+ * This translates the mouse (pointer) state from window coordinates to
+ * video coordinates.
+ * @note @c video and @c window pointers may alias.
+ */
+void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
+                                      const vlc_mouse_t *window);
 
 /**
  * Helper function that applies the necessary transforms to the mouse position
diff --git a/src/video_output/display.c b/src/video_output/display.c
index c68dcda0fb..093889f61a 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -223,6 +223,29 @@ void vout_display_PlacePicture(vout_display_place_t *place,
     }
 }
 
+void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
+                                      const vlc_mouse_t *window)
+{
+    vout_display_place_t place;
+
+    /* Translate window coordinates to video coordinates */
+    vout_display_PlacePicture(&place, &vd->source, vd->cfg);
+
+    if (place.width <= 0 || place.height <= 0) {
+        memset(video, 0, sizeof (*video));
+        return;
+    }
+
+    video->i_x = vd->source.i_x_offset
+        + (int64_t)(window->i_x - place.x)
+          * vd->source.i_visible_width / place.width;
+    video->i_y = vd->source.i_y_offset
+        + (int64_t)(window->i_y - place.y)
+          * vd->source.i_visible_height / place.height;
+    video->i_pressed = window->i_pressed;
+    video->b_double_click = window->b_double_click;
+}
+
 void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, video_orientation_t orient_display, int m_x, int m_y, vout_display_place_t *place)
 {
     video_format_t source_rot = vd->source;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 393d3705f2..4393cf99da 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1347,25 +1347,10 @@ static void ThreadStep(vout_thread_t *vout, vlc_tick_t *duration)
 static void ThreadTranslateMouseState(vout_thread_t *vout,
                                       const vlc_mouse_t *win_mouse)
 {
-    vout_display_t *vd = vout->p->display;
     vlc_mouse_t vid_mouse;
-    vout_display_place_t place;
 
     /* Translate window coordinates to video coordinates */
-    vout_display_PlacePicture(&place, &vd->source, vd->cfg);
-
-    if (place.width <= 0 || place.height <= 0)
-        return;
-
-    const int x = vd->source.i_x_offset
-        + (int64_t)(win_mouse->i_x - place.x)
-          * vd->source.i_visible_width / place.width;
-    const int y = vd->source.i_y_offset
-        + (int64_t)(win_mouse->i_y - place.y)
-          * vd->source.i_visible_height / place.height;
-
-    vid_mouse = *win_mouse;
-    vlc_mouse_SetPosition(&vid_mouse, x, y);
+    vout_display_TranslateMouseState(vout->p->display, &vid_mouse, win_mouse);
 
     /* Then pass up the filter chains. */
     vout_SendDisplayEventMouse(vout, &vid_mouse);



More information about the vlc-commits mailing list