Merge branch 'renderer' into 'master'
Renderer reworks See merge request Librem5/squeekboard!238
This commit is contained in:
@ -50,8 +50,7 @@ typedef struct _EekRendererPrivate
|
||||
gint origin_x;
|
||||
gint origin_y;
|
||||
|
||||
PangoFontDescription *ascii_font;
|
||||
PangoFontDescription *font;
|
||||
PangoFontDescription *font; // owned reference
|
||||
cairo_surface_t *keyboard_surface;
|
||||
|
||||
} EekRendererPrivate;
|
||||
@ -59,8 +58,7 @@ typedef struct _EekRendererPrivate
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (EekRenderer, eek_renderer, G_TYPE_OBJECT)
|
||||
|
||||
/* eek-keyboard-drawing.c */
|
||||
static void eek_renderer_real_render_button_label (EekRenderer *self,
|
||||
PangoLayout *layout,
|
||||
static void eek_renderer_render_button_label (EekRenderer *self, cairo_t *cr, GtkStyleContext *ctx,
|
||||
const struct squeek_button *button);
|
||||
|
||||
static void invalidate (EekRenderer *renderer);
|
||||
@ -125,9 +123,9 @@ static void
|
||||
render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
|
||||
{
|
||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
||||
EekColor foreground;
|
||||
|
||||
eek_renderer_get_foreground_color (priv->view_context, &foreground);
|
||||
GdkRGBA color = {0};
|
||||
gtk_style_context_get_color (priv->view_context, GTK_STATE_FLAG_NORMAL, &color);
|
||||
|
||||
EekBounds bounds = squeek_view_get_bounds (level_keyboard_current(priv->keyboard));
|
||||
|
||||
@ -152,15 +150,16 @@ render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
|
||||
cairo_translate (data.cr, bounds.x, bounds.y);
|
||||
|
||||
cairo_set_source_rgba (data.cr,
|
||||
foreground.red,
|
||||
foreground.green,
|
||||
foreground.blue,
|
||||
foreground.alpha);
|
||||
color.red,
|
||||
color.green,
|
||||
color.blue,
|
||||
color.alpha);
|
||||
|
||||
/* draw rows */
|
||||
squeek_view_foreach(level_keyboard_current(priv->keyboard),
|
||||
create_keyboard_surface_row_callback,
|
||||
&data);
|
||||
|
||||
cairo_restore (data.cr);
|
||||
|
||||
cairo_destroy (data.cr);
|
||||
@ -198,9 +197,6 @@ static void render_button_in_context(EekRenderer *self,
|
||||
struct button_place *place,
|
||||
gboolean active) {
|
||||
cairo_surface_t *outline_surface = NULL;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle extents = { 0, };
|
||||
EekColor foreground;
|
||||
|
||||
/* render outline */
|
||||
EekBounds bounds = squeek_button_get_bounds(place->button);
|
||||
@ -231,7 +227,6 @@ static void render_button_in_context(EekRenderer *self,
|
||||
cairo_surface_destroy(outline_surface);
|
||||
cairo_paint (cr);
|
||||
|
||||
eek_renderer_get_foreground_color (ctx, &foreground);
|
||||
/* render icon (if any) */
|
||||
const char *icon_name = squeek_button_get_icon_name(place->button);
|
||||
|
||||
@ -249,10 +244,13 @@ static void render_button_in_context(EekRenderer *self,
|
||||
cairo_rectangle (cr, 0, 0, width, height);
|
||||
cairo_clip (cr);
|
||||
/* Draw the shape of the icon using the foreground color */
|
||||
cairo_set_source_rgba (cr, foreground.red,
|
||||
foreground.green,
|
||||
foreground.blue,
|
||||
foreground.alpha);
|
||||
GdkRGBA color = {0};
|
||||
gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color);
|
||||
|
||||
cairo_set_source_rgba (cr, color.red,
|
||||
color.green,
|
||||
color.blue,
|
||||
color.alpha);
|
||||
cairo_mask_surface (cr, icon_surface, 0.0, 0.0);
|
||||
cairo_surface_destroy(icon_surface);
|
||||
cairo_fill (cr);
|
||||
@ -260,25 +258,7 @@ static void render_button_in_context(EekRenderer *self,
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* render label */
|
||||
layout = pango_cairo_create_layout (cr);
|
||||
eek_renderer_real_render_button_label (self, layout, place->button);
|
||||
pango_layout_get_extents (layout, NULL, &extents);
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_move_to
|
||||
(cr,
|
||||
(bounds.width - (double)extents.width / PANGO_SCALE) / 2,
|
||||
(bounds.height - (double)extents.height / PANGO_SCALE) / 2);
|
||||
|
||||
cairo_set_source_rgba (cr,
|
||||
foreground.red,
|
||||
foreground.green,
|
||||
foreground.blue,
|
||||
foreground.alpha);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
cairo_restore (cr);
|
||||
g_object_unref (layout);
|
||||
eek_renderer_render_button_label (self, cr, ctx, place->button);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -363,9 +343,10 @@ eek_renderer_apply_transformation_for_button (cairo_t *cr,
|
||||
}
|
||||
|
||||
static void
|
||||
eek_renderer_real_render_button_label (EekRenderer *self,
|
||||
PangoLayout *layout,
|
||||
const struct squeek_button *button)
|
||||
eek_renderer_render_button_label (EekRenderer *self,
|
||||
cairo_t *cr,
|
||||
GtkStyleContext *ctx,
|
||||
const struct squeek_button *button)
|
||||
{
|
||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
||||
|
||||
@ -381,16 +362,11 @@ eek_renderer_real_render_button_label (EekRenderer *self,
|
||||
|
||||
if (!priv->font) {
|
||||
const PangoFontDescription *base_font;
|
||||
gdouble ascii_size, size;
|
||||
gdouble size;
|
||||
|
||||
base_font = pango_context_get_font_description (priv->pcontext);
|
||||
// FIXME: Base font size on the same size unit used for button sizing,
|
||||
// and make the default about 1/3 of the current row height
|
||||
ascii_size = 30000.0;
|
||||
priv->ascii_font = pango_font_description_copy (base_font);
|
||||
pango_font_description_set_size (priv->ascii_font,
|
||||
(gint)round(ascii_size));
|
||||
|
||||
size = 30000.0;
|
||||
priv->font = pango_font_description_copy (base_font);
|
||||
pango_font_description_set_size (priv->font, (gint)round(size * 0.6));
|
||||
@ -403,6 +379,8 @@ eek_renderer_real_render_button_label (EekRenderer *self,
|
||||
font = pango_font_description_copy (priv->font);
|
||||
pango_font_description_set_size (font,
|
||||
(gint)round(pango_font_description_get_size (font) * scale));
|
||||
|
||||
PangoLayout *layout = pango_cairo_create_layout (cr);
|
||||
pango_layout_set_font_description (layout, font);
|
||||
pango_font_description_free (font);
|
||||
|
||||
@ -413,6 +391,27 @@ eek_renderer_real_render_button_label (EekRenderer *self,
|
||||
}
|
||||
pango_layout_set_width (layout,
|
||||
PANGO_SCALE * bounds.width * scale);
|
||||
|
||||
PangoRectangle extents = { 0, };
|
||||
pango_layout_get_extents (layout, NULL, &extents);
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_move_to
|
||||
(cr,
|
||||
(bounds.width - (double)extents.width / PANGO_SCALE) / 2,
|
||||
(bounds.height - (double)extents.height / PANGO_SCALE) / 2);
|
||||
|
||||
GdkRGBA color = {0};
|
||||
gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color);
|
||||
|
||||
cairo_set_source_rgba (cr,
|
||||
color.red,
|
||||
color.green,
|
||||
color.blue,
|
||||
color.alpha);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
cairo_restore (cr);
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -550,7 +549,6 @@ eek_renderer_finalize (GObject *object)
|
||||
g_object_unref(priv->css_provider);
|
||||
g_object_unref(priv->view_context);
|
||||
g_object_unref(priv->button_context);
|
||||
pango_font_description_free (priv->ascii_font);
|
||||
pango_font_description_free (priv->font);
|
||||
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
|
||||
}
|
||||
@ -850,22 +848,6 @@ eek_renderer_render_keyboard (EekRenderer *renderer,
|
||||
EEK_RENDERER_GET_CLASS(renderer)->render_keyboard (renderer, cr);
|
||||
}
|
||||
|
||||
void
|
||||
eek_renderer_get_foreground_color (GtkStyleContext *context,
|
||||
EekColor *color)
|
||||
{
|
||||
g_return_if_fail (color);
|
||||
|
||||
GtkStateFlags flags = GTK_STATE_FLAG_NORMAL;
|
||||
GdkRGBA gcolor;
|
||||
|
||||
gtk_style_context_get_color (context, flags, &gcolor);
|
||||
color->red = gcolor.red;
|
||||
color->green = gcolor.green;
|
||||
color->blue = gcolor.blue;
|
||||
color->alpha = gcolor.alpha;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sign (EekPoint *p1, EekPoint *p2, EekPoint *p3)
|
||||
{
|
||||
|
||||
@ -86,16 +86,6 @@ cairo_surface_t *eek_renderer_get_icon_surface(const gchar *icon_name,
|
||||
|
||||
void eek_renderer_render_keyboard (EekRenderer *renderer,
|
||||
cairo_t *cr);
|
||||
|
||||
void eek_renderer_set_default_foreground_color
|
||||
(EekRenderer *renderer,
|
||||
const EekColor *color);
|
||||
void eek_renderer_set_default_background_color
|
||||
(EekRenderer *renderer,
|
||||
const EekColor *color);
|
||||
void eek_renderer_get_foreground_color
|
||||
(GtkStyleContext *context,
|
||||
EekColor *color);
|
||||
void eek_renderer_set_border_width (EekRenderer *renderer,
|
||||
gdouble border_width);
|
||||
void eek_renderer_apply_transformation_for_button
|
||||
|
||||
@ -72,35 +72,3 @@ eek_bounds_free (EekBounds *bounds)
|
||||
{
|
||||
g_slice_free (EekBounds, bounds);
|
||||
}
|
||||
|
||||
/* EekColor */
|
||||
G_DEFINE_BOXED_TYPE(EekColor, eek_color, eek_color_copy, eek_color_free);
|
||||
|
||||
EekColor *
|
||||
eek_color_copy (const EekColor *color)
|
||||
{
|
||||
return g_slice_dup (EekColor, color);
|
||||
}
|
||||
|
||||
void
|
||||
eek_color_free (EekColor *color)
|
||||
{
|
||||
g_slice_free (EekColor, color);
|
||||
}
|
||||
|
||||
EekColor *
|
||||
eek_color_new (gdouble red,
|
||||
gdouble green,
|
||||
gdouble blue,
|
||||
gdouble alpha)
|
||||
{
|
||||
EekColor *color;
|
||||
|
||||
color = g_slice_new (EekColor);
|
||||
color->red = red;
|
||||
color->green = green;
|
||||
color->blue = blue;
|
||||
color->alpha = alpha;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@ -34,10 +34,8 @@ G_BEGIN_DECLS
|
||||
|
||||
#define EEK_TYPE_POINT (eek_point_get_type ())
|
||||
#define EEK_TYPE_BOUNDS (eek_bounds_get_type ())
|
||||
#define EEK_TYPE_COLOR (eek_color_get_type ())
|
||||
|
||||
typedef struct _EekBounds EekBounds;
|
||||
typedef struct _EekColor EekColor;
|
||||
|
||||
typedef struct _EekboardContextService EekboardContextService;
|
||||
typedef struct _LevelKeyboard LevelKeyboard;
|
||||
@ -85,33 +83,6 @@ GType eek_bounds_get_type (void) G_GNUC_CONST;
|
||||
EekBounds *eek_bounds_copy (const EekBounds *bounds);
|
||||
void eek_bounds_free (EekBounds *bounds);
|
||||
|
||||
/**
|
||||
* EekColor:
|
||||
* @red: red component of color, between 0.0 and 1.0
|
||||
* @green: green component of color, between 0.0 and 1.0
|
||||
* @blue: blue component of color, between 0.0 and 1.0
|
||||
* @alpha: alpha component of color, between 0.0 and 1.0
|
||||
*
|
||||
* Color used for drawing.
|
||||
*/
|
||||
struct _EekColor
|
||||
{
|
||||
/*< public >*/
|
||||
gdouble red;
|
||||
gdouble green;
|
||||
gdouble blue;
|
||||
gdouble alpha;
|
||||
};
|
||||
|
||||
GType eek_color_get_type (void) G_GNUC_CONST;
|
||||
|
||||
EekColor *eek_color_new (gdouble red,
|
||||
gdouble green,
|
||||
gdouble blue,
|
||||
gdouble alpha);
|
||||
EekColor *eek_color_copy (const EekColor *color);
|
||||
void eek_color_free (EekColor *color);
|
||||
|
||||
struct transformation {
|
||||
gdouble origin_x;
|
||||
gdouble origin_y;
|
||||
|
||||
Reference in New Issue
Block a user