format
This commit is contained in:
parent
b873398a79
commit
e2d5748733
41 changed files with 291 additions and 268 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//! Provides functionality to create either a vulkan or opengl window
|
||||
pub mod window_config;
|
||||
pub mod platforms;
|
||||
pub use glfw as glfw;
|
||||
pub mod window_config;
|
||||
pub use glfw;
|
||||
|
||||
use crate::platforms::glfw_window::GLFWWindow;
|
||||
|
||||
|
|
@ -10,8 +10,7 @@ pub enum WindowRenderContext {
|
|||
OPENGLGLFW,
|
||||
}
|
||||
|
||||
pub trait WindowResult {
|
||||
}
|
||||
pub trait WindowResult {}
|
||||
|
||||
pub trait MoonhareWindow {
|
||||
fn init() -> GLFWWindow;
|
||||
|
|
@ -19,9 +18,7 @@ pub trait MoonhareWindow {
|
|||
fn shutdown();
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
}
|
||||
|
||||
pub struct Window {}
|
||||
|
||||
impl Window {
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
@ -39,4 +36,4 @@ impl Window {
|
|||
pub fn create() {
|
||||
todo!("moonhare engine only supports linux for now")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ use std::{cell::RefCell, rc::Rc, sync::Arc};
|
|||
use glfw::{Context, Glfw, GlfwReceiver, PWindow, Window, WindowEvent};
|
||||
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
|
||||
|
||||
use crate::{window_config, MoonhareWindow};
|
||||
use crate::{MoonhareWindow, window_config};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GLFWWindow {
|
||||
// Todo: learn more about rust smart pointers so i actually understand whats going on here, but hey it works for now
|
||||
// Todo: learn more about rust smart pointers so i actually understand whats going on here, but hey it works for now
|
||||
pub glfw_window: Rc<RefCell<PWindow>>,
|
||||
pub events: Rc<RefCell<GlfwReceiver<(f64, WindowEvent)>>>,
|
||||
pub glfw: Glfw,
|
||||
|
|
@ -18,7 +18,12 @@ const APP_ID: &str = "de.lunarakai.moonhare_engine";
|
|||
|
||||
impl Clone for GLFWWindow {
|
||||
fn clone(&self) -> Self {
|
||||
Self { glfw_window: self.glfw_window.clone(), events: self.events.clone(), glfw: self.glfw.clone(), is_running: self.is_running.clone() }
|
||||
Self {
|
||||
glfw_window: self.glfw_window.clone(),
|
||||
events: self.events.clone(),
|
||||
glfw: self.glfw.clone(),
|
||||
is_running: self.is_running.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,11 +31,13 @@ impl GLFWWindow {
|
|||
fn new() -> Self {
|
||||
let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
|
||||
let config = window_config::WindowConfig::default();
|
||||
let (mut window, events) = glfw.create_window(
|
||||
config.width,
|
||||
config.height,
|
||||
format!("{} GLFW {}", config.title, glfw::get_version_string()).as_str(),
|
||||
glfw::WindowMode::Windowed)
|
||||
let (mut window, events) = glfw
|
||||
.create_window(
|
||||
config.width,
|
||||
config.height,
|
||||
format!("{} GLFW {}", config.title, glfw::get_version_string()).as_str(),
|
||||
glfw::WindowMode::Windowed,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
window.set_key_polling(true);
|
||||
|
|
@ -40,36 +47,29 @@ impl GLFWWindow {
|
|||
glfw_window: Rc::new(RefCell::new(window)),
|
||||
events: Rc::new(RefCell::new(events)),
|
||||
glfw: glfw,
|
||||
is_running: true
|
||||
is_running: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn handle_window_event(&self, event: glfw::WindowEvent) {
|
||||
|
||||
match event {
|
||||
glfw::WindowEvent::Close => {
|
||||
WindowCloseEvent::emit();
|
||||
}
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MoonhareWindow for GLFWWindow {
|
||||
impl MoonhareWindow for GLFWWindow {
|
||||
fn init() -> GLFWWindow {
|
||||
let window = GLFWWindow::new();
|
||||
window
|
||||
}
|
||||
|
||||
|
||||
fn on_update() {
|
||||
|
||||
}
|
||||
fn on_update() {}
|
||||
|
||||
fn shutdown() {
|
||||
// todo: emit WindowCloseEvent
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
pub mod glfw_window;
|
||||
pub mod glfw_window;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ pub struct WindowConfig {
|
|||
|
||||
impl Default for WindowConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: "Moonhare Engine".to_owned(),
|
||||
width: 1280,
|
||||
Self {
|
||||
title: "Moonhare Engine".to_owned(),
|
||||
width: 1280,
|
||||
height: 720,
|
||||
visble: default_visibility(),
|
||||
decorations: default_decorations(),
|
||||
|
|
@ -25,7 +25,7 @@ impl WindowConfig {
|
|||
fn set_window_name(mut self, name: String) {
|
||||
self.title = name;
|
||||
}
|
||||
|
||||
|
||||
fn set_window_height(mut self, new_height: u32) {
|
||||
self.height = new_height;
|
||||
}
|
||||
|
|
@ -49,4 +49,4 @@ fn default_visibility() -> bool {
|
|||
|
||||
fn default_decorations() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue