Merge branch 'scale' into 'master'
Simplify icon rendering a bit See merge request Librem5/squeekboard!52
This commit is contained in:
@ -57,10 +57,9 @@ eek_gtk_renderer_real_get_icon_surface (EekRenderer *self,
|
|||||||
gint size)
|
gint size)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
||||||
icon_name,
|
icon_name,
|
||||||
size,
|
size,
|
||||||
|
|||||||
@ -459,7 +459,8 @@ render_key (EekRenderer *self,
|
|||||||
if (!outline_surface) {
|
if (!outline_surface) {
|
||||||
cairo_t *cr;
|
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 =
|
outline_surface =
|
||||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
||||||
(int)ceil(bounds.width) + 10,
|
(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_set_source_surface (cr, outline_surface, 0.0, 0.0);
|
||||||
cairo_paint (cr);
|
cairo_paint (cr);
|
||||||
|
|
||||||
|
eek_renderer_get_foreground_color (self, EEK_ELEMENT(key), &foreground);
|
||||||
/* render icon (if any) */
|
/* render icon (if any) */
|
||||||
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
|
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#define SCALE 0.8
|
||||||
if (eek_symbol_get_icon_name (symbol)) {
|
if (eek_symbol_get_icon_name (symbol)) {
|
||||||
|
|
||||||
cairo_surface_t *icon_surface =
|
cairo_surface_t *icon_surface =
|
||||||
eek_renderer_get_icon_surface (self,
|
eek_renderer_get_icon_surface (self,
|
||||||
eek_symbol_get_icon_name (symbol),
|
eek_symbol_get_icon_name (symbol),
|
||||||
MIN(bounds.width, bounds.height) * 0.5);
|
MIN(bounds.width, bounds.height));
|
||||||
if (icon_surface) {
|
if (icon_surface) {
|
||||||
gint width = cairo_image_surface_get_width (icon_surface);
|
gint width = cairo_image_surface_get_width (icon_surface);
|
||||||
gint height = cairo_image_surface_get_height (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_save (cr);
|
||||||
cairo_translate (cr,
|
cairo_translate (cr,
|
||||||
(bounds.width - width * scale) / 2,
|
(bounds.width - width * SCALE) / 2,
|
||||||
(bounds.height - height * scale) / 2);
|
(bounds.height - height * SCALE) / 2);
|
||||||
cairo_rectangle (cr, 0, 0, width, height);
|
cairo_rectangle (cr, 0, 0, width, height);
|
||||||
|
cairo_scale (cr, SCALE, SCALE);
|
||||||
cairo_clip (cr);
|
cairo_clip (cr);
|
||||||
/* Draw the shape of the icon using the foreground color */
|
/* 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,
|
cairo_set_source_rgba (cr, foreground.red,
|
||||||
foreground.green,
|
foreground.green,
|
||||||
foreground.blue,
|
foreground.blue,
|
||||||
@ -546,7 +534,6 @@ render_key (EekRenderer *self,
|
|||||||
(bounds.width - extents.width / PANGO_SCALE) / 2,
|
(bounds.width - extents.width / PANGO_SCALE) / 2,
|
||||||
(bounds.height - extents.height / 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,
|
cairo_set_source_rgba (cr,
|
||||||
foreground.red,
|
foreground.red,
|
||||||
foreground.green,
|
foreground.green,
|
||||||
|
|||||||
Reference in New Issue
Block a user