1use core::ops::{Deref, DerefMut};
2
3use crate::Surface;
4
5#[derive(Debug)]
7pub struct Rotate<S>(S);
8impl<S> Rotate<S> {
9 pub fn by90(surface: S) -> Rotate<S> {
11 Rotate(surface)
12 }
13 pub fn by180(surface: S) -> Rotate<Rotate<S>> {
15 Rotate(Rotate(surface))
16 }
17 pub fn by270(surface: S) -> Rotate<Rotate<Rotate<S>>> {
19 Rotate(Rotate(Rotate(surface)))
20 }
21}
22impl<S: Surface> Surface for Rotate<S> {
23 fn clear(&mut self) {
24 self.0.clear()
25 }
26 fn height(&self) -> i32 {
27 self.0.width()
28 }
29 fn width(&self) -> i32 {
30 self.0.height()
31 }
32 fn pixel(&mut self, x: i32, y: i32) {
33 self.0.pixel(self.0.width() - 1 - y, x)
34 }
35}
36impl<S> Deref for Rotate<S> {
37 type Target = S;
38 fn deref(&self) -> &Self::Target {
39 &self.0
40 }
41}
42impl<S> DerefMut for Rotate<S> {
43 fn deref_mut(&mut self) -> &mut Self::Target {
44 &mut self.0
45 }
46}
47
48pub struct Measure;
51impl Surface for Measure {
52 fn clear(&mut self) {}
53 fn pixel(&mut self, _x: i32, _y: i32) {}
54 fn height(&self) -> i32 {
55 1000
56 }
57 fn width(&self) -> i32 {
58 1000
59 }
60}