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
40 class Lang
41 {
42 public:
43 std::array<std::string, 2> _str;
44 std::function<void(std::string_view, std::string_view)> _func;
45 };
46
49 {
50 public:
52 _size{},
53 _anchor{},
54 _pos{},
55 _hv{ Align::LT },
56 _orderOffset{ 0 },
57 _bRunAble{ true },
58 _bUpdateAble{ true },
59 _bRenderAble{ true },
60 _bParentW{ false },
61 _bParentH{ false }
62 {}
63
65 {
67 }
68
71 {
72 return _size;
73 }
74
76 {
77 return _anchor;
78 }
79
81 {
82 return _orderOffset;
83 }
84
86 {
87 return createRectF(GetOffset(), GetSize());
88 }
89 public:
92 Position _pos; // 额外偏移
95
96 bool _bRunAble; // 可运行
97 bool _bUpdateAble; // 可更新
98 bool _bRenderAble; // 可绘制
99
100 bool _bParentW; // 跟随panel宽度
101 bool _bParentH; // 跟随panel高度
102 };
103
105 class Drag
106 {
107 public:
109 bool _bControlPanel;// 独立使用时无效
110 RectF _areaPickup; // 拾取范围
111 RectF _areaRange; // 拖拽范围
112 MouseCode _key; // 响应按钮
113
115 _bEnable{ true },
116 _bControlPanel{ false },
117 _areaPickup{},
118 _areaRange{},
119 _key{ MouseCode::LEFT },
120 _state{ 0 },
121 _xyClick{},
122 _posOld{}
123 {}
124
125 void Update(Coor* coor, bool is_pickup);
126 public:
127 int _state; // 0.未点击 1.拖拽中
128 Point _xyClick; // 拖拽点击位置(世界)
131 };
132}
133
134}
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)
垂直位置
子组件命名空间
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
---------------------------—具体组件----------------------------------—
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 &lt, const Position &size)
创建一个Rect,依据左上角和大小
Position4 RectF
consteval uint64_t str_uid(const char(&str)[N])
固定条件的字符串,生成唯一id
Point2 Point