Compare commits
2 Commits
87e06ae249
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8170799f01 | |||
| 3491de4650 |
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_7linedigital[96][6] = {
|
||||
const unsigned char font_7linedigital[96][4] = {
|
||||
{0x00,0x00,0x00,0x00}, //
|
||||
{0x36,0x00,0x00,0x00}, // !
|
||||
{0x06,0x00,0x00,0x06}, // "
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_BMSPA[96][6] = {
|
||||
const unsigned char font_BMSPA[96][8] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x00,0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_Commo-Monospaced[96][6] = {
|
||||
const unsigned char font_Commo_Monospaced[96][8] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x5f,0x5c,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x03,0x07,0x00,0x03,0x07,0x00,0x00,0x00}, // "
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_HUNTER[96][6] = {
|
||||
const unsigned char font_HUNTER[96][8] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x5f,0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x07,0x07,0x00,0x07,0x07,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_Minimum+1[96][6] = {
|
||||
const unsigned char font_Minimum_1[96][7] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x7f,0x51,0x7f,0x00,0x00,0x00,0x00}, // !
|
||||
{0x0f,0x09,0x0f,0x09,0x0f,0x00,0x00}, // "
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_Raumsond[96][6] = {
|
||||
const unsigned char font_Raumsond[96][5] = {
|
||||
{0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x5c,0x00,0x00,0x00,0x00}, // !
|
||||
{0x0c,0x00,0x0c,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_bubblesstandard[96][6] = {
|
||||
const unsigned char font_bubblesstandard[96][7] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0xbf,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_formplex12[96][6] = {
|
||||
const unsigned char font_formplex12[96][8] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x00,0x2f,0x2f,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x03,0x03,0x00,0x03,0x03,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_homespun[96][6] = {
|
||||
const unsigned char font_homespun[96][7] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x5f,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x03,0x00,0x03,0x00,0x00,0x00,0x00}, // "
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_m38[96][6] = {
|
||||
const unsigned char font_m38[96][8] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0xdf,0xdf,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x07,0x07,0x00,0x07,0x07,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_pzim3x5[96][6] = {
|
||||
const unsigned char font_pzim3x5[96][3] = {
|
||||
{0x00,0x00,0x00}, //
|
||||
{0x00,0x2e,0x00}, // !
|
||||
{0x06,0x00,0x06}, // "
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_renew[96][6] = {
|
||||
const unsigned char font_renew[96][7] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x5e,0x00,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x0c,0x00,0x0c,0x00,0x00,0x00,0x00}, // "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned char font_tama_mini02[96][6] = {
|
||||
const unsigned char font_tama_mini02[96][5] = {
|
||||
{0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x2f,0x00,0x00,0x00,0x00}, // !
|
||||
{0x03,0x00,0x03,0x00,0x00}, // "
|
||||
|
||||
+104
-19
@@ -3,7 +3,6 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "./fonts/5x5_font.h"
|
||||
#include "./fonts/7linedigital_font.h"
|
||||
#include "./fonts/BMplain_font.h"
|
||||
#include "./fonts/Blokus_font.h"
|
||||
#include "./fonts/HISKYF21_font.h"
|
||||
@@ -15,12 +14,52 @@
|
||||
#include "./fonts/haiku_font.h"
|
||||
#include "./fonts/sloth_font.h"
|
||||
#include "./fonts/zxpix_font.h"
|
||||
#include "./fonts/Commo-Monospaced_font.h"
|
||||
#include "./fonts/7linedigital_font.h"
|
||||
#include "./fonts/BMSPA_font.h"
|
||||
#include "./fonts/HUNTER_font.h"
|
||||
#include "./fonts/Raumsond_font.h"
|
||||
#include "./fonts/bubblesstandard_font.h"
|
||||
#include "./fonts/formplex12_font.h"
|
||||
#include "./fonts/homespun_font.h"
|
||||
#include "./fonts/Minimum_1_font.h"
|
||||
#include "./fonts/m38_font.h"
|
||||
#include "./fonts/pzim3x5_font.h"
|
||||
#include "./fonts/renew_font.h"
|
||||
#include "./fonts/tama_mini02_font.h"
|
||||
|
||||
// Font object definitions
|
||||
Font font_5x5_obj(reinterpret_cast<const unsigned char*>(font_5x5), 96, 6, 8);
|
||||
Font font_7linedigital_obj(reinterpret_cast<const unsigned char*>(font_7linedigital), 96, 4, 8);
|
||||
Font font_acme_5_outlines_obj(reinterpret_cast<const unsigned char*>(font_acme_5_outlines), 96, 6, 8);
|
||||
Font font_aztech_obj(reinterpret_cast<const unsigned char*>(font_aztech), 96, 6, 8);
|
||||
Font font_BMplain_obj(reinterpret_cast<const unsigned char*>(font_BMplain), 96, 6, 8);
|
||||
Font font_BMSPA_obj(reinterpret_cast<const unsigned char*>(font_BMSPA), 96, 8, 8);
|
||||
Font font_Blokus_obj(reinterpret_cast<const unsigned char*>(font_Blokus), 96, 6, 8);
|
||||
Font font_bubblesstandard_obj(reinterpret_cast<const unsigned char*>(font_bubblesstandard), 96, 7, 8);
|
||||
Font font_Commo_Monospaced_obj(reinterpret_cast<const unsigned char*>(font_Commo_Monospaced), 96, 8, 8);
|
||||
Font font_crackers_obj(reinterpret_cast<const unsigned char*>(font_crackers), 96, 6, 8);
|
||||
Font font_formplex12_obj(reinterpret_cast<const unsigned char*>(font_formplex12), 96, 8, 8);
|
||||
Font font_haiku_obj(reinterpret_cast<const unsigned char*>(font_haiku), 96, 6, 8);
|
||||
Font font_HISKYF21_obj(reinterpret_cast<const unsigned char*>(font_HISKYF21), 96, 6, 8);
|
||||
Font font_homespun_obj(reinterpret_cast<const unsigned char*>(font_homespun), 96, 7, 8);
|
||||
Font font_HUNTER_obj(reinterpret_cast<const unsigned char*>(font_HUNTER), 96, 8, 8);
|
||||
Font font_m38_obj(reinterpret_cast<const unsigned char*>(font_m38), 96, 8, 8);
|
||||
Font font_Minimum_obj(reinterpret_cast<const unsigned char*>(font_Minimum), 96, 6, 8);
|
||||
Font font_Minimum_1_obj(reinterpret_cast<const unsigned char*>(font_Minimum_1), 96, 7, 8);
|
||||
Font font_pzim3x5_obj(reinterpret_cast<const unsigned char*>(font_pzim3x5), 96, 3, 8);
|
||||
Font font_Raumsond_obj(reinterpret_cast<const unsigned char*>(font_Raumsond), 96, 5, 8);
|
||||
Font font_renew_obj(reinterpret_cast<const unsigned char*>(font_renew), 96, 7, 8);
|
||||
Font font_sloth_obj(reinterpret_cast<const unsigned char*>(font_sloth), 96, 6, 8);
|
||||
Font font_SUPERDIG_obj(reinterpret_cast<const unsigned char*>(font_SUPERDIG), 96, 6, 8);
|
||||
Font font_tama_mini02_obj(reinterpret_cast<const unsigned char*>(font_tama_mini02), 96, 5, 8);
|
||||
Font font_zxpix_obj(reinterpret_cast<const unsigned char*>(font_zxpix), 96, 6, 8);
|
||||
|
||||
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(nullptr),
|
||||
clipping_enabled(false), clip_x(0), clip_y(0), clip_width(width), clip_height(height), text_color(true) {}
|
||||
|
||||
void LowLevelRenderer::set_font(const unsigned char (*font)[96][6]) {
|
||||
void LowLevelRenderer::set_font(const Font* font) {
|
||||
current_font = font;
|
||||
}
|
||||
|
||||
@@ -486,51 +525,94 @@ void LowLevelRenderer::draw_filled_circle(int x, int y, int radius, bool on)
|
||||
}
|
||||
}
|
||||
|
||||
void LowLevelRenderer::draw_char_vcol(int x, int y, char c)
|
||||
int LowLevelRenderer::draw_char_vcol(int x, int y, char c)
|
||||
{
|
||||
if (!current_font) return 0;
|
||||
|
||||
// The font table starts at space (ASCII 32)
|
||||
if (c < 32 || c > 127)
|
||||
return;
|
||||
return 0;
|
||||
int font_idx = c - 32;
|
||||
|
||||
for (int col = 0; col < 6; col++)
|
||||
{
|
||||
unsigned char column_byte = (*current_font)[font_idx][col];
|
||||
const unsigned char* char_data = current_font->get_char_data(font_idx);
|
||||
if (!char_data) return 0;
|
||||
|
||||
for (int row = 0; row < 8; row++)
|
||||
int bytes_per_char = current_font->get_bytes_per_char();
|
||||
int char_height = current_font->get_char_height();
|
||||
|
||||
// Find the actual width by skipping trailing empty columns
|
||||
int actual_width = 0;
|
||||
for (int col = bytes_per_char - 1; col >= 0; col--)
|
||||
{
|
||||
if (char_data[col] != 0)
|
||||
{
|
||||
actual_width = col + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw only up to the actual width
|
||||
for (int col = 0; col < actual_width; col++)
|
||||
{
|
||||
unsigned char column_byte = char_data[col];
|
||||
|
||||
for (int row = 0; row < char_height; row++)
|
||||
{
|
||||
// Check if the bit for this row is set
|
||||
// Most of these 1-bit fonts use bit 0 as the top pixel
|
||||
if (column_byte & (1 << row))
|
||||
{
|
||||
set_pixel(x + col, y + row, text_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return actual_width;
|
||||
}
|
||||
|
||||
void LowLevelRenderer::draw_string(int x, int y, const std::string &text, int spacing)
|
||||
{
|
||||
if (!current_font) return;
|
||||
int current_x = x;
|
||||
for (size_t i = 0; i < text.length(); i++)
|
||||
{
|
||||
draw_char_vcol(x + (i * (6 + spacing)), y, text[i]);
|
||||
int char_width = draw_char_vcol(current_x, y, text[i]);
|
||||
current_x += char_width + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
void LowLevelRenderer::draw_char_scaled(int x, int y, char c, int scale)
|
||||
int LowLevelRenderer::draw_char_scaled(int x, int y, char c, int scale)
|
||||
{
|
||||
if (!current_font) return 0;
|
||||
|
||||
if (c < 32 || c > 127)
|
||||
return;
|
||||
return 0;
|
||||
if (scale < 1)
|
||||
scale = 1; // Safety check
|
||||
|
||||
int font_idx = c - 32;
|
||||
const unsigned char* char_data = current_font->get_char_data(font_idx);
|
||||
if (!char_data) return 0;
|
||||
|
||||
for (int col = 0; col < 6; col++)
|
||||
int bytes_per_char = current_font->get_bytes_per_char();
|
||||
int char_height = current_font->get_char_height();
|
||||
|
||||
// Find the actual width by skipping trailing empty columns
|
||||
int actual_width = 0;
|
||||
for (int col = bytes_per_char - 1; col >= 0; col--)
|
||||
{
|
||||
unsigned char column_byte = (*current_font)[font_idx][col];
|
||||
if (char_data[col] != 0)
|
||||
{
|
||||
actual_width = col + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int row = 0; row < 8; row++)
|
||||
// Draw only up to the actual width, scaled
|
||||
for (int col = 0; col < actual_width; col++)
|
||||
{
|
||||
unsigned char column_byte = char_data[col];
|
||||
|
||||
for (int row = 0; row < char_height; row++)
|
||||
{
|
||||
if (column_byte & (1 << row))
|
||||
{
|
||||
@@ -547,16 +629,19 @@ void LowLevelRenderer::draw_char_scaled(int x, int y, char c, int scale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return actual_width * scale;
|
||||
}
|
||||
|
||||
void LowLevelRenderer::draw_string_scaled(int x, int y, const char* text, int scale, int spacing)
|
||||
{
|
||||
if (!current_font) return;
|
||||
int current_x = x;
|
||||
int i = 0;
|
||||
while(text[i] != '\0')
|
||||
{
|
||||
// We multiply the character width (6) and spacing by the scale
|
||||
int next_x = x + (i * (6 + spacing) * scale);
|
||||
draw_char_scaled(next_x, y, text[i], scale);
|
||||
int char_width = draw_char_scaled(current_x, y, text[i], scale);
|
||||
current_x += char_width + (spacing * scale);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
+74
-10
@@ -12,27 +12,91 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Font class that holds font data and dimensions
|
||||
class Font {
|
||||
private:
|
||||
const unsigned char* data;
|
||||
int num_chars;
|
||||
int bytes_per_char;
|
||||
int char_height;
|
||||
|
||||
public:
|
||||
Font(const unsigned char* font_data, int num_chars, int bytes_per_char, int char_height)
|
||||
: data(font_data), num_chars(num_chars), bytes_per_char(bytes_per_char),
|
||||
char_height(char_height) {}
|
||||
|
||||
const unsigned char* get_data() const { return data; }
|
||||
int get_num_chars() const { return num_chars; }
|
||||
int get_bytes_per_char() const { return bytes_per_char; }
|
||||
int get_char_height() const { return char_height; }
|
||||
|
||||
// Get a specific character's data
|
||||
const unsigned char* get_char_data(int char_index) const {
|
||||
if (char_index < 0 || char_index >= num_chars) return nullptr;
|
||||
return data + (char_index * bytes_per_char);
|
||||
}
|
||||
};
|
||||
|
||||
// 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_7linedigital[96][4];
|
||||
extern const unsigned char font_acme_5_outlines[96][6];
|
||||
extern const unsigned char font_aztech[96][6];
|
||||
extern const unsigned char font_BMplain[96][6];
|
||||
extern const unsigned char font_BMSPA[96][8];
|
||||
extern const unsigned char font_Blokus[96][6];
|
||||
extern const unsigned char font_bubblesstandard[96][7];
|
||||
extern const unsigned char font_Commo_Monospaced[96][8];
|
||||
extern const unsigned char font_crackers[96][6];
|
||||
extern const unsigned char font_formplex12[96][8];
|
||||
extern const unsigned char font_haiku[96][6];
|
||||
extern const unsigned char font_HISKYF21[96][6];
|
||||
extern const unsigned char font_homespun[96][7];
|
||||
extern const unsigned char font_HUNTER[96][8];
|
||||
extern const unsigned char font_m38[96][8];
|
||||
extern const unsigned char font_Minimum[96][6];
|
||||
extern const unsigned char font_Minimum_1[96][7];
|
||||
extern const unsigned char font_pzim3x5[96][3];
|
||||
extern const unsigned char font_Raumsond[96][5];
|
||||
extern const unsigned char font_renew[96][7];
|
||||
extern const unsigned char font_sloth[96][6];
|
||||
extern const unsigned char font_SUPERDIG[96][6];
|
||||
extern const unsigned char font_tama_mini02[96][5];
|
||||
extern const unsigned char font_zxpix[96][6];
|
||||
|
||||
// Font object declarations
|
||||
extern Font font_5x5_obj;
|
||||
extern Font font_7linedigital_obj;
|
||||
extern Font font_acme_5_outlines_obj;
|
||||
extern Font font_aztech_obj;
|
||||
extern Font font_BMplain_obj;
|
||||
extern Font font_BMSPA_obj;
|
||||
extern Font font_Blokus_obj;
|
||||
extern Font font_bubblesstandard_obj;
|
||||
extern Font font_Commo_Monospaced_obj;
|
||||
extern Font font_crackers_obj;
|
||||
extern Font font_formplex12_obj;
|
||||
extern Font font_haiku_obj;
|
||||
extern Font font_HISKYF21_obj;
|
||||
extern Font font_homespun_obj;
|
||||
extern Font font_HUNTER_obj;
|
||||
extern Font font_m38_obj;
|
||||
extern Font font_Minimum_obj;
|
||||
extern Font font_Minimum_1_obj;
|
||||
extern Font font_pzim3x5_obj;
|
||||
extern Font font_Raumsond_obj;
|
||||
extern Font font_renew_obj;
|
||||
extern Font font_sloth_obj;
|
||||
extern Font font_SUPERDIG_obj;
|
||||
extern Font font_tama_mini02_obj;
|
||||
extern Font font_zxpix_obj;
|
||||
|
||||
class LowLevelRenderer {
|
||||
private:
|
||||
uint8_t* bit_buffer;
|
||||
int V_WIDTH;
|
||||
int V_HEIGHT;
|
||||
const unsigned char (*current_font)[96][6];
|
||||
const Font* current_font;
|
||||
bool clipping_enabled;
|
||||
int clip_x, clip_y, clip_width, clip_height;
|
||||
bool text_color;
|
||||
@@ -45,7 +109,7 @@ public:
|
||||
LowLevelRenderer(uint8_t* buffer, int width, int height);
|
||||
|
||||
// Font management
|
||||
void set_font(const unsigned char (*font)[96][6]);
|
||||
void set_font(const Font* font);
|
||||
void set_text_color(bool color);
|
||||
|
||||
// --- 1-BIT DRAWING PRIMITIVES ---
|
||||
@@ -76,9 +140,9 @@ public:
|
||||
|
||||
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);
|
||||
int 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);
|
||||
int 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);
|
||||
};
|
||||
|
||||
|
||||
Binary file not shown.
@@ -146,14 +146,15 @@ int main()
|
||||
renderer.set_clip_rect(300, 200, 80, 60); // Small rectangle in bottom-right
|
||||
renderer.draw_filled_circle(340, 230, 40, true); // Circle that extends outside clip rect
|
||||
renderer.reset_clip_rect(); // Reset to full screen
|
||||
|
||||
// Text with different fonts
|
||||
renderer.set_font(&font_acme_5_outlines);
|
||||
renderer.draw_string_scaled(10, 10, "Drawing Demo", 2);
|
||||
|
||||
*/
|
||||
|
||||
renderer.set_font(&font_SUPERDIG);
|
||||
// Text with different fonts
|
||||
renderer.set_font(&font_acme_5_outlines_obj);
|
||||
renderer.draw_string_scaled(10, 10, "Drawing Demo", 2);
|
||||
|
||||
|
||||
|
||||
renderer.set_font(&font_SUPERDIG_obj);
|
||||
renderer.draw_string_scaled(10, 270, command_buffer, 1);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user