aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/lcddisplayview.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-06-28 00:53:34 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-06-28 00:53:34 +0200
commitedabdffead6d33a4e6a0e5a84d9e15f25a6acf83 (patch)
tree4df2aebac195a75a5cc1364fc0593a29105c6daa /qtmips_gui/lcddisplayview.cpp
parent30b15c6d1a328df5d8b0f99a5cbb1f72f25c9cdf (diff)
downloadqtmips-edabdffead6d33a4e6a0e5a84d9e15f25a6acf83.tar.gz
qtmips-edabdffead6d33a4e6a0e5a84d9e15f25a6acf83.tar.bz2
qtmips-edabdffead6d33a4e6a0e5a84d9e15f25a6acf83.zip
Initial optimized version LCD display emulation.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/lcddisplayview.cpp')
-rw-r--r--qtmips_gui/lcddisplayview.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/qtmips_gui/lcddisplayview.cpp b/qtmips_gui/lcddisplayview.cpp
new file mode 100644
index 0000000..450e7d4
--- /dev/null
+++ b/qtmips_gui/lcddisplayview.cpp
@@ -0,0 +1,52 @@
+#include <QPainter>
+#include <QStyle>
+#include "lcddisplay.h"
+#include "lcddisplayview.h"
+
+LcdDisplayView::LcdDisplayView(QWidget *parent) : Super(parent) {
+ setMinimumSize(100, 100);
+ fb_pixels = nullptr;
+}
+
+LcdDisplayView::~LcdDisplayView() {
+ if (fb_pixels != nullptr)
+ delete fb_pixels;
+}
+
+void LcdDisplayView::setup(machine::LcdDisplay *lcd_display) {
+ if (lcd_display == nullptr)
+ return;
+ connect(lcd_display, SIGNAL(pixel_update(uint,uint,uint,uint,uint)),
+ this, SLOT(pixel_update(uint,uint,uint,uint,uint)));
+ if (fb_pixels != nullptr)
+ delete fb_pixels;
+ fb_pixels = nullptr;
+ fb_pixels = new QImage(lcd_display->height(),
+ lcd_display->width(), QImage::Format_RGB32);
+ fb_pixels->fill(qRgb(0, 0, 0));
+ update();
+}
+
+void LcdDisplayView::pixel_update(uint x, uint y, uint r, uint g, uint b) {
+ if (fb_pixels != nullptr) {
+ fb_pixels->setPixel(x, y, qRgb(r, g, b));
+ update();
+ }
+}
+
+void LcdDisplayView::paintEvent(QPaintEvent *event) {
+ if (fb_pixels == nullptr)
+ return Super::paintEvent(event);
+ if (fb_pixels->width() == 0)
+ return Super::paintEvent(event);
+
+ QPainter painter(this);
+ QSize widgetSize = rect().size();
+ const auto newHeight = widgetSize.width() * fb_pixels->height() / fb_pixels->width();
+ if(newHeight <= widgetSize.height())
+ widgetSize.setHeight(newHeight);
+ else
+ widgetSize.setWidth(widgetSize.height() * fb_pixels->width() / fb_pixels->height());
+ painter.drawImage(rect(), fb_pixels->scaled(widgetSize));
+}
+