forked from AuroraMiddleware/gtk
color-swatch: use GtkThemingBackground to draw the background
This allows e.g. for the corner radii to be styled directly from the theme.
This commit is contained in:
parent
33e54e45be
commit
1ccedc5fa4
@ -22,6 +22,7 @@
|
|||||||
#include "gtkcolorswatch.h"
|
#include "gtkcolorswatch.h"
|
||||||
|
|
||||||
#include "gtkroundedboxprivate.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"
|
||||||
@ -106,6 +107,7 @@ swatch_draw (GtkWidget *widget,
|
|||||||
cairo_t *cr)
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
|
GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
|
||||||
|
GtkThemingBackground background;
|
||||||
GtkRoundedBox box;
|
GtkRoundedBox box;
|
||||||
gint i;
|
gint i;
|
||||||
gdouble width, height;
|
gdouble width, height;
|
||||||
@ -118,18 +120,14 @@ swatch_draw (GtkWidget *widget,
|
|||||||
width = gtk_widget_get_allocated_width (widget);
|
width = gtk_widget_get_allocated_width (widget);
|
||||||
height = gtk_widget_get_allocated_height (widget);
|
height = gtk_widget_get_allocated_height (widget);
|
||||||
|
|
||||||
gtk_style_context_save (context);
|
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
|
gtk_style_context_save (context);
|
||||||
gtk_style_context_set_state (context, state);
|
gtk_style_context_set_state (context, state);
|
||||||
|
|
||||||
_gtk_rounded_box_init_rect (&box, 0, 0, width, height);
|
_gtk_theming_background_init_from_context (&background, context,
|
||||||
for (i = 0; i < 4; i++)
|
0, 0, width, height,
|
||||||
box.corner[i].horizontal = box.corner[i].vertical = swatch->priv->radius[i];
|
GTK_JUNCTION_NONE);
|
||||||
|
|
||||||
_gtk_rounded_box_path (&box, cr);
|
|
||||||
|
|
||||||
cairo_clip_preserve (cr);
|
|
||||||
|
|
||||||
if (swatch->priv->has_color)
|
if (swatch->priv->has_color)
|
||||||
{
|
{
|
||||||
@ -138,31 +136,37 @@ swatch_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
if (swatch->priv->use_alpha)
|
if (swatch->priv->use_alpha)
|
||||||
{
|
{
|
||||||
|
cairo_save (cr);
|
||||||
|
|
||||||
|
_gtk_rounded_box_path (&background.clip_box, 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);
|
||||||
cairo_fill_preserve (cr);
|
cairo_fill_preserve (cr);
|
||||||
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
|
|
||||||
|
|
||||||
pattern = get_checkered_pattern ();
|
pattern = get_checkered_pattern ();
|
||||||
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
|
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
|
||||||
cairo_pattern_set_matrix (pattern, &matrix);
|
cairo_pattern_set_matrix (pattern, &matrix);
|
||||||
|
|
||||||
|
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
|
||||||
cairo_mask (cr, pattern);
|
cairo_mask (cr, pattern);
|
||||||
cairo_pattern_destroy (pattern);
|
cairo_pattern_destroy (pattern);
|
||||||
|
|
||||||
gdk_cairo_set_source_rgba (cr, &swatch->priv->color);
|
cairo_restore (cr);
|
||||||
|
|
||||||
|
background.bg_color = swatch->priv->color;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cairo_set_source_rgb (cr,
|
background.bg_color = swatch->priv->color;
|
||||||
swatch->priv->color.red,
|
background.bg_color.alpha = 1.0;
|
||||||
swatch->priv->color.green,
|
|
||||||
swatch->priv->color.blue);
|
|
||||||
}
|
}
|
||||||
cairo_fill_preserve (cr);
|
|
||||||
|
_gtk_theming_background_render (&background, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
|
gtk_render_frame (context, cr,
|
||||||
cairo_set_line_width (cr, 1);
|
0, 0, width, height);
|
||||||
cairo_stroke (cr);
|
|
||||||
|
|
||||||
if (gtk_widget_has_visible_focus (widget))
|
if (gtk_widget_has_visible_focus (widget))
|
||||||
{
|
{
|
||||||
@ -171,8 +175,8 @@ swatch_draw (GtkWidget *widget,
|
|||||||
cairo_set_source_rgba (cr, 1., 1., 1., 0.4);
|
cairo_set_source_rgba (cr, 1., 1., 1., 0.4);
|
||||||
else
|
else
|
||||||
cairo_set_source_rgba (cr, 0., 0., 0., 0.4);
|
cairo_set_source_rgba (cr, 0., 0., 0., 0.4);
|
||||||
_gtk_rounded_box_shrink (&box, 3, 3, 3, 3);
|
_gtk_rounded_box_shrink (&background.clip_box, 3, 3, 3, 3);
|
||||||
_gtk_rounded_box_path (&box, cr);
|
_gtk_rounded_box_path (&background.clip_box, cr);
|
||||||
cairo_stroke (cr);
|
cairo_stroke (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user