rendering element rewrite
This commit is contained in:
parent
4c286e1fd8
commit
3d40256bde
22 changed files with 799 additions and 795 deletions
|
|
@ -30,7 +30,7 @@ import std;
|
|||
|
||||
using namespace Crafter;
|
||||
|
||||
TextElement::TextElement(std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z) : RenderingElementPreScaled(OpaqueType::Transparent, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z) {
|
||||
TextElement::TextElement(Anchor anchor): RenderingElement<false, false, false>(anchor, OpaqueType::Transparent) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ void TextElement::RenderText(Window& window, const std::string_view text, float
|
|||
int baseline = (int)(font.ascent * scale);
|
||||
|
||||
// Clear the scaled buffer
|
||||
for (auto& pixel : bufferScaled) {
|
||||
for (auto& pixel : buffer) {
|
||||
pixel = {0, 0, 0, 0};
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ void TextElement::RenderText(Window& window, const std::string_view text, float
|
|||
|
||||
// Only draw pixels that are within our scaled buffer bounds
|
||||
if (bufferX >= 0 && bufferX < (int)scaled.width && bufferY >= 0 && bufferY < (int)scaled.height) {
|
||||
bufferScaled[bufferY * scaled.width + bufferX] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
buffer[bufferY * scaled.width + bufferX] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -288,11 +288,11 @@ void TextElement::RenderText(Window& window, const std::string_view text, float
|
|||
for (std::uint_fast32_t y = 0; y < scaled.height; ++y) {
|
||||
for (std::uint_fast32_t x = 0; x < scaled.width; ++x) {
|
||||
std::uint_fast32_t index = y * scaled.width + x;
|
||||
if (index < bufferScaled.size()) {
|
||||
if (index < buffer.size()) {
|
||||
// Move the pixel vertically
|
||||
std::uint_fast32_t newIndex = (y + verticalOffset) * scaled.width + x;
|
||||
if (newIndex < bufferScaled.size()) {
|
||||
bufferScaled[newIndex] = bufferScaled[index];
|
||||
if (newIndex < buffer.size()) {
|
||||
buffer[newIndex] = buffer[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ void TextElement::RenderWrappedLine(const std::string_view line, float scale, in
|
|||
|
||||
// Only draw pixels that are within our scaled buffer bounds
|
||||
if (bufferX >= 0 && bufferX < (int)scaled.width && bufferY >= 0 && bufferY < (int)scaled.height) {
|
||||
bufferScaled[bufferY * scaled.width + bufferX] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
buffer[bufferY * scaled.width + bufferX] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue