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
|
use sdl2::ttf;
use sdl2::event::{Event};
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use sdl2::rect::Rect;
use sdl2::render::{Texture, TextureCreator};
pub mod time;
pub mod shuffle;
pub mod text;
const WIDTH: u32 = 640;
const HEIGHT: u32 = 480;
const TITLE: &str = "rutikmer";
fn main() {
let sdl = sdl2::init().unwrap();
let ttf = ttf::init().unwrap();
let video_subsys = sdl.video().unwrap();
let window = video_subsys
.window(TITLE, WIDTH, HEIGHT)
.resizable()
.build()
.unwrap();
let font = ttf.load_font("font/FiraMono-Regular.ttf", 40).unwrap();
let mut canvas = window.into_canvas().build().unwrap();
let mut event_pump = sdl.event_pump().unwrap();
let tex_creator = canvas.texture_creator();
let mut timer = time::Timer::new();
// let mut ui = ui::UI::new(WIDTH, HEIGHT);
//
let timer_rect = Rect::new(10, 10, 100, 40);
'running: loop {
for e in event_pump.poll_iter() {
match e {
Event::Quit {..} => break 'running,
Event::KeyDown { keycode: Some(Keycode::Space), repeat: false, .. } => {
match timer.state {
time::State::Active => timer.stop(),
time::State::Inactive => timer.idle(),
time::State::Idle => {},
}
}
Event::KeyUp { keycode: Some(Keycode::Space), repeat: false, .. } => {
if timer.state == time::State::Idle {
timer.start();
}
},
// Event::Window { win_event: WindowEvent::Resized(w, h), .. } =>
// ui.set_layout(w as u32, h as u32),
_ => {}
}
}
let bg_color = match timer.state {
time::State::Idle => Color::RGB(100, 100, 0),
time::State::Active => Color::RGB(0, 100, 0),
time::State::Inactive => Color::RGB(0, 0, 0),
};
canvas.set_draw_color(bg_color);
canvas.clear();
if timer.state != time::State::Idle {
canvas.copy(&timer.to_texture(&font, &tex_creator, &bg_color),
None,
timer_rect)
.unwrap();
}
let s = shuffle::Move::string_sequence(10);
let shuff_tex = text::to_texture(&s, &font, &tex_creator, &bg_color);
canvas.copy(&shuff_tex, None, Rect::new(10, 100, 500, 40)).unwrap();
canvas.present();
std::thread::sleep(std::time::Duration::new(0, 3_000_000));
}
}
|