[cairo-commit] roadster/src mainwindow.c, 1.18, 1.19 mainwindow.h, 1.7, 1.8 map.c, 1.18, 1.19 map.h, 1.5, 1.6 map_draw_gdk.c, 1.4, 1.5 search_road.c, 1.12, 1.13 searchwindow.c, 1.10, 1.11 searchwindow.h, 1.3, 1.4

Ian McIntosh commit at pdx.freedesktop.org
Sun Mar 6 21:30:13 PST 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv19180/src

Modified Files:
	mainwindow.c mainwindow.h map.c map.h map_draw_gdk.c 
	search_road.c searchwindow.c searchwindow.h 
Log Message:
	* src/searchwindow.c: Sort search results by distance from user, starting with closest.  Also set zoomlevel based on type of result (road, city, state).
	* src/mainwindow.c: Add mainwindow_set_zoomlevel() and mainwindow_get_centerpoint() functions for searchwindow's use.
	* src/map.c: Uncomment map_get_distance_in_meters() for use by searchwindow.
	* src/search_road.c: Suggest zoomlevel of 3 for road search results.


Index: mainwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mainwindow.c	6 Mar 2005 23:38:19 -0000	1.18
+++ mainwindow.c	7 Mar 2005 05:30:10 -0000	1.19
@@ -547,6 +547,11 @@
 //
 // Zoom
 //
