st-widget: Introduce widget resource scale

This commit makes StWidget manage the scale of which its associated
resources should be multiplied with. The resource scale is calculated
by clutter, and is retrieved by clutter_actor_get_resource_scale(). Due
to the resource scale not always being available, the getter may fail,
and the actual widget that draws the content will have to deal with
this situation.

As the resource scale depends on where on the stage the widget is drawn,
the resource scale will in general be available once the widget is
mapped.

https://bugzilla.gnome.org/show_bug.cgi?id=765011
This commit is contained in:
Jonas Ådahl 2017-05-11 06:30:04 +02:00
parent 3590af15bb
commit 9f4ae9618a
2 changed files with 47 additions and 1 deletions

View File

@ -121,6 +121,7 @@ enum
{
STYLE_CHANGED,
POPUP_MENU,
RESOURCE_SCALE_CHANGED,
LAST_SIGNAL
};
@ -452,6 +453,7 @@ static void
st_widget_parent_set (ClutterActor *widget,
ClutterActor *old_parent)
{
StWidget *self = ST_WIDGET (widget);
ClutterActorClass *parent_class;
ClutterActor *new_parent;
@ -463,7 +465,7 @@ st_widget_parent_set (ClutterActor *widget,
/* don't send the style changed signal if we no longer have a parent actor */
if (new_parent)
st_widget_style_changed (ST_WIDGET (widget));
st_widget_style_changed (self);
}
static void
@ -1019,6 +1021,21 @@ st_widget_class_init (StWidgetClass *klass)
G_STRUCT_OFFSET (StWidgetClass, popup_menu),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* StWidget::resource-scale-changed:
* @widget: the #StWidget
*
* Emitted when the paint scale that the widget will be painted as
* changed.
*/
signals[RESOURCE_SCALE_CHANGED] =
g_signal_new ("resource-scale-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (StWidgetClass, resource_scale_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
/**
@ -1448,6 +1465,23 @@ st_widget_get_style (StWidget *actor)
return ST_WIDGET_PRIVATE (actor)->inline_style;
}
/**
* st_widget_get_resource_scale:
* @widget: A #StWidget
* @resource_scale: (out): return location for the resource scale
*
* Retrieves the resource scale for this #StWidget, if available.
*
* The resource scale refers to the scale the actor should use for its resources.
*/
gboolean
st_widget_get_resource_scale (StWidget *widget,
float *resource_scale)
{
return clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget),
resource_scale);
}
static void
st_widget_name_notify (StWidget *widget,
GParamSpec *pspec,
@ -1456,6 +1490,14 @@ st_widget_name_notify (StWidget *widget,
st_widget_style_changed (widget);
}
static void
st_widget_resource_scale_notify (StWidget *widget,
GParamSpec *pspec,
gpointer data)
{
g_signal_emit (widget, signals[RESOURCE_SCALE_CHANGED], 0);
}
static void
st_widget_reactive_notify (StWidget *widget,
GParamSpec *pspec,
@ -1536,6 +1578,7 @@ st_widget_init (StWidget *actor)
/* connect style changed */
g_signal_connect (actor, "notify::name", G_CALLBACK (st_widget_name_notify), NULL);
g_signal_connect (actor, "notify::resource-scale", G_CALLBACK (st_widget_resource_scale_notify), NULL);
g_signal_connect (actor, "notify::reactive", G_CALLBACK (st_widget_reactive_notify), NULL);
g_signal_connect (actor, "notify::first-child", G_CALLBACK (st_widget_first_child_notify), NULL);

View File

@ -63,6 +63,7 @@ struct _StWidgetClass
/* signals */
void (* style_changed) (StWidget *self);
void (* popup_menu) (StWidget *self);
void (* resource_scale_changed) (StWidget *self);
/* vfuncs */
@ -137,6 +138,8 @@ StThemeNode * st_widget_peek_theme_node (StWidget *widg
GList * st_widget_get_focus_chain (StWidget *widget);
void st_widget_paint_background (StWidget *widget);
gboolean st_widget_get_resource_scale (StWidget *widget,
float *resource_scale);
/* debug methods */
char *st_describe_actor (ClutterActor *actor);