]> Pileus Git - aweather/blobdiff - src/aweather-gui.c
* Road plan (HACKING)
[aweather] / src / aweather-gui.c
index d02443eb9c314cd57418a57eae01eab1285a030e..555a9c268f7e62f5e61890952c381a3677e5894d 100644 (file)
@@ -37,6 +37,24 @@ gboolean on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, gpoint
        return TRUE;
 }
 
+void on_refresh(GtkToolButton *button, AWeatherGui *gui)
+{
+       AWeatherView *view = aweather_gui_get_view(gui);
+       aweather_view_refresh(view);
+}
+
+void on_zoomin(GtkToolButton *button, AWeatherGui *gui)
+{
+       AWeatherView *view = aweather_gui_get_view(gui);
+       aweather_view_zoomin(view);
+}
+
+void on_zoomout(GtkToolButton *button, AWeatherGui *gui)
+{
+       AWeatherView *view = aweather_gui_get_view(gui);
+       aweather_view_zoomout(view);
+}
+
 void on_site_changed(GtkComboBox *combo, AWeatherGui *gui)
 {
        gchar *site;
@@ -46,6 +64,7 @@ void on_site_changed(GtkComboBox *combo, AWeatherGui *gui)
        gtk_tree_model_get(model, &iter, 1, &site, -1);
        AWeatherView *view = aweather_gui_get_view(gui);
        aweather_view_set_location(view, site);
+       g_free(site);
 }
 
 void on_time_changed(GtkTreeView *view, GtkTreePath *path,
@@ -58,9 +77,10 @@ void on_time_changed(GtkTreeView *view, GtkTreePath *path,
        gtk_tree_model_get(model, &iter, 0, &time, -1);
        AWeatherView *aview = aweather_gui_get_view(gui);
        aweather_view_set_time(aview, time);
+       g_free(time);
 }
 
-static gboolean map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
+static gboolean on_map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
 {
        //g_message("map:map");
        AWeatherView *view = aweather_gui_get_view(gui);
@@ -69,7 +89,7 @@ static gboolean map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
        /* Misc */
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glClearColor(0.8f, 0.8f, 1.0f, 0.0f);
+       glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 
        /* Tessellation, "finding intersecting triangles" */
        /* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */
@@ -86,13 +106,14 @@ static gboolean map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
        return FALSE;
 }
 
-static gboolean configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
+static gboolean on_configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
 {
        aweather_gui_gl_begin(gui);
 
        double width  = da->allocation.width;
        double height = da->allocation.height;
        double dist   = 500*1000; // 500 km
+       double cam    = 300*1000; // 500 km
 
        glViewport(0, 0, width, height);
 
@@ -101,24 +122,24 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *
        glLoadIdentity();
        double rad = atan(height/2*1000.0/dist); // 1px = 1000 meters
        double deg = (rad*180)/M_PI;
-       gluPerspective(deg*2, width/height, dist-20, dist+20);
+       gluPerspective(deg*2, width/height, cam-20, cam+20);
 
        /* Camera position? */
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
-       glTranslatef(0.0, 0.0, -dist);
+       glTranslatef(0.0, 0.0, -cam);
        //glRotatef(-45, 1, 0, 0);
 
        aweather_gui_gl_end(gui);
        return FALSE;
 }
 
-static gboolean expose_begin(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
+static gboolean on_expose_begin(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
 {
        aweather_gui_gl_begin(gui);
        return FALSE;
 }
-static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
+static gboolean on_expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
 {
        g_message("aweather:espose_end\n");
        aweather_gui_gl_end(gui);
@@ -139,11 +160,16 @@ static void update_time_widget(AWeatherView *view, char *time, AWeatherGui *gui)
                gtk_tree_model_get(model, &iter, 0, &text, -1);
                if (g_str_equal(text, time)) {
                        GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
-                       g_signal_handlers_block_by_func(tview, G_CALLBACK(on_site_changed), gui);
+                       g_signal_handlers_block_by_func(tview,
+                                       G_CALLBACK(on_site_changed), gui);
                        gtk_tree_view_set_cursor(tview, path, NULL, FALSE);
-                       g_signal_handlers_unblock_by_func(tview, G_CALLBACK(on_site_changed), gui);
+                       g_signal_handlers_unblock_by_func(tview,
+                                       G_CALLBACK(on_site_changed), gui);
+                       gtk_tree_path_free(path);
+                       g_free(text);
                        return;
                }
+               g_free(text);
        }
 }
 static void update_location_widget(AWeatherView *view, char *location, AWeatherGui *gui)
@@ -160,12 +186,15 @@ static void update_location_widget(AWeatherView *view, char *location, AWeatherG
                        char *text;
                        gtk_tree_model_get(model, &iter2, 1, &text, -1);
                        if (g_str_equal(text, location)) {
-                               GtkTreePath *path = gtk_tree_model_get_path(model, &iter2);
-                               g_signal_handlers_block_by_func(combo, G_CALLBACK(on_site_changed), gui);
+                               g_signal_handlers_block_by_func(combo,
+                                               G_CALLBACK(on_site_changed), gui);
                                gtk_combo_box_set_active_iter(combo, &iter2);
-                               g_signal_handlers_unblock_by_func(combo, G_CALLBACK(on_site_changed), gui);
+                               g_signal_handlers_unblock_by_func(combo,
+                                               G_CALLBACK(on_site_changed), gui);
+                               g_free(text);
                                return;
                        }
+                       g_free(text);
                }
        }
 }
