rotation clip fix
This commit is contained in:
parent
629841e2ce
commit
e8f7d6e4a2
6 changed files with 23 additions and 74 deletions
|
|
@ -1,33 +0,0 @@
|
|||
import Crafter.Event;
|
||||
import Crafter.Graphics;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
WindowWayland window(200, 200, "Hello Input!");
|
||||
|
||||
RenderingElementScalingRotating2D element(
|
||||
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.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
|
||||
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
|
||||
);
|
||||
|
||||
window.elements.push_back(&element);
|
||||
element.buffer = {{255, 0, 0 ,255}};
|
||||
element.UpdatePosition(window);
|
||||
|
||||
|
||||
|
||||
//window.StartUpdate();
|
||||
window.Render();
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"name": "crafter-graphics",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-wayland-timing"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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, 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(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(RenderingElementScalingRotating2D&) = delete;
|
||||
RenderingElementScalingRotating2D& operator=(RenderingElementScalingRotating2D&) = delete;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue