gtk-demo: Tweak the animated paintable

Make it possible to have no background in
the animated paintable. This will be used
in a future demo.

Update all users.
This commit is contained in:
Matthias Clasen 2020-09-11 21:08:36 -04:00
parent 2679e29375
commit f679ba566e
6 changed files with 28 additions and 14 deletions

View File

@ -48,12 +48,14 @@ void
gtk_nuclear_snapshot (GtkSnapshot *snapshot, gtk_nuclear_snapshot (GtkSnapshot *snapshot,
double width, double width,
double height, double height,
double rotation) double rotation,
gboolean draw_background)
{ {
#define RADIUS 0.3 #define RADIUS 0.3
cairo_t *cr; cairo_t *cr;
double size; double size;
if (draw_background)
gtk_snapshot_append_color (snapshot, gtk_snapshot_append_color (snapshot,
&(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 }, &(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 },
&GRAPHENE_RECT_INIT (0, 0, width, height)); &GRAPHENE_RECT_INIT (0, 0, width, height));
@ -93,7 +95,8 @@ gtk_nuclear_icon_snapshot (GdkPaintable *paintable,
gtk_nuclear_snapshot (snapshot, gtk_nuclear_snapshot (snapshot,
width, height, width, height,
nuclear->rotation); nuclear->rotation,
TRUE);
} }
static GdkPaintableFlags static GdkPaintableFlags

View File

@ -6,10 +6,11 @@
void gtk_nuclear_snapshot (GtkSnapshot *snapshot, void gtk_nuclear_snapshot (GtkSnapshot *snapshot,
double width, double width,
double height, double height,
double rotation); double rotation,
gboolean draw_background);
GdkPaintable * gtk_nuclear_icon_new (double rotation); GdkPaintable * gtk_nuclear_icon_new (double rotation);
GdkPaintable * gtk_nuclear_animation_new (void); GdkPaintable * gtk_nuclear_animation_new (gboolean draw_background);
GtkMediaStream *gtk_nuclear_media_stream_new (void); GtkMediaStream *gtk_nuclear_media_stream_new (void);
#endif /* __PAINTABLE_H__ */ #endif /* __PAINTABLE_H__ */

View File

@ -33,6 +33,8 @@ struct _GtkNuclearAnimation
{ {
GObject parent_instance; GObject parent_instance;
gboolean draw_background;
/* This variable stores the progress of our animation. /* This variable stores the progress of our animation.
* We just count upwards until we hit MAX_PROGRESS and * We just count upwards until we hit MAX_PROGRESS and
* then start from scratch. * then start from scratch.
@ -64,7 +66,8 @@ gtk_nuclear_animation_snapshot (GdkPaintable *paintable,
/* We call the function from the previous example here. */ /* We call the function from the previous example here. */
gtk_nuclear_snapshot (snapshot, gtk_nuclear_snapshot (snapshot,
width, height, width, height,
2 * G_PI * nuclear->progress / MAX_PROGRESS); 2 * G_PI * nuclear->progress / MAX_PROGRESS,
nuclear->draw_background);
} }
static GdkPaintable * static GdkPaintable *
@ -175,9 +178,15 @@ gtk_nuclear_animation_init (GtkNuclearAnimation *nuclear)
/* And finally, we add the simple constructor we declared in the header. */ /* And finally, we add the simple constructor we declared in the header. */
GdkPaintable * GdkPaintable *
gtk_nuclear_animation_new (void) gtk_nuclear_animation_new (gboolean draw_background)
{ {
return g_object_new (GTK_TYPE_NUCLEAR_ANIMATION, NULL); GtkNuclearAnimation *nuclear;
nuclear = g_object_new (GTK_TYPE_NUCLEAR_ANIMATION, NULL);
nuclear->draw_background = draw_background;
return GDK_PAINTABLE (nuclear);
} }
GtkWidget * GtkWidget *
@ -195,7 +204,7 @@ do_paintable_animated (GtkWidget *do_widget)
gtk_window_set_default_size (GTK_WINDOW (window), 300, 200); gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window); g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
nuclear = gtk_nuclear_animation_new (); nuclear = gtk_nuclear_animation_new (TRUE);
image = gtk_image_new_from_paintable (nuclear); image = gtk_image_new_from_paintable (nuclear);
gtk_window_set_child (GTK_WINDOW (window), image); gtk_window_set_child (GTK_WINDOW (window), image);
g_object_unref (nuclear); g_object_unref (nuclear);

View File

@ -74,7 +74,8 @@ gtk_nuclear_media_stream_snapshot (GdkPaintable *paintable,
/* We call the function from the previous example here. */ /* We call the function from the previous example here. */
gtk_nuclear_snapshot (snapshot, gtk_nuclear_snapshot (snapshot,
width, height, width, height,
2 * G_PI * nuclear->progress / DURATION); 2 * G_PI * nuclear->progress / DURATION,
TRUE);
} }
static GdkPaintable * static GdkPaintable *

View File

@ -437,7 +437,7 @@ do_sliding_puzzle (GtkWidget *do_widget)
choices = gtk_flow_box_new (); choices = gtk_flow_box_new ();
gtk_widget_add_css_class (choices, "view"); gtk_widget_add_css_class (choices, "view");
add_choice (choices, puzzle); add_choice (choices, puzzle);
add_choice (choices, gtk_nuclear_animation_new ()); add_choice (choices, gtk_nuclear_animation_new (TRUE));
media = gtk_media_file_new_for_resource ("/images/gtk-logo.webm"); media = gtk_media_file_new_for_resource ("/images/gtk-logo.webm");
gtk_media_stream_set_loop (media, TRUE); gtk_media_stream_set_loop (media, TRUE);
gtk_media_stream_set_muted (media, TRUE); gtk_media_stream_set_muted (media, TRUE);

View File

@ -142,7 +142,7 @@ insert_text (GtkTextView *view)
32, 1, 32, 1,
gtk_widget_get_direction (widget), gtk_widget_get_direction (widget),
0); 0);
nuclear = gtk_nuclear_animation_new (); nuclear = gtk_nuclear_animation_new (TRUE);
/* get start of buffer; each insertion will revalidate the /* get start of buffer; each insertion will revalidate the
* iterator to point to just after the inserted text. * iterator to point to just after the inserted text.