Add LCD Qt emulator.
[bertos.git] / drv / lcd_gfx_qt.cpp
1 /**
2  * \file
3  * <!--
4  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See README.devlib for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \author Bernardo Innocenti <bernie@develer.com>
11  *
12  * \brief Custom control for graphics LCD emulation (interface)
13  */
14
15 /*#*
16  *#* $Log$
17  *#* Revision 1.1  2006/01/16 03:51:35  bernie
18  *#* Add LCD Qt emulator.
19  *#*
20  *#*/
21
22 #include "lcd_gfx_qt.h"
23 #include <emul/emul.h>
24
25 #include <qpainter.h>
26 #include <qimage.h>
27 #include <qsizepolicy.h>
28 #include <qsize.h>
29
30 // Display colors
31 #define LCD_FG_COLOR 0x0, 0x0, 0x0
32 #define LCD_BG_COLOR 0xBB, 0xCC, 0xBB
33
34
35 EmulLCD::EmulLCD(QWidget *parent, const char *name) :
36         QFrame(parent, name, WRepaintNoErase | WResizeNoErase),
37         fg_color(LCD_FG_COLOR),
38         bg_color(LCD_BG_COLOR)
39 {
40         // initialize bitmap
41         memset(raster, 0xAA, sizeof(raster));
42
43         // set widget frame
44         setFrameStyle(QFrame::Panel | QFrame::Sunken);
45         frame_width = frameWidth();
46 }
47
48
49 EmulLCD::~EmulLCD()
50 {
51         // nop
52 }
53
54
55 QSizePolicy EmulLCD::sizePolicy() const
56 {
57         return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false);
58 }
59
60
61 QSize EmulLCD::sizeHint() const
62 {
63         return QSize(
64                 WIDTH + frame_width * 2,
65                 HEIGHT + frame_width * 2);
66 }
67
68
69 void EmulLCD::drawContents(QPainter *p)
70 {
71         QImage img(raster, WIDTH, HEIGHT, 1, NULL, 0, QImage::IgnoreEndian);
72
73         p->setBackgroundMode(OpaqueMode);
74         p->setPen(fg_color);
75         p->setBackgroundColor(bg_color);
76         p->drawImage(frame_width, frame_width, img);
77 }
78
79 void EmulLCD::writeRaster(uint8_t *new_raster)
80 {
81         memcpy(raster, new_raster, sizeof(raster));
82
83         QPainter p(this);
84         drawContents(&p);
85 }
86
87
88
89 #include <gfx/gfx.h>
90 #include <cfg/debug.h>
91
92 /*!
93  * Raster buffer to draw into.
94  * Bits in the bitmap bytes have vertical orientation,
95  * as required by the LCD driver.
96  */
97 DECLARE_WALL(wall_before_raster, WALL_SIZE)
98 static uint8_t lcd_raster[EmulLCD::WIDTH * ((EmulLCD::HEIGHT + 7) / 8)];
99 DECLARE_WALL(wall_after_raster, WALL_SIZE)
100
101 /*! Default LCD bitmap */
102 struct Bitmap lcd_bitmap;
103
104 extern "C" void lcd_init(void)
105 {
106         gfx_bitmapInit(&lcd_bitmap, lcd_raster, EmulLCD::WIDTH, EmulLCD::HEIGHT);
107         gfx_bitmapClear(&lcd_bitmap);
108 }
109
110 extern "C" void lcd_blit_bitmap(Bitmap *bm)
111 {
112         emul->emulLCD->writeRaster(bm->raster);
113 }
114
115 #include "lcd_gfx_qt_moc.cpp"
116