fixes all around gfx and prometeu render
Intrepid/Prometeu/Runtime/pipeline/head There was a failure building this commit

This commit is contained in:
2026-05-16 13:02:47 +01:00
parent 74ef393294
commit eb398846a0
9 changed files with 83 additions and 281 deletions
@@ -4,6 +4,50 @@ use winit::event::{ElementState, MouseButton, WindowEvent};
use winit::keyboard::{KeyCode, PhysicalKey};
use winit::window::Window;
#[derive(Debug, Clone, Copy)]
struct FbViewport {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
pub scale: f32,
}
impl FbViewport {
fn framebuffer_viewport(window: &Window) -> Option<FbViewport> {
let size = window.inner_size();
let win_w = size.width as f32;
let win_h = size.height as f32;
if win_w <= 0.0 || win_h <= 0.0 {
return None;
}
let fb_w = Hardware::W as f32;
let fb_h = Hardware::H as f32;
let scale_x = (win_w / fb_w).floor();
let scale_y = (win_h / fb_h).floor();
let scale = scale_x.min(scale_y).max(1.0);
let viewport_w = fb_w * scale;
let viewport_h = fb_h * scale;
let viewport_x = ((win_w - viewport_w) * 0.5).floor();
let viewport_y = ((win_h - viewport_h) * 0.5).floor();
Some(FbViewport {
x: viewport_x,
y: viewport_y,
w: viewport_w,
h: viewport_h,
scale,
})
}
}
pub struct HostInputHandler {
pub signals: InputSignals,
}
@@ -49,9 +93,10 @@ impl HostInputHandler {
}
WindowEvent::CursorMoved { position, .. } => {
let v = window_to_fb(position.x as f32, position.y as f32, window);
self.signals.x_pos = v.0;
self.signals.y_pos = v.1;
if let Some((x, y)) = window_to_fb(position.x as f32, position.y as f32, window) {
self.signals.x_pos = x;
self.signals.y_pos = y;
}
}
WindowEvent::MouseInput { state, button, .. } if *button == MouseButton::Left => {
@@ -67,16 +112,24 @@ impl HostInputHandler {
_ => {}
}
fn window_to_fb(wx: f32, wy: f32, window: &Window) -> Option<(i32, i32)> {
let viewport = FbViewport::framebuffer_viewport(window)?;
let local_x = wx - viewport.x;
let local_y = wy - viewport.y;
if local_x < 0.0 || local_y < 0.0 || local_x >= viewport.w || local_y >= viewport.h {
return None;
}
let fb_x = (local_x / viewport.scale).floor() as i32;
let fb_y = (local_y / viewport.scale).floor() as i32;
Some((
fb_x.clamp(0, Hardware::W as i32 - 1),
fb_y.clamp(0, Hardware::H as i32 - 1),
))
}
}
}
pub fn window_to_fb(wx: f32, wy: f32, window: &Window) -> (i32, i32) {
let size = window.inner_size();
let fb_w = Hardware::W as f32;
let fb_h = Hardware::H as f32;
let x = (wx * fb_w / size.width as f32).floor() as i32;
let y = (wy * fb_h / size.height as f32).floor() as i32;
(x.clamp(0, Hardware::W as i32 - 1), y.clamp(0, Hardware::H as i32 - 1))
}
}