tDon't use deprecated label alignment/markup funcs - vaccinewars - be a doctor … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 2c85b267fa55314979a78a4ed015c79e7cd10b69 | |
parent 451a8f6cb566edc05cf324ed9199ed121eaa6f18 | |
Author: Ben Webb <[email protected]> | |
Date: Thu, 31 Dec 2020 20:41:53 -0800 | |
Don't use deprecated label alignment/markup funcs | |
Don't use the gtk_misc_set_alignment() function to | |
align the text in a GtkLabel, or gtk_style_new() to | |
apply color to the text, as both of these functions | |
are deprecated in GTK3 and removed in GTK4. | |
Use GTK3 equivalents instead. | |
Diffstat: | |
M src/gtkport/gtkport.c | 37 +++++++++++++++++++++++++++++… | |
M src/gtkport/gtkport.h | 5 +++++ | |
M src/gui_client/gtk_client.c | 37 +++++++----------------------… | |
3 files changed, 48 insertions(+), 31 deletions(-) | |
--- | |
diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c | |
t@@ -5494,6 +5494,28 @@ gchar *GtkGetFile(const GtkWidget *parent, const gchar … | |
return ret; | |
} | |
+#endif /* CYGWIN */ | |
+ | |
+/* Make a new GtkLabel, with the text possibly bold */ | |
+GtkWidget *make_bold_label(const char *text, gboolean bold) | |
+{ | |
+#ifdef CYGWIN | |
+ /* We don't support bold text on Windows yet */ | |
+ return gtk_label_new(text); | |
+#else | |
+ if (bold) { | |
+ GtkWidget *label = gtk_label_new(NULL); | |
+ gchar *markup = g_markup_printf_escaped( | |
+ "<span font_weight=\"bold\" fgcolor=\"#0000DD\">%s</span>", text); | |
+ gtk_label_set_markup(GTK_LABEL(label), markup); | |
+ g_free(markup); | |
+ return label; | |
+ } else { | |
+ return gtk_label_new(text); | |
+ } | |
+#endif | |
+} | |
+ | |
#if !CYGWIN && \ | |
(GTK_MAJOR_VERSION > 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4)) | |
/* GtkGrid does not take a size, unlike GtkTable */ | |
t@@ -5534,8 +5556,19 @@ void dp_gtk_grid_attach(GtkGrid *grid, GtkWidget *child, | |
} | |
#endif | |
- | |
-#endif /* CYGWIN */ | |
+#if !CYGWIN && \ | |
+ (GTK_MAJOR_VERSION > 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 2)) | |
+void set_label_alignment(GtkWidget *widget, gfloat xalign, gfloat yalign) | |
+{ | |
+ gtk_label_set_xalign(GTK_LABEL(widget), xalign); | |
+ gtk_label_set_yalign(GTK_LABEL(widget), yalign); | |
+} | |
+#else | |
+void set_label_alignment(GtkWidget *widget, gfloat xalign, gfloat yalign) | |
+{ | |
+ gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign); | |
+} | |
+#endif | |
#if CYGWIN | |
void TextViewAppend(GtkTextView *textview, const gchar *text, | |
diff --git a/src/gtkport/gtkport.h b/src/gtkport/gtkport.h | |
t@@ -668,4 +668,9 @@ void dp_gtk_grid_attach(GtkGrid *grid, GtkWidget *child, | |
gint left, gint top, | |
gint width, gint height, gboolean expand); | |
+void set_label_alignment(GtkWidget *widget, gfloat xalign, gfloat yalign); | |
+ | |
+/* Make a new GtkLabel, with the text possibly bold */ | |
+GtkWidget *make_bold_label(const char *text, gboolean bold); | |
+ | |
#endif /* __GTKPORT_H__ */ | |
diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c | |
t@@ -658,7 +658,6 @@ void AddScoreToDialog(char *Data) | |
gchar **spl1, **spl2; | |
int index, slen; | |
gboolean bold; | |
- GtkStyle *style = NULL; | |
if (!HiScoreDialog.dialog) | |
return; | |
t@@ -683,20 +682,9 @@ void AddScoreToDialog(char *Data) | |
g_strfreev(spl1); | |
return; | |
} | |
- label = gtk_label_new(spl1[0]); | |
- gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); | |
+ label = make_bold_label(spl1[0], bold); | |
+ set_label_alignment(label, 1.0, 0.5); | |
dp_gtk_grid_attach(GTK_GRID(HiScoreDialog.grid), label, 0, index, 1, 1, TRUE… | |
- if (bold) { | |
- GdkColor color; | |
- | |
- color.red = 0; | |
- color.green = 0; | |
- color.blue = 0xDDDD; | |
- color.pixel = 0; | |
- style = gtk_style_new(); | |
- style->fg[GTK_STATE_NORMAL] = color; | |
- gtk_widget_set_style(label, style); | |
- } | |
gtk_widget_show(label); | |
/* Remove any leading whitespace from the remainder, since g_strsplit | |
t@@ -710,12 +698,9 @@ void AddScoreToDialog(char *Data) | |
g_strfreev(spl2); | |
return; | |
} | |
- label = gtk_label_new(spl2[0]); | |
- gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); | |
+ label = make_bold_label(spl2[0], bold); | |
+ set_label_alignment(label, 0.5, 0.5); | |
dp_gtk_grid_attach(GTK_GRID(HiScoreDialog.grid), label, 1, index, 1, 1, TRUE… | |
- if (bold) { | |
- gtk_widget_set_style(label, style); | |
- } | |
gtk_widget_show(label); | |
/* The remainder is the name, terminated with (R.I.P.) if the player | |
t@@ -731,25 +716,19 @@ void AddScoreToDialog(char *Data) | |
/* Check for (R.I.P.) suffix, and add it to the 4th column if found */ | |
if (slen > 8 && spl2[1][slen - 1] == ')' && spl2[1][slen - 8] == '(') { | |
- label = gtk_label_new(&spl2[1][slen - 8]); | |
- gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); | |
+ label = make_bold_label(&spl2[1][slen - 8], bold); | |
+ set_label_alignment(label, 0.5, 0.5); | |
dp_gtk_grid_attach(GTK_GRID(HiScoreDialog.grid), label, 3, index, 1, 1, | |
TRUE); | |
- if (bold) { | |
- gtk_widget_set_style(label, style); | |
- } | |
gtk_widget_show(label); | |
spl2[1][slen - 8] = '\0'; /* Remove suffix from the player name */ | |
} | |
/* Finally, add in what's left of the player name */ | |
g_strchomp(spl2[1]); | |
- label = gtk_label_new(spl2[1]); | |
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
+ label = make_bold_label(spl2[1], bold); | |
+ set_label_alignment(label, 0, 0.5); | |
dp_gtk_grid_attach(GTK_GRID(HiScoreDialog.grid), label, 2, index, 1, 1, TRUE… | |
- if (bold) { | |
- gtk_widget_set_style(label, style); | |
- } | |
gtk_widget_show(label); | |
g_strfreev(spl1); |