rewrite time

This commit is contained in:
Jorijn van der Graaf 2025-11-22 20:58:42 +01:00
commit 4428cfe12c
24 changed files with 1208 additions and 893 deletions

View file

@ -0,0 +1,54 @@
/*
Crafter®.Graphics
Copyright (C) 2025 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
*/
module Crafter.Graphics:UiElementBuffer_impl;
import :UiElementBuffer;
import :UiElement;
import :WindowFramebuffer;
import std;
namespace Crafter {
UiElementBuffer::UiElementBuffer(UiElementBase& parent, std::uint_fast32_t width, std::uint_fast32_t height) : parent(parent), width(width), height(height) {
}
void UiElementBuffer::DrawNearestNeighbour(Pixel_BU8_GU8_RU8_AU8* dst, std::uint_fast32_t dstWidth, std::uint_fast32_t dstHeight) const {
for (std::uint_fast32_t y = 0; y < dstHeight; y++) {
std::uint_fast32_t srcY = y * height / dstHeight;
for (std::uint_fast32_t x = 0; x < dstWidth; x++) {
std::uint_fast32_t srcX = x * width / dstWidth;
dst[y * dstWidth + x] = buffer[srcY * width + srcX];
}
}
}
ScaleData UiElementBuffer::ScaleElement(const UiElementBase& element, ScaleData own, WindowFramebuffer& window) const {
ScaleData data;
if(element.ignoreScaling) {
data.width = element.relativeWidth*own.width;
data.height = element.relativeHeight*own.height;
} else {
data.width = element.relativeWidth*own.width*window.scale;
data.height = element.relativeHeight*own.height*window.scale;
}
data.x = ((element.anchorX*own.width)-(element.anchorOffsetX*data.width))+own.x;
data.y = ((element.anchorY*own.height)-(element.anchorOffsetY*data.height))+own.y;
return data;
}
}