diff options
author | Wildemann Stefan <stefan.wildemann@corpuls.com> | 2019-07-15 18:15:33 +0200 |
---|---|---|
committer | Wildemann Stefan <stefan.wildemann@corpuls.com> | 2019-07-15 18:15:33 +0200 |
commit | 22588a095da32a2fbbf2db4b8eff303a29d53385 (patch) | |
tree | 3bcbfdb8a002a77756427b383062108251fc46c8 | |
parent | c2c5dc9ec25d95912144fa8176587f73484c1f27 (diff) | |
download | navit-22588a095da32a2fbbf2db4b8eff303a29d53385.tar.gz |
Completely apply the attr_w and attr_h and attr_x and attr_y changes.
-rw-r--r-- | navit/graphics.c | 15 | ||||
-rw-r--r-- | navit/graphics/egl/graphics_egl.c | 5 | ||||
-rw-r--r-- | navit/graphics/gd/graphics_gd.c | 30 | ||||
-rw-r--r-- | navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c | 51 | ||||
-rw-r--r-- | navit/graphics/opengl/graphics_opengl.c | 26 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 9 | ||||
-rw-r--r-- | navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp | 25 | ||||
-rw-r--r-- | navit/graphics/qt_qpainter/graphics_qt_qpainter.h | 47 | ||||
-rw-r--r-- | navit/graphics/sdl/graphics_sdl.c | 5 | ||||
-rw-r--r-- | navit/graphics/win32/graphics_win32.c | 9 | ||||
-rw-r--r-- | navit/layout.c | 21 | ||||
-rw-r--r-- | navit/layout.h | 126 | ||||
-rw-r--r-- | navit/osd.c | 52 | ||||
-rw-r--r-- | navit/osd.h | 4 | ||||
-rw-r--r-- | navit/vehicle.c | 32 |
15 files changed, 270 insertions, 187 deletions
diff --git a/navit/graphics.c b/navit/graphics.c index c69f62bbb..75cd08a06 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -2131,7 +2131,14 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display break; case element_icon: if (count) { + int x, y; + x = osd_rel2real(gra, &e->u.icon.x, 0, 0); + y = osd_rel2real(gra, &e->u.icon.y, 0, 0); if (!img || item_is_custom_poi(di->item)) { + int w, h; + //BUG: get maximum width for % usage + w = osd_rel2real(gra, &e->u.icon.width, 0, 0); + h = osd_rel2real(gra, &e->u.icon.height, 0, 0); if (item_is_custom_poi(di->item)) { char *icon; char *src; @@ -2145,7 +2152,7 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display g_free(icon); } else path=graphics_icon_path(e->u.icon.src); - img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation); + img=graphics_image_new_scaled_rotated(gra, path, w, h, e->u.icon.rotation); if (img) dc->img=img; else @@ -2153,9 +2160,9 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display g_free(path); } if (img) { - if (e->u.icon.x != -1 || e->u.icon.y != -1) { - p.x=pa[0].x - e->u.icon.x; - p.y=pa[0].y - e->u.icon.y; + if (x != -1 || y != -1) { + p.x=pa[0].x - x; + p.y=pa[0].y - y; } else { p.x=pa[0].x - img->hot.x; p.y=pa[0].y - img->hot.y; diff --git a/navit/graphics/egl/graphics_egl.c b/navit/graphics/egl/graphics_egl.c index 2da56047c..61fbca5a5 100644 --- a/navit/graphics/egl/graphics_egl.c +++ b/navit/graphics/egl/graphics_egl.c @@ -36,6 +36,7 @@ #include "callback.h" #include "keys.h" #include "window.h" +#include "osd.h" #include "navit/font/freetype/font_freetype.h" #include "SDL_image.h" @@ -1255,10 +1256,10 @@ static struct graphics_priv *graphics_opengl_new(struct navit *nav, struct graph this->width = SCREEN_WIDTH; if ((attr = attr_search(attrs, NULL, attr_w))) - this->width = attr->u.num; + this->width = attr->u.osd_display_coordinate->num; this->height = SCREEN_HEIGHT; if ((attr = attr_search(attrs, NULL, attr_h))) - this->height = attr->u.num; + this->height = attr->u.osd_display_coordinate->num; this->timeout = 100; if ((attr = attr_search(attrs, NULL, attr_timeout))) this->timeout = attr->u.num; diff --git a/navit/graphics/gd/graphics_gd.c b/navit/graphics/gd/graphics_gd.c index 7c8a45693..215271eff 100644 --- a/navit/graphics/gd/graphics_gd.c +++ b/navit/graphics/gd/graphics_gd.c @@ -31,6 +31,7 @@ #include "window.h" #include "navit.h" #include "debug.h" +#include "osd.h" #include "navit/font/freetype/font_freetype.h" @@ -279,7 +280,8 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics } -static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, 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 *name, + int *w, int *h, struct point *hot, int rotation) { FILE *file; struct graphics_image_priv *ret=NULL; gdImagePtr im=NULL; @@ -376,7 +378,8 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s } -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) { +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) { struct font_freetype_text *t; struct font_freetype_glyph *g, **gp; gdImagePtr im; @@ -428,7 +431,8 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str gr->freetype_methods.text_destroy(t); } -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) { gdImageCopy(gr->im, img->im, p->x, p->y, 0, 0, img->im->sx, img->im->sy); } @@ -507,7 +511,8 @@ 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 struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, + int w, int h, int wraparound); static void add_overlays(struct graphics_priv *overlay, gdImagePtr im) { while (overlay) { @@ -656,8 +661,8 @@ static int set_attr_do(struct graphics_priv *gr, struct attr *attr, int init) { char *s,*c,*n,*p; switch (attr->type) { case attr_w: - if (gr->w != attr->u.num) { - gr->w=attr->u.num; + if (gr->w != attr->u.osd_display_coordinate->num) { + gr->w=attr->u.osd_display_coordinate->num; if (!init) { if (gr->im) image_destroy(gr); @@ -667,8 +672,8 @@ static int set_attr_do(struct graphics_priv *gr, struct attr *attr, int init) { } break; case attr_h: - if (gr->h != attr->u.num) { - gr->h=attr->u.num; + if (gr->h != attr->u.osd_display_coordinate->num) { + gr->h=attr->u.osd_display_coordinate->num; if (!init) { if (gr->im) image_destroy(gr); @@ -756,7 +761,8 @@ static struct graphics_methods graphics_methods = { NULL, /* hide_native_keyboard */ }; -static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) { +static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, + int w, int h, int wraparound) { struct font_priv * (*font_freetype_new)(void *meth); struct graphics_priv *ret; @@ -784,7 +790,8 @@ static void emit_callback(struct graphics_priv *priv) { } -static struct graphics_priv *graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) { +static struct graphics_priv *graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, + struct callback_list *cbl) { struct font_priv * (*font_freetype_new)(void *meth); struct graphics_priv *ret; event_request_system("glib","graphics_gd_new"); @@ -794,7 +801,8 @@ static struct graphics_priv *graphics_gd_new(struct navit *nav, struct graphics_ *meth=graphics_methods; ret=g_new0(struct graphics_priv, 1); 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->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=ret->freetype_methods.get_text_bbox; ret->cb=callback_new_attr_1(callback_cast(emit_callback), attr_navit, ret); navit_add_callback(nav, ret->cb); diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c index b61ac2403..7df96f5c2 100644 --- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c +++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c @@ -50,6 +50,7 @@ #include "navit/font/freetype/font_freetype.h" #include "navit.h" #include <errno.h> +#include "osd.h" #ifndef GDK_Book #define GDK_Book XF86XK_Book @@ -181,7 +182,8 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics } -static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, 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 *name, + int *w, int *h, struct point *hot, int rotation) { GdkPixbuf *pixbuf; struct graphics_image_priv *ret; const char *option; @@ -310,7 +312,8 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s cairo_stroke(gr->cairo); } -static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride, unsigned char *buffer) { +static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, + int stride, unsigned char *buffer) { cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data( buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride); cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y); @@ -318,7 +321,8 @@ static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_h cairo_surface_destroy(buffer_surface); } -static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct point *p) { +static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, + struct graphics_gc_priv *bg, struct point *p) { int i,x,y,stride; struct font_freetype_glyph *g, **gp; struct color transparent= {0x0,0x0,0x0,0x0}; @@ -359,7 +363,8 @@ static void display_text_draw(struct font_freetype_text *text, struct graphics_p } } -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) { +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) { struct font_freetype_text *t; if (! font) { @@ -384,13 +389,15 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str gr->freetype_methods.text_destroy(t); } -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) { gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y); cairo_paint(gr->cairo); } #ifdef HAVE_IMLIB2 -static unsigned char* create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel, size_t output_stride) { +static unsigned char* create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, + size_t bytes_per_pixel, size_t output_stride) { int line; size_t input_offset, output_offset; unsigned char *out_buf; @@ -408,7 +415,8 @@ static unsigned char* create_buffer_with_stride_if_required(unsigned char *input return out_buf; } -static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img) { +static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, + struct graphics_image_priv *img) { int w,h; DATA32 *intermediate_buffer; unsigned char* intermediate_buffer_aligned; @@ -503,7 +511,8 @@ static void overlay_rect(struct graphics_priv *parent, struct graphics_priv *ove r->height += parent->height; } -static void overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo) { +static void overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, + cairo_t *cairo) { GdkRectangle or, ir; if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled) return; @@ -866,7 +875,8 @@ static int set_attr(struct graphics_priv *gr, struct attr *attr) { } } -static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) { +static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, + int w, int h, int wraparound) { int w2,h2; struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth); this->widget=gr->widget; @@ -965,6 +975,21 @@ static void *get_data(struct graphics_priv *this, char const *type) { return NULL; } +/** + * @brief Return number of dots per inch + * @param gr self handle + * @return dpi value + */ +static double get_dpi(struct graphics_priv * gr) { + gdouble dpi = 96; + GdkScreen *screen = gtk_widget_get_screen(gr->widget); + if(screen != NULL) { + dpi = gdk_screen_get_resolution (screen); + } + return (double) dpi; +} + + static struct graphics_methods graphics_methods = { graphics_destroy, draw_mode, @@ -993,6 +1018,7 @@ static struct graphics_methods graphics_methods = { set_attr, NULL, /* show_native_keyboard */ NULL, /* hide_native_keyboard */ + get_dpi, }; static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth) { @@ -1010,7 +1036,8 @@ static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphic return this; } -static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) { +static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, + struct attr **attrs, struct callback_list *cbl) { int i; GtkWidget *draw; struct attr *attr; @@ -1024,10 +1051,10 @@ static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, st this->widget=draw; this->win_w=792; if ((attr=attr_search(attrs, NULL, attr_w))) - this->win_w=attr->u.num; + this->win_w=attr->u.osd_display_coordinate->num; this->win_h=547; if ((attr=attr_search(attrs, NULL, attr_h))) - this->win_h=attr->u.num; + this->win_h=attr->u.osd_display_coordinate->num; this->timeout=100; if ((attr=attr_search(attrs, NULL, attr_timeout))) this->timeout=attr->u.num; diff --git a/navit/graphics/opengl/graphics_opengl.c b/navit/graphics/opengl/graphics_opengl.c index 2789061f1..e001f9d81 100644 --- a/navit/graphics/opengl/graphics_opengl.c +++ b/navit/graphics/opengl/graphics_opengl.c @@ -39,6 +39,7 @@ #include "callback.h" #include "keys.h" #include "window.h" +#include "osd.h" #include "navit/font/freetype/font_freetype.h" #include "graphics_opengl.h" @@ -352,7 +353,8 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics static struct graphics_image_priv image_error; -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) { #ifdef HAVE_FREEIMAGE FIBITMAP *image; RGBQUAD aPixel; @@ -797,7 +799,8 @@ static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc graphics_priv_root->dirty = 1; } -static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, int color, struct point *p) { +static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, + struct graphics_gc_priv *bg, int color, struct point *p) { int i, x, y, stride; struct font_freetype_glyph *g, **gp; unsigned char *shadow, *glyph; @@ -927,7 +930,8 @@ static void display_text_draw(struct font_freetype_text *text, struct graphics_p } } -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) { +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) { if ((gr->parent && !gr->parent->overlay_enabled) || (gr->parent && gr->parent->overlay_enabled && !gr->overlay_enabled)) { @@ -955,7 +959,8 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str } -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) { #ifdef USE_OPENGLES draw_image_es(gr, p, img->w, img->h, img->data); #else @@ -1159,7 +1164,8 @@ static void *get_data(struct graphics_priv *this, const char *type) { this->platform=graphics_opengl_egl_new(this->window_system_methods->get_display(this->window_system), this->window_system_methods->get_window(this->window_system), &this->platform_methods); - this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do, motion_notify_do, NULL); + this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do, + motion_notify_do, NULL); resize_callback(this->width,this->height); #if 0 glClearColor ( 0.4, 0.4, 0.4, 1); @@ -1398,7 +1404,8 @@ static void motion_notify(int x, int y) { static gboolean graphics_opengl_idle(void *data) { static int opengl_init_ok = 0; if (!opengl_init_ok) { - callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize, GINT_TO_POINTER (graphics_priv_root->width), GINT_TO_POINTER (graphics_priv_root->height)); + callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize, GINT_TO_POINTER (graphics_priv_root->width), + GINT_TO_POINTER (graphics_priv_root->height)); opengl_init_ok = 1; } else { @@ -1494,7 +1501,8 @@ static void glut_close(void) { } -static struct graphics_priv *graphics_opengl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) { +static struct graphics_priv *graphics_opengl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, + struct callback_list *cbl) { struct attr *attr; if (!event_request_system("glib", "graphics_opengl_new")) @@ -1509,10 +1517,10 @@ static struct graphics_priv *graphics_opengl_new(struct navit *nav, struct graph this->width = SCREEN_WIDTH; if ((attr = attr_search(attrs, NULL, attr_w))) - this->width = attr->u.num; + this->width = attr->u.osd_display_coordinate->num; this->height = SCREEN_HEIGHT; if ((attr = attr_search(attrs, NULL, attr_h))) - this->height = attr->u.num; + this->height = attr->u.osd_display_coordinate->num; this->timeout = 100; if ((attr = attr_search(attrs, NULL, attr_timeout))) this->timeout = attr->u.num; diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 5b6c62509..ec6448e16 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -35,6 +35,7 @@ extern "C" { #include "graphics.h" #include "plugin.h" #include "window.h" +#include "osd.h" } #include "event_qt5.h" @@ -1042,11 +1043,11 @@ static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics geomet = primary->availableGeometry(); } /* check for height */ - if ((h = attr_search(attrs, NULL, attr_h)) && (h->u.num > 100)) - geomet.setHeight(h->u.num); + if ((h = attr_search(attrs, NULL, attr_h)) && (h->u.osd_display_coordinate->num > 100)) + geomet.setHeight(h->u.osd_display_coordinate->num); /* check for width */ - if ((w = attr_search(attrs, NULL, attr_w)) && (w->u.num > 100)) - geomet.setWidth(w->u.num); + if ((w = attr_search(attrs, NULL, attr_w)) && (w->u.osd_display_coordinate->num > 100)) + geomet.setWidth(w->u.osd_display_coordinate->num); #if USE_QML if (graphics_priv->window != NULL) { graphics_priv->window->resize(geomet.width(), geomet.height()); diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp index 423f3d5fb..b02cabc9d 100644 --- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp +++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp @@ -170,7 +170,8 @@ 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) { +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; @@ -256,7 +257,8 @@ 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); @@ -362,7 +364,8 @@ 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) { +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); @@ -435,7 +438,8 @@ 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); } @@ -584,7 +588,8 @@ 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) { +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); @@ -617,14 +622,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.osd_display_coordinate->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.osd_display_coordinate->num; if (gr->w != 0 && gr->h != 0) { QSize size(gr->w,gr->h); gr->widget->do_resize(size); @@ -672,7 +677,8 @@ 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) { +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 @@ -786,7 +792,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; diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.h b/navit/graphics/qt_qpainter/graphics_qt_qpainter.h index 3b90689f0..7eb60f900 100644 --- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.h +++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.h @@ -34,6 +34,7 @@ #include "navit/window.h" #include "navit/keys.h" #include "navit/navit.h" +#include "navit/osd.h" #include <qglobal.h> #if QT_VERSION < 0x040000 @@ -92,9 +93,9 @@ class RenderArea; //# Authors: Martin Schaller (04/2008) //############################################################################################################## struct graphics_gc_priv { - QPen *pen; - QBrush *brush; - struct color c; + QPen *pen; + QBrush *brush; + struct color c; }; //############################################################################################################## @@ -104,34 +105,34 @@ struct graphics_gc_priv { //############################################################################################################## struct graphics_priv { #ifdef HAVE_QPE - QPEApplication *app; + QPEApplication *app; #else - QApplication *app; + QApplication *app; #endif - RenderArea *widget; - QPainter *painter; - struct graphics_gc_priv *background_gc; - unsigned char rgba[4]; - enum draw_mode_num mode; - struct graphics_priv *parent,*overlays,*next; - struct point p,pclean; - int cleanup; - int overlay_disable; - int wraparound; + RenderArea *widget; + QPainter *painter; + struct graphics_gc_priv *background_gc; + unsigned char rgba[4]; + enum draw_mode_num mode; + struct graphics_priv *parent,*overlays,*next; + struct point p,pclean; + int cleanup; + int overlay_disable; + int wraparound; #ifdef QT_QPAINTER_USE_FREETYPE - struct font_priv * (*font_freetype_new)(void *meth); - struct font_freetype_methods freetype_methods; + struct font_priv * (*font_freetype_new)(void *meth); + struct font_freetype_methods freetype_methods; #endif - int w,h,flags; - struct navit* nav; - char *window_title; + int w,h,flags; + struct navit* nav; + char *window_title; }; void qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev); struct event_watch { - QSocketNotifier *sn; - struct callback *cb; - int fd; + QSocketNotifier *sn; + struct callback *cb; + int fd; }; void event_qt_remove_timeout(struct event_timeout *ev); diff --git a/navit/graphics/sdl/graphics_sdl.c b/navit/graphics/sdl/graphics_sdl.c index 4187d4ed6..874fca7d4 100644 --- a/navit/graphics/sdl/graphics_sdl.c +++ b/navit/graphics/sdl/graphics_sdl.c @@ -32,6 +32,7 @@ #include "item.h" #include "attr.h" #include "callback.h" +#include "osd.h" #include "font/freetype/font_freetype.h" #include "SDL.h" @@ -1356,9 +1357,9 @@ static struct graphics_priv *graphics_sdl_new(struct navit *nav, struct graphics #endif if ((attr=attr_search(attrs, NULL, attr_w))) - w=attr->u.num; + w=attr->u.osd_display_coordinate->num; if ((attr=attr_search(attrs, NULL, attr_h))) - h=attr->u.num; + h=attr->u.osd_display_coordinate->num; if ((attr=attr_search(attrs, NULL, attr_bpp))) this->video_bpp=attr->u.num; if ((attr=attr_search(attrs, NULL, attr_flags))) { diff --git a/navit/graphics/win32/graphics_win32.c b/navit/graphics/win32/graphics_win32.c index 1c8172c7c..d46450e17 100644 --- a/navit/graphics/win32/graphics_win32.c +++ b/navit/graphics/win32/graphics_win32.c @@ -19,6 +19,7 @@ #include "support/win32/ConvertUTF.h" #include "profile.h" #include "keys.h" +#include "osd.h" #ifdef HAVE_API_WIN32_CE #include "libc.h" @@ -1521,16 +1522,16 @@ static struct graphics_priv* graphics_win32_new( struct navit *nav, struct graph this_->frame=attr->u.num; this_->x=0; if ((attr=attr_search(attrs, NULL, attr_x))) - this_->x=attr->u.num; + this_->x=attr->u.osd_display_coordinate->num; this_->y=0; if ((attr=attr_search(attrs, NULL, attr_y))) - this_->y=attr->u.num; + this_->y=attr->u.osd_display_coordinate->num; this_->width=792; if ((attr=attr_search(attrs, NULL, attr_w))) - this_->width=attr->u.num; + this_->width=attr->u.osd_display_coordinate->num; this_->height=547; if ((attr=attr_search(attrs, NULL, attr_h))) - this_->height=attr->u.num; + this_->height=attr->u.osd_display_coordinate->num; this_->overlays = NULL; this_->cbl=cbl; this_->parent = NULL; diff --git a/navit/layout.c b/navit/layout.c index f2f3d1a75..f09dc9b9e 100644 --- a/navit/layout.c +++ b/navit/layout.c @@ -26,6 +26,7 @@ #include "coord.h" #include "debug.h" #include "navit.h" +#include "osd.h" /** * @brief Create a new layout object and attach it to a navit parent @@ -188,8 +189,8 @@ cursor_new(struct attr *parent, struct attr **attrs) { return NULL; this=g_new0(struct cursor,1); - this->w=w->u.num; - this->h=h->u.num; + this->w=*(w->u.osd_display_coordinate); + this->h=*(h->u.osd_display_coordinate); name=attr_search(attrs, NULL, attr_name); if (name) this->name=g_strdup(name->u.str); @@ -534,21 +535,21 @@ icon_new(struct attr *parent, struct attr **attrs) { e->type=element_icon; e->u.icon.src=(char *)(e+1); if ((w=attr_search(attrs, NULL, attr_w))) - e->u.icon.width=w->u.num; + e->u.icon.width=*(w->u.osd_display_coordinate); else - e->u.icon.width=-1; + e->u.icon.width.num=-1; if ((h=attr_search(attrs, NULL, attr_h))) - e->u.icon.height=h->u.num; + e->u.icon.height=*(h->u.osd_display_coordinate); else - e->u.icon.height=-1; + e->u.icon.height.num=-1; if ((x=attr_search(attrs, NULL, attr_x))) - e->u.icon.x=x->u.num; + e->u.icon.x=*(x->u.osd_display_coordinate); else - e->u.icon.x=-1; + e->u.icon.x.num=-1; if ((y=attr_search(attrs, NULL, attr_y))) - e->u.icon.y=y->u.num; + e->u.icon.y=*(y->u.osd_display_coordinate); else - e->u.icon.y=-1; + e->u.icon.y.num=-1; if ((rotation=attr_search(attrs, NULL, attr_rotation))) e->u.icon.rotation=rotation->u.num; strcpy(e->u.icon.src,src->u.str); diff --git a/navit/layout.h b/navit/layout.h index ece5d0cc8..7e5ba137e 100644 --- a/navit/layout.h +++ b/navit/layout.h @@ -22,6 +22,8 @@ #include "item.h" #include "color.h" +#include "point.h" +#include "osd.h" #ifdef __cplusplus extern "C" { @@ -29,81 +31,81 @@ extern "C" { struct element { - enum { element_point, element_polyline, element_polygon, element_circle, element_text, element_icon, element_image, element_arrows } type; - struct color color; - int text_size; - union { - struct element_point { - char stub; - } point; - struct element_polyline { - int width; - int directed; - int dash_num; - int offset; - unsigned char dash_table[4]; - } polyline; - struct element_polygon { - char stub; - } polygon; - struct element_circle { - int width; - int radius; - struct color background_color; - } circle; - struct element_icon { - char *src; - int width; - int height; - int rotation; - int x; - int y; - } icon; - struct element_text { - struct color background_color; - } text; - } u; - int coord_count; - struct coord *coord; + enum { element_point, element_polyline, element_polygon, element_circle, element_text, element_icon, element_image, element_arrows } type; + struct color color; + int text_size; + union { + struct element_point { + char stub; + } point; + struct element_polyline { + int width; + int directed; + int dash_num; + int offset; + unsigned char dash_table[4]; + } polyline; + struct element_polygon { + char stub; + } polygon; + struct element_circle { + int width; + int radius; + struct color background_color; + } circle; + struct element_icon { + char *src; + struct osd_display_coordinate width; + struct osd_display_coordinate height; + int rotation; + struct osd_display_coordinate x; + struct osd_display_coordinate y; + } icon; + struct element_text { + struct color background_color; + } text; + } u; + int coord_count; + struct coord *coord; }; struct itemgra { - struct range order,sequence_range,speed_range,angle_range; - GList *type; - GList *elements; + struct range order,sequence_range,speed_range,angle_range; + GList *type; + GList *elements; }; struct layer { - NAVIT_OBJECT - struct navit *navit; - char *name; - int details; - GList *itemgras; - int active; - struct layer *ref; + NAVIT_OBJECT + struct navit *navit; + char *name; + int details; + GList *itemgras; + int active; + struct layer *ref; }; struct cursor { - struct attr **attrs; - struct range *sequence_range; - char *name; - int w,h; - int interval; + struct attr **attrs; + struct range *sequence_range; + char *name; + struct osd_display_coordinate w,h; + int interval; }; struct layout { - NAVIT_OBJECT - struct navit *navit; - char *name; - char* dayname; - char* nightname; - char *font; - struct color color; - GList *layers; - GList *cursors; - int order_delta; - int active; + NAVIT_OBJECT + struct navit *navit; + char *name; + char* dayname; + char* nightname; + char *font; + struct color color; + GList *layers; + GList *cursors; + int order_delta; + int active; }; /* prototypes */ diff --git a/navit/osd.c b/navit/osd.c index 0acc41748..7c53aeb38 100644 --- a/navit/osd.c +++ b/navit/osd.c @@ -114,32 +114,32 @@ void osd_wrap_point(struct point *p, struct navit *nav) { } -static void osd_evaluate_command(struct osd_item *this, struct navit *nav) { +static void osd_evaluate_command(struct osd_item *this_, struct navit *nav) { struct attr navit; navit.type=attr_navit; navit.u.navit=nav; - dbg(lvl_debug, "calling command '%s'", this->command); - command_evaluate(&navit, this->command); + dbg(lvl_debug, "calling command '%s'", this_->command); + command_evaluate(&navit, this_->command); } -void osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p) { +void osd_std_click(struct osd_item *this_, struct navit *nav, int pressed, int button, struct point *p) { int click_is_outside_item; - struct point bp = this->p; - if (!this->command || !this->command[0]) + struct point bp = this_->p; + if (!this_->command || !this_->command[0]) return; osd_wrap_point(&bp, nav); - click_is_outside_item = p->x < bp.x || p->y < bp.y || p->x > bp.x + this->w || p->y > bp.y + this->h; - if ((click_is_outside_item || !this->configured) && !this->pressed) + click_is_outside_item = p->x < bp.x || p->y < bp.y || p->x > bp.x + this_->w || p->y > bp.y + this_->h; + if ((click_is_outside_item || !this_->configured) && !this_->pressed) return; if (button != 1) return; - if (!!pressed == !!this->pressed) + if (!!pressed == !!this_->pressed) return; if (navit_ignore_button(nav)) return; - this->pressed = pressed; - if (pressed && this->command) - osd_evaluate_command(this, nav); + this_->pressed = pressed; + if (pressed && this_->command) + osd_evaluate_command(this_, nav); } void osd_std_resize(struct osd_item *item) { @@ -189,15 +189,15 @@ void osd_std_calculate_sizes(struct osd_item *item, int w, int h) { } if(!((item->rel_w.type == REL) && (item->rel_w.num == 0))) - item->w=osd_rel2real(item->navit, &(item->rel_w), w, 1); + item->w=osd_rel2real(navit_get_graphics(item->navit), &(item->rel_w), w, 1); if(item->w<0) item->w=0; if(!((item->rel_h.type == REL) && (item->rel_h.num == 0))) - item->h=osd_rel2real(item->navit,&(item->rel_h), h, 1); + item->h=osd_rel2real(navit_get_graphics(item->navit),&(item->rel_h), h, 1); if(item->h<0) item->h=0; - item->p.x=osd_rel2real(item->navit, &(item->rel_x), w, 1); - item->p.y=osd_rel2real(item->navit, &(item->rel_y), h, 1); + item->p.x=osd_rel2real(navit_get_graphics(item->navit), &(item->rel_x), w, 1); + item->p.y=osd_rel2real(navit_get_graphics(item->navit), &(item->rel_y), h, 1); /* add left and top padding to item->p */ if (padding) { @@ -492,21 +492,24 @@ static inline double osd_mm_to_in(double mm) { /** * @brief Derive absolute value from relative attribute, given value of the whole range. * - * @param nav navit handle to get screen dpi value. + * @param gra graphics handle to get screen dpi value. * @param attrval Value of u.osd_display_coordinate member of attribute capable of holding display coordinates. * @param whole Range counted as 100%. * @param treat_neg_as_rel Replace negative absolute values with whole+attr.u.num. * * @return Absolute value corresponding to given relative value. */ -int osd_rel2real(struct navit *nav, const struct osd_display_coordinate * attrval, int whole, int treat_neg_as_rel) { +int osd_rel2real(struct graphics *gra, const struct osd_display_coordinate * attrval, int whole, int treat_neg_as_rel) { int result; - double dpi; + double dpi = 75; - /* get graphics handle if one */ - struct graphics *navit_gr = navit_get_graphics(nav); - /* get screen dpi value */ - dpi = graphics_get_dpi(navit_gr); + if(gra != NULL) { + /* get screen dpi value */ + dpi = graphics_get_dpi(gra); + } else { + dbg(lvl_error, "attrval->type %d, attrval->num %f, whole %d, neg_as_rel %d, dpi NULL (%f)", attrval->type, attrval->num, + whole, treat_neg_as_rel, dpi); + } if (attrval->type == REL) result = (((double)whole) * attrval->num)/ ((double)100); @@ -518,7 +521,8 @@ int osd_rel2real(struct navit *nav, const struct osd_display_coordinate * attrva result = attrval->num; if(treat_neg_as_rel && (result <0) ) result = whole+result; - dbg(lvl_debug, "attrval->type %d, attrval->num %f, whole %d, neg_as_rel %d, dpi %f, -> %d", attrval->type, attrval->num, + dbg(lvl_warning, "attrval->type %d, attrval->num %f, whole %d, neg_as_rel %d, dpi %f, -> %d", attrval->type, + attrval->num, whole, treat_neg_as_rel, dpi, result); return result; } diff --git a/navit/osd.h b/navit/osd.h index 6e454358f..58cc8bc97 100644 --- a/navit/osd.h +++ b/navit/osd.h @@ -81,7 +81,7 @@ struct osd; struct osd *osd_new(struct attr *parent, struct attr **attrs); int osd_set_methods(struct osd_methods *in, int in_size, struct osd_methods *out); void osd_wrap_point(struct point *p, struct navit *nav); -void osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p); +void osd_std_click(struct osd_item *this_, struct navit *nav, int pressed, int button, struct point *p); void osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags); void osd_std_config(struct osd_item *item, struct navit *navit); void osd_set_keypress(struct navit *nav, struct osd_item *item); @@ -92,7 +92,7 @@ void osd_std_calculate_sizes(struct osd_item *item, int w, int h); void osd_fill_with_bgcolor(struct osd_item *item); int osd_set_attr(struct osd *osd, struct attr* attr); int osd_get_attr(struct osd *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter); -int osd_rel2real(struct navit *nav, const struct osd_display_coordinate * attrval, int whole, int treat_neg_as_rel); +int osd_rel2real(struct graphics *gra, const struct osd_display_coordinate * attrval, int whole, int treat_neg_as_rel); /* end of prototypes */ #endif diff --git a/navit/vehicle.c b/navit/vehicle.c index 5bf16c280..1dea29878 100644 --- a/navit/vehicle.c +++ b/navit/vehicle.c @@ -324,14 +324,22 @@ void vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwr } if (cursor && this_->gra && this_->cursor) { - this_->cursor_pnt.x+=(this_->cursor->w - cursor->w)/2; - this_->cursor_pnt.y+=(this_->cursor->h - cursor->h)/2; - graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 0); + int w, h, thisw, thish; + thisw = osd_rel2real(this_->gra, &(this_->cursor->w), 0, 0); + thish = osd_rel2real(this_->gra, &(this_->cursor->h), 0, 0); + w = osd_rel2real(this_->gra, &(cursor->w), 0, 0); + h = osd_rel2real(this_->gra, &(cursor->h), 0, 0); + this_->cursor_pnt.x+=(thisw - w)/2; + this_->cursor_pnt.y+=(thish - h)/2; + graphics_overlay_resize(this_->gra, &this_->cursor_pnt, w, h, 0); } if (cursor) { - sc.x=cursor->w/2; - sc.y=cursor->h/2; + int w, h; + w = osd_rel2real(this_->gra, &(cursor->w), 0, 0); + h = osd_rel2real(this_->gra, &(cursor->h), 0, 0); + sc.x=w/2; + sc.y=h/2; if (!this_->cursor && this_->gra) graphics_overlay_disable(this_->gra, 0); } else { @@ -354,6 +362,7 @@ void vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwr * @param speed The speed of the vehicle. */ void vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int angle, int speed) { + int thisw, thish; if (angle < 0) angle+=360; dbg(lvl_debug,"enter this=%p gra=%p pnt=%p dir=%d speed=%d", this_, gra, pnt, angle, speed); @@ -363,11 +372,13 @@ void vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt this_->speed=speed; if (!this_->cursor) return; - this_->cursor_pnt.x-=this_->cursor->w/2; - this_->cursor_pnt.y-=this_->cursor->h/2; + thisw = osd_rel2real(gra, &(this_->cursor->w), 0, 0); + thish = osd_rel2real(gra, &(this_->cursor->h), 0, 0); + this_->cursor_pnt.x-=thisw/2; + this_->cursor_pnt.y-=thish/2; if (!this_->gra) { struct color c; - this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 0); + this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, thisw, thish, 0); if (this_->gra) { graphics_init(this_->gra); this_->bg=graphics_gc_new(this_->gra); @@ -404,6 +415,7 @@ static void vehicle_set_default_name(struct vehicle *this_) { static void vehicle_draw_do(struct vehicle *this_) { struct point p; struct cursor *cursor=this_->cursor; + int w, h; int speed=this_->speed; int angle=this_->angle; int sequence=this_->sequence; @@ -424,7 +436,9 @@ static void vehicle_draw_do(struct vehicle *this_) { graphics_draw_mode(this_->gra, draw_mode_begin); p.x=0; p.y=0; - graphics_draw_rectangle(this_->gra, this_->bg, &p, cursor->w, cursor->h); + w = osd_rel2real(this_->gra, &(cursor->w), 0, 0); + h = osd_rel2real(this_->gra, &(cursor->h), 0, 0); + graphics_draw_rectangle(this_->gra, this_->bg, &p, w, h); attr=cursor->attrs; while (*attr) { if ((*attr)->type == attr_itemgra) { |