summary refs log tree commit diff
path: root/src/x
diff options
context:
space:
mode:
Diffstat (limited to 'src/x')
-rw-r--r--src/x/geometry.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/x/geometry.rs b/src/x/geometry.rs
new file mode 100644
index 0000000..fcbb15a
--- /dev/null
+++ b/src/x/geometry.rs
@@ -0,0 +1,66 @@
+use crate::geometry::*;
+
+use std::fmt::Debug;
+
+
+pub const X_CLOCKWISE_RIGHT_ANGLE: i16 = -90 * 64;
+
+
+pub trait SideExt {
+  fn to_x_angle(&self) -> i16;
+}
+
+impl SideExt for Side {
+  fn to_x_angle(&self) -> i16 {
+    match self {
+      Side::Top => 90 * 64,
+      Side::Right => 0,
+      Side::Bottom => 270 * 64,
+      Side::Left => 180 * 64,
+    }
+  }
+}
+
+
+pub trait RectangleExt<T: Coordinate> {
+  fn to_x_rectangle(&self) -> xcb::x::Rectangle
+    where T: TryInto<i16> + TryInto<u16> + Debug,
+          <T as TryInto<i16>>::Error: Debug,
+          <T as TryInto<u16>>::Error: Debug;
+  fn to_x_arc(&self, angle1: i16, angle2: i16) -> xcb::x::Arc
+    where T: TryInto<i16> + TryInto<u16> + Debug,
+          <T as TryInto<i16>>::Error: Debug,
+          <T as TryInto<u16>>::Error: Debug;
+}
+
+
+impl<T: Coordinate> RectangleExt<T> for Rectangle<T> {
+  fn to_x_rectangle(&self) -> xcb::x::Rectangle
+    where T: TryInto<i16> + TryInto<u16> + Debug,
+          <T as TryInto<i16>>::Error: Debug,
+          <T as TryInto<u16>>::Error: Debug
+  {
+    xcb::x::Rectangle {
+      x: self.left.try_into().unwrap(),
+      y: self.top.try_into().unwrap(),
+      width: self.width.try_into().unwrap(),
+      height: self.height.try_into().unwrap()
+    }
+  }
+
+  fn to_x_arc(&self, angle1: i16, angle2: i16) -> xcb::x::Arc
+    where T: TryInto<i16> + TryInto<u16> + Debug,
+          <T as TryInto<i16>>::Error: Debug,
+          <T as TryInto<u16>>::Error: Debug
+  {
+    xcb::x::Arc {
+      x: self.left.try_into().unwrap(),
+      y: self.top.try_into().unwrap(),
+      width: self.width.try_into().unwrap(),
+      height: self.height.try_into().unwrap(),
+      angle1: angle1.try_into().unwrap(),
+      angle2: angle2.try_into().unwrap(),
+    }
+  }
+}
+