bresenham-0.rs/src/painter.hpp

45 lines
1.0 KiB
C++

#pragma once
#include "frame.hpp"
class PainterState {
public:
float angle = 0;
struct {
unsigned short x = -1, y = -1;
} clicked_pixel;
PainterState() = default;
void set_clicked_pixel(unsigned short x, unsigned short y) {
this->clicked_pixel.x = x;
this->clicked_pixel.y = y;
}
};
class Painter {
public:
virtual void draw(PainterState *state, Frame *frame) const = 0;
};
extern Painter const *const predefined_painters[];
class PixelGridPainter : public Painter {
private:
const COLOR c1;
const COLOR c2;
public:
inline PixelGridPainter(COLOR c1, COLOR c2) : c1{c1}, c2{c2} {}
inline void draw(PainterState *state, Frame *frame) const override {
for (int y = 0; y < frame->height; y++) {
for (int x = 0; x < frame->width; x++) {
if ((x + y) % 2 == 0)
frame->set_pixel(x, y, this->c1);
else
frame->set_pixel(x, y, this->c2);
}
}
}
};