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);
54
55
65
66
68 {
69 return _coor;
70 }
71
72 // TODO 刷新
73 void SetFixedW(bool fixed) { _bParentW = fixed; }
74 void SetFixedH(bool fixed) { _bParentH = fixed; }
75
76 bool IsFixedW() { return _bParentW; }
77 bool IsFixedH() { return _bParentH; }
78
79 bool IsPickup();
80
81 void Render();
82
83 void SetOrder(float order);
84
85 void SetUI(bool ui);
86
88
91
92 Components* GetCpt() { return &_cpt; }
93
95 {
96 delete _ui._spr9;
97 delete _coor;
98 }
99private:
100 Background() :
101 _size{},
102 _offset{},
103 _bParentW{ false },
104 _bParentH{ false },
105 _cpt{ this }
106 {
107 _init_cpt();
108 }
109
110 struct UI
111 {
113 gcSprite _spr;
114 Sprite9* _spr9 = nullptr;
115 };
116
117 Coor* _coor;
118 Position _size; // 设置的大小
119 Position _offset;
120 bool _bParentW; // 填充父节点宽度
121 bool _bParentH; // 填充父节点高度
122 UI _ui;
123
124 Components _cpt;
125 Cpt::DeleteThis _cptDeleteThis;
126 Cpt::SetOrder _cptSetOrder;
127 Cpt::Render _cptRender;
128 Cpt::IsPickup _cptIsPickup;
129 Cpt::GetCoor _cptGetCoor;
130 Cpt::RenderDebug _cptRenderDebug;
131 Cpt::ElementData _cptElemData;
132
133 void _delete_this() { delete this; }
134
135 void _init_cpt()
136 {
137 _cptDeleteThis = std::bind(&Background::_delete_this, this);
138 _cptSetOrder = std::bind(&Background::SetOrder, this, std::placeholders::_1);
139 _cptIsPickup = std::bind(&Background::IsPickup, this);
140 _cptRender = std::bind(&Background::Render, this);
141 _cptGetCoor = std::bind(&Background::GetCoor, this);
142 _cptRenderDebug = std::bind(&Background::RenderDebug, this);
143
144 _cpt.PushBack(&_cptDeleteThis);
145 _cpt.PushBack(&_cptSetOrder);
146 _cpt.PushBack(&_cptIsPickup);
147 _cpt.PushBack(&_cptRender);
148 _cpt.PushBack(&_cptGetCoor);
149 _cpt.PushBack(&_cptRenderDebug);
150
151 _cpt.PushBack(&_cptElemData);
152 }
153
154};
155
156
157}
158
159
160#endif
2d坐标系
static Coor * Create(Coor *parent=nullptr)
九图精灵
void Set(Sprite9 *spr9)
Background * Clone()
static Background * Create()
Position GetSize()
返回设置的大小
void RefreshSize()
ui缩放变更后会调用
Position GetSizeReal()
返回显示的实际大小
void SetSize(const Position &size)
设置大小,若设置了填充属性,则作为额外大小使用
void SetOrder(float order)
void SetUI(bool ui)
Position GetOffset()
void Set(gcSprite spr)
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()>, str_uid("Render")> Render
绘制
Function< std::function< void()>, str_uid("DeleteThis")> DeleteThis
删除自身
Position2 Position
GC< Sprite > gcSprite