![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
Iterates over all map tiles that intersect with a rectangle in GUI coordinates. More...
#include <view_map_geometry.h>
Collaboration diagram for freeciv::gui_rect_iterator:Public Member Functions | |
| gui_rect_iterator (const struct tileset *t, const QRect &rect) | |
| Constructor. More... | |
| bool | has_corner () const |
| Checks whether the current iteration point has a corner. More... | |
| bool | has_edge () const |
| Checks whether the current iteration point has an edge. More... | |
| bool | has_tile () const |
| Checks whether the current iteration point has a non-null tile. More... | |
| const tile_corner & | corner () const |
Retrieves the current corner. Only valid if has_corner is true. More... | |
| const tile_edge & | edge () const |
Retrieves the current edge. Only valid if has_edge is true. More... | |
| const ::tile * | tile () const |
Retrieves the current tile. Only valid if has_tile is true. More... | |
| int | x () const |
| Retrieves the x position of the current item. More... | |
| int | y () const |
| Retrieves the y position of the current item. More... | |
| bool | next () |
| Iterates to the next item. More... | |
Private Attributes | |
| bool | m_isometric |
| int | m_index |
| int | m_count |
| int | m_r1 |
| int | m_r2 |
| int | m_w |
| int | m_h |
| int | m_x0 |
| int | m_y0 |
| int | m_x1 |
| int | m_y1 |
| int | m_xi |
| int | m_yi |
| tile_corner | m_corner |
| tile_edge | m_edge |
| ::tile * | m_tile = nullptr |
| bool | m_has_corner = false |
| bool | m_has_edge = false |
| bool | m_has_tile = false |
Iterates over all map tiles that intersect with a rectangle in GUI coordinates.
The order of iteration is guaranteed to satisfy the painter's algorithm. The iteration covers not only tiles but tile edges and corners.
Iteration is performed by repeatedly calling next and querying the current available items using has_corner, has_edge, or has_tile. If the item type matches your needs, you can retrieve the corner, edge, or tile using the corresponding functions.
Typical usage is as follows:
One can also retrieve the canvas position of the current item using the x and y functions.
The order of iteration depends on the map topology. The basic idea is to operate on a rectangular grid, which works pretty nicely when the topology is neither isometric nor hexagonal:
In the diagram above, "t" stands for tile, "e" for edge, and "c" for corner. Iteration takes place from left to right and from top to bottom, i.e. in reading order.
Things get more complicated for isometric grids, as some points on the grid don't correspond to anything and need to be skipped. They are represented with dots in the diagram below:
For hexagonal grids, some points are corners and edges at the same time:
During iteration, it may happen that some tiles are null because they are not visible to the current player. In this case, has_tile will return false.
Definition at line 19 of file view_map_geometry.h.
| freeciv::gui_rect_iterator::gui_rect_iterator | ( | const struct tileset * | t, |
| const QRect & | rect | ||
| ) |
Constructor.
Definition at line 148 of file view_map_geometry.cpp.
|
inline |
Retrieves the current corner. Only valid if has_corner is true.
Definition at line 33 of file view_map_geometry.h.
|
inline |
Retrieves the current edge. Only valid if has_edge is true.
Definition at line 36 of file view_map_geometry.h.
|
inline |
Checks whether the current iteration point has a corner.
Definition at line 24 of file view_map_geometry.h.
|
inline |
Checks whether the current iteration point has an edge.
Definition at line 27 of file view_map_geometry.h.
|
inline |
Checks whether the current iteration point has a non-null tile.
Definition at line 30 of file view_map_geometry.h.
| bool freeciv::gui_rect_iterator::next | ( | ) |
Iterates to the next item.
Returns false once the end of the iteration has been reached.
Definition at line 183 of file view_map_geometry.cpp.
Referenced by editor_end_selection_rectangle(), show_city_descriptions(), show_tile_labels(), and update_map_canvas().
|
inline |
Retrieves the current tile. Only valid if has_tile is true.
Definition at line 39 of file view_map_geometry.h.
|
inline |
Retrieves the x position of the current item.
Definition at line 42 of file view_map_geometry.h.
|
inline |
Retrieves the y position of the current item.
Definition at line 45 of file view_map_geometry.h.
|
private |
Definition at line 56 of file view_map_geometry.h.
|
private |
Definition at line 51 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 57 of file view_map_geometry.h.
|
private |
Definition at line 52 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and y().
|
private |
Definition at line 59 of file view_map_geometry.h.
Referenced by has_corner(), and next().
|
private |
Definition at line 59 of file view_map_geometry.h.
Referenced by has_edge(), and next().
|
private |
Definition at line 59 of file view_map_geometry.h.
Referenced by has_tile(), and next().
|
private |
Definition at line 51 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 50 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 52 of file view_map_geometry.h.
Referenced by gui_rect_iterator().
|
private |
Definition at line 52 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), x(), and y().
|
private |
Definition at line 58 of file view_map_geometry.h.
|
private |
Definition at line 52 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and x().
|
private |
Definition at line 53 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 53 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 54 of file view_map_geometry.h.
|
private |
Definition at line 53 of file view_map_geometry.h.
Referenced by gui_rect_iterator(), and next().
|
private |
Definition at line 53 of file view_map_geometry.h.
Referenced by gui_rect_iterator().
|
private |
Definition at line 54 of file view_map_geometry.h.