Removed 'This file is part of DevLib ...'
[bertos.git] / drv / lcd_gfx_qt.cpp
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \version $Id$
34  *
35  * \author Bernardo Innocenti <bernie@develer.com>
36  *
37  * \brief Custom control for graphics LCD emulation (interface)
38  */
39
40 /*#*
41  *#* $Log$
42  *#* Revision 1.9  2006/07/19 12:56:25  bernie
43  *#* Convert to new Doxygen style.
44  *#*
45  *#* Revision 1.8  2006/05/28 12:17:57  bernie
46  *#* Drop almost all the Qt3 cruft.
47  *#*
48  *#* Revision 1.7  2006/04/27 05:43:08  bernie
49  *#* Fix naming conventions.
50  *#*
51  *#* Revision 1.6  2006/02/20 02:00:40  bernie
52  *#* Port to Qt 4.1.
53  *#*
54  *#* Revision 1.5  2006/02/15 09:13:16  bernie
55  *#* Switch to BITMAP_FMT_PLANAR_V_LSB.
56  *#*
57  *#* Revision 1.4  2006/02/10 12:33:49  bernie
58  *#* Make emulator display a bit larger.
59  *#*
60  *#* Revision 1.3  2006/01/23 23:11:07  bernie
61  *#* Use RASTER_SIZE() to compute... err... the raster size.
62  *#*
63  *#* Revision 1.2  2006/01/17 02:30:43  bernie
64  *#* Fix QImage format.
65  *#*
66  *#* Revision 1.1  2006/01/16 03:51:35  bernie
67  *#* Add LCD Qt emulator.
68  *#*/
69
70 #include "lcd_gfx_qt.h"
71 #include <emul/emul.h>
72 #include <cfg/debug.h>
73 #include <gfx/gfx.h> // CONFIG_BITMAP_FMT
74
75 #include <QtGui/QPainter>
76 #include <QtGui/QImage>
77 #include <QtGui/QSizePolicy>
78 #include <QtCore/QSize>
79
80 // Display colors
81 #define LCD_FG_COLOR 0x0, 0x0, 0x0
82 #define LCD_BG_COLOR 0xBB, 0xCC, 0xBB
83
84
85 EmulLCD::EmulLCD(QWidget *parent, const char *name) :
86         QFrame(parent, name, Qt::WRepaintNoErase | Qt::WResizeNoErase),
87         fg_color(LCD_FG_COLOR),
88         bg_color(LCD_BG_COLOR)
89 {
90         // initialize bitmap
91         memset(raster, 0xAA, sizeof(raster));
92
93         // set widget frame
94         setFrameStyle(QFrame::Panel | QFrame::Sunken);
95         frame_width = frameWidth();
96 }
97
98
99 EmulLCD::~EmulLCD()
100 {
101         // nop
102 }
103
104
105 QSizePolicy EmulLCD::sizePolicy() const
106 {
107         return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false);
108 }
109
110
111 QSize EmulLCD::sizeHint() const
112 {
113         return QSize(
114                 WIDTH + frame_width * 2,
115                 HEIGHT + frame_width * 2);
116 }
117
118
119 void EmulLCD::paintEvent(QPaintEvent * /*event*/)
120 {
121         QPainter p(this);
122         QImage img(raster, WIDTH, HEIGHT, 1, NULL, 0, QImage::BigEndian);
123
124         p.setBackgroundMode(Qt::OpaqueMode);
125         p.setPen(fg_color);
126         p.setBackgroundColor(bg_color);
127         p.drawImage(frame_width, frame_width, img);
128 }
129
130 void EmulLCD::writeRaster(uint8_t *new_raster)
131 {
132 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
133
134         /* Straight copy */
135         memcpy(raster, new_raster, sizeof(raster));
136
137 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
138
139         /* Rotation */
140         for (int y = 0; y < HEIGHT; ++y)
141         {
142                 for (int xbyte = 0; xbyte < WIDTH/8; ++xbyte)
143                 {
144                         uint8_t v = 0;
145                         for (int xbit = 0; xbit < 8; ++xbit)
146                                 v |= (new_raster[(xbyte * 8 + xbit) + (y / 8) * WIDTH] & (1 << (y%8)) )
147                                         ? 0 : (1 << (7 - xbit));
148
149                         raster[y * ((WIDTH + 7) / 8) + xbyte] = v;
150                 }
151         }
152
153 #else
154         #error Unsupported bitmap format
155 #endif
156
157         repaint();
158 }
159
160
161
162 #include <gfx/gfx.h>
163 #include <cfg/debug.h>
164
165 DECLARE_WALL(wall_before_raster, WALL_SIZE)
166 /**
167  * Raster buffer to draw into.
168  *
169  * Bits in the bitmap bytes have vertical orientation,
170  * as required by the LCD driver.
171  */
172 static uint8_t lcd_raster[RASTER_SIZE(EmulLCD::WIDTH, EmulLCD::HEIGHT)];
173 DECLARE_WALL(wall_after_raster, WALL_SIZE)
174
175 /** Default LCD bitmap */
176 struct Bitmap lcd_bitmap;
177
178 /*extern "C"*/ void lcd_init(void)
179 {
180         //FIXME INIT_WALL(wall_before_raster);
181         //FIXME INIT_WALL(wall_after_raster);
182         gfx_bitmapInit(&lcd_bitmap, lcd_raster, EmulLCD::WIDTH, EmulLCD::HEIGHT);
183         gfx_bitmapClear(&lcd_bitmap);
184 }
185
186 /*extern "C"*/ void lcd_blitBitmap(Bitmap *bm)
187 {
188         //FIXME CHECK_WALL(wall_before_raster);
189         //FIXME CHECK_WALL(wall_after_raster);
190         emul->emulLCD->writeRaster(bm->raster);
191 }
192
193 #include "lcd_gfx_qt_moc.cpp"
194