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

Remove some qtg_ indirection functions #908

Merged
merged 17 commits into from
Feb 14, 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
6 changes: 3 additions & 3 deletions client/chatline_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void output_window_append(const struct ft_color color,
}

fc_allocate_ow_mutex();
real_output_window_append(plain_text, tags, -1);
real_output_window_append(plain_text, tags);
fc_release_ow_mutex();
text_tag_list_destroy(tags);
}
Expand Down Expand Up @@ -153,10 +153,10 @@ void output_window_printf(const struct ft_color color, const char *format,
Add a line of text to the output ("chatline") window from server event.
*/
void output_window_event(const char *plain_text,
const struct text_tag_list *tags, int conn_id)
const struct text_tag_list *tags)
{
fc_allocate_ow_mutex();
real_output_window_append(plain_text, tags, conn_id);
real_output_window_append(plain_text, tags);
fc_release_ow_mutex();
}

Expand Down
2 changes: 1 addition & 1 deletion client/chatline_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void output_window_vprintf(const struct ft_color color, const char *format,
void output_window_printf(const struct ft_color color, const char *format,
...) fc__attribute((__format__(__printf__, 2, 3)));
void output_window_event(const char *plain_text,
const struct text_tag_list *tags, int conn_id);
const struct text_tag_list *tags);

void chat_welcome_message(bool gui_has_copying_mitem);

Expand Down
46 changes: 23 additions & 23 deletions client/citybar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,15 @@ QRect simple_citybar_painter::paint(QPainter &painter,
QTextCharFormat format;

// Enable shadows
auto dark_color = *get_color(tileset, COLOR_MAPVIEW_CITYTEXT_DARK);
auto dark_color = get_color(tileset, COLOR_MAPVIEW_CITYTEXT_DARK);
first.set_text_shadow_brush(dark_color);
second.set_text_shadow_brush(dark_color);

// First line
if (gui_options.draw_city_names) {
// City name
format.setFont(get_font(FONT_CITY_NAME));
format.setForeground(*get_color(tileset, COLOR_MAPVIEW_CITYTEXT));
format.setForeground(get_color(tileset, COLOR_MAPVIEW_CITYTEXT));
first.add_text(name, format);

static const QString en_space = QStringLiteral(" ");
Expand All @@ -377,7 +377,7 @@ QRect simple_citybar_painter::paint(QPainter &painter,

// Text
format.setFont(get_font(FONT_CITY_PROD));
format.setForeground(*get_color(tileset, growth_color));
format.setForeground(get_color(tileset, growth_color));
first.add_text(growth, format);
}

Expand All @@ -394,7 +394,7 @@ QRect simple_citybar_painter::paint(QPainter &painter,

// Add it
format.setFont(get_font(FONT_CITY_PROD));
format.setForeground(*get_color(tileset, trade_routes_color));
format.setForeground(get_color(tileset, trade_routes_color));
first.add_text(en_space + trade_routes, format);
}
}
Expand All @@ -407,7 +407,7 @@ QRect simple_citybar_painter::paint(QPainter &painter,

// Add text
format.setFont(get_font(FONT_CITY_PROD));
format.setForeground(*get_color(tileset, production_color));
format.setForeground(get_color(tileset, production_color));
second.add_text(prod, format);
}

Expand Down Expand Up @@ -472,7 +472,7 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
sizeof(growth), &growth_color,
&production_color);
const QMargins text_margins(3, 0, 3, 0);
QColor owner_color = *get_player_color(t, city_owner(pcity));
QColor owner_color = get_player_color(t, city_owner(pcity));

// This is used for both lines
QTextCharFormat format;
Expand Down Expand Up @@ -501,7 +501,7 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
}

// City name
format.setForeground(*get_color(t, COLOR_MAPVIEW_CITYTEXT));
format.setForeground(get_color(t, COLOR_MAPVIEW_CITYTEXT));
first.add_spacer(); // Center it
first.add_text(name, format, false, text_margins);
first.add_spacer();
Expand All @@ -512,10 +512,10 @@ QRect traditional_citybar_painter::paint(QPainter &painter,

// Try to pick a color for city size text that contrasts with player
// color
QColor *textcolors[2] = {get_color(t, COLOR_MAPVIEW_CITYTEXT),
get_color(t, COLOR_MAPVIEW_CITYTEXT_DARK)};
format.setForeground(*color_best_contrast(&owner_color, textcolors,
ARRAY_SIZE(textcolors)));
QColor textcolors[2] = {get_color(t, COLOR_MAPVIEW_CITYTEXT),
get_color(t, COLOR_MAPVIEW_CITYTEXT_DARK)};
format.setForeground(color_best_contrast(owner_color, textcolors,
ARRAY_SIZE(textcolors)));

first.add_text(QStringLiteral("%1").arg(city_size_get(pcity)), format,
false, text_margins);
Expand All @@ -536,7 +536,7 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
char prod[512];
get_city_mapview_production(pcity, prod, sizeof(prod));

format.setForeground(*get_color(t, production_color));
format.setForeground(get_color(t, production_color));
second.add_text(prod, format, false, text_margins);
}

