feat: canvas from texture atlas element

This commit is contained in:
MihailRis
2025-11-05 00:20:58 +03:00
parent 497160a5b9
commit d9f2d54bf0
10 changed files with 126 additions and 28 deletions
+11
View File
@@ -95,6 +95,17 @@ void ImageData::blit(const ImageData& image, int x, int y) {
throw std::runtime_error("mismatching format");
}
std::unique_ptr<ImageData> ImageData::cropped(int x, int y, int width, int height) const {
width = std::min<int>(width, this->width - x);
height = std::min<int>(height, this->height - y);
if (width <= 0 || height <= 0) {
throw std::runtime_error("invalid crop dimensions");
}
auto subImage = std::make_unique<ImageData>(format, width, height);
subImage->blitMatchingFormat(*this, -x, -y);
return subImage;
}
static bool clip_line(int& x1, int& y1, int& x2, int& y2, int width, int height) {
const int left = 0;
const int right = width;