/* Add a function to draw the nuclear icon in the given colors */ staticvoid
gtk_nuclear_symbolic_snapshot_symbolic (GtkSymbolicPaintable *paintable,
GdkSnapshot *snapshot, double width, double height, const GdkRGBA *colors,
gsize n_colors)
{
GtkNuclearSymbolic *self = GTK_NUCLEAR_SYMBOLIC (paintable); staticconst GdkRGBA transparent = { 0, }; const GdkRGBA *bg_color;
/* select the right background color from the warning level */ switch (self->warning_level)
{ case WARNING_NONE:
bg_color = &transparent; break; case WARNING_ALERT:
bg_color = &colors[GTK_SYMBOLIC_COLOR_WARNING]; break; case WARNING_EMERGENCY:
bg_color = &colors[GTK_SYMBOLIC_COLOR_ERROR]; break; default: /* This should never happen, but we better do defensive coding
* with this critical icon */
g_assert_not_reached ();
bg_color = &transparent; break;
}
/* Draw the icon with the selected warning color */
gtk_nuclear_snapshot (snapshot,
&colors[GTK_SYMBOLIC_COLOR_FOREGROUND],
bg_color,
width, height, 0);
}
/* We need to implement the functionality required by the GdkPaintable interface */ staticvoid
gtk_nuclear_symbolic_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot, double width, double height)
{ /* Calling this function without passing a color is a neat trick *tomakeGTKusedefaultcolorsandotherwiseforwardthecall *tothesnapshottingfunctionabove.
*/
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable),
snapshot,
width, height,
NULL, 0);
}
static GdkPaintableFlags
gtk_nuclear_symbolic_get_flags (GdkPaintable *paintable)
{ /* This image has a static size, but the contents may change: *Wedrawdifferentthingswhenthewarninglevelchanges.
*/ return GDK_PAINTABLE_STATIC_SIZE;
}
/* When defining the GType, we need to implement bot the GdkPaintable
* and the GtkSymbolicPaintable interface */
G_DEFINE_TYPE_WITH_CODE (GtkNuclearSymbolic, gtk_nuclear_symbolic, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_nuclear_symbolic_paintable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SYMBOLIC_PAINTABLE,
gtk_nuclear_symbolic_symbolic_paintable_init))
/* And finally, we add the simple constructor we declared in the header. */
GdkPaintable *
gtk_nuclear_symbolic_new (void)
{ return g_object_new (GTK_TYPE_NUCLEAR_SYMBOLIC, NULL);
}
/* Add some fun feature to the button */ staticvoid
nuclear_button_clicked (GtkButton *button,
GtkNuclearSymbolic *nuclear)
{ if (nuclear->warning_level >= WARNING_EMERGENCY)
{ /* On maximum warning level, reset the warning */
nuclear->warning_level = WARNING_NONE; /* And sometimes (but not always to confuse people) *closethewindow.
*/ if (g_random_boolean ())
gtk_window_close (GTK_WINDOW (window));
} else
{ /* Otherwise just increase the warning level */
nuclear->warning_level++;
}
/* Don't forget to emit the signal causing the paintable to redraw. *Changingthewarninglevelchangesthebackgroundcolorafterall.
*/
gdk_paintable_invalidate_contents (GDK_PAINTABLE (nuclear));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.