Cleanup
[speedometer] / ui.c
diff --git a/ui.c b/ui.c
index 9878980..8e7d610 100644 (file)
--- a/ui.c
+++ b/ui.c
  */
 gdouble conversion[] = { 1, 3.6, 2.237, 3.281, 1.944 };
 guint unit = 1;
-#define UNIT_COUNT 4
+#define UNIT_COUNT 5
 // TODO: wrap this mess up somewhere
-// TODO: knot graphics are missing
 
-static GdkPixbuf* big_graphics[14];
-static GdkPixbuf* small_graphics[14];
+static GdkPixbuf* big_graphics[15];
+static GdkPixbuf* small_graphics[15];
 static GtkWidget* digits[5];
 static GtkWidget* unit_graphic;
 
@@ -71,7 +70,7 @@ void load_graphics() {
         * and store the pixbufs to the array. Pixbufs are
         * correct size to be used in the big digits.
         */
-       while(i < 14) {
+       while(i < 15) {
                char* path = g_malloc(30);
                g_sprintf(path, IMAGE_PATH, i);
                g_print(path);
@@ -138,26 +137,25 @@ static void repaint_all_digits() {
 void create_ui(AppData* appdata) {
        g_assert(appdata);
 
-       GtkWidget *hbox;
-       GtkWidget *bhbox;
+       GtkWidget *top_hbox;
+       GtkWidget *bottom_hbox;
        GtkWidget *vbox;
 
        vbox = gtk_vbox_new(FALSE, 0);
-       hbox = gtk_hbox_new(TRUE, 0);
-       bhbox = gtk_hbox_new(TRUE, 0);
+       top_hbox = gtk_hbox_new(TRUE, 0);
+       bottom_hbox = gtk_hbox_new(TRUE, 0);
 
-       GtkWidget* middle_e = gtk_event_box_new();
-       GtkWidget* bottom_e = gtk_event_box_new();
+       GtkWidget* event_box = gtk_event_box_new();
 
-       g_signal_connect(G_OBJECT(middle_e),
+       g_signal_connect(G_OBJECT(event_box),
                        "tap_and_hold",
                        G_CALLBACK(long_tap),
                        appdata);
-       gtk_widget_tap_and_hold_setup(middle_e, NULL, NULL, 0);
+       gtk_widget_tap_and_hold_setup(event_box, NULL, NULL, 0);
 
-       g_signal_connect(G_OBJECT(middle_e),
+       g_signal_connect(G_OBJECT(event_box),
                        "button_press_event",
-                       G_CALLBACK(middle_event_box_button_press),
+                       G_CALLBACK(short_tap),
                        appdata);
 
        g_signal_connect(G_OBJECT(appdata->window),
@@ -171,32 +169,30 @@ void create_ui(AppData* appdata) {
                        appdata->window);
 
        // add three big digits to the hbox
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(digits[0]), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(digits[1]), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(digits[2]), FALSE, FALSE, 0);
+       // creates the top row where big digits are placed
+       gtk_box_pack_start(GTK_BOX(top_hbox), GTK_WIDGET(digits[0]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(top_hbox), GTK_WIDGET(digits[1]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(top_hbox), GTK_WIDGET(digits[2]), FALSE, FALSE, 0);
 
        // add small digits to another hbox
-       gtk_box_pack_start(GTK_BOX(bhbox), GTK_WIDGET(unit_graphic), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(bhbox), GTK_WIDGET(digits[3]), FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(bhbox), GTK_WIDGET(digits[4]), FALSE, FALSE, 0);
-
-       // add hboxes to the event boxes
-       gtk_container_add(GTK_CONTAINER(middle_e), hbox);
-       gtk_container_add(GTK_CONTAINER(bottom_e), bhbox);
+       // creates the bottom row with decimals and unit graphic
+       gtk_box_pack_start(GTK_BOX(bottom_hbox), GTK_WIDGET(unit_graphic), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(bottom_hbox), GTK_WIDGET(digits[3]), FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(bottom_hbox), GTK_WIDGET(digits[4]), FALSE, FALSE, 0);
 
        // add event boxes to the vbox
-       //gtk_box_pack_start_defaults(GTK_BOX(vbox), top_e);
-       gtk_box_pack_start_defaults(GTK_BOX(vbox), middle_e);
-       gtk_box_pack_start_defaults(GTK_BOX(vbox), bottom_e);
+       gtk_box_pack_start_defaults(GTK_BOX(vbox), top_hbox);
+       gtk_box_pack_start_defaults(GTK_BOX(vbox), bottom_hbox);
+
+       // add vertival box to the event box
+       gtk_container_add(GTK_CONTAINER(event_box), GTK_WIDGET(vbox));
 
-       // finally add the vertical box with all the children to the window
-       gtk_container_add(GTK_CONTAINER(appdata->window), GTK_WIDGET(vbox));
+       // finally add the event box with all the children to the window
+       gtk_container_add(GTK_CONTAINER(appdata->window), GTK_WIDGET(event_box));
 
        // set backgrounds black
        set_widget_bg_black(GTK_WIDGET(appdata->window));
-       set_widget_bg_black(bottom_e);
-       //set_widget_bg_black(top_e);
-       set_widget_bg_black(middle_e);
+       set_widget_bg_black(event_box);
 
        gtk_window_fullscreen(GTK_WINDOW(appdata->window));
        gtk_widget_show_all(GTK_WIDGET(appdata->window));
@@ -222,6 +218,15 @@ void interpret_and_set_speed(gdouble speed) {
         */
        speed *= conversion[unit];
 
+       /* we need to limit the speed down to
+        * less than 1000 whatever or else hell
+        * breaks loose in the form of assert
+        */
+       if(!(fabs(speed) < 1000)) {
+           g_print("Ahem, may I suggest to limit the speed (%f) a bit, Sir.\n", speed);
+           speed = 0;
+       }
+
        /* Convert float to a 6 digits (including dot) wide
         * string with leading zeros. After conversion
         * the speed looks like:
@@ -261,12 +266,6 @@ static void show_dialog() {
                        "This program is licensed under GNU General Public License, "
                        "which means (among other things) that you don't have to pay "
                        "a dime for it. "
-                       "If you think, however, that this software is worth it, you "
-                       "can always drop me a postcard.\n\n"
-                       "Wellu Mäkinen\n"
-                       "Poste restante\n"
-                       "33580 Tampere\n"
-                       "FINLAND\n\n"
                        "PS. Long-tapping on the screen will quit the program.");
        gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy(dialog);