]> git.cworth.org Git - xoboot/commitdiff
Initial commit of xoboot
authorCarl Worth <cworth@cworth.org>
Tue, 28 Aug 2007 04:19:29 +0000 (21:19 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 28 Aug 2007 04:19:29 +0000 (21:19 -0700)
Really simple to start---just smoothly animating a fadein from black to red.

Makefile [new file with mode: 0644]
xoboot.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..0c5a4a0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+APPS=xoboot
+
+MYCFLAGS=`pkg-config --cflags gtk+-2.0 cairo` -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing
+MYLDFLAGS=`pkg-config --libs gtk+-2.0 cairo`
+
+all: $(APPS)
+
+%.o: %.c
+       $(CC) -c $(CFLAGS) $(CPPFLAGS) $(MYCFLAGS) $< -o $@
+
+%: %.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) $(MYCFLAGS) $(MYLDFLAGS) $^ -o $@
+
+clean:
+       rm -f $(APPS) *.o *.png
diff --git a/xoboot.c b/xoboot.c
new file mode 100644 (file)
index 0000000..eee192f
--- /dev/null
+++ b/xoboot.c
@@ -0,0 +1,85 @@
+/* gcc -Wall -g $(pkg-config --cflags --libs gtk+-2.0 cairo) olpc-boot.c -o olpc-boot */
+
+#include <gtk/gtk.h>
+#include <cairo.h>
+
+typedef struct _state {
+    GtkWidget *drawing_area;
+    double progress;
+} state_t;
+
+static gboolean
+xoboot_expose_event (GtkWidget      *widget,
+                     GdkEventExpose *event,
+                     gpointer        closure)
+{
+    state_t *state = closure;
+    cairo_t *cr;
+
+    cr = gdk_cairo_create (widget->window);
+
+    cairo_set_source_rgb (cr, state->progress, 0, 0);
+    cairo_paint (cr);
+
+    cairo_destroy (cr);
+
+    return TRUE;
+}
+
+static GtkWidget *
+create_window (state_t *state)
+{
+    GtkWidget *window;
+    GtkWidget *drawing_area;
+
+    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_title (GTK_WINDOW (window), "OLPC Boot Animation Demo");
+
+    g_signal_connect (window, "destroy",
+                     G_CALLBACK (gtk_main_quit), &window);
+
+    drawing_area = gtk_drawing_area_new ();
+
+    /* We want to force 640x480 to emulate the OLPC display */
+    gtk_widget_set_size_request (drawing_area, 640, 480);
+
+    gtk_container_add (GTK_CONTAINER (window), drawing_area);
+
+    g_signal_connect (drawing_area, "expose_event",
+                     G_CALLBACK (xoboot_expose_event), state);
+
+    return drawing_area;
+}
+
+static gint
+timeout_callback (gpointer closure)
+{
+    state_t *state = closure;
+
+    state->progress += 0.01;
+    if (state->progress > 1.0)
+       state->progress = 1.0;
+    else
+       gtk_widget_queue_draw (state->drawing_area);
+
+    return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+    state_t state;
+
+    gtk_init (&argc, &argv);
+
+    state.drawing_area = create_window (&state);
+    state.progress = 0.0;
+
+    gtk_widget_show_all (gtk_widget_get_toplevel (state.drawing_area));
+
+    g_timeout_add (100, timeout_callback, &state);
+
+    gtk_main ();
+
+    return 0;
+}