[cairo-commit] roadster/src Makefile.am, 1.14, 1.15 gpsclient.c, 1.7, 1.8 history.c, NONE, 1.1 history.h, NONE, 1.1 mainwindow.c, 1.27, 1.28 map.c, 1.29, 1.30 map.h, 1.8, 1.9 map_draw_gdk.c, 1.7, 1.8 search_road.c, 1.14, 1.15 track.c, 1.4, 1.5

Ian McIntosh commit at pdx.freedesktop.org
Sun Mar 20 02:57:07 PST 2005


Committed by: ian

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

Modified Files:
	Makefile.am gpsclient.c mainwindow.c map.c map.h 
	map_draw_gdk.c search_road.c track.c 
Added Files:
	history.c history.h 
Log Message:
	* src/history.h:
	* src/history.c: Added.  Stores a list of places for the back/forward buttons.
	* src/Makefile.am: Added history.c.
	* src/gpsclient.c: Re-enabled GPS support.
	* src/mainwindow.c: Added back/forward buttons.  Added GTK about box.
	* src/map.c: Added basic support for tracks (for GPS track).
	* src/map_draw_gdk.c: Added basic drawing of tracks.
	* src/search_road.c: Improved GLib version check.
	* src/track.c: Removed debugging message.


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/roadster/src/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile.am	20 Mar 2005 03:37:09 -0000	1.14
+++ Makefile.am	20 Mar 2005 10:57:05 -0000	1.15
@@ -49,7 +49,8 @@
 	road.c\
 	prefs.c\
 	animator.c\
-	gfreelist.c
+	gfreelist.c\
+	history.c
 
 roadster_LDADD = \
 	$(GNOME_LIBS) \

Index: gpsclient.c
===================================================================
RCS file: /cvs/cairo/roadster/src/gpsclient.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gpsclient.c	18 Mar 2005 08:37:35 -0000	1.7
+++ gpsclient.c	20 Mar 2005 10:57:05 -0000	1.8
@@ -49,7 +49,6 @@
 
 static void gpsclient_connect(void)
 {
-return;
 	// don't do anything if already connected
 	if(g_GPSClient.m_pPublicGPSData->m_eStatus != GPS_STATUS_NO_GPSD) return;	// already connected
 
@@ -58,6 +57,8 @@
 		gps_close(g_GPSClient.m_pGPSConnection);
 	}
 
+//	g_print("Attempting connection to GPSD...\n");
+
 	// connect
  	g_GPSClient.m_pGPSConnection = gps_open("localhost", DEFAULT_GPSD_PORT);
 
@@ -87,6 +88,8 @@
 // callback for g_io_add_watch on the GPSD file descriptor
 gboolean gpsclient_callback_data_waiting(GIOChannel *source, GIOCondition condition, gpointer data)
 {
+//	g_print("Data from GPSD...\n");
+
 	gpsdata_t* l = g_GPSClient.m_pPublicGPSData;	// our public data struct, for easy access
 
 	// is there data waiting on the socket?
@@ -147,6 +150,9 @@
 			l->m_eStatus = GPS_STATUS_NO_DEVICE;
 		}
 	}
+	else {
+		//g_print("condition: %d\n", condition);
+	}
 	return TRUE; // TRUE = keep socket notification coming
 }
 

