From: Michal Vokac Date: Fri, 11 Feb 2011 15:23:47 +0000 (+0100) Subject: robomon: Map transformation changes. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/eurobot/public.git/commitdiff_plain/f98978f551477df7a71eda436f72e59985749b76 robomon: Map transformation changes. Transformation of map image from bitmap coordinates to playground coordinates changed. now it is done in map painting method. Added trasnparency. --- diff --git a/src/robomon/Map.cpp b/src/robomon/Map.cpp index ece6b6ba..d3621157 100644 --- a/src/robomon/Map.cpp +++ b/src/robomon/Map.cpp @@ -18,13 +18,13 @@ #include #include -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 diff --git a/src/robomon/Map.h b/src/robomon/Map.h index 2f589580..e7ffc225 100644 --- a/src/robomon/Map.h +++ b/src/robomon/Map.h @@ -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); diff --git a/src/robomon/RobomonAtlantis.cpp b/src/robomon/RobomonAtlantis.cpp index fdf734f4..94172078 100644 --- a/src/robomon/RobomonAtlantis.cpp +++ b/src/robomon/RobomonAtlantis.cpp @@ -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; jcells[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); } } }