Adding more stuff in

This commit is contained in:
2026-04-18 07:41:32 +01:00
parent 34dad5e000
commit e28d4fdb22
6 changed files with 95 additions and 35 deletions
+36
View File
@@ -0,0 +1,36 @@
pub mod structs;
use sdl3::{pixels::Color};
use structs::{Prefs, Screen};
/// Initialize video, allocate buffers and load fonts
/// Based on https://github.com/vhspace/sdl3-rs/blob/master/examples/ttf-demo.rs
pub fn init(prefs: &Prefs) -> &mut structs::Screen {
// Initialize the screen
let sdl_context = sdl3::init().unwrap();
let video_subsys = sdl_context.video().unwrap();
let window = video_subsys
.window("Dublin Bus", prefs.screen_width, prefs.screen_height)
.position_centered()
.borderless()
//.fullscreen()
.build().unwrap();
// Load font
let ttf_context = sdl3::ttf::init().unwrap();
let mut font = ttf_context.load_font(&prefs.font_path, 128.0).unwrap();
// Clear screen
let mut canvas = window.into_canvas();
canvas.set_draw_color(Color::BLACK);
canvas.clear();
canvas.present();
let screen = Screen {
canvas: &canvas,
font: &font,
};
return &mut &screen;
}
+13
View File
@@ -0,0 +1,13 @@
use sdl3::{render::Canvas, ttf::Font, video::Window};
pub struct Prefs {
pub font_path: String,
pub screen_width: u32,
pub screen_height: u32,
}
pub struct Screen<'a> {
pub canvas: &'a Canvas<Window>,
pub font: &'a Font<'a>,
}