2026-03-10 22:32:50 +01:00
|
|
|
/*
|
|
|
|
|
Crafter®.Graphics
|
|
|
|
|
Copyright (C) 2026 Catcrafts®
|
|
|
|
|
catcrafts.net
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License version 3.0 as published by the Free Software Foundation;
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export module Crafter.Graphics:RenderingElement2DBase;
|
|
|
|
|
import Crafter.Asset;
|
|
|
|
|
import Crafter.Math;
|
|
|
|
|
import std;
|
|
|
|
|
import :Transform2D;
|
|
|
|
|
|
|
|
|
|
export namespace Crafter {
|
|
|
|
|
enum class TextAlignment {
|
|
|
|
|
Left,
|
|
|
|
|
Center,
|
|
|
|
|
Right
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class TextOverflowMode {
|
|
|
|
|
Clip,
|
|
|
|
|
Wrap
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class TextScaleMode {
|
|
|
|
|
None,
|
|
|
|
|
Font,
|
|
|
|
|
Element,
|
|
|
|
|
Buffer
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-12 01:07:46 +01:00
|
|
|
template<std::uint8_t Alignment = 0>
|
2026-03-10 22:32:50 +01:00
|
|
|
struct RenderElement2DScalingOwning {
|
2026-03-12 01:07:46 +01:00
|
|
|
std::vector<Vector<std::uint8_t, 4, Alignment>> scalingBuffer;
|
2026-03-10 22:32:50 +01:00
|
|
|
std::uint32_t bufferWidth;
|
|
|
|
|
std::uint32_t bufferHeight;
|
|
|
|
|
RenderElement2DScalingOwning() = default;
|
|
|
|
|
RenderElement2DScalingOwning(std::uint32_t bufferWidth, std::uint32_t bufferHeight) : scalingBuffer(bufferWidth*bufferHeight), bufferWidth(bufferWidth), bufferHeight(bufferHeight) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-12 01:07:46 +01:00
|
|
|
template<std::uint8_t Alignment = 0>
|
2026-03-10 22:32:50 +01:00
|
|
|
struct RenderElement2DScalingNonOwning {
|
2026-03-12 01:07:46 +01:00
|
|
|
Vector<std::uint8_t, 4, Alignment>* scalingBuffer;
|
2026-03-10 22:32:50 +01:00
|
|
|
std::uint32_t bufferWidth;
|
|
|
|
|
std::uint32_t bufferHeight;
|
|
|
|
|
RenderElement2DScalingNonOwning() = default;
|
2026-03-12 01:07:46 +01:00
|
|
|
RenderElement2DScalingNonOwning(Vector<std::uint8_t, 4, Alignment>* scalingBuffer, std::uint32_t bufferWidth, std::uint32_t bufferHeight) : scalingBuffer(scalingBuffer), bufferWidth(bufferWidth), bufferHeight(bufferHeight) {
|
2026-03-10 22:32:50 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct RenderElement2DRotating {
|
|
|
|
|
float rotation;
|
|
|
|
|
RenderElement2DRotating() = default;
|
|
|
|
|
RenderElement2DRotating(float rotation) : rotation(rotation) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct EmptyScalingBase {};
|
|
|
|
|
struct EmptyRotatingBase {};
|
|
|
|
|
|
2026-03-12 01:07:46 +01:00
|
|
|
template<bool Scaling, bool Owning, std::uint8_t Alignment = 0>
|
2026-03-10 22:32:50 +01:00
|
|
|
using ScalingBase =
|
|
|
|
|
std::conditional_t<
|
|
|
|
|
Scaling,
|
|
|
|
|
std::conditional_t<Owning,
|
2026-03-12 01:07:46 +01:00
|
|
|
RenderElement2DScalingOwning<Alignment>,
|
|
|
|
|
RenderElement2DScalingNonOwning<Alignment>>,
|
2026-03-10 22:32:50 +01:00
|
|
|
EmptyScalingBase
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
template<bool Rotating>
|
|
|
|
|
using RotatingBase =
|
|
|
|
|
std::conditional_t<
|
|
|
|
|
Rotating,
|
|
|
|
|
RenderElement2DRotating,
|
|
|
|
|
EmptyRotatingBase
|
|
|
|
|
>;
|
|
|
|
|
|
2026-03-12 21:13:53 +01:00
|
|
|
template<std::uint8_t Frames = 1>
|
2026-03-10 22:32:50 +01:00
|
|
|
struct RenderingElement2DBase : Transform2D {
|
2026-03-12 21:13:53 +01:00
|
|
|
ScaleData2D oldScale[Frames];
|
2026-03-10 22:32:50 +01:00
|
|
|
std::vector<Vector<std::uint8_t, 4>> buffer;
|
|
|
|
|
OpaqueType opaque;
|
|
|
|
|
RenderingElement2DBase(Anchor2D anchor) : Transform2D(anchor) {
|
2026-03-12 21:13:53 +01:00
|
|
|
for(std::uint8_t i = 0; i < Frames; i++) {
|
|
|
|
|
this->scaled[i].size.x = 0;
|
|
|
|
|
}
|
2026-03-10 22:32:50 +01:00
|
|
|
}
|
|
|
|
|
RenderingElement2DBase(Anchor2D anchor, OpaqueType opaque) : Transform2D(anchor), opaque(opaque) {
|
2026-03-12 21:13:53 +01:00
|
|
|
for(std::uint8_t i = 0; i < Frames; i++) {
|
|
|
|
|
this->scaled[i].size.x = 0;
|
|
|
|
|
}
|
2026-03-10 22:32:50 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|