@@ -18,9 +18,17 @@ func glfwCursorPositionCallbackAtPhase(
18
18
window * glfw.Window , phase embedder.PointerPhase ,
19
19
x float64 , y float64 ,
20
20
) {
21
+
22
+ // Pointer events from GLFW are described using screen coordinates.
23
+ // We need to provide Flutter with the position in pixels.
21
24
width , _ := window .GetSize ()
25
+ if width == 0 {
26
+ fmt .Println ("go-flutter: Cannot calculate pointer position in zero-width window." )
27
+ return
28
+ }
22
29
widthPx , _ := window .GetFramebufferSize ()
23
- pixelsPerScreenCoordinate := float64 (widthPx / width )
30
+ pixelsPerScreenCoordinate := float64 (widthPx ) / float64 (width )
31
+
24
32
event := embedder.PointerEvent {
25
33
Phase : phase ,
26
34
X : x * pixelsPerScreenCoordinate ,
@@ -38,19 +46,10 @@ func glfwMouseButtonCallback(window *glfw.Window, key glfw.MouseButton, action g
38
46
if key == glfw .MouseButton1 {
39
47
x , y := window .GetCursorPos ()
40
48
41
- // recalculate x and y from screen cordinates to pixels
42
- widthPx , _ := window .GetFramebufferSize ()
43
- width , _ := window .GetSize ()
44
- pixelsPerScreenCoordinate := float64 (widthPx ) / float64 (width )
45
- x = x * pixelsPerScreenCoordinate
46
- y = y * pixelsPerScreenCoordinate
47
-
48
49
if action == glfw .Press {
49
50
glfwCursorPositionCallbackAtPhase (window , embedder .PointerPhaseDown , x , y )
50
51
// TODO(#90): new kHover pointerphase in embedder.h suggests that pos callback is relevant outside "down" as well...
51
52
window .SetCursorPosCallback (func (window * glfw.Window , x float64 , y float64 ) {
52
- x = x * pixelsPerScreenCoordinate
53
- y = y * pixelsPerScreenCoordinate
54
53
glfwCursorPositionCallbackAtPhase (window , embedder .PointerPhaseMove , x , y )
55
54
})
56
55
}
0 commit comments