mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 10:50:10 +00:00
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.
This commit is contained in:
parent
95a2a5c54c
commit
4d9eedafcd
@ -166,7 +166,6 @@ IGNORE_HFILES = \
|
||||
gtkrenderbackgroundprivate.h \
|
||||
gtkrenderborderprivate.h \
|
||||
gtkrendericonprivate.h \
|
||||
gtkrenderprivate.h \
|
||||
gtkroundedboxprivate.h \
|
||||
gtkscaleprivate.h \
|
||||
gtksearchengine.h \
|
||||
|
@ -526,7 +526,6 @@ gtk_private_h_sources = \
|
||||
gtkrenderbackgroundprivate.h \
|
||||
gtkrenderborderprivate.h \
|
||||
gtkrendericonprivate.h \
|
||||
gtkrenderprivate.h \
|
||||
gtkresources.h \
|
||||
gtkroundedboxprivate.h \
|
||||
gtksearchengine.h \
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "gtkaccessible.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkrenderprivate.h"
|
||||
#include "gtksnapshot.h"
|
||||
|
||||
#include <math.h>
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "gtkcssrgbavalueprivate.h"
|
||||
#include "gtkcssstyleprivate.h"
|
||||
#include "gtkhslaprivate.h"
|
||||
#include "gtkrenderprivate.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "gtkcssrgbavalueprivate.h"
|
||||
#include "gtksnapshot.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtkrenderprivate.h"
|
||||
#include "gtkpango.h"
|
||||
|
||||
#include "gsk/gskcairoblurprivate.h"
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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__ */
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user