gtk window
This commit is contained in:
parent
30ff2325f2
commit
0c3a160dd5
12 changed files with 437 additions and 1714 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
|||
/target
|
||||
*.log
|
||||
push_to_git.sh
|
||||
*.sh
|
||||
1920
Cargo.lock
generated
1920
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -16,9 +16,13 @@ Game Engine written in Rust
|
|||
### Crates
|
||||
- [MoonhareEngine](moonhare_engine/)
|
||||
- [MoonhareEvent](crates/moonhare_event/)
|
||||
- [MoonhareGame](crates/moonhare_game/)
|
||||
- core Engine functionality
|
||||
- [MoonhareGraphics](crates/moonhare_graphics/)
|
||||
- [MoonhareLog](crates/moonhare_log/)
|
||||
- Wrapper around the Log and fern crates
|
||||
- [MoonhareWindow](crates/moonhare_window/)
|
||||
- deals with OpenGL/Vulkan Window creation
|
||||
|
||||
|
||||
### Game Loop:
|
||||
|
|
|
|||
|
|
@ -1,70 +1,3 @@
|
|||
use moonhare_window::{window_config, MoonhareWindow};
|
||||
use moonhare_window::{window_config, MoonhareWindow, WindowResult};
|
||||
|
||||
use crate::{basic::node::Node, Game};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GameWindow {
|
||||
pub title: &'static str,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub visble: bool,
|
||||
pub decorations: bool,
|
||||
pub winit_window: Option<MoonhareWindow>,
|
||||
}
|
||||
|
||||
impl Node for GameWindow {
|
||||
}
|
||||
|
||||
impl Default for GameWindow {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: "window",
|
||||
width: default_game_window_width(),
|
||||
height: default_game_window_height(),
|
||||
visble: default_game_window_visibility(),
|
||||
decorations: default_game_window_decorations(),
|
||||
winit_window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GameWindow {
|
||||
pub fn create() -> Self {
|
||||
let mut window_config = window_config::WindowConfig::default();
|
||||
moonhare_log::info(format!("creating window with config {:?}", window_config));
|
||||
let mut window = Self::default();
|
||||
window_config.title = window.title.to_owned();
|
||||
window_config.width = window.width;
|
||||
window_config.height = window.height;
|
||||
window_config.visble = window.visble;
|
||||
window_config.decorations = window.decorations;
|
||||
|
||||
let _w = moonhare_window::MoonhareWindow::define_context(moonhare_window::WindowRenderContext::OPENGL);
|
||||
_w.create_window_from_context();
|
||||
|
||||
window.winit_window = Some(_w);
|
||||
// todo: tell winit to create a window for us
|
||||
moonhare_log::info(format!("created window {:?}", window));
|
||||
window
|
||||
}
|
||||
}
|
||||
|
||||
fn default_game_window_title() -> String {
|
||||
"Moonhare Engine".to_owned()
|
||||
}
|
||||
|
||||
fn default_game_window_width() -> u32 {
|
||||
1280
|
||||
}
|
||||
|
||||
fn default_game_window_height() -> u32 {
|
||||
720
|
||||
}
|
||||
|
||||
fn default_game_window_visibility() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_game_window_decorations() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
@ -1,22 +1,20 @@
|
|||
//! Base functionality for a Moonhare Game Engine Project
|
||||
|
||||
use moonhare_log::*;
|
||||
use moonhare_window::Window;
|
||||
|
||||
use crate::basic::game_window::GameWindow;
|
||||
pub mod basic;
|
||||
|
||||
/// Only one Game may exist per project
|
||||
#[derive(Debug)]
|
||||
pub struct Game {
|
||||
pub name: String,
|
||||
pub primary_window: Option<GameWindow>,
|
||||
}
|
||||
|
||||
impl Default for Game {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: default_game_name(),
|
||||
primary_window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,10 +33,7 @@ impl Game {
|
|||
|
||||
pub fn add_window(&mut self) {
|
||||
moonhare_log::info(format!("Adding window to {:?}", self));
|
||||
if self.primary_window.is_none() {
|
||||
moonhare_log::trace("Primary Window is none");
|
||||
self.primary_window = Some(GameWindow::create());
|
||||
}
|
||||
Window::create();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ use std::{fmt::Display, io, time::SystemTime};
|
|||
|
||||
/// Configures the Log Output Settings
|
||||
pub fn configere_logger() -> Result<(), fern::InitError>{
|
||||
let base_config = fern::Dispatch::new();
|
||||
let base_config = fern::Dispatch::new().level(log::LevelFilter::Info);
|
||||
|
||||
|
||||
// configure colors for the whole line
|
||||
let colors_line = fern::colors::ColoredLevelConfig::new()
|
||||
|
|
|
|||
|
|
@ -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