@@ -5,22 +5,28 @@ use pyo3::{
55 prelude:: * ,
66} ;
77
8- pub fn mouse_x ( surface : Entity ) -> PyResult < f32 > {
9- processing:: prelude:: input_mouse_x ( surface) . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
8+ pub fn mouse_x ( surface : Entity , width : u32 ) -> PyResult < f32 > {
9+ let raw = processing:: prelude:: input_mouse_x ( surface)
10+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) ) ?;
11+ Ok ( raw. clamp ( 0.0 , width as f32 ) )
1012}
1113
12- pub fn mouse_y ( surface : Entity ) -> PyResult < f32 > {
13- processing:: prelude:: input_mouse_y ( surface) . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
14+ pub fn mouse_y ( surface : Entity , height : u32 ) -> PyResult < f32 > {
15+ let raw = processing:: prelude:: input_mouse_y ( surface)
16+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) ) ?;
17+ Ok ( raw. clamp ( 0.0 , height as f32 ) )
1418}
1519
16- pub fn pmouse_x ( surface : Entity ) -> PyResult < f32 > {
17- processing:: prelude:: input_pmouse_x ( surface)
18- . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
20+ pub fn pmouse_x ( surface : Entity , width : u32 ) -> PyResult < f32 > {
21+ let raw = processing:: prelude:: input_pmouse_x ( surface)
22+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) ) ?;
23+ Ok ( raw. clamp ( 0.0 , width as f32 ) )
1924}
2025
21- pub fn pmouse_y ( surface : Entity ) -> PyResult < f32 > {
22- processing:: prelude:: input_pmouse_y ( surface)
23- . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
26+ pub fn pmouse_y ( surface : Entity , height : u32 ) -> PyResult < f32 > {
27+ let raw = processing:: prelude:: input_pmouse_y ( surface)
28+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) ) ?;
29+ Ok ( raw. clamp ( 0.0 , height as f32 ) )
2430}
2531
2632pub fn mouse_is_pressed ( ) -> PyResult < bool > {
@@ -80,12 +86,17 @@ pub fn key_code() -> PyResult<Option<u32>> {
8086 . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
8187}
8288
83- pub fn sync_globals ( globals : & Bound < ' _ , PyAny > , surface : Entity ) -> PyResult < ( ) > {
89+ pub fn sync_globals (
90+ globals : & Bound < ' _ , PyAny > ,
91+ surface : Entity ,
92+ canvas_width : u32 ,
93+ canvas_height : u32 ,
94+ ) -> PyResult < ( ) > {
8495 use crate :: set_tracked;
85- set_tracked ( globals, "mouse_x" , mouse_x ( surface) ?) ?;
86- set_tracked ( globals, "mouse_y" , mouse_y ( surface) ?) ?;
87- set_tracked ( globals, "pmouse_x" , pmouse_x ( surface) ?) ?;
88- set_tracked ( globals, "pmouse_y" , pmouse_y ( surface) ?) ?;
96+ set_tracked ( globals, "mouse_x" , mouse_x ( surface, canvas_width ) ?) ?;
97+ set_tracked ( globals, "mouse_y" , mouse_y ( surface, canvas_height ) ?) ?;
98+ set_tracked ( globals, "pmouse_x" , pmouse_x ( surface, canvas_width ) ?) ?;
99+ set_tracked ( globals, "pmouse_y" , pmouse_y ( surface, canvas_height ) ?) ?;
89100 set_tracked ( globals, "mouse_is_pressed" , mouse_is_pressed ( ) ?) ?;
90101 set_tracked ( globals, "mouse_button" , mouse_button ( ) ?) ?;
91102 set_tracked ( globals, "moved_x" , moved_x ( ) ?) ?;
0 commit comments