| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,105 @@ |
| 1 |
+/* |
|
| 2 |
+ * Author: Pawel Jablonski |
|
| 3 |
+ * E-mail: pj@xirx.net |
|
| 4 |
+ * WWW: xirx.net |
|
| 5 |
+ * GIT: git.xirx.net |
|
| 6 |
+ * |
|
| 7 |
+ * License: You can use this code however you like |
|
| 8 |
+ * but leave information about the original author. |
|
| 9 |
+ * Code is free for non-commercial and commercial use. |
|
| 10 |
+ */ |
|
| 11 |
+ |
|
| 12 |
+#include "lcdview.h" |
|
| 13 |
+#include "font.h" |
|
| 14 |
+ |
|
| 15 |
+/** |
|
| 16 |
+ * Constructor for the LCD view class |
|
| 17 |
+ * |
|
| 18 |
+ * @param parent Parent object |
|
| 19 |
+ */ |
|
| 20 |
+LCDView::LCDView(QWidget *parent) : QGraphicsView(parent) |
|
| 21 |
+{
|
|
| 22 |
+ this->scene.reset(new QGraphicsScene(QRect(0, 0, WIDTH, HEIGHT), this)); |
|
| 23 |
+ |
|
| 24 |
+ QPixmap pixmap = QPixmap(WIDTH, HEIGHT); |
|
| 25 |
+ pixmap.fill(QColor(0, 0, 0)); |
|
| 26 |
+ |
|
| 27 |
+ this->pixmapItem = this->scene->addPixmap(pixmap); |
|
| 28 |
+ |
|
| 29 |
+ this->scale(2, 2); |
|
| 30 |
+ this->setScene(this->scene.data()); |
|
| 31 |
+ this->setBackgroundBrush(QBrush(QColor(0, 0, 0), Qt::SolidPattern)); |
|
| 32 |
+ this->show(); |
|
| 33 |
+} |
|
| 34 |
+ |
|
| 35 |
+//! Reset the LCD view pixmap canvas |
|
| 36 |
+void LCDView::reset() |
|
| 37 |
+{
|
|
| 38 |
+ QImage image = QImage(WIDTH, HEIGHT, QImage::Format_RGB32); |
|
| 39 |
+ image.fill(QColor(0, 0, 0)); |
|
| 40 |
+ |
|
| 41 |
+ this->pixmapItem->setPixmap(QPixmap::fromImage(image)); |
|
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+/** |
|
| 45 |
+ * Process a mouse press event |
|
| 46 |
+ * |
|
| 47 |
+ * @param event Mouse press event |
|
| 48 |
+ */ |
|
| 49 |
+void LCDView::mousePressEvent(QMouseEvent *) |
|
| 50 |
+{
|
|
| 51 |
+ if(this->parentWidget()) |
|
| 52 |
+ {
|
|
| 53 |
+ this->parentWidget()->setFocus(); |
|
| 54 |
+ } |
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+/** |
|
| 58 |
+ * Draw a LCD buffer on the LCD view canvas |
|
| 59 |
+ * |
|
| 60 |
+ * @param buffer LCD buffer |
|
| 61 |
+ */ |
|
| 62 |
+void LCDView::drawSlot(LCD::Buffer buffer) |
|
| 63 |
+{
|
|
| 64 |
+ QImage image = QImage(WIDTH, HEIGHT, QImage::Format_RGB32); |
|
| 65 |
+ image.fill(QColor(0, 0, 0)); |
|
| 66 |
+ |
|
| 67 |
+ for(int x = 0; x < LCD::WIDTH; x++) |
|
| 68 |
+ {
|
|
| 69 |
+ for(int y = 0; y < LCD::HEIGHT; y++) |
|
| 70 |
+ {
|
|
| 71 |
+ unsigned char c = buffer.charData[y][x]; |
|
| 72 |
+ unsigned char colorChar = (buffer.colorData[y][x] & LCD::COLOR_MASK); |
|
| 73 |
+ unsigned char colorBackground = ((buffer.colorData[y][x] >> LCD::COLOR_SHIFT) & LCD::COLOR_MASK); |
|
| 74 |
+ |
|
| 75 |
+ unsigned char colorCharBlue = ((colorChar & (1 << 0)) ? 170 : 0) + ((colorChar & (1 << 3)) ? 85 : 0); |
|
| 76 |
+ unsigned char colorCharGreen = ((colorChar & (1 << 1)) ? 180 : 0) + ((colorChar & (1 << 3)) ? 75 : 0); |
|
| 77 |
+ unsigned char colorCharRed = ((colorChar & (1 << 2)) ? 180 : 0) + ((colorChar & (1 << 3)) ? 75 : 0); |
|
| 78 |
+ |
|
| 79 |
+ unsigned char colorBackgroundBlue = ((colorBackground & (1 << 0)) ? 170 : 0) + ((colorBackground & (1 << 3)) ? 85 : 0); |
|
| 80 |
+ unsigned char colorBackgroundGreen = ((colorBackground & (1 << 1)) ? 180 : 0) + ((colorBackground & (1 << 3)) ? 75 : 0); |
|
| 81 |
+ unsigned char colorBackgroundRed = ((colorBackground & (1 << 2)) ? 180 : 0) + ((colorBackground & (1 << 3)) ? 75 : 0); |
|
| 82 |
+ |
|
| 83 |
+ for(int j = 0; j < LCD::CHAR_HEIGHT; j++) |
|
| 84 |
+ {
|
|
| 85 |
+ unsigned char b = fontTable[c][j]; |
|
| 86 |
+ |
|
| 87 |
+ for(int i = 0; i < LCD::CHAR_WIDTH; i++) |
|
| 88 |
+ {
|
|
| 89 |
+ if(b & 0x01) |
|
| 90 |
+ {
|
|
| 91 |
+ image.setPixelColor(((x * LCD::CHAR_WIDTH) + i), ((y * LCD::CHAR_HEIGHT) + j), QColor(colorCharRed, colorCharGreen, colorCharBlue)); |
|
| 92 |
+ } |
|
| 93 |
+ else |
|
| 94 |
+ {
|
|
| 95 |
+ image.setPixelColor(((x * LCD::CHAR_WIDTH) + i), ((y * LCD::CHAR_HEIGHT) + j), QColor(colorBackgroundRed, colorBackgroundGreen, colorBackgroundBlue)); |
|
| 96 |
+ } |
|
| 97 |
+ |
|
| 98 |
+ b >>= 1; |
|
| 99 |
+ } |
|
| 100 |
+ } |
|
| 101 |
+ } |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ this->pixmapItem->setPixmap(QPixmap::fromImage(image)); |
|
| 105 |
+} |