--- NEW FILE: history.c ---
/***************************************************************************
 *            history.c
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh at linuxadvocate.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 2 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <gtk/gtk.h>
#include "history.h"
#include "map.h"

typedef struct {
	mappoint_t m_MapPoint;
	gint m_nZoomLevel;
} mapview_t;

void history_init(void)
{
	// module init
}

history_t* history_new()
{
	history_t* pNew = g_new0(history_t, 1);
	pNew->m_MapViewArray = g_array_new(FALSE, FALSE, sizeof(mapview_t));
	pNew->m_nCurrentIndex = -1;
	return pNew;
}

void history_add(history_t* pHistory, mappoint_t* pPoint, gint nZoomLevel)
{
	g_assert(pHistory != NULL);
	g_assert(pPoint != NULL);

	if(pHistory->m_nCurrentIndex < (pHistory->m_MapViewArray->len - 1)) {
		// clear out everything after currentindex in the array!
		g_array_remove_range(pHistory->m_MapViewArray, pHistory->m_nCurrentIndex + 1, (pHistory->m_MapViewArray->len - pHistory->m_nCurrentIndex) - 1);

		pHistory->m_nTotalItems = (pHistory->m_nCurrentIndex + 1);
	}

	// Move to next one
	pHistory->m_nCurrentIndex++;

	if(pHistory->m_nCurrentIndex >= pHistory->m_MapViewArray->len) {
		// XXX: is this doing a realloc every time?  ouch. :)
		g_array_set_size(pHistory->m_MapViewArray, pHistory->m_MapViewArray->len + 1);
	}

	// Get pointer to it
	mapview_t* pNew = &g_array_index(pHistory->m_MapViewArray, mapview_t, pHistory->m_nCurrentIndex);
	g_return_if_fail(pNew != NULL);

	// Save details
	memcpy(&(pNew->m_MapPoint), pPoint, sizeof(mappoint_t));
	pNew->m_nZoomLevel = nZoomLevel;

	pHistory->m_nTotalItems++;
}

gboolean history_can_go_forward(history_t* pHistory)
{
	return(pHistory->m_nCurrentIndex < (pHistory->m_nTotalItems - 1));
}

gboolean history_can_go_back(history_t* pHistory)
{
	return(pHistory->m_nCurrentIndex > 0);
}

gboolean history_go_forward(history_t* pHistory)
{
	if(history_can_go_forward(pHistory)) {
		pHistory->m_nCurrentIndex++;
		return TRUE;
	}
}

gboolean history_go_back(history_t* pHistory)
{
	if(history_can_go_back(pHistory)) {
		pHistory->m_nCurrentIndex--;
		return TRUE;
	}
}

void history_get_current(history_t* pHistory, mappoint_t* pReturnPoint, gint* pnReturnZoomLevel)
{
	g_assert(pHistory != NULL);
	g_assert(pReturnPoint != NULL);
	g_assert(pnReturnZoomLevel != NULL);
	g_assert(pHistory->m_nCurrentIndex >= 0);
	g_assert(pHistory->m_nCurrentIndex < pHistory->m_nTotalItems);

	mapview_t* pCurrent = &g_array_index(pHistory->m_MapViewArray, mapview_t, pHistory->m_nCurrentIndex);
	
	memcpy(pReturnPoint, &(pCurrent->m_MapPoint), sizeof(mappoint_t));
	*pnReturnZoomLevel  = pCurrent->m_nZoomLevel;
}

--- NEW FILE: history.h ---
/***************************************************************************
 *            history.h
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh at linuxadvocate.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 2 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _HISTORY_H_
#define _HISTORY_H_

#include "map.h"

typedef struct {
	gint m_nCurrentIndex;
	gint m_nTotalItems;
	GArray* m_MapViewArray;
} history_t;

void history_init(void);
history_t* history_new();
void history_add(history_t* pHistory, mappoint_t* pPoint, gint nZoomLevel);
gboolean history_can_go_forward(history_t* pHistory);
gboolean history_can_go_back(history_t* pHistory);
gboolean history_go_forward(history_t* pHistory);
gboolean history_go_back(history_t* pHistory);

void history_get_current(history_t* pHistory, mappoint_t* pReturnPoint, gint* pnReturnZoomLevel);

#endif

Index: mainwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- mainwindow.c	20 Mar 2005 03:37:09 -0000	1.27
+++ mainwindow.c	20 Mar 2005 10:57:05 -0000	1.28
@@ -44,6 +44,7 @@
 #include "mainwindow.h"
 #include "glyph.h"
 #include "animator.h"
+#include "history.h"
 
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
@@ -70,7 +71,7 @@
 #define SLIDE_TIMEOUT_MS		(50)	// time between frames (in MS) for smooth-sliding (on double click?)
 #define	SLIDE_TIME_IN_SECONDS		(0.7)	// how long the whole slide should take, in seconds
 
-#define	SLIDE_TIME_IN_SECONDS_AUTO	(1.4)
+#define	SLIDE_TIME_IN_SECONDS_AUTO	(1.3)
 
 // Layerlist columns
 #define LAYERLIST_COLUMN_ENABLED	(0)
@@ -111,6 +112,8 @@
 static gboolean mainwindow_callback_on_slide_timeout(gpointer pData);
 static void mainwindow_setup_selected_tool(void);
 
+void mainwindow_add_history();
+
 void mainwindow_map_center_on_mappoint(mappoint_t* pPoint);
 void mainwindow_map_center_on_windowpoint(gint nX, gint nY);
 
@@ -148,6 +151,13 @@
 	GtkLabel* m_pSpeedLabel;
 	GtkProgressBar* m_pGPSSignalStrengthProgressBar;
 
+	struct {
+		GtkCheckButton* m_pShowPositionCheckButton;
+		GtkCheckButton* m_pKeepPositionCenteredCheckButton;
+		GtkCheckButton* m_pShowTrailCheckButton;
+		GtkCheckButton* m_pStickToRoadsCheckButton;
+	} m_GPS;
+
 	// Statusbar
 	GtkVBox*  m_pStatusbar;
  	GtkLabel* m_pPositionLabel;
@@ -181,6 +191,11 @@
 	mappoint_t m_ptSlideStartLocation;
 	mappoint_t m_ptSlideEndLocation;
 	animator_t* m_pAnimator;
+
+	// History (forward / back)
+	history_t* m_pHistory;
+	GtkButton* m_pForwardButton;
+	GtkButton* m_pBackButton;
 } g_MainWindow = {0};
 
 
@@ -241,7 +256,6 @@
 ** Status bar
 */
 
