rotation clip fix

This commit is contained in:
Jorijn van der Graaf 2025-12-21 20:26:20 +01:00
commit e8f7d6e4a2
6 changed files with 23 additions and 74 deletions

View file

@ -116,7 +116,9 @@ void RenderingElementScaling::CopyNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, s
void RenderingElementScaling::UpdatePosition(Window& window) {
ScaleData oldScale = scaled;
std::cout << MappedToFractional(relativeWidth) << std::endl;
window.ScaleElement(*this);
std::cout << scaled.width << std::endl;
if(oldScale.width != scaled.width || oldScale.height != scaled.height) {

View file

@ -35,11 +35,10 @@ RenderingElementScalingRotating2D::RenderingElementScalingRotating2D(OpaqueType
}
RenderingElementScalingRotating2D::RenderingElementScalingRotating2D(OpaqueType opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::uint_fast32_t rotation, double scaleX, double scaleY, 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)
RenderingElementScalingRotating2D::RenderingElementScalingRotating2D(OpaqueType opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::uint_fast32_t rotation, 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),
rotation(rotation),
RenderingElement(opaque, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling) {
}
void RenderingElementScalingRotating2D::ResizeBuffer(std::uint_fast32_t width, std::uint_fast32_t height) {
@ -57,15 +56,22 @@ void RenderingElementScalingRotating2D::UpdateScaledBuffer(ScaleData& scaled) {
// Rotation
const double rad = (static_cast<double>(rotation) / static_cast<double>(std::numeric_limits<std::uint_fast32_t>::max())) * 2.0 * std::numbers::pi;
std::uint_fast32_t dstWidth = scaled.width;
std::uint_fast32_t dstHeight = scaled.height;
const std::uint_fast32_t dstWidth = scaled.width;
const std::uint_fast32_t dstHeight = scaled.height;
const double rotatedWidth = scaled.width * (std::abs(std::cos(rad)) + std::abs(std::sin(rad)));
const double rotatedWidth = scaled.width * (std::abs(std::cos(rad)) + std::abs(std::sin(rad)));
const double rotatedHeight = scaled.height * (std::abs(std::cos(rad)) + std::abs(std::sin(rad)));
scaled.width = static_cast<std::uint_fast32_t>(std::ceil(rotatedWidth));
scaled.height = static_cast<std::uint_fast32_t>(std::ceil(rotatedHeight));
const std::uint_fast32_t diffX = std::ceil((rotatedWidth - scaled.width)/2);
const std::uint_fast32_t diffY = std::ceil((rotatedHeight - scaled.height)/2);
scaled.width += diffX + diffX;
scaled.height += diffY + diffY;
scaled.x -= diffX;
scaled.y -= diffY;
bufferScaled.clear();
bufferScaled.resize(scaled.width * scaled.height);
// Destination center
@ -87,20 +93,12 @@ void RenderingElementScalingRotating2D::UpdateScaledBuffer(ScaleData& scaled) {
for (std::uint_fast32_t xB = 0; xB < scaled.width; ++xB) {
// ---- Destination pixel relative to center ----
double dx = static_cast<double>(xB) - dstCx;
double dy = static_cast<double>(yB) - dstCy;
// ---- Inverse scale ----
dx *= scaleX;
dy *= scaleY;
const double dx = (static_cast<double>(xB) - dstCx) * scaleX;
const double dy = (static_cast<double>(yB) - dstCy) * scaleY;
// ---- Inverse rotation ----
double sx = c * dx - s * dy;
double sy = s * dx + c * dy;
// ---- Move into source space ----
sx += srcCx;
sy += srcCy;
const double sx = (c * dx - s * dy) + srcCx;
const double sy = (s * dx + c * dy) + srcCy;
// ---- Nearest neighbour sampling ----
const std::int_fast32_t srcX = static_cast<std::int_fast32_t>(std::round(sx));
@ -108,8 +106,6 @@ void RenderingElementScalingRotating2D::UpdateScaledBuffer(ScaleData& scaled) {
if (srcX >= 0 && srcX < bufferWidth && srcY >= 0 && srcY < bufferHeight) {
bufferScaled[yB * scaled.width + xB] = buffer[srcY * bufferWidth + srcX];
} else {
bufferScaled[yB * scaled.width + xB] = {0, 0, 0, 0};
}
}
}
@ -128,7 +124,6 @@ void RenderingElementScalingRotating2D::UpdatePosition(Window& window) {
UpdateScaledBuffer(scaled);
window.AddDirtyRect(oldScale);
window.AddDirtyRect(scaled);
std::cout << scaled.width << std::endl;
rotationUpdated = false;
} else if(oldScale.x != scaled.x || oldScale.y != scaled.y) {

View file

@ -302,9 +302,9 @@ void WindowWayland::Render() {
dirtyRects = std::move(newClip);
for(uint_fast32_t i = 0; i < width*height; i++) {
framebuffer[i] = {0, 0, 0, 255};
}
// for(uint_fast32_t i = 0; i < width*height; i++) {
// framebuffer[i] = {0, 0, 0, 255};
// }
// std::cout << dirtyRects.size() << std::endl;
// for (ClipRect rect : dirtyRects) {