Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tilespec.cpp #450

Merged
merged 24 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fe0aa32
tilespec.cpp: turn drawn_sprites * into vector
lmoureaux Apr 18, 2021
af8183e
Move mapview layer stuff out of tilespec.h
lmoureaux Apr 24, 2021
11380d1
Add a class for map layers
lmoureaux Apr 24, 2021
279d15c
tilespec.cpp: rename layers -> terrain_layers
lmoureaux Apr 24, 2021
e7a9c56
Expose layers through layer objects
lmoureaux Apr 24, 2021
c53d389
Use layer::fill_sprite_array() when rendering
lmoureaux Apr 24, 2021
b3f0a3f
Improve const-correctness in the map drawing code
lmoureaux Apr 25, 2021
e5f57d7
Add constructors to drawn_sprite
lmoureaux Apr 25, 2021
e82f550
Eliminate ADD_SPRITE and ADD_SPRITE_SIMPLE
lmoureaux Apr 25, 2021
82f5a33
Reroute drawing LAYER_BACKGROUND through a class
lmoureaux Apr 25, 2021
4993bd5
Migrate the LAYER_BACKGROUND code to its class
lmoureaux Apr 26, 2021
ec8877f
Remove extraneous blank lines
lmoureaux Apr 26, 2021
7eb092f
Fix "documentation" of tileset layer "Special1"
lmoureaux Aug 18, 2021
ee83835
Simplify fill_basic_extra_sprite_array
lmoureaux Aug 19, 2021
5a24b0a
Move LAYER_SPECIAL* to a class
lmoureaux Aug 19, 2021
d57535d
Add a layer for base flags
lmoureaux Aug 19, 2021
44b18e7
Factor out creating layer objects
lmoureaux Aug 21, 2021
1de6a6a
Move LAYER_BASE_FLAGS to its own class
lmoureaux Aug 21, 2021
f991cb8
Add missing header to climap.h
lmoureaux Aug 22, 2021
5c59306
Move LAYER_DARKNESS to its own class
lmoureaux Aug 22, 2021
15b4f27
Add helper functions to the base layer class
lmoureaux Aug 22, 2021
7fa450c
Migrate LAYER_TERRAIN* to a class
lmoureaux Aug 30, 2021
b5c5b43
Fix loading CELL_CORNER/MATCH_PAIR sprites
lmoureaux Sep 11, 2021
2c3a4eb
Always initialize textras_near
lmoureaux Sep 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ add_library(
gui_interface.cpp
goto.cpp
helpdata.cpp
layer.cpp
layer_background.cpp
layer_base_flags.cpp
layer_darkness.cpp
layer_special.cpp
layer_terrain.cpp
luaconsole_common.cpp
mapctrl_common.cpp
mapview_common.cpp
Expand Down
1 change: 1 addition & 0 deletions client/climap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// common
#include "fc_types.h" // enum direction8, struct tile
#include "tile.h" // known_type

enum known_type client_tile_get_known(const struct tile *ptile);

Expand Down
18 changes: 0 additions & 18 deletions client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2365,19 +2365,6 @@ void request_toggle_city_trade_routes()
update_map_canvas_visible();
}

/**
Toggle display of terrain
*/
void request_toggle_terrain()
{
if (!can_client_change_view()) {
return;
}

gui_options.draw_terrain ^= 1;
update_map_canvas_visible();
}

/**
Toggle display of coastline
*/
Expand Down Expand Up @@ -3692,11 +3679,6 @@ void key_city_productions_toggle() { request_toggle_city_productions(); }
*/
void key_city_trade_routes_toggle() { request_toggle_city_trade_routes(); }

/**
Handle user 'toggle terrain display' input
*/
void key_terrain_toggle() { request_toggle_terrain(); }

