mkRPG
src/editor/Game/mappainter.h
Go to the documentation of this file.
00001 #ifndef MAPPAINTER_H
00002 #define MAPPAINTER_H
00003 
00004 
00005 // Hint : before to read this file, fold all comments blocks/
00006 // all blocks and unfold the class you want to see. :)
00007 
00008 
00025 #include "map.h"
00026 #include "GUI/options.h"
00027 
00028 #define MINMAX(a,x,b) std::min(std::max(a,x),b)
00029 
00037 class RlCoords : public QPointF
00038 {
00039 public:
00040     RlCoords() : QPointF(0,0){}
00041     explicit RlCoords(qreal x, qreal y) : QPointF(x,y){}
00042     explicit RlCoords(const QPointF &p) : QPointF(p){}
00043 };
00044 
00053 class ClCoords : public QPointF
00054 {
00055 public:
00056     ClCoords() : QPointF(0,0){}
00057     explicit ClCoords(qreal x, qreal y) : QPointF(x,y){}
00058     explicit ClCoords(const QPointF &p) : QPointF(p){}
00059 };
00060 
00069 class PtCoords : public QPointF
00070 {
00071 public:
00072     PtCoords() : QPointF(0,0){}
00073     explicit PtCoords(qreal x, qreal y) : QPointF(x,y){}
00074     explicit PtCoords(const QPointF &p) : QPointF(p){}
00075 };
00076 
00084 class PxCoords : public QPointF
00085 {
00086 public:
00087     PxCoords() : QPointF(0,0){}
00088     explicit PxCoords(qreal x, qreal y) : QPointF(x,y){}
00089     explicit PxCoords(const QPointF &p) : QPointF(p){}
00090     PxCoords(const QPoint &p) : QPointF(p){}
00091     PxCoords(int x, int y) : QPointF(x,y){}
00092 };
00093 
00094 
00095 
00112 class MapPainter : public QObject
00113 {
00114     // TODO Mode lecture seule.
00115     Q_OBJECT
00116 public:
00129     enum Element{
00130         Nothing = 0,            
00131         CellBackground = 1,     
00132         Grid = 2,               
00133         CellSelection = 4,      
00134         CellHighlighting = 8,   
00135         Objects = 16,           
00136         All = 31                
00137     };
00138     MapPainter(QObject *parent = 0); 
00141     MapPainter(Map *m, QObject *parent = 0); 
00145     void setPaintedElement(Element e, bool painted = true); 
00150     void setPaintedElements(Element e); 
00156     void setMap(Map* m); 
00159     void paint(QPainter& p); 
00164     const QImage& render(); 
00170     RlCoords viewCenter() const; 
00175     void setViewCenter(RlCoords relativeCenter); 
00182     void setViewCenter(double relativeCenterX, double relativeCenterY); 
00185     void setViewCenterQuiet(double x, double y); 
00189     double scale() const; 
00194     void setScale(double scale); 
00199     void setScaleDomain(double scaleMin, double scaleMax); 
00205     bool setHighlightedCell(const ClCoords& p); 
00210     bool setHighlightedCell(int i, int j); 
00213     QPoint highlightedCell() const; 
00218     bool hasHighlightedCell() const; 
00223     bool isCell(const ClCoords &c) const; 
00227     void resize(QSize s); 
00233     void resize(int wi, int he); 
00236     QSize size() const; 
00242     void zoom(double factor, QPointF fixedPoint); 
00249     QPair<bool,bool> move(PxCoords delta, QPointF center); 
00258     QSize virtualSize() const; 
00262     PxCoords ptToPxl(PtCoords p) const; 
00265     PtCoords pxlToPt(PxCoords p) const; 
00268     PtCoords cooToPt(ClCoords p) const; 
00271     ClCoords ptToCoo(PtCoords p) const; 
00274     PxCoords cooToPxl(ClCoords p) const; 
00277     ClCoords pxlToCoo(PxCoords p) const; 
00280     PtCoords indToPt(int i, int j) const; 
00284     const QColor &selectedCellColor() const; 
00289     const QColor &preSelectedCellColor() const; 
00294     void setSelectedCellColor(const QColor &c); 
00299     void setPreSelectedCellColor(const QColor &c); 
00305 signals:
00306     void mapSizeChanged(QSize); 
00312     void viewCenterChanged(QPoint); 
00319 private slots:
00320     void updateMap(); 
00324 private:
00325     inline void globalViewChanged();
00326     void updateBackground();
00327     void updateViewParameters();
00328 
00329     inline void changeBackgroundSize();
00330     inline void changeBackgroundDistortion();
00331     QImage &getBackground(const CellType *ct);
00332 
00333     Map* map;
00334     Element displayed;
00335     QMatrix isometricTransform; // Matrix of the image transformation
00336     int pWidth, pHeight;
00337     int nbCellsX, nbCellsY;
00338     int mapWidth, mapHeight;
00339     int selCellX, selCellY;
00340     double angleX, angleY;
00341     double centerX, centerY;
00342     double centerVarX, centerVarY;
00343     double viewScale;
00344     double ratioFactor;
00345     QSize cellSize;
00346 
00347     QColor selColor, preSelColor;
00348 
00349     PtCoords *intersec;
00350     bool changesOccured;
00351     QDateTime lastMapUpdate;
00352     QMap<int, QImage> cellBackgrounds; // Contains the distorted images
00353     QMap<int, QImage> scaledCellBackgrounds;
00354 
00355     QImage im;
00356 
00357     int iMin, iMax, jMin, jMax;
00358 
00359 
00360 };
00361 inline MapPainter::Element operator|(MapPainter::Element a, MapPainter::Element b){
00362     return static_cast<MapPainter::Element>(static_cast<int>(a)|static_cast<int>(b));
00363 }
00366 inline MapPainter::Element operator&(MapPainter::Element a, MapPainter::Element b){
00367     return static_cast<MapPainter::Element>(static_cast<int>(a)&static_cast<int>(b));
00368 }
00371 inline MapPainter::Element operator^(MapPainter::Element a, MapPainter::Element b){
00372     return static_cast<MapPainter::Element>(static_cast<int>(a)&!static_cast<int>(b));
00373 }
00379 #endif // MAPPAINTER_H
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines