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
38 class Lang
39 {
40 public:
41 std::array<std::string, 2> _str;
42 std::function<void(std::string_view, std::string_view)> _func;
43 };
44
47 {
48 public:
50 _size{},
51 _anchor{},
52 _pos{},
53 _hv{ Align::LT },
54 _orderOffset{ 0 },
55 _bRunAble{true},
56 _bUpdateAble{true},
57 _bRenderAble{true}
58 {}
59
61 {
63 }
64
67 {
68 return _size;
69 }
70
72 {
73 return _anchor;
74 }
75
77 {
78 return _orderOffset;
79 }
80
82 {
83 return createRectF(GetOffset(), GetSize());
84 }
85 public:
88 Position _pos; // 额外偏移
91
92 bool _bRunAble; // 可运行
93 bool _bUpdateAble; // 可更新
94 bool _bRenderAble; // 可绘制
95 };
96
98 class Drag
99 {
100 public:
102 bool _bControlPanel;// 独立使用时无效
103 RectF _areaPickup; // 拾取范围
104 RectF _areaRange; // 拖拽范围
105 MouseCode _key; // 响应按钮
106
108 _bEnable{ true },
109 _bControlPanel{ false },
110 _areaPickup{},
111 _areaRange{},
112 _key{ MouseCode::LEFT },
113 _state{ 0 },
114 _xyClick{},
115 _posOld{}
116 {}
117
118 void Update(Coor* coor, bool is_pickup);
119 public:
120 int _state; // 0.未点击 1.拖拽中
121 Point _xyClick; // 拖拽点击位置(世界)
124 };
125}
126
127}
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< 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