From 68eb2053add8246aacfbf19dc4bdf015df7ff5b1 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 27 Aug 2007 21:19:29 -0700 Subject: [PATCH] Initial commit of xoboot Really simple to start---just smoothly animating a fadein from black to red. --- Makefile | 15 ++++++++++ xoboot.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 Makefile create mode 100644 xoboot.c diff --git a/Makefile b/Makefile new file mode 100644 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 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 +#include + +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; +} -- 2.43.0