This commit is contained in:
LunarAkai 2025-08-03 01:07:52 +02:00
commit bbd2a6089c
10 changed files with 62 additions and 16 deletions

1
Cargo.lock generated
View file

@ -503,6 +503,7 @@ name = "moonhare_window"
version = "0.1.0"
dependencies = [
"gtk4",
"moonhare_event",
"moonhare_log",
]

View file

@ -4,4 +4,4 @@ edition = "2024"
version.workspace = true
authors.workspace = true
[dependencies]
[dependencies]

View file

@ -9,4 +9,8 @@ pub enum EventType {
pub trait Event {
fn get_event_name() -> &'static str;
fn get_event_type() -> EventType;
}
/// Emits the Event
fn emit();
}

View file

@ -1,5 +1,6 @@
use crate::{event::Event,};
use crate::{event::{Event, EventType}, events::key_events::KeyEvent};
#[derive(Debug)]
struct KeyPressedEvent{}
const KEY_PRESSED_EVENT_NAME: &str = "KeyPressedEvent";
@ -9,8 +10,12 @@ impl Event for KeyPressedEvent {
KEY_PRESSED_EVENT_NAME
}
fn get_event_type() -> crate::event::EventType {
crate::event::EventType::KeyPressed
fn get_event_type() -> EventType {
EventType::KeyPressed
}
fn emit(&self) -> &impl Event{
self
}
}

View file

@ -1,3 +1,5 @@
pub mod window_close_event;
use crate::event::Event;
pub trait WindowEvent: Event {

View file

@ -0,0 +1,23 @@
use crate::{event::Event, events::window_events::WindowEvent};
#[derive(Debug)]
pub struct WindowCloseEvent {
}
impl Event for WindowCloseEvent {
fn get_event_name() -> &'static str {
todo!()
}
fn get_event_type() -> crate::event::EventType {
todo!()
}
fn emit(){
}
}
impl WindowEvent for WindowCloseEvent {
}

View file

@ -8,6 +8,7 @@ pub mod basic;
/// Only one Game may exist per project
#[derive(Debug)]
pub struct Game {
pub is_running: bool,
pub name: String,
pub context: WindowRenderContext,
}
@ -15,6 +16,7 @@ pub struct Game {
impl Default for Game {
fn default() -> Self {
Self {
is_running: true,
name: default_game_name(),
context: WindowRenderContext::OPENGLGTK
}
@ -28,7 +30,7 @@ impl Game {
pub fn run(&self) {
info("Running Game...");
loop {
while self.is_running {
}
}

View file

@ -6,4 +6,5 @@ authors.workspace = true
[dependencies]
moonhare_log = { path = "../moonhare_log" }
moonhare_event = { path = "../moonhare_event" }
gtk4 = "*"

View file

@ -1,12 +1,5 @@
//! Provides functionality to create either a vulkan or opengl window
use std::marker;
#[cfg(target_os = "linux")]
use crate::platforms::gtk_window::GTKWindow;
pub mod window_config;
pub mod platforms;
#[derive(Debug, Clone, Copy)]
@ -30,7 +23,8 @@ pub struct Window {
impl Window {
/// creates a gtk4 window
/// creates a gtk4 window while spaning a new thread that the window runs on.
/// here: gtk sends engine events when _things happen_ with the window that other engine parts can interact with
#[cfg(target_os = "linux")]
pub fn create(context: WindowRenderContext) {
match context {
@ -51,7 +45,6 @@ impl Window {
});
},
}
}
#[cfg(not(target_os = "linux"))]

View file

@ -1,4 +1,5 @@
use gtk4::{gio::prelude::ApplicationExt, glib, prelude::{GtkWindowExt, WidgetExt}, Application, ApplicationWindow};
use gtk4::{gio::{prelude::{ActionMapExtManual, ApplicationExt}, ActionEntry}, glib, prelude::{GtkWindowExt, WidgetExt}, Application, ApplicationWindow};
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
use crate::{window_config, MoonhareWindow};
@ -21,8 +22,20 @@ impl GTKWindow {
window.set_default_size(window_config.width as i32, window_config.height as i32);
window.set_visible(window_config.visble);
// Add action "close" to `window` taking no parameter
let action_close = ActionEntry::builder("close")
.activate(|window: &ApplicationWindow, _, _| {
GTKWindow::shutdown();
window.close();
})
.build();
window.add_action_entries([action_close]);
window.show();
}
}
impl MoonhareWindow for GTKWindow {
@ -43,6 +56,8 @@ impl MoonhareWindow for GTKWindow {
}
fn shutdown() {
// todo: emit WindowCloseEvent
}
}