summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan McIntosh <ian_mcintosh@linuxadvocate.org>2005-03-08 12:40:48 +0000
committerIan McIntosh <ian_mcintosh@linuxadvocate.org>2005-03-08 12:40:48 +0000
commitae7006b9fdb457c2e5635b6884eb5e45368a0c11 (patch)
tree9da50fae298be26109081279fcf0216dcdda7dd0
parent684549f187ce5d88260582aeb0b396677d09e773 (diff)
Added.
location code moved to location.c. Code cleanup. Implement using GdkRegion to prevent overlapping labels. Add new scenemanager calls.
-rw-r--r--ChangeLog10
-rw-r--r--data/layers.xml12
-rw-r--r--src/Makefile.am1
-rw-r--r--src/location.c62
-rw-r--r--src/location.h40
-rw-r--r--src/locationset.c152
-rw-r--r--src/locationset.h7
-rw-r--r--src/mainwindow.c2
-rw-r--r--src/map_draw_cairo.c12
-rw-r--r--src/scenemanager.c58
-rw-r--r--src/scenemanager.h12
11 files changed, 234 insertions, 134 deletions
diff --git a/ChangeLog b/ChangeLog
index abdd32b..6ae7aef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,17 @@
+2005-03-08 Ian McIntosh <ian_mcintosh@linuxadvocate.org>
+
+ * src/location.c:
+ * src/location.h: Added.
+ * src/locationset.c: location code moved to location.c. Code cleanup.
+ * src/scenemanager.c: Implement using GdkRegion to prevent overlapping labels.
+ * src/map_draw_cairo.c: Add new scenemanager calls.
+
2005-03-07 Ian McIntosh <ian_mcintosh@linuxadvocate.org>
* src/prefs.c:
* src/prefs.h: Added. (Not currently used.)
* src/main.c: Add init for prefs.
- * src/mainwindow.c: Squelch redraw user drags 0 distance.
+ * src/mainwindow.c: Squelch redraw if user drags 0 distance.
2005-03-07 Ian McIntosh <ian_mcintosh@linuxadvocate.org>
diff --git a/data/layers.xml b/data/layers.xml
index 8fed1ef..549ae1b 100644
--- a/data/layers.xml
+++ b/data/layers.xml
@@ -226,12 +226,12 @@
<layer name="rivers">
<sublayer>
- <property name="width" level="5" value="1.0" />
- <property name="width" level="6" value="4.0" />
- <property name="width" level="7" value="6.0" />
- <property name="width" level="8" value="10.0" />
- <property name="width" level="9" value="14.0" />
- <property name="width" level="10" value="18.0" />
+ <property name="width" level="5" value="3.0" />
+ <property name="width" level="6" value="3.0" />
+ <property name="width" level="7" value="3.0" />
+ <property name="width" level="8" value="3.0" />
+ <property name="width" level="9" value="6.0" />
+ <property name="width" level="10" value="8.0" />
<property name="color" value="#C2C0F8ff" />
<property name="join-style" value="round" />
<property name="cap-style" value="round" />
diff --git a/src/Makefile.am b/src/Makefile.am
index aa6306d..5c89a28 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,7 @@ roadster_SOURCES = \
datasetwindow.c\
welcomewindow.c\
gpsclient.c\
+ location.c\
locationset.c\
searchwindow.c\
search_road.c\
diff --git a/src/location.c b/src/location.c
new file mode 100644
index 0000000..cf05f54
--- /dev/null
+++ b/src/location.c
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * location.c
+ *
+ * Copyright 2005 Ian McIntosh
+ * ian_mcintosh@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 "map.h"
+#include "location.h"
+
+struct {
+ GMemChunk* m_pLocationChunkAllocator;
+} g_Location;
+
+void location_init()
+{
+ g_Location.m_pLocationChunkAllocator = g_mem_chunk_new("location chunk allocator",
+ sizeof(location_t), 1000, G_ALLOC_AND_FREE);
+ g_return_if_fail(g_Location.m_pLocationChunkAllocator != NULL);
+}
+
+// get a new point struct from the allocator
+gboolean location_new(location_t** ppLocation)
+{
+ g_return_val_if_fail(ppLocation != NULL, FALSE);
+ g_return_val_if_fail(*ppLocation == NULL, FALSE); // must be a pointer to a NULL pointer
+ g_return_val_if_fail(g_Location.m_pLocationChunkAllocator != NULL, FALSE);
+
+ location_t* pNew = g_mem_chunk_alloc0(g_Location.m_pLocationChunkAllocator);
+ if(pNew) {
+ *ppLocation = pNew;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// return a location_t struct to the allocator
+void location_free(location_t* pLocation)
+{
+ g_return_if_fail(pLocation != NULL);
+ g_return_if_fail(g_Location.m_pLocationChunkAllocator != NULL);
+
+ // give back to allocator
+ g_mem_chunk_free(g_Location.m_pLocationChunkAllocator, pLocation);
+}
diff --git a/src/location.h b/src/location.h
new file mode 100644
index 0000000..b95d41b
--- /dev/null
+++ b/src/location.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * location.h
+ *
+ * Copyright 2005 Ian McIntosh
+ * ian_mcintosh@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 _LOCATION_H
+#define _LOCATION_H
+
+#include "map.h"
+
+G_BEGIN_DECLS
+
+// a single location (eg. "Someday Cafe")
+typedef struct location {
+ gint m_nID;
+ gchar* m_pszName;
+ mappoint_t m_Coordinates;
+} location_t;
+
+G_END_DECLS
+
+#endif /* _LOCATION_H */
diff --git a/src/locationset.c b/src/locationset.c
index 7668fe6..6dc19e7 100644
--- a/src/locationset.c
+++ b/src/locationset.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <gtk/gtk.h>
+#include "location.h"
#include "locationset.h"
#include "db.h"
#include "util.h"
@@ -34,7 +35,6 @@ struct {
GPtrArray* m_pLocationSetArray; // an array of locationsets
GHashTable* m_pLocationSetHash; // stores pointers to locationsets, indexed by ID
- GMemChunk* m_pLocationChunkAllocator; // allocs location_t objects
GMemChunk* m_pLocationSetChunkAllocator; // allocs locationset_t objects
} g_LocationSet;
@@ -43,50 +43,21 @@ void locationset_init()
g_LocationSet.m_pLocationSetArray = g_ptr_array_new();
g_LocationSet.m_pLocationSetHash = g_hash_table_new(g_int_hash, g_int_equal);
- // create memory allocators
- g_LocationSet.m_pLocationChunkAllocator = g_mem_chunk_new("location chunk allocator",
- sizeof(location_t), 1000, G_ALLOC_AND_FREE);
- g_return_if_fail(g_LocationSet.m_pLocationChunkAllocator != NULL);
-
+ // create memory allocator
g_LocationSet.m_pLocationSetChunkAllocator = g_mem_chunk_new("locationset chunk allocator",
sizeof(locationset_t), 1000, G_ALLOC_AND_FREE);
g_return_if_fail(g_LocationSet.m_pLocationSetChunkAllocator != NULL);
}
-// get a new point struct from the allocator
-static gboolean locationset_util_new_location(location_t** ppLocation)
-{
- g_return_val_if_fail(ppLocation != NULL, FALSE);
- g_return_val_if_fail(*ppLocation == NULL, FALSE); // must be a pointer to a NULL pointer
- g_return_val_if_fail(g_LocationSet.m_pLocationChunkAllocator != NULL, FALSE);
-
- location_t* pNew = g_mem_chunk_alloc0(g_LocationSet.m_pLocationChunkAllocator);
- if(pNew) {
- *ppLocation = pNew;
- return TRUE;
- }
- return FALSE;
-}
-
-// return a point struct to the allocator
-static void locationset_util_free_location(location_t* pLocation)
-{
- g_return_if_fail(pLocation != NULL);
- g_return_if_fail(g_LocationSet.m_pLocationChunkAllocator != NULL);
-
- // give back to allocator
- g_mem_chunk_free(g_LocationSet.m_pLocationChunkAllocator, pLocation);
-}
-
// get a new locationset struct from the allocator
-static locationset_t* locationset_util_new_locationset(void)
+static locationset_t* locationset_new(void)
{
g_return_val_if_fail(g_LocationSet.m_pLocationSetChunkAllocator != NULL, NULL);
return g_mem_chunk_alloc0(g_LocationSet.m_pLocationSetChunkAllocator);
}
-static void locationset_util_clear_locationset(locationset_t* pLocationSet)
+static void locationset_clear(locationset_t* pLocationSet)
{
g_return_if_fail(pLocationSet != NULL);
g_return_if_fail(g_LocationSet.m_pLocationSetChunkAllocator != NULL);
@@ -95,20 +66,18 @@ static void locationset_util_clear_locationset(locationset_t* pLocationSet)
gint i;
for(i=((pLocationSet->m_pLocationsArray->len)-1) ; i>=0 ; i--) {
location_t* pLocation = g_ptr_array_remove_index_fast(pLocationSet->m_pLocationsArray, i);
- locationset_util_free_location(pLocation);
+ location_free(pLocation);
}
}
// return a locationset struct (and all locations) to the allocator
-#if 0
-static void locationset_util_free_locationset(locationset_t* pLocationSet)
+static void locationset_free(locationset_t* pLocationSet)
{
- locationset_util_clear_locationset(pLocationSet);
+ locationset_clear(pLocationSet);
// give back to allocator
g_mem_chunk_free(g_LocationSet.m_pLocationSetChunkAllocator, pLocationSet);
}
-#endif
static void locationset_clear_all_locations(void)
{
@@ -116,7 +85,7 @@ static void locationset_clear_all_locations(void)
gint i;
for(i=(g_LocationSet.m_pLocationSetArray->len)-1 ; i>=0 ; i--) {
locationset_t* pLocationSet = g_ptr_array_index(g_LocationSet.m_pLocationSetArray, i);
- locationset_util_clear_locationset(pLocationSet);
+ locationset_clear(pLocationSet);
}
// g_hash_table_foreach_steal(g_LocationSet.m_pLocationSets, callback_delete_pointset, NULL);
// g_assert(g_hash_table_size(g_LocationSet.m_pLocationSets) == 0);
@@ -131,11 +100,11 @@ void locationset_load_locationsets()
db_row_t aRow;
while((aRow = db_fetch_row(pResultSet))) {
- locationset_t* pNewLocationSet = locationset_util_new_locationset();
+ locationset_t* pNewLocationSet = locationset_new();
pNewLocationSet->m_nID = atoi(aRow[0]);
pNewLocationSet->m_pszName = g_strdup(aRow[1]);
- pNewLocationSet->m_pLocationsArray = g_ptr_array_new();
+ //pNewLocationSet->m_pLocationsArray = g_ptr_array_new();
// Add the new set to both data structures
g_ptr_array_add(g_LocationSet.m_pLocationSetArray, pNewLocationSet);
@@ -152,58 +121,6 @@ const GPtrArray* locationset_get_set_array()
return g_LocationSet.m_pLocationSetArray;
}
-/**************************************************************
-** PointSets
-***************************************************************/
-
-#if 0
-gboolean db_pointset_insert(const gchar* pszName, gint* pReturnID)
-{
- if(!db_is_connected()) return FALSE;
- g_assert(pszName != NULL);
- g_assert(pReturnID != NULL);
-
- // create query SQL
- gchar azQuery[MAX_SQLBUFFER_LEN];
- gchar* pszEscapedName = db_make_escaped_string(pszName);
- g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "INSERT INTO %s SET ID=NULL, Name='%s';", DB_LOCATIONSETS_TABLENAME, pszEscapedName);
- db_free_escaped_string(pszEscapedName);
-
- // run query
- if(!db_query(azQuery, NULL)) {
- return FALSE;
- }
- // return the new ID
- *pReturnID = db_insert_id();
- return TRUE;
-}
-#endif
-
-#if 0
-gboolean db_pointset_delete(gint nPointSetID)
-{
- if(!db_is_connected(g_pDB)) return FALSE;
-
- gchar azQuery[MAX_SQLBUFFER_LEN];
- g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "DELETE FROM %s WHERE ID=%d;", DB_LOCATIONSETS_TABLENAME, nPointSetID);
- if(MYSQL_RESULT_SUCCESS != mysql_query(g_pDB->m_pMySQLConnection, azQuery)) {
- g_warning("db_pointset_delete: deleting pointset failed: %s (SQL: %s)\n", mysql_error(g_pDB->m_pMySQLConnection), azQuery);
- return FALSE;
- }
-
- g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "DELETE FROM %s WHERE LocationSetID=%d;", DB_LOCATIONS_TABLENAME, nPointSetID);
- if(MYSQL_RESULT_SUCCESS != mysql_query(g_pDB->m_pMySQLConnection, azQuery)) {
- g_warning("db_pointset_delete: deleting points failed: %s (SQL: %s)\n", mysql_error(g_pDB->m_pMySQLConnection), azQuery);
- return FALSE;
- }
- return TRUE;
-}
-#endif
-
-/**************************************************************
-** Points
-***************************************************************/
-
gboolean locationset_add_location(gint nLocationSetID, mappoint_t* pPoint, gint* pReturnID)
{
g_assert(pPoint != NULL);
@@ -307,7 +224,7 @@ gboolean locationset_load_locations(maprect_t* pRect)
// if found (and it should be, at least once we filter by SetID in the SQL above)
// allocate a new location_t and add it to the set
location_t* pNewLocation = NULL;
- if(locationset_util_new_location(&pNewLocation)) {
+ if(location_new(&pNewLocation)) {
pNewLocation->m_nID = nLocationID;
db_parse_point(aRow[2], &pNewLocation->m_Coordinates);
g_ptr_array_add(pLocationSet->m_pLocationsArray, pNewLocation);
@@ -328,7 +245,51 @@ gboolean locationset_load_locations(maprect_t* pRect)
return FALSE;
}
-#if 0
+/**************************************************************
+** PointSets
+***************************************************************/
+
+#ifdef ROADSTER_DEAD_CODE
+/*
+gboolean db_pointset_insert(const gchar* pszName, gint* pReturnID)
+{
+ if(!db_is_connected()) return FALSE;
+ g_assert(pszName != NULL);
+ g_assert(pReturnID != NULL);
+
+ // create query SQL
+ gchar azQuery[MAX_SQLBUFFER_LEN];
+ gchar* pszEscapedName = db_make_escaped_string(pszName);
+ g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "INSERT INTO %s SET ID=NULL, Name='%s';", DB_LOCATIONSETS_TABLENAME, pszEscapedName);
+ db_free_escaped_string(pszEscapedName);
+
+ // run query
+ if(!db_query(azQuery, NULL)) {
+ return FALSE;
+ }
+ // return the new ID
+ *pReturnID = db_insert_id();
+ return TRUE;
+}
+gboolean db_pointset_delete(gint nPointSetID)
+{
+ if(!db_is_connected(g_pDB)) return FALSE;
+
+ gchar azQuery[MAX_SQLBUFFER_LEN];
+ g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "DELETE FROM %s WHERE ID=%d;", DB_LOCATIONSETS_TABLENAME, nPointSetID);
+ if(MYSQL_RESULT_SUCCESS != mysql_query(g_pDB->m_pMySQLConnection, azQuery)) {
+ g_warning("db_pointset_delete: deleting pointset failed: %s (SQL: %s)\n", mysql_error(g_pDB->m_pMySQLConnection), azQuery);
+ return FALSE;
+ }
+
+ g_snprintf(azQuery, MAX_SQLBUFFER_LEN, "DELETE FROM %s WHERE LocationSetID=%d;", DB_LOCATIONS_TABLENAME, nPointSetID);
+ if(MYSQL_RESULT_SUCCESS != mysql_query(g_pDB->m_pMySQLConnection, azQuery)) {
+ g_warning("db_pointset_delete: deleting points failed: %s (SQL: %s)\n", mysql_error(g_pDB->m_pMySQLConnection), azQuery);
+ return FALSE;
+ }
+ return TRUE;
+}
+
gboolean db_point_delete(gint nPointID)
{
if(!db_is_connected()) return FALSE;
@@ -342,4 +303,5 @@ gboolean db_point_delete(gint nPointID)
}
return TRUE;
}
+*/
#endif
diff --git a/src/locationset.h b/src/locationset.h
index 23df324..baa5dbd 100644
--- a/src/locationset.h
+++ b/src/locationset.h
@@ -33,13 +33,6 @@ typedef struct locationsetstyle {
int a;
} locationsetstyle_t;
-// a single location (eg. "Someday Cafe")
-typedef struct location {
- gint m_nID;
- gchar* m_pszName;
- mappoint_t m_Coordinates;
-} location_t;
-
// a set of locations (eg. "Coffee Shops")
typedef struct locationset {
gint m_nID;
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 51a4fc4..27b58e5 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -578,7 +578,7 @@ void mainwindow_on_aboutmenuitem_activate(GtkMenuItem *menuitem, gpointer user_d
const gchar *ppAuthors[] = {
"Ian McIntosh <ian_mcintosh@linuxadvocate.org>",
"Nathan Fredrickson <nathan@silverorange.com>",
- NULL
+ NULL
};
GtkWidget *pAboutWindow = gnome_about_new(
diff --git a/src/map_draw_cairo.c b/src/map_draw_cairo.c
index 952608e..331377b 100644
--- a/src/map_draw_cairo.c
+++ b/src/map_draw_cairo.c
@@ -41,6 +41,7 @@
#include "road.h"
#include "point.h"
#include "layers.h"
+#include "location.h"
#include "locationset.h"
#include "scenemanager.h"
@@ -150,7 +151,7 @@ static void map_draw_cairo_line_label(map_t* pMap, cairo_t *pCairo, textlabelsty
gfloat fFontSize = pLabelStyle->m_afFontSizeAtZoomLevel[pRenderMetrics->m_nZoomLevel-1];
if(fFontSize == 0) return;
- if(!scenemanager_can_draw_label(pMap->m_pSceneManager, pszLabel)) {
+ if(!scenemanager_can_draw_label_at(pMap->m_pSceneManager, pszLabel, NULL)) {
//g_print("dup label: %s\n", pszLabel);
return;
}
@@ -389,10 +390,12 @@ static void map_draw_cairo_line_label(map_t* pMap, cairo_t *pCairo, textlabelsty
cairo_show_text(pCairo, azLabelSegment);
//cairo_fill(pCairo);
cairo_restore(pCairo);
+
+ // scenemanager_claim_polygon(pMap->m_pSceneManager, GdkPoint *pPoints, gint nNumPoints);
}
cairo_restore(pCairo);
- scenemanager_label_drawn(pMap->m_pSceneManager, pszLabel);
+ scenemanager_claim_label(pMap->m_pSceneManager, pszLabel);
}
void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, textlabelstyle_t* pLabelStyle, rendermetrics_t* pRenderMetrics, pointstring_t* pPointString, const gchar* pszLabel)
@@ -405,7 +408,7 @@ void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, textlabelstyle_t
gdouble fAlpha = pLabelStyle->m_clrColor.m_fAlpha;
if(fAlpha == 0.0) return;
- if(!scenemanager_can_draw_label(pMap->m_pSceneManager, pszLabel)) {
+ if(!scenemanager_can_draw_label_at(pMap->m_pSceneManager, pszLabel, NULL)) {
//g_print("dup label: %s\n", pszLabel);
return;
}
@@ -488,9 +491,10 @@ void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, textlabelstyle_t
}
cairo_show_text(pCairo, pszLabel);
//cairo_fill(pCairo);
+// scenemanager_claim_polygon(pMap->m_pSceneManager, GdkPoint *pPoints, gint nNumPoints);
cairo_restore(pCairo);
- scenemanager_label_drawn(pMap->m_pSceneManager, pszLabel);
+ scenemanager_claim_label(pMap->m_pSceneManager, pszLabel);
}
#define CROSSHAIR_LINE_RELIEF (6)
diff --git a/src/scenemanager.c b/src/scenemanager.c
index 549644b..d400bc0 100644
--- a/src/scenemanager.c
+++ b/src/scenemanager.c
@@ -41,44 +41,70 @@ void scenemanager_init(void)
void scenemanager_new(scenemanager_t** ppReturn)
{
+ // create new scenemanager and return it
scenemanager_t* pNew = g_new0(scenemanager_t, 1);
pNew->m_pLabelHash = g_hash_table_new(g_str_hash, g_str_equal);
+ pNew->m_pTakenRegion = gdk_region_new();
*ppReturn = pNew;
}
-gboolean scenemanager_can_draw_label(scenemanager_t* pSceneManager, const gchar* pszLabel)
+gboolean scenemanager_can_draw_label_at(scenemanager_t* pSceneManager, const gchar* pszLabel, GdkPoint* pScreenLocation)
{
g_assert(pSceneManager != NULL);
+ g_assert(pszLabel != NULL);
+
+ // g_assert(pScreenLocation != NULL);
+ // NOTE: ignore pScreenLocation for now
- gpointer pKey;
- gpointer pValue;
+ gpointer pKey, pValue;
- // can draw if it doesn't exist in table
- gboolean bOK = (g_hash_table_lookup_extended(pSceneManager->m_pLabelHash,
- pszLabel, &pKey, &pValue) == FALSE);
+ // Can draw if it doesn't exist in table
+ return (FALSE == g_hash_table_lookup_extended(pSceneManager->m_pLabelHash, pszLabel, &pKey, &pValue));
+}
+
+gboolean scenemanager_can_draw_polygon(scenemanager_t* pSceneManager, GdkPoint *pPoints, gint nNumPoints)
+{
+ GdkRegion* pNewRegion = gdk_region_polygon(pPoints, nNumPoints, GDK_WINDING_RULE);
+
+ // Set pNewRegion to the intersection of it and the 'taken region'
+ gdk_region_intersect(pNewRegion, pSceneManager->m_pTakenRegion);
+ gboolean bOK = gdk_region_empty(pNewRegion); // it's ok to draw here if the intersection is empty
+ gdk_region_destroy(pNewRegion);
-// g_print("permission for %s: %s\n", pszLabel, bOK ? "YES" : "NO");
return bOK;
}
-void scenemanager_label_drawn(scenemanager_t* pSceneManager, const gchar* pszLabel)
+void scenemanager_claim_label(scenemanager_t* pSceneManager, const gchar* pszLabel)
{
g_assert(pSceneManager != NULL);
-// g_print("drawn! %s\n", pszLabel);
+
+ // Just putting the label into the hash is enough
g_hash_table_insert(pSceneManager->m_pLabelHash, pszLabel, NULL);
}
+void scenemanager_claim_polygon(scenemanager_t* pSceneManager, GdkPoint *pPoints, gint nNumPoints)
+{
+ // Create a GdkRegion from the given points and union it with the 'taken region'
+ GdkRegion* pNewRegion = gdk_region_polygon(pPoints, nNumPoints, GDK_WINDING_RULE);
+ gdk_region_union(pSceneManager->m_pTakenRegion, pNewRegion);
+ gdk_region_destroy(pNewRegion);
+}
+
+void scenemanager_claim_rectangle(scenemanager_t* pSceneManager, GdkRectangle* pRect)
+{
+ // Add the area of the rectangle to the region
+ gdk_region_union_with_rect(pSceneManager->m_pTakenRegion, pRect);
+}
+
void scenemanager_clear(scenemanager_t* pSceneManager)
{
g_assert(pSceneManager != NULL);
+ // destroy and recreate hash table (better way to clear it?)
g_hash_table_destroy(pSceneManager->m_pLabelHash);
pSceneManager->m_pLabelHash = g_hash_table_new(g_str_hash, g_str_equal);
-}
-
-#if ROADSTER_DEAD_CODE
-static void scenemanager_add_label_line(geometryset_t* pGeometry, gchar* pszLabel) {}
-static void scenemanager_add_label_polygon(geometryset_t* pGeometry, gchar* pszLabel) {}
-static void scenemanager_draw(void) {}
-#endif /* ROADSTER_DEAD_CODE */
+ // Empty the region (better way?)
+ gdk_region_destroy(pSceneManager->m_pTakenRegion);
+ pSceneManager->m_pTakenRegion = gdk_region_new();
+}
diff --git a/src/scenemanager.h b/src/scenemanager.h
index 5f382b8..f18b194 100644
--- a/src/scenemanager.h
+++ b/src/scenemanager.h
@@ -25,16 +25,20 @@
#define _SCENEMANAGER_H_
typedef struct scenemanager {
- GPtrArray* m_p;
+ GdkRegion* m_pTakenRegion;
+
GHashTable* m_pLabelHash;
} scenemanager_t;
void scenemanager_init(void);
void scenemanager_new(scenemanager_t** ppReturn);
-gboolean scenemanager_can_draw_label(scenemanager_t* pSceneManager, const gchar* pszLabel);
-void scenemanager_label_drawn(scenemanager_t* pSceneManager, const gchar* pszLabel);
-void scenemanager_clear(scenemanager_t* pSceneManager);
+gboolean scenemanager_can_draw_label_at(scenemanager_t* pSceneManager, const gchar* pszLabel, GdkPoint* pScreenLocation);
+gboolean scenemanager_can_draw_polygon(scenemanager_t* pSceneManager, GdkPoint *pPoints, gint nNumPoints);
+void scenemanager_claim_label(scenemanager_t* pSceneManager, const gchar* pszLabel);
+void scenemanager_claim_polygon(scenemanager_t* pSceneManager, GdkPoint *pPoints, gint nNumPoints);
+void scenemanager_claim_rectangle(scenemanager_t* pSceneManager, GdkRectangle* pRect);
+void scenemanager_clear(scenemanager_t* pSceneManager);
#endif