[cairo-commit] roadster/src Makefile.am, 1.13, 1.14 animator.c, 1.1, 1.2 db.c, 1.16, 1.17 gfreelist.c, NONE, 1.1 gfreelist.h, NONE, 1.1 gui.c, 1.6, 1.7 import.c, 1.7, 1.8 import_tiger.c, 1.13, 1.14 main.c, 1.15, 1.16 mainwindow.c, 1.26, 1.27 mainwindow.h, 1.9, 1.10 map.c, 1.28, 1.29 map.h, 1.7, 1.8 map_draw_cairo.c, 1.12, 1.13 point.c, 1.2, 1.3 pointstring.c, 1.3, 1.4 searchwindow.c, 1.13, 1.14

Ian McIntosh commit at pdx.freedesktop.org
Sat Mar 19 19:37:12 PST 2005


Committed by: ian

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

Modified Files:
	Makefile.am animator.c db.c gui.c import.c import_tiger.c 
	main.c mainwindow.c mainwindow.h map.c map.h map_draw_cairo.c 
	point.c pointstring.c searchwindow.c 
Added Files:
	gfreelist.c gfreelist.h 
Log Message:
	* src/gfreelist.h:
	* src/gfreelist.c: Added.
	* src/Makefile.am: Added gfreelist.c.
	* src/animator.c: Cleanup.
	* src/gui.c: Always show welcome window.
	* src/main.c: Remove gnome_program_init() and add gtk_init() and g_type_init().
	* src/mainwindow.c: Slide to search results, if close enough.
	* src/map.c: Add map_get_distance_in_pixels() and map_points_equal().
	* src/map.h: Limit zoomlevels to 6-10 for preview release.
	* src/map_draw_cairo.c: Add a little padding around labels.
	* src/point.c:
	* src/pointstring.c: Use gfreelist instead of gmemchunk.
	* src/searchwindow.c: Slide to results.
	* data/roadster.glade: Remove gnome widgets.  Change welcome window to explain preview release.


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/roadster/src/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Makefile.am	18 Mar 2005 08:37:35 -0000	1.13
+++ Makefile.am	20 Mar 2005 03:37:09 -0000	1.14
@@ -48,7 +48,8 @@
 	map_draw_gdk.c\
 	road.c\
 	prefs.c\
-	animator.c
+	animator.c\
+	gfreelist.c
 
 roadster_LDADD = \
 	$(GNOME_LIBS) \

