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

More qtg_ indirection removal #911

Merged
merged 8 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 0 additions & 34 deletions client/gui-qt/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,6 @@
#include "qtg_cxxside.h"
#include "sprite.h"

/**
Create a canvas of the given size.
*/
QPixmap *qtg_canvas_create(int width, int height)
{
QPixmap *store = new QPixmap(width, height);
return store;
}

/**
Free any resources associated with this canvas and the canvas struct
itself.
*/
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, 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);
QRectF dest_rect(dest_x, dest_y, width, height);
QPainter p;

if (!width || !height) {
return;
}

p.begin(dest);
p.drawPixmap(dest_rect, *src, source_rect);
p.end();
}

/**
Copies an area from the source pixmap to the destination pixmap.
*/
Expand Down
1 change: 0 additions & 1 deletion client/gui-qt/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Qt
#include <QPixmap>

QPixmap *qtg_canvas_create(int width, int height);
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, const QImage *src, int src_x, int src_y,
Expand Down
30 changes: 15 additions & 15 deletions client/gui-qt/citydlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ impr_item::impr_item(QWidget *parent, const impr_type *building,
auto sprite = get_building_sprite(tileset, building);

if (sprite != nullptr) {
impr_pixmap = qtg_canvas_create(sprite->width(), sprite->height());
impr_pixmap = new QPixmap(sprite->width(), sprite->height());
impr_pixmap->fill(Qt::transparent);
pixmap_copy(impr_pixmap, sprite, 0, 0, 0, 0, sprite->width(),
sprite->height());
} else {
impr_pixmap = qtg_canvas_create(10, 10);
impr_pixmap = new QPixmap(10, 10);
impr_pixmap->fill(Qt::red);
}

Expand All @@ -391,7 +391,7 @@ impr_item::impr_item(QWidget *parent, const impr_type *building,
impr_item::~impr_item()
{
if (impr_pixmap) {
canvas_free(impr_pixmap);
delete impr_pixmap;
}
}

Expand All @@ -412,17 +412,17 @@ void impr_item::enterEvent(QEvent *event)
Q_UNUSED(event)

if (impr_pixmap) {
canvas_free(impr_pixmap);
delete impr_pixmap;
}

auto sprite = get_building_sprite(tileset, impr);
if (impr && sprite != nullptr) {
impr_pixmap = qtg_canvas_create(sprite->width(), sprite->height());
impr_pixmap = new QPixmap(sprite->width(), sprite->height());
impr_pixmap->fill(QColor(palette().color(QPalette::Highlight)));
pixmap_copy(impr_pixmap, sprite, 0, 0, 0, 0, sprite->width(),
sprite->height());
} else {
impr_pixmap = qtg_canvas_create(10, 10);
impr_pixmap = new QPixmap(10, 10);
impr_pixmap->fill(QColor(palette().color(QPalette::Highlight)));
}

Expand All @@ -437,17 +437,17 @@ void impr_item::leaveEvent(QEvent *event)
Q_UNUSED(event)

if (impr_pixmap) {
canvas_free(impr_pixmap);
delete impr_pixmap;
}

auto sprite = get_building_sprite(tileset, impr);
if (impr && sprite) {
impr_pixmap = qtg_canvas_create(sprite->width(), sprite->height());
impr_pixmap = new QPixmap(sprite->width(), sprite->height());
impr_pixmap->fill(Qt::transparent);
pixmap_copy(impr_pixmap, sprite, 0, 0, 0, 0, sprite->width(),
sprite->height());
} else {
impr_pixmap = qtg_canvas_create(10, 10);
impr_pixmap = new QPixmap(10, 10);
impr_pixmap->fill(Qt::red);
}

Expand Down Expand Up @@ -602,11 +602,11 @@ static QImage create_unit_image(unit *punit, bool supported, int happy_cost)
if (punit) {
if (supported) {
unit_pixmap =
qtg_canvas_create(tileset_unit_width(get_tileset()),
tileset_unit_with_upkeep_height(get_tileset()));
new QPixmap(tileset_unit_width(get_tileset()),
tileset_unit_with_upkeep_height(get_tileset()));
} else {
unit_pixmap = qtg_canvas_create(tileset_unit_width(get_tileset()),
tileset_unit_height(get_tileset()));
unit_pixmap = new QPixmap(tileset_unit_width(get_tileset()),
tileset_unit_height(get_tileset()));
}

unit_pixmap->fill(Qt::transparent);
Expand All @@ -618,7 +618,7 @@ static QImage create_unit_image(unit *punit, bool supported, int happy_cost)
punit->upkeep, happy_cost);
}
} else {
unit_pixmap = qtg_canvas_create(10, 10);
unit_pixmap = new QPixmap(10, 10);
unit_pixmap->fill(Qt::transparent);
}

