dl
dl_ui_background.h
浏览该文件的文档.
1
13#pragma once
14
15#ifndef DL_DISABLE_RENDER
16#include "render/dl_sprite.h"
17#include "render/dl_sprite9.h"
19
20namespace dl::UI
21{
23class Background
24{
25public:
26 enum class Type
27 {
31 };
32
33 static Background* Create()
34 {
35 Background* ret = new Background;
36 ret->_coor = Coor::Create();
37 return ret;
38 }
39
40 Background* Clone();
41
42 void Set(gcSprite spr);
43 void Set(Sprite9* spr9);
44
45 void Clear();
49 void SetOffset(const Position& offset);
53 void SetSize(const Position& size);
57 void SetSizeExtra(const Position& size);
58
59 // todo 不会即时生效
60 Cpt::ElementData& GetElementData() { return _cptElemData; }
61
71
72
74 {
75 return _coor;
76 }
77
78 // TODO 刷新
79 void SetWindowW(bool fixed) { _bWindowW = fixed; }
80 void SetWindowH(bool fixed) { _bWindowH = fixed; }
81
82 bool IsWindowW() { return _bWindowW; }
83 bool IsWindowH() { return _bWindowH; }
84
85 bool IsPickup();
86
87 void Render();
88
89 void SetOrder(float order);
90
91 void SetUI(bool ui);
92
94
97
98 Components* GetCpt() { return &_cpt; }
99
101 {
102 delete _ui._spr9;
103 delete _coor;
104 }
105private:
106 Background() :
107 _sizeExtra{},
108 _bWindowW{ false },
109 _bWindowH{ false },
110 _cpt{ this }
111 {
112 _init_cpt();
113 }
114
115 struct UI
116 {
118 gcSprite _spr;
119 Sprite9* _spr9 = nullptr;
120 };
121
122 Coor* _coor;
123 Position _sizeExtra;
124 bool _bWindowW; // 填充窗口宽度
125 bool _bWindowH; // 填充窗口高度
126 UI _ui;
127
128 Components _cpt;
129 Cpt::DeleteThis _cptDeleteThis;
130 Cpt::SetOrder _cptSetOrder;
131 Cpt::Render _cptRender;
132 Cpt::IsPickup _cptIsPickup;
133 Cpt::GetCoor _cptGetCoor;
134 Cpt::SetSize _cptSetSize;
135 Cpt::RenderDebug _cptRenderDebug;
136 Cpt::ElementData _cptElemData;
137
138 void _delete_this() { delete this; }
139
140 void _init_cpt()
141 {
142 _cptDeleteThis = std::bind(&Background::_delete_this, this);
143 _cptSetOrder = std::bind(&Background::SetOrder, this, std::placeholders::_1);
144 _cptIsPickup = std::bind(&Background::IsPickup, this);
145 _cptRender = std::bind(&Background::Render, this);
146 _cptGetCoor = std::bind(&Background::GetCoor, this);
147 _cptSetSize = std::bind(&Background::SetSize, this, std::placeholders::_1);
148 _cptRenderDebug = std::bind(&Background::RenderDebug, this);
149
150 _cpt.PushBack(&_cptDeleteThis);
151 _cpt.PushBack(&_cptSetOrder);
152 _cpt.PushBack(&_cptIsPickup);
153 _cpt.PushBack(&_cptRender);
154 _cpt.PushBack(&_cptGetCoor);
155 _cpt.PushBack(&_cptSetSize);
156 _cpt.PushBack(&_cptRenderDebug);
157
158 _cpt.PushBack(&_cptElemData);
159 }
160
161};
162
163
164}
165
166
167#endif
2d坐标系
static Coor * Create(Coor *parent=nullptr)
元素通用属性(默认左上对齐,便于理解)
九图精灵
void Set(Sprite9 *spr9)
void SetWindowW(bool fixed)
Background * Clone()
static Background * Create()
void SetSizeExtra(const Position &size)
设置额外大小
Position GetSize()
返回设置的大小(不包含额外大小)
void RefreshSize()
ui缩放变更后会调用
Position GetSizeReal()
返回显示的实际大小
void SetSize(const Position &size)
设置大小
void SetOrder(float order)
void SetUI(bool ui)
Position GetOffset()
Cpt::ElementData & GetElementData()
void Set(gcSprite spr)
void SetWindowH(bool fixed)
void SetOffset(const Position &offset)
设置偏移
组件实例
九图精灵
2d绘图元素
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< void(const Position &size)>, str_uid("SetSize")> SetSize
设置大小
Function< std::function< void()>, str_uid("Render")> Render
绘制
Function< std::function< void()>, str_uid("DeleteThis")> DeleteThis
删除自身
Position2 Position
GC< Sprite > gcSprite