From bac8afeb8368301e43ee078c491f71ca47253e02 Mon Sep 17 00:00:00 2001 From: oiupoyt Date: Wed, 30 Sep 2026 08:14:57 +0530 Subject: [PATCH] feat(graphics): implement window manager and display resize handler --- crates/molotov-core/src/graphics/mod.rs | 1 + crates/molotov-core/src/graphics/window.rs | 53 +++++++++++++++++++ .../molotov-core/tests/window_manager_test.rs | 23 ++++++++ 3 files changed, 77 insertions(+) create mode 100644 crates/molotov-core/src/graphics/window.rs create mode 100644 crates/molotov-core/tests/window_manager_test.rs diff --git a/crates/molotov-core/src/graphics/mod.rs b/crates/molotov-core/src/graphics/mod.rs index 23f33a0..5c0761e 100644 --- a/crates/molotov-core/src/graphics/mod.rs +++ b/crates/molotov-core/src/graphics/mod.rs @@ -1,3 +1,4 @@ // SPDX-License-Identifier: GPL-3.0-or-later pub mod surface; pub mod types; +pub mod window; diff --git a/crates/molotov-core/src/graphics/window.rs b/crates/molotov-core/src/graphics/window.rs new file mode 100644 index 0000000..6051ff5 --- /dev/null +++ b/crates/molotov-core/src/graphics/window.rs @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use super::surface::GraphicsSurface; +use super::types::WindowFormat; + +#[derive(Debug, Clone)] +pub struct WindowConfig { + pub title: String, + pub width: i32, + pub height: i32, + pub fullscreen: bool, + pub vulkan: bool, +} + +impl Default for WindowConfig { + fn default() -> Self { + Self { + title: "Molotov - Roblox".to_string(), + width: 1280, + height: 720, + fullscreen: false, + vulkan: true, + } + } +} + +pub struct WindowManager { + config: WindowConfig, + pub surface: GraphicsSurface, +} + +impl WindowManager { + pub fn new(config: WindowConfig) -> Self { + let surface = GraphicsSurface::new(config.width, config.height, WindowFormat::Rgba8888); + Self { config, surface } + } + + pub fn width(&self) -> i32 { + self.surface.width() + } + + pub fn height(&self) -> i32 { + self.surface.height() + } + + pub fn handle_resize(&mut self, width: i32, height: i32) { + if width > 0 && height > 0 { + self.config.width = width; + self.config.height = height; + self.surface.set_geometry(width, height, self.surface.format()); + tracing::info!("WindowManager: surface resized to {}x{}", width, height); + } + } +} diff --git a/crates/molotov-core/tests/window_manager_test.rs b/crates/molotov-core/tests/window_manager_test.rs new file mode 100644 index 0000000..cb5ad72 --- /dev/null +++ b/crates/molotov-core/tests/window_manager_test.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use molotov_core::graphics::window::{WindowConfig, WindowManager}; + +#[test] +fn test_window_manager_configuration_and_resize() { + let config = WindowConfig { + title: "Roblox".to_string(), + width: 1280, + height: 720, + fullscreen: false, + vulkan: true, + }; + + let mut manager = WindowManager::new(config); + assert_eq!(manager.width(), 1280); + assert_eq!(manager.height(), 720); + + // Simulate display resize + manager.handle_resize(1920, 1080); + assert_eq!(manager.width(), 1920); + assert_eq!(manager.height(), 1080); + assert_eq!(manager.surface.width(), 1920); +}