Doc fixes.
[bertos.git] / drv / lcd_gfx_qt.cpp
old mode 100755 (executable)
new mode 100644 (file)
index e4582a3..e42be22
@@ -1,8 +1,33 @@
 /**
  * \file
  * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
- * This file is part of DevLib - See README.devlib for information.
+ *
  * -->
  *
  * \version $Id$
  * \brief Custom control for graphics LCD emulation (interface)
  */
 
-/*#*
- *#* $Log$
- *#* Revision 1.2  2006/01/17 02:30:43  bernie
- *#* Fix QImage format.
- *#*
- *#* Revision 1.1  2006/01/16 03:51:35  bernie
- *#* Add LCD Qt emulator.
- *#*
- *#*/
-
 #include "lcd_gfx_qt.h"
 #include <emul/emul.h>
 #include <cfg/debug.h>
+#include <gfx/gfx.h> // CONFIG_BITMAP_FMT
 
-#include <qpainter.h>
-#include <qimage.h>
-#include <qsizepolicy.h>
-#include <qsize.h>
+#include <QtGui/QPainter>
+#include <QtGui/QImage>
+#include <QtGui/QSizePolicy>
+#include <QtCore/QSize>
 
 // Display colors
 #define LCD_FG_COLOR 0x0, 0x0, 0x0
@@ -37,7 +53,7 @@
 
 
 EmulLCD::EmulLCD(QWidget *parent, const char *name) :
-       QFrame(parent, name, WRepaintNoErase | WResizeNoErase),
+       QFrame(parent, name, Qt::WRepaintNoErase | Qt::WResizeNoErase),
        fg_color(LCD_FG_COLOR),
        bg_color(LCD_BG_COLOR)
 {
@@ -70,22 +86,45 @@ QSize EmulLCD::sizeHint() const
 }
 
 
-void EmulLCD::drawContents(QPainter *p)
+void EmulLCD::paintEvent(QPaintEvent * /*event*/)
 {
+       QPainter p(this);
        QImage img(raster, WIDTH, HEIGHT, 1, NULL, 0, QImage::BigEndian);
 
-       p->setBackgroundMode(OpaqueMode);
-       p->setPen(fg_color);
-       p->setBackgroundColor(bg_color);
-       p->drawImage(frame_width, frame_width, img);
+       p.setBackgroundMode(Qt::OpaqueMode);
+       p.setPen(fg_color);
+       p.setBackgroundColor(bg_color);
+       p.drawImage(frame_width, frame_width, img);
 }
 
 void EmulLCD::writeRaster(uint8_t *new_raster)
 {
+#if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
+
+       /* Straight copy */
        memcpy(raster, new_raster, sizeof(raster));
 
-       QPainter p(this);
-       drawContents(&p);
+#elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
+
+       /* Rotation */
+       for (int y = 0; y < HEIGHT; ++y)
+       {
+               for (int xbyte = 0; xbyte < WIDTH/8; ++xbyte)
+               {
+                       uint8_t v = 0;
+                       for (int xbit = 0; xbit < 8; ++xbit)
+                               v |= (new_raster[(xbyte * 8 + xbit) + (y / 8) * WIDTH] & (1 << (y%8)) )
+                                       ? 0 : (1 << (7 - xbit));
+
+                       raster[y * ((WIDTH + 7) / 8) + xbyte] = v;
+               }
+       }
+
+#else
+       #error Unsupported bitmap format
+#endif
+
+       repaint();
 }
 
 
@@ -93,30 +132,31 @@ void EmulLCD::writeRaster(uint8_t *new_raster)
 #include <gfx/gfx.h>
 #include <cfg/debug.h>
 
-/*!
+DECLARE_WALL(wall_before_raster, WALL_SIZE)
+/**
  * Raster buffer to draw into.
+ *
  * Bits in the bitmap bytes have vertical orientation,
  * as required by the LCD driver.
  */
-DECLARE_WALL(wall_before_raster, WALL_SIZE)
-static uint8_t lcd_raster[(EmulLCD::WIDTH + 7 / 8) * EmulLCD::HEIGHT];
+static uint8_t lcd_raster[RAST_SIZE(EmulLCD::WIDTH, EmulLCD::HEIGHT)];
 DECLARE_WALL(wall_after_raster, WALL_SIZE)
 
-/*! Default LCD bitmap */
+/** Default LCD bitmap */
 struct Bitmap lcd_bitmap;
 
-extern "C" void lcd_init(void)
+/*extern "C"*/ void lcd_init(void)
 {
-       //INIT_WALL(wall_before_raster);
-       //INIT_WALL(wall_after_raster);
+       //FIXME INIT_WALL(wall_before_raster);
+       //FIXME INIT_WALL(wall_after_raster);
        gfx_bitmapInit(&lcd_bitmap, lcd_raster, EmulLCD::WIDTH, EmulLCD::HEIGHT);
        gfx_bitmapClear(&lcd_bitmap);
 }
 
-extern "C" void lcd_blit_bitmap(Bitmap *bm)
+/*extern "C"*/ void lcd_blitBitmap(Bitmap *bm)
 {
-       //CHECK_WALL(wall_before_raster);
-       //CHECK_WALL(wall_after_raster);
+       //FIXME CHECK_WALL(wall_before_raster);
+       //FIXME CHECK_WALL(wall_after_raster);
        emul->emulLCD->writeRaster(bm->raster);
 }