Graphical fixes

This commit is contained in:
2024-11-28 12:39:08 -05:00
parent 83377ff5fa
commit 9ff62af310
4 changed files with 56 additions and 15 deletions
+12 -2
View File
@@ -171,14 +171,24 @@ struct GameScreenCallback {
impl egui_wgpu::CallbackTrait for GameScreenCallback {
fn paint(
&self,
_info: egui::PaintCallbackInfo,
info: egui::PaintCallbackInfo,
render_pass: &mut wgpu::RenderPass<'static>,
callback_resources: &egui_wgpu::CallbackResources,
) {
let resources: &SharedGameScreenResources = callback_resources.get().unwrap();
// TODO: maintain aspect ratio
let viewport = info.viewport_in_pixels();
let left = viewport.left_px as f32;
let top = viewport.top_px as f32;
let width = viewport.width_px as f32;
let height = viewport.height_px as f32;
let aspect_ratio = 384.0 / 224.0;
let w = width.min(height * aspect_ratio);
let h = height.min(width / aspect_ratio);
let x = left + (width - w) / 2.0;
let y = top + (height - h) / 2.0;
render_pass.set_pipeline(&resources.pipeline);
render_pass.set_bind_group(0, &self.bind_group, &[]);
render_pass.set_viewport(x, y, w, h, 0.0, 1.0);
render_pass.draw(0..6, 0..1);
}
}