]> err.no Git - mapper/commitdiff
Add some more code to map widget
authorKaj-Michael Lang <milang@tal.org>
Tue, 29 Apr 2008 11:11:21 +0000 (14:11 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 29 Apr 2008 11:11:21 +0000 (14:11 +0300)
src/gtkmap.c

index d3cd94f546a1672c35aa70e99707856517776ba1..e805ba56175bc411cc447d268c8673bfb9c05c31 100644 (file)
 
 G_DEFINE_TYPE(GtkMap, gtk_map, GTK_TYPE_WIDGET);
 
-typedef struct _GtkMapPriv GtkMapPriv;
+typedef struct _GtkMapPriv GtkMapPriv; 
 struct _GtkMapPriv
 { 
 PangoContext *context;
 PangoLayout *layout;
 PangoFontDescription *fontdesc;
+
+PangoLayout *speed_layout;
+PangoLayout *scale_layout;
+gint zoom;
+gint offsetx;
+gint offsety;
 };
 
 #define GTK_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_MAP, GtkMapPriv))
@@ -65,13 +70,16 @@ PangoFontDescription *fontdesc;
 #define leadx2unit(mgps) (mgps.unitx + (_lead_ratio) * pixel2unit(mgps.vel_offsetx))
 #define leady2unit(mgps) (mgps.unity + (0.6f*_lead_ratio)*pixel2unit(mgps.vel_offsety))
 
-static void gtk_map_finalize (GObject *object);
-static void gtk_map_size_request (GtkWidget *widget, GtkRequisition *requisition);
-static void gtk_map_size_allocate (GtkWidget *widget, GtkAllocation *allocate);
-static gboolean gtk_map_expose (GtkWidget *widget, GdkEventExpose *event);
-static void gtk_map_realize (GtkWidget *widget);
-static void gtk_map_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void gtk_map_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void gtk_map_finalize(GObject *object);
+
+static void gtk_map_size_request(GtkWidget *widget, GtkRequisition *requisition);
+static void gtk_map_size_allocate(GtkWidget *widget, GtkAllocation *allocate);
+
+static gboolean gtk_map_expose(GtkWidget *widget, GdkEventExpose *event);
+static void gtk_map_realize(GtkWidget *widget);
+
+static void gtk_map_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void gtk_map_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 
 static void
 gtk_map_class_init (GtkMapClass *class)
@@ -123,17 +131,21 @@ switch (prop_id) {
 static void
 gtk_map_init(GtkMap *map)
 {
+GtkMapPriv *priv;
 
+priv=GTK_MAP_GET_PRIVATE(map);
 }
 
 GtkWidget*
 gtk_map_new(void)
 {
 GtkMap *map;
+GtkMapPriv *priv;
 GtkWidget *widget;
 
 map=g_object_new(GTK_MAP_TYPE, NULL);
 widget=GTK_WIDGET(map);
+priv=GTK_MAP_GET_PRIVATE(map);
 map->heading=0;
 
 #if 0
@@ -196,16 +208,18 @@ static gboolean
 gtk_map_expose(GtkWidget *widget, GdkEventExpose *event)
 {
 GtkMap *map;
+GtkMapPriv *priv;
 
 g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
 g_return_val_if_fail(event != NULL, FALSE);
 
 map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
 
 gdk_draw_drawable(GDK_DRAWABLE(map->widget->window),
-               map->gc[COLORABLE_MARK],
-               map->pixmap,
-               event->area.x + map->offsetx, event->area.y + map->offsety,
+               priv->gc[COLORABLE_MARK],
+               priv->pixmap,
+               event->area.x + priv->offsetx, event->area.y + priv->offsety,
                event->area.x, event->area.y,
                event->area.width, event->area.height);
 
@@ -216,6 +230,7 @@ static void
 map_scale_draw(GtkWidget *widget, GdkEventExpose *event)
 {
 GtkMap *map;
+GtkMapPriv *priv;
 gchar buffer[16];
 gdouble distance;
 gdouble lat1, lon1, lat2, lon2;
@@ -223,10 +238,11 @@ gint width;
 
 g_return_if_fail(GTK_IS_MAP(widget));
 map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
 
-pango_layout_set_text(scale_layout, "0", -1);
-pango_layout_get_pixel_size(scale_layout, NULL, &scale_rect.height);
-scale_rect.y = _screen_height_pixels - scale_rect.height - 1;
+pango_layout_set_text(priv->scale_layout, "0", -1);
+pango_layout_get_pixel_size(priv->scale_layout, NULL, &scale_rect.height);
+scale_rect.y = priv->screen_height_pixels - scale_rect.height - 1;
 
 gdk_rectangle_intersect(&event->area, &scale_rect, &event->area);
 
@@ -294,13 +310,16 @@ if (event->area.width && event->area.height) {
 static void
 map_information_text(GtkWidget *widget, guint x, guint y, GdkGC *gc, gchar *msg)
 {
+GtkMap *map;
+GtkMapPriv *priv;
 guint width, height;
 
 g_return_if_fail(GTK_IS_MAP(widget));
 map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
 
-pango_layout_set_text(speed_layout, msg, -1);
-pango_layout_get_pixel_size(speed_layout, &width, &height);
+pango_layout_set_text(priv->speed_layout, msg, -1);
+pango_layout_get_pixel_size(priv->speed_layout, &width, &height);
 gtk_widget_queue_draw_area(_map_widget, x - 5, y - 5, width * 3 + 15, height + 5);
 gdk_window_process_all_updates();
 gdk_draw_layout(_map_widget->window, gc, x, y, speed_layout);