color-cycle: add reset helper

This will reset the colors and move back to position 0.
This commit is contained in:
Christian Hergert
2016-09-28 14:09:32 -07:00
parent 388557cdfe
commit baabf7692c
2 changed files with 15 additions and 0 deletions

View File

@ -120,3 +120,17 @@ sp_color_cycle_next (SpColorCycle *self,
self->position = (self->position + 1) % self->n_colors;
}
void
sp_color_cycle_reset (SpColorCycle *self)
{
g_return_if_fail (self != NULL);
for (guint i = 0; default_colors[i]; i++)
{
if G_UNLIKELY (!gdk_rgba_parse (&self->colors[i], default_colors[i]))
g_warning ("Failed to parse color %s into an RGBA", default_colors[i]);
}
self->position = 0;
}

View File

@ -31,6 +31,7 @@ GType sp_color_cycle_get_type (void);
SpColorCycle *sp_color_cycle_ref (SpColorCycle *self);
void sp_color_cycle_unref (SpColorCycle *self);
SpColorCycle *sp_color_cycle_new (void);
void sp_color_cycle_reset (SpColorCycle *self);
void sp_color_cycle_next (SpColorCycle *self,
GdkRGBA *rgba);