#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, bool close) { _bClickClose = close; 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); } void Window::TopShow() { if (_bInManager) g_ui->SetWindowTop(this); else SetOrder(Math::OffsetOrder(g_ui->GetWindowOrderMin(), -1)); } void Window::Update() { if (!_bVisible) return; _panel->Update(); if (_bClickClose && _btnClose && _btnClose->IsClick()) { SetVisible(false); } if (_bClickTop && g_input->KeyDown(MouseCode::LEFT) && _bg && _bg->IsPickup()) { TopShow(); } } } #endif