*/
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;
* 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);
g_print("\n");
GError* error = NULL;
- big_graphics[i] = gdk_pixbuf_new_from_file(path, &error);
+ big_graphics[i] = gdk_pixbuf_new_from_file_at_scale(path,
+ 160,
+ 160,
+ FALSE,
+ &error);
if(error) {
- g_print("Error loading graphics: %s\n", error->message);
+ g_print("Error loading big graphics: %s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ small_graphics[i] = gdk_pixbuf_new_from_file_at_scale(path,
+ 120,
+ 120,
+ FALSE,
+ &error);
+ if(error) {
+ g_print("Error loading small graphics: %s\n", error->message);
g_error_free(error);
error = NULL;
}
g_free(path);
-
- small_graphics[i] = gdk_pixbuf_scale_simple(
- big_graphics[i],
- 150,
- 150,
- GDK_INTERP_BILINEAR);
-
i++;
}
g_print("Done\n");
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* top_e = gtk_event_box_new();
- 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(top_e),
- "button_press_event",
- G_CALLBACK(top_event_box_button_press),
+ g_signal_connect(G_OBJECT(event_box),
+ "tap_and_hold",
+ G_CALLBACK(long_tap),
appdata);
+ 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),
- appdata);
-
- g_signal_connect(G_OBJECT(bottom_e),
- "button_press_event",
- G_CALLBACK(bottom_event_box_button_press),
+ G_CALLBACK(short_tap),
appdata);
g_signal_connect(G_OBJECT(appdata->window),
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));
*/
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:
"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"
- "PO BOX\n"
- "33580 Tampere\n"
- "FINLAND");
+ "PS. Long-tapping on the screen will quit the program.");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}