Expand All @@ -635,7 +635,7 @@ static QImage create_unit_image(unit *punit, bool supported, int happy_cost)
unit_img = cropped_img.scaledToHeight(tileset_unit_width(get_tileset()),
Qt::SmoothTransformation);
}
canvas_free(unit_pixmap);
delete unit_pixmap;

return unit_img;
}
Expand Down
18 changes: 9 additions & 9 deletions client/gui-qt/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,12 @@ void choice_dialog::set_layout()
prev->setIconSize(QSize(32, 32));
prev->setFixedSize(QSize(36, 36));
target_unit_button = new QPushButton;
pix = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
pix = new QPixmap(tileset_unit_width(tileset),
tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
target_unit_button->setIcon(QIcon(*pix));
qtg_canvas_free(pix);
delete pix;
target_unit_button->setIconSize(QSize(96, 96));
target_unit_button->setFixedSize(QSize(100, 100));
unit_skip->addStretch(100);
Expand Down Expand Up @@ -1342,12 +1342,12 @@ void choice_dialog::next_unit()
}
unit_list_iterate_end;
targeted_unit = new_target;
pix = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
pix =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
target_unit_button->setIcon(QIcon(*pix));
qtg_canvas_free(pix);
delete pix;
switch_target();
}

Expand All @@ -1373,12 +1373,12 @@ void choice_dialog::prev_unit()
}
unit_list_iterate_end;
targeted_unit = new_target;
pix = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
pix =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
pix->fill(Qt::transparent);
put_unit(targeted_unit, pix, 0, 0);
target_unit_button->setIcon(QIcon(*pix));
qtg_canvas_free(pix);
delete pix;
switch_target();
}

Expand Down
12 changes: 6 additions & 6 deletions client/gui-qt/helpdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,12 @@ void help_widget::set_topic_unit(const help_item *topic, const char *title)
max_utype = uclass_max_values(utype->uclass);

// Unit icon
canvas = qtg_canvas_create(tileset_full_tile_width(tileset),
tileset_full_tile_height(tileset));
canvas = new QPixmap(tileset_full_tile_width(tileset),
tileset_full_tile_height(tileset));
canvas->fill(Qt::transparent);
put_unittype(utype, canvas, 0, 0);
add_info_pixmap(canvas);
qtg_canvas_free(canvas);
delete canvas;

add_info_progress(_("Attack:"), utype->attack_strength, 0,
max_utype->attack_strength);
Expand Down Expand Up @@ -1164,7 +1164,7 @@ QPixmap *terrain_canvas(struct terrain *terrain,
height = tileset_full_tile_height(tileset);
canvas_y = height - tileset_tile_height(tileset);

canvas = qtg_canvas_create(width, height);
canvas = new QPixmap(width, height);
canvas->fill(Qt::transparent);
for (i = 0; i < 3; ++i) {
auto sprites =
Expand Down Expand Up @@ -1328,7 +1328,7 @@ void help_widget::set_topic_terrain(const help_item *topic,
// Create terrain icon. Use shadow to help distinguish terrain.
canvas = terrain_canvas(pterrain);
add_info_pixmap(canvas, true);
qtg_canvas_free(canvas);
delete canvas;

add_info_progress(_("Food:"), pterrain->output[O_FOOD], 0,
max->output[O_FOOD]);
Expand Down Expand Up @@ -1439,7 +1439,7 @@ void help_widget::set_topic_terrain(const help_item *topic,
_("Output (Food, Shields, Trade) of a tile where the resource "
"is "
"present.")));
qtg_canvas_free(canvas);
delete canvas;
show_panel = true;
}
}
Expand Down
24 changes: 12 additions & 12 deletions client/gui-qt/hudwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ void hud_units::update_actions(unit_list *punits)
text_label.setFixedWidth(fm->horizontalAdvance(text_str) + 20);
delete fm;

unit_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
unit_pixmap =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
unit_pixmap->fill(Qt::transparent);
put_unit(punit, unit_pixmap, 0, 0);
img = unit_pixmap->toImage();
Expand Down Expand Up @@ -751,11 +751,11 @@ void hud_units::update_actions(unit_list *punits)
wwidth = 2 * 3 + pix.width();
unit_label.setPixmap(pix);
if (tileset_is_isometric(tileset)) {
tile_pixmap = qtg_canvas_create(tileset_full_tile_width(tileset),
tileset_tile_height(tileset) * 2);
tile_pixmap = new QPixmap(tileset_full_tile_width(tileset),
tileset_tile_height(tileset) * 2);
} else {
tile_pixmap = qtg_canvas_create(tileset_full_tile_width(tileset),
tileset_tile_height(tileset));
tile_pixmap = new QPixmap(tileset_full_tile_width(tileset),
tileset_tile_height(tileset));
}
tile_pixmap->fill(QColor(0, 0, 0, 0));
put_terrain(punit->tile, tile_pixmap, 0, 0);
Expand All @@ -768,8 +768,8 @@ void hud_units::update_actions(unit_list *punits)
unit_label.setToolTip(popup_info_text(punit->tile));
tile_label.setToolTip(popup_terrain_info(punit->tile));
wwidth = wwidth + pix.width();
qtg_canvas_free(tile_pixmap);
qtg_canvas_free(unit_pixmap);
delete tile_pixmap;
delete unit_pixmap;

