2013-04-22 16:03:07 +00:00
|
|
|
/* Revealer
|
|
|
|
*
|
|
|
|
* GtkRevealer is a container that animates showing and hiding
|
|
|
|
* of its sole child with nice transitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
static int count = 0;
|
2015-06-28 13:23:28 +00:00
|
|
|
static guint timeout = 0;
|
2013-04-22 16:03:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
change_direction (GtkRevealer *revealer)
|
|
|
|
{
|
2016-05-07 20:22:13 +00:00
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (revealer)))
|
|
|
|
{
|
|
|
|
gboolean revealed;
|
2013-04-22 16:03:07 +00:00
|
|
|
|
2016-05-07 20:22:13 +00:00
|
|
|
revealed = gtk_revealer_get_child_revealed (revealer);
|
|
|
|
gtk_revealer_set_reveal_child (revealer, !revealed);
|
|
|
|
}
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
reveal_one (gpointer data)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkWidget *window = data;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
2013-04-22 16:03:07 +00:00
|
|
|
GtkRevealer *revealer;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("revealer%d", count);
|
2020-05-21 20:23:42 +00:00
|
|
|
revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (window), name));
|
|
|
|
g_free (name);
|
2013-04-22 16:03:07 +00:00
|
|
|
|
|
|
|
gtk_revealer_set_reveal_child (revealer, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (revealer, "notify::child-revealed",
|
|
|
|
G_CALLBACK (change_direction), NULL);
|
|
|
|
count++;
|
|
|
|
|
2014-04-12 17:35:19 +00:00
|
|
|
if (count >= 9)
|
|
|
|
{
|
|
|
|
timeout = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
2013-04-22 16:03:07 +00:00
|
|
|
static void
|
2015-06-28 13:23:28 +00:00
|
|
|
on_destroy (gpointer data)
|
2013-04-22 16:03:07 +00:00
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
window = NULL;
|
2013-07-04 21:52:09 +00:00
|
|
|
if (timeout != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (timeout);
|
|
|
|
timeout = 0;
|
|
|
|
}
|
2020-05-21 20:23:42 +00:00
|
|
|
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_revealer (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkBuilder *builder;
|
2020-05-21 20:23:42 +00:00
|
|
|
int i;
|
2015-06-28 13:23:28 +00:00
|
|
|
|
|
|
|
builder = gtk_builder_new_from_resource ("/revealer/revealer.ui");
|
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
2020-05-21 20:23:42 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
char *name = g_strdup_printf ("revealer%d", i);
|
|
|
|
GtkWidget *revealer = GTK_WIDGET (gtk_builder_get_object (builder, name));
|
|
|
|
g_object_set_data (G_OBJECT (window), name, revealer);
|
|
|
|
g_free (name);
|
|
|
|
}
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2013-04-22 16:03:07 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2015-06-28 13:23:28 +00:00
|
|
|
G_CALLBACK (on_destroy), NULL);
|
2020-05-21 20:23:42 +00:00
|
|
|
|
|
|
|
g_object_unref (builder);
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
{
|
|
|
|
count = 0;
|
2015-06-28 13:23:28 +00:00
|
|
|
timeout = g_timeout_add (690, reveal_one, window);
|
2022-11-28 04:03:14 +00:00
|
|
|
gtk_widget_set_visible (window, TRUE);
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|