]> Pileus Git - ~andy/gtk/blob - tests/motion-compression.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / motion-compression.c
1 #include <gtk/gtk.h>
2 #include <math.h>
3
4 GtkAdjustment *adjustment;
5 int cursor_x, cursor_y;
6
7 static void
8 on_motion_notify (GtkWidget      *window,
9                   GdkEventMotion *event)
10 {
11   if (event->window == gtk_widget_get_window (window))
12     {
13       float processing_ms = gtk_adjustment_get_value (adjustment);
14       g_usleep (processing_ms * 1000);
15       cursor_x = event->x;
16       cursor_y = event->y;
17       gtk_widget_queue_draw (window);
18     }
19 }
20
21 static void
22 on_draw (GtkWidget *window,
23          cairo_t   *cr)
24 {
25   cairo_set_source_rgb (cr, 1, 1, 1);
26   cairo_paint (cr);
27
28   cairo_set_source_rgb (cr, 0, 0.5, 0.5);
29
30   cairo_arc (cr, cursor_x, cursor_y, 10, 0, 2 * M_PI);
31   cairo_stroke (cr);
32 }
33
34 int
35 main (int argc, char **argv)
36 {
37   GtkWidget *window;
38   GtkWidget *vbox;
39   GtkWidget *label;
40   GtkWidget *scale;
41
42   gtk_init (&argc, &argv);
43
44   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
45   gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
46   gtk_widget_set_app_paintable (window, TRUE);
47   gtk_widget_add_events (window, GDK_POINTER_MOTION_MASK);
48   gtk_widget_set_app_paintable (window, TRUE);
49
50   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
51   gtk_container_add (GTK_CONTAINER (window), vbox);
52
53   adjustment = gtk_adjustment_new (20, 0, 200, 1, 10, 0);
54   scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjustment);
55   gtk_box_pack_end (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
56
57   label = gtk_label_new ("Event processing time (ms):");
58   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
59   gtk_box_pack_end (GTK_BOX (vbox), label, FALSE, FALSE, 0);
60
61   g_signal_connect (window, "motion-notify-event",
62                     G_CALLBACK (on_motion_notify), NULL);
63   g_signal_connect (window, "draw",
64                     G_CALLBACK (on_draw), NULL);
65   g_signal_connect (window, "destroy",
66                     G_CALLBACK (gtk_main_quit), NULL);
67
68   gtk_widget_show_all (window);
69   gtk_main ();
70
71   return 0;
72 }