Move renderer code into a struct (ADT)
This commit is contained in:
parent
dc0581c8cc
commit
81c5b5a1af
20
src/main.rs
20
src/main.rs
|
|
@ -2,11 +2,22 @@ mod gtfs;
|
|||
mod renderer;
|
||||
use std::{collections::HashSet, thread, time::Duration};
|
||||
|
||||
use sdl3::event::{self, Event, EventWatchCallback};
|
||||
|
||||
use crate::renderer::Screen;
|
||||
|
||||
|
||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||
|
||||
struct Callback{}
|
||||
impl EventWatchCallback for Callback{
|
||||
fn callback(&mut self, event: Event) {
|
||||
println!("Event: {:#?}", event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
let gtfs_prefs = gtfs::structs::Preferences {
|
||||
|
|
@ -31,6 +42,13 @@ fn main() {
|
|||
|
||||
screen.print(0, "foo!");
|
||||
|
||||
thread::sleep(Duration::new(10, 0));
|
||||
// Main event loop
|
||||
let mut event_subsystem = screen.get_context().event().unwrap().add_event_watch(Callback{});
|
||||
event_subsystem.activate();
|
||||
|
||||
for _ in 0..10 {
|
||||
thread::sleep(Duration::new(1, 0));
|
||||
}
|
||||
event_subsystem.deactivate();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
|
||||
pub mod structs;
|
||||
|
||||
use sdl3::{pixels::Color, rect::Rect, render::Canvas, sys::metadata::render, ttf::Font, video::Window};
|
||||
use sdl3::{Sdl, pixels::Color, rect::Rect, render::Canvas, sys::metadata::render, ttf::Font, video::Window};
|
||||
use structs::{Prefs};
|
||||
|
||||
pub struct Screen<'a> {
|
||||
canvas: Box<Canvas<Window>>,
|
||||
font: Box<Font<'a>>
|
||||
font: Box<Font<'a>>,
|
||||
context: Box<Sdl>
|
||||
}
|
||||
|
||||
impl Screen<'_> {
|
||||
|
||||
pub fn get_context(&self) -> &Sdl {
|
||||
return &self.context;
|
||||
}
|
||||
|
||||
pub fn print(&mut self, line: u32, text: &str) {
|
||||
let rendered_text = self.font.render(text).solid(Color::RED).unwrap();
|
||||
let texture_creator = self.canvas.texture_creator();
|
||||
|
|
@ -49,6 +54,7 @@ impl Screen<'_> {
|
|||
let mut screen: Screen = Screen {
|
||||
canvas: Box::new(window.into_canvas()),
|
||||
font: Box::new(font),
|
||||
context: Box::new(sdl_context),
|
||||
};
|
||||
|
||||
screen.clear();
|
||||
|
|
|
|||
Loading…
Reference in New Issue