feat(graphics): implement window manager and display resize handler
This commit is contained in:
parent
94584bed1e
commit
bac8afeb83
3 changed files with 77 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
pub mod surface;
|
pub mod surface;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
pub mod window;
|
||||||
|
|
|
||||||
53
crates/molotov-core/src/graphics/window.rs
Normal file
53
crates/molotov-core/src/graphics/window.rs
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
crates/molotov-core/tests/window_manager_test.rs
Normal file
23
crates/molotov-core/tests/window_manager_test.rs
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
Reference in a new issue