refactor(core): 移除字符串编码转换工具并清理头文件包含
移除不再使用的字符串编码转换工具文件 string.h,并清理相关头文件包含关系 调整部分头文件中的代码格式,优化枚举和结构体定义
This commit is contained in:
parent
b949d1a3da
commit
2767d64bf8
|
|
@ -1,10 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <extra2d/core/string.h>
|
|
||||||
#include <extra2d/core/types.h>
|
#include <extra2d/core/types.h>
|
||||||
#include <extra2d/graphics/render_backend.h>
|
#include <extra2d/graphics/render_backend.h>
|
||||||
#include <extra2d/platform/window.h>
|
#include <extra2d/platform/window.h>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace extra2d {
|
namespace extra2d {
|
||||||
|
|
||||||
|
|
@ -22,11 +20,7 @@ class Camera;
|
||||||
// Application 配置
|
// Application 配置
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
enum class PlatformType {
|
enum class PlatformType { Auto = 0, PC, Switch };
|
||||||
Auto = 0,
|
|
||||||
PC,
|
|
||||||
Switch
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AppConfig {
|
struct AppConfig {
|
||||||
std::string title = "Easy2D Application";
|
std::string title = "Easy2D Application";
|
||||||
|
|
@ -40,8 +34,8 @@ struct AppConfig {
|
||||||
int msaaSamples = 0;
|
int msaaSamples = 0;
|
||||||
PlatformType platform = PlatformType::Auto;
|
PlatformType platform = PlatformType::Auto;
|
||||||
// 窗口高级配置
|
// 窗口高级配置
|
||||||
bool enableCursors = true; // 是否启用光标
|
bool enableCursors = true; // 是否启用光标
|
||||||
bool enableDpiScale = false; // 是否启用DPI缩放
|
bool enableDpiScale = false; // 是否启用DPI缩放
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
@ -90,7 +84,8 @@ public:
|
||||||
// 便捷方法
|
// 便捷方法
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void enterScene(Ptr<class Scene> scene);
|
void enterScene(Ptr<class Scene> scene);
|
||||||
void enterScene(Ptr<class Scene> scene, Ptr<class TransitionScene> transitionScene);
|
void enterScene(Ptr<class Scene> scene,
|
||||||
|
Ptr<class TransitionScene> transitionScene);
|
||||||
|
|
||||||
float deltaTime() const { return deltaTime_; }
|
float deltaTime() const { return deltaTime_; }
|
||||||
float totalTime() const { return totalTime_; }
|
float totalTime() const { return totalTime_; }
|
||||||
|
|
|
||||||
|
|
@ -1,209 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace extra2d {
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// 字符串编码转换工具函数
|
|
||||||
// 统一使用 std::string (UTF-8) 作为项目标准字符串类型
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
// UTF-8 ↔ UTF-16 转换
|
|
||||||
std::u16string utf8ToUtf16(const std::string& utf8);
|
|
||||||
std::string utf16ToUtf8(const std::u16string& utf16);
|
|
||||||
|
|
||||||
// UTF-8 ↔ UTF-32 转换
|
|
||||||
std::u32string utf8ToUtf32(const std::string& utf8);
|
|
||||||
std::string utf32ToUtf8(const std::u32string& utf32);
|
|
||||||
|
|
||||||
// UTF-8 ↔ Wide String 转换
|
|
||||||
std::wstring utf8ToWide(const std::string& utf8);
|
|
||||||
std::string wideToUtf8(const std::wstring& wide);
|
|
||||||
|
|
||||||
// UTF-8 ↔ GBK/GB2312 转换(Windows 中文系统常用)
|
|
||||||
std::string utf8ToGbk(const std::string& utf8);
|
|
||||||
std::string gbkToUtf8(const std::string& gbk);
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// 内联实现
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
inline std::u16string utf8ToUtf16(const std::string& utf8) {
|
|
||||||
if (utf8.empty()) return std::u16string();
|
|
||||||
|
|
||||||
// UTF-8 → UTF-32 → UTF-16 (with surrogate pairs)
|
|
||||||
std::u32string u32 = utf8ToUtf32(utf8);
|
|
||||||
std::u16string result;
|
|
||||||
result.reserve(u32.size());
|
|
||||||
|
|
||||||
for (char32_t ch : u32) {
|
|
||||||
if (ch <= 0xFFFF) {
|
|
||||||
result.push_back(static_cast<char16_t>(ch));
|
|
||||||
} else if (ch <= 0x10FFFF) {
|
|
||||||
// Surrogate pair
|
|
||||||
ch -= 0x10000;
|
|
||||||
result.push_back(static_cast<char16_t>(0xD800 | (ch >> 10)));
|
|
||||||
result.push_back(static_cast<char16_t>(0xDC00 | (ch & 0x3FF)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string utf16ToUtf8(const std::u16string& utf16) {
|
|
||||||
if (utf16.empty()) return std::string();
|
|
||||||
|
|
||||||
// UTF-16 → UTF-32 → UTF-8
|
|
||||||
std::u32string u32;
|
|
||||||
u32.reserve(utf16.size());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < utf16.size(); ++i) {
|
|
||||||
char16_t cu = utf16[i];
|
|
||||||
char32_t ch;
|
|
||||||
if (cu >= 0xD800 && cu <= 0xDBFF && i + 1 < utf16.size()) {
|
|
||||||
// High surrogate
|
|
||||||
char16_t cl = utf16[i + 1];
|
|
||||||
if (cl >= 0xDC00 && cl <= 0xDFFF) {
|
|
||||||
ch = 0x10000 + ((static_cast<char32_t>(cu - 0xD800) << 10) |
|
|
||||||
(cl - 0xDC00));
|
|
||||||
++i;
|
|
||||||
} else {
|
|
||||||
ch = cu; // Invalid, pass through
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ch = cu;
|
|
||||||
}
|
|
||||||
u32.push_back(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return utf32ToUtf8(u32);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::u32string utf8ToUtf32(const std::string& utf8) {
|
|
||||||
std::u32string result;
|
|
||||||
result.reserve(utf8.size());
|
|
||||||
|
|
||||||
const char* ptr = utf8.c_str();
|
|
||||||
const char* end = ptr + utf8.size();
|
|
||||||
|
|
||||||
while (ptr < end) {
|
|
||||||
char32_t ch = 0;
|
|
||||||
unsigned char byte = static_cast<unsigned char>(*ptr);
|
|
||||||
|
|
||||||
if ((byte & 0x80) == 0) {
|
|
||||||
// 1-byte sequence
|
|
||||||
ch = byte;
|
|
||||||
ptr += 1;
|
|
||||||
} else if ((byte & 0xE0) == 0xC0) {
|
|
||||||
// 2-byte sequence
|
|
||||||
ch = (byte & 0x1F) << 6;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[1]) & 0x3F);
|
|
||||||
ptr += 2;
|
|
||||||
} else if ((byte & 0xF0) == 0xE0) {
|
|
||||||
// 3-byte sequence
|
|
||||||
ch = (byte & 0x0F) << 12;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[1]) & 0x3F) << 6;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[2]) & 0x3F);
|
|
||||||
ptr += 3;
|
|
||||||
} else if ((byte & 0xF8) == 0xF0) {
|
|
||||||
// 4-byte sequence
|
|
||||||
ch = (byte & 0x07) << 18;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[1]) & 0x3F) << 12;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[2]) & 0x3F) << 6;
|
|
||||||
ch |= (static_cast<unsigned char>(ptr[3]) & 0x3F);
|
|
||||||
ptr += 4;
|
|
||||||
} else {
|
|
||||||
// Invalid UTF-8, skip
|
|
||||||
ptr += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push_back(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string utf32ToUtf8(const std::u32string& utf32) {
|
|
||||||
std::string result;
|
|
||||||
|
|
||||||
for (char32_t ch : utf32) {
|
|
||||||
if (ch <= 0x7F) {
|
|
||||||
// 1-byte
|
|
||||||
result.push_back(static_cast<char>(ch));
|
|
||||||
} else if (ch <= 0x7FF) {
|
|
||||||
// 2-byte
|
|
||||||
result.push_back(static_cast<char>(0xC0 | ((ch >> 6) & 0x1F)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
|
|
||||||
} else if (ch <= 0xFFFF) {
|
|
||||||
// 3-byte
|
|
||||||
result.push_back(static_cast<char>(0xE0 | ((ch >> 12) & 0x0F)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | ((ch >> 6) & 0x3F)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
|
|
||||||
} else if (ch <= 0x10FFFF) {
|
|
||||||
// 4-byte
|
|
||||||
result.push_back(static_cast<char>(0xF0 | ((ch >> 18) & 0x07)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | ((ch >> 12) & 0x3F)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | ((ch >> 6) & 0x3F)));
|
|
||||||
result.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::wstring utf8ToWide(const std::string& utf8) {
|
|
||||||
if (utf8.empty()) return std::wstring();
|
|
||||||
|
|
||||||
if constexpr (sizeof(wchar_t) == 4) {
|
|
||||||
// wchar_t is 32-bit (Linux/Switch): same as UTF-32
|
|
||||||
std::u32string u32 = utf8ToUtf32(utf8);
|
|
||||||
return std::wstring(u32.begin(), u32.end());
|
|
||||||
} else {
|
|
||||||
// wchar_t is 16-bit (Windows): same as UTF-16
|
|
||||||
std::u16string u16 = utf8ToUtf16(utf8);
|
|
||||||
return std::wstring(u16.begin(), u16.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string wideToUtf8(const std::wstring& wide) {
|
|
||||||
if (wide.empty()) return std::string();
|
|
||||||
|
|
||||||
if constexpr (sizeof(wchar_t) == 4) {
|
|
||||||
std::u32string u32(wide.begin(), wide.end());
|
|
||||||
return utf32ToUtf8(u32);
|
|
||||||
} else {
|
|
||||||
std::u16string u16(wide.begin(), wide.end());
|
|
||||||
return utf16ToUtf8(u16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GBK/GB2312 转换(Windows 平台实现)
|
|
||||||
// 注意:Windows 实现在 .cpp 文件中,避免头文件包含 windows.h 导致冲突
|
|
||||||
#ifdef _WIN32
|
|
||||||
// 前向声明,实现在 .cpp 文件中
|
|
||||||
std::string utf8ToGbkImpl(const std::string& utf8);
|
|
||||||
std::string gbkToUtf8Impl(const std::string& gbk);
|
|
||||||
|
|
||||||
inline std::string utf8ToGbk(const std::string& utf8) {
|
|
||||||
return utf8ToGbkImpl(utf8);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string gbkToUtf8(const std::string& gbk) {
|
|
||||||
return gbkToUtf8Impl(gbk);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// 非 Windows 平台,GBK 转换使用 iconv 或返回原字符串
|
|
||||||
inline std::string utf8ToGbk(const std::string& utf8) {
|
|
||||||
// TODO: 使用 iconv 实现
|
|
||||||
return utf8;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string gbkToUtf8(const std::string& gbk) {
|
|
||||||
// TODO: 使用 iconv 实现
|
|
||||||
return gbk;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace extra2d
|
|
||||||
|
|
@ -4,21 +4,20 @@
|
||||||
// 包含所有公共 API
|
// 包含所有公共 API
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
#include <extra2d/core/types.h>
|
|
||||||
#include <extra2d/core/string.h>
|
|
||||||
#include <extra2d/core/color.h>
|
#include <extra2d/core/color.h>
|
||||||
#include <extra2d/core/math_types.h>
|
#include <extra2d/core/math_types.h>
|
||||||
|
#include <extra2d/core/types.h>
|
||||||
|
|
||||||
// Platform
|
// Platform
|
||||||
#include <extra2d/platform/window.h>
|
|
||||||
#include <extra2d/platform/input.h>
|
#include <extra2d/platform/input.h>
|
||||||
|
#include <extra2d/platform/window.h>
|
||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
#include <extra2d/graphics/render_backend.h>
|
|
||||||
#include <extra2d/graphics/texture.h>
|
|
||||||
#include <extra2d/graphics/font.h>
|
|
||||||
#include <extra2d/graphics/camera.h>
|
#include <extra2d/graphics/camera.h>
|
||||||
|
#include <extra2d/graphics/font.h>
|
||||||
|
#include <extra2d/graphics/render_backend.h>
|
||||||
#include <extra2d/graphics/shader_system.h>
|
#include <extra2d/graphics/shader_system.h>
|
||||||
|
#include <extra2d/graphics/texture.h>
|
||||||
|
|
||||||
#include <extra2d/graphics/render_target.h>
|
#include <extra2d/graphics/render_target.h>
|
||||||
#include <extra2d/graphics/vram_manager.h>
|
#include <extra2d/graphics/vram_manager.h>
|
||||||
|
|
@ -26,20 +25,20 @@
|
||||||
// Scene
|
// Scene
|
||||||
#include <extra2d/scene/node.h>
|
#include <extra2d/scene/node.h>
|
||||||
#include <extra2d/scene/scene.h>
|
#include <extra2d/scene/scene.h>
|
||||||
#include <extra2d/scene/sprite.h>
|
|
||||||
#include <extra2d/scene/shape_node.h>
|
|
||||||
#include <extra2d/scene/scene_manager.h>
|
#include <extra2d/scene/scene_manager.h>
|
||||||
#include <extra2d/scene/transition_scene.h>
|
#include <extra2d/scene/shape_node.h>
|
||||||
#include <extra2d/scene/transition_fade_scene.h>
|
#include <extra2d/scene/sprite.h>
|
||||||
#include <extra2d/scene/transition_slide_scene.h>
|
|
||||||
#include <extra2d/scene/transition_scale_scene.h>
|
|
||||||
#include <extra2d/scene/transition_flip_scene.h>
|
|
||||||
#include <extra2d/scene/transition_box_scene.h>
|
#include <extra2d/scene/transition_box_scene.h>
|
||||||
|
#include <extra2d/scene/transition_fade_scene.h>
|
||||||
|
#include <extra2d/scene/transition_flip_scene.h>
|
||||||
|
#include <extra2d/scene/transition_scale_scene.h>
|
||||||
|
#include <extra2d/scene/transition_scene.h>
|
||||||
|
#include <extra2d/scene/transition_slide_scene.h>
|
||||||
|
|
||||||
// Event
|
// Event
|
||||||
#include <extra2d/event/event.h>
|
#include <extra2d/event/event.h>
|
||||||
#include <extra2d/event/event_queue.h>
|
|
||||||
#include <extra2d/event/event_dispatcher.h>
|
#include <extra2d/event/event_dispatcher.h>
|
||||||
|
#include <extra2d/event/event_queue.h>
|
||||||
#include <extra2d/event/input_codes.h>
|
#include <extra2d/event/input_codes.h>
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
|
|
@ -50,10 +49,10 @@
|
||||||
#include <extra2d/resource/resource_manager.h>
|
#include <extra2d/resource/resource_manager.h>
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
#include <extra2d/utils/logger.h>
|
|
||||||
#include <extra2d/utils/timer.h>
|
|
||||||
#include <extra2d/utils/data.h>
|
#include <extra2d/utils/data.h>
|
||||||
|
#include <extra2d/utils/logger.h>
|
||||||
#include <extra2d/utils/random.h>
|
#include <extra2d/utils/random.h>
|
||||||
|
#include <extra2d/utils/timer.h>
|
||||||
|
|
||||||
// Application
|
// Application
|
||||||
#include <extra2d/app/application.h>
|
#include <extra2d/app/application.h>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <extra2d/core/types.h>
|
|
||||||
#include <extra2d/core/string.h>
|
|
||||||
#include <extra2d/core/math_types.h>
|
#include <extra2d/core/math_types.h>
|
||||||
|
#include <extra2d/core/types.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
@ -17,32 +15,33 @@ class Input;
|
||||||
// 窗口配置
|
// 窗口配置
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
struct WindowConfig {
|
struct WindowConfig {
|
||||||
std::string title = "Extra2D Application";
|
std::string title = "Extra2D Application";
|
||||||
int width = 1280;
|
int width = 1280;
|
||||||
int height = 720;
|
int height = 720;
|
||||||
bool fullscreen = true;
|
bool fullscreen = true;
|
||||||
bool resizable = false;
|
bool resizable = false;
|
||||||
bool vsync = true;
|
bool vsync = true;
|
||||||
int msaaSamples = 0;
|
int msaaSamples = 0;
|
||||||
bool centerWindow = true;
|
bool centerWindow = true;
|
||||||
bool enableCursors = true;
|
bool enableCursors = true;
|
||||||
bool enableDpiScale = true;
|
bool enableDpiScale = true;
|
||||||
bool fullscreenDesktop = true; // true: SDL_WINDOW_FULLSCREEN_DESKTOP, false: SDL_WINDOW_FULLSCREEN
|
bool fullscreenDesktop =
|
||||||
|
true; // true: SDL_WINDOW_FULLSCREEN_DESKTOP, false: SDL_WINDOW_FULLSCREEN
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// 鼠标光标形状枚举
|
// 鼠标光标形状枚举
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
enum class CursorShape {
|
enum class CursorShape {
|
||||||
Arrow,
|
Arrow,
|
||||||
IBeam,
|
IBeam,
|
||||||
Crosshair,
|
Crosshair,
|
||||||
Hand,
|
Hand,
|
||||||
HResize,
|
HResize,
|
||||||
VResize,
|
VResize,
|
||||||
ResizeAll,
|
ResizeAll,
|
||||||
ResizeNWSE,
|
ResizeNWSE,
|
||||||
ResizeNESW
|
ResizeNESW
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
@ -51,103 +50,107 @@ enum class CursorShape {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window();
|
Window();
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
// 创建窗口
|
// 创建窗口
|
||||||
bool create(const WindowConfig& config);
|
bool create(const WindowConfig &config);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
// 窗口操作
|
// 窗口操作
|
||||||
void pollEvents();
|
void pollEvents();
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
bool shouldClose() const;
|
bool shouldClose() const;
|
||||||
void setShouldClose(bool close);
|
void setShouldClose(bool close);
|
||||||
|
|
||||||
// 窗口属性
|
// 窗口属性
|
||||||
void setTitle(const std::string& title);
|
void setTitle(const std::string &title);
|
||||||
void setSize(int width, int height);
|
void setSize(int width, int height);
|
||||||
void setPosition(int x, int y);
|
void setPosition(int x, int y);
|
||||||
void setFullscreen(bool fullscreen);
|
void setFullscreen(bool fullscreen);
|
||||||
void setVSync(bool enabled);
|
void setVSync(bool enabled);
|
||||||
void setResizable(bool resizable);
|
void setResizable(bool resizable);
|
||||||
|
|
||||||
// 获取窗口属性
|
// 获取窗口属性
|
||||||
int getWidth() const { return width_; }
|
int getWidth() const { return width_; }
|
||||||
int getHeight() const { return height_; }
|
int getHeight() const { return height_; }
|
||||||
Size getSize() const { return Size(static_cast<float>(width_), static_cast<float>(height_)); }
|
Size getSize() const {
|
||||||
Vec2 getPosition() const;
|
return Size(static_cast<float>(width_), static_cast<float>(height_));
|
||||||
bool isFullscreen() const { return fullscreen_; }
|
}
|
||||||
bool isVSync() const { return vsync_; }
|
Vec2 getPosition() const;
|
||||||
|
bool isFullscreen() const { return fullscreen_; }
|
||||||
|
bool isVSync() const { return vsync_; }
|
||||||
|
|
||||||
// DPI 缩放 (PC 端自动检测,Switch 固定 1.0)
|
// DPI 缩放 (PC 端自动检测,Switch 固定 1.0)
|
||||||
float getContentScaleX() const;
|
float getContentScaleX() const;
|
||||||
float getContentScaleY() const;
|
float getContentScaleY() const;
|
||||||
Vec2 getContentScale() const;
|
Vec2 getContentScale() const;
|
||||||
|
|
||||||
// 窗口状态
|
// 窗口状态
|
||||||
bool isFocused() const { return focused_; }
|
bool isFocused() const { return focused_; }
|
||||||
bool isMinimized() const;
|
bool isMinimized() const;
|
||||||
bool isMaximized() const;
|
bool isMaximized() const;
|
||||||
|
|
||||||
// 获取 SDL2 窗口和 GL 上下文
|
// 获取 SDL2 窗口和 GL 上下文
|
||||||
SDL_Window* getSDLWindow() const { return sdlWindow_; }
|
SDL_Window *getSDLWindow() const { return sdlWindow_; }
|
||||||
SDL_GLContext getGLContext() const { return glContext_; }
|
SDL_GLContext getGLContext() const { return glContext_; }
|
||||||
|
|
||||||
// 设置/获取用户数据
|
// 设置/获取用户数据
|
||||||
void setUserData(void* data) { userData_ = data; }
|
void setUserData(void *data) { userData_ = data; }
|
||||||
void* getUserData() const { return userData_; }
|
void *getUserData() const { return userData_; }
|
||||||
|
|
||||||
// 事件队列
|
// 事件队列
|
||||||
void setEventQueue(EventQueue* queue) { eventQueue_ = queue; }
|
void setEventQueue(EventQueue *queue) { eventQueue_ = queue; }
|
||||||
EventQueue* getEventQueue() const { return eventQueue_; }
|
EventQueue *getEventQueue() const { return eventQueue_; }
|
||||||
|
|
||||||
// 获取输入管理器
|
// 获取输入管理器
|
||||||
Input* getInput() const { return input_.get(); }
|
Input *getInput() const { return input_.get(); }
|
||||||
|
|
||||||
// 光标操作 (PC 端有效,Switch 上为空操作)
|
// 光标操作 (PC 端有效,Switch 上为空操作)
|
||||||
void setCursor(CursorShape shape);
|
void setCursor(CursorShape shape);
|
||||||
void resetCursor();
|
void resetCursor();
|
||||||
void setMouseVisible(bool visible);
|
void setMouseVisible(bool visible);
|
||||||
|
|
||||||
// 窗口回调
|
// 窗口回调
|
||||||
using ResizeCallback = std::function<void(int width, int height)>;
|
using ResizeCallback = std::function<void(int width, int height)>;
|
||||||
using FocusCallback = std::function<void(bool focused)>;
|
using FocusCallback = std::function<void(bool focused)>;
|
||||||
using CloseCallback = std::function<void()>;
|
using CloseCallback = std::function<void()>;
|
||||||
|
|
||||||
void setResizeCallback(ResizeCallback callback) { resizeCallback_ = callback; }
|
void setResizeCallback(ResizeCallback callback) {
|
||||||
void setFocusCallback(FocusCallback callback) { focusCallback_ = callback; }
|
resizeCallback_ = callback;
|
||||||
void setCloseCallback(CloseCallback callback) { closeCallback_ = callback; }
|
}
|
||||||
|
void setFocusCallback(FocusCallback callback) { focusCallback_ = callback; }
|
||||||
|
void setCloseCallback(CloseCallback callback) { closeCallback_ = callback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// SDL2 状态
|
// SDL2 状态
|
||||||
SDL_Window* sdlWindow_;
|
SDL_Window *sdlWindow_;
|
||||||
SDL_GLContext glContext_;
|
SDL_GLContext glContext_;
|
||||||
SDL_Cursor* sdlCursors_[9]; // 光标缓存
|
SDL_Cursor *sdlCursors_[9]; // 光标缓存
|
||||||
SDL_Cursor* currentCursor_;
|
SDL_Cursor *currentCursor_;
|
||||||
|
|
||||||
int width_;
|
int width_;
|
||||||
int height_;
|
int height_;
|
||||||
bool vsync_;
|
bool vsync_;
|
||||||
bool shouldClose_;
|
bool shouldClose_;
|
||||||
bool fullscreen_;
|
bool fullscreen_;
|
||||||
bool focused_;
|
bool focused_;
|
||||||
float contentScaleX_;
|
float contentScaleX_;
|
||||||
float contentScaleY_;
|
float contentScaleY_;
|
||||||
bool enableDpiScale_;
|
bool enableDpiScale_;
|
||||||
void* userData_;
|
void *userData_;
|
||||||
EventQueue* eventQueue_;
|
EventQueue *eventQueue_;
|
||||||
UniquePtr<Input> input_;
|
UniquePtr<Input> input_;
|
||||||
|
|
||||||
ResizeCallback resizeCallback_;
|
ResizeCallback resizeCallback_;
|
||||||
FocusCallback focusCallback_;
|
FocusCallback focusCallback_;
|
||||||
CloseCallback closeCallback_;
|
CloseCallback closeCallback_;
|
||||||
|
|
||||||
bool initSDL(const WindowConfig& config);
|
bool initSDL(const WindowConfig &config);
|
||||||
void deinitSDL();
|
void deinitSDL();
|
||||||
void initCursors();
|
void initCursors();
|
||||||
void deinitCursors();
|
void deinitCursors();
|
||||||
void updateContentScale();
|
void updateContentScale();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace extra2d
|
} // namespace extra2d
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue