diff options
Diffstat (limited to 'src/statistics/gtk_statistics_demo.c')
-rw-r--r-- | src/statistics/gtk_statistics_demo.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/statistics/gtk_statistics_demo.c b/src/statistics/gtk_statistics_demo.c new file mode 100644 index 00000000..cdd61cd0 --- /dev/null +++ b/src/statistics/gtk_statistics_demo.c | |||
@@ -0,0 +1,69 @@ | |||
1 | |||
2 | #include "gtk_statistics.h" | ||
3 | #include <math.h> | ||
4 | |||
5 | |||
6 | /** | ||
7 | * Update view (add more points). | ||
8 | */ | ||
9 | static gboolean | ||
10 | update (GtkWidget *widget, GdkEvent *event, gpointer user_data) | ||
11 | { | ||
12 | static unsigned int i = 600; | ||
13 | struct GtkStatistics *statistics = user_data; | ||
14 | |||
15 | gtk_statistics_update_value (GTK_STATISTICS (statistics), | ||
16 | "sin", | ||
17 | i, | ||
18 | (uint64_t) (500 * (1.0 + sin(i/100.0)))); | ||
19 | gtk_statistics_update_value (GTK_STATISTICS (statistics), | ||
20 | "cos", | ||
21 | i * 2, | ||
22 | (uint64_t) (i * (1.0 + cos(i/100.0)))); | ||
23 | i++; | ||
24 | return FALSE; | ||
25 | } | ||
26 | |||
27 | |||
28 | int main (int argc, char ** argv) | ||
29 | { | ||
30 | GtkWidget *window; | ||
31 | GtkWidget *statistics; | ||
32 | unsigned int i; | ||
33 | |||
34 | gtk_init(&argc, &argv); | ||
35 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
36 | gtk_window_set_title(GTK_WINDOW(window), "STATISTICS widget"); | ||
37 | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | ||
38 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); | ||
39 | g_signal_connect(G_OBJECT(window), "destroy", | ||
40 | G_CALLBACK(gtk_main_quit), NULL); | ||
41 | statistics = gtk_statistics_new(); | ||
42 | gtk_statistics_add_line (GTK_STATISTICS (statistics), | ||
43 | "sin", | ||
44 | "sin", | ||
45 | "red"); | ||
46 | for (i=0;i<600;i++) | ||
47 | gtk_statistics_update_value (GTK_STATISTICS (statistics), | ||
48 | "sin", | ||
49 | i, | ||
50 | (uint64_t) (500 * (1.0 + sin(i/100.0)))); | ||
51 | gtk_statistics_add_line (GTK_STATISTICS (statistics), | ||
52 | "cos", | ||
53 | "cos", | ||
54 | "blue"); | ||
55 | for (i=0;i<600;i++) | ||
56 | gtk_statistics_update_value (GTK_STATISTICS (statistics), | ||
57 | "cos", | ||
58 | i * 2, | ||
59 | (uint64_t) (i * (1.0 + cos(i/100.0)))); | ||
60 | g_signal_connect (G_OBJECT(window), "motion-notify-event", G_CALLBACK (update), statistics); | ||
61 | gtk_container_add(GTK_CONTAINER(window), statistics); | ||
62 | gtk_widget_add_events (GTK_WIDGET (window), GDK_POINTER_MOTION_MASK); | ||
63 | |||
64 | gtk_widget_show(statistics); | ||
65 | gtk_widget_show_all(window); | ||
66 | gtk_main(); | ||
67 | |||
68 | return 0; | ||
69 | } | ||