Refactored Project Structure for use with emulator
This commit is contained in:
26
emulator/qt/emulatorqt.pro
Normal file
26
emulator/qt/emulatorqt.pro
Normal file
@@ -0,0 +1,26 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2015-04-02T22:09:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += widgets gui
|
||||
|
||||
TARGET = emulatorqt
|
||||
TEMPLATE = lib
|
||||
CONFIG += staticlib
|
||||
|
||||
SOURCES += \
|
||||
mainwindow.cpp \
|
||||
main.cpp \
|
||||
ll_tft.cpp
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
|
||||
|
||||
INCLUDEPATH+= ../../common/lowlevel/
|
||||
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
17
emulator/qt/ll_tft.cpp
Normal file
17
emulator/qt/ll_tft.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
#include "ll_tft.h"
|
||||
|
||||
MainWindow* mainwindow;
|
||||
|
||||
bool ll_tft_init() {
|
||||
qDebug() << "tft init done";
|
||||
mainwindow = new MainWindow();
|
||||
mainwindow->show();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
31
emulator/qt/main.cpp
Normal file
31
emulator/qt/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <QApplication>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
|
||||
extern "C" {
|
||||
void qt_init(int argc, char* argv[]);
|
||||
int qt_execute();
|
||||
void app_init();
|
||||
void app_process();
|
||||
}
|
||||
|
||||
QApplication* app_ptr;
|
||||
|
||||
void qt_init(int argc, char* argv[]) {
|
||||
static QApplication app(argc,argv);
|
||||
app_ptr = &app;
|
||||
app_init();
|
||||
}
|
||||
|
||||
void app_loop() {
|
||||
while(1) {
|
||||
app_process();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
int qt_execute() {
|
||||
|
||||
QtConcurrent::run(&app_loop);
|
||||
return app_ptr->exec();
|
||||
}
|
||||
50
emulator/qt/mainwindow.cpp
Normal file
50
emulator/qt/mainwindow.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <math.h>
|
||||
|
||||
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),
|
||||
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)
|
||||
{
|
||||
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
painter.drawLine(x1,y1,x2,y2);
|
||||
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);
|
||||
render_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
30
emulator/qt/mainwindow.h
Normal file
30
emulator/qt/mainwindow.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMutex>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
void draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * evt);
|
||||
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
QMutex render_mutex;
|
||||
QPixmap pixmap;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
45
emulator/qt/mainwindow.ui
Normal file
45
emulator/qt/mainwindow.ui
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user