-
 void mainwindow_init(GladeXML* pGladeXML)
 {
 	g_MainWindow.m_pWindow				= GTK_WINDOW(glade_xml_get_widget(pGladeXML, "mainwindow"));			g_return_if_fail(g_MainWindow.m_pWindow != NULL);
@@ -265,6 +279,16 @@
 	g_MainWindow.m_pSpeedLabel			= GTK_LABEL(glade_xml_get_widget(pGladeXML, "speedlabel"));		g_return_if_fail(g_MainWindow.m_pSpeedLabel != NULL);
 	g_MainWindow.m_pGPSSignalStrengthProgressBar = GTK_PROGRESS_BAR(glade_xml_get_widget(pGladeXML, "gpssignalprogressbar"));		g_return_if_fail(g_MainWindow.m_pGPSSignalStrengthProgressBar != NULL);
 
+	g_MainWindow.m_GPS.m_pShowPositionCheckButton	= GTK_CHECK_BUTTON(glade_xml_get_widget(pGladeXML, "gpsshowpositioncheckbutton"));		g_return_if_fail(g_MainWindow.m_GPS.m_pShowPositionCheckButton != NULL);
+	g_MainWindow.m_GPS.m_pKeepPositionCenteredCheckButton= GTK_CHECK_BUTTON(glade_xml_get_widget(pGladeXML, "gpskeeppositioncenteredcheckbutton"));		g_return_if_fail(g_MainWindow.m_GPS.m_pKeepPositionCenteredCheckButton != NULL);
+	g_MainWindow.m_GPS.m_pShowTrailCheckButton = GTK_CHECK_BUTTON(glade_xml_get_widget(pGladeXML, "gpsshowtrailcheckbutton"));		g_return_if_fail(g_MainWindow.m_GPS.m_pKeepPositionCenteredCheckButton != NULL);
+	g_MainWindow.m_GPS.m_pStickToRoadsCheckButton = GTK_CHECK_BUTTON(glade_xml_get_widget(pGladeXML, "gpssticktoroadscheckbutton"));		g_return_if_fail(g_MainWindow.m_GPS.m_pStickToRoadsCheckButton != NULL);
+
+	g_MainWindow.m_pForwardButton = GTK_BUTTON(glade_xml_get_widget(pGladeXML, "forwardbutton"));		g_return_if_fail(g_MainWindow.m_pForwardButton != NULL);
+	g_MainWindow.m_pBackButton = GTK_BUTTON(glade_xml_get_widget(pGladeXML, "backbutton"));		g_return_if_fail(g_MainWindow.m_pBackButton != NULL);
+	g_MainWindow.m_pHistory = history_new();
+	g_assert(g_MainWindow.m_pHistory);
+
 	g_signal_connect(G_OBJECT(g_MainWindow.m_pWindow), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
 
 	// create drawing area
@@ -571,6 +595,8 @@
 
 	mainwindow_draw_map(DRAWFLAG_GEOMETRY);
 	mainwindow_set_draw_pretty_timeout(DRAW_PRETTY_ZOOM_TIMEOUT_MS);
+
+	mainwindow_add_history();
 }
 
 //
@@ -578,6 +604,8 @@
 //
 void mainwindow_set_zoomlevel(gint nZoomLevel)
 {
+	map_set_zoomlevel(g_MainWindow.m_pMap, nZoomLevel);
+
 	// set zoomlevel scale but prevent it from calling handler (mainwindow_on_zoomscale_value_changed)
         g_signal_handlers_block_by_func(g_MainWindow.m_pZoomScale, mainwindow_on_zoomscale_value_changed, NULL);
 	gtk_range_set_value(GTK_RANGE(g_MainWindow.m_pZoomScale), nZoomLevel);
@@ -615,22 +643,21 @@
 
 void mainwindow_on_aboutmenuitem_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
-//         const gchar *ppAuthors[] = {
-//                 "Ian McIntosh <ian_mcintosh at linuxadvocate.org>",
-//                 "Nathan Fredrickson <nathan at silverorange.com>",
-//                 NULL
-//         };
-//
-//         GtkWidget *pAboutWindow = gnome_about_new(
-//                                         PROGRAM_NAME,
-//                                         VERSION,
-//                                         PROGRAM_COPYRIGHT,
-//                                         PROGRAM_DESCRIPTION,
-//                                         (const gchar **) ppAuthors,
-//                                         NULL,
-//                                         NULL,
-//                                         NULL);
-//         gtk_widget_show(pAboutWindow);
+#if(GLIB_CHECK_VERSION(2,6,0))
+         const gchar *ppAuthors[] = {
+                 "Ian McIntosh <ian_mcintosh at linuxadvocate.org>",
+                 "Nathan Fredrickson <nathan at silverorange.com>",
+                 NULL
+         };
+
+         gtk_show_about_dialog(g_MainWindow.m_pWindow,
+			       "authors", ppAuthors,
+			       "comments", PROGRAM_DESCRIPTION,
+			       "copyright", PROGRAM_COPYRIGHT,
+			       "name", PROGRAM_NAME,
+			       "version", VERSION,
+			       NULL);
+#endif
 }
 
 // Toggle toolbar visibility
@@ -656,6 +683,7 @@
 	zoom_in_one();
 	mainwindow_draw_map(DRAWFLAG_GEOMETRY);
 	mainwindow_set_draw_pretty_timeout(DRAW_PRETTY_ZOOM_TIMEOUT_MS);
+	mainwindow_add_history();
 }
 
 void mainwindow_on_zoomout_activate(GtkMenuItem *menuitem, gpointer user_data)
