make fonts more generic
This commit is contained in:
parent
1009d689bc
commit
58f3d1f02b
9 changed files with 235 additions and 183 deletions
6
OBJECTS
6
OBJECTS
|
@ -1,5 +1,9 @@
|
||||||
TARGET = main
|
TARGET = main
|
||||||
SRC = col.cpp hal.cpp main.cpp example.cpp gfx/screen.cpp gfx/canvas.cpp gfx/font.cpp
|
SRC = col.cpp hal.cpp main.cpp example.cpp
|
||||||
|
|
||||||
|
SRC += gfx/screen.cpp gfx/canvas.cpp gfx/font.cpp
|
||||||
|
|
||||||
|
SRC += fonts/basic_5x4.cpp
|
||||||
|
|
||||||
SRCDIR = src
|
SRCDIR = src
|
||||||
INCDIR = inc
|
INCDIR = inc
|
||||||
|
|
12
inc/fonts/basic_5x4.h
Normal file
12
inc/fonts/basic_5x4.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
//
|
||||||
|
// Created by jedi on 11/2/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MGL_DMXMENU_BASIC_5X4_H
|
||||||
|
#define MGL_DMXMENU_BASIC_5X4_H
|
||||||
|
|
||||||
|
#include "gfx/font.h"
|
||||||
|
|
||||||
|
extern font basic_5x4;
|
||||||
|
|
||||||
|
#endif //MGL_DMXMENU_BASIC_5X4_H
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "gfx/font.h"
|
#include "gfx/font.h"
|
||||||
|
#include "fonts/basic_5x4.h"
|
||||||
|
|
||||||
class canvas {
|
class canvas {
|
||||||
private:
|
private:
|
||||||
|
@ -23,23 +24,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(int x, int y, const char *str) {
|
void print(int x, int y, const char *str) {
|
||||||
for (int i = 0; str[i]; i++) {
|
basic_5x4.print(x, y, str, *this);
|
||||||
int j = (str[i] - ' ') % 32;
|
|
||||||
for (int x_ = 0; x_ < 4; x_++)
|
|
||||||
for (int y_ = 0; y_ < 5; y_++)
|
|
||||||
if (testFont[j][x_ + 4 * y_])
|
|
||||||
draw(x + i * 5 + x_, y + y_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(int x, int y, char *str) {
|
void print(int x, int y, char *str) {
|
||||||
for (int i = 0; str[i]; i++) {
|
basic_5x4.print(x, y, str, *this);
|
||||||
int j = (str[i] - ' ') % 32;
|
|
||||||
for (int x_ = 0; x_ < 4; x_++)
|
|
||||||
for (int y_ = 0; y_ < 5; y_++)
|
|
||||||
if (testFont[j][x_ + 4 * y_])
|
|
||||||
draw(x + i * 5 + x_, y + y_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,12 +5,18 @@
|
||||||
#ifndef MGL_DMXMENU_FONT_H
|
#ifndef MGL_DMXMENU_FONT_H
|
||||||
#define MGL_DMXMENU_FONT_H
|
#define MGL_DMXMENU_FONT_H
|
||||||
|
|
||||||
|
class canvas;
|
||||||
|
|
||||||
class font {
|
class font {
|
||||||
|
public:
|
||||||
|
typedef const bool raw_font[32][20];
|
||||||
|
private:
|
||||||
|
raw_font& raw_data_;
|
||||||
|
public:
|
||||||
|
font(raw_font&);
|
||||||
|
void print(int x, int y, char c, canvas&);
|
||||||
|
void print(int x, int y, char* str, canvas&);
|
||||||
|
void print(int x, int y, const char* str, canvas&);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool testFont[32][20];
|
|
||||||
|
|
||||||
#endif //MGL_DMXMENU_FONT_H
|
#endif //MGL_DMXMENU_FONT_H
|
||||||
|
|
|
@ -15,6 +15,7 @@ void hal_init();
|
||||||
void hal_draw(int x, int y);
|
void hal_draw(int x, int y);
|
||||||
void hal_print(int x, int y, const char* str);
|
void hal_print(int x, int y, const char* str);
|
||||||
void render(Layout&);
|
void render(Layout&);
|
||||||
|
void hal_render();
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
extern bool input[4];
|
extern bool input[4];
|
||||||
|
|
172
src/fonts/basic_5x4.cpp
Normal file
172
src/fonts/basic_5x4.cpp
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
//
|
||||||
|
// Created by jedi on 11/2/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "fonts/basic_5x4.h"
|
||||||
|
|
||||||
|
const bool basic_5x4_raw[32][20] = {
|
||||||
|
//0
|
||||||
|
{0,0,0,0,
|
||||||
|
0,0,0,0,
|
||||||
|
0,0,0,0,
|
||||||
|
0,0,0,0,
|
||||||
|
0,0,0,0},
|
||||||
|
//A
|
||||||
|
{0,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,1,
|
||||||
|
1,0,0,1},
|
||||||
|
//B
|
||||||
|
{1,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,0},
|
||||||
|
//C
|
||||||
|
{0,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,0,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,0},
|
||||||
|
//D
|
||||||
|
{1,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,0},
|
||||||
|
//E
|
||||||
|
{1,1,1,1,
|
||||||
|
1,0,0,0,
|
||||||
|
1,1,1,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,1,1,1},
|
||||||
|
//F
|
||||||
|
{1,1,1,1,
|
||||||
|
1,0,0,0,
|
||||||
|
1,1,1,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,0,0,0},
|
||||||
|
//G
|
||||||
|
{0,1,1,1,
|
||||||
|
1,0,0,0,
|
||||||
|
1,0,1,1,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,1},
|
||||||
|
//H
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1},
|
||||||
|
//I
|
||||||
|
{1,1,1,0,
|
||||||
|
0,1,0,0,
|
||||||
|
0,1,0,0,
|
||||||
|
0,1,0,0,
|
||||||
|
1,1,1,0},
|
||||||
|
//J
|
||||||
|
{1,1,1,1,
|
||||||
|
0,0,0,1,
|
||||||
|
0,0,0,1,
|
||||||
|
0,0,0,1,
|
||||||
|
1,1,1,0},
|
||||||
|
//K
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,1,0,
|
||||||
|
1,1,0,0,
|
||||||
|
1,0,1,0,
|
||||||
|
1,0,0,1},
|
||||||
|
//L
|
||||||
|
{1,0,0,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,1,1,1},
|
||||||
|
//M
|
||||||
|
{1,0,0,1,
|
||||||
|
1,1,1,1,
|
||||||
|
1,1,1,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1},
|
||||||
|
//N
|
||||||
|
{1,0,0,1,
|
||||||
|
1,1,0,1,
|
||||||
|
1,0,1,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1},
|
||||||
|
//O
|
||||||
|
{0,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,0},
|
||||||
|
//P
|
||||||
|
{1,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,0,
|
||||||
|
1,0,0,0},
|
||||||
|
//Q
|
||||||
|
{0,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,1,1,
|
||||||
|
0,1,1,1},
|
||||||
|
//R
|
||||||
|
{1,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,0,
|
||||||
|
1,0,0,1},
|
||||||
|
//S
|
||||||
|
{0,1,1,1,
|
||||||
|
1,0,0,0,
|
||||||
|
0,1,1,0,
|
||||||
|
0,0,0,1,
|
||||||
|
1,1,1,0},
|
||||||
|
//T
|
||||||
|
{1,1,1,1,
|
||||||
|
0,0,1,0,
|
||||||
|
0,0,1,0,
|
||||||
|
0,0,1,0,
|
||||||
|
0,0,1,0},
|
||||||
|
//U
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,0},
|
||||||
|
//V
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,1,0,
|
||||||
|
1,0,1,0,
|
||||||
|
0,1,0,0},
|
||||||
|
//W
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
1,1,1,1,
|
||||||
|
1,1,1,1,
|
||||||
|
0,1,1,0},
|
||||||
|
//X
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,0,
|
||||||
|
1,0,0,1,
|
||||||
|
1,0,0,1},
|
||||||
|
//Y
|
||||||
|
{1,0,0,1,
|
||||||
|
1,0,0,1,
|
||||||
|
0,1,1,1,
|
||||||
|
0,0,0,1,
|
||||||
|
1,1,1,0},
|
||||||
|
//Z
|
||||||
|
{1,1,1,1,
|
||||||
|
0,0,0,1,
|
||||||
|
0,1,1,0,
|
||||||
|
1,0,0,0,
|
||||||
|
1,1,1,1},
|
||||||
|
};
|
||||||
|
|
||||||
|
font basic_5x4(basic_5x4_raw);
|
189
src/gfx/font.cpp
189
src/gfx/font.cpp
|
@ -3,168 +3,29 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gfx/font.h"
|
#include "gfx/font.h"
|
||||||
|
#include "gfx/canvas.h"
|
||||||
|
|
||||||
bool testFont[32][20] = {
|
|
||||||
//0
|
|
||||||
{0,0,0,0,
|
font::font(raw_font& raw ):raw_data_(raw){
|
||||||
0,0,0,0,
|
}
|
||||||
0,0,0,0,
|
|
||||||
0,0,0,0,
|
void font::print(int x, int y, char l, canvas& c) {
|
||||||
0,0,0,0},
|
int j = (l - ' ') % 32;
|
||||||
//A
|
for (int x_ = 0; x_ < 4; x_++)
|
||||||
{0,1,1,0,
|
for (int y_ = 0; y_ < 5; y_++)
|
||||||
1,0,0,1,
|
if (raw_data_[j][x_ + 4 * y_])
|
||||||
1,0,0,1,
|
c.draw(x + x_, y + y_);
|
||||||
1,1,1,1,
|
}
|
||||||
1,0,0,1},
|
|
||||||
//B
|
void font::print(int x, int y, char* str, canvas& c) {
|
||||||
{1,1,1,0,
|
for (int i = 0; str[i]; i++) {
|
||||||
1,0,0,1,
|
print(x + i * 5,y,str[i],c);
|
||||||
1,1,1,0,
|
}
|
||||||
1,0,0,1,
|
}
|
||||||
1,1,1,0},
|
|
||||||
//C
|
void font::print(int x, int y, const char* str, canvas& c) {
|
||||||
{0,1,1,0,
|
for (int i = 0; str[i]; i++) {
|
||||||
1,0,0,1,
|
print(x + i * 5,y,str[i],c);
|
||||||
1,0,0,0,
|
}
|
||||||
1,0,0,1,
|
}
|
||||||
0,1,1,0},
|
|
||||||
//D
|
|
||||||
{1,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,1,1,0},
|
|
||||||
//E
|
|
||||||
{1,1,1,1,
|
|
||||||
1,0,0,0,
|
|
||||||
1,1,1,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,1,1,1},
|
|
||||||
//F
|
|
||||||
{1,1,1,1,
|
|
||||||
1,0,0,0,
|
|
||||||
1,1,1,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,0,0,0},
|
|
||||||
//G
|
|
||||||
{0,1,1,1,
|
|
||||||
1,0,0,0,
|
|
||||||
1,0,1,1,
|
|
||||||
1,0,0,1,
|
|
||||||
0,1,1,1},
|
|
||||||
//H
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,1,1,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1},
|
|
||||||
//I
|
|
||||||
{1,1,1,0,
|
|
||||||
0,1,0,0,
|
|
||||||
0,1,0,0,
|
|
||||||
0,1,0,0,
|
|
||||||
1,1,1,0},
|
|
||||||
//J
|
|
||||||
{1,1,1,1,
|
|
||||||
0,0,0,1,
|
|
||||||
0,0,0,1,
|
|
||||||
0,0,0,1,
|
|
||||||
1,1,1,0},
|
|
||||||
//K
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,1,0,
|
|
||||||
1,1,0,0,
|
|
||||||
1,0,1,0,
|
|
||||||
1,0,0,1},
|
|
||||||
//L
|
|
||||||
{1,0,0,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,1,1,1},
|
|
||||||
//M
|
|
||||||
{1,0,0,1,
|
|
||||||
1,1,1,1,
|
|
||||||
1,1,1,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1},
|
|
||||||
//N
|
|
||||||
{1,0,0,1,
|
|
||||||
1,1,0,1,
|
|
||||||
1,0,1,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1},
|
|
||||||
//O
|
|
||||||
{0,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
0,1,1,0},
|
|
||||||
//P
|
|
||||||
{1,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,1,1,0,
|
|
||||||
1,0,0,0},
|
|
||||||
//Q
|
|
||||||
{0,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,1,1,
|
|
||||||
0,1,1,1},
|
|
||||||
//R
|
|
||||||
{1,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,1,1,0,
|
|
||||||
1,0,0,1},
|
|
||||||
//S
|
|
||||||
{0,1,1,1,
|
|
||||||
1,0,0,0,
|
|
||||||
0,1,1,0,
|
|
||||||
0,0,0,1,
|
|
||||||
1,1,1,0},
|
|
||||||
//T
|
|
||||||
{1,1,1,1,
|
|
||||||
0,0,1,0,
|
|
||||||
0,0,1,0,
|
|
||||||
0,0,1,0,
|
|
||||||
0,0,1,0},
|
|
||||||
//U
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
0,1,1,0},
|
|
||||||
//V
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,1,0,
|
|
||||||
1,0,1,0,
|
|
||||||
0,1,0,0},
|
|
||||||
//W
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
1,1,1,1,
|
|
||||||
1,1,1,1,
|
|
||||||
0,1,1,0},
|
|
||||||
//X
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
0,1,1,0,
|
|
||||||
1,0,0,1,
|
|
||||||
1,0,0,1},
|
|
||||||
//Y
|
|
||||||
{1,0,0,1,
|
|
||||||
1,0,0,1,
|
|
||||||
0,1,1,1,
|
|
||||||
0,0,0,1,
|
|
||||||
1,1,1,0},
|
|
||||||
//Z
|
|
||||||
{1,1,1,1,
|
|
||||||
0,0,0,1,
|
|
||||||
0,1,1,0,
|
|
||||||
1,0,0,0,
|
|
||||||
1,1,1,1},
|
|
||||||
};
|
|
|
@ -14,6 +14,7 @@ void hal_init(){
|
||||||
ssd1306_fillScreen( 0x00 );
|
ssd1306_fillScreen( 0x00 );
|
||||||
//ssd1306_setFixedFont(ssd1306xled_font6x8);
|
//ssd1306_setFixedFont(ssd1306xled_font6x8);
|
||||||
ssd1306_setFixedFont(ssd1306xled_font5x7);
|
ssd1306_setFixedFont(ssd1306xled_font5x7);
|
||||||
|
canvas.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal_draw(int x, int y){
|
void hal_draw(int x, int y){
|
||||||
|
@ -44,6 +45,10 @@ void render(Layout& layout) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hal_render(){
|
||||||
|
canvas.blt(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void * operator new(unsigned int size)
|
void * operator new(unsigned int size)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
|
|
|
@ -83,6 +83,8 @@ int main() {
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
|
#else
|
||||||
|
hal_render();
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue