INCPATH = `pkg-config --cflags gtk+-2.0 liblocation`
LIBS = `pkg-config --libs gtk+-2.0 liblocation`
-SOURCES = main.c callbacks.c ui.c
-OBJECTS = main.o callbacks.o ui.o
+SOURCES = main.c callbacks.c ui.c util.c
+OBJECTS = main.o callbacks.o ui.o util.o
TARGET = speedometer
HildonWindow *window;
GtkImage* image_array[10]; // stores the images
-
GtkImage* speed_array[3]; // actual images that are shown
};
****/
#include "callbacks.h"
+#include "appdata.h"
// this is just here for debugging and tracing purposes
static void print_location(LocationGPSDevice* device) {
return FALSE;
}
-gboolean button_press(GtkWidget* widget, GdkEventButton* event, gpointer data) {
+gboolean top_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gpointer data) {
+ gdouble x = event->x;
+ g_print("Top event box pressed at: %f\n", x);
+ AppData* appdata = (AppData*) data;
- g_print("Hello");
- exit(0);
+ if(x > 750) {
+ g_print("Exiting..\n");
+ stop_gps(appdata);
+ g_signal_emit_by_name(appdata->window, "delete_event");
+ }
+ else {
+ randomize(appdata);
+ }
+ return TRUE;
+}
+
+
+gboolean bottom_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gpointer data) {
+ gdouble x = event->x;
+ g_print("Bottom event box pressed at: %f\n", x);
+ AppData* appdata = (AppData*) data;
+
+ randomize(data);
return TRUE;
}
// for hardware keys
gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, HildonWindow* window);
-// for pointer events
-gboolean button_press(GtkWidget* widget, GdkEventButton* event, gpointer data);
+// top event box
+gboolean top_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gpointer data);
+
+// bottom event box
+gboolean bottom_event_box_button_press(GtkWidget* widget, GdkEventButton* event, gpointer data);
#endif /* CALLBACKS_H_ */
+speedometer (0.3) unstable; urgency=low
+
+ * Experimental UI layout implemented.
+ * Code cleanups.
+
+ -- Wellu Mäkinen <wellu@wellu.org> Sat, 6 Sep 2008 10:26:47 +0300
+
speedometer (0.2) unstable; urgency=low
* Added .desktop and .service files.
#include <hildon/hildon-window.h>
#include <stdlib.h>
#include <gtk/gtk.h>
-#include <location/location-gps-device.h>
-#include <location/location-gpsd-control.h>
#include "callbacks.h"
#include "appdata.h"
#include "ui.h"
+#include "util.h"
int main(int argc, char** argv) {
gtk_init(&argc, &argv);
-
- GtkWidget *hbox;
- GtkWidget *vbox;
-
appdata->program = HILDON_PROGRAM(hildon_program_get_instance());
appdata->window = HILDON_WINDOW(hildon_window_new());
hildon_program_add_window(appdata->program, appdata->window);
- set_app_bg_black(appdata);
-
- populate_image_array(appdata);
-
- load_default_images(appdata);
+ // loads images from the disk to the image array
+ load_images(appdata);
- vbox = gtk_vbox_new(FALSE, 0);
- hbox = gtk_hbox_new(TRUE, 0);
+ // set display to 000
+ reset_speed(appdata);
- gtk_box_pack_start_defaults(vbox, gtk_event_box_new());
- gtk_box_pack_start_defaults(vbox, hbox);
-
- gtk_box_pack_start(hbox, appdata->speed_array[0], FALSE, FALSE, 0);
- gtk_box_pack_start(hbox, appdata->speed_array[1], FALSE, FALSE, 0);
- gtk_box_pack_start(hbox, appdata->speed_array[2], FALSE, FALSE, 0);
-
- gtk_box_pack_start_defaults(vbox, gtk_button_new_with_label("Bottom"));
-
- gtk_container_add(GTK_CONTAINER(appdata->window), GTK_WIDGET(vbox));
+ // create ui structure
+ create_ui(appdata);
// set the window fullscreen
gtk_window_fullscreen(GTK_WINDOW(appdata->window));
gtk_widget_show_all(GTK_WIDGET(appdata->window));
-
-
g_thread_init(NULL);
- g_idle_add(randomize, appdata);
-
-
-#ifdef __arm__
- // gps device
- LocationGPSDevice *device;
- device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
- // connect some signal handlers
- g_signal_connect (device, "changed", G_CALLBACK (location_changed), NULL);
-
- LocationGPSDControl *control;
-
- control = location_gpsd_control_get_default();
- location_gpsd_control_start(control);
-#endif // __arm__
-
- g_signal_connect(G_OBJECT(appdata->window),
- "delete_event",
- G_CALLBACK(gtk_main_quit),
- NULL);
-
- g_signal_connect(G_OBJECT(appdata->window),
- "key_press_event",
- G_CALLBACK(key_press_cb),
- appdata->window);
+ //g_idle_add(randomize, appdata);
- g_signal_connect(G_OBJECT(appdata->window),
- "button_press_event",
- G_CALLBACK(button_press),
- appdata->window);
+ start_gps(appdata);
- gtk_main();
+ gtk_main();
return EXIT_SUCCESS;
}
--- /dev/null
+/****
+ Speedometer, shows your current speed using GPS
+ Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ****/
+
+#include <gtk/gtk.h>
+
+#include "ui.h"
+#include "callbacks.h"
+
+#define IMAGE_PATH "/usr/share/speedometer/%d.png"
+
+static void set_widget_bg_black(GtkWidget* widget) {
+ GdkColor black;
+ black.red = 0x0000;
+ black.blue = 0x0000;
+ black.green = 0x0000;
+ gtk_widget_modify_bg(GTK_WIDGET(widget), GTK_STATE_NORMAL, &black);
+}
+
+void load_images(AppData *appdata) {
+ g_print("Loading images\n");
+ int i = 0;
+ while(i < 10) {
+ char* path = malloc(30);
+ g_sprintf(path, IMAGE_PATH, i);
+ appdata->image_array[i] = gtk_image_new_from_file(path);
+ g_print(path);
+ g_print("\n");
+ free(path);
+ i++;
+ }
+}
+
+void reset_speed(AppData* appdata) {
+
+ GdkPixbuf* zero = gtk_image_get_pixbuf(appdata->image_array[0]);
+
+ appdata->speed_array[0] = gtk_image_new_from_pixbuf(zero);
+ appdata->speed_array[1] = gtk_image_new_from_pixbuf(zero);
+ appdata->speed_array[2] = gtk_image_new_from_pixbuf(zero);
+}
+
+guint randomize(AppData* appdata) {
+
+ gint32 n = g_random_int_range(0, 3);
+ GtkImage* image = appdata->speed_array[n];
+
+ gint32 m = g_random_int_range(0, 10);
+ GdkPixbuf* buf = gtk_image_get_pixbuf(appdata->image_array[m]);
+
+ g_print("Setting number %d to %d.. ", n+1, m);
+
+ gtk_image_set_from_pixbuf(image, buf);
+ gtk_widget_queue_draw(appdata->speed_array[n]);
+
+ return TRUE;
+}
+
+void create_ui(AppData* appdata) {
+
+ GtkWidget *hbox;
+ GtkWidget *vbox;
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ hbox = gtk_hbox_new(TRUE, 0);
+
+ GtkWidget* top_e = gtk_event_box_new();
+ GtkWidget* bottom_e = gtk_event_box_new();
+
+ g_signal_connect(G_OBJECT(top_e),
+ "button_press_event",
+ G_CALLBACK(top_event_box_button_press),
+ appdata);
+
+ g_signal_connect(G_OBJECT(bottom_e),
+ "button_press_event",
+ G_CALLBACK(bottom_event_box_button_press),
+ appdata);
+
+ g_signal_connect(G_OBJECT(appdata->window),
+ "delete_event",
+ G_CALLBACK(gtk_main_quit),
+ NULL);
+
+ g_signal_connect(G_OBJECT(appdata->window),
+ "key_press_event",
+ G_CALLBACK(key_press_cb),
+ appdata->window);
+
+ // add three digits to the hbox
+ gtk_box_pack_start(hbox, appdata->speed_array[0], FALSE, FALSE, 0);
+ gtk_box_pack_start(hbox, appdata->speed_array[1], FALSE, FALSE, 0);
+ gtk_box_pack_start(hbox, appdata->speed_array[2], FALSE, FALSE, 0);
+
+ gtk_box_pack_start_defaults(vbox, top_e); // add event box on top
+ gtk_box_pack_start_defaults(vbox, hbox); // numbers to the middle
+ gtk_box_pack_start_defaults(vbox, bottom_e); // add event box on bottom
+
+ gtk_container_add(GTK_CONTAINER(appdata->window), GTK_WIDGET(vbox));
+
+
+ // set backgrounds black
+ set_widget_bg_black(appdata->window);
+ set_widget_bg_black(bottom_e);
+ set_widget_bg_black(top_e);
+
+}
+
--- /dev/null
+/****
+ Speedometer, shows your current speed using GPS
+ Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+****/
+
+#ifndef UI_H_
+#define UI_H_
+
+#include "appdata.h"
+
+void load_images(AppData *appdata);
+
+void reset_speed(AppData* appdata);
+
+guint randomize(AppData* appdata);
+
+void create_ui(AppData* appdata);
+
+void connect_signals(AppData* appdata);
+
+#endif /* UI_H_ */
--- /dev/null
+/****
+ Speedometer, shows your current speed using GPS
+ Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ****/
+
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+
+#include "util.h"
+#include "appdata.h"
+
+void start_gps(AppData* appdata) {
+
+#ifdef __arm__
+ // gps device
+ LocationGPSDevice *device;
+ device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+
+ g_signal_connect(device, "changed", G_CALLBACK(location_changed), appdata);
+
+ LocationGPSDControl *control;
+
+ control = location_gpsd_control_get_default();
+ location_gpsd_control_start(control);
+#endif // __arm__
+
+}
+
+void stop_gps(AppData* appdata) {
+
+}
+
--- /dev/null
+/****
+ Speedometer, shows your current speed using GPS
+ Copyright (C) 2008 Wellu Mäkinen <wellu@wellu.org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ****/
+
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include "appdata.h"
+
+void start_gps(AppData* appdata);
+void stop_gps(AppData* appdata);
+
+#endif /* UTIL_H_ */