[cairo-commit] roadster/src main.c, 1.2, 1.3 map.c, 1.6, 1.7 scenemanager.c, 1.3, 1.4

Ian McIntosh commit at pdx.freedesktop.org
Tue Feb 22 17:44:42 PST 2005


Committed by: ian

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

Modified Files:
	main.c map.c scenemanager.c 
Log Message:
        * main.c: Added call to init scenemanager.
        * scenemanager.c: Added quasi-hack to prevent road/label names from showing up twice on one screen.
        * map.c: Request permission from scenemanager before drawing a label.


Index: main.c
===================================================================
RCS file: /cvs/cairo/roadster/src/main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- main.c	20 Feb 2005 14:58:46 -0000	1.2
+++ main.c	23 Feb 2005 01:44:39 -0000	1.3
@@ -34,6 +34,7 @@
 #include "../include/import.h"
 #include "../include/gpsclient.h"
 #include "../include/locationset.h"
+#include "../include/scenemanager.h"
 
 int main (int argc, char *argv[])
 {
@@ -47,6 +48,7 @@
 	/*
 	** init our modules
 	*/
+	scenemanager_init();
 	geometryset_init();
 	locationset_init();
 	gpsclient_init();

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- map.c	22 Feb 2005 17:33:14 -0000	1.6
+++ map.c	23 Feb 2005 01:44:39 -0000	1.7
@@ -36,6 +36,7 @@
 #include "../include/db.h"
 #include "../include/layers.h"
 #include "../include/locationset.h"
+#include "../include/scenemanager.h"
 
 // 4,382,755 inches per degree
 // 363 inches of world represented in 3.63 inches
@@ -482,6 +483,11 @@
 	gfloat fFontSize = pLabelStyle->m_afFontSizeAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
 	if(fFontSize == 0) return;
 
+	if(!scenemanager_can_draw_label(pszLabel)) {
+		//g_print("dup label: %s\n", pszLabel);
+		return;
+	}
+
 	mappoint_t* apPoints[ROAD_MAX_SEGMENTS];
 	gint nNumPoints = pPointString->m_pPointsArray->len;
 
@@ -529,8 +535,10 @@
 		fTotalLineLength += fLineLength;
 	}
 
+	gchar* pszFontFamily = "Bitstream Vera Sans";
+
 	cairo_save(pCairo);
-	cairo_select_font(pCairo, "Monospace",
+	cairo_select_font(pCairo, pszFontFamily,
 						CAIRO_FONT_SLANT_NORMAL,
 						pLabelStyle->m_abBoldAtZoomLevel[pRenderMetrics->m_nZoomLevel-1] ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
 	cairo_scale_font(pCairo, fFontSize);	
@@ -700,6 +708,8 @@
 				cairo_save(pCairo);
 					cairo_set_line_width(pCairo, 4);
 					cairo_set_rgb_color(pCairo, 1.0,1.0,1.0);
+					cairo_set_line_join(pCairo, CAIRO_LINE_JOIN_BEVEL);
+					//cairo_set_miter_limit(pCairo, 0.1);
 					cairo_stroke(pCairo);
 				cairo_restore(pCairo);
 			}
@@ -707,6 +717,8 @@
 		cairo_restore(pCairo);
 	}
 	cairo_restore(pCairo);
+	
+	scenemanager_label_drawn(pszLabel);
 }
 
 void map_draw_polygon_label(cairo_t *pCairo, textlabelstyle_t* pLabelStyle, rendermetrics_t* pRenderMetrics, pointstring_t* pPointString, const gchar* pszLabel)
@@ -719,6 +731,11 @@
 	gdouble fAlpha = pLabelStyle->m_clrColor.m_fAlpha;
 	if(fAlpha == 0.0) return;
 
+	if(!scenemanager_can_draw_label(pszLabel)) {
+		//g_print("dup label: %s\n", pszLabel);
+		return;
+	}
+
 	gdouble fTotalX = 0.0;
 	gdouble fTotalY = 0.0;
 
@@ -756,9 +773,11 @@
 	gdouble fDrawX = fTotalX / pPointString->m_pPointsArray->len;
 	gdouble fDrawY = fTotalY / pPointString->m_pPointsArray->len;
 
