Improved Emulator Gui

This commit is contained in:
t-moe
2015-05-09 14:32:35 +02:00
parent 0b5173ecbe
commit c652b6bd05
5 changed files with 112 additions and 19 deletions

View File

@@ -62,6 +62,8 @@ static void enter(void* screen) {
//tft test
tft_draw_pixel(0,0,BLACK);
tft_draw_pixel(319,239,BLACK);
tft_draw_pixel(10,210,BLUE);
tft_draw_pixel(12,210,BLUE);
tft_draw_rectangle(40,100,60,235,BLUE);

View File

@@ -15,6 +15,7 @@ void ll_system_delay(uint32_t msec) {
void ll_system_process() {
QApplication::processEvents();
QThread::msleep(1);
}
void ll_system_toggle_led() {

View File

@@ -12,8 +12,6 @@ extern "C" {
#define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240
#define DISPLAY_X 10
#define DISPLAY_Y 10
QColor QColorFromRGB565(uint16_t color) {
@@ -35,6 +33,7 @@ QRgb QRgbFromRGB565(uint16_t color) {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), image(DISPLAY_WIDTH,DISPLAY_HEIGHT, QImage::Format_RGB16), ui(new Ui::MainWindow){
ui->setupUi(this);
image.fill(Qt::black);
currentScale = 1;
}
void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
@@ -134,9 +133,13 @@ void MainWindow::paintEvent(QPaintEvent *)
//render_mutex.lock();
QPainter painter(this);
painter.drawImage(DISPLAY_X,DISPLAY_Y,image);
QRectF imgRect (ui->widgetDisplay->geometry().topLeft(),QSizeF(DISPLAY_WIDTH*currentScale,DISPLAY_HEIGHT*currentScale));
painter.drawImage(imgRect,image);
painter.setPen(QPen(Qt::green,2));
painter.drawRect(DISPLAY_X-1,DISPLAY_Y-1,DISPLAY_WIDTH+2,DISPLAY_HEIGHT+2);
painter.drawRect(imgRect.adjusted(-1,-1,1,1));
//render_mutex.unlock();
}
@@ -167,7 +170,8 @@ MainWindow::~MainWindow()
void MainWindow::checkAndSendEvent(QPoint pos, bool down)
{
QPoint p = pos - QPoint(DISPLAY_X,DISPLAY_Y);
QPoint p = pos - ui->widgetDisplay->geometry().topLeft();
p/=currentScale;
if(p.x()<0 || p.y()<0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) return;
//qDebug() << down << p;
@@ -175,3 +179,9 @@ void MainWindow::checkAndSendEvent(QPoint pos, bool down)
touch_add_raw_event(p.x(),p.y(),down?TOUCH_DOWN:TOUCH_UP);
}
void MainWindow::on_cboZoom_currentIndexChanged(int index)
{
currentScale=index+1;
update();
}

View File

@@ -31,9 +31,13 @@ protected:
void mouseMoveEvent(QMouseEvent* evt);
~MainWindow();
private slots:
void on_cboZoom_currentIndexChanged(int index);
private:
//QMutex render_mutex;
QImage image;
int currentScale;
void checkAndSendEvent(QPoint pos, bool down);
Ui::MainWindow *ui;

View File

@@ -6,26 +6,102 @@
<rect>
<x>0</x>
<y>0</y>
<width>339</width>
<height>263</height>
<width>980</width>
<height>778</height>
</rect>
</property>
<property name="windowTitle">
<string>DiscoverPixy Emulator</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>339</width>
<height>19</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Zoom</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboZoom">
<item>
<property name="text">
<string>1x</string>
</property>
</item>
<item>
<property name="text">
<string>2x</string>
</property>
</item>
<item>
<property name="text">
<string>3x</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnExit">
<property name="text">
<string>Exit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetDisplay" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>btnExit</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>652</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>351</x>
<y>244</y>
</hint>
</hints>
</connection>
</connections>
</ui>