rascam/src/main.rs

123 lines
3.1 KiB
Rust

extern crate sdl2;
extern crate toml;
#[macro_use]
extern crate serde_derive;
extern crate gst;
extern crate itertools;
use std::time::{SystemTime, Duration};
use std::f32::consts::PI;
use sdl2::pixels;
use sdl2::event::Event;
use sdl2::image::LoadTexture;
use sdl2::gfx::primitives::DrawRenderer;
mod config;
mod pipeline;
const SCREEN_WIDTH: u32 = 160;
const SCREEN_HEIGHT: u32 = 128;
fn main() {
gst::init();
let record_config = config::read_config("rascam.toml");
//let mut recoding_pipeline = pipeline::RecordingPipeline::new(&record_config);
let sdl_context = sdl2::init().unwrap();
let video_subsys = sdl_context.video().unwrap();
let window = video_subsys.window("rascam", SCREEN_WIDTH, SCREEN_HEIGHT)
.position_centered()
.build()
.unwrap();
let mut canvas = window.into_canvas().build().unwrap();
let texture_creator = canvas.texture_creator();
let texture = texture_creator.load_texture("bg.png").unwrap();
//recoding_pipeline.start();
let mut events = sdl_context.event_pump().unwrap();
let center1_x = 44;
let center1_y = 20;
let center2_x = 115;
let center2_y = 20;
let radius = 14.0f32;
let mut angle = 0.0f32;
let mut now = SystemTime::now();
'main: loop {
/*if !recoding_pipeline.handle_events() {
break;
}
let result = recoding_pipeline.get_max_samples();
match result {
Ok((max0, max1)) => {
println!("{} | {}", max0, max1);
}
Err(msg) => {
println!("Error occured: {}", msg);
break;
}
}*/
if now.elapsed().unwrap() > Duration::from_millis(100) {
canvas.copy(&texture, None, None).expect("Render failed");
canvas.filled_circle(80, 18, 6, pixels::Color::RGB(255, 0, 0)).unwrap();
for quad in 0..2 {
let offset = PI / 2.0f32 * (quad as f32);
let cur_angle = angle + offset;
let off_x = (cur_angle.cos() * 14.0f32).round() as i16;
let off_y = (cur_angle.sin() * 14.0f32).round() as i16;
canvas.line(center1_x - off_x, center1_y - off_y, center1_x + off_x, center1_y + off_y, pixels::Color::RGB(255, 255, 255)).unwrap();
canvas.line(center2_x - off_x, center2_y - off_y, center2_x + off_x, center2_y + off_y, pixels::Color::RGB(255, 255, 255)).unwrap();
canvas.filled_circle(center1_x, center1_y, 3, pixels::Color::RGB(160, 160, 160)).unwrap();
canvas.filled_circle(center2_x, center2_y, 3, pixels::Color::RGB(160, 160, 160)).unwrap();
}
//canvas.clear();
canvas.present();
angle = angle - PI / 15.0f32;
if angle < -PI / 2.0f32 {
angle = angle - PI / 2.0f32;
}
now = SystemTime::now();
}
for event in events.poll_iter() {
match event {
Event::Quit {..} => break 'main,
_ => {}
}
}
}
//recoding_pipeline.stop();
}