gtk window
This commit is contained in:
parent
30ff2325f2
commit
0c3a160dd5
12 changed files with 437 additions and 1714 deletions
|
|
@ -5,6 +5,5 @@ version.workspace = true
|
|||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
ash = "0.38"
|
||||
glium = "0.36"
|
||||
moonhare_log = { path = "../moonhare_log" }
|
||||
moonhare_log = { path = "../moonhare_log" }
|
||||
gtk4 = "*"
|
||||
|
|
@ -1 +1,4 @@
|
|||
# MoonhareWindow
|
||||
# MoonhareWindow
|
||||
|
||||
- Only functionality is to create a Window with either OpenGL or Vulkan Context
|
||||
- rendering stuff(tm) on the window is handled by the [moonhare_graphics](../moonhare_graphics/) crate
|
||||
|
|
@ -1,35 +1,47 @@
|
|||
//! Provides functionality to create either a vulkan or opengl window
|
||||
|
||||
use crate::opengl_window::create_open_gl_window;
|
||||
use std::marker;
|
||||
|
||||
pub mod window_config;
|
||||
pub mod opengl_window;
|
||||
|
||||
pub mod platforms;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum WindowRenderContext {
|
||||
VULKAN, // TODO
|
||||
OPENGL,
|
||||
OPENGLGTK,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct MoonhareWindow {
|
||||
render_context: WindowRenderContext
|
||||
pub trait WindowResult {
|
||||
}
|
||||
|
||||
impl MoonhareWindow {
|
||||
pub fn define_context(context: WindowRenderContext) -> Self {
|
||||
Self {
|
||||
render_context: context
|
||||
}
|
||||
pub trait MoonhareWindow {
|
||||
type WindowResult;
|
||||
fn init() -> Self::WindowResult;
|
||||
fn on_update();
|
||||
fn shutdown();
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
|
||||
}
|
||||
|
||||
impl Window {
|
||||
/// creates a gtk4 window
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn create() {
|
||||
use gtk4::gio::prelude::ApplicationExtManual;
|
||||
|
||||
use crate::platforms::gtk_window::GTKWindow;
|
||||
|
||||
let application = GTKWindow::init();
|
||||
|
||||
application.get_application().run();
|
||||
}
|
||||
|
||||
pub fn create_window_from_context(self) {
|
||||
match self.render_context {
|
||||
WindowRenderContext::VULKAN => {
|
||||
todo!("Vulkan not implemented yet")
|
||||
},
|
||||
WindowRenderContext::OPENGL => {
|
||||
create_open_gl_window();
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn create() {
|
||||
todo!("moonhare engine only supports linux for now")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
use glium::{winit::dpi::{LogicalPosition, LogicalSize}, Surface};
|
||||
|
||||
use crate::window_config::WindowConfig;
|
||||
|
||||
pub fn create_open_gl_window() {
|
||||
let event_loop = glium::winit::event_loop::EventLoopBuilder::new().build().expect("event loop building");
|
||||
let (mut _window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
|
||||
|
||||
let config = WindowConfig::default();
|
||||
_window.set_title(format!("{} OpenGL", &config.title).as_str());
|
||||
_window.set_decorations(config.decorations);
|
||||
_window.set_visible(config.visble);
|
||||
//_window.set_min_inner_size(Some(LogicalSize::new(config.width, config.height)));
|
||||
|
||||
|
||||
let mut frame = display.draw();
|
||||
frame.clear_color(0.0, 0.0, 1.0, 1.0);
|
||||
frame.finish().unwrap();
|
||||
|
||||
let _ = event_loop.run(move | event, window_target| {
|
||||
match event {
|
||||
glium::winit::event::Event::WindowEvent { event, .. } => match event {
|
||||
glium::winit::event::WindowEvent::CloseRequested => {
|
||||
window_target.exit()
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
51
crates/moonhare_window/src/platforms/gtk_window.rs
Normal file
51
crates/moonhare_window/src/platforms/gtk_window.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use gtk4::{gio::prelude::{ApplicationExt, ApplicationExtManual}, glib::object::ObjectExt, prelude::{GtkWindowExt, WidgetExt}, subclass::prelude::GtkApplicationImpl, Application, ApplicationWindow};
|
||||
|
||||
use crate::{MoonhareWindow, WindowResult};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GTKWindow {
|
||||
application: Application,
|
||||
}
|
||||
|
||||
const APP_ID: &str = "de.lunarakai.moonhare_engine";
|
||||
|
||||
impl GTKWindow {
|
||||
pub fn get_application(self) -> Application {
|
||||
self.application
|
||||
}
|
||||
|
||||
fn build_ui(application: &Application) {
|
||||
let window = ApplicationWindow::new(application);
|
||||
window.set_title(Some("Moonhare Engine GTK"));
|
||||
window.set_default_size(1280, 720);
|
||||
|
||||
window.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl MoonhareWindow for GTKWindow {
|
||||
type WindowResult = GTKWindow;
|
||||
fn init() -> Self::WindowResult {
|
||||
let app = Application::builder().application_id(APP_ID).build();
|
||||
|
||||
app.connect_activate(GTKWindow::build_ui);
|
||||
|
||||
Self {
|
||||
application: app
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn on_update() {
|
||||
|
||||
}
|
||||
|
||||
fn shutdown() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
1
crates/moonhare_window/src/platforms/mod.rs
Normal file
1
crates/moonhare_window/src/platforms/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod gtk_window;
|
||||
Loading…
Add table
Add a link
Reference in a new issue