gtk window
This commit is contained in:
parent
30ff2325f2
commit
0c3a160dd5
12 changed files with 435 additions and 1712 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
/target
|
/target
|
||||||
*.log
|
*.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
|
### Crates
|
||||||
- [MoonhareEngine](moonhare_engine/)
|
- [MoonhareEngine](moonhare_engine/)
|
||||||
- [MoonhareEvent](crates/moonhare_event/)
|
- [MoonhareEvent](crates/moonhare_event/)
|
||||||
|
- [MoonhareGame](crates/moonhare_game/)
|
||||||
|
- core Engine functionality
|
||||||
- [MoonhareGraphics](crates/moonhare_graphics/)
|
- [MoonhareGraphics](crates/moonhare_graphics/)
|
||||||
- [MoonhareLog](crates/moonhare_log/)
|
- [MoonhareLog](crates/moonhare_log/)
|
||||||
|
- Wrapper around the Log and fern crates
|
||||||
- [MoonhareWindow](crates/moonhare_window/)
|
- [MoonhareWindow](crates/moonhare_window/)
|
||||||
|
- deals with OpenGL/Vulkan Window creation
|
||||||
|
|
||||||
|
|
||||||
### Game Loop:
|
### 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};
|
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
|
//! Base functionality for a Moonhare Game Engine Project
|
||||||
|
|
||||||
use moonhare_log::*;
|
use moonhare_log::*;
|
||||||
|
use moonhare_window::Window;
|
||||||
|
|
||||||
use crate::basic::game_window::GameWindow;
|
|
||||||
pub mod basic;
|
pub mod basic;
|
||||||
|
|
||||||
/// Only one Game may exist per project
|
/// Only one Game may exist per project
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub primary_window: Option<GameWindow>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Game {
|
impl Default for Game {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: default_game_name(),
|
name: default_game_name(),
|
||||||
primary_window: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +33,7 @@ impl Game {
|
||||||
|
|
||||||
pub fn add_window(&mut self) {
|
pub fn add_window(&mut self) {
|
||||||
moonhare_log::info(format!("Adding window to {:?}", self));
|
moonhare_log::info(format!("Adding window to {:?}", self));
|
||||||
if self.primary_window.is_none() {
|
Window::create();
|
||||||
moonhare_log::trace("Primary Window is none");
|
|
||||||
self.primary_window = Some(GameWindow::create());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ use std::{fmt::Display, io, time::SystemTime};
|
||||||
|
|
||||||
/// Configures the Log Output Settings
|
/// Configures the Log Output Settings
|
||||||
pub fn configere_logger() -> Result<(), fern::InitError>{
|
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
|
// configure colors for the whole line
|
||||||
let colors_line = fern::colors::ColoredLevelConfig::new()
|
let colors_line = fern::colors::ColoredLevelConfig::new()
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,5 @@ version.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ash = "0.38"
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
glium = "0.36"
|
gtk4 = "*"
|
||||||
moonhare_log = { path = "../moonhare_log" }
|
|
||||||
|
|
@ -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
|
//! 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 window_config;
|
||||||
pub mod opengl_window;
|
|
||||||
|
pub mod platforms;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum WindowRenderContext {
|
pub enum WindowRenderContext {
|
||||||
VULKAN, // TODO
|
VULKAN, // TODO
|
||||||
OPENGL,
|
OPENGL,
|
||||||
|
OPENGLGTK,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
pub trait WindowResult {
|
||||||
pub struct MoonhareWindow {
|
|
||||||
render_context: WindowRenderContext
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MoonhareWindow {
|
pub trait MoonhareWindow {
|
||||||
pub fn define_context(context: WindowRenderContext) -> Self {
|
type WindowResult;
|
||||||
Self {
|
fn init() -> Self::WindowResult;
|
||||||
render_context: context
|
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) {
|
#[cfg(not(target_os = "linux"))]
|
||||||
match self.render_context {
|
pub fn create() {
|
||||||
WindowRenderContext::VULKAN => {
|
todo!("moonhare engine only supports linux for now")
|
||||||
todo!("Vulkan not implemented yet")
|
|
||||||
},
|
|
||||||
WindowRenderContext::OPENGL => {
|
|
||||||
create_open_gl_window();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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