summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre GRANDIN <pgrandin@users.noreply.github.com>2019-10-29 18:28:58 -0600
committerGitHub <noreply@github.com>2019-10-29 18:28:58 -0600
commit55ce2c2bcdd819ccd130c75bd0d4e4812418aa76 (patch)
tree2b984c577a58b842214f7cb3826ddd257e359d5e
parent78d43cd302feafc09fa57ad8118e8942ae2ef7c8 (diff)
parentdf2c55b4d9c334bcc5f74d4d0b456d8e3685c3d1 (diff)
downloadnavit-55ce2c2bcdd819ccd130c75bd0d4e4812418aa76.tar.gz
Merge branch 'trunk' into i18n/ckb
-rw-r--r--navit/graphics.c232
-rw-r--r--navit/graphics/qt5/event_qt5.cpp1
-rw-r--r--navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp301
-rw-r--r--navit/gui/qml/gui_qml.cpp1
-rw-r--r--navit/gui/qml/vehicleProxy.h1
-rw-r--r--navit/gui/qt5_qml/backend.cpp2
-rw-r--r--navit/iphone/downloader/Classes/DownloaderDetailViewController.h5
-rw-r--r--navit/item.c102
-rw-r--r--navit/item.h2
-rw-r--r--navit/map.h3
-rw-r--r--navit/map/binfile/binfile.c11
-rw-r--r--navit/speech/qt5_espeak/Qt5EspeakAudioOut.h3
-rw-r--r--navit/vehicle/qt5/vehicle_qt5.cpp17
13 files changed, 441 insertions, 240 deletions
diff --git a/navit/graphics.c b/navit/graphics.c
index b3b9e54c2..662a74f0b 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -53,6 +53,10 @@
#include "event.h"
#include "navit.h"
+/**
+ * @brief maximum amount of coordinates to allocate on stack using g_alloca
+ */
+#define ALLOCA_COORD_LIMIT 16384
//##############################################################################################################
//# Description:
@@ -1035,11 +1039,18 @@ void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode) {
* @author Martin Schaller (04/2008)
*/
void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count) {
- struct point * p_scaled = g_alloca(sizeof (struct point)*count);
+ struct point * p_scaled;
int a;
+ if(count < ALLOCA_COORD_LIMIT)
+ p_scaled = g_alloca(sizeof (struct point)* count);
+ else
+ p_scaled = g_malloc(sizeof (struct point)* count);
+
for(a=0; a < count; a ++)
p_scaled[a] = graphics_dpi_scale_point(this_,&(p[a]));
this_->meth.draw_lines(this_->priv, gc->priv, p_scaled, count);
+ if(count >= ALLOCA_COORD_LIMIT)
+ g_free(p_scaled);
}
/**
@@ -1052,8 +1063,13 @@ void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct
* @author Martin Schaller (04/2008)
*/
void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r) {
- struct point *pnt=g_alloca(sizeof(struct point)*(r*4+64));
+ struct point *pnt;
int i=0;
+ if((r*4+64) < ALLOCA_COORD_LIMIT)
+ pnt=g_alloca(sizeof(struct point)*(r*4+64));
+ else
+ pnt=g_malloc(sizeof(struct point)*(r*4+64));
+
if(this_->meth.draw_circle) {
struct point p_scaled;
p_scaled = graphics_dpi_scale_point(this_,p);
@@ -1065,6 +1081,8 @@ void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct
i++;
graphics_draw_lines(this_, gc, pnt, i);
}
+ if((r*4+64) >= ALLOCA_COORD_LIMIT)
+ g_free(pnt);
}
/**
@@ -1091,11 +1109,18 @@ static void graphics_draw_polygon(struct graphics *gra, struct graphics_gc *gc,
if (! gra->meth.draw_polygon) {
return;
} else {
- struct point * pin_scaled = g_alloca(sizeof (struct point)*count_in);
+ struct point * pin_scaled;
int a;
+ if(count_in < ALLOCA_COORD_LIMIT)
+ pin_scaled = g_alloca(sizeof (struct point)*count_in);
+ else
+ pin_scaled = g_malloc(sizeof (struct point)*count_in);
+
for(a=0; a < count_in; a ++)
pin_scaled[a] = graphics_dpi_scale_point(gra,&(pin[a]));
gra->meth.draw_polygon(gra->priv, gc->priv, pin_scaled, count_in);
+ if(count_in >= ALLOCA_COORD_LIMIT)
+ g_free(pin_scaled);
}
}
@@ -1120,17 +1145,16 @@ static void graphics_draw_polygon_with_holes(struct graphics *gra, struct graphi
graphics_draw_polygon(gra, gc, pin, count_in);
return;
} else {
- int limit=10000;
struct point * pin_scaled;
struct point ** holes_scaled;
int a;
int b;
- if(count_in < limit) {
+ if(count_in < ALLOCA_COORD_LIMIT) {
pin_scaled = g_alloca(sizeof (struct point)*count_in);
} else {
pin_scaled = g_malloc(sizeof (struct point)*count_in);
}
- if(hole_count < limit) {
+ if(hole_count < ALLOCA_COORD_LIMIT) {
holes_scaled = g_alloca(sizeof (struct point *)*hole_count);
} else {
holes_scaled = g_malloc(sizeof (struct point *)*hole_count);
@@ -1148,21 +1172,25 @@ static void graphics_draw_polygon_with_holes(struct graphics *gra, struct graphi
/* free the hole arrays */
for(b=0; b < hole_count; b ++)
g_free(holes_scaled[b]);
- if(count_in >= limit)
+ if(count_in >= ALLOCA_COORD_LIMIT)
g_free(pin_scaled);
- if(hole_count >= limit)
+ if(hole_count >= ALLOCA_COORD_LIMIT)
g_free(holes_scaled);
}
}
void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h,
int r, int fill) {
- struct point *p=g_alloca(sizeof(struct point)*(r*4+32));
+ struct point *p;
struct point pi0= {plu->x+r,plu->y+r};
struct point pi1= {plu->x+w-r,plu->y+r};
struct point pi2= {plu->x+w-r,plu->y+h-r};
struct point pi3= {plu->x+r,plu->y+h-r};
int i=0;
+ if((r*4+32) < ALLOCA_COORD_LIMIT)
+ p=g_alloca(sizeof(struct point)*(r*4+32));
+ else
+ p=g_malloc(sizeof(struct point)*(r*4+32));
circle_to_points(&pi2, r*2, 0, -1, 258, p, &i, 1);
circle_to_points(&pi1, r*2, 0, 255, 258, p, &i, 1);
@@ -1174,6 +1202,8 @@ void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc
graphics_draw_polygon(this_,gc,p,i);
else
graphics_draw_lines(this_,gc,p,i);
+ if((r*4+32) >= ALLOCA_COORD_LIMIT)
+ g_free(p);
}
@@ -1243,11 +1273,18 @@ void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct
static void graphics_draw_image_warp(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count,
struct graphics_image *img) {
if(this_->meth.draw_image_warp) {
- struct point * p_scaled = g_alloca(sizeof (struct point)*count);
+ struct point * p_scaled;
int a;
+ if(count < ALLOCA_COORD_LIMIT)
+ p_scaled = g_alloca(sizeof (struct point)*count);
+ else
+ p_scaled = g_malloc(sizeof (struct point)*count);
+
for(a=0; a < count; a ++)
p_scaled[a] = graphics_dpi_scale_point(this_,&(p[a]));
this_->meth.draw_image_warp(this_->priv, gc->priv, p_scaled, count, img->priv);
+ if(count >= ALLOCA_COORD_LIMIT)
+ g_free(p_scaled);
} else {
dbg(lvl_error,"draw_image_warp not supported by graphics driver");
}
@@ -2009,7 +2046,10 @@ static void graphics_draw_polyline_as_polygon(struct graphics *gra, struct graph
return;
ctx.shape.l=0;
ctx.shape.wi=0;
- ctx.res=g_alloca(sizeof(struct point)*maxpoints);
+ if(maxpoints < ALLOCA_COORD_LIMIT)
+ ctx.res=g_alloca(sizeof(struct point)*maxpoints);
+ else
+ ctx.res=g_malloc(sizeof(struct point)*maxpoints);
i=0;
draw_init_ctx(&ctx, maxpoints);
draw_shape(&ctx, pnt, *width++);
@@ -2029,6 +2069,8 @@ static void graphics_draw_polyline_as_polygon(struct graphics *gra, struct graph
draw_end(&ctx,&pnt[count-1]);
ctx.res[ctx.npos]=ctx.res[ctx.ppos-1];
graphics_draw_polygon(gra, gc, ctx.res+ctx.npos, ctx.ppos-ctx.npos);
+ if(maxpoints >= ALLOCA_COORD_LIMIT)
+ g_free(ctx.res);
}
@@ -2128,14 +2170,22 @@ static int clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *cl
*/
void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count,
int *width, int poly) {
- struct point *points_to_draw=g_alloca(sizeof(struct point)*(count+1));
- int *w=g_alloca(sizeof(int)*(count+1));
+ struct point *points_to_draw;
+ int *w;
struct wpoint segment_start,segment_end;
int i,points_to_draw_cnt=0;
int clip_result;
int r_width, r_height;
struct point_rect r=gra->r;
+ if(count < ALLOCA_COORD_LIMIT) {
+ points_to_draw=g_alloca(sizeof(struct point)*(count+1));
+ w=g_alloca(sizeof(int)*(count+1));
+ } else {
+ points_to_draw=g_malloc(sizeof(struct point)*(count+1));
+ w=g_malloc(sizeof(int)*(count+1));
+ }
+
r_width=r.rl.x-r.lu.x;
r_height=r.rl.y-r.lu.y;
@@ -2186,6 +2236,10 @@ void graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc
}
}
}
+ if(count >= ALLOCA_COORD_LIMIT) {
+ g_free(points_to_draw);
+ g_free(w);
+ }
}
static int is_inside(struct point *p, struct point_rect *r, int edge) {
@@ -2239,11 +2293,9 @@ static void poly_intersection(struct point *p1, struct point *p2, struct point_r
*/
static void graphics_clip_polygon(struct point_rect * r, struct point * in, int count_in, struct point *out,
int* count_out) {
- /* set our self a limit for the in stack buffer. To not overflow stack */
- const int limit=10000;
/* get a temp buffer to store points after one direction clipping.
* since we are clipping 4 directions, result is always in out at the end*/
- struct point *temp=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
+ struct point *temp;
struct point *pout;
struct point *pin;
int edge;
@@ -2258,7 +2310,9 @@ static void graphics_clip_polygon(struct point_rect * r, struct point * in, int
* 1. the output buffer
* 2. temp
*/
- if (count_in >= limit) {
+ if (count_in < ALLOCA_COORD_LIMIT) {
+ temp=g_alloca(sizeof(struct point) * (count_in < ALLOCA_COORD_LIMIT ? count_in*8+1:0));
+ } else {
/* too big. Allocate a buffer (slower) */
temp=g_new(struct point, count_in*8+1);
}
@@ -2319,7 +2373,7 @@ static void graphics_clip_polygon(struct point_rect * r, struct point * in, int
/* have clipped poly in out. And number of points now in *count_out */
/* if we had to allocate the buffer, we need to free it */
- if (count_in >= limit) {
+ if (count_in >= ALLOCA_COORD_LIMIT) {
g_free(temp);
}
return;
@@ -2335,14 +2389,13 @@ static void graphics_clip_polygon(struct point_rect * r, struct point * in, int
*/
void graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in) {
struct point_rect r=gra->r;
- int limit=10000;
struct point *clipped;
int count_out = count_in*8+1;
/* prepare buffer */
- if (count_in < limit) {
+ if (count_in < ALLOCA_COORD_LIMIT) {
/* use on stack buffer */
- clipped=g_alloca(sizeof(struct point) * (count_in < limit ? count_in*8+1:0));
+ clipped=g_alloca(sizeof(struct point) * (count_in < ALLOCA_COORD_LIMIT ? count_in*8+1:0));
} else {
/* too big. allocate buffer (slower) */
clipped=g_new(struct point, count_in*8+1);
@@ -2352,7 +2405,7 @@ void graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc,
graphics_draw_polygon(gra, gc, clipped, count_out);
/* if we had to allocate buffer, free it */
- if (count_in >= limit) {
+ if (count_in >= ALLOCA_COORD_LIMIT) {
g_free(clipped);
}
}
@@ -2373,7 +2426,6 @@ static void graphics_draw_polygon_with_holes_clipped(struct graphics *gra, struc
int count_in, int hole_count, int* ccount, struct point **holes) {
int i;
struct point_rect r=gra->r;
- int limit=10000;
struct point *clipped;
int total_count_in;
int count_out;
@@ -2390,7 +2442,7 @@ static void graphics_draw_polygon_with_holes_clipped(struct graphics *gra, struc
count_out = total_count_in*8+1+hole_count;
/* prepare buffer for outer and all holes!*/
- if (count_out < limit) {
+ if (count_out < ALLOCA_COORD_LIMIT) {
/* use on stack buffer */
clipped=g_alloca(sizeof(struct point) * count_out);
/* no need to free on stack buffer */
@@ -2404,7 +2456,7 @@ static void graphics_draw_polygon_with_holes_clipped(struct graphics *gra, struc
count_used=0;
/* prepare arrays for new holes */
- if(hole_count < limit) {
+ if(hole_count < ALLOCA_COORD_LIMIT) {
found_ccount=g_alloca(sizeof(int)* hole_count);
found_holes=g_alloca(sizeof(struct point*)* hole_count);
} else {
@@ -2431,7 +2483,7 @@ static void graphics_draw_polygon_with_holes_clipped(struct graphics *gra, struc
}
/* call drawing function */
graphics_draw_polygon_with_holes(gra, gc, clipped, count_out, found_hole_count, found_ccount, found_holes);
- if(hole_count >= limit) {
+ if(hole_count >= ALLOCA_COORD_LIMIT) {
g_free(found_ccount);
g_free(found_holes);
}
@@ -2763,13 +2815,21 @@ static inline void displayitem_draw_image (struct displayitem *di, struct displa
* @brief dc The display_context to use to draw items
*/
static void displayitem_draw(struct displayitem *di, struct layout *l, struct display_context *dc) {
- int *width=g_alloca(sizeof(int)*dc->maxlen);
+ int *width;
int limit=0;
- struct point *pa=g_alloca(sizeof(struct point)*dc->maxlen);
+ struct point *pa;
struct graphics *gra=dc->gra;
struct element *e=dc->e;
int draw_underground=0;
+ if (dc->maxlen < ALLOCA_COORD_LIMIT) {
+ width=g_alloca(sizeof(int)*dc->maxlen);
+ pa=g_alloca(sizeof(struct point)*dc->maxlen);
+ } else {
+ width=g_malloc(sizeof(int)*dc->maxlen);
+ pa=g_malloc(sizeof(struct point)*dc->maxlen);
+ }
+
while (di) {
int count=di->count,mindist=dc->mindist;
struct displayitem_poly_holes t_holes;
@@ -2852,6 +2912,10 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
di=di->next;
}
+ if (dc->maxlen >= ALLOCA_COORD_LIMIT) {
+ g_free(width);
+ g_free(pa);
+ }
}
/**
* FIXME
@@ -2888,8 +2952,15 @@ void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct tra
GList *es;
struct display_context dc;
int max_coord=32;
- char *buffer=g_alloca(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
- struct displayitem *di=(struct displayitem *)buffer;
+ char *buffer;
+ struct displayitem *di;
+ if (max_coord < ALLOCA_COORD_LIMIT) {
+ buffer=g_alloca(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
+ } else {
+ buffer=g_malloc(sizeof(struct displayitem)+max_coord*sizeof(struct coord));
+ }
+ di=(struct displayitem *)buffer;
+
es=itm->elements;
di->item.type=type_none;
di->item.id_hi=0;
@@ -2927,6 +2998,9 @@ void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct tra
display_context_free(&dc);
es=g_list_next(es);
}
+ if (max_coord >= ALLOCA_COORD_LIMIT) {
+ g_free(buffer);
+ }
}
/**
@@ -3061,9 +3135,19 @@ GList *displaylist_get_clicked_list(struct displaylist *displaylist, struct poin
static void do_draw(struct displaylist *displaylist, int cancel, int flags) {
struct item *item;
int count,max=displaylist->dc.maxlen,workload=0;
- struct coord *ca=g_alloca(sizeof(struct coord)*max);
+ int used=0;
+ struct coord *ca;
struct attr attr,attr2;
enum projection pro;
+ int need_free=0;
+
+ if (max < ALLOCA_COORD_LIMIT) {
+ ca=g_alloca(sizeof(struct coord)*max);
+ need_free=0;
+ } else {
+ ca=g_malloc(sizeof(struct coord)*max);
+ need_free=1;
+ }
if (displaylist->order != displaylist->order_hashed || displaylist->layout != displaylist->layout_hashed) {
displaylist_update_hash(displaylist);
@@ -3095,24 +3179,59 @@ static void do_draw(struct displaylist *displaylist, int cancel, int flags) {
int label_count=0;
char *labels[2];
struct hash_entry *entry;
+ int coords_left;
if (item == &busy_item) {
- if (displaylist->workload)
+ if (displaylist->workload) {
+ if (need_free) {
+ g_free(ca);
+ }
return;
- else
+ } else
continue;
}
entry=get_hash_entry(displaylist, item->type);
if (!entry)
continue;
count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel);
+ /* abort if no coordinates within selection at all */
if (! count)
continue;
- if (displaylist->dc.pro != pro)
- transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count);
+ /* handle overflow */
if (count == max) {
- dbg(lvl_error,"point count overflow %d for %s "ITEM_ID_FMT"", count,item_to_name(item->type),ITEM_ID_ARGS(*item));
- displaylist->dc.maxlen=max*2;
+ /* get required space */
+ item_coord_rewind(item);
+ coords_left=item_coords_left(item);
+ /* increase to required space, or double space if we couldn't get required space */
+ if(coords_left > 0) {
+ displaylist->dc.maxlen=(coords_left+2);
+ } else {
+ displaylist->dc.maxlen=max*2;
+ }
+ dbg(lvl_error,"point count overflow %d for %s "ITEM_ID_FMT". Increase to %d", count,item_to_name(item->type),
+ ITEM_ID_ARGS(*item), displaylist->dc.maxlen);
+ /* remember the new maximum */
+ max=displaylist->dc.maxlen;
+ /* get more memory */
+ if(need_free)
+ g_free(ca);
+ ca=g_malloc(sizeof(struct coord)*(displaylist->dc.maxlen));
+ need_free=1;
+ /* try again to get coordinates */
+ item_coord_rewind(item);
+ count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel);
+ /* check if we got valid coordinates in second attempt. If not don't try to draw this at all */
+ if(count <= 0) {
+ continue;
+ }
}
+ /* transform the coordinates */
+ if (displaylist->dc.pro != pro)
+ transform_from_to_count(ca, displaylist->dc.pro, ca, pro, count);
+
+ /* remember the peak coordinates actually used */
+ if(used < count)
+ used=count;
+
if (item_is_custom_poi(*item)) {
if (item_attr_get(item, attr_icon_src, &attr2))
labels[1]=map_convert_string(displaylist->m, attr2.u.str);
@@ -3138,8 +3257,12 @@ static void do_draw(struct displaylist *displaylist, int cancel, int flags) {
if (labels[1])
map_convert_free(labels[1]);
workload++;
- if (workload == displaylist->workload)
+ if (workload == displaylist->workload) {
+ if (need_free) {
+ g_free(ca);
+ }
return;
+ }
}
map_rect_destroy(displaylist->mr);
}
@@ -3170,6 +3293,15 @@ static void do_draw(struct displaylist *displaylist, int cancel, int flags) {
displaylist->msh=NULL;
profile(1,"callback\n");
callback_call_1(displaylist->cb, cancel);
+ /* check if we can shrink item buffer next time */
+ if((displaylist->dc.maxlen > ALLOCA_COORD_LIMIT) && (used < ALLOCA_COORD_LIMIT)) {
+ dbg(lvl_debug, "Shrink memory. %d actually used", used);
+ displaylist->dc.maxlen=ALLOCA_COORD_LIMIT;
+ }
+ /* clean up if required */
+ if (need_free) {
+ g_free(ca);
+ }
profile(0,"end\n");
}
@@ -3336,7 +3468,7 @@ void graphics_displaylist_close(struct displaylist_handle *dlh) {
struct displaylist * graphics_displaylist_new(void) {
struct displaylist *ret=g_new0(struct displaylist, 1);
- ret->dc.maxlen=16384;
+ ret->dc.maxlen=ALLOCA_COORD_LIMIT;
return ret;
}
@@ -3503,18 +3635,28 @@ static int within_dist_polygon(struct point *p, struct point *poly_pnt, int coun
*/
int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p,
int dist) {
- struct point *pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen);
+ int result;
+ struct point *pa;
int count;
+ if (displaylist->dc.maxlen < ALLOCA_COORD_LIMIT) {
+ pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen);
+ } else {
+ pa=g_malloc(sizeof(struct point)*displaylist->dc.maxlen);
+ }
count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 0, 0, NULL);
if (di->item.type < type_line) {
- return within_dist_point(p, &pa[0], dist);
- }
- if (di->item.type < type_area) {
- return within_dist_polyline(p, pa, count, dist, 0);
+ result = within_dist_point(p, &pa[0], dist);
+ } else if (di->item.type < type_area) {
+ result = within_dist_polyline(p, pa, count, dist, 0);
+ } else
+ result = within_dist_polygon(p, pa, count, dist);
+
+ if (displaylist->dc.maxlen >= ALLOCA_COORD_LIMIT) {
+ g_free(pa);
}
- return within_dist_polygon(p, pa, count, dist);
+ return result;
}
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index 99361011c..1c6f0e685 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -92,7 +92,6 @@ void qt5_navit_timer::timerEvent(QTimerEvent* event) {
qt5_navit_timer* qt5_timer = NULL;
static void event_qt5_main_loop_run(void) {
-
dbg(lvl_debug, "enter");
if (navit_app != NULL)
navit_app->exec();
diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
index 423f3d5fb..b293b2a56 100644
--- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
+++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
@@ -39,17 +39,17 @@ static void overlay_rect(struct graphics_priv *parent, struct graphics_priv *ove
struct point p;
int w,h;
if (clean) {
- p=overlay->pclean;
+ p = overlay->pclean;
} else {
- p=overlay->p;;
+ p = overlay->p;;
}
- w=overlay->widget->pixmap->width();
- h=overlay->widget->pixmap->height();
+ w = overlay->widget->pixmap->width();
+ h = overlay->widget->pixmap->height();
if (overlay->wraparound) {
if (p.x < 0)
- p.x+=parent->widget->pixmap->width();
+ p.x += parent->widget->pixmap->width();
if (p.y < 0)
- p.y+=parent->widget->pixmap->height();
+ p.y += parent->widget->pixmap->height();
if (w < 0)
w += parent->widget->pixmap->width();
if (h < 0)
@@ -77,9 +77,9 @@ void qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev) {
}
QPixmap pixmap(r->width(),r->height());
QPainter painter(&pixmap);
- struct graphics_priv *overlay=NULL;
+ struct graphics_priv *overlay = NULL;
if (! gr->overlay_disable)
- overlay=gr->overlays;
+ overlay = gr->overlays;
if ((gr->p.x || gr->p.y) && gr->background_gc) {
painter.setPen(*gr->background_gc->pen);
painter.fillRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height(), *gr->background_gc->brush);
@@ -90,17 +90,17 @@ void qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev) {
overlay_rect(gr, overlay, 0, &ovr);
if (!overlay->overlay_disable && r->intersects(ovr)) {
unsigned char *data;
- int i,size=ovr.width()*ovr.height();
- QImage img=overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
+ int i,size = ovr.width()*ovr.height();
+ QImage img = overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ data = img.bits();
for (i = 0 ; i < size ; i++) {
if (data[0] == overlay->rgba[0] && data[1] == overlay->rgba[1] && data[2] == overlay->rgba[2])
- data[3]=overlay->rgba[3];
- data+=4;
+ data[3] = overlay->rgba[3];
+ data += 4;
}
painter.drawImage(QPoint(ovr.x()-r->x(),ovr.y()-r->y()), img);
}
- overlay=overlay->next;
+ overlay = overlay->next;
}
#ifndef QT_QPAINTER_NO_WIDGET
QPainter painterw(gr->widget);
@@ -153,7 +153,6 @@ static void graphics_destroy(struct graphics_priv *gr) {
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static void font_destroy(struct graphics_font_priv *font) {
-
}
//##############################################################################################################
@@ -170,10 +169,11 @@ static struct graphics_font_methods font_methods = {
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *fontfamily, int size, int flags) {
- struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
- ret->font=new QFont("Arial",size/20);
- *meth=font_methods;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth,
+ char *fontfamily, int size, int flags) {
+ struct graphics_font_priv *ret = g_new0(struct graphics_font_priv, 1);
+ ret->font = new QFont("Arial",size/20);
+ *meth = font_methods;
return ret;
}
@@ -214,7 +214,7 @@ static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8 /* , c->a >> 8 */);
gc->pen->setColor(col);
gc->brush->setColor(col);
- gc->c=*c;
+ gc->c = *c;
}
//##############################################################################################################
@@ -244,10 +244,10 @@ static struct graphics_gc_methods gc_methods = {
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
- *meth=gc_methods;
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- ret->pen=new QPen();
- ret->brush=new QBrush(Qt::SolidPattern);
+ *meth = gc_methods;
+ struct graphics_gc_priv *ret = g_new0(struct graphics_gc_priv, 1);
+ ret->pen = new QPen();
+ ret->brush = new QBrush(Qt::SolidPattern);
return ret;
}
@@ -256,14 +256,15 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation) {
+static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path,
+ int *w, int *h, struct point *hot, int rotation) {
struct graphics_image_priv *ret;
QPixmap *cachedPixmap;
QString key(path);
- ret=g_new0(struct graphics_image_priv, 1);
+ ret = g_new0(struct graphics_image_priv, 1);
- cachedPixmap=QPixmapCache::find(key);
+ cachedPixmap = QPixmapCache::find(key);
if (!cachedPixmap) {
#ifdef HAVE_QT_SVG
if(key.endsWith(".svg", Qt::CaseInsensitive)) {
@@ -272,18 +273,15 @@ static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct g
g_free(ret);
return NULL;
}
- ret->pixmap=new QPixmap(renderer.defaultSize());
+ ret->pixmap = new QPixmap(renderer.defaultSize());
ret->pixmap->fill(Qt::transparent);
QPainter painter(ret->pixmap);
renderer.render(&painter);
-
} else {
-
- ret->pixmap=new QPixmap(path);
-
+ ret->pixmap = new QPixmap(path);
}
#else
- ret->pixmap=new QPixmap(path);
+ ret->pixmap = new QPixmap(path);
#endif /* QT__VERSION */
if (ret->pixmap->isNull()) {
g_free(ret);
@@ -292,14 +290,14 @@ static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct g
QPixmapCache::insert(key,QPixmap(*ret->pixmap));
} else {
- ret->pixmap=new QPixmap(*cachedPixmap);
+ ret->pixmap = new QPixmap(*cachedPixmap);
}
- *w=ret->pixmap->width();
- *h=ret->pixmap->height();
+ *w = ret->pixmap->width();
+ *h = ret->pixmap->height();
if (hot) {
- hot->x=*w/2;
- hot->y=*h/2;
+ hot->x = *w/2;
+ hot->y = *h/2;
}
return ret;
@@ -354,7 +352,6 @@ static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc
static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
gr->painter->setPen(*gc->pen);
gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16);
-
}
//##############################################################################################################
@@ -362,12 +359,13 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
- QPainter *painter=gr->painter;
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ QPainter *painter = gr->painter;
#ifndef QT_QPAINTER_USE_FREETYPE
- QString tmp=QString::fromUtf8(text);
+ QString tmp = QString::fromUtf8(text);
#ifndef QT_NO_TRANSFORMATIONS
- QMatrix sav=gr->painter->worldMatrix();
+ QMatrix sav = gr->painter->worldMatrix();
QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y);
painter->setWorldMatrix(m,TRUE);
painter->setPen(*fg->pen);
@@ -383,48 +381,48 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
struct font_freetype_text *t;
struct font_freetype_glyph *g, **gp;
struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000};
- struct color *fgc=&fg->c, *bgc=&bg->c;
+ struct color *fgc = &fg->c, *bgc = &bg->c;
int i,x,y;
if (! font)
return;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
+ t = gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ x = p->x << 6;
+ y = p->y << 6;
+ gp = t->glyph;
+ i = t->glyph_count;
if (bg) {
while (i-- > 0) {
- g=*gp++;
+ g = *gp++;
if (g->w && g->h) {
unsigned char *data;
QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
+ data = img.bits();
gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent);
painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img);
}
- x+=g->dx;
- y+=g->dy;
+ x += g->dx;
+ y += g->dy;
}
} else
- bgc=&transparent;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
+ bgc = &transparent;
+ x = p->x << 6;
+ y = p->y << 6;
+ gp = t->glyph;
+ i = t->glyph_count;
while (i-- > 0) {
- g=*gp++;
+ g = *gp++;
if (g->w && g->h) {
unsigned char *data;
QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
+ data = img.bits();
gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent);
painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img);
}
- x+=g->dx;
- y+=g->dy;
+ x += g->dx;
+ y += g->dy;
}
gr->freetype_methods.text_destroy(t);
#endif
@@ -435,20 +433,21 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
}
static void draw_drag(struct graphics_priv *gr, struct point *p) {
if (!gr->cleanup) {
- gr->pclean=gr->p;
- gr->cleanup=1;
+ gr->pclean = gr->p;
+ gr->cleanup = 1;
}
if (p)
- gr->p=*p;
+ gr->p = *p;
else {
- gr->p.x=0;
- gr->p.y=0;
+ gr->p.x = 0;
+ gr->p.y = 0;
}
}
@@ -458,11 +457,11 @@ static void draw_drag(struct graphics_priv *gr, struct point *p) {
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
- gr->background_gc=gc;
- gr->rgba[2]=gc->c.r >> 8;
- gr->rgba[1]=gc->c.g >> 8;
- gr->rgba[0]=gc->c.b >> 8;
- gr->rgba[3]=gc->c.a >> 8;
+ gr->background_gc = gc;
+ gr->rgba[2] = gc->c.r >> 8;
+ gr->rgba[1] = gc->c.g >> 8;
+ gr->rgba[0] = gc->c.b >> 8;
+ gr->rgba[3] = gc->c.a >> 8;
}
@@ -486,7 +485,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
if (gr->cleanup) {
overlay_rect(gr->parent, gr, 1, &r);
qt_qpainter_draw(gr->parent, &r, 0);
- gr->cleanup=0;
+ gr->cleanup = 0;
}
overlay_rect(gr->parent, gr, 0, &r);
qt_qpainter_draw(gr->parent, &r, 0);
@@ -498,7 +497,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
QCoreApplication::processEvents(
QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
}
- gr->mode=mode;
+ gr->mode = mode;
}
//##############################################################################################################
@@ -509,17 +508,17 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
int w, int h,int wraparound);
-static int argc=1;
-static char *argv[]= {NULL,NULL,NULL};
+static int argc = 1;
+static char *argv[] = {NULL,NULL,NULL};
static int fullscreen(struct window *win, int on) {
#ifndef QT_QPAINTER_NO_WIDGET
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ struct graphics_priv *this_ = (struct graphics_priv *)win->priv;
QWidget* _outerWidget;
#ifdef QT_QPAINTER_USE_EMBEDDING
- _outerWidget=(QWidget*)this_->widget->parent();
+ _outerWidget = (QWidget*)this_->widget->parent();
#else
- _outerWidget=this_->widget;
+ _outerWidget = this_->widget;
#endif /* QT_QPAINTER_USE_EMBEDDING */
if (on)
_outerWidget->showFullScreen();
@@ -531,7 +530,7 @@ static int fullscreen(struct window *win, int on) {
static void disable_suspend(struct window *win) {
#ifdef HAVE_QPE
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ struct graphics_priv *this_ = (struct graphics_priv *)win->priv;
this_->app->setTempScreenSaverMode(QPEApplication::DisableLightOff);
#endif
}
@@ -556,11 +555,11 @@ static void * get_data(struct graphics_priv *this_, const char *type) {
if (!strcmp(type, "qt_pixmap"))
return this_->widget->pixmap;
if (!strcmp(type, "window")) {
- win=g_new(struct window, 1);
+ win = g_new(struct window, 1);
#ifndef QT_QPAINTER_NO_WIDGET
#ifdef QT_QPAINTER_USE_EMBEDDING
- EmbeddedWidget* _outerWidget=new EmbeddedWidget(this_,this_->widget,NULL);
- xid=getenv("NAVIT_XID");
+ EmbeddedWidget* _outerWidget = new EmbeddedWidget(this_,this_->widget,NULL);
+ xid = getenv("NAVIT_XID");
if (xid.length()>0) {
_outerWidget->embedInto(xid.toULong(&ok,0));
}
@@ -571,9 +570,9 @@ static void * get_data(struct graphics_priv *this_, const char *type) {
else
this_->widget->showMaximized();
#endif /* QT_QPAINTER_NO_WIDGET */
- win->priv=this_;
- win->fullscreen=fullscreen;
- win->disable_suspend=disable_suspend;
+ win->priv = this_;
+ win->fullscreen = fullscreen;
+ win->disable_suspend = disable_suspend;
return win;
}
return NULL;
@@ -584,19 +583,20 @@ static void image_free(struct graphics_priv *gr, struct graphics_image_priv *pri
g_free(priv);
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate) {
- QPainter *painter=gr->painter;
- QString tmp=QString::fromUtf8(text);
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
+ QPainter *painter = gr->painter;
+ QString tmp = QString::fromUtf8(text);
painter->setFont(*font->font);
- QRect r=painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
- ret[0].x=0;
- ret[0].y=-r.height();
- ret[1].x=0;
- ret[1].y=0;
- ret[2].x=r.width();
- ret[2].y=0;
- ret[3].x=r.width();
- ret[3].y=-r.height();
+ QRect r = painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
+ ret[0].x = 0;
+ ret[0].y = -r.height();
+ ret[1].x = 0;
+ ret[1].y = 0;
+ ret[2].x = r.width();
+ ret[2].y = 0;
+ ret[3].x = r.width();
+ ret[3].y = -r.height();
}
@@ -606,7 +606,7 @@ static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *f
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static void overlay_disable(struct graphics_priv *gr, int disable) {
- gr->overlay_disable=disable;
+ gr->overlay_disable = disable;
}
//##############################################################################################################
@@ -617,14 +617,14 @@ static void overlay_disable(struct graphics_priv *gr, int disable) {
static int set_attr(struct graphics_priv *gr, struct attr *attr) {
switch (attr->type) {
case attr_w:
- gr->w=attr->u.num;
+ gr->w = attr->u.num;
if (gr->w != 0 && gr->h != 0) {
QSize size(gr->w,gr->h);
gr->widget->do_resize(size);
}
break;
case attr_h:
- gr->h=attr->u.num;
+ gr->h = attr->u.num;
if (gr->w != 0 && gr->h != 0) {
QSize size(gr->w,gr->h);
gr->widget->do_resize(size);
@@ -672,26 +672,27 @@ static struct graphics_methods graphics_methods = {
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound) {
- *meth=graphics_methods;
- struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h,int wraparound) {
+ *meth = graphics_methods;
+ struct graphics_priv *ret = g_new0(struct graphics_priv, 1);
#ifdef QT_QPAINTER_USE_FREETYPE
if (gr->font_freetype_new) {
- ret->font_freetype_new=gr->font_freetype_new;
+ ret->font_freetype_new = gr->font_freetype_new;
gr->font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
- int))ret->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
}
#endif
- ret->widget= new RenderArea(ret,gr->widget,w,h,1);
- ret->wraparound=wraparound;
- ret->painter=new QPainter;
- ret->p=*p;
- ret->parent=gr;
- ret->next=gr->overlays;
- gr->overlays=ret;
+ ret->widget = new RenderArea(ret,gr->widget,w,h,1);
+ ret->wraparound = wraparound;
+ ret->painter = new QPainter;
+ ret->p = *p;
+ ret->parent = gr;
+ ret->next = gr->overlays;
+ gr->overlays = ret;
#ifndef QT_QPAINTER_NO_WIDGET
ret->widget->hide();
#endif
@@ -714,11 +715,11 @@ static void event_qt_main_loop_quit(void) {
static struct event_watch *event_qt_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
dbg(lvl_debug,"enter fd=%d",(int)(long)fd);
- struct event_watch *ret=g_new0(struct event_watch, 1);
- ret->fd=fd;
- ret->cb=cb;
+ struct event_watch *ret = g_new0(struct event_watch, 1);
+ ret->fd = fd;
+ ret->cb = cb;
g_hash_table_insert(event_gr->widget->watches, GINT_TO_POINTER(fd), ret);
- ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
+ ret->sn = new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
QObject::connect(ret->sn, SIGNAL(activated(int)), event_gr->widget, SLOT(watchEvent(int)));
return ret;
}
@@ -727,12 +728,11 @@ static void event_qt_remove_watch(struct event_watch *ev) {
g_hash_table_remove(event_gr->widget->watches, GINT_TO_POINTER(ev->fd));
delete(ev->sn);
g_free(ev);
-
}
static struct event_timeout *event_qt_add_timeout(int timeout, int multi, struct callback *cb) {
int id;
- id=event_gr->widget->startTimer(timeout);
+ id = event_gr->widget->startTimer(timeout);
g_hash_table_insert(event_gr->widget->timer_callback, (void *)id, cb);
g_hash_table_insert(event_gr->widget->timer_type, (void *)id, (void *)!!multi);
return (struct event_timeout *)id;
@@ -776,7 +776,7 @@ struct event_priv {
struct event_priv *
event_qt_new(struct event_methods *meth) {
dbg(lvl_debug,"enter");
- *meth=event_qt_methods;
+ *meth = event_qt_methods;
return NULL;
}
#endif
@@ -786,7 +786,8 @@ event_qt_new(struct event_methods *meth) {
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth,
+ struct attr **attrs, struct callback_list *cbl) {
struct graphics_priv *ret;
struct font_priv * (*font_freetype_new)(void *meth);
struct attr *attr;
@@ -803,36 +804,36 @@ static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct
return NULL;
#endif
#ifdef QT_QPAINTER_USE_FREETYPE
- font_freetype_new=(struct font_priv *(*)(void *))plugin_get_category_font("freetype");
+ font_freetype_new = (struct font_priv *(*)(void *))plugin_get_category_font("freetype");
if (!font_freetype_new) {
dbg(lvl_error,"no freetype");
return NULL;
}
#endif
- ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- ret->nav=nav;
+ ret = g_new0(struct graphics_priv, 1);
+ *meth = graphics_methods;
+ ret->nav = nav;
#ifdef QT_QPAINTER_USE_FREETYPE
- ret->font_freetype_new=font_freetype_new;
+ ret->font_freetype_new = font_freetype_new;
font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
- int))ret->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
#endif
#if defined QT_QPAINTER_USE_EMBEDDING && QT_VERSION >= 0x040500
- if ((attr=attr_search(attrs, NULL, attr_gc_type)))
+ if ((attr = attr_search(attrs, NULL, attr_gc_type)))
QApplication::setGraphicsSystem(attr->u.str);
else
QApplication::setGraphicsSystem("raster");
#endif
- argv[0]=(char*)malloc(255);
+ argv[0] = (char*)malloc(255);
strcpy(argv[0], "navit");
- if ((attr=attr_search(attrs, NULL, attr_flags)))
- ret->flags=attr->u.num;
+ if ((attr = attr_search(attrs, NULL, attr_flags)))
+ ret->flags = attr->u.num;
if (ret->flags & 1) {
- argv[1]=(char*)malloc(255);
+ argv[1] = (char*)malloc(255);
strcpy(argv[1], "-qws");
argc++;
}
@@ -843,22 +844,22 @@ static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct
ret->app = new QApplication(argc, argv);
#endif
#endif
- ret->widget= new RenderArea(ret);
- ret->widget->cbl=cbl;
+ ret->widget = new RenderArea(ret);
+ ret->widget->cbl = cbl;
ret->painter = new QPainter;
#ifdef QT_QPAINTER_USE_EVENT_QT
- event_gr=ret;
+ event_gr = ret;
#endif
- ret->w=800;
- ret->h=600;
- if ((attr=attr_search(attrs, NULL, attr_w)))
- ret->w=attr->u.num;
+ ret->w = 800;
+ ret->h = 600;
+ if ((attr = attr_search(attrs, NULL, attr_w)))
+ ret->w = attr->u.num;
if ((attr=attr_search(attrs, NULL, attr_h)))
- ret->h=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_window_title)))
- ret->window_title=g_strdup(attr->u.str);
+ ret->h = attr->u.num;
+ if ((attr = attr_search(attrs, NULL, attr_window_title)))
+ ret->window_title = g_strdup(attr->u.str);
else
- ret->window_title=g_strdup("Navit");
+ ret->window_title = g_strdup("Navit");
dbg(lvl_debug,"return");
return ret;
diff --git a/navit/gui/qml/gui_qml.cpp b/navit/gui/qml/gui_qml.cpp
index 8c6f232f8..764319e78 100644
--- a/navit/gui/qml/gui_qml.cpp
+++ b/navit/gui/qml/gui_qml.cpp
@@ -97,7 +97,6 @@ class NGQMainWindow : public QX11EmbedWidget {
class NGQMainWindow : public QWidget {
#endif /* Q_WS_X11 */
public:
-
#ifdef Q_WS_X11
NGQMainWindow(struct gui_priv* this_,QWidget *parent) : QX11EmbedWidget(parent) {
#else
diff --git a/navit/gui/qml/vehicleProxy.h b/navit/gui/qml/vehicleProxy.h
index 483a1837b..f5ebdad68 100644
--- a/navit/gui/qml/vehicleProxy.h
+++ b/navit/gui/qml/vehicleProxy.h
@@ -16,7 +16,6 @@ protected:
void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); };
private:
-
};
#include "vehicleProxy.moc"
diff --git a/navit/gui/qt5_qml/backend.cpp b/navit/gui/qt5_qml/backend.cpp
index 4b83bad32..7a455c2a6 100644
--- a/navit/gui/qt5_qml/backend.cpp
+++ b/navit/gui/qt5_qml/backend.cpp
@@ -231,7 +231,6 @@ void Backend::get_pois() {
item_coord_get_pro(item, &c, 1, pro) &&
coord_rect_contains(&sel->u.c_rect, &c) &&
(idist=transform_distance(pro, &center, &c)) < dist) {
-
struct attr attr;
char * label;
char * icon = get_icon(this->nav, item);
@@ -564,7 +563,6 @@ void Backend::setSearchContext(QString text) {
} else {
dbg(lvl_error, "Unhandled search context '%s'", text.toUtf8().data());
}
-
}
QString Backend::currentCountry() {
diff --git a/navit/iphone/downloader/Classes/DownloaderDetailViewController.h b/navit/iphone/downloader/Classes/DownloaderDetailViewController.h
index a7238e8ed..33c397304 100644
--- a/navit/iphone/downloader/Classes/DownloaderDetailViewController.h
+++ b/navit/iphone/downloader/Classes/DownloaderDetailViewController.h
@@ -10,11 +10,8 @@
@interface DownloaderDetailViewController : UIViewController {
-
@private
- NSDictionary *locationName_;
-
-
+ NSDictionary *locationName_;
}
@property(nonatomic, retain) NSDictionary *locationName;
diff --git a/navit/item.c b/navit/item.c
index c17f31f8b..ab590cb4e 100644
--- a/navit/item.c
+++ b/navit/item.c
@@ -165,6 +165,22 @@ int item_coord_get(struct item *it, struct coord *c, int count) {
}
/**
+ * @brief Gets the number of coordinates left for this item
+ *
+ * This function returnes the number of coordinates left to get for this item. It does not
+ * change the "coordinates pointer".
+ *
+ * @param it The map item
+ * @returns The number of coordinates left. -1 if not supported by the actual map.
+ */
+int item_coords_left(struct item * it) {
+ if(!it->meth->item_coords_left) {
+ return (-1);
+ }
+ return it->meth->item_coords_left(it->priv_data);
+}
+
+/**
* @brief Sets coordinates of an item
*
* This function supports different modes:
@@ -195,33 +211,69 @@ int item_coord_set(struct item *it, struct coord *c, int count, enum change_mode
return it->meth->item_coord_set(it->priv_data, c, count, mode);
}
+/**
+ * @brief Get coordinates within selection
+ * This function returns the coordinates of an item if at least one coordinate of that item is inside the
+ * selection. If the given buffer is too small, it returns the buffer size if at least one coordinate
+ * intersects with the selection, otherwise it returnes 0
+ *
+ * If the return value equals count, the content of c is undefined.
+ *
+ * @param it requested item
+ * @param c preallocated buffer for the result
+ * @param count number of coordinates in c
+ * @param sel current map selection
+ * @return number of coordinates read to c, or count if out of space, or 0 if not intersecting, or <0 on read error.
+ */
int item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel) {
- int i,ret=it->meth->item_coord_get(it->priv_data, c, count);
- struct coord_rect r;
- struct map_selection *curr;
- if (ret <= 0 || !sel)
- return ret;
- r.lu=c[0];
- r.rl=c[0];
- for (i = 1 ; i < ret ; i++) {
- if (r.lu.x > c[i].x)
- r.lu.x=c[i].x;
- if (r.rl.x < c[i].x)
- r.rl.x=c[i].x;
- if (r.rl.y > c[i].y)
- r.rl.y=c[i].y;
- if (r.lu.y < c[i].y)
- r.lu.y=c[i].y;
- }
- curr=sel;
- while (curr) {
- struct coord_rect *sr=&curr->u.c_rect;
- if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
- r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
- return ret;
- curr=curr->next;
+ int in_coords;
+ int ret = 0;
+ struct coord_rect bbox;
+ int intersects=0;
+
+ /* scan all coordinates. Even if buffer is too small */
+ while ((in_coords=item_coord_get(it, c, count)) > 0) {
+ int i;
+ struct map_selection *curr;
+ /* update ret */
+ if(ret == 0) {
+ ret=in_coords;
+ /* init bbox */
+ bbox.lu=c[0];
+ bbox.rl=c[0];
+ }
+
+ /* update bbox */
+ for (i = 0 ; i < in_coords ; i++) {
+ if (bbox.lu.x > c[i].x)
+ bbox.lu.x=c[i].x;
+ if (bbox.rl.x < c[i].x)
+ bbox.rl.x=c[i].x;
+ if (bbox.rl.y > c[i].y)
+ bbox.rl.y=c[i].y;
+ if (bbox.lu.y < c[i].y)
+ bbox.lu.y=c[i].y;
+ }
+ /* check if bbox intersects already with selection */
+ curr=sel;
+ while ((!intersects) && (curr)) {
+ struct coord_rect *sr=&curr->u.c_rect;
+ if (bbox.lu.x <= sr->rl.x && bbox.rl.x >= sr->lu.x &&
+ bbox.lu.y >= sr->rl.y && bbox.rl.y <= sr->lu.y)
+ intersects=1;
+ curr=curr->next;
+ }
+
+ /* abort on the special case to read only one coord. */
+ if(count == 1)
+ break;
+ /* we can abort if already intersecting. */
+ if(intersects)
+ break;
}
- return 0;
+ if(!intersects)
+ ret=0;
+ return ret;
}
/**
diff --git a/navit/item.h b/navit/item.h
index 0d0e84c7f..26c83cd72 100644
--- a/navit/item.h
+++ b/navit/item.h
@@ -83,6 +83,7 @@ struct item_methods {
int (*item_attr_set)(void *priv_data, struct attr *attr, enum change_mode mode);
int (*item_coord_set)(void *priv_data, struct coord *c, int count, enum change_mode mode);
int (*item_type_set)(void *priv_data, enum item_type type);
+ int (*item_coords_left)(void *priv_data);
};
struct item_id {
@@ -127,6 +128,7 @@ void item_create_hash(void);
void item_destroy_hash(void);
int *item_get_default_flags(enum item_type type);
void item_coord_rewind(struct item *it);
+int item_coords_left(struct item * it);
int item_coord_get(struct item *it, struct coord *c, int count);
int item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode);
int item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel);
diff --git a/navit/map.h b/navit/map.h
index df8f9bf4e..78521bccf 100644
--- a/navit/map.h
+++ b/navit/map.h
@@ -89,8 +89,7 @@ struct map_methods {
struct item * (*map_search_get_item)(struct map_search_priv *ms); /**< Function to get the next item of a search on the map, ignored if `map_search_new` is NULL */
struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type); /**< Function to create a new item in the map */
int (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr); /**< Function to get a map attribute, can be NULL */
- int (*map_set_attr)(struct map_priv *priv, struct attr *attr); /**< Function to set a map attribute, can be NULL */
-
+ int (*map_set_attr)(struct map_priv *priv, struct attr *attr); /**< Function to set a map attribute, can be NULL */
};
/**
diff --git a/navit/map/binfile/binfile.c b/navit/map/binfile/binfile.c
index 7cc707ac8..18a4166b1 100644
--- a/navit/map/binfile/binfile.c
+++ b/navit/map/binfile/binfile.c
@@ -454,6 +454,15 @@ static int binfile_coord_get(void *priv_data, struct coord *c, int count) {
}
/**
+ * @brief Get nuber of coords left for current item
+ *
+ * @param prv_data
+ */
+static int binfile_coords_left(void *priv_data) {
+ return binfile_coord_left(priv_data);
+}
+
+/**
* @brief
* @param
* @return
@@ -829,6 +838,8 @@ static struct item_methods methods_binfile = {
NULL,
binfile_attr_set,
binfile_coord_set,
+ NULL,
+ binfile_coords_left,
};
static void push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length) {
diff --git a/navit/speech/qt5_espeak/Qt5EspeakAudioOut.h b/navit/speech/qt5_espeak/Qt5EspeakAudioOut.h
index d7eb632fd..520163ad1 100644
--- a/navit/speech/qt5_espeak/Qt5EspeakAudioOut.h
+++ b/navit/speech/qt5_espeak/Qt5EspeakAudioOut.h
@@ -26,6 +26,7 @@
#include <QObject>
class Qt5EspeakAudioOut : public QObject {
Q_OBJECT
+
public:
/* Instantiate this. Parameters are the sample rate to use,
* and the category to sort this audio output to. Not all platforms
@@ -45,6 +46,8 @@ signals:
void call_resume(int state);
protected:
+ /* None */
+
private:
/* internal buffer */
QByteArray* data;
diff --git a/navit/vehicle/qt5/vehicle_qt5.cpp b/navit/vehicle/qt5/vehicle_qt5.cpp
index 9c613ca54..9daa2ecb9 100644
--- a/navit/vehicle/qt5/vehicle_qt5.cpp
+++ b/navit/vehicle/qt5/vehicle_qt5.cpp
@@ -38,7 +38,7 @@ extern "C" {
#include <time.h>
#include "vehicle_qt5.h"
-//#include "vehicle_qt5.moc"
+// #include "vehicle_qt5.moc"
#include <QDateTime>
/**
@@ -75,7 +75,6 @@ void QNavitGeoReceiver::satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&
}
void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) {
-
/* ignore stale view */
if (info.coordinate().isValid()) {
if (info.timestamp().toUTC().secsTo(QDateTime::currentDateTimeUtc()) > 20) {
@@ -120,17 +119,17 @@ void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) {
dbg(lvl_debug, "Got valid altitude (alt %f)", info.coordinate().altitude());
priv->height = info.coordinate().altitude();
}
- //dbg(lvl_debug, "Time %s", info.timestamp().toUTC().toString().toLatin1().data());
+ // dbg(lvl_debug, "Time %s", info.timestamp().toUTC().toString().toLatin1().data());
priv->fix_time = info.timestamp().toUTC().toTime_t();
callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- if(priv->have_coords != attr_position_valid_valid) {
+ if (priv->have_coords != attr_position_valid_valid) {
priv->have_coords = attr_position_valid_valid;
callback_list_call_attr_0(priv->cbl, attr_position_valid);
}
} else {
dbg(lvl_debug, "Got invalid coordinate");
callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
- if(priv->have_coords != attr_position_valid_invalid) {
+ if (priv->have_coords != attr_position_valid_invalid) {
priv->have_coords = attr_position_valid_invalid;
callback_list_call_attr_0(priv->cbl, attr_position_valid);
}
@@ -205,9 +204,9 @@ static int vehicle_qt5_position_attr_get(struct vehicle_priv* priv,
priv->fix_time = 0;
return 0;
}
- //dbg(lvl_debug,"Fix Time: %s", priv->fixiso8601);
+ // dbg(lvl_debug,"Fix Time: %s", priv->fixiso8601);
} else {
- //dbg(lvl_debug,"Fix Time: 0");
+ // dbg(lvl_debug,"Fix Time: 0");
return 0;
}
break;
@@ -239,7 +238,7 @@ static int vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr) {
break;
case attr_position_coord_geo:
priv->geo = *attr->u.coord_geo;
- if(priv->have_coords != attr_position_valid_valid) {
+ if (priv->have_coords != attr_position_valid_valid) {
priv->have_coords = attr_position_valid_valid;
callback_list_call_attr_0(priv->cbl, attr_position_valid);
}
@@ -282,7 +281,7 @@ static struct vehicle_priv* vehicle_qt5_new_qt5(struct vehicle_methods* meth,
} else {
dbg(lvl_debug, "Using %s", ret->source->sourceName().toLatin1().data());
ret->receiver = new QNavitGeoReceiver(NULL, ret);
- if(ret->satellites != NULL) {
+ if (ret->satellites != NULL) {
ret->satellites->setUpdateInterval(1000);
ret->satellites->startUpdates();
}