#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);
}
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
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);
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);
}
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];
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);
}
}
}