+	gchar* pszFontFamily = "Bitstream Vera Sans";
+
 	cairo_save(pCairo);
 
-		cairo_select_font(pCairo, "Monospace",
+		cairo_select_font(pCairo, pszFontFamily,
 							CAIRO_FONT_SLANT_NORMAL,
 							pLabelStyle->m_abBoldAtZoomLevel[pRenderMetrics->m_nZoomLevel-1] ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
 		cairo_scale_font(pCairo, fFontSize);	
@@ -788,11 +807,15 @@
 			cairo_save(pCairo);
 				cairo_set_line_width(pCairo, 3);
 				cairo_set_rgb_color(pCairo, 1.0,1.0,1.0);
+				cairo_set_line_join(pCairo, CAIRO_LINE_JOIN_BEVEL);
+//				cairo_set_miter_limit(pCairo, 0.1);
 				cairo_stroke(pCairo);
 			cairo_restore(pCairo);
 		}
 		cairo_fill(pCairo);
 	cairo_restore(pCairo);
+	
+	scenemanager_label_drawn(pszLabel);
 }
 // g_print("map (%f,%f)->(%f,%f) screen (%f,%f)->(%f,%f) center (%f,%f)\n",pMapPoint1->m_fLatitude,pMapPoint1->m_fLongitude,  pMapPoint2->m_fLatitude,pMapPoint2->m_fLongitude,  fX1,fY1,  fX2,fY2,  fX,fY);
 		// Calculate line length (in screen pixels)
@@ -932,6 +955,8 @@
 	map_get_render_metrics(&renderMetrics);
 	rendermetrics_t* pRenderMetrics = &renderMetrics;
 
+	scenemanager_clear();
+
 	//
 	// Load geometry
 	//
@@ -1218,7 +1243,6 @@
 		pointstring_t* pPointString = g_ptr_array_index(pGeometry->m_pPointStringsArray, i);
 		
 		if(pPointString->m_pszName[0] != '\0') {
-			g_print("printing %s\n", pPointString->m_pszName);
 			map_draw_polygon_label(pCairo, pLabelStyle, pRenderMetrics, pPointString, pPointString->m_pszName);
 		}
 	}

Index: scenemanager.c
===================================================================
RCS file: /cvs/cairo/roadster/src/scenemanager.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- scenemanager.c	22 Feb 2005 17:12:27 -0000	1.3
+++ scenemanager.c	23 Feb 2005 01:44:39 -0000	1.4
@@ -46,6 +46,34 @@
 	g_SceneManager.m_pLabelHash = g_hash_table_new(g_str_hash, g_str_equal);
 }
 
+gboolean scenemanager_can_draw_label(const gchar* pszLabel)
+{
+	gpointer pKey;
+	gpointer pValue;
+
+	// can draw if it doesn't exist in table
+    gboolean bOK = (g_hash_table_lookup_extended(g_SceneManager.m_pLabelHash,
+                                        pszLabel,
+										&pKey, &pValue) == FALSE);
+
+//	g_print("permission for %s: %s\n", pszLabel, bOK ? "YES" : "NO");
+	return bOK;
+}
+
+void scenemanager_label_drawn(const gchar* pszLabel)
+{
+//	g_print("drawn! %s\n", pszLabel);
+	g_hash_table_insert(g_SceneManager.m_pLabelHash, pszLabel, NULL);
+}
+
+void scenemanager_clear(void)
+{
+	g_hash_table_destroy(g_SceneManager.m_pLabelHash);
+
+	scenemanager_init();
+}
+
+
 #if ROADSTER_DEAD_CODE
 static void scenemanager_add_label_line(geometryset_t* pGeometry, gchar* pszLabel)
 {
@@ -61,11 +89,4 @@
 {
 	
 }
-
-static void scenemanager_clear(void)
-{
-	g_hash_table_destroy(g_SceneManager.m_pLabelHash);
-
-	scenemanager_init();
-}
 #endif /* ROADSTER_DEAD_CODE */




More information about the cairo-commit mailing list