setFixedWidth(wwidth
+ qMax(unit_icons->update_actions() * (height() * 8) / 10,
Expand Down Expand Up @@ -1737,8 +1737,8 @@ void hud_unit_combat::init_images(bool redraw)
w = 3 * hud_scale * tileset_unit_height(tileset) / 2;
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
setFixedSize(2 * w, w);
defender_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
defender_pixmap =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
defender_pixmap->fill(Qt::transparent);
if (defender != nullptr) {
if (!redraw) {
Expand All @@ -1760,8 +1760,8 @@ void hud_unit_combat::init_images(bool redraw)
dimg = dt;
}
dimg = dimg.scaled(w, w, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
attacker_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
attacker_pixmap =
new QPixmap(tileset_unit_width(tileset), tileset_unit_height(tileset));
attacker_pixmap->fill(Qt::transparent);
if (attacker != nullptr) {
if (!redraw) {
Expand Down
3 changes: 0 additions & 3 deletions client/gui-qt/qtg_cxxside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ void setup_gui_funcs()
{
struct gui_funcs *funcs = get_gui_funcs();

funcs->canvas_create = qtg_canvas_create;
funcs->canvas_free = qtg_canvas_free;
funcs->canvas_copy = qtg_canvas_copy;
funcs->canvas_put_sprite = qtg_canvas_put_sprite;
funcs->canvas_put_sprite_full = qtg_canvas_put_sprite_full;
funcs->canvas_put_sprite_fogged = qtg_canvas_put_sprite_fogged;
Expand Down
4 changes: 0 additions & 4 deletions client/gui-qt/qtg_cxxside.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class QTcpSocket;

void setup_gui_funcs();

QPixmap *qtg_canvas_create(int width, int height);
void qtg_canvas_free(QPixmap *store);
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,
const QPixmap *sprite, int offset_x, int offset_y,
int width, int height);
Expand Down
6 changes: 3 additions & 3 deletions client/gui-qt/sciencedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ research_diagram::research_diagram(QWidget *parent) : QWidget(parent)
research_diagram::~research_diagram()
{
NFCN_FREE(tt_help);
canvas_free(pcanvas);
delete pcanvas;
destroy_reqtree(req);
}

Expand All @@ -90,11 +90,11 @@ void research_diagram::reset()
destroy_reqtree(req);
}
if (pcanvas != NULL) {
canvas_free(pcanvas);
delete pcanvas;
}
req = create_reqtree(client_player(), true);
get_reqtree_dimensions(req, &width, &height);
pcanvas = qtg_canvas_create(width, height);
pcanvas = new QPixmap(width, height);
pcanvas->fill(Qt::transparent);
resize(width, height);
}
Expand Down
4 changes: 2 additions & 2 deletions client/gui-qt/spaceshipdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ss_report::ss_report(struct player *pplayer)
setAttribute(Qt::WA_DeleteOnClose);
player = pplayer;
get_spaceship_dimensions(&w, &h);
can = qtg_canvas_create(w, h);
can = new QPixmap(w, h);

QGridLayout *layout = new QGridLayout;
ss_pix_label = new QLabel;
Expand All @@ -60,7 +60,7 @@ ss_report::ss_report(struct player *pplayer)
ss_report::~ss_report()
{
queen()->removeRepoDlg(QStringLiteral("SPS"));
qtg_canvas_free(can);
delete can;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions client/gui-qt/unitselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void units_select::create_pixmap()
}
pix->fill(Qt::transparent);
for (auto *punit : qAsConst(unit_list)) {
unit_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
tileset_unit_height(tileset));
unit_pixmap = new QPixmap(tileset_unit_width(tileset),
tileset_unit_height(tileset));
unit_pixmap->fill(Qt::transparent);
put_unit(punit, unit_pixmap, 0, 0);
img = unit_pixmap->toImage();
Expand All @@ -136,7 +136,7 @@ void units_select::create_pixmap()
pixc = QPixmap::fromImage(img);
pixp = new QPixmap(pixc);
pix_list.push_back(pixp);
qtg_canvas_free(unit_pixmap);
delete unit_pixmap;
}
a = qMin(item_size.width() / 4, 12);
x = 0, y = -item_size.height(), i = -1;
Expand Down
Loading