/**
Handle user 'toggle coastline display' input
*/
Expand Down
2 changes: 0 additions & 2 deletions client/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ void request_toggle_city_growth();
void request_toggle_city_productions();
void request_toggle_city_buycost();
void request_toggle_city_trade_routes();
void request_toggle_terrain();
void request_toggle_coastline();
void request_toggle_roads_rails();
void request_toggle_irrigation();
Expand Down Expand Up @@ -194,7 +193,6 @@ void key_city_growth_toggle();
void key_city_productions_toggle();
void key_city_buycost_toggle();
void key_city_trade_routes_toggle();
void key_terrain_toggle();
void key_coastline_toggle();
void key_roads_rails_toggle();
void key_irrigation_toggle();
Expand Down
39 changes: 21 additions & 18 deletions client/gui-qt/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void qtg_canvas_free(QPixmap *store) { delete store; }
/**
Copies an area from the source canvas to the destination canvas.
*/
void qtg_canvas_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
void qtg_canvas_copy(QPixmap *dest, const QPixmap *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height)
{
QRectF source_rect(src_x, src_y, width, height);
Expand All @@ -73,7 +73,7 @@ void qtg_canvas_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
/**
Copies an area from the source pixmap to the destination pixmap.
*/
void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
void pixmap_copy(QPixmap *dest, const QPixmap *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height)
{
QRectF source_rect(src_x, src_y, width, height);
Expand All @@ -92,8 +92,8 @@ void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
/**
Copies an area from the source image to the destination image.
*/
void image_copy(QImage *dest, QImage *src, int src_x, int src_y, int dest_x,
int dest_y, int width, int height)
void image_copy(QImage *dest, const QImage *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height)
{
QRectF source_rect(src_x, src_y, width, height);
QRectF dest_rect(dest_x, dest_y, width, height);
Expand All @@ -112,7 +112,7 @@ void image_copy(QImage *dest, QImage *src, int src_x, int src_y, int dest_x,
Draw some or all of a sprite onto the canvas.
*/
void qtg_canvas_put_sprite(QPixmap *pcanvas, int canvas_x, int canvas_y,
QPixmap *sprite, int offset_x, int offset_y,
const QPixmap *sprite, int offset_x, int offset_y,
int width, int height)
{
QPainter p;
Expand All @@ -127,7 +127,7 @@ void qtg_canvas_put_sprite(QPixmap *pcanvas, int canvas_x, int canvas_y,
Draw a full sprite onto the canvas.
*/
void qtg_canvas_put_sprite_full(QPixmap *pcanvas, int canvas_x, int canvas_y,
QPixmap *sprite)
const QPixmap *sprite)
{
int width, height;

Expand All @@ -141,8 +141,8 @@ void qtg_canvas_put_sprite_full(QPixmap *pcanvas, int canvas_x, int canvas_y,
fog.
*/
void qtg_canvas_put_sprite_fogged(QPixmap *pcanvas, int canvas_x,
int canvas_y, QPixmap *psprite, bool fog,
int fog_x, int fog_y)
int canvas_y, const QPixmap *psprite,
bool fog, int fog_x, int fog_y)
{
Q_UNUSED(fog_x)
Q_UNUSED(fog_y)
Expand All @@ -165,8 +165,8 @@ void qtg_canvas_put_sprite_fogged(QPixmap *pcanvas, int canvas_x,
Draw fog outside city map when city is opened
*/
void qtg_canvas_put_sprite_citymode(QPixmap *pcanvas, int canvas_x,
int canvas_y, QPixmap *psprite, bool fog,
int fog_x, int fog_y)
int canvas_y, const QPixmap *psprite,
bool fog, int fog_x, int fog_y)
{
Q_UNUSED(fog_x)
Q_UNUSED(fog_y)
Expand All @@ -183,7 +183,8 @@ void qtg_canvas_put_sprite_citymode(QPixmap *pcanvas, int canvas_x,
Put unit in city area when city dialog is open
*/
void canvas_put_unit_fogged(QPixmap *pcanvas, int canvas_x, int canvas_y,
QPixmap *psprite, bool fog, int fog_x, int fog_y)
const QPixmap *psprite, bool fog, int fog_x,
int fog_y)
{
Q_UNUSED(fog_y)
Q_UNUSED(fog_x)
Expand All @@ -197,8 +198,9 @@ void canvas_put_unit_fogged(QPixmap *pcanvas, int canvas_x, int canvas_y,
/**
Draw a filled-in colored rectangle onto canvas.
*/
void qtg_canvas_put_rectangle(QPixmap *pcanvas, QColor *pcolor, int canvas_x,
int canvas_y, int width, int height)
void qtg_canvas_put_rectangle(QPixmap *pcanvas, const QColor *pcolor,
int canvas_x, int canvas_y, int width,
int height)
{
QBrush brush(*pcolor);
QPen pen(*pcolor);
Expand All @@ -223,8 +225,9 @@ void qtg_canvas_put_rectangle(QPixmap *pcanvas, QColor *pcolor, int canvas_x,
/**
Fill the area covered by the sprite with the given color.
*/
void qtg_canvas_fill_sprite_area(QPixmap *pcanvas, QPixmap *psprite,
QColor *pcolor, int canvas_x, int canvas_y)
void qtg_canvas_fill_sprite_area(QPixmap *pcanvas, const QPixmap *psprite,
const QColor *pcolor, int canvas_x,
int canvas_y)
{
int width, height;

Expand All @@ -236,7 +239,7 @@ void qtg_canvas_fill_sprite_area(QPixmap *pcanvas, QPixmap *psprite,
/**
Draw a 1-pixel-width colored line onto the canvas.
*/
void qtg_canvas_put_line(QPixmap *pcanvas, QColor *pcolor,
void qtg_canvas_put_line(QPixmap *pcanvas, const QColor *pcolor,
enum line_type ltype, int start_x, int start_y,
int dx, int dy)
{
Expand Down Expand Up @@ -274,7 +277,7 @@ void qtg_canvas_put_line(QPixmap *pcanvas, QColor *pcolor,
/**
Draw a 1-pixel-width colored curved line onto the canvas.
*/
void qtg_canvas_put_curved_line(QPixmap *pcanvas, QColor *pcolor,
void qtg_canvas_put_curved_line(QPixmap *pcanvas, const QColor *pcolor,
enum line_type ltype, int start_x,
int start_y, int dx, int dy)
{
Expand Down Expand Up @@ -340,7 +343,7 @@ void qtg_get_text_size(int *width, int *height, enum client_font font,
take care of this manually. The text will not be NULL but may be empty.
*/
void qtg_canvas_put_text(QPixmap *pcanvas, int canvas_x, int canvas_y,
enum client_font font, QColor *pcolor,
enum client_font font, const QColor *pcolor,
const QString &text)
{
QPainter p;
Expand Down
6 changes: 3 additions & 3 deletions client/gui-qt/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <QPixmap>

QPixmap *qtg_canvas_create(int width, int height);
void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
void pixmap_copy(QPixmap *dest, const QPixmap *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height);
void image_copy(QImage *dest, QImage *src, int src_x, int src_y, int dest_x,
int dest_y, int width, int height);
void image_copy(QImage *dest, const QImage *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height);
QRect zealous_crop_rect(QImage &p);
36 changes: 22 additions & 14 deletions client/gui-qt/helpdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Qt
#include <QApplication>
#include <QGraphicsDropShadowEffect>
#include <QPainter>
#include <QProgressBar>
#include <QScreen>
#include <QScrollArea>
Expand Down Expand Up @@ -219,7 +220,7 @@ void help_dialog::make_tree()
QHash<int, QTreeWidgetItem *> hash;
QIcon icon;
QTreeWidgetItem *item;
QPixmap *spite;
const QPixmap *spite;
struct advance *padvance;
QPixmap *pcan;
struct extra_type *pextra;
Expand All @@ -228,7 +229,6 @@ void help_dialog::make_tree()
struct nation_type *nation;
struct terrain *pterrain;
struct unit_type *f_type;
struct drawn_sprite sprs[80];

for (const auto *pitem : qAsConst(*help_nodes)) {
const char *s;
Expand All @@ -251,11 +251,19 @@ void help_dialog::make_tree()
icon = QIcon();

switch (pitem->type) {
case HELP_EXTRA:
case HELP_EXTRA: {
pextra = extra_type_by_translated_name(s);
fill_basic_extra_sprite_array(tileset, sprs, pextra);
spite = sprs->sprite;
break;
auto sprs = fill_basic_extra_sprite_array(tileset, pextra);
if (!sprs.empty()) {
QPixmap pix(*sprs.front().sprite);
QPainter p;
p.begin(&pix);
for (std::size_t i = 1; i < sprs.size(); ++i) {
p.drawPixmap(0, 0, *sprs[i].sprite);
}
icon = QIcon(pix);
}
} break;

case HELP_GOVERNMENT:
gov = government_by_translated_name(s);
Expand Down Expand Up @@ -1150,8 +1158,7 @@ QPixmap *terrain_canvas(struct terrain *terrain,
enum extra_cause cause)
{
QPixmap *canvas;
struct drawn_sprite sprs[80];
int canvas_y, count, i, width, height;
int canvas_y, i, width, height;
struct extra_type *pextra;

width = tileset_full_tile_width(tileset);
Expand All @@ -1161,8 +1168,9 @@ QPixmap *terrain_canvas(struct terrain *terrain,
canvas = qtg_canvas_create(width, height);
canvas->fill(Qt::transparent);
for (i = 0; i < 3; ++i) {
count = fill_basic_terrain_layer_sprite_array(tileset, sprs, i, terrain);
put_drawn_sprites(canvas, 0, canvas_y, count, sprs, false);
auto sprites =
fill_basic_terrain_layer_sprite_array(tileset, i, terrain);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
}

pextra = NULL;
Expand All @@ -1174,13 +1182,13 @@ QPixmap *terrain_canvas(struct terrain *terrain,
}
extra_type_by_cause_iterate_end;
fc_assert_ret_val(pextra, nullptr);
count = fill_basic_extra_sprite_array(tileset, sprs, pextra);
put_drawn_sprites(canvas, 0, canvas_y, count, sprs, false);
auto sprites = fill_basic_extra_sprite_array(tileset, pextra);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
}

if (resource != NULL) {
count = fill_basic_extra_sprite_array(tileset, sprs, resource);
put_drawn_sprites(canvas, 0, canvas_y, count, sprs, false);
auto sprites = fill_basic_extra_sprite_array(tileset, resource);
put_drawn_sprites(canvas, 0, canvas_y, sprites, false);
}

return canvas;
Expand Down
39 changes: 21 additions & 18 deletions client/gui-qt/qtg_cxxside.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ bool qtg_is_view_supported(enum ts_type type);
void qtg_tileset_type_set(enum ts_type type);
void qtg_free_intro_radar_sprites();
QPixmap *qtg_load_gfxfile(const char *filename);
QPixmap *qtg_create_sprite(int width, int height, QColor *pcolor);
void qtg_get_sprite_dimensions(QPixmap *sprite, int *width, int *height);
QPixmap *qtg_crop_sprite(QPixmap *source, int x, int y, int width,
int height, QPixmap *mask, int mask_offset_x,
QPixmap *qtg_create_sprite(int width, int height, const QColor *pcolor);
void qtg_get_sprite_dimensions(const QPixmap *sprite, int *width,
int *height);
QPixmap *qtg_crop_sprite(const QPixmap *source, int x, int y, int width,
int height, const QPixmap *mask, int mask_offset_x,
int mask_offset_y, float scale, bool smooth);
void qtg_free_sprite(QPixmap *s);

Expand All @@ -50,33 +51,35 @@ void qtg_color_free(QColor *pcolor);

QPixmap *qtg_canvas_create(int width, int height);
void qtg_canvas_free(QPixmap *store);
void qtg_canvas_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y,
void qtg_canvas_copy(QPixmap *dest, const QPixmap *src, int src_x, int src_y,
int dest_x, int dest_y, int width, int height);
void qtg_canvas_put_sprite(QPixmap *pcanvas, int canvas_x, int canvas_y,
QPixmap *sprite, int offset_x, int offset_y,
const QPixmap *sprite, int offset_x, int offset_y,
int width, int height);
void qtg_canvas_put_sprite_full(QPixmap *pcanvas, int canvas_x, int canvas_y,
QPixmap *sprite);
const QPixmap *sprite);
void qtg_canvas_put_sprite_fogged(QPixmap *pcanvas, int canvas_x,
int canvas_y, QPixmap *psprite, bool fog,
int fog_x, int fog_y);
int canvas_y, const QPixmap *psprite,
bool fog, int fog_x, int fog_y);
void qtg_canvas_put_sprite_citymode(QPixmap *pcanvas, int canvas_x,
int canvas_y, QPixmap *psprite, bool fog,
int fog_x, int fog_y);
void qtg_canvas_put_rectangle(QPixmap *pcanvas, QColor *pcolor, int canvas_x,
int canvas_y, int width, int height);
void qtg_canvas_fill_sprite_area(QPixmap *pcanvas, QPixmap *psprite,
QColor *pcolor, int canvas_x, int canvas_y);
void qtg_canvas_put_line(QPixmap *pcanvas, QColor *pcolor,
int canvas_y, const QPixmap *psprite,
bool fog, int fog_x, int fog_y);
void qtg_canvas_put_rectangle(QPixmap *pcanvas, const QColor *pcolor,
int canvas_x, int canvas_y, int width,
int height);
void qtg_canvas_fill_sprite_area(QPixmap *pcanvas, const QPixmap *psprite,
const QColor *pcolor, int canvas_x,
int canvas_y);
void qtg_canvas_put_line(QPixmap *pcanvas, const QColor *pcolor,
enum line_type ltype, int start_x, int start_y,
int dx, int dy);
void qtg_canvas_put_curved_line(QPixmap *pcanvas, QColor *pcolor,
void qtg_canvas_put_curved_line(QPixmap *pcanvas, const QColor *pcolor,
enum line_type ltype, int start_x,
int start_y, int dx, int dy);
void qtg_get_text_size(int *width, int *height, enum client_font font,
const QString &);
void qtg_canvas_put_text(QPixmap *pcanvas, int canvas_x, int canvas_y,
enum client_font font, QColor *pcolor,
enum client_font font, const QColor *pcolor,
const QString &text);

void qtg_set_rulesets(int num_rulesets, QStringList rulesets);
Expand Down
9 changes: 5 additions & 4 deletions client/gui-qt/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ QPixmap *qtg_load_gfxfile(const char *filename)
in the mask image will be used to clip pixel (0,0) in the source image
which is pixel (-x,-y) in the new image.
*/
QPixmap *qtg_crop_sprite(QPixmap *source, int x, int y, int width,
int height, QPixmap *mask, int mask_offset_x,
QPixmap *qtg_crop_sprite(const QPixmap *source, int x, int y, int width,
int height, const QPixmap *mask, int mask_offset_x,
int mask_offset_y, float scale, bool smooth)
{
QPainter p;
Expand Down Expand Up @@ -116,7 +116,8 @@ QPixmap *qtg_crop_sprite(QPixmap *source, int x, int y, int width,
/**
Find the dimensions of the sprite.
*/
void qtg_get_sprite_dimensions(QPixmap *sprite, int *width, int *height)
void qtg_get_sprite_dimensions(const QPixmap *sprite, int *width,
int *height)
{
*width = sprite->width();
*height = sprite->height();
Expand All @@ -130,7 +131,7 @@ void qtg_free_sprite(QPixmap *s) { delete s; }
/**
Create a new sprite with the given height, width and color.
*/
QPixmap *qtg_create_sprite(int width, int height, QColor *pcolor)
QPixmap *qtg_create_sprite(int width, int height, const QColor *pcolor)
{
QPixmap *created = new QPixmap;

Expand Down
Loading