diff --git a/examples/HelloRotation/main.cpp b/examples/HelloAnimationcopy/main.cpp similarity index 73% rename from examples/HelloRotation/main.cpp rename to examples/HelloAnimationcopy/main.cpp index 4279614..5e2c167 100644 --- a/examples/HelloRotation/main.cpp +++ b/examples/HelloAnimationcopy/main.cpp @@ -7,14 +7,14 @@ int main() { WindowWayland window(200, 200, "Hello Input!"); RenderingElementScalingRotating2D element( - OpaqueType::SemiOpaque, //opaque, wether the element is opague or semi-transparant + OpaqueType::FullyOpaque, //opaque, wether the element is opague or semi-transparant 1, //bufferWidth: the width of this elements pixel buffer 1, //bufferHeight: the height of this elements pixel buffer FractionalToMappedBoundlessU(0.125), FractionalToMapped(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor FractionalToMapped(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor - FractionalToMapped(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent - FractionalToMapped(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent + FractionalToMapped(0.1), //relativeSizeX: the relative x size this element should be scaled to compared to its parent + FractionalToMapped(0.1), //relativeSizeY: the relative y size this element should be scaled to compared to its parent FractionalToMapped(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle) FractionalToMapped(0.5), //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle) 0, //z: this elements Z position @@ -24,14 +24,10 @@ int main() { window.elements.push_back(&element); element.buffer = {{255, 0, 0 ,255}}; element.UpdatePosition(window); + - EventListener updateListener(&window.onUpdate, [&](FrameTime time){ - element.rotation += 50000000000000000; - std::cout << element.rotation << std::endl; - element.UpdatePosition(window); - window.LogTiming(); - }); - - window.StartUpdate(); + + //window.StartUpdate(); + window.Render(); window.StartSync(); } diff --git a/examples/HelloRotation/project.json b/examples/HelloAnimationcopy/project.json similarity index 100% rename from examples/HelloRotation/project.json rename to examples/HelloAnimationcopy/project.json diff --git a/implementations/Crafter.Graphics-RenderingElement.cpp b/implementations/Crafter.Graphics-RenderingElement.cpp index ab25706..4e70351 100644 --- a/implementations/Crafter.Graphics-RenderingElement.cpp +++ b/implementations/Crafter.Graphics-RenderingElement.cpp @@ -116,9 +116,7 @@ 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) { diff --git a/implementations/Crafter.Graphics-RenderingElementScalingRotating2D.cpp b/implementations/Crafter.Graphics-RenderingElementScalingRotating2D.cpp index c807b6b..4f996be 100644 --- a/implementations/Crafter.Graphics-RenderingElementScalingRotating2D.cpp +++ b/implementations/Crafter.Graphics-RenderingElementScalingRotating2D.cpp @@ -35,10 +35,11 @@ RenderingElementScalingRotating2D::RenderingElementScalingRotating2D(OpaqueType } -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) +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) : 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) { @@ -56,22 +57,15 @@ void RenderingElementScalingRotating2D::UpdateScaledBuffer(ScaleData& scaled) { // Rotation const double rad = (static_cast(rotation) / static_cast(std::numeric_limits::max())) * 2.0 * std::numbers::pi; - const std::uint_fast32_t dstWidth = scaled.width; - const std::uint_fast32_t dstHeight = scaled.height; + std::uint_fast32_t dstWidth = scaled.width; + 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))); - 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 = static_cast(std::ceil(rotatedWidth)); + scaled.height = static_cast(std::ceil(rotatedHeight)); - scaled.width += diffX + diffX; - scaled.height += diffY + diffY; - - scaled.x -= diffX; - scaled.y -= diffY; - - bufferScaled.clear(); bufferScaled.resize(scaled.width * scaled.height); // Destination center @@ -93,12 +87,20 @@ void RenderingElementScalingRotating2D::UpdateScaledBuffer(ScaleData& scaled) { for (std::uint_fast32_t xB = 0; xB < scaled.width; ++xB) { // ---- Destination pixel relative to center ---- - const double dx = (static_cast(xB) - dstCx) * scaleX; - const double dy = (static_cast(yB) - dstCy) * scaleY; + double dx = static_cast(xB) - dstCx; + double dy = static_cast(yB) - dstCy; + + // ---- Inverse scale ---- + dx *= scaleX; + dy *= scaleY; // ---- Inverse rotation ---- - const double sx = (c * dx - s * dy) + srcCx; - const double sy = (s * dx + c * dy) + srcCy; + double sx = c * dx - s * dy; + double sy = s * dx + c * dy; + + // ---- Move into source space ---- + sx += srcCx; + sy += srcCy; // ---- Nearest neighbour sampling ---- const std::int_fast32_t srcX = static_cast(std::round(sx)); @@ -106,6 +108,8 @@ 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}; } } } @@ -124,6 +128,7 @@ 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) { diff --git a/implementations/Crafter.Graphics-Window_wayland.cpp b/implementations/Crafter.Graphics-Window_wayland.cpp index 88e59fd..9c06fcd 100644 --- a/implementations/Crafter.Graphics-Window_wayland.cpp +++ b/implementations/Crafter.Graphics-Window_wayland.cpp @@ -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) { diff --git a/interfaces/Crafter.Graphics-RenderingElement.cppm b/interfaces/Crafter.Graphics-RenderingElement.cppm index 10b30ed..66a5672 100644 --- a/interfaces/Crafter.Graphics-RenderingElement.cppm +++ b/interfaces/Crafter.Graphics-RenderingElement.cppm @@ -81,7 +81,7 @@ export namespace Crafter { RenderingElementScalingRotating2D(OpaqueType opaque = OpaqueType::Transparent); RenderingElementScalingRotating2D(OpaqueType 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); - RenderingElementScalingRotating2D(OpaqueType opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::uint_fast32_t rotationAngle = 0, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false); + RenderingElementScalingRotating2D(OpaqueType opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight, std::uint_fast32_t rotationAngle = 0, double scaleX = 1.0, double scaleY = 1.0, std::int_fast32_t anchorX = FractionalToMapped(0.5), std::int_fast32_t anchorY = FractionalToMapped(0.5), std::uint_fast32_t relativeWidth = FractionalToMapped(1), std::uint_fast32_t relativeHeight = FractionalToMapped(1), std::int_fast32_t anchorOffsetX = FractionalToMapped(0.5), std::int_fast32_t anchorOffsetY = FractionalToMapped(0.5), std::int_fast32_t z = 0, bool ignoreScaling = false); RenderingElementScalingRotating2D(RenderingElementScalingRotating2D&) = delete; RenderingElementScalingRotating2D& operator=(RenderingElementScalingRotating2D&) = delete;