Expand All @@ -548,7 +548,7 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
second.add_icon(citybar->food);

// Text
format.setForeground(*get_color(t, growth_color));
format.setForeground(get_color(t, growth_color));
second.add_text(growth, format, false, text_margins);
}

Expand All @@ -562,7 +562,7 @@ QRect traditional_citybar_painter::paint(QPainter &painter,
get_city_mapview_trade_routes(
pcity, trade_routes, sizeof(trade_routes), &trade_routes_color);

format.setForeground(*get_color(t, trade_routes_color));
format.setForeground(get_color(t, trade_routes_color));
second.add_text(trade_routes, format, false, text_margins);
}
}
Expand Down Expand Up @@ -632,13 +632,13 @@ QRect polished_citybar_painter::paint(QPainter &painter,
&production_color);

// Decide colors
QColor owner_color = *get_player_color(t, city_owner(pcity));
QColor *textcolors[2] = {get_color(t, COLOR_MAPVIEW_CITYTEXT),
get_color(t, COLOR_MAPVIEW_CITYTEXT_DARK)};
QColor owner_color = get_player_color(t, city_owner(pcity));
QColor textcolors[2] = {get_color(t, COLOR_MAPVIEW_CITYTEXT),
get_color(t, COLOR_MAPVIEW_CITYTEXT_DARK)};
QColor text_color = pcity->owner == client_player()
? *get_color(t, COLOR_MAPVIEW_CITYTEXT)
: *color_best_contrast(&owner_color, textcolors,
ARRAY_SIZE(textcolors));
? get_color(t, COLOR_MAPVIEW_CITYTEXT)
: color_best_contrast(owner_color, textcolors,
ARRAY_SIZE(textcolors));

// Decide on the target height. It's the max of the font sizes and the
// occupied indicator (we assume all indicators have the same size).
Expand Down Expand Up @@ -702,7 +702,7 @@ QRect polished_citybar_painter::paint(QPainter &painter,
// Text
format.setFont(get_font(FONT_CITY_PROD));
format.setFontPointSize(format.fontPointSize() / 1.5);
format.setForeground(*get_color(t, growth_color));
format.setForeground(get_color(t, growth_color));
line.add_text(growth, format, false, text_margins);
}

