From 0802ed3b3af8f1908bdf3bc447c5ab91de3eae3c Mon Sep 17 00:00:00 2001 From: Andy Terra <152812+airstrike@users.noreply.github.com> Date: Mon, 27 Jan 2025 23:05:24 -0500 Subject: Implement `Mul` for `mouse::Cursor` --- core/src/transformation.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core/src') diff --git a/core/src/transformation.rs b/core/src/transformation.rs index 74183147..735fd9c4 100644 --- a/core/src/transformation.rs +++ b/core/src/transformation.rs @@ -1,3 +1,4 @@ +use crate::mouse::Cursor; use crate::{Point, Rectangle, Size, Vector}; use glam::{Mat4, Vec3, Vec4}; @@ -106,6 +107,19 @@ impl Mul for Rectangle { } } +impl Mul for Cursor { + type Output = Self; + + fn mul(self, transformation: Transformation) -> Self { + match self { + Cursor::Unavailable => Cursor::Unavailable, + Cursor::Available(point) => { + Cursor::Available(point * transformation) + } + } + } +} + impl AsRef<[f32; 16]> for Transformation { fn as_ref(&self) -> &[f32; 16] { self.0.as_ref() -- cgit From 34673fc54f3a2dd7c7f91a0b82ea312b1d01c83e Mon Sep 17 00:00:00 2001 From: Andy Terra <152812+airstrike@users.noreply.github.com> Date: Mon, 27 Jan 2025 23:05:51 -0500 Subject: Implement `Mul` for `mouse::Click` --- core/src/mouse/click.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index dd1c84cd..12039d79 100644 --- a/core/src/mouse/click.rs +++ b/core/src/mouse/click.rs @@ -1,7 +1,9 @@ //! Track mouse clicks. use crate::mouse::Button; use crate::time::Instant; -use crate::Point; +use crate::{Point, Transformation}; + +use std::ops::Mul; /// A mouse click. #[derive(Debug, Clone, Copy)] @@ -88,3 +90,16 @@ impl Click { .unwrap_or(false) } } + +impl Mul for Click { + type Output = Click; + + fn mul(self, transformation: Transformation) -> Click { + Click { + kind: self.kind, + button: self.button, + position: self.position * transformation, + time: self.time, + } + } +} -- cgit From 6576184baed72218005ccd3e0ad008465ad5dbb8 Mon Sep 17 00:00:00 2001 From: Andy Terra <152812+airstrike@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:34:36 -0500 Subject: Move cursor `Transformation` to `mouse::cursor` module --- core/src/mouse/cursor.rs | 17 ++++++++++++++++- core/src/transformation.rs | 14 -------------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'core/src') diff --git a/core/src/mouse/cursor.rs b/core/src/mouse/cursor.rs index 203526e9..616cd315 100644 --- a/core/src/mouse/cursor.rs +++ b/core/src/mouse/cursor.rs @@ -1,4 +1,6 @@ -use crate::{Point, Rectangle, Vector}; +use crate::{Point, Rectangle, Transformation, Vector}; + +use std::ops::Mul; /// The mouse cursor state. #[derive(Debug, Clone, Copy, PartialEq, Default)] @@ -50,3 +52,16 @@ impl Cursor { self.position_over(bounds).is_some() } } + +impl Mul for Cursor { + type Output = Self; + + fn mul(self, transformation: Transformation) -> Self { + match self { + Cursor::Unavailable => Cursor::Unavailable, + Cursor::Available(point) => { + Cursor::Available(point * transformation) + } + } + } +} diff --git a/core/src/transformation.rs b/core/src/transformation.rs index 735fd9c4..74183147 100644 --- a/core/src/transformation.rs +++ b/core/src/transformation.rs @@ -1,4 +1,3 @@ -use crate::mouse::Cursor; use crate::{Point, Rectangle, Size, Vector}; use glam::{Mat4, Vec3, Vec4}; @@ -107,19 +106,6 @@ impl Mul for Rectangle { } } -impl Mul for Cursor { - type Output = Self; - - fn mul(self, transformation: Transformation) -> Self { - match self { - Cursor::Unavailable => Cursor::Unavailable, - Cursor::Available(point) => { - Cursor::Available(point * transformation) - } - } - } -} - impl AsRef<[f32; 16]> for Transformation { fn as_ref(&self) -> &[f32; 16] { self.0.as_ref() -- cgit