window.py

Window Management System - Display and Surface Control

LOCATION: lunaengine/core/window.py

DESCRIPTION:
Handles the creation, configuration, and management of the game window.
Provides functionality for display mode changes, window properties, and
surface management. Supports both windowed and fullscreen modes with
dynamic resizing capabilities.

KEY FEATURES:
- Window creation with customizable flags
- Fullscreen/windowed mode switching
- Dynamic window resizing support
- Display surface management
- Window property configuration
- Window event decorators

LIBRARIES USED:
- pygame: Display system, surface creation, and window flags
- typing: Type hints for coordinates and optional parameters
- functools: Decorator utilities

WINDOW FLAGS SUPPORTED:
- OPENGL: OpenGL context creation
- FULLSCREEN: Fullscreen display mode
- RESIZABLE: User-resizable window
- DOUBLEBUF: Double buffering for smooth rendering

class Window

Description

Manages the game window and display settings.

This class handles window creation, resizing, fullscreen mode,
and provides utility methods for window information.

Attributes:
   title (str): Window title
   width (int): Window width
   height (int): Window height
   fullscreen (bool): Whether window is in fullscreen mode
   resizable (bool): Whether window is resizable
   surface (pygame.Surface): The window surface
   _event_handlers (Dict): Registered event handlers

Methods
def __init__(self: Any, title: str = 'LunaEngine', width: int = 800, height: int = 600, fullscreen: bool = False, resizable: bool = True) -> Any
Initialize window settings.

Args:
   title (str): Window title (default: "LunaEngine")
   width (int): Window width (default: 800)
   height (int): Window height (default: 600)
   fullscreen (bool): Start in fullscreen mode (default: False)
   resizable (bool): Allow window resizing (default: True)
def create(self: Any) -> Any
Create the game window with specified settings.
def set_title(self: Any, title: str) -> Any
Set window title.

Args:
   title (str): New window title
def set_size(self: Any, width: int, height: int) -> Any
Resize the window.

Args:
   width (int): New window width
   height (int): New window height
def toggle_fullscreen(self: Any) -> Any
Toggle between fullscreen and windowed mode.
def get_size(self: Any) -> Tuple[int, int]
Get current window size.

Returns:
   Tuple[int, int]: (width, height) of the window
def get_center(self: Any) -> Tuple[int, int]
Get window center coordinates.

Returns:
   Tuple[int, int]: (x, y) coordinates of window center
def _register_event_handler(self: Any, event_type: WindowEventType, func: Callable) -> Any
Register an event handler.
def handle_pygame_event(self: Any, event: pygame.event.Event) -> Any
Handle pygame window events and call registered handlers.

Args:
   event (pygame.event.Event): Pygame event to handle
def _extract_event_data(self: Any, event: pygame.event.Event, event_type: WindowEventType) -> Dict[str, Any]
Extract relevant data from pygame event.
def on_resize(self: Any, func: Callable) -> Any
Decorator to register window resize event handler.

Args:
   func (Callable): The resize event handler function.
def on_close(self: Any, func: Callable) -> Any
Decorator to register window close event handler.

Args:
   func (Callable): The window close event handler function.
def on_focus(self: Any, func: Callable) -> Any
Decorator to register window focus gained event handler.

Args:
   func (Callable): The window focus event handler function.
def on_blur(self: Any, func: Callable) -> Any
Decorator to register window blur (focus lost) event handler.

Args:
   func (Callable): The window blur event handler function.
def on_move(self: Any, func: Callable) -> Any
Decorator to register window move event handler.

Args:
   func (Callable): The window move event handler function.
def on_minimize(self: Any, func: Callable) -> Any
Decorator to register window minimize event handler.

Args:
   func (Callable): The window minimize event handler function.
def on_maximize(self: Any, func: Callable) -> Any
Decorator to register window maximize event handler.

Args:
   func (Callable): The window maximize event handler function.
def on_restore(self: Any, func: Callable) -> Any
Decorator to register window restore event handler.

Args:
   func (Callable): The window restore event handler function.
def on_enter(self: Any, func: Callable) -> Any
Decorator to register mouse entering window event handler.

Args:
   func (Callable): The window enter event handler function.
def on_leave(self: Any, func: Callable) -> Any
Decorator to register mouse leaving window event handler.

Args:
   func (Callable): The window leave event handler function.
def get_window_state(self: Any) -> Dict[str, Any]
Get current window state.

Returns:
   Dict[str, Any]: Current window state
def is_focused(self: Any) -> bool
Check if window is focused.

Returns:
   bool: True if window is focused
def is_visible(self: Any) -> bool
Check if window is visible.

Returns:
   bool: True if window is visible
def is_minimized(self: Any) -> bool
Check if window is minimized.

Returns:
   bool: True if window is minimized
def is_maximized(self: Any) -> bool
Check if window is maximized.

Returns:
   bool: True if window is maximized
Back to Core Module