mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
//
|
|
// Created by Stepan Usatiuk on 27.07.2025.
|
|
//
|
|
|
|
#ifndef SUBSURFACE_HPP
|
|
#define SUBSURFACE_HPP
|
|
|
|
#include <memory>
|
|
#include <type_traits>
|
|
|
|
#include "Pixel.hpp"
|
|
#include "StandardEvents.hpp"
|
|
#include "Surface.hpp"
|
|
#include "Window.hpp"
|
|
#include "utils.hpp"
|
|
|
|
template<typename SurfaceParent, typename PixelType>
|
|
requires std::is_base_of_v<Pixel, PixelType>
|
|
class SubSurface : public Surface<SubSurface<SurfaceParent, PixelType>, PixelType> {
|
|
public:
|
|
SubSurface(SurfaceParent* parent) : _parent(parent) {}
|
|
|
|
void draw_pixel_impl(unsigned x, unsigned y, const PixelType& pixel) {
|
|
if (x >= _x_size || y >= _y_size) {
|
|
return; // Out of bounds
|
|
}
|
|
|
|
_parent->draw_pixel(x + _x_offset, y + _y_offset, pixel);
|
|
}
|
|
|
|
void clear_impl() {
|
|
for (unsigned y = 0; y < _y_size; y++) {
|
|
for (unsigned x = 0; x < _x_size; x++) {
|
|
_parent->draw_pixel(x + _x_offset, y + _y_offset, PixelType());
|
|
}
|
|
}
|
|
}
|
|
|
|
unsigned get_width_impl() const { return _x_size; }
|
|
|
|
unsigned get_height_impl() const { return _y_size; }
|
|
|
|
void set_pos(unsigned x_offset, unsigned y_offset, unsigned x_size, unsigned y_size) {
|
|
_x_offset = x_offset;
|
|
_y_offset = y_offset;
|
|
_x_size = x_size;
|
|
_y_size = y_size;
|
|
this->handle(SurfaceResizeEvent(x_size, y_size));
|
|
}
|
|
|
|
private:
|
|
unsigned _x_offset = 0;
|
|
unsigned _y_offset = 0;
|
|
unsigned _x_size = 0;
|
|
unsigned _y_size = 0;
|
|
|
|
SurfaceParent* _parent;
|
|
};
|
|
|
|
#endif // SUBSURFACE_HPP
|