38 lines
1.6 KiB
C++
38 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <limits>
|
|
#include <bgtu/computer_graphics_lab_work/renderer_api/color.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/renderer_api/point.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/renderer_api/sprite.hpp>
|
|
#include <bgtu/computer_graphics_lab_work/utilities/shapes/rectangle.hpp>
|
|
#include "variants/sprite_data.hpp"
|
|
|
|
|
|
namespace BGTU::ComputerGraphicsLabWork::Impl {
|
|
class PixelGridSprite : public RendererApi::Sprite<SpriteData, Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl> {
|
|
private:
|
|
RendererApi::Color bg, fg;
|
|
public:
|
|
PixelGridSprite(RendererApi::Color bg, RendererApi::Color fg) : bg{bg}, fg{fg} {};
|
|
|
|
void draw(Utilities::DefaultVoxelDrawerCache::VoxelPainterImpl *frame, const SpriteData *data) const override {
|
|
if (!data->show_grid)
|
|
return;
|
|
|
|
long long start_x = data->central_pixel_tl.x - ((data->central_pixel_tl.x + data->pixel_size - 1) / data->pixel_size * data->pixel_size);
|
|
long long start_y = data->central_pixel_tl.y - ((data->central_pixel_tl.y + data->pixel_size - 1) / data->pixel_size * data->pixel_size);
|
|
long long w = frame->width();
|
|
long long h = frame->height();
|
|
bool y_flag = ((data->central_pixel_tl.x - start_x) / data->pixel_size + (data->central_pixel_tl.y - start_y) / data->pixel_size) % 2 == 0;
|
|
bool x_flag;
|
|
for (long long y = start_y; y < h; y += data->pixel_size, y_flag = !y_flag) {
|
|
x_flag = y_flag;
|
|
for (long long x = start_x; x < w; x += data->pixel_size, x_flag = !x_flag) {
|
|
auto c = x_flag ? this->bg : this->fg;
|
|
|
|
Utilities::Shapes::fill_square(frame, x, y, data->pixel_size, std::numeric_limits<double>::max(), c);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
} |