4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2006, 2008 Develer S.r.l. (http://www.develer.com/)
34 * \author Bernie Innocenti <bernie@codewiz.org>
36 * \brief Custom control for graphics LCD emulation (implementation)
39 #include "lcd_gfx_qt.h"
40 #include <emul/emul.h>
41 #include <cfg/debug.h>
42 #include <gfx/gfx.h> // CONFIG_BITMAP_FMT
44 #include <QtGui/QPainter>
45 #include <QtGui/QImage>
46 #include <QtGui/QSizePolicy>
47 #include <QtCore/QSize>
50 #define LCD_FG_COLOR 0x0, 0x0, 0x0
51 #define LCD_BG_COLOR 0xBB, 0xCC, 0xBB
54 EmulLCD::EmulLCD(QWidget *parent) :
56 fg_color(LCD_FG_COLOR),
57 bg_brush(QColor(LCD_BG_COLOR))
59 // Optimized rendering: we repaint everything anyway
60 setAttribute(Qt::WA_NoSystemBackground);
63 memset(raster, 0xAA, sizeof(raster));
66 setFrameStyle(QFrame::Panel | QFrame::Sunken);
67 frame_width = frameWidth();
69 setMinimumSize(WIDTH + frame_width * 2, HEIGHT + frame_width * 2);
71 #if CONFIG_EMULLCD_SCALE
72 QSizePolicy pol = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred, QSizePolicy::Frame);
73 pol.setHeightForWidth(true);
75 QSizePolicy pol = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::Frame);
86 #if CONFIG_EMULLCD_SCALE
87 int EmulLCD::heightForWidth(int w) const
92 h = (w * HEIGHT + WIDTH/2) / WIDTH;
97 #endif // CONFIG_EMULLCD_SCALE
99 void EmulLCD::paintEvent(QPaintEvent * /*event*/)
102 QImage img(raster, WIDTH, HEIGHT, QImage::Format_Mono);
104 #if CONFIG_EMULLCD_SCALE
105 int w = width() - frame_width * 2;
106 int h = height() - frame_width * 2;
107 if ((w != WIDTH) || (h != HEIGHT))
109 p.scale((qreal)w / WIDTH, (qreal)h / HEIGHT);
110 //p.setRenderHint(QPainter::SmoothPixmapTransform);
112 #endif // CONFIG_EMULLCD_SCALE
114 p.setBackgroundMode(Qt::OpaqueMode);
115 p.setBackground(bg_brush);
118 p.drawImage(QPoint(frame_width, frame_width), img);
121 void EmulLCD::writeRaster(uint8_t *new_raster)
123 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
126 //memcpy(raster, new_raster, sizeof(raster));
129 for (int i = 0; i < (int)sizeof(raster); ++i)
130 raster[i] = ~new_raster[i];
132 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
134 // Rotation + inversion
135 for (int y = 0; y < HEIGHT; ++y)
137 for (int xbyte = 0; xbyte < WIDTH/8; ++xbyte)
140 for (int xbit = 0; xbit < 8; ++xbit)
141 v |= (new_raster[(xbyte * 8 + xbit) + (y / 8) * WIDTH] & (1 << (y%8)) )
142 ? (1 << (7 - xbit)) : 0;
144 raster[y * ((WIDTH + 7) / 8) + xbyte] = v;
148 #error Unsupported bitmap format
157 #include <cfg/debug.h>
159 DECLARE_WALL(wall_before_raster, WALL_SIZE)
161 * Raster buffer to draw into.
163 * Bits in the bitmap bytes have vertical orientation,
164 * as required by the LCD driver.
166 static uint8_t lcd_raster[RAST_SIZE(EmulLCD::WIDTH, EmulLCD::HEIGHT)];
167 DECLARE_WALL(wall_after_raster, WALL_SIZE)
169 /** Default LCD bitmap */
170 struct Bitmap lcd_bitmap;
172 /*extern "C"*/ void lcd_init(void)
174 //FIXME INIT_WALL(wall_before_raster);
175 //FIXME INIT_WALL(wall_after_raster);
176 gfx_bitmapInit(&lcd_bitmap, lcd_raster, EmulLCD::WIDTH, EmulLCD::HEIGHT);
177 gfx_bitmapClear(&lcd_bitmap);
180 /*extern "C"*/ void lcd_blitBitmap(Bitmap *bm)
182 //FIXME CHECK_WALL(wall_before_raster);
183 //FIXME CHECK_WALL(wall_after_raster);
184 emul->emulLCD->writeRaster(bm->raster);
187 #include "lcd_gfx_qt_moc.cpp"