]> err.no Git - mapper/commitdiff
Map widget:
authorKaj-Michael Lang <milang@tal.org>
Wed, 7 May 2008 10:11:23 +0000 (13:11 +0300)
committerKaj-Michael Lang <milang@tal.org>
Wed, 7 May 2008 10:11:23 +0000 (13:11 +0300)
- Fix some return without value warings
- Add stub marker function
- Enable path rendering
- Use cairo to paint the buffer if available

src/gtkmap.c

index f8db4cbe76f10146333e46d4b194991185bf1150..526d330e219b5f3a506fc5418c3ececce2c85d6c 100644 (file)
@@ -163,6 +163,9 @@ struct _GtkMapPriv
        gboolean show_location;
        gboolean show_velvec;
        gboolean show_markers;
+       gboolean show_speed;
+       gboolean rotate_view;
+       gfloat rotate_angle;
 
        guint draw_width;
 
@@ -236,6 +239,10 @@ static gboolean gtk_map_configure(GtkWidget *widget, GdkEventConfigure *event);
 
 static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event);
 static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event);
+static void gtk_map_speed_draw(GtkWidget *widget, GdkEventExpose *event);
+
+static void gtk_map_render_markers(GtkWidget *widget, GdkEventExpose *event);
+static void gtk_map_render_paths(GtkWidget *widget, GdkEventExpose *event);
 
 static gboolean gtk_map_update_buffer_size(GtkWidget *widget, gint new_width, gint new_height);
 static void gtk_map_update_size(GtkWidget *widget, gint width, gint height);
@@ -386,6 +393,9 @@ priv->show_velvec=TRUE;
 priv->show_markers=TRUE;
 priv->show_location=TRUE;
 
+priv->rotate_angle=M_PI;
+priv->rotate_view=TRUE;
+
 priv->gl=FALSE;
 priv->buffer=NULL;
 }
@@ -680,21 +690,46 @@ priv->ct=gdk_cairo_create(widget->window);
 #endif
 
 g_debug("GTKMAP: expose (%d, %d)-(%d, %d)", event->area.x, event->area.y, event->area.width, event->area.height);
+g_debug("GTKMAP: expose (%d, %d)", event->area.x + priv->offsetx, event->area.y + priv->offsety);
+g_debug("GTKMAP: expose (%d, %d)", unit2x(priv->center.unitx), unit2y(priv->center.unity));
 
-if (priv->buffer)
+if (priv->buffer) {
+#ifdef WITH_CAIRO
+       cairo_save(priv->ct);
+       cairo_rectangle(priv->ct, event->area.x, event->area.y, event->area.width, event->area.height);
+       cairo_clip(priv->ct);
+       cairo_translate(priv->ct, -(event->area.x+priv->offsetx), -(event->area.y+priv->offsety));
+#if 0
+       if (priv->rotate_view) {
+               cairo_translate(priv->ct, (gdouble)-unit2x(priv->center.unitx), (gdouble)-unit2y(priv->center.unity) );
+               cairo_rotate(priv->ct, (gdouble)priv->rotate_angle);
+               cairo_translate(priv->ct, (gdouble)unit2x(priv->center.unitx), (gdouble)unit2y(priv->center.unity) );
+       }
+#endif
+#if 0
+       if (priv->animate_zoom_change) {
+               cairo_scale(priv->ct, 0.5, 0.5);
+       }
+#endif
+       gdk_cairo_set_source_pixmap(priv->ct, priv->buffer, event->area.x, event->area.y);
+       cairo_set_operator (priv->ct, CAIRO_OPERATOR_SOURCE);
+       cairo_paint(priv->ct);
+       cairo_restore(priv->ct);
+#else
        gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], priv->buffer,
                event->area.x + priv->offsetx, event->area.y + priv->offsety,
                event->area.x, event->area.y, event->area.width, event->area.height);
+#endif
+}
 
-#if 0
-gtk_map_paths_draw(widget, event);
+if (priv->show_paths!=0)
+       gtk_map_render_paths(widget, event);
 
 if (priv->show_markers)
-       gtk_map_markers_draw(widget, event);
+       gtk_map_render_markers(widget, event);
 
 if (priv->show_speed)
        gtk_map_speed_draw(widget, event);
-#endif
 
 if (priv->show_location)
        gtk_map_mark_draw(widget, event);
@@ -710,6 +745,12 @@ priv->ct=NULL;
 return TRUE;
 }
 
+static void 
+gtk_map_render_markers(GtkWidget *widget, GdkEventExpose *event)
+{
+
+}
+
 static void
 gtk_map_render_waypoint(GtkWidget *widget, guint x1, guint y1)
 {
@@ -772,7 +813,7 @@ priv=GTK_MAP_GET_PRIVATE(map);
 for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) {
        /* Draw the line from (curr - 1) to (curr). */
 
-       gtk_map_render_segment(widget, curr[-1].unitx, curr[-1].unity, curr->unitx, curr->unity);
+       gtk_map_render_path_segment(widget, curr[-1].unitx, curr[-1].unity, curr->unitx, curr->unity);
        /* Now, check if curr is a waypoint. */
        if (wcurr && wcurr <= path->wtail && wcurr->point == curr) {
                guint x1 = unit2bufx(wcurr->point->unitx);
@@ -782,8 +823,10 @@ for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) {
                wcurr++;
        }
 }
+#if 0
 if (path->type==PATH_TYPE_ROUTE)
        gtk_map_render_next_waypoint(widget, path);
+#endif
 }
 
 static void 
@@ -817,8 +860,8 @@ gtk_map_add_path(GtkWidget *widget, Path *path)
 GtkMap *map;
 GtkMapPriv *priv;
 
-g_return_if_fail(GTK_IS_MAP(widget));
-g_return_if_fail(path);
+g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
+g_return_val_if_fail(path, FALSE);
 
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
@@ -836,8 +879,8 @@ gtk_map_remove_path(GtkWidget *widget, Path *path)
 GtkMap *map;
 GtkMapPriv *priv;
 
-g_return_if_fail(GTK_IS_MAP(widget));
-g_return_if_fail(path);
+g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
+g_return_val_if_fail(path, FALSE);
 
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
@@ -1034,7 +1077,7 @@ if (priv->speed<0)
        return;
 
 g_snprintf(buffer, sizeof(buffer), "%0.0f %s", priv->speed * priv->units_conv, priv->units_str);
-map_information_text(10, 10, priv->speed_gc, buffer);
+gtk_map_information_text(widget, 10, 10, priv->speed_gc, buffer);
 }
 
 void