remove pixels, add softbuffer for drawing to window
This commit is contained in:
parent
205cd566cb
commit
0aa66e3ebd
7 changed files with 268 additions and 747 deletions
46
src/gui_window.rs
Normal file
46
src/gui_window.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use softbuffer::Buffer;
|
||||
use std::{num::NonZero, rc::Rc};
|
||||
use winit::{dpi::LogicalSize, event_loop::ActiveEventLoop, window::Window};
|
||||
|
||||
type Context = softbuffer::Context<Rc<Window>>;
|
||||
type Surface = softbuffer::Surface<Rc<Window>, Rc<Window>>;
|
||||
|
||||
pub struct GuiWindow {
|
||||
winit_window: Rc<Window>,
|
||||
surface: Surface,
|
||||
}
|
||||
|
||||
impl GuiWindow {
|
||||
pub fn new(
|
||||
event_loop: &ActiveEventLoop,
|
||||
logical_size: LogicalSize<u16>,
|
||||
) -> GuiWindow {
|
||||
let attributes = Window::default_attributes()
|
||||
.with_title("servicepoint-simulator")
|
||||
.with_min_inner_size(logical_size)
|
||||
.with_inner_size(logical_size)
|
||||
.with_transparent(false);
|
||||
let winit_window =
|
||||
Rc::new(event_loop.create_window(attributes).unwrap());
|
||||
let context = Context::new(winit_window.clone()).unwrap();
|
||||
let mut surface = Surface::new(&context, winit_window.clone()).unwrap();
|
||||
surface
|
||||
.resize(
|
||||
NonZero::new(logical_size.width as u32).unwrap(),
|
||||
NonZero::new(logical_size.height as u32).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Self {
|
||||
winit_window,
|
||||
surface,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_buffer(&mut self) -> Buffer<Rc<Window>, Rc<Window>> {
|
||||
self.surface.buffer_mut().unwrap()
|
||||
}
|
||||
pub(crate) fn request_redraw(&self) {
|
||||
self.winit_window.request_redraw();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue