#include <gtk/gtk.h>
+#include "Fonts.h" // the MetaWatch fonts
+#include "oswald.h"
+#include "oswald_main.h"
-typedef struct {
- GtkWidget *mainwin;
- GtkDrawingArea *darea;
- GdkPixmap *pixmap;
-} oswald_ui;
+#include "oswald-ui.h"
+#define BITMAP_WIDTH 192
+#define BITMAP_HEIGHT 192
+static oswald_ui *ui_g;
-void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
+void lcd_set_pixel(gint x, gint y, gboolean state)
{
- GdkRectangle update_rect;
- GdkGC *gc;
gint ix, iy;
ix = x*2;
iy = y*2;
- update_rect.x = ix - 5;
- update_rect.y = iy - 5;
- update_rect.width = 10;
- update_rect.height = 10;
+ gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy);
+ gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy);
+ gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1);
+ gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy+1);
- 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);
+ gtk_widget_queue_draw(ui_g->darea);
+}
+
+void lcd_clear_display(void)
+{
+ gdk_draw_rectangle (ui_g->pixmap,
+ ui_g->darea->style->white_gc,
+ TRUE,
+ 0, 0,
+ ui_g->darea->allocation.width,
+ ui_g->darea->allocation.height);
- gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
+ gtk_widget_queue_draw(ui_g->darea);
}
static gint
return FALSE;
}
+void button_A_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-A clicked\n");
+ oswald_handle_button_press(BUTTON_A);
+}
+
+void button_B_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-B clicked\n");
+ oswald_handle_button_press(BUTTON_B);
+}
+
+void button_C_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-C clicked\n");
+ oswald_handle_button_press(BUTTON_C);
+}
+
+void button_D_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-D clicked\n");
+ oswald_handle_button_press(BUTTON_D);
+}
+
+void button_E_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-E clicked\n");
+ oswald_handle_button_press(BUTTON_E);
+}
+
+void button_F_clicked (GtkButton *button, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+
+ // g_print("Button-F clicked\n");
+ oswald_handle_button_press(BUTTON_F);
+}
+
+gboolean button_F_pr (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+ oswald_ui *ui = (oswald_ui *)user_data;
+ static gint32 press_time;
+
+ GdkEventButton *bev = (GdkEventButton *)event;
+ if (bev->type == GDK_BUTTON_PRESS) {
+ press_time = bev->time;
+ return FALSE;
+ };
+ if (bev->type == GDK_BUTTON_RELEASE) {
+ if (bev->time > (press_time+1000)) {
+ g_print("Button-F long press\n");
+ return TRUE;
+ };
+ };
+
+ return FALSE;
+}
+
static void create_mainwin(oswald_ui *ui)
{
- GtkWidget *hb, *vb, *btn;
+ GtkWidget *mvb, *hb, *vb, *btn, *sc, *l;
ui->pixmap = NULL;
// gtk_window_set_default_size (GTK_WINDOW (ui->mainwin), 440, 240);
g_signal_connect(G_OBJECT(ui->mainwin), "destroy", gtk_main_quit, NULL);
+ mvb = gtk_vbox_new(FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(ui->mainwin), mvb);
+
hb = gtk_hbox_new(FALSE, 5);
- gtk_container_add(GTK_CONTAINER(ui->mainwin), hb);
+ gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5);
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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui);
- 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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_E_clicked), ui);
- 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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui);
+ g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui);
+ g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui);
- 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);
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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_A_clicked), ui);
- 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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_B_clicked), ui);
- 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);
+ g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_C_clicked), ui);
+
+ sc = gtk_vscale_new_with_range (0, 255, 1);
+ gtk_box_pack_start (GTK_BOX(hb), sc, FALSE, FALSE, 5);
+
+ hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(mvb), hb, FALSE, FALSE, 5);
+
+ l = gtk_label_new("X:");
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+ sc = gtk_hscale_new_with_range (0, 255, 1);
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
+
+ l = gtk_label_new("Y:");
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+ sc = gtk_hscale_new_with_range (0, 255, 1);
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
+
+ l = gtk_label_new("Z:");
+ gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
+ sc = gtk_hscale_new_with_range (0, 255, 1);
+ gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
gtk_widget_show_all(ui->mainwin);
}
+gboolean one_second_tmo_handler (gpointer userdata)
+{
+ oswald_ui *ui = (oswald_ui *)userdata;
+
+ oswald_one_second_tick();
+
+ return TRUE;
+}
+
+gboolean app_idle_handler (gpointer user_data)
+{
+ g_print("i");
+ if (OswaldState.pending_idle) {
+ // call Oswald's idle function
+ return TRUE;
+ };
+ return FALSE;
+}
+
int main(int argc , char ** argv)
{
oswald_ui ui;
+ time_t mt;
+ struct tm mtime;
+
+ ui_g = &ui;
+
+ mt = time(NULL);
+ localtime_r(&mt, &mtime);
gtk_init (&argc, &argv);
create_mainwin(&ui);
+ gtk_widget_realize(ui.mainwin);
+
+ oswald_set_time(mtime.tm_hour, mtime.tm_min, mtime.tm_sec);
+ oswald_init();
- set_pixel(&ui, 48, 48, TRUE);
+ g_timeout_add_seconds(1, one_second_tmo_handler, &ui);
+ // g_idle_add(app_idle_handler, &ui);
gtk_main ();
return 0;