X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Faweather-gui.c;h=320a14d59de224a17a8a36c9de2d45c5981ea44e;hp=83d9a3f79b70e7caf287808a403cc6a4a689cf5c;hb=93c853165104b5119e17be07e325f9097a5ebdb3;hpb=4fcef1604ab68160bb3fc51755cc87d23e215fee diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 83d9a3f..320a14d 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2009 Andy Spencer + * + * 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 @@ -52,7 +69,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 */ @@ -76,6 +93,7 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui * 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); @@ -84,12 +102,12 @@ 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); @@ -109,6 +127,52 @@ static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gu return FALSE; } +/* TODO: replace the code in these with `gtk_tree_model_find' utility */ +static void update_time_widget(AWeatherView *view, char *time, AWeatherGui *gui) +{ + g_message("updating time widget"); + GtkTreeView *tview = GTK_TREE_VIEW(aweather_gui_get_widget(gui, "time")); + GtkTreeModel *model = GTK_TREE_MODEL(gtk_tree_view_get_model(tview)); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) { + char *text; + GtkTreeIter iter; + gtk_tree_model_iter_nth_child(model, &iter, NULL, i); + 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); + gtk_tree_view_set_cursor(tview, path, NULL, FALSE); + g_signal_handlers_unblock_by_func(tview, G_CALLBACK(on_site_changed), gui); + return; + } + } +} +static void update_location_widget(AWeatherView *view, char *location, AWeatherGui *gui) +{ + g_message("updating location widget to %s", location); + GtkComboBox *combo = GTK_COMBO_BOX(aweather_gui_get_widget(gui, "site")); + GtkTreeModel *model = GTK_TREE_MODEL(gtk_combo_box_get_model(combo)); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) { + GtkTreeIter iter1; + gtk_tree_model_iter_nth_child(model, &iter1, NULL, i); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, &iter1); i++) { + GtkTreeIter iter2; + gtk_tree_model_iter_nth_child(model, &iter2, &iter1, i); + 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); + gtk_combo_box_set_active_iter(combo, &iter2); + g_signal_handlers_unblock_by_func(combo, G_CALLBACK(on_site_changed), gui); + g_free(text); + return; + } + g_free(text); + } + } +} + /***************** * Setup helpers * *****************/ @@ -144,6 +208,8 @@ static void site_setup(AWeatherGui *gui) combo_sensitive, NULL, NULL); g_signal_connect(combo, "changed", G_CALLBACK(on_site_changed), gui); + AWeatherView *aview = aweather_gui_get_view(gui); + g_signal_connect(aview, "location-changed", G_CALLBACK(update_location_widget), gui); } static void time_setup(AWeatherGui *gui) @@ -158,6 +224,8 @@ static void time_setup(AWeatherGui *gui) gtk_tree_view_append_column(tview, col); g_signal_connect(tview, "row-activated", G_CALLBACK(on_time_changed), gui); + AWeatherView *aview = aweather_gui_get_view(gui); + g_signal_connect(aview, "time-changed", G_CALLBACK(update_time_widget), gui); } gboolean opengl_setup(AWeatherGui *gui)