Added font support
This commit is contained in:
@@ -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