You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
C
59 lines
1.8 KiB
C
#include <stdint.h>
|
|
#include "text.h"
|
|
|
|
uint8_t check_chr_width(const uint8_t chr[]){
|
|
for(int i=6;i>=0;i--)
|
|
if(chr[i] != 0)
|
|
return i;
|
|
return 2; //space character
|
|
}
|
|
|
|
void put_chr(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, uint8_t pos, const uint8_t chr[], uint8_t size){
|
|
for(int i=0;i<8;i++)
|
|
for(int j=0;j<7;j++){
|
|
uint8_t val = (chr[j]&(1<<i))>>i;
|
|
for(int x=0;x<size;x++)
|
|
for(int y=0;y<size;y++)
|
|
framebuffer[1+(line*10)+(i*size)+y][(pos)+(j*size)+x][0] = val;
|
|
}
|
|
}
|
|
|
|
void put_line(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size){
|
|
uint8_t pos = 0;
|
|
uint8_t disp_pos = 0;
|
|
while(str[pos] != 0){
|
|
uint16_t code = 0;
|
|
if((str[pos]&0xE0) == 0xC0 && (str[pos+1]&0xC0) == 0x80){
|
|
code = (str[pos] & 0x1F) << 6;
|
|
code |= (str[pos+1] & 0x3F);
|
|
pos++;
|
|
}else{
|
|
code = str[pos];
|
|
}
|
|
put_chr(framebuffer, line, disp_pos, font[code-0x20], size);
|
|
disp_pos += (check_chr_width(font[code-0x20]) + 1 + spacing)*size;
|
|
pos++;
|
|
}
|
|
}
|
|
|
|
void put_line_center(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t line, char *str, uint8_t spacing, uint8_t size){
|
|
uint8_t pos = 0;
|
|
uint8_t txt_length = 0;
|
|
|
|
while(str[pos] != 0){
|
|
txt_length += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size;
|
|
pos++;
|
|
}
|
|
pos=0;
|
|
|
|
uint8_t disp_pos = (DISPLAY_WIDTH/2) - (txt_length/2);
|
|
|
|
while(str[pos] != 0){
|
|
put_chr(framebuffer, line, disp_pos, font[str[pos]-0x20], size);
|
|
disp_pos += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size;
|
|
pos++;
|
|
}
|
|
}
|
|
|
|
|