dl
dl_component_use.h
浏览该文件的文档.
1
12#pragma once
13
14#include "base/dl_type_def.h"
15#include "misc/dl_component.h"
16#include "io/dl_input.h"
17
18namespace dl
19{
20namespace Cpt
21{
23 using IsPickup = Function<std::function<bool()>, str_uid("IsPickup")>;
24 using IsSelect = Function<std::function<bool()>, str_uid("IsSelect")>;
25 using IsClick = Function<std::function<bool()>, str_uid("IsClick")>;
26 using IsDown = Function<std::function<bool()>, str_uid("IsDown")>;
27 using GetCoor = Function<std::function<dl::Coor* ()>, str_uid("GetCoor")>;
28 using GetOrder = Function<std::function<float()>, str_uid("GetOrder")>;
29 using Update = Function<std::function<void()>, str_uid("Update")>;
30 using Render = Function<std::function<void()>, str_uid("Render")>;
31 using SetOrder = Function<std::function<void(float)>, str_uid("SetOrder")>;
32 using SetSelect = Function<std::function<void(bool)>, str_uid("SetSelect")>;
33 using DeleteThis = Function<std::function<void()>, str_uid("DeleteThis")>;
34 using Clone = Function<std::function<Components* ()>, str_uid("Clone")>;
35 using RenderDebug = Function<std::function<void()>, str_uid("RenderD")>;
36 using SetSize = Function<std::function<void(const Position& size)>, str_uid("SetSize")>;
37 using GetSize = Function<std::function<Position(void)>, str_uid("GetSize")>;
38 using CustomTag = Variable<int, str_uid("CustomTag")>;
39 using CustomName = Variable<std::string, str_uid("CustomName")>;
40
42 class Lang
43 {
44 public:
45 std::array<std::string, 2> _str;
46 std::function<void(std::string_view, std::string_view)> _func;
47 };
48
51 {
52 public:
54 _size{},
55 _anchor{},
56 _pos{},
57 _hv{ Align::LT },
58 _orderOffset{ 0 },
59 _bRunAble{ true },
60 _bUpdateAble{ true },
61 _bRenderAble{ true },
62 _bParentW{ false },
63 _bParentH{ false }
64 {}
65
67 {
69 }
70
73 {
74 return _size;
75 }
76
78 {
79 return _anchor;
80 }
81
83 {
84 return _orderOffset;
85 }
86
88 {
89 return createRectF(GetOffset(), GetSize());
90 }
91 public:
94 Position _pos; // 额外偏移
97
98 bool _bRunAble; // 可运行
99 bool _bUpdateAble; // 可更新
100 bool _bRenderAble; // 可绘制
101
102 bool _bParentW; // 跟随panel宽度
103 bool _bParentH; // 跟随panel高度
104 };
105
107 class Drag
108 {
109 public:
111 bool _bControlPanel;// 独立使用时无效(因为没有父Panel)
112 RectF _areaPickup; // 拾取范围
113 RectF _areaRange; // 拖拽范围
114 MouseCode _key; // 响应按钮
115
117 _bEnable{ true },
118 _bControlPanel{ false },
119 _areaPickup{},
120 _areaRange{},
121 _key{ MouseCode::LEFT },
122 _state{ 0 },
123 _xyClick{},
124 _posOld{}
125 {}
126
127 void Update(Coor* coor, bool is_pickup);
128 public:
129 int _state; // 0.未点击 1.拖拽中
130 Point _xyClick; // 拖拽点击位置(世界)
133 };
134}
135
136}
2d坐标系
void Update(Coor *coor, bool is_pickup)
可独立使用
Position GetSize() const
自身大小
Position GetOffset() const
位置偏移(实际coor位置)
Position GetAnchor() const
锚点位置
int GetOrderOffset()
order偏移
由于this指针在构造完成之前无效,不能在初始化列表构造
std::array< std::string, 2 > _str
std::function< void(std::string_view, std::string_view)> _func
变量,注意模板参数 需要实例化后不重复
组件系统
键盘与手柄等按键操作
通用类型定义
方向、对齐定义
Array< Direction, 2 > Direction2
constexpr Array< T, N > Size2Anchor(const Array< T, N > &size, const Array< Direction, N > &dir)
根据大小和对齐,计算锚点
子组件命名空间
Variable< std::string, str_uid("CustomName")> CustomName
Function< std::function< bool()>, str_uid("IsSelect")> IsSelect
选择
Function< std::function< void(float)>, str_uid("SetOrder")> SetOrder
设置order
Function< std::function< void()>, str_uid("RenderD")> RenderDebug
调试绘图
Function< std::function< dl::Coor *()>, str_uid("GetCoor")> GetCoor
返回坐标系
Function< std::function< bool()>, str_uid("IsPickup")> IsPickup
---------------------------—具体组件----------------------------------—
Variable< int, str_uid("CustomTag")> CustomTag
Function< std::function< bool()>, str_uid("IsDown")> IsDown
按下状态
Function< std::function< float()>, str_uid("GetOrder")> GetOrder
返回order
Function< std::function< Position(void)>, str_uid("GetSize")> GetSize
获取大小
Function< std::function< void(const Position &size)>, str_uid("SetSize")> SetSize
设置大小
Function< std::function< void(bool)>, str_uid("SetSelect")> SetSelect
设置是否选择
Function< std::function< void()>, str_uid("Render")> Render
绘制
Function< std::function< void()>, str_uid("DeleteThis")> DeleteThis
删除自身
Function< std::function< void()>, str_uid("Update")> Update
逻辑
Function< std::function< bool()>, str_uid("IsClick")> IsClick
点击
Function< std::function< Components *()>, str_uid("Clone")> Clone
克隆
Position2 Position
constexpr RectF createRectF(const Position &size)
创建一个RectF,依据大小
Position4 RectF
consteval uint64_t str_uid(const char(&str)[N])
固定条件的字符串,生成唯一id
Point2 Point