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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
extern crate device_query;
extern crate failure;

use easel::EaselCoords;
use std::thread;
use std::time::Duration;
use failure::Error;
use self::device_query::{DeviceQuery, DeviceState};
use coords::Coord;

pub fn create_config(path: &str) -> Result<(), Error> {
    println!("This will walk you through creation of a configuration file.");
    println!("First, let's gather the portrait coordinates.");
    println!("This will reset the cursor after each click.");
    println!("Click when ready.");
    get_pos();

    println!("Please click on the upper left corner of the easel.");
    let portrait_ul = get_pos();

    println!("Please click on the lower right corner of the easel.");
    let portrait_lr = get_pos();

    println!(
        "Please click on the button to change from portrait to landscape."
    );
    let orientation = get_pos();

    println!("Please click on the upper left corner of the easel.");
    let landscape_ul = get_pos();

    println!("Please elick on the lower right corner of the easel.");
    let landscape_lr = get_pos();

    println!("Please click on the button to decrease brush size.");
    let decrease_brush = get_pos();

    println!("Please click on the button to increase brush size.");
    let increase_brush = get_pos();

    println!("Please click on the paintbrush tool.");
    let paintbrush = get_pos();

    println!("Please click on the spray can tool.");
    let spray_can = get_pos();

    println!("Please click on the pen tool.");
    let pen = get_pos();

    println!("Next, we'll be figuring out the distance between colors.");
    println!("Try to click in the center of the color.");
    println!("Please click on black.");
    let color_start = get_pos();

    println!("Please click on grey.");
    let grey = get_pos();

    println!("Please click on dark brown.");
    let dark_brown = get_pos();

    let color_row_step = dark_brown.x - color_start.x;
    let color_col_step = grey.y - color_start.y;

    let easel_coords = EaselCoords {
        portrait_bounds: (portrait_ul, portrait_lr),
        landscape_bounds: (landscape_ul, landscape_lr),
        paintbrush: paintbrush,
        spray_can: spray_can,
        pen: pen,
        decrease_brush: decrease_brush,
        increase_brush: increase_brush,
        change_orientation: orientation,
        color_start: color_start,
        color_row_step: color_row_step,
        color_col_step: color_col_step,
    };

    easel_coords.save(path)
}

pub fn get_pos() -> Coord {
    let mut mouse_pos = (0, 0);
    let device_query = DeviceState::new();

    let mut running = true;
    while running {
        let mouse_state = device_query.get_mouse();
        if mouse_state.button_pressed.get(1) == Some(&true) {
            mouse_pos = mouse_state.coords;
            running = false;
        }
    }
    thread::sleep(Duration::from_secs(1));
    Coord::from(mouse_pos)
}