that's how it's done, this winit shim is pretty small so I'mma just steal it and substitute my custom events in my own local winit shim
This commit is contained in:
13
Cargo.toml
13
Cargo.toml
@@ -15,7 +15,7 @@ typed-arena = "2.0.1"
|
|||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
png = "0.16"
|
png = "0.16"
|
||||||
winit = "0.24.0"
|
#winit = { version = "0.24.0"}
|
||||||
rand = { version = "0.7.2", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.2", features = ["wasm-bindgen"] }
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
noise = "0.6"
|
noise = "0.6"
|
||||||
@@ -32,4 +32,13 @@ legion = "0.3.1"
|
|||||||
wgpu = "0.7.0"
|
wgpu = "0.7.0"
|
||||||
imgui = "0.7.0"
|
imgui = "0.7.0"
|
||||||
imgui-wgpu = "0.14.0"
|
imgui-wgpu = "0.14.0"
|
||||||
imgui-winit-support = "0.7.0"
|
|
||||||
|
winit-19 = { version = ">= 0.16, < 0.20", package = "winit", optional = true }
|
||||||
|
winit-20 = { version = ">= 0.20, < 0.22", package = "winit", optional = true }
|
||||||
|
winit-22 = { version = "0.22", package = "winit", optional = true }
|
||||||
|
winit-23 = { version = "0.23", package = "winit", optional = true }
|
||||||
|
winit-24 = { version = "0.24", package = "winit", optional = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["winit-24"]
|
||||||
|
debug = ["winit-24"]
|
||||||
@@ -2,8 +2,8 @@ use std::f32::consts::{FRAC_PI_2, PI};
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use cgmath::{Decomposed, InnerSpace, Matrix4, Point3, Rad, Vector3};
|
use cgmath::{Decomposed, InnerSpace, Matrix4, Point3, Rad, Vector3};
|
||||||
use winit::dpi::{LogicalPosition, PhysicalPosition};
|
use winit_24::dpi::{LogicalPosition, PhysicalPosition};
|
||||||
use winit::event::{ElementState, MouseScrollDelta, VirtualKeyCode};
|
use winit_24::event::{ElementState, MouseScrollDelta, VirtualKeyCode};
|
||||||
|
|
||||||
use crate::render::OPENGL_TO_WGPU_MATRIX;
|
use crate::render::OPENGL_TO_WGPU_MATRIX;
|
||||||
|
|
||||||
|
|||||||
1165
src/extended_winit_imgui_support.rs
Normal file
1165
src/extended_winit_imgui_support.rs
Normal file
File diff suppressed because it is too large
Load Diff
21
src/main.rs
21
src/main.rs
@@ -1,8 +1,7 @@
|
|||||||
extern crate imgui;
|
extern crate imgui;
|
||||||
extern crate imgui_wgpu;
|
extern crate imgui_wgpu;
|
||||||
extern crate imgui_winit_support;
|
|
||||||
extern crate tobj;
|
extern crate tobj;
|
||||||
extern crate winit;
|
extern crate winit_24;
|
||||||
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -31,13 +30,13 @@ use rapier3d::na::{Isometry, Isometry3, Vector, Vector3};
|
|||||||
use rapier3d::pipeline::PhysicsPipeline;
|
use rapier3d::pipeline::PhysicsPipeline;
|
||||||
use wgpu::{BindGroup, Buffer, TextureView};
|
use wgpu::{BindGroup, Buffer, TextureView};
|
||||||
use wgpu_subscriber;
|
use wgpu_subscriber;
|
||||||
use winit::{
|
use winit_24::{
|
||||||
event::{self, WindowEvent},
|
event::{self, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
};
|
};
|
||||||
use winit::event::DeviceEvent::MouseMotion;
|
use winit_24::event::DeviceEvent::MouseMotion;
|
||||||
use winit::platform::unix::x11::ffi::Time;
|
use winit_24::platform::unix::x11::ffi::Time;
|
||||||
use winit::window::Window;
|
use winit_24::window::Window;
|
||||||
|
|
||||||
use crate::camera::{Camera, CameraController};
|
use crate::camera::{Camera, CameraController};
|
||||||
use crate::components::{Collider, Color, LoopState, Physics, Position};
|
use crate::components::{Collider, Color, LoopState, Physics, Position};
|
||||||
@@ -47,7 +46,7 @@ use crate::render::Renderer;
|
|||||||
use legion::systems::{UnsafeResources, SyncResources};
|
use legion::systems::{UnsafeResources, SyncResources};
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use imgui::__core::convert::TryInto;
|
use imgui::__core::convert::TryInto;
|
||||||
use imgui_winit_support::WinitPlatform;
|
use crate::extended_winit_imgui_support::WinitPlatform;
|
||||||
|
|
||||||
mod camera;
|
mod camera;
|
||||||
mod components;
|
mod components;
|
||||||
@@ -56,6 +55,7 @@ mod light;
|
|||||||
mod owned_event;
|
mod owned_event;
|
||||||
mod physics;
|
mod physics;
|
||||||
mod render;
|
mod render;
|
||||||
|
mod extended_winit_imgui_support;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@@ -107,7 +107,6 @@ fn main() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut update_schedule = Schedule::builder()
|
let mut update_schedule = Schedule::builder()
|
||||||
.add_system(physics::test_unsafe_system())
|
|
||||||
.add_system(physics::update_camera_system())
|
.add_system(physics::update_camera_system())
|
||||||
.add_system(physics::run_physics_system())
|
.add_system(physics::run_physics_system())
|
||||||
.add_system(physics::update_models_system())
|
.add_system(physics::update_models_system())
|
||||||
@@ -119,7 +118,7 @@ fn main() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let event_loop = EventLoop::<OwnedEventExtension>::with_user_event();
|
let event_loop = EventLoop::<OwnedEventExtension>::with_user_event();
|
||||||
let mut builder = winit::window::WindowBuilder::new();
|
let mut builder = winit_24::window::WindowBuilder::new();
|
||||||
builder = builder.with_title("MVGE");
|
builder = builder.with_title("MVGE");
|
||||||
|
|
||||||
let window = builder.build(&event_loop).unwrap();
|
let window = builder.build(&event_loop).unwrap();
|
||||||
@@ -129,11 +128,11 @@ fn main() {
|
|||||||
// Load up all the resources
|
// Load up all the resources
|
||||||
{
|
{
|
||||||
let mut imgui_context = imgui::Context::create();
|
let mut imgui_context = imgui::Context::create();
|
||||||
let mut platform = imgui_winit_support::WinitPlatform::init(&mut imgui_context);
|
let mut platform = extended_winit_imgui_support::WinitPlatform::init(&mut imgui_context);
|
||||||
platform.attach_window(
|
platform.attach_window(
|
||||||
imgui_context.io_mut(),
|
imgui_context.io_mut(),
|
||||||
&window,
|
&window,
|
||||||
imgui_winit_support::HiDpiMode::Default,
|
extended_winit_imgui_support::HiDpiMode::Default,
|
||||||
);
|
);
|
||||||
|
|
||||||
// imgui rendering context
|
// imgui rendering context
|
||||||
|
|||||||
@@ -3,18 +3,20 @@ use std::path::PathBuf;
|
|||||||
use gilrs::Event as GilEvent;
|
use gilrs::Event as GilEvent;
|
||||||
use legion::world::SubWorld;
|
use legion::world::SubWorld;
|
||||||
use legion::*;
|
use legion::*;
|
||||||
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
use winit_24::dpi::{PhysicalPosition, PhysicalSize};
|
||||||
use winit::event::DeviceEvent::MouseMotion;
|
use winit_24::event::DeviceEvent::MouseMotion;
|
||||||
use winit::event::{
|
use winit_24::event::{
|
||||||
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
|
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
|
||||||
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
|
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
|
||||||
};
|
};
|
||||||
use winit::window::{Theme, WindowId, Window};
|
use winit_24::window::{Theme, WindowId, Window};
|
||||||
|
|
||||||
use crate::camera::{Camera, CameraController};
|
use crate::camera::{Camera, CameraController};
|
||||||
use crate::owned_event::OwnedWindowEvent::MouseWheel;
|
use crate::owned_event::OwnedWindowEvent::MouseWheel;
|
||||||
use crate::{ImguiPlatform, ImguiContext};
|
use crate::{ImguiPlatform, ImguiContext};
|
||||||
use std::sync::{Mutex, Arc};
|
use std::sync::{Mutex, Arc};
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use imgui::Io;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum OwnedUIEvent<T> {
|
pub enum OwnedUIEvent<T> {
|
||||||
@@ -239,6 +241,7 @@ pub enum OwnedWindowEvent {
|
|||||||
ThemeChanged(Theme),
|
ThemeChanged(Theme),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Because I am a glutton for punishment I am going to just do a mono-event-dispatch-magoooo
|
/// Because I am a glutton for punishment I am going to just do a mono-event-dispatch-magoooo
|
||||||
#[system]
|
#[system]
|
||||||
#[write_component(Camera)]
|
#[write_component(Camera)]
|
||||||
@@ -250,13 +253,13 @@ pub fn event_dispatch(
|
|||||||
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
||||||
#[resource] winit_window: &mut Window,
|
#[resource] winit_window: &mut Window,
|
||||||
) {
|
) {
|
||||||
use winit::event::Event::DeviceEvent;
|
use winit_24::event::Event::DeviceEvent;
|
||||||
|
|
||||||
for event in event_stack {
|
for event in event_stack {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
OwnedEvent::DeviceEvent {
|
OwnedEvent::DeviceEvent {
|
||||||
event: winit::event::DeviceEvent::MouseMotion { delta },
|
event: winit_24::event::DeviceEvent::MouseMotion { delta },
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut query = <(&mut CameraController)>::query();
|
let mut query = <(&mut CameraController)>::query();
|
||||||
@@ -265,7 +268,7 @@ pub fn event_dispatch(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
OwnedEvent::DeviceEvent {
|
OwnedEvent::DeviceEvent {
|
||||||
event: winit::event::DeviceEvent::Key(keyboard_input),
|
event: winit_24::event::DeviceEvent::Key(keyboard_input),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut query = <(&mut CameraController)>::query();
|
let mut query = <(&mut CameraController)>::query();
|
||||||
@@ -297,6 +300,6 @@ pub fn event_dispatch(
|
|||||||
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
|
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
|
||||||
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
|
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
|
||||||
|
|
||||||
imgui_platform.handle_event(imgui_context.io_mut(), &winit_window, &event.into());
|
imgui_platform.handle_event(imgui_context.io_mut(), &winit_window, &event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,17 +87,6 @@ pub fn run_physics(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[system]
|
|
||||||
#[write_component(Camera)]
|
|
||||||
pub fn test_unsafe(world: &mut SubWorld,
|
|
||||||
#[resource] loop_state: &mut LoopState,
|
|
||||||
// #[resource] imgui_context: &mut imgui::Context,
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[system]
|
#[system]
|
||||||
#[write_component(Camera)]
|
#[write_component(Camera)]
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ use wgpu::{
|
|||||||
Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView,
|
Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView,
|
||||||
VertexState,
|
VertexState,
|
||||||
};
|
};
|
||||||
use winit::dpi::PhysicalSize;
|
use winit_24::dpi::PhysicalSize;
|
||||||
use winit::platform::unix::x11::ffi::Time;
|
use winit_24::platform::unix::x11::ffi::Time;
|
||||||
use winit::window::Window;
|
use winit_24::window::Window;
|
||||||
|
|
||||||
use crate::camera::{Camera, CameraController};
|
use crate::camera::{Camera, CameraController};
|
||||||
use crate::components::{Color, Mesh, Position, RangeCopy};
|
use crate::components::{Color, Mesh, Position, RangeCopy};
|
||||||
use crate::geometry::{import_mesh, vertex, Vertex};
|
use crate::geometry::{import_mesh, vertex, Vertex};
|
||||||
use crate::light::{DirectionalLight, LightRaw};
|
use crate::light::{DirectionalLight, LightRaw};
|
||||||
use imgui_winit_support::WinitPlatform;
|
|
||||||
use imgui::*;
|
use imgui::*;
|
||||||
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
|
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|||||||
Reference in New Issue
Block a user