diff options
author | Benjamin Otte <otte@redhat.com> | 2016-12-19 19:19:15 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-12-20 18:01:12 +0100 |
commit | 4d9eedafcd13423d4ccb3530fad29bda75701879 (patch) | |
tree | 12a19f366d0268ba98c91861ec37191b619679aa | |
parent | 95a2a5c54c6480b62be482145ee40c58a15b4bd8 (diff) | |
download | gtk+-4d9eedafcd13423d4ccb3530fad29bda75701879.tar.gz |
roundedbox: Add gtk_rounded_boxes_init_for_style()
Instead of making people intiialize a rectangle and then applying border
radius manually, provide a constructor that does it for them.
While doing that, also allow people to instead request the padding box
or the content box.
Refactor all relevant code to use this new constructor.
-rw-r--r-- | docs/reference/gtk/Makefile.am | 1 | ||||
-rw-r--r-- | gtk/Makefile.am | 1 | ||||
-rw-r--r-- | gtk/gtkcolorscale.c | 1 | ||||
-rw-r--r-- | gtk/gtkcolorswatch.c | 18 | ||||
-rw-r--r-- | gtk/gtkcssimagebuiltin.c | 1 | ||||
-rw-r--r-- | gtk/gtkcssshadowvalue.c | 1 | ||||
-rw-r--r-- | gtk/gtkpopover.c | 7 | ||||
-rw-r--r-- | gtk/gtkrender.c | 45 | ||||
-rw-r--r-- | gtk/gtkrenderbackground.c | 36 | ||||
-rw-r--r-- | gtk/gtkrenderborder.c | 6 | ||||
-rw-r--r-- | gtk/gtkrenderprivate.h | 34 | ||||
-rw-r--r-- | gtk/gtkroundedbox.c | 40 | ||||
-rw-r--r-- | gtk/gtkroundedboxprivate.h | 11 |
13 files changed, 68 insertions, 134 deletions
diff --git a/docs/reference/gtk/Makefile.am b/docs/reference/gtk/Makefile.am index 300c5859e2..e02fc818b8 100644 --- a/docs/reference/gtk/Makefile.am +++ b/docs/reference/gtk/Makefile.am @@ -166,7 +166,6 @@ IGNORE_HFILES = \ gtkrenderbackgroundprivate.h \ gtkrenderborderprivate.h \ gtkrendericonprivate.h \ - gtkrenderprivate.h \ gtkroundedboxprivate.h \ gtkscaleprivate.h \ gtksearchengine.h \ diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 2578e1f5f2..bdb489859e 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -526,7 +526,6 @@ gtk_private_h_sources = \ gtkrenderbackgroundprivate.h \ gtkrenderborderprivate.h \ gtkrendericonprivate.h \ - gtkrenderprivate.h \ gtkresources.h \ gtkroundedboxprivate.h \ gtksearchengine.h \ diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c index b6560a76fc..b8564ae13a 100644 --- a/gtk/gtkcolorscale.c +++ b/gtk/gtkcolorscale.c @@ -28,7 +28,6 @@ #include "gtkaccessible.h" #include "gtkprivate.h" #include "gtkintl.h" -#include "gtkrenderprivate.h" #include "gtksnapshot.h" #include <math.h> diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index 15f6b6c73d..9c95754189 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -28,14 +28,15 @@ #include "gtkmenushell.h" #include "gtkprivate.h" #include "gtkintl.h" -#include "gtkrenderprivate.h" #include "gtkiconhelperprivate.h" #include "gtkcssnodeprivate.h" #include "gtkcsscustomgadgetprivate.h" +#include "gtkroundedboxprivate.h" #include "gtkwidgetprivate.h" #include "gtkstylecontextprivate.h" #include "a11y/gtkcolorswatchaccessibleprivate.h" +#include "gsk/gskroundedrectprivate.h" /* * GtkColorSwatch has two CSS nodes, the main one named colorswatch @@ -120,6 +121,7 @@ gtk_color_swatch_render (GtkCssGadget *gadget, cairo_pattern_t *pattern; cairo_matrix_t matrix; GtkAllocation allocation, border_allocation; + GskRoundedRect content_box; gtk_widget_get_allocation (widget, &allocation); gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL); @@ -127,11 +129,15 @@ gtk_color_swatch_render (GtkCssGadget *gadget, border_allocation.x -= allocation.x; border_allocation.y -= allocation.y; - gtk_render_content_path (context, cr, - border_allocation.x, - border_allocation.y, - border_allocation.width, - border_allocation.height); + gtk_rounded_boxes_init_for_style (NULL, + NULL, + &content_box, + gtk_style_context_lookup_style (context), + border_allocation.x, + border_allocation.y, + border_allocation.width, + border_allocation.height); + gsk_rounded_rect_path (&content_box, cr); if (swatch->priv->use_alpha) { diff --git a/gtk/gtkcssimagebuiltin.c b/gtk/gtkcssimagebuiltin.c index 00a267ca1a..67cc061472 100644 --- a/gtk/gtkcssimagebuiltin.c +++ b/gtk/gtkcssimagebuiltin.c @@ -26,7 +26,6 @@ #include "gtkcssrgbavalueprivate.h" #include "gtkcssstyleprivate.h" #include "gtkhslaprivate.h" -#include "gtkrenderprivate.h" #include <math.h> diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c index d9e1aaa3fb..bcb874db98 100644 --- a/gtk/gtkcssshadowvalue.c +++ b/gtk/gtkcssshadowvalue.c @@ -26,7 +26,6 @@ #include "gtkcssrgbavalueprivate.h" #include "gtksnapshot.h" #include "gtkstylecontextprivate.h" -#include "gtkrenderprivate.h" #include "gtkpango.h" #include "gsk/gskcairoblurprivate.h" diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index 6e8ba94c96..48778fb954 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -918,9 +918,10 @@ gtk_popover_fill_border_path (GtkPopover *popover, gtk_popover_get_rect_coords (popover, &x, &y, &w, &h); - _gtk_rounded_box_init_rect (&box, x, y, w, h); - _gtk_rounded_box_apply_border_radius_for_style (&box, - gtk_style_context_lookup_style (context)); + gtk_rounded_boxes_init_for_style (&box, + NULL, NULL, + gtk_style_context_lookup_style (context), + x, y, w, h); gsk_rounded_rect_path (&box, cr); cairo_fill (cr); } diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c index 7ff34275de..3d4bbbaf3e 100644 --- a/gtk/gtkrender.c +++ b/gtk/gtkrender.c @@ -18,7 +18,6 @@ #include "config.h" #include "gtkrender.h" -#include "gtkrenderprivate.h" #include <math.h> @@ -914,47 +913,3 @@ gtk_render_icon_surface (GtkStyleContext *context, x, y); } -/* - * gtk_render_content_path: - * @context: style context to get style information from - * @cr: cairo context to add path to - * @x: x coordinate of CSS box - * @y: y coordinate of CSS box - * @width: width of CSS box - * @height: height of CSS box - * - * Adds the path of the content box to @cr for a given border box. - * This function respects rounded corners. - * - * This is useful if you are drawing content that is supposed to - * fill the whole content area, like the color buttons in - * #GtkColorChooserDialog. - **/ -void -gtk_render_content_path (GtkStyleContext *context, - cairo_t *cr, - double x, - double y, - double width, - double height) -{ - GskRoundedRect box; - - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - g_return_if_fail (cr != NULL); - - _gtk_rounded_box_init_rect (&box, x, y, width, height); - _gtk_rounded_box_apply_border_radius_for_style (&box, gtk_style_context_lookup_style (context)); - - gsk_rounded_rect_shrink (&box, - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100) - + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_TOP), 100), - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100) - + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_RIGHT), 100), - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100) - + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100), - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100) - + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_LEFT), 100)); - - gsk_rounded_rect_path (&box, cr); -} diff --git a/gtk/gtkrenderbackground.c b/gtk/gtkrenderbackground.c index ae80f5fefc..051a9fddd1 100644 --- a/gtk/gtkrenderbackground.c +++ b/gtk/gtkrenderbackground.c @@ -529,39 +529,13 @@ gtk_theming_background_init (GtkThemingBackground *bg, double width, double height) { - GtkBorder border, padding; - bg->style = style; - border.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100); - border.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100); - border.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100); - border.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100); - padding.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_TOP), 100); - padding.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_RIGHT), 100); - padding.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100); - padding.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, GTK_CSS_PROPERTY_PADDING_LEFT), 100); - - /* In the CSS box model, by default the background positioning area is - * the padding-box, i.e. all the border-box minus the borders themselves, - * which determines also its default size, see - * http://dev.w3.org/csswg/css3-background/#background-origin - * - * In the future we might want to support different origins or clips, but - * right now we just shrink to the default. - */ - _gtk_rounded_box_init_rect (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], 0, 0, width, height); - _gtk_rounded_box_apply_border_radius_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], bg->style); - - bg->boxes[GTK_CSS_AREA_PADDING_BOX] = bg->boxes[GTK_CSS_AREA_BORDER_BOX]; - gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_PADDING_BOX], - border.top, border.right, - border.bottom, border.left); - - bg->boxes[GTK_CSS_AREA_CONTENT_BOX] = bg->boxes[GTK_CSS_AREA_PADDING_BOX]; - gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_CONTENT_BOX], - padding.top, padding.right, - padding.bottom, padding.left); + gtk_rounded_boxes_init_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], + &bg->boxes[GTK_CSS_AREA_PADDING_BOX], + &bg->boxes[GTK_CSS_AREA_CONTENT_BOX], + style, + 0, 0, width, height); } void diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c index 429ae39c73..d6223c441f 100644 --- a/gtk/gtkrenderborder.c +++ b/gtk/gtkrenderborder.c @@ -912,8 +912,7 @@ gtk_css_style_render_border (GtkCssStyle *style, colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR)); colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR)); - _gtk_rounded_box_init_rect (&border_box, x, y, width, height); - _gtk_rounded_box_apply_border_radius_for_style (&border_box, style); + gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, x, y, width, height); render_border (cr, &border_box, border_width, colors, border_style); } @@ -970,8 +969,7 @@ gtk_css_style_snapshot_border (GtkCssStyle *style, colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR)); colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_COLOR)); - _gtk_rounded_box_init_rect (&border_box, 0, 0, width, height); - _gtk_rounded_box_apply_border_radius_for_style (&border_box, style); + gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, 0, 0, width, height); snapshot_border (snapshot, &border_box, border_width, colors, border_style); } diff --git a/gtk/gtkrenderprivate.h b/gtk/gtkrenderprivate.h deleted file mode 100644 index 5c851c88fb..0000000000 --- a/gtk/gtkrenderprivate.h +++ /dev/null @@ -1,34 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __GTK_RENDER_PRIVATE_H__ -#define __GTK_RENDER_PRIVATE_H__ - -#include <cairo.h> -#include <pango/pango.h> -#include <gdk/gdk.h> - -#include "gtkcssenumvalueprivate.h" - -void gtk_render_content_path (GtkStyleContext *context, - cairo_t *cr, - double x, - double y, - double width, - double height); - -#endif /* __GTK_RENDER_PRIVATE_H__ */ diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c index 11430c0a70..6c45067d16 100644 --- a/gtk/gtkroundedbox.c +++ b/gtk/gtkroundedbox.c @@ -20,6 +20,7 @@ #include "gtkroundedboxprivate.h" #include "gtkcsscornervalueprivate.h" +#include "gtkcssnumbervalueprivate.h" #include "gtkcsstypesprivate.h" #include "gtkstylecontextprivate.h" @@ -121,17 +122,50 @@ _gtk_rounded_box_apply_border_radius (GskRoundedRect *box, } void -_gtk_rounded_box_apply_border_radius_for_style (GskRoundedRect *box, - GtkCssStyle *style) +gtk_rounded_boxes_init_for_style (GskRoundedRect *border_box, + GskRoundedRect *padding_box, + GskRoundedRect *content_box, + GtkCssStyle *style, + double x, + double y, + double width, + double height) { GtkCssValue *corner[4]; + GskRoundedRect box; + + gsk_rounded_rect_init_from_rect (&box, &GRAPHENE_RECT_INIT (x, y, width, height), 0); corner[GSK_CORNER_TOP_LEFT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS); corner[GSK_CORNER_TOP_RIGHT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS); corner[GSK_CORNER_BOTTOM_LEFT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS); corner[GSK_CORNER_BOTTOM_RIGHT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS); - _gtk_rounded_box_apply_border_radius (box, corner); + _gtk_rounded_box_apply_border_radius (&box, corner); + + if (border_box) + gsk_rounded_rect_init_copy (border_box, &box); + + if (padding_box || content_box) + { + gsk_rounded_rect_shrink (&box, + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100)); + if (padding_box) + gsk_rounded_rect_init_copy (padding_box, &box); + + if (content_box) + { + gsk_rounded_rect_shrink (&box, + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_TOP), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_RIGHT), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100), + _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_PADDING_LEFT), 100)); + gsk_rounded_rect_init_copy (content_box, &box); + } + } } void diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h index 55f72d739a..4f9c0a1697 100644 --- a/gtk/gtkroundedboxprivate.h +++ b/gtk/gtkroundedboxprivate.h @@ -33,9 +33,14 @@ void _gtk_rounded_box_init_rect (GskRoundedRect double y, double width, double height); - -void _gtk_rounded_box_apply_border_radius_for_style (GskRoundedRect *box, - GtkCssStyle *style); +void gtk_rounded_boxes_init_for_style (GskRoundedRect *border_box, + GskRoundedRect *padding_box, + GskRoundedRect *content_box, + GtkCssStyle *style, + double x, + double y, + double width, + double height); void _gtk_rounded_box_apply_outline_radius_for_style (GskRoundedRect *box, GtkCssStyle *style); |