]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robomon/Map.cpp
robomon: Map changed from rectangles to bitmap.
[eurobot/public.git] / src / robomon / Map.cpp
1 /*
2  * Map.cpp      11/01/31
3  *
4  * Draw a map on the playground.
5  *
6  * Copyright: (c) 2007 CTU Dragons
7  *            CTU FEE - Department of Control Engineering
8  * Authors: Michal Vokac, Michal Sojka
9  * License: GNU GPL v.2
10  */
11
12 #include <math.h>
13 #include <QPen>
14
15 #include "PlaygroundScene.h"
16 #include "Map.h"
17 #include <map.h>
18 #include <robodim.h>
19 #include <iostream>
20
21 Map::Map(const QPen &pen, const QBrush &brush) :
22         QObject(), QGraphicsItem()
23 {
24         this->pen = pen;
25         this->brush = brush;
26         mapImage = QImage(MAP_WIDTH, MAP_HEIGHT, QImage::Format_ARGB32);
27         mapImage.fill(QColor(0, 0, 0, 200).rgba());
28         setVisible(false);
29 }
30
31 Map::~Map()
32 {
33 }
34
35 QRectF Map::boundingRect() const
36 {
37         return QRectF(0,0,PLAYGROUND_WIDTH_MM,PLAYGROUND_HEIGHT_MM);
38 }
39
40 void Map::paint(QPainter *painter,
41                 const QStyleOptionGraphicsItem *option, QWidget *widget)
42 {
43         Q_UNUSED(option);
44         Q_UNUSED(widget);
45         Q_UNUSED(painter);
46
47         painter->setPen(pen);
48         painter->setBrush(brush);
49         painter->drawImage(QPointF(0,0),mapImage) ;
50 }
51
52 void Map::setPixelColor(int x, int y, QColor color)
53 {
54         QRgb value;
55
56         value = color.rgb();
57
58         mapImage.setPixel(x, y, value);
59 }