Expand Down Expand Up @@ -743,7 +743,7 @@ QRect polished_citybar_painter::paint(QPainter &painter,
// Format
format.setFont(get_font(FONT_CITY_PROD));
format.setFontPointSize(format.fontPointSize() / 1.5);
format.setForeground(*get_color(t, production_color));
format.setForeground(get_color(t, production_color));

QMargins prod_margins = text_margins;
prod_margins.setLeft(0); // Already have the city name on the left
Expand Down Expand Up @@ -848,7 +848,7 @@ QRect polished_citybar_painter::paint(QPainter &painter,
&trade_routes_color);

format.setFont(get_font(FONT_CITY_PROD));
format.setForeground(*get_color(t, trade_routes_color));
format.setForeground(get_color(t, trade_routes_color));
trade_line.add_text(trade_routes, format, false, text_margins);

// Lay it out
Expand Down
6 changes: 1 addition & 5 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@
#include "version.h"

/* client/include */
#include "chatline_g.h"
#include "citydlg_g.h"
#include "connectdlg_g.h"
#include "dialogs_g.h"
#include "diplodlg_g.h"
#include "editgui_g.h"
#include "graphics_g.h"
#include "gui_main_g.h"
#include "mapctrl_g.h"
#include "mapview_g.h"
Expand All @@ -80,6 +78,7 @@
// client
#include "attribute.h"
#include "audio.h"
#include "chatline_common.h"
#include "cityrepdata.h"
#include "climisc.h"
#include "clinet.h"
Expand Down Expand Up @@ -524,7 +523,6 @@ int client_main(int argc, char *argv[])
game.all_connections = conn_list_new();
game.est_connections = conn_list_new();

ui_init();
charsets_init();
update_queue::uq()->init();

Expand Down Expand Up @@ -867,7 +865,6 @@ void set_client_state(enum client_states newstate)
set_client_page(PAGE_GAME);
// Find something sensible to display instead of the intro gfx.
center_on_something();
free_intro_radar_sprites();
editgui_tileset_changed();
voteinfo_gui_update();

Expand Down Expand Up @@ -1386,7 +1383,6 @@ static void fc_interface_init_client()
funcs->destroy_extra = NULL;
funcs->player_tile_vision_get = client_map_is_known_and_seen;
funcs->player_tile_city_id_get = client_plr_tile_city_id_get;
funcs->gui_color_free = color_free;

/* Keep this function call at the end. It checks if all required functions
are defined. */
Expand Down
4 changes: 2 additions & 2 deletions client/climisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
#include "unitlist.h"

/* client/include */
#include "chatline_g.h"
#include "citydlg_g.h"
#include "cityrep_g.h"
#include "dialogs_g.h"
#include "gui_main_g.h"
#include "mapview_g.h"

// client
#include "chatline_common.h"
#include "client_main.h"
#include "climap.h"
#include "climisc.h"
Expand Down Expand Up @@ -1082,7 +1082,7 @@ void handle_event(const char *featured_text, struct tile *ptile,

// Chatline
if (BOOL_VAL(where & MW_OUTPUT) || (fallback_needed && !shown)) {
output_window_event(plain_text, tags, conn_id);
output_window_event(plain_text, tags);
}

if (turn == game.info.turn) {
Expand Down
5 changes: 3 additions & 2 deletions client/clinet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

// client
#include "attribute.h"
#include "chatline_common.h"
#include "chatline_g.h"
#include "client_main.h"
#include "climisc.h"
Expand Down Expand Up @@ -152,8 +153,8 @@ static int try_to_connect(const QUrl &url, char *errbuf, int errbufsize)
[] {
if (client.conn.sock != nullptr) {
log_debug("%s", qUtf8Printable(client.conn.sock->errorString()));
real_output_window_append(client.conn.sock->errorString(), NULL,
-1);
real_output_window_append(client.conn.sock->errorString(),
nullptr);
}
client.conn.used = false;
});
Expand Down
67 changes: 33 additions & 34 deletions client/colors_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,17 @@ void color_system_free(struct color_system *colors)
delete colors;
}

/**
Return the RGB color, allocating it if necessary.
*/
QColor *ensure_color(struct rgbcolor *rgb)
{
fc_assert_ret_val(rgb != NULL, NULL);

if (!rgb->color) {
rgb->color = color_alloc(rgb->r, rgb->g, rgb->b);
}
return rgb->color;
}

/**
Return a pointer to the given "standard" color.
*/
QColor *get_color(const struct tileset *t, enum color_std stdcolor)
QColor get_color(const struct tileset *t, enum color_std stdcolor)
{
struct color_system *colors = get_color_system(t);

fc_assert_ret_val(colors != NULL, NULL);
fc_assert_ret_val(colors != NULL, Qt::black);

return ensure_color(*(colors->stdcolors + stdcolor));
auto &color = *(colors->stdcolors + stdcolor);
return QColor(color->r, color->g, color->b);
}

/**
Expand All @@ -123,52 +111,63 @@ bool player_has_color(const struct tileset *t, const struct player *pplayer)
In pregame, callers should check player_has_color() before calling
this.
*/
QColor *get_player_color(const struct tileset *t,
const struct player *pplayer)
QColor get_player_color(const struct tileset *t,
const struct player *pplayer)
{
Q_UNUSED(t)
fc_assert_ret_val(pplayer != NULL, NULL);
fc_assert_ret_val(pplayer->rgb != NULL, NULL);
fc_assert_ret_val(pplayer != NULL, Qt::black);
fc_assert_ret_val(pplayer->rgb != NULL, Qt::black);

return ensure_color(pplayer->rgb);
return QColor(pplayer->rgb->r, pplayer->rgb->g, pplayer->rgb->b);
}

/**
Return a pointer to the given "terrain" color.
*/
QColor *get_terrain_color(const struct tileset *t,
const struct terrain *pterrain)
QColor get_terrain_color(const struct tileset *t,
const struct terrain *pterrain)
{
Q_UNUSED(t)
fc_assert_ret_val(pterrain != NULL, NULL);
fc_assert_ret_val(pterrain->rgb != NULL, NULL);
fc_assert_ret_val(pterrain != NULL, Qt::black);
fc_assert_ret_val(pterrain->rgb != NULL, Qt::black);

return ensure_color(pterrain->rgb);
return QColor(pterrain->rgb->r, pterrain->rgb->g, pterrain->rgb->b);
}

/**
Find the colour from 'candidates' with the best perceptual contrast from
'subject'.
*/
QColor *color_best_contrast(QColor *subject, QColor **candidates,
int ncandidates)
QColor color_best_contrast(const QColor &subject, const QColor *candidates,
int ncandidates)
{
int sbright = color_brightness_score(subject), bestdiff = 0;
int i;
QColor *best = NULL;

fc_assert_ret_val(candidates != NULL, NULL);
fc_assert_ret_val(ncandidates > 0, NULL);
fc_assert_ret_val(candidates != NULL, Qt::black);
fc_assert_ret_val(ncandidates > 0, Qt::black);

for (i = 0; i < ncandidates; i++) {
QColor best;
for (int i = 0; i < ncandidates; i++) {
int cbright = color_brightness_score(candidates[i]);
int diff = ABS(sbright - cbright);

if (best == NULL || diff > bestdiff) {
if (i == 0 || diff > bestdiff) {
best = candidates[i];
bestdiff = diff;
}
}

return best;
}

/**
* Return a number indicating the perceptual brightness of this color
* relative to others (larger is brighter).
*/
int color_brightness_score(const QColor &color)
{
/* QColor has color space conversions, but nothing giving a perceptually
* even color space */
rgbcolor prgb{color.red(), color.green(), color.blue()};
return rgbcolor_brightness_score(&prgb);
}
Loading