1 | /* -*- mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ |
2 | |
3 | #include <gtk/gtk.h> |
4 | |
5 | #include "frame-stats.h" |
6 | |
7 | double reveal_time = 5; |
8 | |
9 | static GOptionEntry options[] = { |
10 | { "time" , 't', 0, G_OPTION_ARG_DOUBLE, &reveal_time, "Reveal time" , "SECONDS" }, |
11 | { NULL } |
12 | }; |
13 | |
14 | static void |
15 | toggle_reveal (GtkRevealer *revealer) |
16 | { |
17 | gtk_revealer_set_reveal_child (revealer, reveal_child: !gtk_revealer_get_reveal_child (revealer)); |
18 | } |
19 | |
20 | static void |
21 | quit_cb (GtkWidget *widget, |
22 | gpointer data) |
23 | { |
24 | gboolean *done = data; |
25 | |
26 | *done = TRUE; |
27 | |
28 | g_main_context_wakeup (NULL); |
29 | } |
30 | |
31 | int |
32 | main(int argc, char **argv) |
33 | { |
34 | GtkWidget *window, *revealer, *grid, *widget; |
35 | GtkCssProvider *cssprovider; |
36 | GError *error = NULL; |
37 | guint x, y; |
38 | gboolean done = FALSE; |
39 | |
40 | GOptionContext *context = g_option_context_new (NULL); |
41 | g_option_context_add_main_entries (context, entries: options, NULL); |
42 | frame_stats_add_options (group: g_option_context_get_main_group (context)); |
43 | |
44 | if (!g_option_context_parse (context, argc: &argc, argv: &argv, error: &error)) |
45 | { |
46 | g_printerr (format: "Option parsing failed: %s\n" , error->message); |
47 | return 1; |
48 | } |
49 | |
50 | gtk_init (); |
51 | |
52 | window = gtk_window_new (); |
53 | g_signal_connect (window, "destroy" , G_CALLBACK (quit_cb), &done); |
54 | frame_stats_ensure (GTK_WINDOW (window)); |
55 | |
56 | revealer = gtk_revealer_new (); |
57 | gtk_widget_set_valign (widget: revealer, align: GTK_ALIGN_START); |
58 | gtk_revealer_set_transition_type (GTK_REVEALER (revealer), transition: GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); |
59 | gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), duration: reveal_time * 1000); |
60 | gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE); |
61 | g_signal_connect_after (revealer, "map" , G_CALLBACK (toggle_reveal), NULL); |
62 | g_signal_connect_after (revealer, "notify::child-revealed" , G_CALLBACK (toggle_reveal), NULL); |
63 | gtk_window_set_child (GTK_WINDOW (window), child: revealer); |
64 | |
65 | grid = gtk_grid_new (); |
66 | gtk_revealer_set_child (GTK_REVEALER (revealer), child: grid); |
67 | |
68 | cssprovider = gtk_css_provider_new (); |
69 | gtk_css_provider_load_from_data (css_provider: cssprovider, data: "* { padding: 2px; text-shadow: 5px 5px 2px grey; }" , length: -1); |
70 | |
71 | for (x = 0; x < 10; x++) |
72 | { |
73 | for (y = 0; y < 20; y++) |
74 | { |
75 | widget = gtk_label_new (str: "Hello World" ); |
76 | gtk_style_context_add_provider (context: gtk_widget_get_style_context (widget), |
77 | GTK_STYLE_PROVIDER (cssprovider), |
78 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
79 | gtk_grid_attach (GTK_GRID (grid), child: widget, column: x, row: y, width: 1, height: 1); |
80 | } |
81 | } |
82 | |
83 | gtk_widget_show (widget: window); |
84 | |
85 | while (!done) |
86 | g_main_context_iteration (NULL, TRUE); |
87 | |
88 | return 0; |
89 | } |
90 | |