#include "dl_ui_background.h" #ifndef DL_DISABLE_RENDER #include "render/dl_graphics.h" namespace dl::UI { void Background::_refresh_size() { switch (_ui._type) { case Type::SPRITE: _ui._spr->SetQuad(createQuad(_size, false) + _offset); break; case Type::SPRITE9: _ui._spr9->SetRect(createRect(toPoint(_offset), toSize(_size))); break; default: break; } } dl::UI::Background* Background::Clone() { Background* ret = new Background; ret->_coor = _coor->Clone(); switch (_ui._type) { case Type::SPRITE: ret->_ui._spr = g_factory->CloneSprite(_ui._spr); ret->_ui._spr->SetCoor(ret->_coor); break; case Type::SPRITE9: ret->_ui._spr9 = _ui._spr9->Clone(); ret->_ui._spr9->GetCoor()->SetParent(ret->_coor); break; default: break; } ret->_ui._type = _ui._type; ret->_size = _size; ret->_offset = _offset; return ret; } void Background::Set(gcSprite spr) { Clear(); _ui._spr = spr; _ui._type = Type::SPRITE; _ui._spr->SetUI(true); _ui._spr->SetCoor(_coor); } void Background::Set(Sprite9* spr9) { Clear(); _ui._spr9 = spr9; _ui._type = Type::SPRITE9; _ui._spr9->SetUI(true); _ui._spr9->GetCoor()->SetParent(_coor); } void Background::Clear() { switch (_ui._type) { case Type::SPRITE: break; case Type::SPRITE9: delete _ui._spr9; _ui._spr9 = nullptr; break; default: break; } _ui._type = Type::NONE; } bool Background::IsPickup() { switch (_ui._type) { case Type::SPRITE: return _ui._spr->IsPickup(); case Type::SPRITE9: return _ui._spr9->IsPickup(); default: return false; } } void Background::Render() { switch (_ui._type) { case Type::SPRITE: _ui._spr->Render(); break; case Type::SPRITE9: _ui._spr9->Render(); break; default: break; } } void Background::SetOrder(float order) { switch (_ui._type) { case Type::SPRITE: _ui._spr->SetOrder(order); break; case Type::SPRITE9: _ui._spr9->SetOrder(order); break; default: break; } } void Background::SetUI(bool ui) { switch (_ui._type) { case Type::SPRITE: _ui._spr->SetUI(ui); break; case Type::SPRITE9: _ui._spr9->SetUI(ui); break; default: break; } } void Background::SetOffset(const Position& offset) { _offset = offset; _refresh_size(); } Position Background::GetOffset() { return _offset; } void Background::SetSize(const Position& size) { _size = size; _refresh_size(); } Position Background::GetSize() { return _size; } void Background::RenderDebug() { { Position p0 = _offset; Position p1 = p0 + GetSize(); g_gfx->SetCoor(_coor); g_gfx->SetColor(createColor(ColorDef::PURPLE, 1.0f)); g_gfx->Rectangle2D(p0, p1); } } } #endif