@@ -663,6 +691,7 @@
 	zoom_out_one();
 	mainwindow_draw_map(DRAWFLAG_GEOMETRY);
 	mainwindow_set_draw_pretty_timeout(DRAW_PRETTY_ZOOM_TIMEOUT_MS);
+	mainwindow_add_history();
 }
 
 void mainwindow_on_fullscreenmenuitem_activate(GtkMenuItem *menuitem, gpointer user_data)
@@ -788,6 +817,8 @@
 				if(g_MainWindow.m_bMouseDragMovement) {
 					mainwindow_cancel_draw_pretty_timeout();
 					mainwindow_draw_map(DRAWFLAG_ALL);
+
+					mainwindow_add_history();
 				}
 			}
 
@@ -799,6 +830,8 @@
 
 				mainwindow_cancel_draw_pretty_timeout();
 				mainwindow_draw_map(DRAWFLAG_ALL);
+
+				mainwindow_add_history();
 			}
 		}
 		else if(event->type == GDK_2BUTTON_PRESS) {
@@ -1021,6 +1054,29 @@
 	return FALSE;
 }
 
+/*
+** GPS Functions
+*/ 
+
+gboolean mainwindow_on_gps_show_position_toggled(GtkWidget* _unused, gpointer* __unused)
+{
+
+}
+
+gboolean mainwindow_on_gps_keep_position_centered_toggled(GtkWidget* _unused, gpointer* __unused)
+{
+
+}
+
+gboolean mainwindow_on_gps_show_trail_toggled(GtkWidget* _unused, gpointer* __unused)
+{
+
+}
+
+gboolean mainwindow_on_gps_stick_to_roads_toggled(GtkWidget* _unused, gpointer* __unused)
+{
+
+}
 
 static gboolean mainwindow_callback_on_gps_redraw_timeout(gpointer __unused)
 {
@@ -1033,17 +1089,22 @@
 		if(g_MainWindow.m_nCurrentGPSPath == 0) {
 			// create a new track for GPS trail
 			g_MainWindow.m_nCurrentGPSPath = track_new();
+			map_add_track(g_MainWindow.m_pMap, g_MainWindow.m_nCurrentGPSPath);
 		}
 
 		track_add_point(g_MainWindow.m_nCurrentGPSPath, &pData->m_ptPosition);
 
-		// if(keep position centered) {
-//         map_center_on_worldpoint(pData->m_ptPosition.m_fLatitude, pData->m_ptPosition.m_fLongitude);
-//         mainwindow_statusbar_update_position();
-		// }
+		// Show position?
+		if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_MainWindow.m_GPS.m_pShowPositionCheckButton))) {
+			// Keep it centered?
+			if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_MainWindow.m_GPS.m_pKeepPositionCenteredCheckButton))) {
+				map_set_centerpoint(g_MainWindow.m_pMap, &pData->m_ptPosition);
+				mainwindow_statusbar_update_position();
+			}
 
