add more low level drawing functions

This commit is contained in:
Adolfo Reyna
2026-01-13 10:55:21 -05:00
parent 55475d10ec
commit 5e0fe7c6d9
4 changed files with 77 additions and 2 deletions

View File

@@ -17,16 +17,64 @@
#include "./fonts/zxpix_font.h"
LowLevelRenderer::LowLevelRenderer(uint8_t* buffer, int width, int height)
: bit_buffer(buffer), V_WIDTH(width), V_HEIGHT(height), current_font(&font_acme_5_outlines) {}
: bit_buffer(buffer), V_WIDTH(width), V_HEIGHT(height), current_font(&font_acme_5_outlines),
clipping_enabled(false), clip_x(0), clip_y(0), clip_width(width), clip_height(height) {}
void LowLevelRenderer::set_font(const unsigned char (*font)[96][6]) {
current_font = font;
}
// Clipping functions
void LowLevelRenderer::set_clip_rect(int x, int y, int width, int height) {
clip_x = x;
clip_y = y;
clip_width = width;
clip_height = height;
clipping_enabled = true;
}
void LowLevelRenderer::reset_clip_rect() {
clipping_enabled = false;
clip_x = 0;
clip_y = 0;
clip_width = V_WIDTH;
clip_height = V_HEIGHT;
}
bool LowLevelRenderer::is_clipping_enabled() const {
return clipping_enabled;
}
bool LowLevelRenderer::is_point_in_clip_rect(int x, int y) {
if (!clipping_enabled) return true;
return (x >= clip_x && x < clip_x + clip_width &&
y >= clip_y && y < clip_y + clip_height);
}
// Buffer operations
void LowLevelRenderer::invert_buffer() {
int buffer_size = (V_WIDTH * V_HEIGHT + 7) / 8; // Round up for bit buffer size
for (int i = 0; i < buffer_size; ++i) {
bit_buffer[i] = ~bit_buffer[i]; // Bitwise NOT to invert all bits
}
}
void LowLevelRenderer::clear_buffer() {
int buffer_size = (V_WIDTH * V_HEIGHT + 7) / 8;
for (int i = 0; i < buffer_size; ++i) {
bit_buffer[i] = 0;
}
}
void LowLevelRenderer::set_pixel(int x, int y, bool on)
{
if (x < 0 || x >= V_WIDTH || y < 0 || y >= V_HEIGHT)
return;
// Check clipping
if (!is_point_in_clip_rect(x, y))
return;
int bit_pos = y * V_WIDTH + x;
if (on)
bit_buffer[bit_pos / 8] |= (1 << (7 - (bit_pos % 8)));