@@ -203,6 +232,8 @@ static void site_setup(AWeatherGui *gui)
        gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(store));
        gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo), renderer,
                        combo_sensitive, NULL, NULL);
+       g_object_unref(renderer);
+       g_object_unref(store);
 
        g_signal_connect(combo, "changed", G_CALLBACK(on_site_changed),  gui);
        AWeatherView *aview = aweather_gui_get_view(gui);
@@ -225,7 +256,7 @@ static void time_setup(AWeatherGui *gui)
        g_signal_connect(aview, "time-changed", G_CALLBACK(update_time_widget), gui);
 }
 
-gboolean opengl_setup(AWeatherGui *gui)
+static void opengl_setup(AWeatherGui *gui)
 {
        GtkDrawingArea *drawing = GTK_DRAWING_AREA(aweather_gui_get_widget(gui, "drawing"));
 
@@ -234,15 +265,25 @@ gboolean opengl_setup(AWeatherGui *gui)
                        GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA);
        if (!glconfig)
                g_error("Failed to create glconfig");
-       if (!gtk_widget_set_gl_capability(GTK_WIDGET(drawing), glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
+       if (!gtk_widget_set_gl_capability(GTK_WIDGET(drawing),
+                               glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
                g_error("GL lacks required capabilities");
 
        /* Set up OpenGL Stuff */
-       g_signal_connect      (drawing, "map-event",       G_CALLBACK(map),          gui);
-       g_signal_connect      (drawing, "configure-event", G_CALLBACK(configure),    gui);
-       g_signal_connect      (drawing, "expose-event",    G_CALLBACK(expose_begin), gui);
-       g_signal_connect_after(drawing, "expose-event",    G_CALLBACK(expose_end),   gui);
-       return TRUE;
+       g_signal_connect      (drawing, "map-event",       G_CALLBACK(on_map),          gui);
+       g_signal_connect      (drawing, "configure-event", G_CALLBACK(on_configure),    gui);
+       g_signal_connect      (drawing, "expose-event",    G_CALLBACK(on_expose_begin), gui);
+       g_signal_connect_after(drawing, "expose-event",    G_CALLBACK(on_expose_end),   gui);
+}
+
+static void toolbar_setup(AWeatherGui *gui)
+{
+       GtkWidget *refresh = aweather_gui_get_widget(gui, "refresh_button");
+       GtkWidget *zoomin  = aweather_gui_get_widget(gui, "zoomin_button");
+       GtkWidget *zoomout = aweather_gui_get_widget(gui, "zoomout_button");
+       g_signal_connect(refresh, "clicked", G_CALLBACK(on_refresh), gui);
+       g_signal_connect(zoomin,  "clicked", G_CALLBACK(on_zoomin ), gui);
+       g_signal_connect(zoomout, "clicked", G_CALLBACK(on_zoomout), gui);
 }
 
 
@@ -310,6 +351,7 @@ AWeatherGui *aweather_gui_new()
        gtk_builder_connect_signals(gui->builder, NULL);
 
        /* Load components */
+       toolbar_setup(gui);
        site_setup(gui);
        time_setup(gui);
        opengl_setup(gui);