-		// redraw because GPS icon/trail may be different
-		mainwindow_draw_map(DRAWFLAG_ALL);
+			// redraw because GPS icon/trail may be different
+			mainwindow_draw_map(DRAWFLAG_ALL);
+		}
 
 		// update image and tooltip for GPS icon
 		util_set_image_to_stock(g_MainWindow.m_pStatusbarGPSIcon, GTK_STOCK_OK, GTK_ICON_SIZE_MENU);
@@ -1110,6 +1171,7 @@
 
 			fPercent = 1.0;
 
+			mainwindow_add_history();
 			// should we delete the timer?
 		}
 
@@ -1187,6 +1249,9 @@
 	}
 	else {
 		mainwindow_map_center_on_mappoint(pPoint);
+		
+		// XXX: this is kind of a hack, but the caller can't add a history item because it might be a slide... hmm
+		mainwindow_add_history();
 	}
 }
 
@@ -1219,7 +1284,48 @@
 	gtk_notebook_set_current_page(g_MainWindow.m_pSidebarNotebook, nTab);
 }
 
+void mainwindow_update_forward_back_buttons()
+{
+	gtk_widget_set_sensitive(GTK_WIDGET(g_MainWindow.m_pForwardButton), history_can_go_forward(g_MainWindow.m_pHistory));
+	gtk_widget_set_sensitive(GTK_WIDGET(g_MainWindow.m_pBackButton), history_can_go_back(g_MainWindow.m_pHistory));
+}
+
+void mainwindow_go_to_current_history_item()
+{
+	mappoint_t point;
+	gint nZoomLevel;
+	history_get_current(g_MainWindow.m_pHistory, &point, &nZoomLevel);
+
+	mainwindow_set_zoomlevel(nZoomLevel);
+	mainwindow_map_center_on_mappoint(&point);
+	mainwindow_draw_map(DRAWFLAG_ALL);
+//	mainwindow_draw_map(DRAWFLAG_GEOMETRY);
+}
+
+void mainwindow_on_backbutton_clicked(GtkWidget* _unused, gpointer* __unused)
+{
+	history_go_back(g_MainWindow.m_pHistory);
+	mainwindow_go_to_current_history_item();
+	mainwindow_update_forward_back_buttons();
+}
+
+void mainwindow_on_forwardbutton_clicked(GtkWidget* _unused, gpointer* __unused)
+{
+	history_go_forward(g_MainWindow.m_pHistory);
+	mainwindow_go_to_current_history_item();
+	mainwindow_update_forward_back_buttons();
+}
 