+void mainwindow_set_zoomlevel(gint nZoomLevel)
+{
+	gtk_range_set_value(GTK_RANGE(g_MainWindow.m_pZoomScale), nZoomLevel);
+}
+
 static void zoom_in_one(void)
 {
 	map_set_zoomlevel(g_MainWindow.m_pMap, map_get_zoomlevel(g_MainWindow.m_pMap) + 1);
@@ -713,9 +718,9 @@
 				// else begin a drag
 //                                 GdkCursor* pCursor = gdk_cursor_new(GDK_HAND2);
 //                                 if(GDK_GRAB_SUCCESS == gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME)) {
-				GdkCursor* pCursor = gdk_cursor_new(GDK_FLEUR);
-				gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
-				gdk_cursor_unref(pCursor);
+//                                 GdkCursor* pCursor = gdk_cursor_new(GDK_FLEUR);
+//                                 gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
+//                                 gdk_cursor_unref(pCursor);
 
 				g_MainWindow.m_bMouseDragging = TRUE;
 				g_MainWindow.m_ptClickLocation.m_nX = nX;
@@ -778,6 +783,11 @@
 	EDirection eScrollDirection = match_border(nX, nY, nWidth, nHeight, BORDER_SCROLL_CLICK_TARGET_SIZE);
 
 	if(g_MainWindow.m_bMouseDragging) {
+		// Set it here and no when first clicking because now we know it's a drag (on click it could be a double-click)
+		GdkCursor* pCursor = gdk_cursor_new(GDK_FLEUR);
+		gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
+		gdk_cursor_unref(pCursor);
+
 		gint nDeltaX = g_MainWindow.m_ptClickLocation.m_nX - nX;
                 gint nDeltaY = g_MainWindow.m_ptClickLocation.m_nY - nY;
 
@@ -1009,6 +1019,11 @@
 	mainwindow_statusbar_update_position();
 }
 
+void mainwindow_get_centerpoint(mappoint_t* pPoint)
+{
+	map_get_centerpoint(g_MainWindow.m_pMap, pPoint);
+}
+
 void mainwindow_on_addpointmenuitem_activate(GtkWidget *_unused, gpointer* __unused)
 {
 	mappoint_t point;

Index: mainwindow.h
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mainwindow.h	6 Mar 2005 23:38:19 -0000	1.7
+++ mainwindow.h	7 Mar 2005 05:30:10 -0000	1.8
@@ -61,6 +61,8 @@
 void mainwindow_statusbar_update_zoomscale(void);
 void mainwindow_statusbar_update_position(void);
 
+void mainwindow_set_zoomlevel(gint nZoomLevel);
+
 void mainwindow_statusbar_progressbar_set_text(const gchar* pszText);
 void mainwindow_statusbar_progressbar_pulse(void);
 void mainwindow_statusbar_progressbar_clear(void);
@@ -69,6 +71,7 @@
 
 // Map
 void mainwindow_set_centerpoint(mappoint_t* pPoint);
+void mainwindow_get_centerpoint(mappoint_t* pPoint);
 
 typedef enum {
 	DIRECTION_NONE, DIRECTION_N, DIRECTION_NE, DIRECTION_E, DIRECTION_SE, DIRECTION_S, DIRECTION_SW, DIRECTION_W, DIRECTION_NW

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- map.c	4 Mar 2005 21:08:23 -0000	1.18
+++ map.c	7 Mar 2005 05:30:10 -0000	1.19
@@ -567,12 +567,9 @@
 	}
 }
 
-
-#if ROADSTER_DEAD_CODE
-/*
-static double map_get_distance_in_meters(mappoint_t* pA, mappoint_t* pB)
+double map_get_distance_in_meters(mappoint_t* pA, mappoint_t* pB)
 {
-	g_assert_not_reached();	// unused/tested
+//	g_assert_not_reached();	// unused/tested
 
 	// This functions calculates the length of the arc of the "greatcircle" that goes through
 	// the two points A and B and whos center is the center of the sphere, O.
@@ -596,6 +593,9 @@
 	return fAOB_Rad * RADIUS_OF_WORLD_IN_METERS;
 }
 
+#if ROADSTER_DEAD_CODE
+/*
+
 // ========================================================
 //  Redraw
 // ========================================================

Index: map.h
===================================================================
RCS file: /cvs/cairo/roadster/src/map.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- map.h	4 Mar 2005 09:27:26 -0000	1.5
+++ map.h	7 Mar 2005 05:30:10 -0000	1.6
@@ -196,6 +196,7 @@
 // Conversions
 void map_windowpoint_to_mappoint(map_t* pMap, screenpoint_t* pScreenPoint, mappoint_t* pMapPoint);
 gdouble map_distance_in_units_to_degrees(map_t* pMap, gdouble fDistance, gint nDistanceUnit);
+double map_get_distance_in_meters(mappoint_t* pA, mappoint_t* pB);
 
 
 // remove this!

Index: map_draw_gdk.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_gdk.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- map_draw_gdk.c	5 Mar 2005 05:47:51 -0000	1.4
+++ map_draw_gdk.c	7 Mar 2005 05:30:10 -0000	1.5
@@ -201,9 +201,9 @@
 static void map_draw_gdk_background(map_t* pMap, GdkPixmap* pPixmap)
 {
 	GdkColor clr;
-	clr.red = 247/255.0 * 65535;
-	clr.green = 235/255.0 * 65535;
-	clr.blue = 230/255.0 * 65535;
+	clr.red = 239/255.0 * 65535;
+	clr.green = 239/255.0 * 65535;
+	clr.blue = 239/255.0 * 65535;
 	gdk_gc_set_rgb_fg_color(pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)], &clr);
 	
 	gdk_draw_rectangle(pPixmap, pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)],

Index: search_road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search_road.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- search_road.c	4 Mar 2005 02:27:29 -0000	1.12
+++ search_road.c	7 Mar 2005 05:30:10 -0000	1.13
@@ -33,6 +33,8 @@
 #include "search_road.h"
 #include "road.h"
 
+#define ROAD_RESULT_SUGGESTED_ZOOMLEVEL		(8)
+
 typedef struct {
 	gint m_nNumber;			// house number	eg. 51
 	gchar* m_pszRoadName;	// road name eg. "Washington"
@@ -572,7 +574,7 @@
 			// reverse start/end for the dear user :)
 			g_snprintf(azBuffer, BUFFER_SIZE, "%d-%d %s %s\n%s", nAddressRightEnd, nAddressRightStart, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZRight);
 		}
-		searchwindow_add_result(azBuffer, &ptAddress);
+		searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);
 
 		// do left side, same as right side (see above)
 		if(nAddressLeftStart == 0 && nAddressLeftEnd == 0) {
@@ -585,7 +587,7 @@
 			// swap address to keep smaller number to the left
 			g_snprintf(azBuffer, BUFFER_SIZE, "%d-%d %s %s\n%s", nAddressLeftEnd, nAddressLeftStart, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZLeft);
 		}
-		searchwindow_add_result(azBuffer, &ptAddress);		
+		searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);		
 	}
 	else {	// else the search had a road number
 		// NOTE: we have to filter out results like "97-157" when searching for "124" because it's
@@ -610,7 +612,7 @@
 					pointstring_walk_percentage(pPointString, fPercent, ROADSIDE_LEFT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, "%d %s %s\n%s", nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZLeft);
-				searchwindow_add_result(azBuffer, &ptAddress);				
+				searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);				
 			}
 			else if(nRoadNumber >= nAddressLeftEnd && nRoadNumber <= nAddressLeftStart) {
 				// MATCH: left side backwards
@@ -626,7 +628,7 @@
 					pointstring_walk_percentage(pPointString, (100.0 - fPercent), ROADSIDE_RIGHT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, "%d %s %s\n%s", nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZLeft);
-				searchwindow_add_result(azBuffer, &ptAddress);
+				searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);
 			}
 		}
 
@@ -647,7 +649,7 @@
 					pointstring_walk_percentage(pPointString, fPercent, ROADSIDE_RIGHT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, "%d %s %s\n%s", nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZRight);
-				searchwindow_add_result(azBuffer, &ptAddress);				
+				searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);				
 			}
 			else if(nRoadNumber >= nAddressRightEnd && nRoadNumber <= nAddressRightStart) {
 				// MATCH: right side backwards
@@ -663,8 +665,7 @@
 					pointstring_walk_percentage(pPointString, (100.0 - fPercent), ROADSIDE_LEFT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, "%d %s %s\n%s", nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZRight);
-				searchwindow_add_result
-					(azBuffer, &ptAddress);				
+				searchwindow_add_result(azBuffer, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);				
 			}
 		}
 	}

Index: searchwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- searchwindow.c	4 Mar 2005 21:08:23 -0000	1.10
+++ searchwindow.c	7 Mar 2005 05:30:10 -0000	1.11
@@ -35,10 +35,13 @@
 
 #define GTK_PROCESS_MAINLOOP  while (gtk_events_pending ()) { gtk_main_iteration (); }
 
-#define RESULTLIST_COLUMN_NAME 	0
+#define RESULTLIST_COLUMN_NAME 	0	// visible data
 #define RESULTLIST_LATITUDE	1
 #define RESULTLIST_LONGITUDE	2
+#define RESULTLIST_DISTANCE	3
+#define RESULTLIST_ZOOMLEVEL	4
 
+#define MAGIC_GTK_NO_SORT_COLUMN (-2)	// why -2?  dunno.  is there a real define for this?  dunno.
 
 struct {
 	// window
@@ -53,9 +56,6 @@
 	// results list (on the sidebar)
 	GtkTreeView* m_pResultsTreeView;
 	GtkListStore* m_pResultsListStore;
-	
-	// go to selected result button (on the sidebar)
-	GtkButton* m_pGoButton;
 } g_SearchWindow = {0};
 
 static void searchwindow_on_resultslist_selection_changed(GtkTreeSelection *treeselection, gpointer user_data);
@@ -65,10 +65,9 @@
 	g_SearchWindow.m_pSearchEntry 		= GTK_ENTRY(glade_xml_get_widget(pGladeXML, "searchentry"));			g_return_if_fail(g_SearchWindow.m_pSearchEntry != NULL);	
 	g_SearchWindow.m_pSearchButton		= GTK_BUTTON(glade_xml_get_widget(pGladeXML, "searchbutton"));			g_return_if_fail(g_SearchWindow.m_pSearchButton != NULL);	
 	g_SearchWindow.m_pResultsTreeView	= GTK_TREE_VIEW(glade_xml_get_widget(pGladeXML, "searchresultstreeview"));	g_return_if_fail(g_SearchWindow.m_pResultsTreeView != NULL);	
-	g_SearchWindow.m_pGoButton		= GTK_BUTTON(glade_xml_get_widget(pGladeXML, "searchgobutton"));		g_return_if_fail(g_SearchWindow.m_pGoButton != NULL);	
 
 	// create results tree view
-	g_SearchWindow.m_pResultsListStore = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+	g_SearchWindow.m_pResultsListStore = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_INT);
 	gtk_tree_view_set_model(g_SearchWindow.m_pResultsTreeView, GTK_TREE_MODEL(g_SearchWindow.m_pResultsListStore));
 
 	GtkCellRenderer* pCellRenderer;
@@ -95,15 +94,13 @@
 // begin a search
 void searchwindow_on_findbutton_clicked(GtkWidget *pWidget, gpointer* p)
 {
-	g_print("begin search\n");
-
-	gtk_widget_set_sensitive(GTK_WIDGET(g_SearchWindow.m_pSearchButton), FALSE);
-
-	searchwindow_clear_results();
+	// make list unsorted (sorting once at the end is much faster than for each insert)
+	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(g_SearchWindow.m_pResultsListStore), MAGIC_GTK_NO_SORT_COLUMN, GTK_SORT_ASCENDING);
 
 	const gchar* pszSearch = gtk_entry_get_text(g_SearchWindow.m_pSearchEntry);
 
 	void* pBusy = mainwindow_set_busy();
+	searchwindow_clear_results();
 	search_road_execute(pszSearch);
 	mainwindow_set_not_busy(&pBusy);
 
@@ -111,21 +108,30 @@
 	mainwindow_sidebar_set_tab(SIDEBAR_TAB_SEARCH_RESULTS);
 	mainwindow_set_sidebox_visible(TRUE);
 
-	gtk_widget_set_sensitive(GTK_WIDGET(g_SearchWindow.m_pSearchButton), TRUE);
+	// Sort the list by distance from viewer!
+	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(g_SearchWindow.m_pResultsListStore), RESULTLIST_DISTANCE, GTK_SORT_ASCENDING);
 }
 
 // add a result row to the list
-void searchwindow_add_result(const gchar* pszText, mappoint_t* pPoint)
+void searchwindow_add_result(const gchar* pszText, mappoint_t* pPoint, gint nZoomLevel)
 {
 	GtkTreeIter iter;
 
+	mappoint_t ptCenter;
+	mainwindow_get_centerpoint(&ptCenter);
+
+	gdouble fDistance = map_get_distance_in_meters(&ptCenter, pPoint);
+
 	gchar* pszBuffer = g_strdup_printf("<span size='small'>%s</span>", pszText);
 	gtk_list_store_append(g_SearchWindow.m_pResultsListStore, &iter);
 	gtk_list_store_set(g_SearchWindow.m_pResultsListStore, &iter,
 		RESULTLIST_COLUMN_NAME, pszBuffer,
 		RESULTLIST_LATITUDE, pPoint->m_fLatitude,
-		RESULTLIST_LONGITUDE, pPoint->m_fLongitude,		
+		RESULTLIST_LONGITUDE, pPoint->m_fLongitude,
+		RESULTLIST_DISTANCE, fDistance,
+		RESULTLIST_ZOOMLEVEL, nZoomLevel,
 		-1);
+
 	g_free(pszBuffer);
 }
 
@@ -138,11 +144,14 @@
 	GtkTreeModel* pModel = GTK_TREE_MODEL(g_SearchWindow.m_pResultsListStore);
 	if(gtk_tree_selection_get_selected(pSelection, &pModel, &iter)) {
 		mappoint_t pt;
+		gint nZoomLevel;
 		gtk_tree_model_get(GTK_TREE_MODEL(g_SearchWindow.m_pResultsListStore), &iter,
 			RESULTLIST_LATITUDE, &pt.m_fLatitude,
 			RESULTLIST_LONGITUDE, &pt.m_fLongitude,
+			RESULTLIST_ZOOMLEVEL, &nZoomLevel,
 			-1);
 
+		mainwindow_set_zoomlevel(nZoomLevel);
 		mainwindow_set_centerpoint(&pt);
 		mainwindow_draw_map(DRAWFLAG_ALL);
 		mainwindow_statusbar_update_position();
@@ -154,19 +163,8 @@
 	searchwindow_go_to_selected_result();
 }
 
-void searchwindow_on_gobutton_clicked(GtkWidget *pWidget, gpointer* p)
-{
-	searchwindow_go_to_selected_result();
-}
-
-#define GTK_PROCESS_MAINLOOP  while (gtk_events_pending ()) { gtk_main_iteration (); }
-
 static void searchwindow_on_resultslist_selection_changed(GtkTreeSelection *treeselection, gpointer user_data)
 {
 	GTK_PROCESS_MAINLOOP;
-
 	searchwindow_go_to_selected_result();
-
-	/* set "Go" button sensitive if >0 items selected */
-//	gtk_widget_set_sensitive(GTK_WIDGET(g_SearchWindow.m_pGoButton), gtk_tree_selection_count_selected_rows(treeselection) > 0);	
 }

Index: searchwindow.h
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- searchwindow.h	4 Mar 2005 02:27:29 -0000	1.3
+++ searchwindow.h	7 Mar 2005 05:30:10 -0000	1.4
@@ -31,9 +31,9 @@
 	
 void searchwindow_init(GladeXML* pGladeXML);
 
-void searchwindow_add_result(const gchar* pszText, mappoint_t* pPoint);
+void searchwindow_add_result(const gchar* pszText, mappoint_t* pPoint, gint nZoomLevel);
 
-void searchwindow_go_to_selected_result(void);
+static void searchwindow_go_to_selected_result(void);
 
 void searchwindow_clear_results(void);
 




More information about the cairo-commit mailing list