Added more tft functions to common and emulator. Fixed eventloop.
This commit is contained in:
@@ -13,7 +13,8 @@ CONFIG += staticlib
|
||||
SOURCES += \
|
||||
mainwindow.cpp \
|
||||
main.cpp \
|
||||
ll_tft.cpp
|
||||
ll_tft.cpp \
|
||||
ll_system.cpp
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
|
||||
|
||||
7
emulator/qt/ll_system.cpp
Normal file
7
emulator/qt/ll_system.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
extern "C" {
|
||||
#include "ll_system.h"
|
||||
}
|
||||
|
||||
bool ll_system_init() {
|
||||
return true;
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
|
||||
extern "C" {
|
||||
#include "ll_tft.h"
|
||||
}
|
||||
|
||||
|
||||
MainWindow* mainwindow;
|
||||
|
||||
@@ -15,3 +19,26 @@ bool ll_tft_init() {
|
||||
void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
|
||||
mainwindow->draw_line(x1,y1,x2,y2,color);
|
||||
}
|
||||
|
||||
|
||||
void ll_tft_clear(uint16_t color) {
|
||||
mainwindow->clear(color);
|
||||
}
|
||||
|
||||
void ll_tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color) {
|
||||
mainwindow->draw_pixel(x,y,color);
|
||||
}
|
||||
|
||||
void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color) {
|
||||
mainwindow->draw_rectangle(x1,y1,x2,y2,color);
|
||||
}
|
||||
|
||||
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color) {
|
||||
mainwindow->fill_rectangle(x1,y1,x2,y2,color);
|
||||
}
|
||||
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat) {
|
||||
mainwindow->draw_bitmap_unscaled(x,y,width,height,dat);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,29 +3,29 @@
|
||||
|
||||
|
||||
extern "C" {
|
||||
void qt_init(int argc, char* argv[]);
|
||||
int qt_execute();
|
||||
void app_init();
|
||||
void app_process();
|
||||
void qt_init(int argc, char* argv[]); //Will be called at the top of the main() function
|
||||
int qt_execute(); //Will be called after calling qt_execute
|
||||
void app_init(); //Initializes the app
|
||||
void app_process(); //Processes one eventloop of the app
|
||||
}
|
||||
|
||||
QApplication* app_ptr;
|
||||
QApplication* app_ptr=NULL;
|
||||
|
||||
void qt_init(int argc, char* argv[]) {
|
||||
static QApplication app(argc,argv);
|
||||
app_ptr = &app;
|
||||
app_ptr = new QApplication(argc,argv);
|
||||
app_init();
|
||||
}
|
||||
|
||||
void app_loop() {
|
||||
while(1) {
|
||||
while(QApplication::activeWindow()!=NULL) {
|
||||
app_process();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
int qt_execute() {
|
||||
|
||||
QtConcurrent::run(&app_loop);
|
||||
return app_ptr->exec();
|
||||
int ret= app_ptr->exec();
|
||||
delete app_ptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -4,22 +4,26 @@
|
||||
#include <QPainter>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_X 100
|
||||
#define DISPLAY_Y 100
|
||||
|
||||
QColor colorFromRGB565(uint16_t color) {
|
||||
int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5);
|
||||
int G8 = (int) floor( ((color>>5)&0x2F) * 255.0 / 63.0 + 0.5);
|
||||
int B8 = (int) floor( (color&0x1F) * 255.0 / 31.0 + 0.5);
|
||||
return QColor::fromRgb(R8,G8,B8);
|
||||
|
||||
}
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
pixmap(320,240),
|
||||
pixmap(DISPLAY_WIDTH,DISPLAY_HEIGHT),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
@@ -32,14 +36,61 @@ void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, u
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::draw_pixel(uint16_t x, uint16_t y, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
painter.drawPoint(x,y);
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::clear(uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
pixmap.fill(colorFromRGB565(color));
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
painter.drawRect(x1,y1,x2,y2);
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.fillRect(x1,y1,x2,y2,colorFromRGB565(color));
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *dat)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
|
||||
for(int yi=0; yi<height; yi++) {
|
||||
for(int xi=0; xi<width; xi++) {
|
||||
painter.setPen(colorFromRGB565(dat[yi*width+xi]));
|
||||
painter.drawPoint(x+xi,y+yi);
|
||||
}
|
||||
}
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::paintEvent(QPaintEvent *)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(this);
|
||||
|
||||
painter.drawPixmap(100,100,pixmap);
|
||||
painter.setPen(Qt::green);
|
||||
painter.drawRect(100-1,100-1,320+2,240+2);
|
||||
painter.drawPixmap(DISPLAY_X,DISPLAY_Y,pixmap);
|
||||
painter.setPen(QPen(Qt::green,2));
|
||||
painter.drawRect(DISPLAY_X-1,DISPLAY_Y-1,DISPLAY_WIDTH+2,DISPLAY_HEIGHT+2);
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
@@ -48,3 +99,4 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,15 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
void draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
void draw_pixel(uint16_t x,uint16_t y,uint16_t color);
|
||||
void clear(uint16_t color);
|
||||
void draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
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 uint8_t* dat);
|
||||
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * evt);
|
||||
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
@@ -26,5 +32,6 @@ private:
|
||||
QPixmap pixmap;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user