From 8bd00384b1f1e9ac7d4a888d53aab0bfce6bd5f8 Mon Sep 17 00:00:00 2001 From: wellu Date: Sat, 6 Sep 2008 07:31:56 +0000 Subject: [PATCH] 0.3 release with experimental layoyt. git-svn-id: file:///svnroot/speedometer/trunk@23 df364472-da61-43ef-8a67-511c89aa921b --- Makefile | 4 +- appdata.h | 1 - callbacks.c | 26 ++++++++++-- callbacks.h | 7 +++- debian/changelog | 7 ++++ main.c | 66 +++++------------------------ ui.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui.h | 34 +++++++++++++++ util.c | 45 ++++++++++++++++++++ util.h | 27 ++++++++++++ 10 files changed, 275 insertions(+), 64 deletions(-) create mode 100644 ui.c create mode 100644 ui.h create mode 100644 util.c create mode 100644 util.h diff --git a/Makefile b/Makefile index b24d586..29ce894 100644 --- 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 diff --git a/appdata.h b/appdata.h index f1ffb29..f1a39fa 100644 --- 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 }; diff --git a/callbacks.c b/callbacks.c index 55126e6..5953252 100644 --- a/callbacks.c +++ b/callbacks.c @@ -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; } diff --git a/callbacks.h b/callbacks.h index 9bc2d81..e36d354 100644 --- a/callbacks.h +++ b/callbacks.h @@ -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_ */ diff --git a/debian/changelog b/debian/changelog index 4d05b0c..5d487eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +speedometer (0.3) unstable; urgency=low + + * Experimental UI layout implemented. + * Code cleanups. + + -- Wellu Mäkinen 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 --- a/main.c +++ b/main.c @@ -20,12 +20,11 @@ #include #include #include -#include -#include #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 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 + + 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 . + ****/ + +#include + +#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 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 + + 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 . +****/ + +#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 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 + + 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 . + ****/ + +#include +#include + +#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 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 + + 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 . + ****/ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#include "appdata.h" + +void start_gps(AppData* appdata); +void stop_gps(AppData* appdata); + +#endif /* UTIL_H_ */ -- 1.7.9.5