text changes

This commit is contained in:
Jorijn van der Graaf 2025-11-26 03:35:58 +01:00
commit d5ee272290
6 changed files with 135 additions and 54 deletions

View file

@ -36,17 +36,63 @@ RenderingElement::RenderingElement(bool opaque, std::int_fast32_t anchorX, std::
}
RenderingElement::RenderingElement(bool opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, 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, bool ignoreScaling) : bufferWidth(bufferWidth), bufferHeight(bufferHeight), buffer(bufferWidth*bufferHeight), Transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), opaque(opaque) {
RenderingElementPreScaled::RenderingElementPreScaled(bool opaque) : RenderingElement(opaque) {
}
void RenderingElement::ResizeBuffer(std::uint_fast32_t width, std::uint_fast32_t height) {
this->bufferWidth = width;
this->bufferHeight = height;
buffer.resize(width * height);
RenderingElementPreScaled::RenderingElementPreScaled(bool opaque, 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, bool ignoreScaling) : RenderingElement(opaque, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
}
void RenderingElement::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
RenderingElementScaling::RenderingElementScaling(bool opaque) : RenderingElement(opaque) {
}
RenderingElementScaling::RenderingElementScaling(bool opaque, 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, bool ignoreScaling) : RenderingElement(opaque, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
}
RenderingElementScaling::RenderingElementScaling(bool opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, 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, bool ignoreScaling) : bufferWidth(bufferWidth), bufferHeight(bufferHeight), buffer(bufferWidth*bufferHeight), RenderingElement(opaque, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
}
void RenderingElementPreScaled::UpdatePosition(Window& window) {
std::uint_fast32_t oldWidth = scaled.width;
std::uint_fast32_t oldHeight = scaled.height;
window.ScaleElement(*this);
if(oldWidth != scaled.width || oldHeight && scaled.height) {
bufferScaled.resize(scaled.width * scaled.height);
}
for(Transform* child : children) {
child->UpdatePosition(window, *this);
}
}
void RenderingElementPreScaled::UpdatePosition(Window& window, Transform& parent) {
std::uint_fast32_t oldWidth = scaled.width;
std::uint_fast32_t oldHeight = scaled.height;
window.ScaleElement(*this, parent);
if(oldWidth != scaled.width || oldHeight && scaled.height) {
bufferScaled.resize(scaled.width * scaled.height);
}
for(Transform* child : children) {
child->UpdatePosition(window, *this);
}
}
void RenderingElementPreScaled::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
for (std::uint_fast32_t y = 0; y < dstHeight; y++) {
std::uint_fast32_t srcY = y * scaled.height / dstHeight;
for (std::uint_fast32_t x = 0; x < dstWidth; x++) {
std::uint_fast32_t srcX = x * scaled.width / dstWidth;
dst[y * dstWidth + x] = bufferScaled[srcY * scaled.width + srcX];
}
}
}
void RenderingElementScaling::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
for (std::uint_fast32_t y = 0; y < dstHeight; y++) {
std::uint_fast32_t srcY = y * bufferHeight / dstHeight;
for (std::uint_fast32_t x = 0; x < dstWidth; x++) {
@ -56,7 +102,7 @@ void RenderingElement::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uin
}
}
void RenderingElement::UpdatePosition(Window& window) {
void RenderingElementScaling::UpdatePosition(Window& window) {
std::uint_fast32_t oldWidth = scaled.width;
std::uint_fast32_t oldHeight = scaled.height;
window.ScaleElement(*this);
@ -69,7 +115,7 @@ void RenderingElement::UpdatePosition(Window& window) {
}
}
void RenderingElement::UpdatePosition(Window& window, Transform& parent) {
void RenderingElementScaling::UpdatePosition(Window& window, Transform& parent) {
std::uint_fast32_t oldWidth = scaled.width;
std::uint_fast32_t oldHeight = scaled.height;
window.ScaleElement(*this, parent);
@ -77,9 +123,13 @@ void RenderingElement::UpdatePosition(Window& window, Transform& parent) {
bufferScaled.resize(scaled.width * scaled.height);
CopyNearestNeighbour(bufferScaled.data(), scaled.width, scaled.height);
}
bufferScaled.resize(scaled.width * scaled.height);
CopyNearestNeighbour(bufferScaled.data(), scaled.width, scaled.height);
for(Transform* child : children) {
child->UpdatePosition(window, *this);
}
}
}
void RenderingElementScaling::ResizeBuffer(std::uint_fast32_t width, std::uint_fast32_t height) {
this->bufferWidth = width;
this->bufferHeight = height;
buffer.resize(width * height);
}