mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
//
|
|
// Created by Stepan Usatiuk on 26.07.2025.
|
|
//
|
|
|
|
#ifndef SURFACE_HPP
|
|
#define SURFACE_HPP
|
|
|
|
#include <cassert>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
|
|
#include "Pixel.hpp"
|
|
#include "StandardEvents.hpp"
|
|
#include "Window.hpp"
|
|
#include "backend_interface.hpp"
|
|
#include "utils.hpp"
|
|
|
|
class SubSurface;
|
|
|
|
class Surface : public StandardEventHandler<Surface>, public SdkPort::SurfaceBase {
|
|
public:
|
|
Surface();
|
|
~Surface();
|
|
|
|
void draw_rect(unsigned x, unsigned y, unsigned width, unsigned height, const Pixel& pixel) {
|
|
for (unsigned i = 0; i < width; ++i) {
|
|
draw_pixel(x + i, y, pixel);
|
|
draw_pixel(x + i, y + height - 1, pixel);
|
|
}
|
|
for (unsigned i = 0; i < height; ++i) {
|
|
draw_pixel(x, y + i, pixel);
|
|
draw_pixel(x + width - 1, y + i, pixel);
|
|
}
|
|
}
|
|
|
|
void clear() {
|
|
for (unsigned x = 0; x < get_width(); x++) {
|
|
for (unsigned y = 0; y < get_height(); y++) {
|
|
draw_pixel(x, y, Pixel());
|
|
}
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
EventHandlingResult handle(const T& event);
|
|
SubSurface& get_subsurface();
|
|
|
|
protected:
|
|
SubSurface* _subsurface = nullptr;
|
|
};
|
|
|
|
#endif // SURFACE_HPP
|