+// Add the current spot to the history
+void mainwindow_add_history()
+{
+	mappoint_t point;
+
+	map_get_centerpoint(g_MainWindow.m_pMap, &point);
+	history_add(g_MainWindow.m_pHistory, &point, map_get_zoomlevel(g_MainWindow.m_pMap));
+
+	mainwindow_update_forward_back_buttons();
+}
 #ifdef ROADSTER_DEAD_CODE
 /*
 

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- map.c	20 Mar 2005 03:37:09 -0000	1.29
+++ map.c	20 Mar 2005 10:57:05 -0000	1.30
@@ -135,7 +135,6 @@
 {
 }
 
-
 gboolean map_new(map_t** ppMap, GtkWidget* pTargetWidget)
 {
 	g_assert(ppMap != NULL);
@@ -144,8 +143,10 @@
 	// create a new map struct
 	map_t* pMap = g_new0(map_t, 1);
 
-//         pMap->m_pDataMutex = g_mutex_new();
-//         pMap->m_pPixmapMutex = g_mutex_new();
+	// Create array of Track handles
+	pMap->m_pTracksArray = g_array_new(FALSE, /* not zero-terminated */
+					  TRUE,  /* clear to 0 (?) */
+					  sizeof(gint));
 
 	pMap->m_pTargetWidget = pTargetWidget;
 
@@ -167,12 +168,6 @@
 	return TRUE;
 }
 
-//         pointstring_t* pTrackPointString = track_get_pointstring(g_MainWindow.m_nCurrentGPSPath);
-//         if(pTrackPointString) {
-//                 map_draw_gps_trail(pCairoInstance, pTrackPointString);
-//         }
-
-
 #define	RENDERMODE_FAST 	1
 #define	RENDERMODE_PRETTY 	2
 
@@ -205,9 +200,11 @@
 //         scenemanager_claim_rectangle(pMap->m_pSceneManager, &rect);
 
 	if(nRenderMode == RENDERMODE_FAST) {
+		// 
 		if(nDrawFlags & DRAWFLAG_GEOMETRY) {
 			map_draw_gdk(pMap, pRenderMetrics, pMap->m_pPixmap, DRAWFLAG_GEOMETRY);
 		}
+		// Always draw labels with Cairo
 		if(nDrawFlags & DRAWFLAG_LABELS) {
 			map_draw_cairo(pMap, pRenderMetrics, pMap->m_pPixmap, DRAWFLAG_LABELS);
 		}
@@ -728,6 +725,11 @@
 	return( p1->m_fLatitude == p2->m_fLatitude && p1->m_fLongitude == p2->m_fLongitude);
 }
 
