dl
dl_system.h
浏览该文件的文档.
1
12#pragma once
13
14#ifndef DL_DISABLE_RENDER
15#include <string_view>
16#include <vector>
17
18#include "dl_type.h"
19#include "base/dl_type_user.h"
20#include "script/dl_lua.h"
21
22namespace dl
23{
31
39
42{
43 std::string _strTitle;
45 FullScreenMode _fullScreenMode; //0.窗口 1.全屏 2.全屏窗口
47
49 _strTitle{ "C++ drawing library" },
50 _size{ 800,600 },
52 _bHideTitle{ false }
53 {}
54};
55
64
65class SystemImp;
67class System
68{
69public:
70 using Func = void (*)(void);
73
79 void Start(std::string_view json_window,
80 std::string_view json_path = "");
81
85 void Start(const ParamWindow& param = {});
89 void Exit();
93 void SetFuncInit(Func func) { _funcInit = func; }
97 void SetFuncRun(Func func) { _funcRun = func; }
98
105
117 void SetWindowPoint(const Point& xy);
118
126 void SetWindowTitle(std::string_view str);
131
135
139 void ScreenShot(std::string_view path_name);
140
141 enum class CursorMode
142 {
146 };
147
152
156 void SetClipboardString(std::string_view str);
160 std::string GetClipboardString();
161
166 {
167 _vecDropFile.clear();
168 }
169
172 const std::vector<std::string>& GetDropFile()
173 {
174 return _vecDropFile;
175 }
176
181 void ShowMessageBox(std::string_view title, std::string_view text);
182
184 void SetFullScreen(FullScreenMode mode, const Size& size = {});
185
187 void SetWindowSize(const Size& size);
188
189 // todo(可能不再支持)
191 {
192 _dir = dir;
193 }
194
197
199 SystemStep GetStep() { return _step; }
200
201
203 std::string GetHardwareId();
204
206 std::string GetUsername();
207
209 void Pause();
210
212 void _add_drop_file(std::string_view str)
213 {
214 _vecDropFile.push_back(std::string{ str });
215 }
216
217 SystemImp* GetImp() { return _imp; }
218
219 // 提前初始化,以便使用glfw的一些接口,例如显示器相关
222
223 // 触发窗口大小变更(用户请勿调用)
224 void _resize();
225 // 设置屏幕方向(用户请勿调用)
226 void _set_dir(WindowDirection dir) { _dir = dir; }
227 // 屏幕方向处理glfw输入坐标
230 //--------------------------lua----------------------------
231 void lua_SetFuncInit(luabridge::LuaRef func);
232 void lua_SetFuncRun(luabridge::LuaRef func);
233private:
234 SystemImp* _imp;
235 Func _funcInit;
236 Func _funcRun;
237 SystemStep _step;
238
239 CursorMode _cursorMode;
240 bool _bCursorModeChange;
241
242 void* _nativeWindow;
243
244 std::vector<std::string> _vecDropFile;
245 FullScreenMode _fullScreenMode;
246 Size _desktopSize;// 仅用于恢复全屏到窗口全屏使用
247 WindowDirection _dir;
248
249 struct
250 {
251 luabridge::LuaRef _funcInit{ g_lua->GetL() };
252 luabridge::LuaRef _funcRun{ g_lua->GetL() };
253 }_lua;
254
255 bool _start_init(const ParamWindow& param);
256 void _start_loop();
257
258 // 在linux上,framebuffer大小 = 窗口大小 * 缩放值
259 // 我们只关心绘制内容 framebuffer视作用户层的窗口大小
260 void _get_window_size(int& w, int& h);
261};
262extern System* g_system;
263}
264
265#endif
void SetWindowDirection(WindowDirection dir)
void _convert_system_to_glfw(Point &xy)
void SetFuncInit(Func func)
设置 初始化函数
void SetFullScreen(FullScreenMode mode, const Size &size={})
设置全屏
const std::vector< std::string > & GetDropFile()
返回拖入文件列表
void Start(const ParamWindow &param={})
创建窗口 并进入 游戏循环
void _init_glfw()
void SetWindowTitle(std::string_view str)
设置窗口标题
void SetFuncRun(Func func)
设置 帧函数
SystemStep GetStep()
返回引擎运行状态
void _delete_glfw()
void ScreenShot(std::string_view path_name)
截屏
std::string GetClipboardString()
返回剪贴板
Size GetWindowSize()
返回窗口大小
void _convert_glfw_to_system(Point &xy)
std::string GetHardwareId()
硬件码(md5 长度32)
void SetWindowPoint(const Point &xy)
设置窗口位置
void _add_drop_file(std::string_view str)
内部调用
bool IsWindowExist()
窗口是否存在
std::string GetUsername()
返回用户名
const RenderInfo2D & GetRenderInfo2D()
返回上一帧绘图信息
void _resize()
void SetWindowCenter()
设置窗口居中(以工作区大小)
SystemImp * GetImp()
void SetWindowSize(const Size &size)
设置窗口大小
void ClearDropFile()
清空拖入文件列表
void lua_SetFuncInit(luabridge::LuaRef func)
void Exit()
创建窗口 并进入 游戏循环
void SetClipboardString(std::string_view str)
设置剪贴板
void lua_SetFuncRun(luabridge::LuaRef func)
void SetCursorMode(CursorMode mode)
设置光标模式
void SetCursorPosition(Point xy)
设置鼠标位置,不用此来实现摄像机
const RenderInfo3D & GetRenderInfo3D()
WindowDirection GetWindowDirection()
返回屏幕方向
void Start(std::string_view json_window, std::string_view json_path="")
进入 游戏循环
void ShowMessageBox(std::string_view title, std::string_view text)
系统框提示
void _set_dir(WindowDirection dir)
void Pause()
暂停程序,等待用户输入后继续(Windows:按任意键;其他平台:回车)
Size GetWorkArea()
获取桌面大小,不包含任务栏
void(*)(void) Func
lua封装
通用类型
常用类型
SystemStep
运行步骤
WindowDirection
屏幕方向
System * g_system
LuaScript * g_lua
FullScreenMode
全屏模式
PointU Size
Point2 Point
创建窗口参数
std::string _strTitle
FullScreenMode _fullScreenMode