mkRPG
Public Types | Signals | Public Member Functions
MapPainter Class Reference

The MapPainter class that can paint a Map using a QPainter. More...

#include <mappainter.h>

Public Types

enum  Element {
  Nothing = 0, CellBackground = 1, Grid = 2, CellSelection = 4,
  CellHighlighting = 8, Objects = 16, All = 31
}
 The Element enum discribes the different elements that can be render. More...

Signals

void mapSizeChanged (QSize)
void viewCenterChanged (QPoint)

Public Member Functions

 MapPainter (QObject *parent=0)
 MapPainter (Map *m, QObject *parent=0)
void setPaintedElement (Element e, bool painted=true)
void setPaintedElements (Element e)
void setMap (Map *m)
void paint (QPainter &p)
const QImage & render ()
RlCoords viewCenter () const
void setViewCenter (RlCoords relativeCenter)
void setViewCenter (double relativeCenterX, double relativeCenterY)
void setViewCenterQuiet (double x, double y)
double scale () const
void setScale (double scale)
void setScaleDomain (double scaleMin, double scaleMax)
bool setHighlightedCell (const ClCoords &p)
bool setHighlightedCell (int i, int j)
QPoint highlightedCell () const
bool hasHighlightedCell () const
bool isCell (const ClCoords &c) const
void resize (QSize s)
void resize (int wi, int he)
QSize size () const
void zoom (double factor, QPointF fixedPoint)
QPair< bool, bool > move (PxCoords delta, QPointF center)
QSize virtualSize () const
PxCoords ptToPxl (PtCoords p) const
PtCoords pxlToPt (PxCoords p) const
PtCoords cooToPt (ClCoords p) const
ClCoords ptToCoo (PtCoords p) const
PxCoords cooToPxl (ClCoords p) const
ClCoords pxlToCoo (PxCoords p) const
PtCoords indToPt (int i, int j) const
const QColor & selectedCellColor () const
const QColor & preSelectedCellColor () const
void setSelectedCellColor (const QColor &c)
void setPreSelectedCellColor (const QColor &c)

Detailed Description

The MapPainter class that can paint a Map using a QPainter.

The class take charge of the different ratios of the map rendering and the area in which it will be rendered.

Note:
The view is kept updated with the associated map at each paint or render call. It is thus just needed to call one of these functions to update the view after a modification.

To ensure a type checking security about the different types of coordinates that are used, four different types that inherit from QPointF are used : RlCoords, ClCoords, PtCoords and PxCoords


Member Enumeration Documentation

The Element enum discribes the different elements that can be render.

This includes both map's objects and user interaction and editing elements.

Element value can be used as flags using the operators operator| "|", operator| "&", operator| "^".

See also:
Cell, CellType
Enumerator:
Nothing 

Represent no elements

CellBackground 

The bacground associated to the cell type

Grid 

A thin grid that separate cells

CellSelection 

Graphical information about the selection state

CellHighlighting 

Graphical visualisation of the cells the mouse is over

Objects 

The objects that lay on the cells

All 

Represent all elements


Constructor & Destructor Documentation

MapPainter::MapPainter ( QObject *  parent = 0)

Constructs a new MapPainter with a default size of (42,42).

MapPainter::MapPainter ( Map m,
QObject *  parent = 0 
)

Constructs a new MapPainter with a default size of (42,42), and loads the map m.


Member Function Documentation

Converts cells indice to virtual point coordinates

Convenient function equivalent to ptToPxl(cooToPt(p))

Returns true if a cell is highligthed.

See also:
highlightedCell, setHighlightedCell
QPoint MapPainter::highlightedCell ( ) const

Returns the integer index of the cell the is highlighted.

See also:
setHighlightedCell, hasHighlightedCell
PtCoords MapPainter::indToPt ( int  i,
int  j 
) const

Converts to coordinates

bool MapPainter::isCell ( const ClCoords c) const

Returns true if the coordinate c correspond to a cell.

