obstacle = new QGraphicsEllipseItem(0, 0, 300, 300);
obstacle->translate(-150,-150);
obstacle->setZValue(5);
- obstacle->setBrush(QBrush(QColor(blue)));
+ obstacle->setBrush(QBrush(QColor(0, 0, 255, 200)));
obstacle->setVisible(false);
this->addItem(obstacle);
+
+ initMap();
}
PlaygroundScene::~PlaygroundScene()
else
obstacle->setVisible(false);
}
+
+void PlaygroundScene::initMap()
+{
+ this->map = new QGraphicsItemGroup();
+ for(int i=0; i < MAP_WIDTH; i++) {
+ for(int j=0; j<MAP_HEIGHT; j++) {
+ rects[i][j] = new QGraphicsRectItem(
+ QRectF(i*MAP_CELL_SIZE_MM, (MAP_HEIGHT-1-j)*MAP_CELL_SIZE_MM,
+ MAP_CELL_SIZE_MM,MAP_CELL_SIZE_MM));
+ rects[i][j]->setPen(QPen());
+ rects[i][j]->setBrush(QBrush(Qt::lightGray));
+ map->addToGroup(rects[i][j]);
+ }
+ }
+ map->setVisible(false);
+ map->setZValue(4);
+ addItem(map);
+}
+
+void PlaygroundScene::showMap(int show)
+{
+ map->setVisible(show);
+}
+
+void PlaygroundScene::setMapColor(int x, int y, QColor color)
+{
+ color.setAlpha(200);
+ rects[x][y]->setBrush(QBrush(color));
+}
#define PLAYGROUND_SCENE_H
#include <QGraphicsScene>
+#include <map.h>
class PlaygroundScene : public QGraphicsScene
{
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
static QPointF scene2world(QPointF scenePos);
static QPointF world2scene(QPointF worldPos);
+ void setMapColor(int x, int y, QColor color);
signals:
void obstacleChanged(QPointF pos);
private:
- void createPlaygroundEurobot2007();
- void createPlaygroundEurobot2008();
+ void initMap();
+ QGraphicsItemGroup *map;
+ QGraphicsRectItem *rects[MAP_WIDTH][MAP_HEIGHT]; // This must be slow - convert to pixmap. -- M.S.
QGraphicsEllipseItem *obstacle;
public slots:
void showObstacle(int val);
+ void showMap(int show);
};
#endif
disconnect(showMapPushButton, SIGNAL(clicked()), this, SLOT(showMap()));
connect(showMapPushButton, SIGNAL(clicked()),
this, SLOT(showPlayground()));
+ playgroundScene->showMap(true);
}
void RobomonAtlantis::showPlayground()
disconnect(showMapPushButton, SIGNAL(clicked()),
this, SLOT(showPlayground()));
connect(showMapPushButton, SIGNAL(clicked()), this, SLOT(showMap()));
+ playgroundScene->showMap(false);
}
void RobomonAtlantis::paintMap()
{
using namespace Qt;
- static QGraphicsRectItem *rects[MAP_WIDTH][MAP_HEIGHT];
- static bool firstMap = true;
int x, y;
struct map *map = ShmapIsMapInit();
for(int i=0; i < MAP_WIDTH; i++) {
for(int j=0; j<MAP_HEIGHT; j++) {
- x = TOP_LEFT_X+i*cellSize;
- y = TOP_LEFT_Y+j*cellSize;
-
- if(firstMap) {
- rects[i][j] = playgroundScene->addRect(
- QRectF(x,y,cellSize,cellSize),
- QPen(QBrush(Qt::black),
- 1,
- Qt::SolidLine,
- Qt::FlatCap,
- Qt::BevelJoin),
- QBrush(Qt::lightGray));
- rects[i][j]->setZValue(4);
- }
-
QColor color;
struct map_cell *cell = &map->cells[j][i];
if (cell->flags & MAP_FLAG_DET_OBST)
color = cyan;
- rects[i][j]->setBrush(QBrush(color));
+ playgroundScene->setMapColor(i, j, color);
}
}
- firstMap = false;
}
void RobomonAtlantis::setSimulation(int state)
if (sharedMemoryOpened)
return;
- cellSize = PG_X / MAP_WIDTH;
-
sharedSegmentSize = sizeof(char) * MAP_WIDTH * MAP_HEIGHT;
/* Get segment identificator in a read only mode */
class QProgressBar;
class QFont;
-#define PG_X 600
-#define PG_Y 420
-
-#define TOP_LEFT QPointF(10,0)
-#define TOP_LEFT_X 10
-#define TOP_LEFT_Y 0
-
class RobomonAtlantis : public QWidget
{
Q_OBJECT
/* map */
void openSharedMemory();
bool sharedMemoryOpened;
- int cellSize;
QTimer *mapTimer;
/* obstacle simulation */