From: Kaj-Michael Lang Date: Sun, 4 May 2008 11:22:28 +0000 (+0300) Subject: More map widget work. Now it compiles. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ded57ac19e297d94ee00e4ca1ae6ca4da7b9aaf9;p=mapper More map widget work. Now it compiles. --- diff --git a/src/gtkmap.c b/src/gtkmap.c index 6b45832..e6b58d0 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -55,7 +55,12 @@ struct _GtkMapPriv { /* Map image buffer */ GdkPixmap *buffer; + guint buf_width_tiles; + guint buf_height_tiles; + guint buf_width_pixels; + guint buf_height_pixels; + /* Cairo context for widget->window */ #ifdef WITH_CAIRO cairo_t *ct; #endif @@ -88,26 +93,22 @@ struct _GtkMapPriv ImageCache *icache; GList *markers; + /* OpenGL data */ #ifdef WITH_GL GdkGLConfig* gl_config; #endif + gboolean gl; GdkGC *gc_mark; GdkGC *gc_velvec; + /* Cached Location dot x,y values */ gint mark_x1; gint mark_x2; gint mark_y1; gint mark_y2; GdkRectangle mark_rect; - guint buf_width_tiles; - guint buf_height_tiles; - guint buf_width_pixels; - guint buf_height_pixels; - - gboolean gl; - GtkMapCenterMode center_mode; Point center; @@ -115,14 +116,19 @@ struct _GtkMapPriv Point max_center; Point focus; + /* Our "location" on the map */ Point location; guint lead_ratio; guint center_ratio; + gint vel_offsetx; + gint vel_offsety; + guint base_tilex; guint base_tiley; + /* Zoom settings */ gint zoom; gint max_zoom; gint min_zoom; @@ -132,6 +138,7 @@ struct _GtkMapPriv gfloat speed; + /* Buffer offset */ gint offsetx; gint offsety; @@ -194,49 +201,11 @@ struct _GtkMapPriv /* #define GTK_MAP_WORLD_SIZE_UNITS(max_zoom) (2 << (max_zoom + GTK_MAP_TILE_SIZE_P2)) */ #define GTK_MAP_WORLD_SIZE_UNITS (1<<31) +#define WORLD_SIZE_UNITS GTK_MAP_WORLD_SIZE_UNITS /* Pans are done two "grids" at a time, or 64 pixels. */ #define GTK_MAP_PAN_UNITS (grid2unit(2)) -#define GTK_MAP_MACRO_RECALC_CENTER(center_unitx, center_unity) { \ - switch(priv->center_mode) { \ - case CENTER_LEAD: \ - priv->center.unitx = priv->leadx2unit; \ - priv->center.unity = priv->leady2unit; \ - break; \ - case CENTER_LATLON: \ - priv->center.unitx = priv->location.unitx; \ - priv->center.unity = priv->location.unity; \ - break; \ - default: \ - priv->center.unitx = center_unitx; \ - priv->center.unity = center_unity; \ - break; \ - } \ -}; - -#define GTK_MAP_MACRO_RECALC_OFFSET(center) { \ - priv->offsetx = grid2pixel(unit2grid(center.unitx) - priv->screen_grids_halfwidth - tile2grid(priv->base_tilex)); \ - priv->offsety = grid2pixel(unit2grid(center.unity) - priv->screen_grids_halfheight - tile2grid(priv->base_tiley)); \ -} - -#define GTK_MAP_MACRO_RECALC_FOCUS_BASE { \ - priv->focus.unitx = x2unit(priv->screen_width_pixels * priv->center_ratio / 20); \ - priv->focus.unity = y2unit(priv->screen_height_pixels * priv->center_ratio / 20); \ -} - -#define GTK_MAP_MACRO_RECALC_FOCUS_SIZE { \ - priv->focus_unitwidth = pixel2unit((10 - priv->center_ratio) * priv->screen_width_pixels / 10); \ - priv->focus_unitheight = pixel2unit((10 - priv->center_ratio) * priv->screen_height_pixels / 10); \ -} - -#define GTK_MAP_MACRO_RECALC_CENTER_BOUNDS() { \ - priv->min_center.unitx = pixel2unit(grid2pixel(priv->screen_grids_halfwidth)); \ - priv->min_center.unity = pixel2unit(grid2pixel(priv->screen_grids_halfheight)); \ - priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfwidth) - 1; \ - priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfheight) - 1; \ -} - #define BOUND(x, a, b) { \ if((x) < (a)) \ (x) = (a); \ @@ -253,7 +222,7 @@ static gboolean gtk_map_expose(GtkWidget *widget, GdkEventExpose *event); static gboolean gtk_map_configure(GtkWidget *widget, GdkEventConfigure *event); static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event); -static void gtk_map_draw_mark(GtkWidget *widget, GdkEventExpose *event); +static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event); static gboolean gtk_map_update_buffer_size(GtkMap *map, gint new_width, gint new_height); @@ -303,6 +272,62 @@ widget_class->size_allocate = gtk_map_size_allocate; g_type_class_add_private (object_class, sizeof(GtkMapPriv)); } +static inline void +gtk_map_recalc_center(GtkMapPriv *priv) +{ +g_return_if_fail(priv); +switch(priv->center_mode) { + case CENTER_LEAD: + priv->center.unitx = leadx2unit; + priv->center.unity = leady2unit; + break; + case CENTER_LATLON: + priv->center.unitx = priv->location.unitx; + priv->center.unity = priv->location.unity; + break; + default: +#if 0 + priv->center.unitx = center->unitx; + priv->center.unity = center->unity; +#endif + break; +} +} + +static inline void +gtk_map_recalc_offset(GtkMapPriv *priv) +{ +g_return_if_fail(priv); +priv->offsetx = grid2pixel(unit2grid(priv->center.unitx) - priv->screen_grids_halfwidth - tile2grid(priv->base_tilex)); +priv->offsety = grid2pixel(unit2grid(priv->center.unity) - priv->screen_grids_halfheight - tile2grid(priv->base_tiley)); +} + +static inline void +gtk_map_recalc_focus_base(GtkMapPriv *priv) +{ +g_return_if_fail(priv); +priv->focus.unitx = x2unit(priv->screen_width_pixels * priv->center_ratio / 20); +priv->focus.unity = y2unit(priv->screen_height_pixels * priv->center_ratio / 20); +} + +static inline void +gtk_map_recalc_focus_size(GtkMapPriv *priv) +{ +g_return_if_fail(priv); +priv->focus_unitwidth = pixel2unit((10 - priv->center_ratio) * priv->screen_width_pixels / 10); +priv->focus_unitheight = pixel2unit((10 - priv->center_ratio) * priv->screen_height_pixels / 10); +} + +static inline void +gtk_map_recalc_center_bounds(GtkMapPriv *priv) +{ +g_return_if_fail(priv); +priv->min_center.unitx = pixel2unit(grid2pixel(priv->screen_grids_halfwidth)); +priv->min_center.unity = pixel2unit(grid2pixel(priv->screen_grids_halfheight)); +priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfwidth) - 1; +priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfheight) - 1; +} + static void gtk_map_init(GtkMap *map) { @@ -411,8 +436,8 @@ priv->screen_grids_halfheight = pixel2grid(priv->screen_height_pixels) / 2; priv->scale_rect.x = (priv->screen_width_pixels - SCALE_WIDTH) / 2; priv->scale_rect.width = SCALE_WIDTH; -GTK_MAP_MACRO_RECALC_FOCUS_BASE; -GTK_MAP_MACRO_RECALC_FOCUS_SIZE; +gtk_map_recalc_focus_base(priv); +gtk_map_recalc_focus_size(priv); priv->min_center.unitx = pixel2unit(grid2pixel(priv->screen_grids_halfwidth)); priv->min_center.unity = pixel2unit(grid2pixel(priv->screen_grids_halfheight)); @@ -565,7 +590,7 @@ return TRUE; } static void -gtk_map_draw_mark(GtkWidget *widget, GdkEventExpose *event) +gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event) { GtkMap *map; GtkMapPriv *priv; @@ -626,7 +651,7 @@ priv->mark_y1 = unit2y(priv->location.unity); priv->mark_x2 = priv->mark_x1 + (priv->show_velvec ? priv->vel_offsetx : 0); priv->mark_y2 = priv->mark_y1 + (priv->show_velvec ? priv->vel_offsety : 0); -priv->mark_rect.x= = MIN(priv->mark_x1, priv->mark_x2) - (2 * priv->draw_width); +priv->mark_rect.x = MIN(priv->mark_x1, priv->mark_x2) - (2 * priv->draw_width); priv->mark_rect.y = MIN(priv->mark_y1, priv->mark_y2) - (2 * priv->draw_width); priv->mark_rect.width = abs(priv->mark_x1 - priv->mark_x2) + (4 * priv->draw_width); priv->mark_rect.height = abs(priv->mark_y1 - priv->mark_y2) + (4 * priv->draw_width); @@ -826,7 +851,7 @@ GtkMapPriv *priv; GdkPixbuf *pixbuf=NULL; gint zoff; -g_return_if_val_fail(GTK_IS_MAP(widget), FALSE); +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); @@ -951,7 +976,7 @@ if (new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) { GTK_MAP_TILE_SIZE_PIXELS, GTK_MAP_TILE_SIZE_PIXELS); } else { - gtk_map_render_tile(map, + gtk_map_render_tile(GTK_MAP(map), new_base_tilex + new_x, new_base_tiley + new_y, new_x * GTK_MAP_TILE_SIZE_PIXELS, @@ -962,10 +987,8 @@ if (new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) { } } -GTK_MAP_MACRO_RECALC_OFFSET(); -GTK_MAP_MACRO_RECALC_FOCUS_BASE(priv->center_ratio); - -/* gtk_map_set_mark(&_gps->data); */ +gtk_map_recalc_offset(priv); +gtk_map_recalc_focus_base(priv); gtk_map_refresh(map); } @@ -1012,17 +1035,17 @@ if (new_zoom > (priv->max_zoom - 1)) if (new_zoom == priv->zoom) return FALSE; -priv->zoom = new_zoom / _curr_repo->view_zoom_steps * _curr_repo->view_zoom_steps; -priv->world_size_tiles = unit2tile(GTK_MAP_WORLD_SIZE_UNITS(priv->max_zoom)); +priv->zoom = new_zoom / priv->curr_repo->view_zoom_steps * priv->curr_repo->view_zoom_steps; +priv->world_size_tiles = unit2tile(GTK_MAP_WORLD_SIZE_UNITS); /* If we're leading, update the center to reflect new zoom level. */ -GTK_MAP_MACRO_RECALC_CENTER(priv->center.unitx, priv->center.unity); +gtk_map_recalc_center(priv); /* Update center bounds to reflect new zoom level. */ priv->min_center.unitx = pixel2unit(grid2pixel(priv->screen_grids_halfwidth)); priv->min_center.unity = pixel2unit(grid2pixel(priv->screen_grids_halfheight)); -priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS(priv->max_zoom) - grid2unit(priv->screen_grids_halfwidth) - 1; -priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS(priv->max_zoom) - grid2unit(priv->screen_grids_halfheight) - 1; +priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids_halfwidth) - 1; +priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids_halfheight) - 1; BOUND(priv->center.unitx, priv->min_center.unitx, priv->max_center.unitx); BOUND(priv->center.unity, priv->min_center.unity, priv->max_center.unity); @@ -1030,14 +1053,12 @@ BOUND(priv->center.unity, priv->min_center.unity, priv->max_center.unity); priv->base_tilex = grid2tile((gint) pixel2grid((gint) unit2pixel((gint) priv->center.unitx)) - (gint) priv->screen_grids_halfwidth); priv->base_tiley = grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight); -/* New zoom level, so we can't reuse the old buffer's pixels. */ -/* Update state variables. */ -GTK_MAP_MACRO_RECALC_OFFSET(); -GTK_MAP_MACRO_RECALC_FOCUS_BASE(priv->center_ratio); -GTK_MAP_MACRO_RECALC_FOCUS_SIZE(priv->center_ratio); +/* New zoom level, so we can't reuse the old buffer's pixels. Update state variables. */ +gtk_map_recalc_offset(priv); +gtk_map_recalc_focus_base(priv); +gtk_map_recalc_focus_size(priv); -/* gtk_map_set_mark(&_gps->data); */ -gtk_map_refresh(map); +gtk_map_refresh(GTK_WIDGET(map)); return TRUE; }