* ui系统改进
This commit is contained in:
@@ -129,4 +129,29 @@ constexpr std::array<PointU::value_type, N> toSizeDefault(const std::array<T, N>
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 长度+1
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
constexpr std::array<T, N + 1> toLonger(const std::array<T, N>& a, const T& v = {})
|
||||
{
|
||||
std::array<T, N + 1> ret;
|
||||
for (int i = 0; i != N; ++i)
|
||||
ret[i] = a[i];
|
||||
ret[N] = v;
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief 长度-1
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
constexpr std::array<T, N - 1> toShorter(const std::array<T, N>& a)
|
||||
{
|
||||
std::array<T, N - 1> ret;
|
||||
for (int i = 0; i != N - 1; ++i)
|
||||
ret[i] = a[i];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "dl_graphics.h"
|
||||
|
||||
#include "vk/dl_vk.h"
|
||||
#include "math/dl_coor.h"
|
||||
|
||||
namespace dl
|
||||
{
|
||||
@@ -10,25 +11,62 @@ namespace dl
|
||||
// 汉
|
||||
void Graphics::Dot(const Position3& p)
|
||||
{
|
||||
VertexGfx v;
|
||||
v._pos = p;
|
||||
v._color = _col;
|
||||
g_vk->GfxPushDot(v);
|
||||
std::array<VertexGfx, 1> v;
|
||||
v[0]._pos = toShorter(_mat * toLonger(p, 1.0_f));
|
||||
v[0]._color = _col[0];
|
||||
|
||||
g_vk->GfxPushDot(v[0]);
|
||||
}
|
||||
|
||||
void Graphics::Line(const Position3& p0, const Position3& p1)
|
||||
{
|
||||
g_vk->GfxPushLine({ p0, _col }, { p1, _col });
|
||||
std::array<VertexGfx, 2> v;
|
||||
v[0]._pos = toShorter(_mat * toLonger(p0, 1.0_f));
|
||||
v[1]._pos = toShorter(_mat * toLonger(p1, 1.0_f));
|
||||
v[0]._color = _col[0];
|
||||
v[1]._color = _col[1];
|
||||
|
||||
g_vk->GfxPushLine(v[0], v[1]);
|
||||
}
|
||||
|
||||
void Graphics::Triangle(const Position3& p0, const Position3& p1, const Position3& p2)
|
||||
{
|
||||
g_vk->GfxPushTriangle({ p0, _col }, { p1, _col }, { p2, _col });
|
||||
std::array<VertexGfx, 2> v;
|
||||
v[0]._pos = toShorter(_mat * toLonger(p0, 1.0_f));
|
||||
v[1]._pos = toShorter(_mat * toLonger(p1, 1.0_f));
|
||||
v[2]._pos = toShorter(_mat * toLonger(p2, 1.0_f));
|
||||
v[0]._color = _col[0];
|
||||
v[1]._color = _col[1];
|
||||
v[2]._color = _col[2];
|
||||
g_vk->GfxPushTriangle(v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
void Graphics::TriangleSolid(const Position3& p0, const Position3& p1, const Position3& p2)
|
||||
{
|
||||
g_vk->GfxPushTriangleSolid({ p0, _col }, { p1, _col }, { p2, _col });
|
||||
std::array<VertexGfx, 2> v;
|
||||
v[0]._pos = toShorter(_mat * toLonger(p0, 1.0_f));
|
||||
v[1]._pos = toShorter(_mat * toLonger(p1, 1.0_f));
|
||||
v[2]._pos = toShorter(_mat * toLonger(p2, 1.0_f));
|
||||
v[0]._color = _col[0];
|
||||
v[1]._color = _col[1];
|
||||
v[2]._color = _col[2];
|
||||
g_vk->GfxPushTriangleSolid(v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
void Graphics::RenderCoor(Coor* coor)
|
||||
{
|
||||
SetMatrix(coor);
|
||||
|
||||
Line({}, { 1, 0, 0 });
|
||||
Line({}, { 0, 1, 0 });
|
||||
}
|
||||
|
||||
void Graphics::SetMatrix(Coor* coor)
|
||||
{
|
||||
Matrix4 m_t = Mat::CreateTranslation(toLonger(coor->GetPosition()));
|
||||
Matrix4 m_r = Mat::CreateRotation({ 0, 0, 1 }, coor->GetRotate());
|
||||
Matrix4 m_s = Mat::CreateScaling(toLonger(coor->GetPosition(), 1.0_f));
|
||||
_mat = m_t * m_r * m_s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-5
@@ -16,12 +16,18 @@
|
||||
|
||||
namespace dl
|
||||
{
|
||||
class Coor;
|
||||
|
||||
class Graphics
|
||||
{
|
||||
public:
|
||||
Graphics():
|
||||
_col{ColorDef::RED}
|
||||
{}
|
||||
Graphics()
|
||||
{
|
||||
for (auto& iter : _col)
|
||||
{
|
||||
iter = ColorDef::RED;
|
||||
}
|
||||
}
|
||||
//-----------------------------基础------------------------------
|
||||
void Dot(const Position3& p);
|
||||
void Line(const Position3& p0, const Position3& p1);
|
||||
@@ -101,15 +107,29 @@ public:
|
||||
col = { cur - 4.0f, 1.0f, 0.0f, 1.0f };
|
||||
else
|
||||
col = { 1.0f, 6.0f - cur, 0.0f, 1.0f };
|
||||
_col = col;
|
||||
SetColor(col);
|
||||
++i;
|
||||
Line(p0, p1);
|
||||
});
|
||||
|
||||
}
|
||||
//! 绘制Coor
|
||||
void RenderCoor(Coor* coor);
|
||||
|
||||
//------------------------------参数设置--------------------------------
|
||||
//! 设置变换矩阵
|
||||
void SetMatrix(const Matrix4 mat) { _mat = mat; }
|
||||
void SetMatrix(Coor* coor);
|
||||
|
||||
//! 设置颜色
|
||||
void SetColor(const Color& col)
|
||||
{
|
||||
for (auto& iter : _col)
|
||||
iter = col;
|
||||
}
|
||||
private:
|
||||
Matrix4 _mat;
|
||||
Color _col;
|
||||
std::array<Color, 3> _col;
|
||||
};
|
||||
|
||||
extern Graphics* g_gfx;
|
||||
|
||||
@@ -226,5 +226,6 @@ private:
|
||||
};
|
||||
|
||||
using ButtonMode = Button::Mode;
|
||||
using ButtonState = Button::State;
|
||||
|
||||
}
|
||||
@@ -126,4 +126,26 @@ void ButtonSprite::_create(const std::vector<gcSprite>& mul_spr)
|
||||
_update_coor();
|
||||
}
|
||||
|
||||
void ButtonSprite::SetSpriteQuad(Button::State state, const Quad& quad)
|
||||
{
|
||||
if (state < Button::State::MAX_NUM)
|
||||
_spr[state]->SetQuad(quad);
|
||||
else
|
||||
{
|
||||
for (auto& spr : _spr)
|
||||
spr->SetQuad(quad);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonSprite::SetSpriteColor(Button::State state, const Color& color)
|
||||
{
|
||||
if (state < Button::State::MAX_NUM)
|
||||
_spr[state]->SetColor(color);
|
||||
else
|
||||
{
|
||||
for (auto& spr : _spr)
|
||||
spr->SetColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,6 +48,20 @@ public:
|
||||
|
||||
void SetString(std::string_view str);
|
||||
|
||||
/**
|
||||
* @brief 设置精灵quad
|
||||
* @param[in] state 状态,传入MAX_NUM表示所有
|
||||
* @param[in] quad 大小
|
||||
* @note 会拉伸图像
|
||||
*/
|
||||
void SetSpriteQuad(Button::State state, const Quad& quad);
|
||||
/**
|
||||
* @brief 设置精灵颜色
|
||||
* @param[in] state 状态,传入MAX_NUM表示所有
|
||||
* @param[in] quad 大小
|
||||
* @note 会拉伸图像
|
||||
*/
|
||||
void SetSpriteColor(Button::State state, const Color& color);
|
||||
|
||||
virtual bool IsPickup() override
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "io/dl_file.h"
|
||||
#include "dl_string.h"
|
||||
#include "render/dl_graphics.h"
|
||||
|
||||
namespace dl::UI
|
||||
{
|
||||
@@ -156,6 +157,11 @@ ListBox* Manager::CreateListBoxDefault()
|
||||
{
|
||||
ButtonSprite* btn = g_ui->CreateButtonSpriteDefault();
|
||||
btn->SetMode(ButtonMode::SWITCH);
|
||||
btn->SetSpriteQuad(ButtonState::MAX_NUM, createQuad(Size{ 200, 16 }, false));
|
||||
btn->SetSpriteColor(ButtonState::NORMAL, ColorDef::GRAY);
|
||||
btn->SetSpriteColor(ButtonState::OVER, ColorDef::GREEN);
|
||||
btn->SetSpriteColor(ButtonState::DOWN, ColorDef::BLUE);
|
||||
|
||||
panel->Add(btn->GetCpt());
|
||||
}
|
||||
ListBox* ret = ListBox::Create(panel);
|
||||
@@ -498,6 +504,32 @@ void Manager::_resize_panel_root()
|
||||
_panelRoot->SetBackgroundSize(toSizeNeg2Zero(toPosition(size) / _uiScale));
|
||||
}
|
||||
|
||||
void Manager::RenderDebug()
|
||||
{
|
||||
//_mulPriCoor.Clear();
|
||||
//_mulPriQuad.Clear();
|
||||
//
|
||||
for (auto& node : _allPanel)
|
||||
{
|
||||
Panel* panel = node->GetValue();
|
||||
if (!panel->IsRender())
|
||||
continue;
|
||||
g_gfx->RenderCoor(panel->_coor);
|
||||
|
||||
//组件处理
|
||||
for (Components* cpts : panel->_ele)
|
||||
{
|
||||
if (Cpt::ElementData* comp = cpts->Get<Cpt::ElementData>())
|
||||
{
|
||||
g_gfx->SetMatrix(panel->_coor);
|
||||
g_gfx->Rectangle(
|
||||
toLonger(comp->GetOffset()),
|
||||
toLonger(comp->GetOffset() + comp->GetSize()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-27
@@ -180,33 +180,7 @@ public:
|
||||
/**
|
||||
* @brief 绘制调试信息
|
||||
*/
|
||||
void RenderDebug()
|
||||
{
|
||||
//_mulPriCoor.Clear();
|
||||
//_mulPriQuad.Clear();
|
||||
//
|
||||
for (auto& node : _allPanel)
|
||||
{
|
||||
Panel* panel = node->GetValue();
|
||||
if (!panel->IsRender())
|
||||
continue;
|
||||
//Panel Coor
|
||||
//Primitive::Coor* pri_coor = _mulPriCoor.Get(panel->_coor);
|
||||
//pri_coor->Render();
|
||||
////组件处理
|
||||
//for (Components* cpts : panel->_ele)
|
||||
//{
|
||||
// if (Cpt::ElementData* cpt = cpts->Get<Cpt::ElementData>())
|
||||
// {
|
||||
// Primitive::QuadLine* pri_quad = _mulPriQuad.Get();
|
||||
// pri_quad->GetCoor()->SetParent(panel->_coor);
|
||||
// pri_quad->Set(createQuad(cpt->_size, false) + cpt->GetOffset());
|
||||
// pri_quad->SetColor(ColorDef::PURPLE);
|
||||
// pri_quad->Render();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
void RenderDebug();
|
||||
|
||||
~Manager()
|
||||
{
|
||||
|
||||
@@ -103,6 +103,11 @@ void Run()
|
||||
//g_gfx->Love();
|
||||
|
||||
//base->spr9->Render();
|
||||
|
||||
if (g_input->KeyState(KeyCode::F1))
|
||||
{
|
||||
g_ui->RenderDebug();
|
||||
}
|
||||
}
|
||||
|
||||
void Release()
|
||||
|
||||
Reference in New Issue
Block a user