fixes
This commit is contained in:
parent
3d40256bde
commit
8489c57d40
8 changed files with 135 additions and 14 deletions
|
|
@ -24,16 +24,10 @@ export module Crafter.Graphics:RenderingElement;
|
|||
import std;
|
||||
import :Transform;
|
||||
import :Types;
|
||||
import :Image;
|
||||
import :Window;
|
||||
|
||||
export namespace Crafter {
|
||||
enum class OpaqueType {
|
||||
FullyOpaque, // All pixels have A of 255
|
||||
SemiOpaque, // All pixels have A of 0 or 255 (no blending needed)
|
||||
Transparent // Color blending is used
|
||||
};
|
||||
|
||||
|
||||
struct RenderElementScalingOwning {
|
||||
std::vector<Pixel_BU8_GU8_RU8_AU8> scalingBuffer;
|
||||
std::uint_fast32_t bufferWidth;
|
||||
|
|
@ -91,6 +85,9 @@ export namespace Crafter {
|
|||
public:
|
||||
std::vector<Pixel_BU8_GU8_RU8_AU8> buffer;
|
||||
OpaqueType opaque;
|
||||
RenderingElementBase(Anchor anchor) : Transform(anchor) {
|
||||
scaled.width = 0;
|
||||
}
|
||||
RenderingElementBase(Anchor anchor, OpaqueType opaque) : Transform(anchor), opaque(opaque) {
|
||||
scaled.width = 0;
|
||||
}
|
||||
|
|
@ -107,10 +104,10 @@ export namespace Crafter {
|
|||
|
||||
}
|
||||
|
||||
RenderingElement(Anchor anchor, const std::string_view imagePath) : Transform(anchor) {
|
||||
RenderingElement(Anchor anchor, const std::string_view imagePath) : RenderingElementBase(anchor) {
|
||||
LoadImage(imagePath);
|
||||
}
|
||||
RenderingElement(Anchor anchor, const std::string_view imagePath, std::uint_fast32_t rotation) requires(Rotating) : Transform(anchor), RotatingBase<Rotating>(rotation) {
|
||||
RenderingElement(Anchor anchor, const std::string_view imagePath, std::uint_fast32_t rotation) requires(Rotating) : RenderingElementBase(anchor), RotatingBase<Rotating>(rotation) {
|
||||
LoadImage(imagePath);
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +125,20 @@ export namespace Crafter {
|
|||
|
||||
}
|
||||
|
||||
RenderingElement(Anchor anchor, OpaqueType opaque, Image& image) requires(Scaling && !Owning) : RenderingElementBase(anchor, opaque), ScalingBase<Scaling, Owning>(image.buffer.data(), image.width, image.height) {
|
||||
|
||||
}
|
||||
RenderingElement(Anchor anchor, OpaqueType opaque, Image& image, std::uint_fast32_t rotation) requires(Scaling && !Owning && Rotating) : RenderingElementBase(anchor, opaque), ScalingBase<Scaling, Owning>(image.buffer.data(), image.width, image.height), RotatingBase<Rotating>(rotation) {
|
||||
|
||||
}
|
||||
|
||||
RenderingElement(Anchor anchor, Image& image) requires(Scaling && !Owning) : RenderingElementBase(anchor, image.opaque), ScalingBase<Scaling, Owning>(image.buffer.data(), image.width, image.height) {
|
||||
|
||||
}
|
||||
RenderingElement(Anchor anchor, Image& image, std::uint_fast32_t rotation) requires(Scaling && !Owning && Rotating) : RenderingElementBase(anchor, image.opaque), ScalingBase<Scaling, Owning>(image.buffer.data(), image.width, image.height), RotatingBase<Rotating>(rotation) {
|
||||
|
||||
}
|
||||
|
||||
RenderingElement(Anchor anchor, OpaqueType opaque, std::uint_fast32_t bufferWidth, std::uint_fast32_t bufferHeight) requires(Owning) : RenderingElementBase(anchor, opaque), ScalingBase<Scaling, Owning>(bufferWidth, bufferHeight) {
|
||||
|
||||
}
|
||||
|
|
@ -169,8 +180,8 @@ export namespace Crafter {
|
|||
scaled.x -= diffX;
|
||||
scaled.y -= diffY;
|
||||
|
||||
ScalingBase<true, Owning>::scalingBuffer.clear();
|
||||
ScalingBase<true, Owning>::scalingBuffer.resize(scaled.width * scaled.height);
|
||||
buffer.clear();
|
||||
buffer.resize(scaled.width * scaled.height);
|
||||
|
||||
// Destination center
|
||||
const double dstCx = (static_cast<double>(scaled.width) - 1.0) * 0.5;
|
||||
|
|
@ -289,6 +300,7 @@ export namespace Crafter {
|
|||
ScalingBase<true, true>::bufferWidth = xSize;
|
||||
ScalingBase<true, true>::bufferHeight = ySize;
|
||||
ScalingBase<true, true>::bufferUpdated = true;
|
||||
ScalingBase<true, Owning>::scalingBuffer.resize(xSize*ySize);
|
||||
} else {
|
||||
buffer.resize(xSize*ySize);
|
||||
}
|
||||
|
|
@ -302,7 +314,7 @@ export namespace Crafter {
|
|||
ScalingBase<true, Owning>::scalingBuffer[x*ySize+y].r = bgData[idx];
|
||||
ScalingBase<true, Owning>::scalingBuffer[x*ySize+y].g = bgData[idx+1];
|
||||
ScalingBase<true, Owning>::scalingBuffer[x*ySize+y].b = bgData[idx+2];
|
||||
ScalingBase<true, Owning>::calingBuffer[x*ySize+y].a = bgData[idx+3];
|
||||
ScalingBase<true, Owning>::scalingBuffer[x*ySize+y].a = bgData[idx+3];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -356,6 +368,7 @@ export namespace Crafter {
|
|||
ScalingBase<true, true>::bufferWidth = xSize;
|
||||
ScalingBase<true, true>::bufferHeight = ySize;
|
||||
ScalingBase<true, true>::bufferUpdated = true;
|
||||
ScalingBase<true, Owning>::scalingBuffer.resize(xSize*ySize);
|
||||
} else {
|
||||
buffer.resize(xSize*ySize);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue