4 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Bernardo Innocenti <bernie@develer.com>
12 * \brief Custom control for graphics LCD emulation (interface)
17 *#* Revision 1.6 2006/02/20 02:00:40 bernie
20 *#* Revision 1.5 2006/02/15 09:13:16 bernie
21 *#* Switch to BITMAP_FMT_PLANAR_V_LSB.
23 *#* Revision 1.4 2006/02/10 12:33:49 bernie
24 *#* Make emulator display a bit larger.
26 *#* Revision 1.3 2006/01/23 23:11:07 bernie
27 *#* Use RASTER_SIZE() to compute... err... the raster size.
29 *#* Revision 1.2 2006/01/17 02:30:43 bernie
30 *#* Fix QImage format.
32 *#* Revision 1.1 2006/01/16 03:51:35 bernie
33 *#* Add LCD Qt emulator.
37 #include "lcd_gfx_qt.h"
38 #include <emul/emul.h>
39 #include <cfg/debug.h>
40 #include <gfx/gfx.h> // CONFIG_BITMAP_FMT
45 #include <qsizepolicy.h>
48 #include <QtGui/QPainter>
49 #include <QtGui/QImage>
50 #include <QtGui/QSizePolicy>
51 #include <QtCore/QSize>
55 #define LCD_FG_COLOR 0x0, 0x0, 0x0
56 #define LCD_BG_COLOR 0xBB, 0xCC, 0xBB
59 EmulLCD::EmulLCD(QWidget *parent, const char *name) :
60 QFrame(parent, name, Qt::WRepaintNoErase | Qt::WResizeNoErase),
61 fg_color(LCD_FG_COLOR),
62 bg_color(LCD_BG_COLOR)
65 memset(raster, 0xAA, sizeof(raster));
68 setFrameStyle(QFrame::Panel | QFrame::Sunken);
69 frame_width = frameWidth();
79 QSizePolicy EmulLCD::sizePolicy() const
81 return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false);
85 QSize EmulLCD::sizeHint() const
88 WIDTH + frame_width * 2,
89 HEIGHT + frame_width * 2);
93 void EmulLCD::paintEvent(QPaintEvent * /*event*/)
96 QImage img(raster, WIDTH, HEIGHT, 1, NULL, 0, QImage::BigEndian);
98 p.setBackgroundMode(Qt::OpaqueMode);
100 p.setBackgroundColor(bg_color);
101 p.drawImage(frame_width, frame_width, img);
104 void EmulLCD::writeRaster(uint8_t *new_raster)
106 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
109 memcpy(raster, new_raster, sizeof(raster));
111 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
114 for (int y = 0; y < HEIGHT; ++y)
116 for (int xbyte = 0; xbyte < WIDTH/8; ++xbyte)
119 for (int xbit = 0; xbit < 8; ++xbit)
120 v |= (new_raster[(xbyte * 8 + xbit) + (y / 8) * WIDTH] & (1 << (y%8)) )
121 ? (1 << (7 - xbit)) : 0;
123 raster[y * ((WIDTH + 7) / 8) + xbyte] = v;
128 #error Unsupported bitmap format
137 #include <cfg/debug.h>
140 * Raster buffer to draw into.
142 * Bits in the bitmap bytes have vertical orientation,
143 * as required by the LCD driver.
145 DECLARE_WALL(wall_before_raster, WALL_SIZE)
146 static uint8_t lcd_raster[RASTER_SIZE(EmulLCD::WIDTH, EmulLCD::HEIGHT)];
147 DECLARE_WALL(wall_after_raster, WALL_SIZE)
149 /*! Default LCD bitmap */
150 struct Bitmap lcd_bitmap;
152 /*extern "C"*/ void lcd_init(void)
154 //FIXME INIT_WALL(wall_before_raster);
155 //FIXME INIT_WALL(wall_after_raster);
156 gfx_bitmapInit(&lcd_bitmap, lcd_raster, EmulLCD::WIDTH, EmulLCD::HEIGHT);
157 gfx_bitmapClear(&lcd_bitmap);
160 /*extern "C"*/ void lcd_blit_bitmap(Bitmap *bm)
162 //FIXME CHECK_WALL(wall_before_raster);
163 //FIXME CHECK_WALL(wall_after_raster);
164 emul->emulLCD->writeRaster(bm->raster);
167 #include "lcd_gfx_qt_moc.cpp"