Freeciv21
Develop your civilization from humble roots to a global empire
freeciv::renderer Class Reference

Renders the map on widgets. More...

#include <renderer.h>

+ Inheritance diagram for freeciv::renderer:
+ Collaboration diagram for freeciv::renderer:

Signals

void repaint_needed (const QRegion &where)
 

Public Member Functions

 renderer (QObject *parent=nullptr)
 Constructor. More...
 
virtual ~renderer ()=default
 
QPointF origin () const
 The origin of the view (the point at the top left corner) More...
 
void set_origin (const QPointF &origin)
 Changes the origin of the canvas (the point at the top left of the view). More...
 
double scale () const
 The scale (zoom) at which rendering is performed. More...
 
void set_scale (double scale)
 Changes the scale of the rendering (zooms in or out). More...
 
QSize viewport_size () const
 The current dimensions of the viewport. More...
 
void set_viewport_size (const QSize &size)
 Instructs the renderer to draw a viewport with a different size. More...
 
void render (QPainter &painter, const QRegion &region) const
 Renders the specified region of the visible portion of the map on painter. More...
 
void render (QPainter &painter, const QRect &area) const
 Renders the specified area of the visible portion of the map on painter. More...
 

Properties

QPointF origin
 
double scale
 

Private Slots

void unqueue_updates ()
 Processes all pending map updates and writes them to the map buffer. More...
 

Private Attributes

QPointF m_origin
 
double m_scale = 1.0
 
QSize m_viewport_size
 
map_updates_handlerm_updates
 

Detailed Description

Renders the map on widgets.

This class is used to draw the map. The position of the mapview is given by origin and zoom is set via the scale property.

Definition at line 20 of file renderer.h.

Constructor & Destructor Documentation

◆ renderer()

freeciv::renderer::renderer ( QObject *  parent = nullptr)
explicit

Constructor.

Definition at line 26 of file renderer.cpp.

◆ ~renderer()

virtual freeciv::renderer::~renderer ( )
virtualdefault

Member Function Documentation

◆ origin()

QPointF freeciv::renderer::origin ( ) const
inline

The origin of the view (the point at the top left corner)

Definition at line 30 of file renderer.h.

◆ render() [1/2]

void freeciv::renderer::render ( QPainter &  painter,
const QRect &  area 
) const

Renders the specified area of the visible portion of the map on painter.

This is meant to be used directly from paintEvent, so the position of area is relative to the viewport. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 88 of file renderer.cpp.

◆ render() [2/2]

void freeciv::renderer::render ( QPainter &  painter,
const QRegion &  region 
) const

Renders the specified region of the visible portion of the map on painter.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 75 of file renderer.cpp.

Referenced by map_view::paintEvent().

◆ repaint_needed

void freeciv::renderer::repaint_needed ( const QRegion &  where)
signal

◆ scale()

double freeciv::renderer::scale ( ) const
inline

The scale (zoom) at which rendering is performed.

Definition at line 34 of file renderer.h.

◆ set_origin()

void freeciv::renderer::set_origin ( const QPointF &  origin)

Changes the origin of the canvas (the point at the top left of the view).

Definition at line 36 of file renderer.cpp.

Referenced by map_view::center_on_tile(), and map_view::wheelEvent().

◆ set_scale()

void freeciv::renderer::set_scale ( double  scale)

Changes the scale of the rendering (zooms in or out).

A scale of 2 means that everything is 2x bigger.

Definition at line 47 of file renderer.cpp.

Referenced by map_view::set_scale_now().

◆ set_viewport_size()

void freeciv::renderer::set_viewport_size ( const QSize &  size)

Instructs the renderer to draw a viewport with a different size.

Definition at line 60 of file renderer.cpp.

Referenced by map_view::resizeEvent(), and mr_menu::save_image().

◆ unqueue_updates

void freeciv::renderer::unqueue_updates ( )
privateslot

Processes all pending map updates and writes them to the map buffer.

Definition at line 103 of file renderer.cpp.

Referenced by renderer().

◆ viewport_size()

QSize freeciv::renderer::viewport_size ( ) const
inline

The current dimensions of the viewport.

Definition at line 38 of file renderer.h.

Member Data Documentation

◆ m_origin

QPointF freeciv::renderer::m_origin
private

Definition at line 51 of file renderer.h.

Referenced by origin(), and set_origin().

◆ m_scale

double freeciv::renderer::m_scale = 1.0
private

Definition at line 52 of file renderer.h.

Referenced by scale(), set_scale(), and set_viewport_size().

◆ m_updates

map_updates_handler* freeciv::renderer::m_updates
private

Definition at line 54 of file renderer.h.

Referenced by renderer(), and unqueue_updates().

◆ m_viewport_size

QSize freeciv::renderer::m_viewport_size
private

Definition at line 53 of file renderer.h.

Referenced by set_origin(), set_scale(), set_viewport_size(), and viewport_size().

Property Documentation

◆ origin

QPointF freeciv::renderer::origin
readwrite

Definition at line 1 of file renderer.h.

Referenced by set_origin(), and map_view::wheelEvent().

◆ scale

double freeciv::renderer::scale
readwrite

Definition at line 1 of file renderer.h.

Referenced by render(), map_view::scale(), set_scale(), and unqueue_updates().