colorswatch: Render background properly
We want to render a background *and* the current color (if there is one). This also adds a custom function gtk_render_add_content_path() which adds the path of the current content area to a cairo_t.
This commit is contained in:
parent
7295c8f12b
commit
c39bd623f6
@ -20,8 +20,6 @@
|
|||||||
#include "gtkcolorswatchprivate.h"
|
#include "gtkcolorswatchprivate.h"
|
||||||
|
|
||||||
#include "gtkcolorchooserprivate.h"
|
#include "gtkcolorchooserprivate.h"
|
||||||
#include "gtkroundedboxprivate.h"
|
|
||||||
#include "gtkthemingbackgroundprivate.h"
|
|
||||||
#include "gtkdnd.h"
|
#include "gtkdnd.h"
|
||||||
#include "gtkicontheme.h"
|
#include "gtkicontheme.h"
|
||||||
#include "gtkmain.h"
|
#include "gtkmain.h"
|
||||||
@ -30,6 +28,7 @@
|
|||||||
#include "gtkmenushell.h"
|
#include "gtkmenushell.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
|
#include "gtkrenderprivate.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "a11y/gtkcolorswatchaccessibleprivate.h"
|
#include "a11y/gtkcolorswatchaccessibleprivate.h"
|
||||||
|
|
||||||
@ -107,7 +106,6 @@ swatch_draw (GtkWidget *widget,
|
|||||||
cairo_t *cr)
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
|
GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
|
||||||
GtkThemingBackground background;
|
|
||||||
gdouble width, height;
|
gdouble width, height;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkStateFlags state;
|
GtkStateFlags state;
|
||||||
@ -126,20 +124,19 @@ swatch_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
gtk_style_context_save (context);
|
gtk_style_context_save (context);
|
||||||
|
|
||||||
_gtk_theming_background_init (&background, context,
|
gtk_render_background (context, cr, 0, 0, width, height);
|
||||||
0, 0, width, height,
|
|
||||||
GTK_JUNCTION_NONE);
|
|
||||||
|
|
||||||
if (swatch->priv->has_color)
|
if (swatch->priv->has_color)
|
||||||
{
|
{
|
||||||
cairo_pattern_t *pattern;
|
cairo_pattern_t *pattern;
|
||||||
cairo_matrix_t matrix;
|
cairo_matrix_t matrix;
|
||||||
|
|
||||||
|
gtk_render_content_path (context, cr, 0, 0, width, height);
|
||||||
|
|
||||||
if (swatch->priv->use_alpha)
|
if (swatch->priv->use_alpha)
|
||||||
{
|
{
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
_gtk_rounded_box_path (&background.padding_box, cr);
|
|
||||||
cairo_clip_preserve (cr);
|
cairo_clip_preserve (cr);
|
||||||
|
|
||||||
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
|
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
|
||||||
@ -155,18 +152,18 @@ swatch_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
|
|
||||||
background.bg_color = swatch->priv->color;
|
gdk_cairo_set_source_rgba (cr, &swatch->priv->color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
background.bg_color = swatch->priv->color;
|
cairo_set_source_rgb (cr,
|
||||||
background.bg_color.alpha = 1.0;
|
swatch->priv->color.red,
|
||||||
|
swatch->priv->color.green,
|
||||||
|
swatch->priv->color.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
_gtk_theming_background_render (&background, cr);
|
cairo_fill (cr);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
_gtk_theming_background_render (&background, cr);
|
|
||||||
|
|
||||||
gtk_render_frame (context, cr, 0, 0, width, height);
|
gtk_render_frame (context, cr, 0, 0, width, height);
|
||||||
|
|
||||||
|
@ -2446,3 +2446,47 @@ gtk_render_icon_surface (GtkStyleContext *context,
|
|||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
GtkRoundedBox 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_context (&box, context, 0);
|
||||||
|
|
||||||
|
_gtk_rounded_box_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));
|
||||||
|
|
||||||
|
_gtk_rounded_box_path (&box, cr);
|
||||||
|
}
|
||||||
|
@ -22,6 +22,12 @@
|
|||||||
#include <pango/pango.h>
|
#include <pango/pango.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
|
void gtk_render_content_path (GtkStyleContext *context,
|
||||||
|
cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double width,
|
||||||
|
double height);
|
||||||
void gtk_render_paint_spinner (cairo_t *cr,
|
void gtk_render_paint_spinner (cairo_t *cr,
|
||||||
gdouble radius,
|
gdouble radius,
|
||||||
gdouble progress);
|
gdouble progress);
|
||||||
|
Loading…
Reference in New Issue
Block a user