diff --git a/clutter/clutter-canvas.c b/clutter/clutter-canvas.c index 071d1d868..eb9eeb83d 100644 --- a/clutter/clutter-canvas.c +++ b/clutter/clutter-canvas.c @@ -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; +} diff --git a/clutter/clutter-canvas.h b/clutter/clutter-canvas.h index 2ab4a48e7..4e8f2ae4f 100644 --- a/clutter/clutter-canvas.h +++ b/clutter/clutter-canvas.h @@ -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 diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols index d34c94e29..dd3bc1081 100644 --- a/clutter/clutter.symbols +++ b/clutter/clutter.symbols @@ -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 diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 8550d3426..019fa065f 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -3225,6 +3225,8 @@ ClutterCanvas ClutterCanvasClass clutter_canvas_new clutter_canvas_set_size +clutter_canvas_set_scale_factor +clutter_canvas_get_scale_factor CLUTTER_TYPE_CANVAS CLUTTER_CANVAS