Added font support
This commit is contained in:
@@ -50,7 +50,7 @@ void app_init() {
|
||||
tft_draw_rectangle(40,210,60,235,BLUE);
|
||||
tft_fill_rectangle(100,215,200,225,GREEN);
|
||||
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
||||
tft_draw_circle(10,10,100, RED);
|
||||
tft_draw_circle(10,10,100, RED);
|
||||
|
||||
a1.hookedActions = PEN_DOWN | PEN_UP | PEN_MOVE | PEN_ENTER | PEN_LEAVE;
|
||||
a1.x1 = 30;
|
||||
@@ -60,8 +60,8 @@ void app_init() {
|
||||
a1.callback = touchCB;
|
||||
touch_register_area(&a1);
|
||||
|
||||
tft_draw_rectangle(30,30,100,60,BLUE);
|
||||
|
||||
tft_draw_rectangle(30,30,100,60,BLUE);
|
||||
tft_print_line(30, 30, RED, BLUE, 0, "Hallo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,3 +9,13 @@ void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
|
||||
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||
void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||
|
||||
|
||||
uint8_t ll_tft_num_fonts();
|
||||
uint8_t ll_tft_font_height(uint8_t fontnum);
|
||||
uint8_t ll_tft_font_width(uint8_t fontnum);
|
||||
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "tft.h"
|
||||
#include "ll_tft.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
//it might seems pointless to forward all the functions but we might also introduce functions which have some logic here
|
||||
|
||||
@@ -37,3 +39,24 @@ void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t h
|
||||
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
||||
ll_tft_draw_circle(x, y, r, color);
|
||||
}
|
||||
|
||||
uint8_t tft_num_fonts() {
|
||||
return ll_tft_num_fonts();
|
||||
}
|
||||
|
||||
uint8_t tft_font_height(uint8_t fontnum) {
|
||||
return ll_tft_font_height(fontnum);
|
||||
}
|
||||
|
||||
uint8_t tft_font_width(uint8_t fontnum) {
|
||||
return ll_tft_font_width(fontnum);
|
||||
}
|
||||
|
||||
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* text) {
|
||||
if(font>=ll_tft_num_fonts()) return;
|
||||
for(int i=0; i<strlen(text); i++) {
|
||||
ll_tft_draw_char(x,y,color,bgcolor, font, text[i]);
|
||||
x+=ll_tft_font_width(font);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define WHITE RGB(255,255,255)
|
||||
#define BLACK RGB(0,0,0)
|
||||
#define HEX(h) (RGB(((h)>>16),((h)>>8),(h)))
|
||||
#define TRANSPARENT ((uint16_t)0x80C2)
|
||||
|
||||
|
||||
bool tft_init();
|
||||
@@ -19,3 +20,9 @@ void tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_
|
||||
void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
|
||||
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||
|
||||
|
||||
uint8_t tft_num_fonts();
|
||||
uint8_t tft_font_height(uint8_t fontnum);
|
||||
uint8_t tft_font_width(uint8_t fontnum);
|
||||
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* text);
|
||||
|
||||
@@ -32,6 +32,23 @@ void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
||||
|
||||
}
|
||||
|
||||
uint8_t ll_tft_num_fonts() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ll_tft_font_height(uint8_t fontnum) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t ll_tft_font_width(uint8_t fontnum) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
doc/docu.odt
BIN
doc/docu.odt
Binary file not shown.
@@ -21,7 +21,8 @@ HEADERS += \
|
||||
|
||||
|
||||
INCLUDEPATH+= ../../common/lowlevel/ \
|
||||
../../common/touch/
|
||||
../../common/touch/ \
|
||||
../../common/tft/
|
||||
|
||||
|
||||
FORMS += \
|
||||
|
||||
@@ -43,4 +43,37 @@ void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
||||
mainwindow->draw_circle(x,y,r,color);
|
||||
}
|
||||
|
||||
uint8_t ll_tft_num_fonts() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
QFont get_font(uint8_t fontnum) {
|
||||
switch(fontnum) {
|
||||
case 0:
|
||||
return QFont("Monospace",8);
|
||||
default:
|
||||
return QFont();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t ll_tft_font_height(uint8_t fontnum) {
|
||||
QFont f = get_font(fontnum);
|
||||
if(f == QFont()) return -1;
|
||||
QFontMetrics m(f);
|
||||
return m.height();
|
||||
}
|
||||
|
||||
uint8_t ll_tft_font_width(uint8_t fontnum) {
|
||||
QFont f = get_font(fontnum);
|
||||
if(f == QFont()) return -1;
|
||||
QFontMetrics m(f);
|
||||
return m.averageCharWidth();
|
||||
}
|
||||
|
||||
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c) {
|
||||
QFont f = get_font(font);
|
||||
if(f == QFont()) return;
|
||||
mainwindow->draw_char(x,y,color,bgcolor,f,c);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include "touch.h"
|
||||
#include "tft.h"
|
||||
}
|
||||
|
||||
#define DISPLAY_WIDTH 320
|
||||
@@ -110,6 +111,24 @@ void MainWindow::draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c)
|
||||
{
|
||||
//render_mutex.lock();
|
||||
QPainter painter(&(image));
|
||||
painter.setFont(font);
|
||||
|
||||
if(bgcolor!=TRANSPARENT) {
|
||||
painter.setBackgroundMode(Qt::OpaqueMode);
|
||||
painter.setBackground(QColorFromRGB565(bgcolor));
|
||||
}
|
||||
|
||||
painter.setPen(QColorFromRGB565(color));
|
||||
y+=QFontMetrics(font).ascent(); //use y pos as highest point of char, instead of baseline
|
||||
painter.drawText(QPoint(x,y), QString(QChar(c)));
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::paintEvent(QPaintEvent *)
|
||||
{
|
||||
//render_mutex.lock();
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
void fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
void draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||
void draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||
|
||||
void draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * evt);
|
||||
|
||||
Reference in New Issue
Block a user