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
use crate::{
    events::{Events, KeyCode},
    history::{History, Record},
    make_tool_transform,
    world::{DataRaw, World},
};

use super::Manipulate;

const ACTOR_NAME: &str = "Rot90";

/// rotate 90 degrees counter clockwise
fn rot90(ims: &DataRaw) -> DataRaw {
    let mut ims = ims.clone();
    ims.apply(|im| im.rotate270());
    ims
}
#[derive(Clone, Copy, Debug)]
pub struct Rot90;

impl Rot90 {
    fn key_pressed(
        &mut self,
        _events: &Events,
        mut world: World,
        mut history: History,
    ) -> (World, History) {
        history.push(Record::new(world.data.clone(), ACTOR_NAME));
        world = World::new(rot90(&world.data), *world.zoom_box());
        (world, history)
    }
}

impl Manipulate for Rot90 {
    fn new() -> Self {
        Self {}
    }

    fn events_tf(&mut self, world: World, history: History, event: &Events) -> (World, History) {
        make_tool_transform!(
            self,
            world,
            history,
            event,
            [(pressed, KeyCode::R, key_pressed)]
        )
    }
}