+void map_add_track(map_t* pMap, gint hTrack)
+{
+	g_array_append_val(pMap->m_pTracksArray, hTrack);
+}
+
 #if ROADSTER_DEAD_CODE
 /*
 

Index: map.h
===================================================================
RCS file: /cvs/cairo/roadster/src/map.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- map.h	20 Mar 2005 03:37:09 -0000	1.8
+++ map.h	20 Mar 2005 10:57:05 -0000	1.9
@@ -145,6 +145,8 @@
 	 GtkWidget*			m_pTargetWidget;
 	 scenemanager_t*		m_pSceneManager;
 
+	 GArray*			m_pTracksArray;
+
 	// Mutex and the data it controls (always lock before reading/writing)
 	//GMutex* m_pPixmapMutex;
 	 GdkPixmap* m_pPixmap;
@@ -168,6 +170,7 @@
 // Draw flags
 #define DRAWFLAG_LABELS 	(1)
 #define DRAWFLAG_GEOMETRY	(2)
+
 // next is 4 :)
 #define DRAWFLAG_ALL 		(1|2)
 
@@ -213,4 +216,6 @@
 
 gdouble map_get_distance_in_pixels(map_t* pMap, mappoint_t* p1, mappoint_t* p2);
 
+void map_add_track(map_t* pMap, gint hTrack);
+
 #endif

Index: map_draw_gdk.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_gdk.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- map_draw_gdk.c	18 Mar 2005 08:37:35 -0000	1.7
+++ map_draw_gdk.c	20 Mar 2005 10:57:05 -0000	1.8
@@ -39,9 +39,10 @@
 #include "locationset.h"
 #include "scenemanager.h"
 
+static void map_draw_gdk_background(map_t* pMap, GdkPixmap* pPixmap);
 static void map_draw_gdk_layer_polygons(map_t* pMap, GdkPixmap* pPixmap, rendermetrics_t* pRenderMetrics, GPtrArray* pPointStringsArray, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
 static void map_draw_gdk_layer_lines(map_t* pMap, GdkPixmap* pPixmap, rendermetrics_t* pRenderMetrics, GPtrArray* pPointStringsArray, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle);
-static void map_draw_gdk_background(map_t* pMap, GdkPixmap* pPixmap);
+static void map_draw_gdk_tracks(map_t* pMap, GdkPixmap* pPixmap, rendermetrics_t* pRenderMetrics);
 
 void map_draw_gdk(map_t* pMap, rendermetrics_t* pRenderMetrics, GdkPixmap* pPixmap, gint nDrawFlags)
 {
@@ -72,8 +73,7 @@
 				/* style */ 	&(g_aLayers[nLayer]->m_Style.m_aSubLayers[nSubLayer]),
 						&(g_aLayers[nLayer]->m_TextLabelStyle));
 			}
-			else 
-                if(layerdraworder[i].eSubLayerRenderType == SUBLAYER_RENDERTYPE_POLYGONS) {
+			else if(layerdraworder[i].eSubLayerRenderType == SUBLAYER_RENDERTYPE_POLYGONS) {
 				map_draw_gdk_layer_polygons(pMap, pPixmap,
 						pRenderMetrics,
 				/* geometry */ 	pMap->m_apLayerData[nLayer]->m_pPointStringsArray,
@@ -81,6 +81,8 @@
 						&(g_aLayers[nLayer]->m_TextLabelStyle));
 			}
 		}
+
+		map_draw_gdk_tracks(pMap, pPixmap, pRenderMetrics);
 	}
 
 	// 3. Labels
@@ -91,6 +93,61 @@
 	TIMER_END(maptimer, "END RENDER MAP (gdk)");
 }
 
