Files
emulatedisplay/low_level_render.h

67 lines
3.0 KiB
C++

// class that handles low-level rendering operations, such as drawing pixels and shapes to the display.
// This class is framework-agnostic and focuses solely on manipulating a 1-bit per pixel buffer.
// Constructor Args:
// uint8_t* buffer: Pointer to the bit buffer
// int width: Display width in pixels
// int height: Display height in pixels
#ifndef LOW_LEVEL_RENDER_H
#define LOW_LEVEL_RENDER_H
#include <cstdint>
#include <string>
#include <vector>
// Font extern declarations
extern const unsigned char font_5x5[96][6];
extern const unsigned char font_7linedigital[96][6];
extern const unsigned char font_BMplain[96][6];
extern const unsigned char font_Blokus[96][6];
extern const unsigned char font_HISKYF21[96][6];
extern const unsigned char font_Minimum[96][6];
extern const unsigned char font_SUPERDIG[96][6];
extern const unsigned char font_acme_5_outlines[96][6];
extern const unsigned char font_aztech[96][6];
extern const unsigned char font_crackers[96][6];
extern const unsigned char font_haiku[96][6];
extern const unsigned char font_sloth[96][6];
extern const unsigned char font_zxpix[96][6];
class LowLevelRenderer {
private:
uint8_t* bit_buffer;
int V_WIDTH;
int V_HEIGHT;
const unsigned char (*current_font)[96][6];
void draw_corner_arc(int center_x, int center_y, int radius, int quadrant, bool on);
void fill_bottom_flat_triangle(int x1, int y1, int x2, int y2, int x3, int y3, bool on);
void fill_top_flat_triangle(int x1, int y1, int x2, int y2, int x3, int y3, bool on);
public:
LowLevelRenderer(uint8_t* buffer, int width, int height);
// Font management
void set_font(const unsigned char (*font)[96][6]);
// --- 1-BIT DRAWING PRIMITIVES ---
void set_pixel(int x, int y, bool on);
void draw_line(int x0, int y0, int x1, int y1, bool on);
void draw_rectangle(int x, int y, int width, int height, bool on);
void draw_filled_rectangle(int x, int y, int width, int height, bool on);
void draw_rounded_rectangle(int x, int y, int width, int height, int radius, bool on);
void draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, bool on);
void draw_filled_triangle(int x1, int y1, int x2, int y2, int x3, int y3, bool on);
void draw_ellipse(int center_x, int center_y, int radius_x, int radius_y, bool on);
void draw_filled_ellipse(int center_x, int center_y, int radius_x, int radius_y, bool on);
void draw_polygon(const std::vector<std::pair<int, int>>& points, bool on);
void draw_filled_polygon(const std::vector<std::pair<int, int>>& points, bool on);
void draw_arc(int center_x, int center_y, int radius, int start_angle, int end_angle, bool on);
void draw_circle(int x, int y, int radius, bool on);
void draw_filled_circle(int x, int y, int radius, bool on);
void draw_char_vcol(int x, int y, char c);
void draw_string(int x, int y, const std::string &text, int spacing = 1);
void draw_char_scaled(int x, int y, char c, int scale);
void draw_string_scaled(int x, int y, const char* text, int scale, int spacing = 1);
};
#endif // LOW_LEVEL_RENDER_H