diff options
author | Stefan Wildemann <gta04@metalstrolche.de> | 2019-07-20 16:45:33 +0200 |
---|---|---|
committer | Stefan Wildemann <gta04@metalstrolche.de> | 2019-07-20 16:45:33 +0200 |
commit | 1103dc4026677ab164c5ffc20bb4fc693c9bea76 (patch) | |
tree | f06500fd4750e8d22032666e092f238ac31007ee | |
parent | 8ae995950a48dfcceb1b18c1148193059b4a6d81 (diff) | |
download | navit-1103dc4026677ab164c5ffc20bb4fc693c9bea76.tar.gz |
Unscale coordinates coming back from backend via callback.
Now it seems to be complete.
-rw-r--r-- | navit/callback.c | 12 | ||||
-rw-r--r-- | navit/callback.h | 2 | ||||
-rw-r--r-- | navit/graphics.c | 44 |
3 files changed, 58 insertions, 0 deletions
diff --git a/navit/callback.c b/navit/callback.c index c9ce5adea..edf594c3e 100644 --- a/navit/callback.c +++ b/navit/callback.c @@ -23,6 +23,7 @@ #include "debug.h" #include "callback.h" + struct callback { /* func has variable number of arguments, not (void), * but we must declare something... */ @@ -34,6 +35,8 @@ struct callback { }; struct callback_list { + callback_patch patch; + void * patch_context; GList *list; }; @@ -115,6 +118,13 @@ void callback_list_remove_destroy(struct callback_list *l, struct callback *cb) g_free(cb); } +void callback_list_add_patch_function (struct callback_list *l, callback_patch patch, void * context) { + if(!l) + return; + l->patch = patch; + l->patch_context = context; +} + void callback_call(struct callback *cb, int pcount, void **p) { int i; void *pf[8]; @@ -193,6 +203,8 @@ void callback_list_call_attr(struct callback_list *l, enum attr_type type, int p if (!l) { return; } + if(l->patch != NULL) + l->patch(l, type, pcount, p, l->patch_context); cbi=l->list; while (cbi) { diff --git a/navit/callback.h b/navit/callback.h index b0f4b9f81..c45735280 100644 --- a/navit/callback.h +++ b/navit/callback.h @@ -30,6 +30,7 @@ extern "C" { enum attr_type; struct callback; struct callback_list; +typedef void (*callback_patch) (struct callback_list *l, enum attr_type type, int pcount, void **p, void * context); struct callback_list *callback_list_new(void); struct callback *callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p); struct callback *callback_new_attr_args(void (*func)(void), enum attr_type type, int count, ...); @@ -41,6 +42,7 @@ void callback_list_add(struct callback_list *l, struct callback *cb); struct callback *callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p); void callback_list_remove(struct callback_list *l, struct callback *cb); void callback_list_remove_destroy(struct callback_list *l, struct callback *cb); +void callback_list_add_patch_function (struct callback_list *l, callback_patch patch, void * context); void callback_call(struct callback *cb, int pcount, void **p); void callback_call_args(struct callback *cb, int count, ...); void callback_list_call_attr(struct callback_list *l, enum attr_type type, int pcount, void **p); diff --git a/navit/graphics.c b/navit/graphics.c index bfc5e93aa..96f4acb47 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -277,6 +277,49 @@ void graphics_set_rect(struct graphics *gra, struct point_rect *pr) { } /** + * @brief unscale coordinates coming from the graphics backend via callback. + * + * @param l pointer to callback list + * @param pcount number of parameters attached to this callback + * @param p list of parameters + * @param context context handed over by callback_list_add_patch_function, gra in this case. + * @return nothing + */ +static void graphics_dpi_patch (struct callback_list *l, enum attr_type type, int pcount, void **p, void * context) { + /* this is black magic. We scaled all coordinates to the graphics backend + * to compensate screen dpi. Since the backends communicate back via the callback + * list, we hook this function to unscale the coordinates coming back to + * navit before actually calling the callbacks. + */ + struct graphics * gra; + gra = (struct graphics *) context; + if(gra == NULL) + return; + + if((type == attr_resize) && (pcount >= 2)) { + int w, h; + w = GPOINTER_TO_INT(p[0]); + h = GPOINTER_TO_INT(p[1]); + dbg(lvl_debug,"scaling attr_resize %d, %d, %d", pcount, w, h); + p[0] = GINT_TO_POINTER(graphics_dpi_unscale(gra,w)); + p[1] = GINT_TO_POINTER(graphics_dpi_unscale(gra,h)); + } + if((type == attr_button) && (pcount >=3)) { + struct point * pnt; + pnt = (struct point *) p[2]; + dbg(lvl_debug,"scaling attr_button %d, %d, %d", pcount, pnt->x, pnt->y); + *pnt = graphics_dpi_unscale_point(gra, pnt); + } + if((type == attr_motion) && (pcount >=1)) { + struct point * pnt; + pnt = (struct point *) p[0]; + dbg(lvl_debug,"scaling attr_motion %d, %d, %d", pcount, pnt->x, pnt->y); + *pnt = graphics_dpi_unscale_point(gra, pnt); + } + /* any more? attr_keypress doesn't come with coordinates */ +} + +/** * Creates a new graphics object * attr type required * @param <> @@ -304,6 +347,7 @@ struct graphics * graphics_new(struct attr *parent, struct attr **attrs) { this_->cbl=callback_list_new(); cbl_attr.type=attr_callback_list; cbl_attr.u.callback_list=this_->cbl; + callback_list_add_patch_function (this_->cbl, graphics_dpi_patch, (void*) this_); this_->attrs=attr_generic_add_attr(this_->attrs, &cbl_attr); this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, this_->attrs, this_->cbl); this_->brightness=0; |