breaking: Use raw-window-handle version 0.6
Signed-off-by: John Nunley <dev@notgull.net> Co-Authored-By: dAxpeDDa <daxpedda@gmail.com>
This commit is contained in:
parent
18c944736e
commit
0bcd2e22a2
22 changed files with 830 additions and 628 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use image::GenericImageView;
|
||||
use std::num::NonZeroU32;
|
||||
use std::rc::Rc;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
|
|
@ -8,11 +9,13 @@ fn main() {
|
|||
//see fruit.jpg.license for the license of fruit.jpg
|
||||
let fruit = image::load_from_memory(include_bytes!("fruit.jpg")).unwrap();
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new()
|
||||
.with_inner_size(winit::dpi::PhysicalSize::new(fruit.width(), fruit.height()))
|
||||
.build(&event_loop)
|
||||
.unwrap();
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let window = Rc::new(
|
||||
WindowBuilder::new()
|
||||
.with_inner_size(winit::dpi::PhysicalSize::new(fruit.width(), fruit.height()))
|
||||
.build(&event_loop)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
|
|
@ -24,45 +27,50 @@ fn main() {
|
|||
.unwrap()
|
||||
.body()
|
||||
.unwrap()
|
||||
.append_child(&window.canvas())
|
||||
.append_child(&window.canvas().unwrap())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let context = unsafe { softbuffer::Context::new(&window) }.unwrap();
|
||||
let mut surface = unsafe { softbuffer::Surface::new(&context, &window) }.unwrap();
|
||||
let context = softbuffer::Context::new(window.clone()).unwrap();
|
||||
let mut surface = softbuffer::Surface::new(&context, window.clone()).unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
event_loop
|
||||
.run(move |event, elwt| {
|
||||
elwt.set_control_flow(ControlFlow::Wait);
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(fruit.width()).unwrap(),
|
||||
NonZeroU32::new(fruit.height()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::CloseRequested,
|
||||
} if window_id == window.id() => {
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(fruit.width()).unwrap(),
|
||||
NonZeroU32::new(fruit.height()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
let width = fruit.width() as usize;
|
||||
for (x, y, pixel) in fruit.pixels() {
|
||||
let red = pixel.0[0] as u32;
|
||||
let green = pixel.0[1] as u32;
|
||||
let blue = pixel.0[2] as u32;
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
let width = fruit.width() as usize;
|
||||
for (x, y, pixel) in fruit.pixels() {
|
||||
let red = pixel.0[0] as u32;
|
||||
let green = pixel.0[1] as u32;
|
||||
let blue = pixel.0[2] as u32;
|
||||
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
buffer[y as usize * width + x as usize] = color;
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
buffer[y as usize * width + x as usize] = color;
|
||||
}
|
||||
|
||||
buffer.present().unwrap();
|
||||
}
|
||||
|
||||
buffer.present().unwrap();
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
elwt.exit();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue