diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-03-20 20:10:28 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-03-20 20:10:28 +0000 |
commit | ce7c726eec11f054b7711e02f9ced78f8d0d4870 (patch) | |
tree | 554b636a55d8c9d346dcb2cee1aecf6d9e3033b9 /navit/osd.c | |
parent | 2d52d5c0a497dc67e6466b9dc05305b13fb83fd1 (diff) | |
download | navit-ce7c726eec11f054b7711e02f9ced78f8d0d4870.tar.gz |
Fix:Core:Moved general functions from osd_core to main module
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2152 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/osd.c')
-rw-r--r-- | navit/osd.c | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/navit/osd.c b/navit/osd.c index 7faa8337a..a6e1ccc6c 100644 --- a/navit/osd.c +++ b/navit/osd.c @@ -21,6 +21,12 @@ #include "debug.h" #include "plugin.h" #include "item.h" +#include "color.h" +#include "point.h" +#include "navit.h" +#include "graphics.h" +#include "command.h" +#include "callback.h" #include "osd.h" @@ -46,3 +52,167 @@ osd_new(struct attr *parent, struct attr **attrs) return o; } +void +osd_wrap_point(struct point *p, struct navit *nav) +{ + if (p->x < 0) + p->x += navit_get_width(nav); + if (p->y < 0) + p->y += navit_get_height(nav); + +} + +void +osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p) +{ + struct point bp = this->p; + osd_wrap_point(&bp, nav); + if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->w || p->y > bp.y + this->h || !this->configured) && !this->pressed) + return; + if (navit_ignore_button(nav)) + return; + this->pressed = pressed; + if (pressed) { + struct attr navit; + navit.type=attr_navit; + navit.u.navit=nav; + dbg(0, "calling command '%s'\n", this->command); + command_evaluate(&navit, this->command); + } +} + +void +osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags) +{ + struct attr *attr; + + item->flags=flags; + item->osd_configuration=-1; + item->color_white.r = 0xffff; + item->color_white.g = 0xffff; + item->color_white.b = 0xffff; + item->color_white.a = 0xffff; + item->text_color.r = 0xffff; + item->text_color.g = 0xffff; + item->text_color.b = 0xffff; + item->text_color.a = 0xffff; + if (flags & 1) { + item->color_bg.r = 0x0808; + item->color_bg.g = 0x0808; + item->color_bg.b = 0xf8f8; + item->color_bg.a = 0x0000; + } else { + item->color_bg.r = 0x0; + item->color_bg.g = 0x0; + item->color_bg.b = 0x0; + item->color_bg.a = 0x5fff; + } + + attr=attr_search(attrs, NULL, attr_osd_configuration); + if (attr) + item->osd_configuration = attr->u.num; + + attr = attr_search(attrs, NULL, attr_w); + if (attr) + item->w = attr->u.num; + + attr = attr_search(attrs, NULL, attr_h); + if (attr) + item->h = attr->u.num; + + attr = attr_search(attrs, NULL, attr_x); + if (attr) + item->p.x = attr->u.num; + + attr = attr_search(attrs, NULL, attr_y); + if (attr) + item->p.y = attr->u.num; + + attr = attr_search(attrs, NULL, attr_font_size); + if (attr) + item->font_size = attr->u.num; + + attr=attr_search(attrs, NULL, attr_background_color); + if (attr) + item->color_bg=*attr->u.color; + attr = attr_search(attrs, NULL, attr_command); + if (attr) + item->command = g_strdup(attr->u.str); + attr=attr_search(attrs, NULL, attr_text_color); + if (attr) + item->text_color=*attr->u.color; + attr=attr_search(attrs, NULL, attr_flags); + if (attr) + item->attr_flags=attr->u.num; + +} + +void +osd_std_config(struct osd_item *item, struct navit *navit) +{ + struct attr osd_configuration; + dbg(1,"enter\n"); + if (!navit_get_attr(navit, attr_osd_configuration, &osd_configuration, NULL)) + osd_configuration.u.num=-1; + item->configured = !!(osd_configuration.u.num & item->osd_configuration); + graphics_overlay_disable(item->gr, !item->configured); +} + +void +osd_set_std_graphic(struct navit *nav, struct osd_item *item) +{ + struct graphics *navit_gr; + + navit_gr = navit_get_graphics(nav); + item->gr = graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 65535, 1); + + item->graphic_bg = graphics_gc_new(item->gr); + graphics_gc_set_foreground(item->graphic_bg, &item->color_bg); + graphics_background_gc(item->gr, item->graphic_bg); + + item->graphic_fg_white = graphics_gc_new(item->gr); + graphics_gc_set_foreground(item->graphic_fg_white, &item->color_white); + + if (item->flags & 2) { + item->font = graphics_font_new(item->gr, item->font_size, 1); + item->graphic_fg_text = graphics_gc_new(item->gr); + graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color); + } + + item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav); + navit_add_callback(nav, item->cb); + osd_std_config(item, nav); +} + +void +osd_std_resize(struct osd_item *item) +{ + graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 65535, 1); +} + +void +osd_std_draw(struct osd_item *item) +{ + struct point p[2]; + int flags=item->attr_flags; + graphics_draw_mode(item->gr, draw_mode_begin); + p[0].x=0; + p[0].y=0; + graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h); + p[1].x=item->w-1; + p[1].y=0; + if (flags & 1) + graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2); + p[0].x=item->w-1; + p[0].y=item->h-1; + if (flags & 2) + graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2); + p[1].x=0; + p[1].y=item->h-1; + if (flags & 4) + graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2); + p[0].x=0; + p[0].y=0; + if (flags & 8) + graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2); +} |