renders great. need to 2 step it so I can render in the other systems, and figure out how to get winit events into the system. bleh

master
mitchellhansen 4 years ago
parent 0a7fe889d2
commit 6fb6e433fb

@ -143,9 +143,8 @@ fn main() {
let mut imgui_platform = ImguiPlatform { let mut imgui_platform = ImguiPlatform {
platform: platform, platform: platform,
}; };
let font_size = 10.0 as f32; let font_size = 20.0 as f32;
imgui_context.context.io_mut().font_global_scale = 10.0 as f32; imgui_context.context.io_mut().font_global_scale = 1.0 as f32;
imgui_context.context.fonts().add_font(&[FontSource::DefaultFontData { imgui_context.context.fonts().add_font(&[FontSource::DefaultFontData {
config: Some(imgui::FontConfig { config: Some(imgui::FontConfig {
oversample_h: 1, oversample_h: 1,

@ -9,10 +9,12 @@ use winit::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}; use winit::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 std::sync::{Mutex, Arc};
#[derive(Clone)] #[derive(Clone)]
pub enum OwnedUIEvent<T> { pub enum OwnedUIEvent<T> {
@ -244,10 +246,14 @@ pub enum OwnedWindowEvent {
pub fn event_dispatch( pub fn event_dispatch(
world: &mut SubWorld, world: &mut SubWorld,
#[resource] event_stack: &mut Vec<OwnedEvent<OwnedEventExtension>>, #[resource] event_stack: &mut Vec<OwnedEvent<OwnedEventExtension>>,
#[resource] imgui_context: &mut Arc<Mutex<ImguiContext>>,
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
#[resource] winit_window: &mut Window,
) { ) {
use winit::event::Event::DeviceEvent; use winit::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::event::DeviceEvent::MouseMotion { delta },
@ -288,5 +294,9 @@ pub fn event_dispatch(
} }
_ => {} _ => {}
} }
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
imgui_platform.handle_event(imgui_context.io_mut(), &winit_window, &event.into());
} }
} }

@ -246,50 +246,43 @@ pub fn render_test(
{ {
// 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_state.context.io_mut().update_delta_time(Duration::new(0,160)); //imgui_state.context.io_mut().update_delta_time(Duration::new(0,160));
// imgui_platform imgui_platform
// .prepare_frame(imgui_context.io_mut(), &winit_window) .prepare_frame(imgui_context.io_mut(), &winit_window)
// .expect("Failed to prepare frame"); .expect("Failed to prepare frame");
//
// // get the frame and build a ui window // get the frame and build a ui window
// let ui = imgui_context.frame(); let ui = imgui_context.frame();
// let window = imgui::Window::new(im_str!("Hello too")); let window = imgui::Window::new(im_str!("Hello too"));
// window window
// .size([400.0, 200.0], Condition::FirstUseEver) .size([400.0, 100.0], Condition::FirstUseEver)
// .position([400.0, 200.0], Condition::FirstUseEver) .position([50.0, 50.0], Condition::FirstUseEver)
// .build(&ui, || { .build(&ui, || {
// ui.text(im_str!("Frametime: {:?}", 10.0)); ui.text(im_str!("Frametime: {:?}", 10.0));
// }); });
//
//
// //ui.show_demo_window(&mut demo_open); //ui.show_demo_window(&mut demo_open);
// imgui_platform.prepare_render(&ui, &winit_window); imgui_platform.prepare_render(&ui, &winit_window);
//
// let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
// label: None,
// color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
// attachment: &frame.output.view,
// resolve_target: None,
// ops: wgpu::Operations {
// load: wgpu::LoadOp::Clear(wgpu::Color {
// r: 0.1,
// g: 0.2,
// b: 0.3,
// a: 1.0,
// }),
// store: true,
// },
// }],
// depth_stencil_attachment: None,
// });
// renderer.imgui_renderer
// .render(ui.render(), &renderer.queue, &renderer.device, &mut rpass)
// .expect("Rendering failed");
//
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
depth_stencil_attachment: None,
});
renderer.imgui_renderer
.render(ui.render(), &renderer.queue, &renderer.device, &mut rpass)
.expect("Rendering failed");
} }

Loading…
Cancel
Save