resizable game window

This commit is contained in:
Theis Pieter Hollebeek 2025-03-03 19:17:29 +01:00
parent 489c2814e2
commit 1830aec847
3 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,5 @@
mod audio;
mod render;
mod sdl;
mod ui;
pub use render::start_game;
pub use sdl::start_game;

View File

@ -1,6 +1,5 @@
use crate::actions::{Action, ActionsHeld};
use crate::board::Board;
use crate::game::{CurrentTetromino, Game};
use crate::game::Game;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
@ -10,7 +9,7 @@ use sdl2::ttf::Sdl2TtfContext;
use std::time::Duration;
use super::audio::{self};
use super::ui::{Rgb, UiCtx};
use super::ui::{GameUiCtx, Rgb, UiCtx};
const WIDTH: i32 = 1000;
const HEIGHT: i32 = 800;
@ -128,6 +127,7 @@ pub fn start_game() -> Result<(), String> {
let window = video_subsystem
.window("reimtris2", WIDTH as u32, HEIGHT as u32)
.resizable()
.position_centered()
.build()
.unwrap();

View File

@ -26,7 +26,9 @@ pub trait UiCtx<Err> {
height: i32,
) -> Result<(), Err>;
fn clear(&mut self, rgb: &Rgb) -> Result<(), Err>;
}
pub trait GameUiCtx<Err>: UiCtx<Err> {
fn draw_tetromino_from_parts(
&mut self,
x: i8,
@ -131,6 +133,8 @@ pub trait UiCtx<Err> {
}
}
impl<T, Err> GameUiCtx<Err> for T where T: UiCtx<Err> {}
pub struct Rgb(pub u8, pub u8, pub u8);
impl Rgb {