Files
dl_old/dl/ui/dl_ui_window.cpp
T
2026-08-21 12:53:03 +08:00

80 lines
1.3 KiB
C++

#include "dl_ui_window.h"
#ifndef DL_DISABLE_RENDER
#include "dl_ui_manager.h"
namespace dl::UI
{
void Window::_init()
{
_panel = g_ui->CreatePanel();
_panel->SetAutoRun(false);
_panel->SetOrderMode(Panel::FORCE);
}
Window::~Window()
{
g_ui->DeletePanel(_panel, true);
g_ui->_release_window(this);
}
void Window::SetBackground(UI::Background* bg, bool auto_size)
{
if (_bg)
_panel->Del(_bg);
_bg = bg;
if (auto_size)
{
_bg->GetElementData()._bParentW = true;
_bg->GetElementData()._bParentH = true;
}
_drag._bControlPanel = true;
_bg->GetCpt()->PushBack(&_drag);
_panel->Add(bg);
_refresh_order_bg(_panel->GetOrder());
}
void Window::SetButtonClose(UI::Button* btn)
{
if (_btnClose)
_panel->Del(_btnClose);
_panel->Add(btn);
_btnClose = btn;
_refresh_order_btn_close(_panel->GetOrder());
}
void Window::SetVisible(bool visible)
{
_bVisible = visible;
if(_bInManager)
g_ui->_on_window_show_change(this, _bVisible);
if (!_bVisible && _btnClose)
_btnClose->ClearState();
}
void Window::ExFastSet()
{
SetBackground(g_ui->CreateBackgroundDefault());
auto btn = g_ui->CreateButtonSpriteDefault(ButtonStyle::CLOSE);
btn->SetElementData(Align::RT, { 400, 0 });
SetButtonClose(btn);
SetSize({ 400, 300 });
Center();
SetVisible(false);
}
}
#endif