mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
canvas: Add scale-factor property
We need to provide an escape hatch to ClutterCanvas so that it's possible to override the window-scaling-factor ClutterSetting. This is going to be useful in the future in case the user has better knowledge of the window scaling factor that is going to be used with a specific set of ClutterCanvas contents (e.g. on different outputs or stages). https://bugzilla.gnome.org/show_bug.cgi?id=705915
This commit is contained in:
parent
c1d6194d24
commit
857f53f42d
@ -77,6 +77,9 @@ struct _ClutterCanvasPrivate
|
||||
int height;
|
||||
|
||||
CoglBitmap *buffer;
|
||||
|
||||
int scale_factor;
|
||||
guint scale_factor_set : 1;
|
||||
};
|
||||
|
||||
enum
|
||||
@ -85,6 +88,8 @@ enum
|
||||
|
||||
PROP_WIDTH,
|
||||
PROP_HEIGHT,
|
||||
PROP_SCALE_FACTOR,
|
||||
PROP_SCALE_FACTOR_SET,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
@ -179,6 +184,11 @@ clutter_canvas_set_property (GObject *gobject,
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_SCALE_FACTOR:
|
||||
clutter_canvas_set_scale_factor (CLUTTER_CANVAS (gobject),
|
||||
g_value_get_int (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
@ -203,6 +213,17 @@ clutter_canvas_get_property (GObject *gobject,
|
||||
g_value_set_int (value, priv->height);
|
||||
break;
|
||||
|
||||
case PROP_SCALE_FACTOR:
|
||||
if (priv->scale_factor_set)
|
||||
g_value_set_int (value, priv->scale_factor);
|
||||
else
|
||||
g_value_set_int (value, -1);
|
||||
break;
|
||||
|
||||
case PROP_SCALE_FACTOR_SET:
|
||||
g_value_set_boolean (value, priv->scale_factor_set);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
@ -246,6 +267,47 @@ clutter_canvas_class_init (ClutterCanvasClass *klass)
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* ClutterCanvas:scale-factor-set:
|
||||
*
|
||||
* Whether the #ClutterCanvas:scale-factor property is set.
|
||||
*
|
||||
* If the #ClutterCanvas:scale-factor-set property is %FALSE
|
||||
* then #ClutterCanvas will use the #ClutterSettings:window-scaling-factor
|
||||
* property.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
obj_props[PROP_SCALE_FACTOR_SET] =
|
||||
g_param_spec_boolean ("scale-factor-set",
|
||||
P_("Scale Factor Set"),
|
||||
P_("Whether the scale-factor property is set"),
|
||||
FALSE,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* ClutterCanvas:scale-factor:
|
||||
*
|
||||
* The scaling factor to be applied to the Cairo surface used for
|
||||
* drawing.
|
||||
*
|
||||
* If #ClutterCanvas:scale-factor is set to a negative value, the
|
||||
* value of the #ClutterSettings:window-scaling-factor property is
|
||||
* used instead.
|
||||
*
|
||||
* Use #ClutterCanvas:scale-factor-set to check if the scale factor
|
||||
* is set.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
obj_props[PROP_SCALE_FACTOR] =
|
||||
g_param_spec_int ("scale-factor",
|
||||
P_("Scale Factor"),
|
||||
P_("The scaling factor for the surface"),
|
||||
-1, 1000,
|
||||
-1,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* ClutterCanvas::draw:
|
||||
* @canvas: the #ClutterCanvas that emitted the signal
|
||||
@ -288,8 +350,10 @@ static void
|
||||
clutter_canvas_init (ClutterCanvas *self)
|
||||
{
|
||||
self->priv = clutter_canvas_get_instance_private (self);
|
||||
|
||||
self->priv->width = -1;
|
||||
self->priv->height = -1;
|
||||
self->priv->scale_factor = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -366,9 +430,12 @@ clutter_canvas_emit_draw (ClutterCanvas *self)
|
||||
|
||||
g_assert (priv->width > 0 && priv->width > 0);
|
||||
|
||||
g_object_get (clutter_settings_get_default (),
|
||||
"window-scaling-factor", &window_scale,
|
||||
NULL);
|
||||
if (priv->scale_factor_set)
|
||||
window_scale = priv->scale_factor;
|
||||
else
|
||||
g_object_get (clutter_settings_get_default (),
|
||||
"window-scaling-factor", &window_scale,
|
||||
NULL);
|
||||
|
||||
real_width = priv->width * window_scale;
|
||||
real_height = priv->height * window_scale;
|
||||
@ -596,3 +663,81 @@ clutter_canvas_set_size (ClutterCanvas *canvas,
|
||||
|
||||
return clutter_canvas_invalidate_internal (canvas, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_canvas_set_scale_factor:
|
||||
* @canvas: a #ClutterCanvas
|
||||
* @scale: the scale factor, or -1 for the default
|
||||
*
|
||||
* Sets the scaling factor for the Cairo surface used by @canvas.
|
||||
*
|
||||
* This function should rarely be used.
|
||||
*
|
||||
* The default scaling factor of a #ClutterCanvas content uses the
|
||||
* #ClutterSettings:window-scaling-factor property, which is set by
|
||||
* the windowing system. By using this function it is possible to
|
||||
* override that setting.
|
||||
*
|
||||
* Changing the scale factor will invalidate the @canvas.
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
void
|
||||
clutter_canvas_set_scale_factor (ClutterCanvas *canvas,
|
||||
int scale)
|
||||
{
|
||||
ClutterCanvasPrivate *priv;
|
||||
GObject *obj;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_CANVAS (canvas));
|
||||
g_return_if_fail (scale != 0);
|
||||
|
||||
priv = canvas->priv;
|
||||
|
||||
if (scale < 0)
|
||||
{
|
||||
if (!priv->scale_factor_set)
|
||||
return;
|
||||
|
||||
priv->scale_factor_set = FALSE;
|
||||
priv->scale_factor = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (priv->scale_factor_set && priv->scale_factor == scale)
|
||||
return;
|
||||
|
||||
priv->scale_factor_set = TRUE;
|
||||
priv->scale_factor = scale;
|
||||
}
|
||||
|
||||
clutter_content_invalidate (CLUTTER_CONTENT (canvas));
|
||||
|
||||
obj = G_OBJECT (canvas);
|
||||
|
||||
g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_FACTOR]);
|
||||
g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_FACTOR_SET]);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_canvas_get_scale_factor:
|
||||
* @canvas: a #ClutterCanvas
|
||||
*
|
||||
* Retrieves the scaling factor of @canvas, as set using
|
||||
* clutter_canvas_set_scale_factor().
|
||||
*
|
||||
* Return value: the scaling factor, or -1 if the @canvas
|
||||
* uses the default from #ClutterSettings
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
int
|
||||
clutter_canvas_get_scale_factor (ClutterCanvas *canvas)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_CANVAS (canvas), -1);
|
||||
|
||||
if (!canvas->priv->scale_factor_set)
|
||||
return -1;
|
||||
|
||||
return canvas->priv->scale_factor;
|
||||
}
|
||||
|
@ -95,6 +95,11 @@ gboolean clutter_canvas_set_size (ClutterCanvas *
|
||||
int width,
|
||||
int height);
|
||||
|
||||
CLUTTER_AVAILABLE_IN_1_18
|
||||
void clutter_canvas_set_scale_factor (ClutterCanvas *canvas,
|
||||
int scale);
|
||||
CLUTTER_AVAILABLE_IN_1_18
|
||||
int clutter_canvas_get_scale_factor (ClutterCanvas *canvas);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -521,6 +521,8 @@ clutter_brightness_contrast_effect_set_contrast_full
|
||||
clutter_brightness_contrast_effect_set_contrast
|
||||
clutter_canvas_get_type
|
||||
clutter_canvas_new
|
||||
clutter_canvas_get_scale_factor
|
||||
clutter_canvas_set_scale_factor
|
||||
clutter_canvas_set_size
|
||||
clutter_cairo_clear
|
||||
clutter_cairo_set_source_color
|
||||
|
@ -3225,6 +3225,8 @@ ClutterCanvas
|
||||
ClutterCanvasClass
|
||||
clutter_canvas_new
|
||||
clutter_canvas_set_size
|
||||
clutter_canvas_set_scale_factor
|
||||
clutter_canvas_get_scale_factor
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_TYPE_CANVAS
|
||||
CLUTTER_CANVAS
|
||||
|
Loading…
Reference in New Issue
Block a user