[gimp] app: remove almost all code from GimpOverlayFrame
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: remove almost all code from GimpOverlayFrame
- Date: Mon, 21 May 2018 22:36:19 +0000 (UTC)
commit 2152bdc588661daf7f271dcf86ca481aca8762ad
Author: Michael Natterer <mitch gimp org>
Date: Tue May 22 00:35:04 2018 +0200
app: remove almost all code from GimpOverlayFrame
Let the parent GtkBin handle size request and allocation, and steal
the CDD style from GtkPopover.
app/widgets/gimpoverlayframe.c | 116 ++++++++--------------------------------
1 files changed, 22 insertions(+), 94 deletions(-)
---
diff --git a/app/widgets/gimpoverlayframe.c b/app/widgets/gimpoverlayframe.c
index 67a8e47..9c4b48b 100644
--- a/app/widgets/gimpoverlayframe.c
+++ b/app/widgets/gimpoverlayframe.c
@@ -32,16 +32,8 @@
#include "gimpwidgets-utils.h"
-static void gimp_overlay_frame_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width);
-static void gimp_overlay_frame_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height);
-static void gimp_overlay_frame_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gboolean gimp_overlay_frame_draw (GtkWidget *widget,
- cairo_t *cr);
+static gboolean gimp_overlay_frame_draw (GtkWidget *widget,
+ cairo_t *cr);
G_DEFINE_TYPE (GimpOverlayFrame, gimp_overlay_frame, GTK_TYPE_BIN)
@@ -54,78 +46,18 @@ gimp_overlay_frame_class_init (GimpOverlayFrameClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- widget_class->get_preferred_width = gimp_overlay_frame_get_preferred_width;
- widget_class->get_preferred_height = gimp_overlay_frame_get_preferred_height;
- widget_class->size_allocate = gimp_overlay_frame_size_allocate;
- widget_class->draw = gimp_overlay_frame_draw;
+ widget_class->draw = gimp_overlay_frame_draw;
+
+ gtk_widget_class_set_css_name (widget_class, "popover");
}
static void
gimp_overlay_frame_init (GimpOverlayFrame *frame)
{
gtk_widget_set_app_paintable (GTK_WIDGET (frame), TRUE);
-}
-
-static void
-gimp_overlay_frame_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
- gint border_width;
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
- if (child && gtk_widget_get_visible (child))
- gtk_widget_get_preferred_width (child, minimum_width, natural_width);
- else
- *minimum_width = *natural_width = 0;
-
- *minimum_width += 2 * border_width;
- *natural_width += 2 * border_width;
-}
-
-static void
-gimp_overlay_frame_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
- gint border_width;
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
- if (child && gtk_widget_get_visible (child))
- gtk_widget_get_preferred_height (child, minimum_height, natural_height);
- else
- *minimum_height = *natural_height = 0;
- *minimum_height += 2 * border_width;
- *natural_height += 2 * border_width;
-}
-
-static void
-gimp_overlay_frame_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-
- gtk_widget_set_allocation (widget, allocation);
-
- if (child && gtk_widget_get_visible (child))
- {
- GtkAllocation child_allocation;
- gint border_width;
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
- child_allocation.x = allocation->x + border_width;
- child_allocation.y = allocation->y + border_width;
- child_allocation.width = MAX (allocation->width - 2 * border_width, 0);
- child_allocation.height = MAX (allocation->height - 2 * border_width, 0);
-
- gtk_widget_size_allocate (child, &child_allocation);
- }
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (frame)),
+ "background");
}
static gboolean
@@ -134,9 +66,8 @@ gimp_overlay_frame_draw (GtkWidget *widget,
{
GtkStyleContext *style = gtk_widget_get_style_context (widget);
GtkAllocation allocation;
- GdkRGBA color;
gboolean rgba;
- gint border_width;
+ gint border_radius;
rgba = gdk_screen_get_rgba_visual (gtk_widget_get_screen (widget)) != NULL;
@@ -148,37 +79,34 @@ gimp_overlay_frame_draw (GtkWidget *widget,
}
gtk_widget_get_allocation (widget, &allocation);
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ gtk_style_context_get (style, gtk_style_context_get_state (style),
+ "border-radius", &border_radius,
+ NULL);
if (rgba)
{
gimp_cairo_rounded_rectangle (cr,
0.0, 0.0,
allocation.width, allocation.height,
- border_width);
+ border_radius);
}
else
{
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
}
- cairo_clip_preserve (cr);
+ cairo_clip (cr);
- gtk_style_context_get_background_color (style,
- gtk_widget_get_state_flags (widget),
- &color);
- gdk_cairo_set_source_rgba (cr, &color);
- cairo_paint (cr);
+ gtk_render_background (style, cr,
+ 0, 0,
+ allocation.width,
+ allocation.height);
- if (border_width > 0)
- {
- cairo_set_line_width (cr, 2.0);
- gtk_style_context_get_color (style,
- gtk_widget_get_state_flags (widget),
- &color);
- gdk_cairo_set_source_rgba (cr, &color);
- cairo_stroke (cr);
- }
+ gtk_render_frame (style, cr,
+ 0, 0,
+ allocation.width,
+ allocation.height);
return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]