render: Remove spinner special-cases

The spinner is a regular builtin image now. There is no need to go
through the shadows code manually anymore as regular items do get
shadows automatically.

This also allows simplifying the actual spinner drawing code so that it
actually works.
This commit is contained in:
Benjamin Otte 2015-01-19 17:41:29 +01:00
parent cc4d34e688
commit e697213b35
7 changed files with 31 additions and 104 deletions

View File

@ -732,17 +732,44 @@ gtk_css_image_builtin_draw_spinner (GtkCssImage *image,
double height)
{
GtkCssImageBuiltin *builtin = GTK_CSS_IMAGE_BUILTIN (image);
guint num_steps;
gdouble radius;
gdouble half;
gint i;
radius = MIN (width / 2, height / 2);
cairo_save (cr);
cairo_translate (cr, width / 2, height / 2);
gdk_cairo_set_source_rgba (cr, &builtin->fg_color);
gtk_render_paint_spinner (cr, radius, -1);
num_steps = 12;
cairo_restore (cr);
cairo_set_line_width (cr, 2.0);
half = num_steps / 2;
for (i = 0; i < num_steps; i++)
{
gint inset = 0.7 * radius;
/* transparency is a function of time and intial value */
gdouble t = 1.0 - (gdouble) i / num_steps;
gdouble xscale = - sin (i * G_PI / half);
gdouble yscale = - cos (i * G_PI / half);
cairo_move_to (cr,
(radius - inset) * xscale,
(radius - inset) * yscale);
cairo_line_to (cr,
radius * xscale,
radius * yscale);
cairo_set_source_rgba (cr,
builtin->fg_color.red,
builtin->fg_color.green,
builtin->fg_color.blue,
builtin->fg_color.alpha * t);
cairo_stroke (cr);
}
}
static void

View File

@ -281,22 +281,6 @@ _gtk_css_shadows_value_paint_icon (const GtkCssValue *shadows,
}
}
void
_gtk_css_shadows_value_paint_spinner (const GtkCssValue *shadows,
cairo_t *cr,
gdouble radius,
gdouble progress)
{
guint i;
g_return_if_fail (shadows->class == &GTK_CSS_VALUE_SHADOWS);
for (i = 0; i < shadows->len; i++)
{
_gtk_css_shadow_value_paint_spinner (shadows->values[i], cr, radius, progress);
}
}
void
_gtk_css_shadows_value_paint_box (const GtkCssValue *shadows,
cairo_t *cr,

View File

@ -43,10 +43,6 @@ void _gtk_css_shadows_value_paint_layout (const GtkCssValue
void _gtk_css_shadows_value_paint_icon (const GtkCssValue *shadows,
cairo_t *cr);
void _gtk_css_shadows_value_paint_spinner (const GtkCssValue *shadows,
cairo_t *cr,
gdouble radius,
gdouble progress);
void _gtk_css_shadows_value_paint_box (const GtkCssValue *shadows,
cairo_t *cr,
const GtkRoundedBox *padding_box,

View File

@ -542,29 +542,6 @@ _gtk_css_shadow_value_paint_icon (const GtkCssValue *shadow,
cairo_pattern_destroy (pattern);
}
void
_gtk_css_shadow_value_paint_spinner (const GtkCssValue *shadow,
cairo_t *cr,
gdouble radius,
gdouble progress)
{
g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
cairo_save (cr);
gdk_cairo_set_source_rgba (cr, _gtk_css_rgba_value_get_rgba (shadow->color));
cr = gtk_css_shadow_value_start_drawing (shadow, cr);
cairo_translate (cr,
_gtk_css_number_value_get (shadow->hoffset, 0),
_gtk_css_number_value_get (shadow->voffset, 0));
gtk_render_paint_spinner (cr, radius, progress);
cr = gtk_css_shadow_value_finish_drawing (shadow, cr);
cairo_restore (cr);
}
gboolean
_gtk_css_shadow_value_get_inset (const GtkCssValue *shadow)
{

View File

@ -50,10 +50,6 @@ void _gtk_css_shadow_value_paint_layout (const GtkCssValue
void _gtk_css_shadow_value_paint_icon (const GtkCssValue *shadow,
cairo_t *cr);
void _gtk_css_shadow_value_paint_spinner (const GtkCssValue *shadow,
cairo_t *cr,
gdouble radius,
gdouble progress);
void _gtk_css_shadow_value_paint_box (const GtkCssValue *shadow,
cairo_t *cr,
const GtkRoundedBox *padding_box);

View File

@ -1042,56 +1042,6 @@ gtk_render_handle (GtkStyleContext *context,
cairo_restore (cr);
}
void
gtk_render_paint_spinner (cairo_t *cr,
gdouble radius,
gdouble progress)
{
guint num_steps, step;
gdouble half;
gint i;
num_steps = 12;
if (progress >= 0)
step = (guint) (progress * num_steps);
else
step = 0;
cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_line_width (cr, 2.0);
half = num_steps / 2;
for (i = 0; i < num_steps; i++)
{
gint inset = 0.7 * radius;
/* transparency is a function of time and intial value */
gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
gdouble xscale = - sin (i * G_PI / half);
gdouble yscale = - cos (i * G_PI / half);
cairo_push_group (cr);
cairo_move_to (cr,
(radius - inset) * xscale,
(radius - inset) * yscale);
cairo_line_to (cr,
radius * xscale,
radius * yscale);
cairo_stroke (cr);
cairo_pop_group_to_source (cr);
cairo_paint_with_alpha (cr, t);
}
cairo_restore (cr);
}
/**
* gtk_render_activity:
* @context: a #GtkStyleContext

View File

@ -28,8 +28,5 @@ void gtk_render_content_path (GtkStyleContext *context,
double y,
double width,
double height);
void gtk_render_paint_spinner (cairo_t *cr,
gdouble radius,
gdouble progress);
#endif /* __GTK_RENDER_PRIVATE_H__ */