From 7fa4f497f77471fa145881d759afe0b521971e04 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 10 Jun 2020 20:55:43 +0200 Subject: Added shuffle generator --- src/main.rs | 55 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d87720a..c997be1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,57 +1,80 @@ use sdl2::ttf; -use sdl2::event::Event; +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 video_subsys = sdl.video().unwrap(); let ttf = ttf::init().unwrap(); - let font = ttf.load_font("font/FiraMono-Regular.ttf", 40).unwrap(); - + let video_subsys = sdl.video().unwrap(); let window = video_subsys - .window("rutikmer", 640, 480) + .window(TITLE, WIDTH, HEIGHT) + .resizable() .build() .unwrap(); - - let mut timer = time::Timer::new(); + let font = ttf.load_font("font/FiraMono-Regular.ttf", 40).unwrap(); let mut canvas = window.into_canvas().build().unwrap(); - let texture_creator = canvas.texture_creator(); 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), .. } => { + 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), .. } => { + 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), _ => {} } } - match timer.state { - time::State::Idle => canvas.set_draw_color(Color::RGB(100, 100, 0)), - time::State::Active => canvas.set_draw_color(Color::RGB(0, 100, 0)), - time::State::Inactive => canvas.set_draw_color(Color::RGB(0, 0, 0)), - } + 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, &texture_creator), None, None).unwrap(); + 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)); } -- cgit