/* * Copyright (C) 2022 Umut İnan Erdoğan * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #[cfg(windows)] use windows::Win32::{ Foundation::RECT, Graphics::Direct2D::Common::{D2D_RECT_F, D2D_RECT_U}, }; #[derive(Copy, Clone, Debug)] pub struct Rect { x: f32, y: f32, width: f32, height: f32, } impl Rect { pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self { Self { x, y, width, height, } } } impl From for (f64, f64, f64, f64) { fn from(rect: Rect) -> Self { (rect.x.into(), rect.y.into(), rect.width.into(), rect.height.into()) } } #[cfg(windows)] impl From for RECT { fn from(rect: Rect) -> Self { Self { left: rect.x as i32, top: rect.y as i32, right: rect.width as i32, bottom: rect.height as i32, } } } #[cfg(windows)] impl From for D2D_RECT_U { fn from(rect: Rect) -> Self { Self { left: rect.x as u32, top: rect.y as u32, right: rect.width as u32, bottom: rect.height as u32, } } } #[cfg(windows)] impl From for D2D_RECT_F { fn from(rect: Rect) -> Self { Self { left: rect.x, top: rect.y, right: rect.width, bottom: rect.height, } } }