summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWildemann Stefan <stefan.wildemann@corpuls.com>2019-07-17 14:39:35 +0200
committerWildemann Stefan <stefan.wildemann@corpuls.com>2019-07-17 14:39:35 +0200
commitddc94aa0699699e2c89db985ec8a12171f085ec5 (patch)
tree4418f4bd751d1b494978ccd9e4faf5239ab185ca
parentfac4e878cd273446db65e91db33a015fa0b92a0e (diff)
downloadnavit-ddc94aa0699699e2c89db985ec8a12171f085ec5.tar.gz
Prepare cursor scaling by bbox calculation
-rw-r--r--navit/graphics.c75
-rw-r--r--navit/graphics.h1
-rw-r--r--navit/vehicle.c27
3 files changed, 100 insertions, 3 deletions
diff --git a/navit/graphics.c b/navit/graphics.c
index 7a3c2800d..7580354df 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -2222,6 +2222,81 @@ static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *dis
}
}
+/**
+ * @brief alter a box to contain a point
+ *
+ * @param pt new point
+ * @param tl top left of existing box
+ * @param br bottom right of existing box
+ * @param width line width to assume at the point
+ * @returns nothing
+ */
+static void graphics_itemgra_add_point_to_bbox (const struct coord *pt, struct coord *tl, struct coord *br, int width) {
+ if (pt->x-width < tl->x)
+ tl->x = pt->x-width;
+ if (pt->x+width > br->x)
+ br->x = pt->x+width;
+ if (pt->y-width < tl->y)
+ tl->y = pt->y-width;
+ if (pt->y+width > br->y)
+ br->y = pt->y+width;
+}
+
+/**
+ * @brief get bounding box of a raw and unscaled itemgra.
+ *
+ * @param itm the itemgra
+ * @param tl top left coordinate of the itemgra. Needs to be properly initialized.
+ * @param br bottom right coordinate of the itemgra. Needs to be properly initialized.
+ * returns notinhg
+ */
+void graphics_itmgra_bbox(struct itemgra * itm, struct coord *tl, struct coord *br) {
+ GList *es;
+ if(!itm || !tl || !br)
+ return;
+
+ es = itm->elements;
+ while(es) {
+ struct element *e=es->data;
+ switch (e->type) {
+ case element_point:
+ if(e->coord_count > 0)
+ graphics_itemgra_add_point_to_bbox (&(e->coord[0]), tl, br, 0);
+ break;
+ case element_polyline:
+ case element_polygon:
+ if(e->coord_count > 0) {
+ int a;
+ int width = 0;
+ if(e->type == element_polyline)
+ width = e->u.polyline.width;
+ for(a=0; a < e->coord_count; a ++)
+ graphics_itemgra_add_point_to_bbox (&(e->coord[a]), tl, br,width);
+ }
+ break;
+ case element_circle:
+ if(e->coord_count > 0) {
+ struct coord box;
+ box.x = e->coord[0].x - e->u.circle.radius;
+ box.y = e->coord[0].y - e->u.circle.radius;
+ graphics_itemgra_add_point_to_bbox (&box, tl, br, e->u.circle.width);
+ box.x = e->coord[0].x + e->u.circle.radius;
+ box.y = e->coord[0].y + e->u.circle.radius;
+ graphics_itemgra_add_point_to_bbox (&box, tl, br, e->u.circle.width);
+ }
+ break;
+ case element_text:
+ case element_icon:
+ case element_image:
+ case element_arrows:
+ /* ignore */
+ dbg(lvl_error,"getting bbox for \"text, icon, image, arows\" not yet supported.");
+ break;
+ }
+ es=g_list_next(es);
+ }
+}
+
void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label) {
GList *es;
struct display_context dc;
diff --git a/navit/graphics.h b/navit/graphics.h
index 9271fd6ef..f92961354 100644
--- a/navit/graphics.h
+++ b/navit/graphics.h
@@ -271,6 +271,7 @@ int graphics_draw_drag(struct graphics *this_, struct point *p);
void graphics_background_gc(struct graphics *this_, struct graphics_gc *gc);
void graphics_draw_text_std(struct graphics *this_, int text_size, char *text, struct point *p);
char *graphics_icon_path(const char *icon);
+void graphics_itmgra_bbox(struct itemgra * itm, struct coord *tl, struct coord *br);
void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t, char *label);
void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans,
struct layout *l, int flags);
diff --git a/navit/vehicle.c b/navit/vehicle.c
index 67306c3d3..196051743 100644
--- a/navit/vehicle.c
+++ b/navit/vehicle.c
@@ -73,6 +73,8 @@ struct vehicle {
int need_resize;
int real_w;
int real_h;
+ struct coord tl;
+ struct coord br;
struct graphics *gra;
struct graphics_gc *bg;
struct transformation *trans;
@@ -331,6 +333,25 @@ void vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwr
this_->need_resize=1;
this_->cursor=cursor;
+ /* calculate the raw bounding box of the cursor*/
+ if (this_->cursor) {
+ struct attr **attr;
+ this_->tl.x = 0;
+ this_->tl.y = 0;
+ this_->br.x = 0;
+ this_->br.y = 0;
+ attr=cursor->attrs;
+ while (*attr) {
+ if ((*attr)->type == attr_itemgra) {
+ struct itemgra *itm=(*attr)->u.itemgra;
+ /* use all elements for outline regardless if speed or angle ranged */
+ graphics_itmgra_bbox(itm, &(this_->tl), &(this_->br));
+ }
+ ++attr;
+ }
+ dbg(lvl_debug,"got cursor bbox %d,%d %d,%d", this_->tl.x, this_->tl.y,this_->br.x, this_->br.y);
+ }
+
/* if the graphics was already created, but a NULL cursor was set, we need to disable
* otherwise stale overlay
*/
@@ -383,10 +404,10 @@ void vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt
sc.x = this_->real_w/2;
sc.y = this_->real_h/2;
transform_set_screen_center(this_->trans, &sc);
+ /*TODO: use the transformation to scale the cursor to fit inside the scaled surrounding.
+ * We already have the bbox in br / tl. */
+
}
- /*TODO: use the transformation to scale the cursor to fit inside the scaled surrounding.
- * to do this we need to scan all coordinates inside the cursor to get it's bounding box
- * in raw pixels. then we can scale it to fit */
/* move the cursor point from te center to the top left*/
this_->cursor_pnt.x-=(this_->real_w/2);