summary refs log tree commit diff
path: root/src/x/geometry.rs
blob: fcbb15a8a5ba489859608f66ac72acd04aaf3066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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(),
    }
  }
}