Graphical fixes
This commit is contained in:
+7
-6
@@ -3,8 +3,8 @@ use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
};
|
||||
use egui::{
|
||||
menu, Button, CentralPanel, Color32, Context, Response, TopBottomPanel, Ui, ViewportBuilder,
|
||||
ViewportCommand, ViewportId, WidgetText,
|
||||
menu, Button, CentralPanel, Color32, Context, Frame, Response, TopBottomPanel, Ui,
|
||||
ViewportBuilder, ViewportCommand, ViewportId, WidgetText,
|
||||
};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
|
||||
@@ -67,7 +67,7 @@ impl GameWindow {
|
||||
for scale in 1..=4 {
|
||||
let label = format!("x{scale}");
|
||||
let scale = scale as f32;
|
||||
let dims = (384.0 * scale, 224.0 * scale + 20.0).into();
|
||||
let dims = (384.0 * scale, 224.0 * scale + 22.0).into();
|
||||
if ui
|
||||
.selectable_button((current_dims - dims).length() < 1.0, label)
|
||||
.clicked()
|
||||
@@ -133,18 +133,19 @@ impl AppWindow for GameWindow {
|
||||
fn initial_viewport(&self) -> ViewportBuilder {
|
||||
ViewportBuilder::default()
|
||||
.with_title("Shrooms VB")
|
||||
.with_inner_size((384.0, 244.0))
|
||||
.with_inner_size((384.0, 246.0))
|
||||
}
|
||||
|
||||
fn show(&mut self, ctx: &Context) {
|
||||
TopBottomPanel::top("menubar")
|
||||
.exact_height(20.0)
|
||||
.exact_height(22.0)
|
||||
.show(ctx, |ui| {
|
||||
menu::bar(ui, |ui| {
|
||||
self.show_menu(ctx, ui);
|
||||
});
|
||||
});
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
let frame = Frame::central_panel(&ctx.style()).fill(Color32::BLACK);
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
if let Some(screen) = self.screen.as_ref() {
|
||||
ui.add(screen);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user