diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.rustfmt.toml b/.rustfmt.toml old mode 100644 new mode 100755 diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/examples/open_window.rs b/examples/open_window.rs old mode 100644 new mode 100755 diff --git a/src/coordinates.rs b/src/coordinates.rs deleted file mode 100644 index 286c50f..0000000 --- a/src/coordinates.rs +++ /dev/null @@ -1,93 +0,0 @@ -use crate::WindowInfo; - -/// A point in logical coordinates -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct Point { - pub x: f64, - pub y: f64 -} - -impl Point { - /// Create a new point in logical coordinates - pub fn new(x: f64, y: f64) -> Self { - Self { x, y } - } - - /// Convert to actual physical coordinates - #[inline] - pub fn to_physical(&self, window_info: &WindowInfo) -> PhyPoint { - PhyPoint { - x: (self.x * window_info.scale()).round() as i32, - y: (self.y * window_info.scale()).round() as i32, - } - } -} - -/// A point in actual physical coordinates -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct PhyPoint { - pub x: i32, - pub y: i32 -} - -impl PhyPoint { - /// Create a new point in actual physical coordinates - pub fn new(x: i32, y: i32) -> Self { - Self { x, y } - } - - /// Convert to logical coordinates - #[inline] - pub fn to_logical(&self, window_info: &WindowInfo) -> Point { - Point { - x: f64::from(self.x) * window_info.scale_recip(), - y: f64::from(self.y) * window_info.scale_recip(), - } - } -} - -/// A size in logical coordinates -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct Size { - pub width: f64, - pub height: f64, -} - -impl Size { - /// Create a new size in logical coordinates - pub fn new(width: f64, height: f64) -> Self { - Self { width, height } - } - - /// Convert to actual physical size - #[inline] - pub fn to_physical(&self, window_info: &WindowInfo) -> PhySize { - PhySize { - width: (self.width * window_info.scale()).round() as u32, - height: (self.height * window_info.scale()).round() as u32, - } - } -} - -/// An actual size in physical coordinates -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct PhySize { - pub width: u32, - pub height: u32, -} - -impl PhySize { - /// Create a new size in actual physical coordinates - pub fn new(width: u32, height: u32) -> Self { - Self { width, height } - } - - /// Convert to logical size - #[inline] - pub fn to_logical(&self, window_info: &WindowInfo) -> Size { - Size { - width: f64::from(self.width) * window_info.scale_recip(), - height: f64::from(self.height) * window_info.scale_recip(), - } - } -} \ No newline at end of file diff --git a/src/event.rs b/src/event.rs old mode 100644 new mode 100755 diff --git a/src/keyboard.rs b/src/keyboard.rs old mode 100644 new mode 100755 diff --git a/src/lib.rs b/src/lib.rs old mode 100644 new mode 100755 index 97a1f25..d45e20a --- a/src/lib.rs +++ b/src/lib.rs @@ -15,17 +15,15 @@ mod macos; #[cfg(target_os = "macos")] pub use macos::*; -mod coordinates; mod event; mod keyboard; mod mouse_cursor; mod window_info; mod window_open_options; -pub use coordinates::*; pub use event::*; pub use keyboard::*; pub use mouse_cursor::MouseCursor; -pub use window_info::WindowInfo; +pub use window_info::*; pub use window_open_options::*; #[derive(Debug)] diff --git a/src/macos/mod.rs b/src/macos/mod.rs old mode 100644 new mode 100755 diff --git a/src/macos/window.rs b/src/macos/window.rs old mode 100644 new mode 100755 diff --git a/src/mouse_cursor.rs b/src/mouse_cursor.rs old mode 100644 new mode 100755 diff --git a/src/win/mod.rs b/src/win/mod.rs old mode 100644 new mode 100755 diff --git a/src/win/window.rs b/src/win/window.rs old mode 100644 new mode 100755 diff --git a/src/window_info.rs b/src/window_info.rs old mode 100644 new mode 100755 index e37d52c..1dad5d5 --- a/src/window_info.rs +++ b/src/window_info.rs @@ -1,5 +1,3 @@ -use crate::{Size, PhySize}; - /// The info about the window #[derive(Debug, Copy, Clone)] pub struct WindowInfo { @@ -61,4 +59,96 @@ impl WindowInfo { pub fn scale_recip(&self) -> f64 { self.scale_recip } +} + +/// A point in logical coordinates +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct Point { + pub x: f64, + pub y: f64 +} + +impl Point { + /// Create a new point in logical coordinates + pub fn new(x: f64, y: f64) -> Self { + Self { x, y } + } + + /// Convert to actual physical coordinates + #[inline] + pub fn to_physical(&self, window_info: &WindowInfo) -> PhyPoint { + PhyPoint { + x: (self.x * window_info.scale()).round() as i32, + y: (self.y * window_info.scale()).round() as i32, + } + } +} + +/// A point in actual physical coordinates +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct PhyPoint { + pub x: i32, + pub y: i32 +} + +impl PhyPoint { + /// Create a new point in actual physical coordinates + pub fn new(x: i32, y: i32) -> Self { + Self { x, y } + } + + /// Convert to logical coordinates + #[inline] + pub fn to_logical(&self, window_info: &WindowInfo) -> Point { + Point { + x: f64::from(self.x) * window_info.scale_recip(), + y: f64::from(self.y) * window_info.scale_recip(), + } + } +} + +/// A size in logical coordinates +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct Size { + pub width: f64, + pub height: f64, +} + +impl Size { + /// Create a new size in logical coordinates + pub fn new(width: f64, height: f64) -> Self { + Self { width, height } + } + + /// Convert to actual physical size + #[inline] + pub fn to_physical(&self, window_info: &WindowInfo) -> PhySize { + PhySize { + width: (self.width * window_info.scale()).round() as u32, + height: (self.height * window_info.scale()).round() as u32, + } + } +} + +/// An actual size in physical coordinates +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct PhySize { + pub width: u32, + pub height: u32, +} + +impl PhySize { + /// Create a new size in actual physical coordinates + pub fn new(width: u32, height: u32) -> Self { + Self { width, height } + } + + /// Convert to logical size + #[inline] + pub fn to_logical(&self, window_info: &WindowInfo) -> Size { + Size { + width: f64::from(self.width) * window_info.scale_recip(), + height: f64::from(self.height) * window_info.scale_recip(), + } + } } \ No newline at end of file diff --git a/src/window_open_options.rs b/src/window_open_options.rs old mode 100644 new mode 100755 diff --git a/src/x11/cursor.rs b/src/x11/cursor.rs old mode 100644 new mode 100755 diff --git a/src/x11/mod.rs b/src/x11/mod.rs old mode 100644 new mode 100755 diff --git a/src/x11/window.rs b/src/x11/window.rs old mode 100644 new mode 100755 index 92e5bba..8549255 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -13,7 +13,7 @@ use super::XcbConnection; use crate::{ Event, KeyboardEvent, MouseButton, MouseCursor, MouseEvent, Parent, ScrollDelta, WindowEvent, WindowHandle, WindowHandler, WindowInfo, WindowOpenOptions, WindowOpenResult, - WindowScalePolicy, Size, Point, + WindowScalePolicy, PhyPoint, PhySize, }; pub struct Window { @@ -25,7 +25,7 @@ pub struct Window { frame_interval: Duration, event_loop_running: bool, - new_physical_size: Option + new_physical_size: Option } impl Window { @@ -307,7 +307,7 @@ impl Window { xcb::CONFIGURE_NOTIFY => { let event = unsafe { xcb::cast_event::(&event) }; - let new_physical_size = Size::new(event.width() as u32, event.height() as u32); + let new_physical_size = PhySize::new(event.width() as u32, event.height() as u32); if self.new_physical_size.is_some() || new_physical_size != self.window_info.physical_size() { self.new_physical_size = Some(new_physical_size); @@ -322,14 +322,13 @@ impl Window { let detail = event.detail(); if detail != 4 && detail != 5 { - let physical_pos = Point::new(event.event_x() as f64, event.event_y() as f64); - let logical_pos = self.window_info.physical_to_logical(physical_pos); + let physical_pos = PhyPoint::new(event.event_x() as i32, event.event_y() as i32); + let logical_pos = physical_pos.to_logical(&self.window_info); handler.on_event( self, Event::Mouse(MouseEvent::CursorMoved { - logical_pos: logical_pos.into(), - physical_pos: physical_pos.into(), + position: logical_pos, }), ); } diff --git a/src/x11/xcb_connection.rs b/src/x11/xcb_connection.rs old mode 100644 new mode 100755