]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
robomon: Map transformation changes.
authorMichal Vokac <vokac.m@gmail.com>
Fri, 11 Feb 2011 15:23:47 +0000 (16:23 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 11 Feb 2011 16:31:55 +0000 (17:31 +0100)
Transformation of map image from bitmap coordinates to playground coordinates changed. now it is done in map painting method. Added trasnparency.

src/robomon/Map.cpp
src/robomon/Map.h
src/robomon/RobomonAtlantis.cpp

index ece6b6bad91aa8d22d2679953778a4a8a4e26290..d36211570f6d2936d841e5ba59b6c6b8b3889afc 100644 (file)
 #include <robodim.h>
 #include <iostream>
 
-Map::Map(const QPen &pen, const QBrush &brush) :
+Map::Map() :
        QObject(), QGraphicsItem()
 {
        this->pen = pen;
        this->brush = brush;
        mapImage = QImage(MAP_WIDTH, MAP_HEIGHT, QImage::Format_ARGB32);
-       mapImage.fill(QColor(0, 0, 0, 200).rgba());
+       mapImage.fill(Qt::transparent);
        setVisible(false);
 }
 
@@ -44,22 +44,10 @@ void Map::paint(QPainter *painter,
        Q_UNUSED(widget);
        Q_UNUSED(painter);
 
-       painter->setPen(pen);
-       painter->setBrush(brush);
-
-       QTransform resize, mirror;
-       mirror.scale(1,-1);
-       resize.scale(MAP_WIDTH, MAP_HEIGHT);
-
-       painter->setTransform(mirror, true);
-       painter->setTransform(resize, true);
-
-       painter->drawImage(QPointF(0, -MAP_HEIGHT),mapImage);
-
-
+       painter->drawImage(QPointF(0, 0), mapImage);
 }
 
 void Map::setPixelColor(int x, int y, QColor color)
 {
-       mapImage.setPixel(x, y, color.rgb());
+       mapImage.setPixel(x, y, color.rgba());
 }
\ No newline at end of file
index 2f589580eed0848fc089f15a634072169159ac4e..e7ffc225b2c30b20a6ef108c4ba5f8bdd7640e59 100644 (file)
@@ -21,7 +21,7 @@ class Map : public QObject, public QGraphicsItem
        Q_OBJECT
        Q_INTERFACES(QGraphicsItem);
 public:
-       Map(const QPen &pen = QPen(), const QBrush &brush = QBrush());
+       Map();
        ~Map();
        QRectF boundingRect() const;
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
index fdf734f4cb3d9e90f3a27e791868ef4f18a2f6c5..94172078e0f71c978ab55bd6357ef32994e129aa 100644 (file)
@@ -319,8 +319,10 @@ void RobomonAtlantis::createRobots()
 
 void RobomonAtlantis::createMap()
 {
-       mapImage = new Map(QPen(Qt::lightGray), QBrush(Qt::NoBrush));
+       mapImage = new Map();
        mapImage->setZValue(3);
+       mapImage->setTransform(QTransform().scale(MAP_CELL_SIZE_MM, MAP_CELL_SIZE_MM), true);
+
 
        playgroundScene->addItem(mapImage);
 }
@@ -455,8 +457,8 @@ void RobomonAtlantis::paintMap()
 
         if (!map) return;
 
-       for(int i=0; i < MAP_WIDTH; i++) {
-               for(int j=0; j<MAP_HEIGHT; j++) {
+       for(int i = 0; i < MAP_WIDTH; i++) {
+               for(int j = 0; j < MAP_HEIGHT; j++) {
                         QColor color;
 
                         struct map_cell *cell = &map->cells[j][i];
@@ -490,7 +492,8 @@ void RobomonAtlantis::paintMap()
                         if (cell->flags & MAP_FLAG_DET_OBST)
                                 color = cyan;
 
-                        mapImage->setPixelColor(i, j, color);
+                       color.setAlpha(200);
+                        mapImage->setPixelColor(i, MAP_HEIGHT - j - 1, color);
                 }
        }
 }