]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald-ui.c
Add MetaWatch Fonts package, LcdDisplay and start demo
[oswald.git] / ui / oswald-ui.c
index 2e9312a05e008b22c7ac3fb6dbbc3b3b3e303a15..6ce61efb4f5f0a97c335a3e3145b9244380faf35 100644 (file)
 
 #include <gtk/gtk.h>
 
+#include "oswald-ui.h"
+#include "Fonts.h" // the MetaWatch fonts
 
-typedef struct {
-       GtkWidget *mainwin;
-       GtkDrawingArea *darea;
-       GdkPixmap *pixmap;
-} oswald_ui;
-
-
+#define BITMAP_WIDTH   192
+#define BITMAP_HEIGHT  192
 
 void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
 {
        GdkRectangle update_rect;
-       GdkGC *gc;
        gint ix, iy;
 
        ix = x*2;
@@ -35,10 +31,29 @@ void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
        update_rect.width = 10;
        update_rect.height = 10;
 
-       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy);
-       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy);
-       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix, iy+1);
-       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->mainwin->style->black_gc : ui->mainwin->style->white_gc, ix+1, iy+1);
+       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy);
+       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy);
+       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy+1);
+       gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy+1);
+
+       gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
+}
+
+void clear_display(oswald_ui *ui)
+{
+       GdkRectangle update_rect;
+
+       update_rect.x = 0;
+       update_rect.y = 0;
+       update_rect.width = BITMAP_WIDTH;
+       update_rect.height = BITMAP_HEIGHT;
+
+       gdk_draw_rectangle (ui->pixmap,
+               ui->darea->style->white_gc,
+               TRUE,
+               0, 0,
+               ui->darea->allocation.width,
+               ui->darea->allocation.height);
 
        gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
 }
@@ -96,18 +111,18 @@ static void create_mainwin(oswald_ui *ui)
        vb = gtk_vbox_new(FALSE, 5);
        gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
 
-       btn = gtk_button_new_with_label("D");
+       btn = gtk_button_new_with_label(" D ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
-       btn = gtk_button_new_with_label("E");
+       btn = gtk_button_new_with_label(" E ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
-       btn = gtk_button_new_with_label("F");
+       btn = gtk_button_new_with_label(" F ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
-       ui->darea = (GtkDrawingArea *)gtk_drawing_area_new ();
+       ui->darea = gtk_drawing_area_new ();
        gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
-       gtk_drawing_area_size (ui->darea, 192, 192);
+       gtk_drawing_area_size (GTK_DRAWING_AREA(ui->darea), BITMAP_WIDTH, BITMAP_HEIGHT);
 
        gtk_signal_connect (GTK_OBJECT (ui->darea), "expose_event", (GtkSignalFunc) expose_event, ui);
        gtk_signal_connect (GTK_OBJECT (ui->darea), "configure_event", (GtkSignalFunc) configure_event, ui);
@@ -123,18 +138,37 @@ static void create_mainwin(oswald_ui *ui)
        vb = gtk_vbox_new(FALSE, 5);
        gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
 
-       btn = gtk_button_new_with_label("A");
+       btn = gtk_button_new_with_label(" A ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
-       btn = gtk_button_new_with_label("B");
+       btn = gtk_button_new_with_label(" B ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
-       btn = gtk_button_new_with_label("C");
+       btn = gtk_button_new_with_label(" C ");
        gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
 
        gtk_widget_show_all(ui->mainwin);
 }
 
+gboolean app_tmo_handler (gpointer userdata)
+{
+       oswald_ui *ui = (oswald_ui *)userdata;
+
+       // fprintf(stderr, "tmo...\n");
+
+       if (ui->OnIdleScreen) {
+               update_idle_time_date(ui);
+#if 0
+       } else {
+               // go back to idle screen after IDLE_TIMEOUT seconds
+               if ((time(NULL) - ui->idle_tmo) > ui->conf.idle_tmo /*IDLE_TIMEOUT*/)
+                       create_main_screen(ui);
+#endif
+       }
+
+       return TRUE;
+}
+
 int main(int argc , char ** argv)
 {
        oswald_ui ui;
@@ -143,7 +177,10 @@ int main(int argc , char ** argv)
 
        create_mainwin(&ui);
 
-       set_pixel(&ui, 48, 48, TRUE);
+       //set_pixel(&ui, 48, 48, TRUE);
+       // demo_time(&ui);
+       ui.OnIdleScreen = TRUE;
+       g_timeout_add_seconds(1, app_tmo_handler, &ui);
 
        gtk_main ();
        return 0;