+static void map_draw_gdk_tracks(map_t* pMap, GdkPixmap* pPixmap, rendermetrics_t* pRenderMetrics)
+{
+	gint i;
+	for(i=0 ; i<pMap->m_pTracksArray->len ; i++) {
+		gint hTrack = g_array_index(pMap->m_pTracksArray, gint, i);
+
+		GdkColor clr;
+		clr.red = (gint)(0.5 * 65535.0);
+		clr.green = (gint)(0.5 * 65535.0);
+		clr.blue = (gint)(1.0 * 65535.0);
+		gdk_gc_set_rgb_fg_color(pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)], &clr);
+
+		pointstring_t* pPointString = track_get_pointstring(hTrack);
+		if(pPointString == NULL) continue;
+
+		if(pPointString->m_pPointsArray->len >= 2) {
+			GdkPoint aPoints[MAX_GDK_LINE_SEGMENTS];
+			gint nMaxX=G_MININT;
+			gint nMaxY=G_MININT;
+			gint nMinX=G_MAXINT;
+			gint nMinY=G_MAXINT;
+
+			if(pPointString->m_pPointsArray->len > MAX_GDK_LINE_SEGMENTS) {
+				g_warning("not drawing track with > %d segments\n", MAX_GDK_LINE_SEGMENTS);
+				continue;
+			}
+
+			gint iPoint;
+			for(iPoint=0 ; iPoint<pPointString->m_pPointsArray->len ; iPoint++) {
+				mappoint_t* pPoint = g_ptr_array_index(pPointString->m_pPointsArray, iPoint);
+
+				gint nX,nY;
+				nX = (gint)SCALE_X(pRenderMetrics, pPoint->m_fLongitude);
+				nY = (gint)SCALE_Y(pRenderMetrics, pPoint->m_fLatitude);
+
+				// find extents
+				nMaxX = max(nX,nMaxX);
+				nMinX = min(nX,nMinX);
+				nMaxY = max(nY,nMaxY);
+				nMinY = min(nY,nMinY);
+
+				aPoints[iPoint].x = nX;
+				aPoints[iPoint].y = nY;
+			}
+
+			// overlap test
+			if(nMaxX < 0 || nMaxY < 0 || nMinX > pRenderMetrics->m_nWindowWidth || nMinY > pRenderMetrics->m_nWindowHeight) {
+				continue;
+			}
+
+			gdk_draw_lines(pPixmap, pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)], aPoints, pPointString->m_pPointsArray->len);
+   		}
+	}
+}
+
 static void map_draw_gdk_layer_polygons(map_t* pMap, GdkPixmap* pPixmap, rendermetrics_t* pRenderMetrics, GPtrArray* pPointStringsArray, sublayerstyle_t* pSubLayerStyle, textlabelstyle_t* pLabelStyle)
 {
 	mappoint_t* pPoint;
@@ -207,7 +264,7 @@
 		gint nMaxY=G_MININT;
 		gint nMinX=G_MAXINT;
 		gint nMinY=G_MAXINT;
-	
+
 		if(pPointString->m_pPointsArray->len >= 2) {
 			GdkPoint aPoints[MAX_GDK_LINE_SEGMENTS];
 

Index: search_road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search_road.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- search_road.c	10 Mar 2005 06:12:03 -0000	1.14
+++ search_road.c	20 Mar 2005 10:57:05 -0000	1.15
@@ -50,7 +50,7 @@
 #define ROAD_MIN_LENGTH_FOR_WILDCARD_SEARCH	(3)
 
 // if glib < 2.6
-#if ((GLIB_MAJOR_VERSION < 2) || ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 6)))
+#if(!GLIB_CHECK_VERSION(2,6,0))
 gint g_strv_length(const gchar** a)
 {
 	gint nCount=0;

Index: track.c
===================================================================
RCS file: /cvs/cairo/roadster/src/track.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- track.c	13 Mar 2005 19:11:57 -0000	1.4
+++ track.c	20 Mar 2005 10:57:05 -0000	1.5
@@ -66,7 +66,7 @@
 
 void track_add_point(gint nTrackID, const mappoint_t *pPoint)
 {
-	g_print("adding point to track %d\n", nTrackID);
+//	g_print("adding point to track %d\n", nTrackID);
 
 	track_t* pTrack = g_hash_table_lookup(g_Tracks.m_pTracksHash, &nTrackID);
 	if(pTrack == NULL) {




More information about the cairo-commit mailing list