0.3 release with experimental layoyt.
authorwellu <wellu@wellu.org>
Sat, 6 Sep 2008 07:31:56 +0000 (07:31 +0000)
committerwellu <wellu@wellu.org>
Sat, 6 Sep 2008 07:31:56 +0000 (07:31 +0000)
git-svn-id: file:///svnroot/speedometer/trunk@23 df364472-da61-43ef-8a67-511c89aa921b

Makefile
appdata.h
callbacks.c
callbacks.h
debian/changelog
main.c
ui.c [new file with mode: 0644]
ui.h [new file with mode: 0644]
util.c [new file with mode: 0644]
util.h [new file with mode: 0644]

index b24d586..29ce894 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,8 @@ CFLAGS   = -g -Wall -O0
 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
 
 
index f1ffb29..f1a39fa 100644 (file)
--- a/appdata.h
+++ b/appdata.h
@@ -28,7 +28,6 @@ struct _AppData {
     HildonWindow *window;
 
        GtkImage* image_array[10]; // stores the images
-
        GtkImage* speed_array[3]; // actual images that are shown
 };
 
index 55126e6..5953252 100644 (file)
@@ -17,6 +17,7 @@
 ****/
 
 #include "callbacks.h"
+#include "appdata.h"
 
 // this is just here for debugging and tracing purposes
 static void print_location(LocationGPSDevice* device) {
@@ -76,10 +77,29 @@ gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, HildonWindow* windo
        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;
 }
 
index 9bc2d81..e36d354 100644 (file)
@@ -29,7 +29,10 @@ void location_changed(LocationGPSDevice* device, gpointer userdata);
 // 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_ */
index 4d05b0c..5d487eb 100644 (file)
@@ -1,3 +1,10 @@
+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.
diff --git a/main.c b/main.c
index d15a304..82c24c8 100644 (file)
--- a/main.c
+++ b/main.c
 #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) {
 
@@ -33,76 +32,31 @@ 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;
 }
diff --git a/ui.c b/ui.c
new file mode 100644 (file)
index 0000000..bb30df7
--- /dev/null
+++ b/ui.c
@@ -0,0 +1,122 @@
+/****
+       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);
+
+}
+
diff --git a/ui.h b/ui.h
new file mode 100644 (file)
index 0000000..0b44c4d
--- /dev/null
+++ b/ui.h
@@ -0,0 +1,34 @@
+/****
+       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_ */
diff --git a/util.c b/util.c
new file mode 100644 (file)
index 0000000..d5a6df6
--- /dev/null
+++ b/util.c
@@ -0,0 +1,45 @@
+/****
+       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) {
+
+}
+
diff --git a/util.h b/util.h
new file mode 100644 (file)
index 0000000..64ba629
--- /dev/null
+++ b/util.h
@@ -0,0 +1,27 @@
+/****
+       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_ */