figuring out windows, eventually...
This commit is contained in:
parent
bbd2a6089c
commit
ceac5a09bb
9 changed files with 2033 additions and 8 deletions
1930
Cargo.lock
generated
1930
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,8 +14,8 @@ impl Event for KeyPressedEvent {
|
||||||
EventType::KeyPressed
|
EventType::KeyPressed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit(&self) -> &impl Event{
|
fn emit() {
|
||||||
self
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ impl Default for Game {
|
||||||
Self {
|
Self {
|
||||||
is_running: true,
|
is_running: true,
|
||||||
name: default_game_name(),
|
name: default_game_name(),
|
||||||
context: WindowRenderContext::OPENGLGTK
|
context: WindowRenderContext::OPENGLWINIT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ version.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bevy_ecs = "0.16.1"
|
||||||
|
|
||||||
moonhare_event = { path = "../moonhare_event" }
|
moonhare_event = { path = "../moonhare_event" }
|
||||||
moonhare_game = { path = "../moonhare_game" }
|
moonhare_game = { path = "../moonhare_game" }
|
||||||
moonhare_graphics = { path = "../moonhare_graphics" }
|
moonhare_graphics = { path = "../moonhare_graphics" }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// Writing an ecs from scratch seems hard, might do it in the future though
|
||||||
|
pub use bevy_ecs as ecs;
|
||||||
|
|
||||||
pub use moonhare_event as event;
|
pub use moonhare_event as event;
|
||||||
pub use moonhare_game as game;
|
pub use moonhare_game as game;
|
||||||
pub use moonhare_graphics as graphics;
|
pub use moonhare_graphics as graphics;
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,5 @@ authors.workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
moonhare_log = { path = "../moonhare_log" }
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
moonhare_event = { path = "../moonhare_event" }
|
moonhare_event = { path = "../moonhare_event" }
|
||||||
gtk4 = "*"
|
gtk4 = "*"
|
||||||
|
winit = "0.30"
|
||||||
|
|
@ -6,6 +6,7 @@ pub mod platforms;
|
||||||
pub enum WindowRenderContext {
|
pub enum WindowRenderContext {
|
||||||
VULKANGTK, // TODO
|
VULKANGTK, // TODO
|
||||||
OPENGLGTK,
|
OPENGLGTK,
|
||||||
|
OPENGLWINIT,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WindowResult {
|
pub trait WindowResult {
|
||||||
|
|
@ -39,11 +40,17 @@ impl Window {
|
||||||
use crate::platforms::gtk_window::GTKWindow;
|
use crate::platforms::gtk_window::GTKWindow;
|
||||||
|
|
||||||
thread::spawn(|| {
|
thread::spawn(|| {
|
||||||
moonhare_log::info("Created Window thread");
|
moonhare_log::info("Created GTK Window thread");
|
||||||
let application = GTKWindow::init();
|
let application = GTKWindow::init();
|
||||||
application.get_application().run();
|
application.get_application().run();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
WindowRenderContext::OPENGLWINIT => {
|
||||||
|
use crate::platforms::winit_window::WinitWindow;
|
||||||
|
|
||||||
|
moonhare_log::info("Creating Winit OpenGL Winit");
|
||||||
|
let application = WinitWindow::init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
pub mod gtk_window;
|
pub mod gtk_window;
|
||||||
|
pub mod winit_window;
|
||||||
85
crates/moonhare_window/src/platforms/winit_window.rs
Normal file
85
crates/moonhare_window/src/platforms/winit_window.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use winit::{application::ApplicationHandler, event::WindowEvent, event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, window::Window};
|
||||||
|
|
||||||
|
use crate::MoonhareWindow;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct WinitWindow {
|
||||||
|
window: Option<Arc<Window>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WinitWindow {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
window: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const APP_ID: &str = "de.lunarakai.moonhare_engine";
|
||||||
|
|
||||||
|
impl ApplicationHandler for WinitWindow {
|
||||||
|
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||||
|
self.window = Some(Arc::new(event_loop.create_window(Window::default_attributes()).unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
window_id: winit::window::WindowId,
|
||||||
|
event: winit::event::WindowEvent,
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
|
println!("The close button was pressed; stopping");
|
||||||
|
event_loop.exit();
|
||||||
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
// Redraw the application.
|
||||||
|
//
|
||||||
|
// It's preferable for applications that do not render continuously to render in
|
||||||
|
// this event rather than in AboutToWait, since rendering in here allows
|
||||||
|
// the program to gracefully handle redraws requested by the OS.
|
||||||
|
|
||||||
|
// Draw.
|
||||||
|
|
||||||
|
// Queue a RedrawRequested event.
|
||||||
|
//
|
||||||
|
// You only need to call this if you've determined that you need to redraw in
|
||||||
|
// applications which do not always need to. Applications that redraw continuously
|
||||||
|
// can render here instead.
|
||||||
|
self.window.as_ref().unwrap().request_redraw();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
impl MoonhareWindow for WinitWindow {
|
||||||
|
type WindowResult = WinitWindow;
|
||||||
|
fn init() -> Self::WindowResult {
|
||||||
|
let event_loop = EventLoop::new().unwrap();
|
||||||
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
|
let mut app = WinitWindow::default();
|
||||||
|
let _ = event_loop.run_app(&mut app);
|
||||||
|
|
||||||
|
// Need to find a better way because this will not return until the window is closed
|
||||||
|
app
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn on_update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shutdown() {
|
||||||
|
// todo: emit WindowCloseEvent
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue