Files
dl_old/dltest/ui_main.h
T
2024-01-03 15:16:54 +08:00

186 lines
3.8 KiB
C++

/**
* @file ui_main.h
* @brief 主界面
*
*
* @version 1.0
* @author lveyou
* @date 23-08-13
*
* @note
*/
#pragma once
#include <dl_ui.h>
#include <tool/dl_tool_debug_info.h>
#include <tool/dl_tool_ruler.h>
#include "ui_def.h"
#include "ui_gfx.h"
#include "ui_gui.h"
#include "ui_text.h"
#include "ui_sprite.h"
#include "ui_audio.h"
using namespace dl;
class UIMain
{
public:
UIMain()
{
_panel = g_ui->CreatePanel();
_panel->SetAutoRun(false);
_panel->SetPosScale({ 0.5f, 0.1f });
_panel->SetLocator("main");
{
UI::Text* txt = g_ui->CreateText("title");
txt->SetString("dl库测试程序v0.1");
_panel->Add(txt);
}
_panel->AddCpt(createComponents());
_panel->AddCpt(createComponents());
std::array menu = {
"gfx", "sprite", "text", "gui", "audio"
};
for(auto& iter : menu)
{
UI::ButtonSprite* btn = g_ui->CreateButtonSpriteDefault();
btn->SetElementData(Align::CC);
btn->GetCpt()->SetName(iter);
btn->SetMode(UI::ButtonMode::RADIO);
btn->SetString(iter);
_panel->Add(btn);
}
//
_debugInfo = Tool::DebugInfo::Create();
_ruler = Tool::Ruler::Create();
}
void Run()
{
std::string name = _panel->GetSelectName();
if (name.empty())
{
_panel->Update();
_panel->Render();
}
else if (name == "gfx")
{
_uiInfo._txtTitle->SetString("Graphics 基础绘图");
_uiInfo._txtInfo->SetString("基本几何图形绘制");
_uiInfo._panelInfo->Update();
_uiInfo._panelInfo->Render();
_uiGfx.Update();
_uiGfx.Render();
}
else if (name == "sprite")
{
_uiInfo._txtTitle->SetString("Sprite 2d绘图");
_uiInfo._txtInfo->SetString("2d图形绘制");
_uiInfo._panelInfo->Update();
_uiInfo._panelInfo->Render();
_uiSprite.Update();
_uiSprite.Render();
}
else if (name == "text")
{
_uiInfo._txtTitle->SetString("Text 文本绘制");
_uiInfo._txtInfo->SetString("文本绘制");
_uiInfo._panelInfo->Update();
_uiInfo._panelInfo->Render();
_uiText.Update();
_uiText.Render();
}
else if (name == "gui")
{
_uiInfo._txtTitle->SetString("GUI 图像用户界面");
_uiInfo._txtInfo->SetString("GUI展示");
_uiInfo._panelInfo->Update();
_uiInfo._panelInfo->Render();
_uiGui.Update();
_uiGui.Render();
}
else if (name == "audio")
{
_uiInfo._txtTitle->SetString("Audio 音频系统");
_uiInfo._txtInfo->SetString("音频系统 点左键播放");
_uiInfo._panelInfo->Update();
_uiInfo._panelInfo->Render();
_uiAudio.Update();
_uiAudio.Render();
// if (g_input->KeyDown(MouseCode::LEFT))
// {
// snd_play("wanwu");
// snd_play("swt_over");
// }
}
if (!name.empty())
{
if (_uiInfo._btnBack->IsClick())
{
_panel->SetSelect(-1);
}
}
_debugInfo->Render("[c_yellow]ctrl使用尺子工具\nf1显示ui框架\nf2隐藏ui");
_ruler->Update();
_ruler->Render();
}
~UIMain()
{
delete _ruler;
delete _debugInfo;
}
private:
UI::Panel* _panel;// 主菜单
struct UIInfo
{
UI::Panel* _panelInfo;// 界面介绍
UI::Text* _txtTitle;
UI::Text* _txtInfo;
UI::ButtonSprite* _btnBack;
UIInfo()
{
_panelInfo = g_ui->CreatePanel();
_panelInfo->SetAutoRun(false);
_panelInfo->SetPosScale({ 0.0f, 0.0f });
_panelInfo->SetPosPixel({ 100, 50 });
_panelInfo->SetLocator("main_info");
//_panelInfo->AddCpt(createComponents());
_txtTitle = g_ui->CreateText("t_normal");
//_txtTitle->SetElementData(Align::LT);
_panelInfo->Add(_txtTitle);
_txtInfo = g_ui->CreateText("c_normal");
_panelInfo->Add(_txtInfo);
_panelInfo->AddCpt(createComponents());
_btnBack = g_ui->CreateButtonSpriteDefault();
_btnBack->SetString("返回");
_panelInfo->Add(_btnBack);
}
}_uiInfo;
UIGfx _uiGfx;
UIText _uiText;
UIGui _uiGui;
UISprite _uiSprite;
UIAudio _uiAudio;
Tool::DebugInfo* _debugInfo;
Tool::Ruler* _ruler;
};