Precursor to triangle in editor

This commit is contained in:
Richard Feldman 2020-05-05 21:40:14 -04:00
parent 931910532b
commit 05e13e9842
5 changed files with 99 additions and 7 deletions

View file

@ -1,4 +1,11 @@
use gfx_hal::{
device::Device,
window::{Extent2D, PresentationSurface, Surface},
Instance,
};
use glsl_to_spirv::ShaderType;
use std::io;
use std::mem::ManuallyDrop;
use std::path::Path;
/// The editor is actually launched from the CLI if you pass it zero arguments,
@ -18,10 +25,38 @@ use winit::{
};
fn run_event_loop() {
// TODO do a better window size
const WINDOW_SIZE: [u32; 2] = [512, 512];
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let (logical_window_size, physical_window_size) = {
use winit::dpi::{LogicalSize, PhysicalSize};
let dpi = event_loop.primary_monitor().scale_factor();
let logical: LogicalSize<u32> = WINDOW_SIZE.into();
let physical: PhysicalSize<u32> = logical.to_physical(dpi);
(logical, physical)
};
let mut surface_extent = Extent2D {
width: physical_window_size.width,
height: physical_window_size.height,
};
let window = WindowBuilder::new()
.with_title("roc")
.with_inner_size(logical_window_size)
.build(&event_loop)
.unwrap();
let mut should_configure_swapchain = true;
event_loop.run(move |event, _, control_flow| {
use winit::event::{Event, WindowEvent};
use winit::event_loop::ControlFlow;
// TODO try ControlFlow::Poll and see if it affects input latency.
// Otherwise, this seems like a better default for minimizing idle
// CPU usage and battry drain. (Might want to switch to Poll whenever
@ -30,12 +65,29 @@ fn run_event_loop() {
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
event: window_event,
..
} => {
println!("✈️ Thank you for flying Roc Airlines!");
*control_flow = ControlFlow::Exit
}
} => match window_event {
WindowEvent::CloseRequested => {
println!("✈️ Thank you for flying Roc Airlines!");
*control_flow = ControlFlow::Exit
}
WindowEvent::Resized(dims) => {
surface_extent = Extent2D {
width: dims.width,
height: dims.height,
};
should_configure_swapchain = true;
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
surface_extent = Extent2D {
width: new_inner_size.width,
height: new_inner_size.height,
};
should_configure_swapchain = true;
}
_ => (),
},
Event::MainEventsCleared => window.request_redraw(),
Event::RedrawRequested(_) => {
// TODO render the editor