Departure and 2 pass draw
This commit is contained in:
107
src/main.rs
107
src/main.rs
@@ -18,16 +18,26 @@ use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize,Clone)]
|
||||
struct Config {
|
||||
tournament: String,
|
||||
update: Option<u32>,
|
||||
fullscreen: Option<bool>,
|
||||
smash_key: String,
|
||||
tournament: String,
|
||||
update: Option<u32>,
|
||||
fullscreen: Option<bool>,
|
||||
smash_key: String,
|
||||
font_size: u16
|
||||
|
||||
}
|
||||
|
||||
struct Line<'a> {
|
||||
height : u32,
|
||||
width : u32,
|
||||
players : String,
|
||||
alt_color : bool,
|
||||
texture : sdl2::render::Texture<'a>,
|
||||
y: u32
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn new() -> Self {
|
||||
Self { tournament: String::new(), update: Some(1),fullscreen:Some(false), smash_key: String::new() }
|
||||
Self { tournament: String::new(), update: Some(1),fullscreen:Some(false), smash_key: String::new(), font_size: 30 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +48,7 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
||||
let texture_creator = canvas.texture_creator();
|
||||
let mut backline_text = texture_creator.create_texture_streaming(PixelFormatEnum::RGB24, 1, 1).map_err(|e| e.to_string()).unwrap();
|
||||
|
||||
//Back line texture
|
||||
backline_text.with_lock(None, |buffer : &mut [u8], pitch: usize| {
|
||||
buffer[1] = 5;
|
||||
buffer[1] = 30;
|
||||
@@ -46,39 +57,68 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
||||
|
||||
let mut y : u32 = 0;
|
||||
let mut index = 0;
|
||||
let mut lines = Vec::<Line>::new();
|
||||
for sq in queues {
|
||||
|
||||
|
||||
let surface = font.render(sq.name.as_str()).blended(Color::RGBA(255, 255, 0, 255)).map_err(|e| e.to_string()).unwrap();
|
||||
let surface: sdl2::surface::Surface<'_> = font.render(sq.name.as_str()).blended(Color::RGBA(255, 255, 0, 255)).map_err(|e| e.to_string()).unwrap();
|
||||
let text = texture_creator.create_texture_from_surface(&surface).unwrap();
|
||||
let textq : TextureQuery = text.query();
|
||||
let _ = canvas.copy(&text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), textq.width, textq.height));
|
||||
|
||||
y += textq.height+10;
|
||||
|
||||
|
||||
//compute line
|
||||
for current_match in &sq.matches {
|
||||
|
||||
|
||||
index += 1;
|
||||
let switch_col : bool = index%2 == 0;
|
||||
|
||||
let var_name = format!("{} vs {}", ¤t_match.player1, current_match.player2);
|
||||
let surface = font.render(var_name.as_str()).blended(Color::RGBA(255, 255, 255, 255)).map_err(|e| e.to_string()).unwrap();
|
||||
|
||||
let text = texture_creator.create_texture_from_surface(&surface).unwrap();
|
||||
let textq : TextureQuery = text.query();
|
||||
let line = Line{
|
||||
height : textq.height,
|
||||
width : textq.width,
|
||||
players : var_name,
|
||||
texture : texture_creator.create_texture_from_surface(&surface).unwrap(),
|
||||
alt_color : switch_col,
|
||||
y: 0
|
||||
};
|
||||
lines.push(line);
|
||||
|
||||
if switch_col {
|
||||
let _ = canvas.copy(&backline_text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), canvas.viewport().width(), textq.height));
|
||||
}
|
||||
|
||||
|
||||
let _ = canvas.copy(&text, None, Rect::new(0, y.try_into().map_err(|e| 0).unwrap(), textq.width, textq.height));
|
||||
y += textq.height + 5;
|
||||
}
|
||||
|
||||
|
||||
let prev_y = y;
|
||||
// background
|
||||
for l in &lines {
|
||||
if l.alt_color {
|
||||
let _ = canvas.copy(&backline_text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), canvas.viewport().width(), l.height));
|
||||
}
|
||||
y += l.height + 5;
|
||||
}
|
||||
// depart !
|
||||
let d_surface = font.render("Départ / Departure").blended(Color::RGBA(130, 218, 255, 255)).map_err(|e| e.to_string()).unwrap();
|
||||
let d_text = texture_creator.create_texture_from_surface(&d_surface).unwrap();
|
||||
let d_textq : TextureQuery = d_text.query();
|
||||
|
||||
let angle : f64 = f64::from(-90.0);
|
||||
let d_x = canvas.viewport().width() as i32 - (d_textq.width as i32/2) - d_textq.height as i32;
|
||||
let d_y = canvas.viewport().height() as i32 - ( d_textq.width as i32 /2) - d_textq.height as i32;
|
||||
let dst = Rect::new(d_x, d_y,d_textq.width,d_textq.height);
|
||||
let _ = canvas.copy_ex(&d_text, None, dst,angle,None,false,false).unwrap();// d_textq.width, d_textq.height));
|
||||
|
||||
|
||||
// foreground
|
||||
y = prev_y;
|
||||
for l in &lines {
|
||||
let _ = canvas.copy(&l.texture, None, Rect::new(10, y.try_into().map_err(|e| 0).unwrap(), l.width, l.height));
|
||||
y += l.height + 5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +137,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Empty Tournament , Exiting.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
let fullscreen = match config.fullscreen {
|
||||
Some(v) => v,
|
||||
None => false
|
||||
@@ -105,11 +145,13 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
println!("Fullscreen : {}",fullscreen);
|
||||
println!("Done");
|
||||
|
||||
|
||||
let test = Arc::new(Mutex::new(Vec::<SmashQueue>::new()));
|
||||
|
||||
let sdl_context = sdl2::init().unwrap();
|
||||
let video_subsystem = sdl_context.video().unwrap();
|
||||
|
||||
|
||||
let mut build = video_subsystem.window("LaDOSE-SNCF", 1280, 720);
|
||||
if fullscreen {
|
||||
build.fullscreen();
|
||||
@@ -123,12 +165,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let mut canvas: Canvas<sdl2::video::Window> = window.into_canvas().build().unwrap();
|
||||
let ttf_context = sdl2::ttf::init().unwrap();
|
||||
let font : sdl2::ttf::Font<'_, '_> = ttf_context.load_font("font/achemine_bold.ttf", 30).unwrap();
|
||||
let font : sdl2::ttf::Font<'_, '_> = ttf_context.load_font("font/achemine_bold.ttf", config.font_size).unwrap();
|
||||
|
||||
// let stream_queues : Vec<smashrequest::SmashQueue>= smashrequest::get_matches(config.tournament.as_str(),config.smash_key.as_str());
|
||||
|
||||
let stream_queues : Vec<smashrequest::SmashQueue>= smashrequest::get_matches(config.tournament.as_str(),config.smash_key.as_str());
|
||||
|
||||
let timer = sdl_context.timer()?;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -140,18 +182,13 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let data = smashrequest::get_matches(config.tournament.as_str(), config.smash_key.as_str());
|
||||
println!("{:?}", data);
|
||||
let mut a = test_clone.lock().unwrap();
|
||||
if a.len()>1 {
|
||||
a.clear();
|
||||
}
|
||||
else{
|
||||
a.clone_from(&data);
|
||||
}
|
||||
a.clone_from(&data);
|
||||
println!("{:?}",a);
|
||||
return config.update.ok_or(10).unwrap()*1000;
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
canvas.set_draw_color(Color::RGB(0, 255, 255));
|
||||
canvas.clear();
|
||||
canvas.present();
|
||||
@@ -167,9 +204,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
for event in event_pump.poll_iter() {
|
||||
match event {
|
||||
Event::Quit {..} |
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
break 'running Ok(());
|
||||
},
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
break 'running Ok(());
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user