summaryrefslogtreecommitdiff
path: root/navit/graphics.c
diff options
context:
space:
mode:
Diffstat (limited to 'navit/graphics.c')
-rw-r--r--navit/graphics.c213
1 files changed, 104 insertions, 109 deletions
diff --git a/navit/graphics.c b/navit/graphics.c
index 97b1c0f69..7680d96ce 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -274,7 +274,7 @@ struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
return NULL;
}
- graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
+ graphicstype_new=plugin_get_category_graphics(type_attr->u.str);
if (! graphicstype_new) {
dbg(lvl_error,"Failed to load graphics plugin %s.\n", type_attr->u.str);
return NULL;
@@ -654,11 +654,12 @@ void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsig
}
/**
- * Create a new image from file path scaled to w and h pixels
+ * @brief Create a new image from file path, optionally scaled to w and h pixels.
+ *
* @param gra the graphics instance
* @param path path of the image to load
- * @param w width to rescale to
- * @param h height to rescale to
+ * @param w width to rescale to, or IMAGE_W_H_UNSET for original width
+ * @param h height to rescale to, or IMAGE_W_H_UNSET for original height
* @returns <>
* @author Martin Schaller (04/2008)
*/
@@ -684,7 +685,7 @@ image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path,
case 1:
/* The best variant both for cpu usage and quality would be prescaled png of a needed size */
mode++;
- if (width != -1 && height != -1) {
+ if (width != IMAGE_W_H_UNSET && height != IMAGE_W_H_UNSET) {
new_name=g_strdup_printf("%s_%d_%d.png", name, width, height);
}
break;
@@ -782,12 +783,13 @@ image_new_helper(struct graphics *gra, struct graphics_image *this_, char *path,
}
/**
- * Create a new image from file path scaled to w and h pixels and possibly rotated
+ * @brief Create a new image from file path, optionally scaled to w and h pixels and rotated.
+ *
* @param gra the graphics instance
* @param path path of the image to load
- * @param w width to rescale to
- * @param h height to rescale to
- * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
+ * @param w width to rescale to, or IMAGE_W_H_UNSET for original width
+ * @param h height to rescale to, or IMAGE_W_H_UNSET for original height
+ * @param rotate angle to rotate the image, in 90 degree steps (not supported by all plugins).
* @returns <>
* @author Martin Schaller (04/2008)
*/
@@ -818,7 +820,7 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra,
char *pathi=paths[i];
int len=strlen(pathi);
int i,k;
- int newwidth=-1, newheight=-1;
+ int newwidth=IMAGE_W_H_UNSET, newheight=IMAGE_W_H_UNSET;
ext=g_utf8_strrchr(pathi,-1,'.');
i=pathi-ext+len;
@@ -855,8 +857,8 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra,
}
if(k==1 || s<=pathi || *s!='_') {
- newwidth=-1;
- newheight=-1;
+ newwidth=IMAGE_W_H_UNSET;
+ newheight=IMAGE_W_H_UNSET;
if(ext)
s=ext;
else
@@ -865,15 +867,12 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra,
}
/* If exact h and w values were given as function parameters, they take precedence over values guessed from the image name */
- if(w!=-1)
+ if(w!=IMAGE_W_H_UNSET)
newwidth=w;
- if(h!=-1)
+ if(h!=IMAGE_W_H_UNSET)
newheight=h;
name=g_strndup(pathi,s-pathi);
-#if 0
- if (!strstr(name,"test.zip"))
-#endif
image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 0);
if (!this_->priv && strstr(pathi, ".zip/"))
image_new_helper(gra, this_, pathi, name, newwidth, newheight, rotate, 1);
@@ -902,7 +901,7 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra,
*/
struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
{
- return graphics_image_new_scaled_rotated(gra, path, -1, -1, 0);
+ return graphics_image_new_scaled_rotated(gra, path, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
}
/**
@@ -1071,59 +1070,94 @@ graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
}
-#include "attr.h"
-#include "popup.h"
-#include <stdio.h>
-
-#if 0
-//##############################################################################################################
-//# Description:
-//# Comment:
-//# Authors: Martin Schaller (04/2008)
-//##############################################################################################################
-static void popup_view_html(struct popup_item *item, char *file)
-{
- char command[1024];
- sprintf(command,"firefox %s", file);
- system(command);
+/**
+ * @brief Shows the native on-screen keyboard or other input method
+ *
+ * This method is a wrapper around the respective method of the graphics plugin.
+ *
+ * The caller should populate the {@code kbd} argument with appropriate {@code mode} and {@code lang}
+ * members so the graphics plugin can determine the best matching layout.
+ *
+ * If an input method is shown, the graphics plugin should try to select the configuration which best
+ * matches the specified {@code mode}. For example, if {@code mode} specifies a numeric layout, the
+ * graphics plugin should select a numeric keyboard layout (if available), or the equivalent for another
+ * input method (such as setting stroke recognition to identify strokes as numbers). Likewise, when an
+ * alphanumeric-uppercase mode is requested, it should switch to uppercase input.
+ *
+ * Implementations should, however, consider that Navit's internal keyboard allows the user to switch
+ * modes at will (the only exception being degree mode) and thus must not "lock" the user into a limited
+ * layout with no means to switch to a general-purpose one. For example, house number entry in an
+ * address search dialog may default to numeric mode, but since some house numbers may contain
+ * non-numeric characters, a pure numeric keyboard is suitable only if the user has the option to switch
+ * to an alphanumeric layout.
+ *
+ * When multiple alphanumeric layouts are available, the graphics plugin should use the {@code lang}
+ * argument to determine the best layout.
+ *
+ * When selecting an input method, preference should always be given to the default or last selected
+ * input method and configuration if it matches the requested {@code mode} and {@code lang}.
+ *
+ * If the native input method is going to obstruct parts of Navit's UI, the graphics plugin should set
+ * {@code kbd->w} and {@code kbd->h} to the height and width to the appropriate value in pixels. A value
+ * of -1 indicates that the input method fills the entire available width or height of the space
+ * available to Navit. On windowed platforms, where the on-screen input method and Navit's window may be
+ * moved relative to each other as needed and can be displayed alongside each other, the graphics plugin
+ * should report 0 for both dimensions.
+ *
+ * @param this_ The graphics instance
+ * @param kbd The keyboard instance
+ *
+ * @return 1 if the native keyboard is going to be displayed, 0 if not, -1 if the method is not
+ * supported by the plugin
+ */
+int graphics_show_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd) {
+ int ret;
+ if (!this_->meth.show_native_keyboard)
+ ret = -1;
+ else
+ ret = this_->meth.show_native_keyboard(kbd);
+ dbg(lvl_debug, "return %d\n", ret);
+ return ret;
}
-struct transformatin *tg;
-enum projection pg;
-//##############################################################################################################
-//# Description:
-//# Comment:
-//# Authors: Martin Schaller (04/2008)
-//##############################################################################################################
-static void graphics_popup(struct display_list *list, struct popup_item **popup)
-{
- struct item *item;
- struct attr attr;
- struct map_rect *mr;
- struct coord c;
- struct popup_item *curr_item,*last=NULL;
- item=list->data;
- mr=map_rect_new(item->map, NULL, NULL, 0);
- printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
- item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
- if (item) {
- if (item_attr_get(item, attr_name, &attr)) {
- curr_item=popup_item_new_text(popup,attr.u.str,1);
- if (item_attr_get(item, attr_info_html, &attr)) {
- popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
- }
- if (item_attr_get(item, attr_price_html, &attr)) {
- popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
- }
- curr_item->submenu=last;
- }
- }
- map_rect_destroy(mr);
+/**
+ * @brief Hides the native on-screen keyboard or other input method
+ *
+ * This method is a wrapper around the respective method of the graphics plugin.
+ *
+ * A call to this function indicates that Navit no longer needs the input method and is about to reclaim
+ * any screen real estate it may have previously reserved for the input method.
+ *
+ * On platforms that don't support overlapping windows this means that the on-screen input method should
+ * be hidden, as it may otherwise obstruct parts of Navit's UI.
+ *
+ * On windowed platforms, where on-screen input methods can be displayed alongside Navit or moved around
+ * as needed, the graphics driver should instead notify the on-screen method that it is no longer
+ * expecting user input, allowing the input method to take the appropriate action.
+ *
+ * The graphics plugin must free any data it has stored in {@code kbd->gra_priv} and reset the pointer
+ * to {@code NULL} to indicate it has done so.
+ *
+ * The caller may free {@code kbd} after this function returns.
+ *
+ * @param this The graphics instance
+ * @param kbd The keyboard instance
+ *
+ * @return True if the call was successfully passed to the plugin, false if the method is not supported
+ * by the plugin
+ */
+int graphics_hide_native_keyboard (struct graphics *this_, struct graphics_keyboard *kbd) {
+ if (!this_->meth.hide_native_keyboard)
+ return 0;
+ this_->meth.hide_native_keyboard(kbd);
+ return 1;
}
-#endif
+#include "attr.h"
+#include "popup.h"
+#include <stdio.h>
/**
* FIXME
@@ -1252,9 +1286,6 @@ static void label_line(struct graphics *gra, struct graphics_gc *fg, struct grap
y+=dx*thm/l/64;
p_t.x=x;
p_t.y=y;
-#if 0
- dbg(lvl_debug,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
-#endif
if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y)
gra->meth.draw_text(gra->priv, fg->priv, bg?bg->priv:NULL, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
}
@@ -1310,12 +1341,6 @@ intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, in
a = -a;
b = -b;
}
-#if 0
- if (a < 0 || b < 0)
- return 0;
- if (a > n || b > n)
- return 0;
-#endif
if (n == 0)
return 0;
res->x = a1->x + a * adx / n;
@@ -1397,10 +1422,6 @@ static void
draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir)
{
struct circle *c;
-
-#if 0
- dbg(lvl_debug,"diameter=%d start=%d len=%d pos=%d dir=%d\n", diameter, start, len, *pos, dir);
-#endif
int count=64;
int end=start+len;
int i,step;
@@ -1521,32 +1542,6 @@ int_sqrt(unsigned int n)
return p;
}
-#if 0
-static void
-debug_line(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int dx, int dy)
-{
- struct point p[2];
- p[0]=p[1]=*pnt;
- p[1].x+=dx;
- p[1].y+=dy;
- gra->meth.draw_lines(gra->priv, gc->priv, p, 2);
-}
-
-static void
-debug_point(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int s)
-{
- struct point p[4];
- p[0]=p[1]=p[2]=*pnt;
- p[0].x-=s;
- p[0].y+=s;
- p[1].x+=s;
- p[1].y+=s;
- p[2].y-=s;
- p[3]=p[0];
- gra->meth.draw_lines(gra->priv, gc->priv, p, 4);
-}
-#endif
-
struct draw_polyline_shape {
int wi;
int step;
@@ -1723,6 +1718,7 @@ graphics_draw_polyline_as_polygon(struct graphics_priv *gra_priv, struct graphic
dbg(lvl_debug,"%d,%d width %d\n",pnt[i].x,pnt[i].y,width[i]);
#endif
ctx.shape.l=0;
+ ctx.shape.wi=0;
ctx.res=g_alloca(sizeof(struct point)*maxpoints);
i=0;
draw_init_ctx(&ctx, maxpoints);
@@ -2104,7 +2100,6 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
struct element *e=dc->e;
struct graphics_image *img=dc->img;
struct point p;
- struct coord *c;
char *path;
while (di) {
@@ -2121,7 +2116,6 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
count=limit_count(di->c, count);
if (dc->type == type_poly_water_tiled)
mindist=0;
- c=di->c;
#if 0
if (dc->e->type == element_polygon) {
int max=1000;
@@ -2135,9 +2129,9 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
}
#endif
if (dc->e->type == element_polyline)
- count=transform(dc->trans, dc->pro, c, pa, count, mindist, e->u.polyline.width, width);
+ count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
else
- count=transform(dc->trans, dc->pro, c, pa, count, mindist, 0, NULL);
+ count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
switch (e->type) {
case element_polygon:
graphics_draw_polygon_clipped(gra, gc, pa, count);
@@ -2232,7 +2226,7 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
case element_image:
dbg(lvl_debug,"image: '%s'\n", di->label);
if (gra->meth.draw_image_warp) {
- img=graphics_image_new_scaled_rotated(gra, di->label, -1, -1, 0);
+ img=graphics_image_new_scaled_rotated(gra, di->label, IMAGE_W_H_UNSET, IMAGE_W_H_UNSET, 0);
if (img)
gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, img->priv);
} else
@@ -3051,3 +3045,4 @@ graphics_process_selection(struct graphics *gra, struct displaylist *dl)
curr=g_list_next(curr);
}
}
+