[gimp] app: make GimpFgBgEditor and GimpStatusbar HiDPI-aware
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make GimpFgBgEditor and GimpStatusbar HiDPI-aware
- Date: Mon, 31 Dec 2018 18:13:37 +0000 (UTC)
commit e3e2cdcbd25ca9f15e3437e1846e0e57b3ffd4a3
Author: Michael Natterer <mitch gimp org>
Date: Mon Dec 31 19:12:00 2018 +0100
app: make GimpFgBgEditor and GimpStatusbar HiDPI-aware
so their icons look proper again on HiDPI monitors.
app/display/gimpstatusbar.c | 25 +++++++++++++++++++------
app/widgets/gimpfgbgeditor.c | 35 +++++++++++++++++++++++++----------
2 files changed, 44 insertions(+), 16 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index 398b99881a..9c31c3c674 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -620,10 +620,12 @@ gimp_statusbar_progress_message (GimpProgress *progress,
if (icon_name)
{
GdkPixbuf *pixbuf;
+ gint scale_factor;
pixbuf = gimp_statusbar_load_icon (statusbar, icon_name);
- width += ICON_SPACING + gdk_pixbuf_get_width (pixbuf);
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
+ width += ICON_SPACING + gdk_pixbuf_get_width (pixbuf) / scale_factor;
g_object_unref (pixbuf);
@@ -675,14 +677,18 @@ gimp_statusbar_set_text (GimpStatusbar *statusbar,
PangoAttribute *attr;
PangoRectangle rect;
gchar *tmp;
+ gint scale_factor;
tmp = g_strconcat (" ", text, NULL);
gtk_label_set_text (GTK_LABEL (statusbar->label), tmp);
g_free (tmp);
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
+
rect.x = 0;
rect.y = 0;
- rect.width = PANGO_SCALE * (gdk_pixbuf_get_width (statusbar->icon) +
+ rect.width = PANGO_SCALE * (gdk_pixbuf_get_width (statusbar->icon) /
+ scale_factor +
ICON_SPACING);
rect.height = 0;
@@ -1273,9 +1279,11 @@ gimp_statusbar_label_draw (GtkWidget *widget,
{
if (statusbar->icon)
{
- PangoRectangle rect;
- GtkAllocation allocation;
- gint x, y;
+ cairo_surface_t *surface;
+ PangoRectangle rect;
+ GtkAllocation allocation;
+ gint scale_factor;
+ gint x, y;
gtk_label_get_layout_offsets (GTK_LABEL (widget), &x, &y);
@@ -1291,7 +1299,12 @@ gimp_statusbar_label_draw (GtkWidget *widget,
PANGO_PIXELS (rect.width) : 0);
y += PANGO_PIXELS (rect.y);
- gdk_cairo_set_source_pixbuf (cr, statusbar->icon, x, y);
+ scale_factor = gtk_widget_get_scale_factor (widget);
+ surface = gdk_cairo_surface_create_from_pixbuf (statusbar->icon,
+ scale_factor, NULL);
+ cairo_set_source_surface (cr, surface, x, y);
+ cairo_surface_destroy (surface);
+
cairo_paint (cr);
}
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 200be0ba39..424ccb6376 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -259,6 +259,7 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
GtkBorder border;
GtkBorder padding;
GdkRectangle rect;
+ gint scale_factor;
gint width, height;
gint default_w, default_h;
gint swap_w, swap_h;
@@ -280,19 +281,27 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
border.top += padding.top;
border.bottom += padding.bottom;
+ scale_factor = gtk_widget_get_scale_factor (widget);
+
/* draw the default colors pixbuf */
if (! editor->default_icon)
editor->default_icon = gimp_widget_load_icon (widget,
GIMP_ICON_COLORS_DEFAULT, 12);
- default_w = gdk_pixbuf_get_width (editor->default_icon);
- default_h = gdk_pixbuf_get_height (editor->default_icon);
+ default_w = gdk_pixbuf_get_width (editor->default_icon) / scale_factor;
+ default_h = gdk_pixbuf_get_height (editor->default_icon) / scale_factor;
if (default_w < width / 2 && default_h < height / 2)
{
- gdk_cairo_set_source_pixbuf (cr, editor->default_icon,
- border.left,
- height - border.bottom - default_h);
+ cairo_surface_t *surface;
+
+ surface = gdk_cairo_surface_create_from_pixbuf (editor->default_icon,
+ scale_factor, NULL);
+ cairo_set_source_surface (cr, surface,
+ border.left,
+ height - border.bottom - default_h);
+ cairo_surface_destroy (surface);
+
cairo_paint (cr);
}
else
@@ -305,14 +314,20 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
editor->swap_icon = gimp_widget_load_icon (widget,
GIMP_ICON_COLORS_SWAP, 12);
- swap_w = gdk_pixbuf_get_width (editor->swap_icon);
- swap_h = gdk_pixbuf_get_height (editor->swap_icon);
+ swap_w = gdk_pixbuf_get_width (editor->swap_icon) / scale_factor;
+ swap_h = gdk_pixbuf_get_height (editor->swap_icon) / scale_factor;
if (swap_w < width / 2 && swap_h < height / 2)
{
- gdk_cairo_set_source_pixbuf (cr, editor->swap_icon,
- width - border.right - swap_w,
- border.top);
+ cairo_surface_t *surface;
+
+ surface = gdk_cairo_surface_create_from_pixbuf (editor->swap_icon,
+ scale_factor, NULL);
+ cairo_set_source_surface (cr, surface,
+ width - border.right - swap_w,
+ border.top);
+ cairo_surface_destroy (surface);
+
cairo_paint (cr);
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]