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 test
tft_draw_pixel(0,0,BLACK);
tft_draw_pixel(319,239,BLACK);
tft_draw_pixel(10,210,BLUE); tft_draw_pixel(10,210,BLUE);
tft_draw_pixel(12,210,BLUE); tft_draw_pixel(12,210,BLUE);
tft_draw_rectangle(40,100,60,235,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() { void ll_system_process() {
QApplication::processEvents(); QApplication::processEvents();
QThread::msleep(1);
} }
void ll_system_toggle_led() { void ll_system_toggle_led() {

View File

@@ -12,8 +12,6 @@ extern "C" {
#define DISPLAY_WIDTH 320 #define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240 #define DISPLAY_HEIGHT 240
#define DISPLAY_X 10
#define DISPLAY_Y 10
QColor QColorFromRGB565(uint16_t color) { 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){ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), image(DISPLAY_WIDTH,DISPLAY_HEIGHT, QImage::Format_RGB16), ui(new Ui::MainWindow){
ui->setupUi(this); ui->setupUi(this);
image.fill(Qt::black); 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) 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(); //render_mutex.lock();
QPainter painter(this); 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.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(); //render_mutex.unlock();
} }
@@ -167,7 +170,8 @@ MainWindow::~MainWindow()
void MainWindow::checkAndSendEvent(QPoint pos, bool down) 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; if(p.x()<0 || p.y()<0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) return;
//qDebug() << down << p; //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); 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); void mouseMoveEvent(QMouseEvent* evt);
~MainWindow(); ~MainWindow();
private slots:
void on_cboZoom_currentIndexChanged(int index);
private: private:
//QMutex render_mutex; //QMutex render_mutex;
QImage image; QImage image;
int currentScale;
void checkAndSendEvent(QPoint pos, bool down); void checkAndSendEvent(QPoint pos, bool down);
Ui::MainWindow *ui; Ui::MainWindow *ui;

View File

@@ -6,26 +6,102 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>339</width> <width>980</width>
<height>263</height> <height>778</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>DiscoverPixy Emulator</string> <string>DiscoverPixy Emulator</string>
</property> </property>
<widget class="QWidget" name="centralwidget"/> <widget class="QWidget" name="centralwidget">
<widget class="QMenuBar" name="menubar"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="geometry"> <item>
<rect> <layout class="QHBoxLayout" name="horizontalLayout">
<x>0</x> <item>
<y>0</y> <widget class="QLabel" name="label">
<width>339</width> <property name="text">
<height>19</height> <string>Zoom</string>
</rect> </property>
</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>
<widget class="QStatusBar" name="statusbar"/>
</widget> </widget>
<resources/> <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> </ui>