2025-01-09 20:22:49 +01:00
|
|
|
/*
|
|
|
|
MIT License
|
2025-02-04 21:44:27 +01:00
|
|
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
2025-01-09 20:22:49 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2025-02-22 00:23:48 +01:00
|
|
|
#include <pd/external/stb_truetype.h>
|
2025-01-09 20:22:49 +01:00
|
|
|
|
2025-02-22 00:23:48 +01:00
|
|
|
#include <pd/core/io.hpp>
|
|
|
|
#include <pd/core/strings.hpp>
|
|
|
|
#include <pd/core/sys.hpp>
|
|
|
|
#include <pd/lithium/font.hpp>
|
|
|
|
#include <pd/lithium/renderer.hpp>
|
2025-01-09 20:22:49 +01:00
|
|
|
|
|
|
|
namespace PD {
|
2025-02-22 00:23:48 +01:00
|
|
|
namespace LI {
|
|
|
|
void StaticText::Setup(Renderer* ren, const vec2& pos, u32 clr,
|
|
|
|
const std::string& text, LITextFlags flags,
|
|
|
|
const vec2& box) {
|
|
|
|
this->tdim = ren->GetTextDimensions(text);
|
|
|
|
this->pos = pos;
|
|
|
|
this->ren = ren;
|
|
|
|
this->text = StaticObject::New();
|
|
|
|
/// Ensure that it also renders Out of Screen i guess
|
|
|
|
ren->TextCommand(this->text->List(), pos, clr, text,
|
|
|
|
flags | LITextFlags_RenderOOS, box);
|
|
|
|
Renderer::OptiCommandList(this->text->List());
|
2025-01-09 20:22:49 +01:00
|
|
|
}
|
2025-02-22 00:23:48 +01:00
|
|
|
|
|
|
|
void StaticText::Draw() {
|
|
|
|
used = true;
|
|
|
|
for (auto& it : text->List()) {
|
|
|
|
ren->PushCommand(it);
|
2025-01-09 20:22:49 +01:00
|
|
|
}
|
2025-02-22 00:23:48 +01:00
|
|
|
text->ReCopy();
|
2025-01-09 20:22:49 +01:00
|
|
|
}
|
2025-02-22 00:23:48 +01:00
|
|
|
|
|
|
|
void StaticText::SetColor(u32 col) { text->ReColor(col); }
|
|
|
|
void StaticText::SetPos(const vec2& pos) { text->MoveIt(pos - this->pos); }
|
|
|
|
|
|
|
|
void StaticText::SetLayer(int layer) { text->ReLayer(layer); }
|
|
|
|
} // namespace LI
|
2025-01-09 20:22:49 +01:00
|
|
|
} // namespace PD
|