[gnome-software: 54/110] Replace GtkWidget.draw by GtkWidget.snapshot
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 54/110] Replace GtkWidget.draw by GtkWidget.snapshot
- Date: Tue, 5 Oct 2021 20:32:37 +0000 (UTC)
commit d81b38aa6a145a9361c81312e5c071a730b87f5a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Aug 24 19:48:24 2021 -0300
Replace GtkWidget.draw by GtkWidget.snapshot
src/gs-review-bar.c | 41 ++++++++++++++++++-----------------------
src/gs-screenshot-image.c | 24 +++++++++++-------------
src/gs-star-image.c | 16 +++++++++++-----
3 files changed, 40 insertions(+), 41 deletions(-)
---
diff --git a/src/gs-review-bar.c b/src/gs-review-bar.c
index 8b4e50453..a20c997a2 100644
--- a/src/gs-review-bar.c
+++ b/src/gs-review-bar.c
@@ -32,40 +32,35 @@ gs_review_bar_init (GsReviewBar *bar)
{
}
-static gboolean
-gs_review_bar_draw (GtkWidget *widget, cairo_t *cr)
+static void
+gs_review_bar_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
- GtkStyleContext *context;
- gdouble y_offset, bar_height;
+ gdouble y_offset, bar_width, bar_height;
GdkRGBA color;
- context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (gtk_widget_get_style_context (widget), &color);
/* don't fill the complete height (too heavy beside GtkLabel of that height) */
- y_offset = floor (0.15 * gtk_widget_get_allocated_height (widget));
- bar_height = gtk_widget_get_allocated_height (widget) - (y_offset * 2);
-
- gtk_render_background (context, cr,
- 0, y_offset,
- gtk_widget_get_allocated_width (widget),
- bar_height);
-
- cairo_rectangle (cr,
- 0, y_offset,
- round (GS_REVIEW_BAR (widget)->fraction * gtk_widget_get_allocated_width (widget)),
- bar_height);
- gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color);
- cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
- cairo_fill (cr);
-
- return GTK_WIDGET_CLASS (gs_review_bar_parent_class)->draw (widget, cr);
+ y_offset = floor (0.15 * gtk_widget_get_height (widget));
+ bar_height = gtk_widget_get_height (widget) - (y_offset * 2);
+ bar_width = round (GS_REVIEW_BAR (widget)->fraction * gtk_widget_get_width (widget));
+
+ gtk_snapshot_append_color (snapshot,
+ &color,
+ &GRAPHENE_RECT_INIT (0,
+ y_offset,
+ bar_width,
+ bar_height));
+
+ GTK_WIDGET_CLASS (gs_review_bar_parent_class)->snapshot (widget, snapshot);
}
static void
gs_review_bar_class_init (GsReviewBarClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- widget_class->draw = gs_review_bar_draw;
+ widget_class->snapshot = gs_review_bar_snapshot;
gtk_widget_class_set_css_name (widget_class, "review-bar");
}
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 21ce662e9..b8eca0220 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -684,22 +684,20 @@ gs_screenshot_image_init (GsScreenshotImage *ssimg)
gtk_widget_init_template (GTK_WIDGET (ssimg));
}
-static gboolean
-gs_screenshot_image_draw (GtkWidget *widget, cairo_t *cr)
+static void
+gs_screenshot_image_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
- gtk_render_background (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
- gtk_render_frame (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
-
- return GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->draw (widget, cr);
+ gtk_snapshot_render_frame (snapshot,
+ context,
+ 0.0, 0.0,
+ gtk_widget_get_width (widget),
+ gtk_widget_get_height (widget));
+
+ GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->snapshot (widget, snapshot);
}
static void
@@ -710,7 +708,7 @@ gs_screenshot_image_class_init (GsScreenshotImageClass *klass)
object_class->dispose = gs_screenshot_image_dispose;
- widget_class->draw = gs_screenshot_image_draw;
+ widget_class->snapshot = gs_screenshot_image_snapshot;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Software/gs-screenshot-image.ui");
diff --git a/src/gs-star-image.c b/src/gs-star-image.c
index cf4161dae..254a037ef 100644
--- a/src/gs-star-image.c
+++ b/src/gs-star-image.c
@@ -137,11 +137,12 @@ gs_star_image_set_property (GObject *object,
}
}
-static gboolean
-gs_star_image_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+gs_star_image_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
GtkAllocation allocation;
+ cairo_t *cr;
gdouble fraction;
gint radius;
@@ -151,6 +152,11 @@ gs_star_image_draw (GtkWidget *widget,
radius = MIN (allocation.width, allocation.height) / 2;
+ cr = gtk_snapshot_append_cairo (snapshot,
+ &GRAPHENE_RECT_INIT (0, 0,
+ gtk_widget_get_width (widget),
+ gtk_widget_get_height (widget)));
+
if (radius > 0) {
GtkStyleContext *style_context;
GdkRGBA *star_bg = NULL;
@@ -187,7 +193,7 @@ gs_star_image_draw (GtkWidget *widget,
g_clear_pointer (&star_bg, gdk_rgba_free);
}
- return FALSE;
+ cairo_destroy (cr);
}
static void
@@ -201,7 +207,7 @@ gs_star_image_class_init (GsStarImageClass *klass)
object_class->set_property = gs_star_image_set_property;
widget_class = GTK_WIDGET_CLASS (klass);
- widget_class->draw = gs_star_image_draw;
+ widget_class->snapshot = gs_star_image_snapshot;
g_object_class_install_property (object_class,
PROP_FRACTION,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]