ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Window.h
浏览该文件的文档.
1#pragma once
2#include <memory>
3#include <SDL3/SDL.h>
4#include "Core.h"
5
6struct SDL_Window;
7
8namespace Shit {
15 public:
16 Window() = default;
17 ~Window() = default;
18
19 // --- 静态API ---
20 static Window& GetInstance();
21 static bool Init() { return GetInstance().init(); }
22 static SDL_Window* GetWindow() { return GetInstance().m_window.get(); }
23 static void HandleEvent(const SDL_Event& event) { GetInstance().handleEvent(event); }
24 static bool IsOpen() { return GetInstance().isOpen(); }
25 static void Close() { GetInstance().close(); }
26 static void Destroy();
27
28 Window(const Window&) = delete;
29 Window& operator=(const Window&) = delete;
30 Window(Window&&) = delete;
31 Window& operator=(Window&&) = delete;
32
33 private:
34 bool init();
35 void handleEvent(const SDL_Event& event);
36 bool isOpen() { return m_isOpen; }
37 void close();
38
39 struct SDLWindowDeleter {
40 void operator()(SDL_Window* window) const {
41 if (window) SDL_DestroyWindow(window);
42 }
43 };
44
45 std::unique_ptr<SDL_Window, SDLWindowDeleter> m_window;
46 bool m_isOpen = false;
47 };
48}
#define SHIT_API
定义 Core.h:12
static SDL_Window * GetWindow()
获取原生 SDL_Window 指针
定义 Window.h:22
~Window()=default
static void Destroy()
销毁窗口及资源
Window(const Window &)=delete
Window()=default
static bool IsOpen()
窗口是否仍然打开
定义 Window.h:24
Window(Window &&)=delete
static Window & GetInstance()
获取单例
Window & operator=(Window &&)=delete
Window & operator=(const Window &)=delete
static bool Init()
初始化窗口
定义 Window.h:21
static void HandleEvent(const SDL_Event &event)
分发窗口事件给子系统
定义 Window.h:23
static void Close()
关闭窗口
定义 Window.h:25
定义 AudioPlayer.h:9