Merge branch 'scale' into 'master'

Simplify icon rendering a bit

See merge request Librem5/squeekboard!52
This commit is contained in:
David Boddie
2019-07-11 13:42:50 +00:00
2 changed files with 17 additions and 31 deletions

View File

@ -57,10 +57,9 @@ eek_gtk_renderer_real_get_icon_surface (EekRenderer *self,
gint size)
{
GdkPixbuf *pixbuf;
GError *error;
GError *error = NULL;
cairo_surface_t *surface;
error = NULL;
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
icon_name,
size,

View File

@ -459,7 +459,8 @@ render_key (EekRenderer *self,
if (!outline_surface) {
cairo_t *cr;
// Outline will be drawn on the outside of the button, so the surface needs to be bigger than the button
// Outline will be drawn on the outside of the button, so the
// surface needs to be bigger than the button
outline_surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
(int)ceil(bounds.width) + 10,
@ -485,44 +486,31 @@ render_key (EekRenderer *self,
cairo_set_source_surface (cr, outline_surface, 0.0, 0.0);
cairo_paint (cr);
eek_renderer_get_foreground_color (self, EEK_ELEMENT(key), &foreground);
/* render icon (if any) */
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
return;
#define SCALE 0.8
if (eek_symbol_get_icon_name (symbol)) {
cairo_surface_t *icon_surface =
eek_renderer_get_icon_surface (self,
eek_symbol_get_icon_name (symbol),
MIN(bounds.width, bounds.height) * 0.5);
MIN(bounds.width, bounds.height));
if (icon_surface) {
gint width = cairo_image_surface_get_width (icon_surface);
gint height = cairo_image_surface_get_height (icon_surface);
gdouble scale;
if (width < bounds.width && height < bounds.height)
scale = 1;
else {
if (height * bounds.width / width <= bounds.height)
scale = bounds.width / width;
else if (width * bounds.height / height <= bounds.width)
scale = bounds.height / height;
else {
if (width * bounds.height < height * bounds.width)
scale = width / bounds.width;
else
scale = height / bounds.height;
}
}
cairo_save (cr);
cairo_translate (cr,
(bounds.width - width * scale) / 2,
(bounds.height - height * scale) / 2);
(bounds.width - width * SCALE) / 2,
(bounds.height - height * SCALE) / 2);
cairo_rectangle (cr, 0, 0, width, height);
cairo_scale (cr, SCALE, SCALE);
cairo_clip (cr);
/* Draw the shape of the icon using the foreground color */
eek_renderer_get_foreground_color (self, EEK_ELEMENT(key), &foreground);
cairo_set_source_rgba (cr, foreground.red,
foreground.green,
foreground.blue,
@ -546,7 +534,6 @@ render_key (EekRenderer *self,
(bounds.width - extents.width / PANGO_SCALE) / 2,
(bounds.height - extents.height / PANGO_SCALE) / 2);
eek_renderer_get_foreground_color (self, EEK_ELEMENT(key), &foreground);
cairo_set_source_rgba (cr,
foreground.red,
foreground.green,