1
0
Fork 0
forked from wry/wry

wayland: implement surface transformations

- buffer scale
- buffer transform
- viewporter
This commit is contained in:
Julian Orth 2022-05-28 18:18:29 +02:00
parent 20f0fba553
commit 95327685c1
16 changed files with 635 additions and 75 deletions

View file

@ -1,4 +1,5 @@
use std::{
cmp::Ordering,
fmt::{Debug, Display, Formatter},
ops::{Add, AddAssign, Sub, SubAssign},
};
@ -8,6 +9,10 @@ use std::{
pub struct Fixed(pub i32);
impl Fixed {
pub fn is_integer(self) -> bool {
self.0 & 255 == 0
}
pub fn from_f64(f: f64) -> Self {
Self((f * 256.0) as i32)
}
@ -20,6 +25,10 @@ impl Fixed {
Self(i >> 8)
}
pub fn to_int(self) -> i32 {
self.0 >> 8
}
pub fn from_int(i: i32) -> Self {
Self(i << 8)
}
@ -33,6 +42,18 @@ impl Fixed {
}
}
impl PartialEq<i32> for Fixed {
fn eq(&self, other: &i32) -> bool {
self.0 == *other << 8
}
}
impl PartialOrd<i32> for Fixed {
fn partial_cmp(&self, other: &i32) -> Option<Ordering> {
self.0.partial_cmp(&(*other << 8))
}
}
impl Debug for Fixed {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.to_f64(), f)