Compare commits

..

No commits in common. "e8f7d6e4a2218a9d57b4ebd297a03e1d712fc710" and "c9fadb377935359a233fc127b329cb8250e0fee9" have entirely different histories.

6 changed files with 33 additions and 34 deletions

View file

@ -7,14 +7,14 @@ int main() {
WindowWayland window(200, 200, "Hello Input!"); WindowWayland window(200, 200, "Hello Input!");
RenderingElementScalingRotating2D element( 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, //bufferWidth: the width of this elements pixel buffer
1, //bufferHeight: the height of this elements pixel buffer 1, //bufferHeight: the height of this elements pixel buffer
FractionalToMappedBoundlessU(0.125), 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), //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), //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.1), //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), //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), //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) 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 0, //z: this elements Z position
@ -25,13 +25,9 @@ int main() {
element.buffer = {{255, 0, 0 ,255}}; element.buffer = {{255, 0, 0 ,255}};
element.UpdatePosition(window); element.UpdatePosition(window);
EventListener<FrameTime> 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(); window.StartSync();
} }

View file

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

View file

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

View file

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

View file

@ -81,7 +81,7 @@ export namespace Crafter {
RenderingElementScalingRotating2D(OpaqueType opaque = OpaqueType::Transparent); 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::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(RenderingElementScalingRotating2D&) = delete;
RenderingElementScalingRotating2D& operator=(RenderingElementScalingRotating2D&) = delete; RenderingElementScalingRotating2D& operator=(RenderingElementScalingRotating2D&) = delete;