Index: animator.c
===================================================================
RCS file: /cvs/cairo/roadster/src/animator.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- animator.c	18 Mar 2005 08:37:35 -0000	1.1
+++ animator.c	20 Mar 2005 03:37:09 -0000	1.2
@@ -37,6 +37,8 @@
 
 animator_t* animator_new(EAnimationType eAnimationType, gdouble fAnimationTimeInSeconds)
 {
+	g_assert(fAnimationTimeInSeconds > 0.0);
+
         animator_t* pNew = g_new0(animator_t, 1);
 
         pNew->m_pTimer = g_timer_new();
@@ -82,18 +84,14 @@
         g_assert(pAnimator != NULL);
 
 	gdouble fTimePercent = animator_get_time_percent(pAnimator);
-
-	// for now use a constant slide
-	gdouble fReturn;
-	 
-	// constant movement
-	//fReturn = fTimePercent;
-
+ 
 	// The formula for a parabola is:  y = Ax^2 + Bx + C
-	// Here, x is an input percentage (of time) from 0.0 to 1.0
-	// ...and y is an output percetange (distance) from 0.0 to 1.0
+	// x is an input percentage (of time) from 0.0 to 1.0
+	// y is an output percetange (distance) from 0.0 to 1.0
 
-	if(pAnimator->m_eAnimationType == ANIMATIONTYPE_SLIDE) {
+	gdouble fReturn;
+	switch(pAnimator->m_eAnimationType) {
+	case ANIMATIONTYPE_SLIDE:
 		// Slide - accelerate for the first half (standard upward facing parabola going from x=0 to x=0.5) 
 		if(fTimePercent < 0.5) {
 			// use parabola function y=2x^2 + 0x + 0
@@ -102,23 +100,26 @@
 		// Slide - decelerate for the last half (try graphing this with x instead of fTimePercent and y instead of fReturn) 
 		else {
 			// this meets up with the above equation at (0.5,0.5)
-			fReturn = 1.0 - (2.0 * (1.0 - fTimePercent) * (1.0 - fTimePercent));
+			fReturn = 1.0 - (2.0 * (1.0-fTimePercent) * (1.0-fTimePercent));
 		}
-	}
-	else if(pAnimator->m_eAnimationType == ANIMATIONTYPE_FAST_THEN_SLIDE) {
+		break;
+	case ANIMATIONTYPE_FAST_THEN_SLIDE:
 		if(fTimePercent < 0.5) {
 			// go 80% of the distance in half the time
+			// uses a simple 45 degree slope (constant-speed movement with no smooth acceration)
 			fReturn = (fTimePercent / 0.5) * 0.8;
 		}
 		else {
+			// (note: same as above)
 			fReturn = 1.0 - (2.0 * (1.0 - fTimePercent) * (1.0 - fTimePercent));
 
-			// compress it into last 10%
+			// compress it into last 20%
 			fReturn = (fReturn * 0.2) + 0.8;
 		}
-	}
-	else {
+		break;
+	default:
 		g_assert_not_reached();
+		break;
 	}
 
 	// Make 100% sure it's capped to 0.0 -> 1.0
@@ -126,81 +127,3 @@
 	fReturn = max(fReturn, 0.0);
 	return fReturn;
 }
-
-/*
-UINT CSequencer::SlideTo(UINT iFrame, ENTITY* pEntity, LONG nDestX, LONG nDestY, double fTripTime)
-{
-        RECT rcEntity;
-        
-        rcEntity = pEntity->rcDest;
-        
-        LONG nStartX = rcEntity.left;
-        LONG nStartY = rcEntity.top;
-        
-        // We want trips to take about 'tripTime' seconds.
-        //
-	gdouble fDeltaX = nDestX - nStartX;
-	gdouble fDeltaY = nDestY - nStartY;
-	gdouble fDistance = (LONG)sqrt((fDeltaX * fDeltaX) + (fDeltaY * fDeltaY));
-	fDistance = max( fDistance, 1.0 );
-
-        LONG cFrames = (LONG)(m_uTargetFPS * fTripTime);
-
-        // (avoid divide-by-zero problems)
-        //
-        dxy = max( dxy, 1 );
-        cFrames = max( cFrames, 1 );
-        
-        // Graceful movement is solved by the parabola:
-        //       y = (2*dxy*x*x)/(f*f) - (2*dxy*x)/(f) + (dxy)/(2)
-        // where y = distance from starting point
-        //   and x = frame number
-        //
-        // Find the coefficients (Ax^2 + Bx +C) of that formula.
-        //
-        double A =    ((double)(2 * dxy) / (cFrames * cFrames));
-        double B = 0 -((double)(2 * dxy) / (cFrames));
-	double C =    ((double)(    dxy) / (2));
-
-	// Perform the first half of the movement (where we're accelerating)
-	//
- 
-	LONG x, y;
-
-
-	for (LONG iMove = cFrames/2; iMove < cFrames; iMove++)
-    {
-		double percentMove = ((A * iMove * iMove) + (B * iMove) + C) / dxy;
-
-		x = nStartX + (LONG)( percentMove * dx );
-		y = nStartY + (LONG)( percentMove * dy );
-
-		MoveRectangle(&rcEntity, x,y);
-		
-		this->AddAction_MoveEntity(iFrame++, pEntity, rcEntity);
-	}
-
-    // Perform the second half of the movement (where we're decelerating)
-    //
-	for (iMove = 0; iMove < cFrames/2; iMove++)
-    {
-		double percentMove = 1.0 - (A * iMove * iMove + B * iMove + C) / dxy;
-
-		x = nStartX + (LONG)( percentMove * dx );
-		y = nStartY + (LONG)( percentMove * dy );
-
-		MoveRectangle(&rcEntity, x,y);
-
-		this->AddAction_MoveEntity(iFrame++, pEntity, rcEntity);
-	}
-
-	// Make sure they end up exactly where we told them to go
-	if(x != nDestX || y != nDestY) {
-		MoveRectangle(&rcEntity, x, y);
-
-		this->AddAction_MoveEntity(iFrame, pEntity, rcEntity);
-	}
-
-	return iFrame;
-}
-*/

Index: db.c
===================================================================
RCS file: /cvs/cairo/roadster/src/db.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- db.c	14 Mar 2005 02:04:30 -0000	1.16
+++ db.c	20 Mar 2005 03:37:09 -0000	1.17
@@ -21,6 +21,8 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#define USE_GNOME_VFS
+
 #include <mysql.h>
 
 #define HAVE_MYSQL_EMBED
@@ -33,7 +35,10 @@
 #include <gtk/gtk.h>
 #include <stdio.h>
 #include <string.h>
+
+#ifdef USE_GNOME_VFS
 #include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h>
+#endif
 
 #include "db.h"
 #include "mainwindow.h"
@@ -50,7 +55,7 @@
 //						better for embedded or local servers
 // mysql_store_result - more client memory, gets all results right away and frees up server
 //						better for remote servers
-#define MYSQL_GET_RESULT(x)		mysql_use_result((x))
+#define MYSQL_GET_RESULT(x)		mysql_store_result((x))
 
 db_connection_t* g_pDB = NULL;
 
@@ -70,10 +75,12 @@
 	gchar* pszSetQueryCacheSize = g_strdup_printf("--query-cache-size=%dMB", 40);
 	gchar* pszKeyBufferSize	= g_strdup_printf("--key-buffer-size=%dMB", 32);
 
+#ifdef USE_GNOME_VFS
 	// Create directory if it doesn't exist
 	if(GNOME_VFS_OK != gnome_vfs_make_directory(pszDataDir, 0700)) {
 		// no big deal, probably already exists (should we check?)
 	}
+#endif
 
 	gchar* apszServerOptions[] = {
 		"",	// program name -- unused

--- NEW FILE: gfreelist.c ---
/* GLIB - Library of useful routines for C programming
 *
 * Copyright (C) 2003 Soeren Sandmann (sandmann at daimi.au.dk)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#define G_IMPLEMENT_INLINES 1
#define __G_FREELIST_C__

#include "gfreelist.h"

#include <glib.h>

struct _GFreeListBlock
{
  GFreeListBlock *next;
  gint8 *data;
};
     
GFreeList *
g_free_list_new (gsize atom_size,
		 gint n_prealloc)
{
  GFreeList *list;

  g_return_val_if_fail (atom_size > 0, NULL);
  g_return_val_if_fail (n_prealloc > 0, NULL);

  list = g_new0 (GFreeList, 1);

  list->allocated = TRUE;
  list->atom_size = MAX (atom_size, sizeof (GFreeListAtom));
  list->n_prealloc = n_prealloc;
  list->atoms = NULL;
  list->blocks = NULL;
  
  return list;
}

static void
g_free_list_ensure_atoms (GFreeList *list)
{
  if (!list->atoms)
    {
      gint i;
#ifdef DISABLE_MEM_POOLS
      const int n_atoms = 1;
#else
      const int n_atoms = list->n_prealloc;
#endif
      
      GFreeListBlock *block = g_new (GFreeListBlock, 1);
      block->data = g_malloc (list->atom_size * n_atoms);
      block->next = list->blocks;
      list->blocks = block;

      for (i = n_atoms - 1; i >= 0; --i)
	{
	  GFreeListAtom *atom =
	    (GFreeListAtom *)(block->data + i * list->atom_size);

	  atom->next = list->atoms;
	  list->atoms = atom;
	}
    }
}

gpointer
g_free_list_alloc_internal (GFreeList *list)
{
  gpointer result;

  g_return_val_if_fail (list != NULL, NULL);
  
  if (!list->atoms)
    g_free_list_ensure_atoms (list);

  result = list->atoms;
  list->atoms = list->atoms->next;

  return result;
}

void
g_free_list_free_internal (GFreeList *list,
			   gpointer   mem)
{
  GFreeListAtom *atom;

  g_return_if_fail (list != NULL);

  if (!mem)
    return;
  
  atom = mem;
  
  atom->next = list->atoms;
  list->atoms = atom;
}

static void
g_free_list_free_all (GFreeList *list)
{
  GFreeListBlock *block;

  g_return_if_fail (list != NULL);

  block = list->blocks;
  while (block)
    {
      GFreeListBlock *next = block->next;

      g_free (block->data);
      g_free (block);
      
      block = next;
    }
  
  list->atoms = NULL;
  list->blocks = NULL;
}

void
g_free_list_destroy (GFreeList *list)
{
  g_return_if_fail (list != NULL);
  g_return_if_fail (list->allocated);

  g_free_list_free_all (list);
  g_free (list);
}

--- NEW FILE: gfreelist.h ---
/* GLIB - Library of useful routines for C programming
 *
 * Copyright (C) 2003 Soeren Sandmann (sandmann at daimi.au.dk)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __G_FREELIST_H__
#define __G_FREELIST_H__

#include <glib/gtypes.h>
#include <glib/gutils.h>

G_BEGIN_DECLS

typedef struct _GFreeList GFreeList;
typedef struct _GFreeListAtom GFreeListAtom;
typedef struct _GFreeListBlock GFreeListBlock;

struct _GFreeListAtom
{
  GFreeListAtom *next;    
};

struct _GFreeList
{
  /*< private >*/
  gboolean		allocated;
  gsize			atom_size;
  gint			n_prealloc;
  GFreeListAtom *	atoms;
  GFreeListBlock *	blocks;
};

#define G_FREE_LIST_NAME(name)						\
  g__ ## name ## __free_list

#define G_FREE_LIST_EXTERN(name)					\
  extern GFreeList G_FREE_LIST_NAME (name)

/* Defining free lists */
#define G_FREE_LIST_DEFINE(name, atom_size, n_prealloc)			\
  GFreeList G_FREE_LIST_NAME (name) =					\
  {									\
    FALSE,					/* allocated */		\
    MAX (atom_size, sizeof (GFreeListAtom)),	/* atom_size */		\
    n_prealloc,					/* n_prealloc */	\
    NULL,					/* atoms */		\
    NULL					/* blocks */		\
  }

#define G_FREE_LIST_DEFINE_STATIC(name, atom_size, n_prealloc)		\
  static G_FREE_LIST_DEFINE (name, atom_size, n_prealloc)

/* Macros to allocate and free atoms */
#define G_FREE_LIST_ALLOC(name)						\
  g_free_list_alloc (&G_FREE_LIST_NAME (name))

#define G_FREE_LIST_FREE(name, mem)					\
  g_free_list_free (&G_FREE_LIST_NAME (name), mem)


/* functions */
GFreeList *   g_free_list_new        (gsize      atom_size,
				      gint       n_prealloc);
void          g_free_list_destroy    (GFreeList *free_list);

G_INLINE_FUNC
gpointer      g_free_list_alloc      (GFreeList *list);

G_INLINE_FUNC
void          g_free_list_free       (GFreeList *list,
				      gpointer   mem);

/* internal functions */
gpointer g_free_list_alloc_internal (GFreeList *flist);
void     g_free_list_free_internal  (GFreeList *flist,
				     gpointer   mem);

/* inline functions */

#if defined (G_CAN_INLINE) || defined (__G_FREELIST_C__)

G_INLINE_FUNC gpointer
g_free_list_alloc (GFreeList *flist)
{
  GFreeListAtom *result = flist->atoms;

  if (G_LIKELY (result))
    flist->atoms = result->next;
  else
    result = g_free_list_alloc_internal (flist);

  return result;
}

G_INLINE_FUNC void
g_free_list_free (GFreeList *flist,
		  gpointer   mem)
{
  ((GFreeListAtom *)mem)->next = flist->atoms;
  flist->atoms = mem;
}

#endif /* G_CAN_INLINE || __G_FREELIST_C__ */

G_END_DECLS

#endif /* __G_FREELIST_H__ */

Index: gui.c
===================================================================
RCS file: /cvs/cairo/roadster/src/gui.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- gui.c	4 Mar 2005 09:27:26 -0000	1.6
+++ gui.c	20 Mar 2005 03:37:09 -0000	1.7
@@ -66,12 +66,12 @@
 
 void gui_run()
 {
-	if(db_is_empty()) {
+//	if(db_is_empty()) {
 		welcomewindow_show();
-	}
-	else {
-		mainwindow_show();
-	}
+//	}
+//	else {
+//		mainwindow_show();
+//	}
 	gtk_main();
 }
 

Index: import.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- import.c	26 Feb 2005 04:41:40 -0000	1.7
+++ import.c	20 Mar 2005 03:37:09 -0000	1.8
@@ -21,6 +21,8 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#define USE_GNOME_VFS
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -31,7 +33,9 @@
 #include "import_tiger.h"
 #include "db.h"
 
+#ifdef USE_GNOME_VFS
 #include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h>
+#endif
 
 #if ROADSTER_DEAD_CODE
 static void import_progress_pulse(void)
@@ -42,6 +46,7 @@
 
 gboolean import_from_uri(const gchar* pszURI)
 {
+#ifdef USE_GNOME_VFS
 	gboolean bResult = FALSE;
 
 	GnomeVFSFileInfo info;
@@ -83,4 +88,5 @@
 
 //	func_progress_callback(1.0, pCallbackData);
 	return bResult;
+#endif
 }

Index: import_tiger.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import_tiger.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- import_tiger.c	13 Mar 2005 19:11:57 -0000	1.13
+++ import_tiger.c	20 Mar 2005 03:37:09 -0000	1.14
@@ -22,11 +22,15 @@
  */
 
 // See TGR2003.PDF page 208 for county list
+#define USE_GNOME_VFS
 
 #include <stdlib.h>			// for strtod
 
 #include <string.h>
+
+#ifdef USE_GNOME_VFS
 #include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h>
+#endif
 
 #include "util.h"
 #include "import_tiger.h"
@@ -1035,6 +1039,7 @@
 
 gboolean import_tiger_from_uri(const gchar* pszURI, gint nTigerSetNumber)
 {
+#ifdef USE_GNOME_VFS
 	//g_print("pszURI = %s\n", pszURI);
 
 	importwindow_progress_pulse();
@@ -1088,10 +1093,12 @@
 	
 	g_free(pszTempDir);
 	return bSuccess;
+#endif
 }
 
 static gboolean import_tiger_from_directory(const gchar* pszDirectoryPath, gint nTigerSetNumber)
 {
+#ifdef USE_GNOME_VFS
 	g_print("import_tiger_from_directory\n");
 
 	gchar* pszFilePath;
@@ -1127,6 +1134,7 @@
 		g_free(apBuffers[i]); // can be null
 	}
 	return bSuccess;
+#endif
 }
 
 static gboolean import_tiger_from_buffers(

Index: main.c
===================================================================
RCS file: /cvs/cairo/roadster/src/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- main.c	18 Mar 2005 08:37:35 -0000	1.15
+++ main.c	20 Mar 2005 03:37:09 -0000	1.16
@@ -20,12 +20,13 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
+#define USE_GNOME_VFS
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-#include <gnome.h>
+#include <gtk/gtk.h>
 #include "gui.h"
 #include "db.h"
 #include "map.h"
@@ -44,13 +45,16 @@
 		textdomain(PACKAGE);
 	#endif
 
-	gnome_program_init(PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL);
+//	gnome_program_init(PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL);
+	gtk_init(&argc, &argv);
 
+	g_type_init();
 	if(!main_init())
 		return 1;
 
 	prefs_read();
 
+	g_print("Running in %s mode\n", g_thread_supported() ? "multi-threaded" : "single-threaded");
 	gui_run();
 	main_deinit();
 
@@ -59,10 +63,7 @@
 
 gboolean main_init(void)
 {
-	// Initialize GLib thread system
-	//g_thread_init(NULL);
-	//gdk_threads_init();
-
+#ifdef USE_GNOME_VFS
 	if(!gnome_vfs_init()) {	
 		g_warning("gnome_vfs_init failed\n");
 		return FALSE;
@@ -71,7 +72,7 @@
 	gchar* pszApplicationDir = g_strdup_printf("%s/.roadster", g_get_home_dir());
 	gnome_vfs_make_directory(pszApplicationDir, 0700);
 	g_free(pszApplicationDir);
-
+#endif
 	g_print("initializing prefs\n");
 	prefs_init();	// note: doesn't READ prefs yet
 

Index: mainwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mainwindow.c	18 Mar 2005 08:37:35 -0000	1.26
+++ mainwindow.c	20 Mar 2005 03:37:09 -0000	1.27
@@ -64,11 +64,13 @@
 #define DRAW_PRETTY_RESIZE_TIMEOUT_MS	(180)
 
 #define SCROLL_TIMEOUT_MS		(80)	// how often (in MS) to move
-#define SCROLL_DISTANCE_IN_PIXELS	(80)	// how far to move every (above) MS
+#define SCROLL_DISTANCE_IN_PIXELS	(70)	// how far to move every (above) MS
 #define BORDER_SCROLL_CLICK_TARGET_SIZE	(20)	// the size of the click target (distance from edge of map view) to begin scrolling
 
-#define SLIDE_TIMEOUT_MS		(90)	// time between frames (in MS) for smooth-sliding (on double click?)
-#define	SLIDE_TIME_IN_SECONDS		(1.2)	// how long the whole slide should take, in seconds
+#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)
 
 // Layerlist columns
 #define LAYERLIST_COLUMN_ENABLED	(0)
@@ -81,6 +83,8 @@
 // Settings
 #define TIMER_GPS_REDRAW_INTERVAL_MS	(2500)		// lower this (to 1?) when it's faster to redraw track
 
+#define MAX_DISTANCE_FOR_AUTO_SLIDE_IN_PIXELS	(3500.0)
+
 // Types
 typedef struct {
 	GdkCursorType m_CursorType;
@@ -1160,6 +1164,32 @@
 	mainwindow_statusbar_update_position();
 }
 
+void mainwindow_map_slide_to_mappoint(mappoint_t* pPoint)
+{
+	mappoint_t centerPoint;
+	map_get_centerpoint(g_MainWindow.m_pMap, &centerPoint);
+
+	if(map_points_equal(pPoint, &centerPoint)) return;
+
+	if(map_get_distance_in_pixels(g_MainWindow.m_pMap, pPoint, &centerPoint) < MAX_DISTANCE_FOR_AUTO_SLIDE_IN_PIXELS) {
+		g_MainWindow.m_bSliding = TRUE;
+		g_MainWindow.m_pAnimator = animator_new(ANIMATIONTYPE_FAST_THEN_SLIDE, SLIDE_TIME_IN_SECONDS_AUTO);
+
+		// set startpoint
+		g_MainWindow.m_ptSlideStartLocation.m_fLatitude = centerPoint.m_fLatitude;
+		g_MainWindow.m_ptSlideStartLocation.m_fLongitude = centerPoint.m_fLongitude;
+
+		// set endpoint
+		g_MainWindow.m_ptSlideEndLocation.m_fLatitude = pPoint->m_fLatitude;
+		g_MainWindow.m_ptSlideEndLocation.m_fLongitude = pPoint->m_fLongitude;
+
+		//mainwindow_callback_on_slide_timeout(NULL);
+	}
+	else {
+		mainwindow_map_center_on_mappoint(pPoint);
+	}
+}
+
 void mainwindow_get_centerpoint(mappoint_t* pPoint)
 {
 	g_assert(pPoint != NULL);

Index: mainwindow.h
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mainwindow.h	13 Mar 2005 23:31:21 -0000	1.9
+++ mainwindow.h	20 Mar 2005 03:37:09 -0000	1.10
@@ -70,8 +70,9 @@
 void mainwindow_statusbar_update_position(void);
 
 // Map
-void mainwindow_map_set_centerpoint(mappoint_t* pPoint);
+void mainwindow_map_center_on_mappoint(mappoint_t* pPoint);
 void mainwindow_map_get_centerpoint(mappoint_t* pPoint);
+void mainwindow_map_slide_to_mappoint(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.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- map.c	18 Mar 2005 08:37:35 -0000	1.28
+++ map.c	20 Mar 2005 03:37:09 -0000	1.29
@@ -705,6 +705,29 @@
 	return fAOB_Rad * RADIUS_OF_WORLD_IN_METERS;
 }
 
+gdouble map_get_distance_in_pixels(map_t* pMap, mappoint_t* p1, mappoint_t* p2)
+{
+	rendermetrics_t metrics;
+	map_get_render_metrics(pMap, &metrics);
+
+	gdouble fX1 = SCALE_X(&metrics, p1->m_fLongitude);
+	gdouble fY1 = SCALE_Y(&metrics, p1->m_fLongitude);
+	gdouble fX2 = SCALE_X(&metrics, p2->m_fLongitude);
+	gdouble fY2 = SCALE_Y(&metrics, p2->m_fLongitude);
+
+	gdouble fDeltaX = fX2 - fX1;
+	gdouble fDeltaY = fY2 - fY1;
+
+	gdouble d = sqrt((fDeltaX*fDeltaX) + (fDeltaY*fDeltaY));
+//	g_print("%f\n", d);
+	return d;
+}
+
+gboolean map_points_equal(mappoint_t* p1, mappoint_t* p2)
+{
+	return( p1->m_fLatitude == p2->m_fLatitude && p1->m_fLongitude == p2->m_fLongitude);
+}
+
 #if ROADSTER_DEAD_CODE
 /*
 

Index: map.h
===================================================================
RCS file: /cvs/cairo/roadster/src/map.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- map.h	13 Mar 2005 23:31:21 -0000	1.7
+++ map.h	20 Mar 2005 03:37:09 -0000	1.8
@@ -37,9 +37,9 @@
 
 #define INCHES_PER_METER (39.37007)
 
-#define MIN_ZOOMLEVEL (1)
+#define MIN_ZOOMLEVEL (6)	// 1
 #define MAX_ZOOMLEVEL (10)
-#define NUM_ZOOMLEVELS (10)
+#define NUM_ZOOMLEVELS (10)	// 10
 
 #define WORLD_CIRCUMFERENCE_IN_METERS (40076000)
 #define WORLD_METERS_PER_DEGREE (WORLD_CIRCUMFERENCE_IN_METERS / 360.0)
@@ -209,4 +209,8 @@
 void map_draw(map_t* pMap, gint nDrawFlags);
 double map_degrees_to_pixels(map_t* pMap, gdouble fDegrees, guint16 uZoomLevel);
 
+gboolean map_points_equal(mappoint_t* p1, mappoint_t* p2);
+
+gdouble map_get_distance_in_pixels(map_t* pMap, mappoint_t* p1, mappoint_t* p2);
+
 #endif

Index: map_draw_cairo.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_cairo.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- map_draw_cairo.c	18 Mar 2005 08:37:35 -0000	1.12
+++ map_draw_cairo.c	20 Mar 2005 03:37:09 -0000	1.13
@@ -502,18 +502,21 @@
         // get total width of string
         cairo_text_extents_t extents;
         cairo_text_extents(pCairo, pszLabel, &extents);
+	gdouble fLabelWidth = extents.width;
+	gdouble fFontHeight = extents.height;
 
-        cairo_font_extents_t font_extents;
-        cairo_current_font_extents(pCairo, &font_extents);
+//        cairo_font_extents_t font_extents;
+//        cairo_current_font_extents(pCairo, &font_extents);
+//	gdouble fFontHeight = font_extents.ascent;
 
         // text too big for line?       XXX: This math is not right but good enough for now ;)
-        if((extents.width * extents.width) > (fLineLengthSquared + (ACCEPTABLE_LINE_LABEL_OVERDRAW_IN_PIXELS_SQUARED))) {
+        if((fLabelWidth * fLabelWidth) > (fLineLengthSquared + (ACCEPTABLE_LINE_LABEL_OVERDRAW_IN_PIXELS_SQUARED))) {
             cairo_restore(pCairo);
             return;
         }
         gdouble fLineLength = sqrt(fLineLengthSquared);
 
-        gdouble fTotalPadding = fLineLength - extents.width;
+        gdouble fTotalPadding = fLineLength - fLabelWidth;
 
         // Normalize (make length = 1.0) by dividing by line length
         // This makes a line with length 1 from the origin (0,0)
@@ -538,22 +541,24 @@
                 gdouble fDrawY = fY1 + (fNormalizedY * fFrontPadding);
                 
                 // center text vertically by shifting down by half of height
-                fDrawX -= (fPerpendicularNormalizedX * font_extents.ascent/2);
-                fDrawY -= (fPerpendicularNormalizedY * font_extents.ascent/2);
-                
+                fDrawX -= (fPerpendicularNormalizedX * fFontHeight/2);
+                fDrawY -= (fPerpendicularNormalizedY * fFontHeight/2);
+
+		#define B (3)	// a border around the text to keep things readable, in pixels
+
                 GdkPoint aBoundingPolygon[4];
                 // 0 is bottom left point
-                aBoundingPolygon[0].x = fDrawX;	
-                aBoundingPolygon[0].y = fDrawY;
+                aBoundingPolygon[0].x = fDrawX - (fPerpendicularNormalizedX * B) - (fNormalizedX * B);
+                aBoundingPolygon[0].y = fDrawY - (fPerpendicularNormalizedX * B) - (fNormalizedX * B);
                 // 1 is upper left point
-                aBoundingPolygon[1].x = fDrawX + (fPerpendicularNormalizedX * font_extents.ascent);
-                aBoundingPolygon[1].y = fDrawY + (fPerpendicularNormalizedY * font_extents.ascent);
+                aBoundingPolygon[1].x = fDrawX + (fPerpendicularNormalizedX * (fFontHeight+B)) - (fNormalizedX * B); ;
+                aBoundingPolygon[1].y = fDrawY + (fPerpendicularNormalizedY * (fFontHeight+B)) - (fNormalizedY * B);;
                 // 2 is upper right point
-                aBoundingPolygon[2].x = aBoundingPolygon[1].x + (fNormalizedX * extents.width);
-                aBoundingPolygon[2].y = aBoundingPolygon[1].y + (fNormalizedY * extents.width);
+                aBoundingPolygon[2].x = aBoundingPolygon[1].x + (fNormalizedX * (fLabelWidth+B+B));
+                aBoundingPolygon[2].y = aBoundingPolygon[1].y + (fNormalizedY * (fLabelWidth+B+B));
                 // 3 is lower right point
-                aBoundingPolygon[3].x = fDrawX + (fNormalizedX * extents.width);
-                aBoundingPolygon[3].y = fDrawY + (fNormalizedY * extents.width);
+                aBoundingPolygon[3].x = fDrawX + (fNormalizedX * (fLabelWidth+B)) - (fPerpendicularNormalizedX * B);
+                aBoundingPolygon[3].y = fDrawY + (fNormalizedY * (fLabelWidth+B)) - (fPerpendicularNormalizedY * B);
                 
                 // Ask whether we can draw here
                 if(FALSE == scenemanager_can_draw_polygon(pMap->m_pSceneManager, aBoundingPolygon, 4)) {
@@ -1159,8 +1164,8 @@
 	gdouble fPolygonHeight = fMaxY - fMinY;
 	gdouble fPolygonWidth = fMaxX - fMinX;
 
-	gdouble fDrawX = fTotalX / pPointString->m_pPointsArray->len;
-	gdouble fDrawY = fTotalY / pPointString->m_pPointsArray->len;
+	gdouble fDrawX = fMinX + fPolygonWidth/2;	//fTotalX / pPointString->m_pPointsArray->len;
+	gdouble fDrawY = fMinY + fPolygonHeight/2; 	//fTotalY / pPointString->m_pPointsArray->len;
 
 	cairo_save(pCairo);
 

Index: point.c
===================================================================
RCS file: /cvs/cairo/roadster/src/point.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- point.c	13 Mar 2005 19:11:57 -0000	1.2
+++ point.c	20 Mar 2005 03:37:09 -0000	1.3
@@ -25,14 +25,24 @@
 #include "map.h"
 #include "point.h"
 
+#define USE_GFREELIST
+
+#ifdef USE_GFREELIST
+#include "gfreelist.h"
+GFreeList* g_pPointFreeList;
+#else
 GMemChunk* g_pPointChunkAllocator;		// chunk allocators to be shared by all geometrysets
+#endif
 
 void point_init(void)
 {
+#ifdef USE_GFREELIST
+	g_pPointFreeList = g_free_list_new(sizeof(mappoint_t), 1000);
+#else
 	// create memory allocators
 	g_pPointChunkAllocator = g_mem_chunk_new("ROADSTER points",
 			sizeof(mappoint_t), 1000, G_ALLOC_AND_FREE);
-	g_return_if_fail(g_pPointChunkAllocator != NULL);
+#endif
 }
 
 /*******************************************************
@@ -44,7 +54,12 @@
 	g_return_val_if_fail(*ppPoint == NULL, FALSE);	// must be a pointer to a NULL pointer
 
 	// get a new point struct from the allocator
+#ifdef USE_GFREELIST
+	mappoint_t* pNew = g_free_list_alloc(g_pPointFreeList);
+	memset(pNew, 0, sizeof(mappoint_t));
+#else
 	mappoint_t* pNew = g_mem_chunk_alloc0(g_pPointChunkAllocator);
+#endif
 	if(pNew) {
 		*ppPoint = pNew;
 		return TRUE;
@@ -57,6 +72,10 @@
 	g_return_if_fail(pPoint != NULL);
 
 	// give back to allocator
+#ifdef USE_GFREELIST
+	g_free_list_free(g_pPointFreeList, pPoint);
+#else
 	g_mem_chunk_free(g_pPointChunkAllocator, pPoint);
+#endif
 }
 

Index: pointstring.c
===================================================================
RCS file: /cvs/cairo/roadster/src/pointstring.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pointstring.c	13 Mar 2005 19:11:57 -0000	1.3
+++ pointstring.c	20 Mar 2005 03:37:09 -0000	1.4
@@ -26,13 +26,23 @@
 #include "point.h"
 #include "pointstring.h"
 
-GMemChunk* g_pPointStringChunkAllocator;
+#define USE_GFREELIST
+
+#ifdef USE_GFREELIST
+#include "gfreelist.h"
+GFreeList* g_pPointStringFreeList = NULL;
+#else
+GMemChunk* g_pPointStringChunkAllocator = NULL;
+#endif
 
 void pointstring_init(void)
 {
+#ifdef USE_GFREELIST
+	g_pPointStringFreeList = g_free_list_new(sizeof(pointstring_t), 1000);
+#else
 	g_pPointStringChunkAllocator = g_mem_chunk_new("ROADSTER pointstrings",
 			sizeof(pointstring_t), 1000, G_ALLOC_AND_FREE);
-	g_return_if_fail(g_pPointStringChunkAllocator != NULL);
+#endif
 }
 
 /*******************************************************
@@ -46,7 +56,14 @@
 	g_return_val_if_fail(*ppPointString == NULL, FALSE);	// must be a pointer to a NULL pointer
 
 	// allocate it
+#ifdef USE_GFREELIST
+	g_assert(g_pPointStringFreeList != NULL);
+	pointstring_t* pNew = g_free_list_alloc(g_pPointStringFreeList);
+	memset(pNew, 0, sizeof(pointstring_t));
+#else
+	g_assert(g_pPointStringChunkAllocator != NULL);
 	pointstring_t* pNew = g_mem_chunk_alloc0(g_pPointStringChunkAllocator);
+#endif
 	if(pNew) {
 		// configure it
 		pNew->m_pPointsArray = g_ptr_array_sized_new(2);
@@ -70,7 +87,12 @@
 
 	g_ptr_array_free(pPointString->m_pPointsArray, TRUE);
 	g_free(pPointString->m_pszName);
+
+#ifdef USE_GFREELIST
+	g_free_list_free(g_pPointStringFreeList, pPointString);
+#else
 	g_mem_chunk_free(g_pPointStringChunkAllocator, pPointString);
+#endif
 }
 
 // copies pPoint and adds it
@@ -83,4 +105,3 @@
 
 	g_ptr_array_add(pPointString->m_pPointsArray, pNewPoint);
 }
-

Index: searchwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- searchwindow.c	13 Mar 2005 23:31:21 -0000	1.13
+++ searchwindow.c	20 Mar 2005 03:37:09 -0000	1.14
@@ -151,7 +151,8 @@
 			RESULTLIST_ZOOMLEVEL, &nZoomLevel,
 			-1);
 
-		mainwindow_map_center_on_mappoint(&pt);
+		mainwindow_map_slide_to_mappoint(&pt);
+//		mainwindow_map_center_on_mappoint(&pt);
 		//mainwindow_statusbar_update_position();
 		mainwindow_set_zoomlevel(nZoomLevel);
 		mainwindow_draw_map(DRAWFLAG_ALL);




More information about the cairo-commit mailing list