From 03c4628cadc72b627581f82a889c10e6d4514af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 31 Jul 2017 14:08:29 +0200 Subject: [PATCH] st-drawing-area: Draw content taking care of the resource_scale https://bugzilla.gnome.org/show_bug.cgi?id=765011 --- src/st/st-drawing-area.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/st/st-drawing-area.c b/src/st/st-drawing-area.c index e8fc4f6d2..f561759c6 100644 --- a/src/st/st-drawing-area.c +++ b/src/st/st-drawing-area.c @@ -35,6 +35,7 @@ #include "st-drawing-area.h" #include +#include typedef struct _StDrawingAreaPrivate StDrawingAreaPrivate; struct _StDrawingAreaPrivate { @@ -84,12 +85,22 @@ st_drawing_area_allocate (ClutterActor *self, ClutterContent *content = clutter_actor_get_content (self); ClutterActorBox content_box; int width, height; + float resource_scale; + + if (!st_widget_get_resource_scale (ST_WIDGET (self), &resource_scale)) + { + ClutterActorBox empty = CLUTTER_ACTOR_BOX_INIT_ZERO; + clutter_actor_set_allocation (self, &empty, 0); + return; + } clutter_actor_set_allocation (self, box, flags); st_theme_node_get_content_box (theme_node, box, &content_box); width = (int)(0.5 + content_box.x2 - content_box.x1); height = (int)(0.5 + content_box.y2 - content_box.y1); + + clutter_canvas_set_scale_factor (CLUTTER_CANVAS (content), resource_scale); clutter_canvas_set_size (CLUTTER_CANVAS (content), width, height); } @@ -101,6 +112,16 @@ st_drawing_area_style_changed (StWidget *self) st_drawing_area_queue_repaint (ST_DRAWING_AREA (self)); } +static void +st_drawing_area_resource_scale_changed (StWidget *self) +{ + float resource_scale; + ClutterContent *content = clutter_actor_get_content (CLUTTER_ACTOR (self)); + + if (st_widget_get_resource_scale (ST_WIDGET (self), &resource_scale)) + clutter_canvas_set_scale_factor (CLUTTER_CANVAS (content), resource_scale); +} + static void st_drawing_area_class_init (StDrawingAreaClass *klass) { @@ -109,6 +130,7 @@ st_drawing_area_class_init (StDrawingAreaClass *klass) actor_class->allocate = st_drawing_area_allocate; widget_class->style_changed = st_drawing_area_style_changed; + widget_class->resource_scale_changed = st_drawing_area_resource_scale_changed; st_drawing_area_signals[REPAINT] = g_signal_new ("repaint", @@ -185,7 +207,7 @@ st_drawing_area_get_surface_size (StDrawingArea *area, { StDrawingAreaPrivate *priv; ClutterContent *content; - float w, h; + float w, h, resource_scale; g_return_if_fail (ST_IS_DRAWING_AREA (area)); @@ -195,8 +217,18 @@ st_drawing_area_get_surface_size (StDrawingArea *area, content = clutter_actor_get_content (CLUTTER_ACTOR (area)); clutter_content_get_preferred_size (content, &w, &h); + if (st_widget_get_resource_scale (ST_WIDGET (area), &resource_scale)) + { + w /= resource_scale; + h /= resource_scale; + } + else + { + w = h = 0.0f; + } + if (width) - *width = (guint)w; + *width = ceilf (w); if (height) - *height = (guint)h; + *height = ceilf (h); }