Dawn/src/dawn/component/vn/VNManager.cpp
2024-09-29 00:47:12 -05:00

62 lines
1.6 KiB
C++

// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNManager.hpp"
using namespace Dawn;
void VNManager::onInit() {
assertNotNull(canvas, "Canvas must be set.");
assertNotNull(texture, "Texture must be set.");
container = std::make_shared<UIContainer>();
container->align = { 0, 128, 0, 0 };
container->alignX = UIAlignmentType::STRETCH;
container->alignY = UIAlignmentType::END;
borders = std::make_shared<UIRectangle>();
borders->align = { 0, 0, 0, 0 };
borders->alignX = UIAlignmentType::STRETCH;
borders->alignY = UIAlignmentType::STRETCH;
borders->color = COLOR_BLUE;
container->appendChild(borders);
background = std::make_shared<UIRectangle>();
background->align = { 16, 16, 16, 16 };
background->alignX = UIAlignmentType::STRETCH;
background->alignY = UIAlignmentType::STRETCH;
background->color = COLOR_RED;
container->appendChild(background);
label = std::make_shared<UILabel>();
label->align = { 16, 16, 16, 16 };
label->alignX = UIAlignmentType::STRETCH;
label->alignY = UIAlignmentType::STRETCH;
label->setFont(texture);
label->setText(text);
container->appendChild(label);
canvas->addElement(container);
listeners.push_back(getScene()->onUnpausedUpdate.listen([&](const float_t d) {
}));
}
void VNManager::onDispose() {
canvas->removeElement(container);
container = nullptr;
label = nullptr;
background = nullptr;
borders = nullptr;
texture = nullptr;
canvas = nullptr;
}
void VNManager::setText(const std::wstring &text) {
this->text = text;
if(label) label->setText(text);
}