void MapPainter::mapSizeChanged ( QSize  ) [signal]

This signal is emitted when the total size of the map's view change.

It appends mainly during scale change and modification on the map (resize, angles setting, ...).

QPair< bool, bool > MapPainter::move ( PxCoords  delta,
QPointF  center 
)

Change the center position from the given center and a pixel difference.

The return value indicate if the expected center was valid (regarding x or y coordinate).

See also:
setViewCenter
void MapPainter::paint ( QPainter &  p)

Draws the map in the QPaintDevice.

See also:
render
const QColor & MapPainter::preSelectedCellColor ( ) const

Returns the color of the filter that is applied to pre-selected cells.

See also:
setPreSelectedCellColor, selectedCellColor

Converts virtual point to cell indice

Converts virtual point to real pixel coordinates

Convenient function equivalent to ptToCoo(pxlToPt(p))

Converts real pixel to virtual point coordinates

const QImage & MapPainter::render ( )

Provides a QImage with a view of the map.

See also:
paint
void MapPainter::resize ( QSize  s)

Change the size of the view, ie the rectangle in which the map will be render.

See also:
size
void MapPainter::resize ( int  wi,
int  he 
)

This is an overload function, see resize

double MapPainter::scale ( ) const

Returns the current scale of the view.

See also:
setScale
const QColor & MapPainter::selectedCellColor ( ) const

Returns the color of the filter that is applied to selected cells.

See also:
setSelectedCellColor, preSelectedCellColor

Sets the highligthed cell to the one at the ClCoords p

See also:
highlightedCell, hasHighlightedCell
bool MapPainter::setHighlightedCell ( int  i,
int  j 
)

This is an overload function, see setViewCenter.

void MapPainter::setMap ( Map m)

Loads the map, computing the new size of the view area.

void MapPainter::setPaintedElement ( MapPainter::Element  e,
bool  painted = true 
)

Enables or disables the render of an element.

See also:
setPaintedElements

Sets the rendered elements.

See also:
setPaintedElement
void MapPainter::setPreSelectedCellColor ( const QColor &  c)

Sets the color of the filter that is applied to pre-selected cells.

See also:
preSelectedCellColor, setSelectedCellColor
void MapPainter::setScale ( double  scale)

Sets the current view scale. This closest value in the scale domain will be used.

See also:
scale, setScaleDomain
void MapPainter::setScaleDomain ( double  scaleMin,
double  scaleMax 
)

Sets the valid values for the scale.

See also:
scale, setScale
void MapPainter::setSelectedCellColor ( const QColor &  c)

Sets the color of the filter that is applied to selected cells.

See also:
selectedCellColor, setPreSelectedCellColor
void MapPainter::setViewCenter ( RlCoords  relativeCenter)

Change the view center, using relative coordinates.

If the new center is invalid (the view exceed the map area), the closest valid center is used.

See also:
viewCenter
void MapPainter::setViewCenter ( double  relativeCenterX,
double  relativeCenterY 
)

This is an overload function, see setViewCenter.

void MapPainter::setViewCenterQuiet ( double  x,
double  y 
)

does the same as setViewCenter, without emitting the signal viewCenterChanged to avoid event loop.

QSize MapPainter::size ( ) const

Return the size of the rectangle in which the map is render. This is also the size of the image returned by render.

See also:
resize

Return the relative coordinates of the current view center.

See also:
setViewCenter
void MapPainter::viewCenterChanged ( QPoint  ) [signal]

This signal is emitted when the center of the map change.

It appends mainly during moving on the view and zooming.

QSize MapPainter::virtualSize ( ) const

Computes the total size of the image of the map

void MapPainter::zoom ( double  factor,
QPointF  fixedPoint 
)

Multiplying the scale of the view by factor, trying to leave the point center at the same position.

Note:
It is not always possible to keep this point fixed, in particulary when the view is resulting view would exceed the map region. In that case, the center is adapt to minimise the difference.

The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines