2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
34 struct osd_methods meth;
35 struct osd_priv *priv;
36 struct attr** osd_attrs;
40 osd_new(struct attr *parent, struct attr **attrs)
43 struct osd_priv *(*new)(struct navit *nav, struct osd_methods *meth, struct attr **attrs);
44 struct attr *type=attr_search(attrs, NULL, attr_type);
48 new=plugin_get_osd_type(type->u.str);
51 o=g_new0(struct osd, 1);
52 o->priv=new(parent->u.navit, &o->meth, attrs);
54 o->osd_attrs = attr_list_dup(attrs);
60 osd_get_attr(struct osd *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
62 return attr_generic_get_attr(this_->osd_attrs, NULL, type, attr, NULL);
66 osd_set_attr(struct osd *osd, struct attr* attr)
68 osd->osd_attrs=attr_generic_set_attr(osd->osd_attrs,attr);
69 if(osd && osd->meth.set_attr) {
70 osd->meth.set_attr(osd->priv, attr);
77 osd_wrap_point(struct point *p, struct navit *nav)
80 p->x += navit_get_width(nav);
82 p->y += navit_get_height(nav);
87 osd_evaluate_command(struct osd_item *this, struct navit *nav)
90 navit.type=attr_navit;
92 dbg(0, "calling command '%s'\n", this->command);
93 command_evaluate(&navit, this->command);
97 osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
99 struct point bp = this->p;
100 if (!this->command || !this->command[0])
102 osd_wrap_point(&bp, nav);
103 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)
107 if (!!pressed == !!this->pressed)
109 if (navit_ignore_button(nav))
111 this->pressed = pressed;
112 if (pressed && this->command)
113 osd_evaluate_command(this, nav);
117 osd_std_resize(struct osd_item *item)
119 graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 65535, 1);
123 osd_std_calculate_sizes(struct osd_item *item, struct osd_priv *priv, int w, int h)
125 struct attr vehicle_attr;
128 item->w = (item->rel_w * w) / 100;
132 item->h = (item->rel_h * h) / 100;
136 item->p.x = (item->rel_x * w) / 100;
140 item->p.y = (item->rel_y * h) / 100;
143 osd_std_resize(item);
144 if (item->meth.draw) {
145 if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
146 item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
152 osd_std_keypress(struct osd_item *item, struct navit *nav, char *key)
156 dbg(0,"key=%s\n",key);
157 for (i = 0 ; i < strlen(key) ; i++) {
158 dbg(0,"key:0x%02x\n",key[i]);
160 for (i = 0 ; i < strlen(item->accesskey) ; i++) {
161 dbg(0,"accesskey:0x%02x\n",item->accesskey[i]);
164 if ( ! graphics_is_disabled(item->gr) && item->accesskey && key && !strcmp(key, item->accesskey))
165 osd_evaluate_command(item, nav);
169 osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
171 if (!command_saved_error(cs)) {
172 graphics_overlay_disable(item->gr, !command_saved_get_int(cs));
174 dbg(0, "Error in saved command: %i\n", command_saved_error(cs));
179 osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
184 item->osd_configuration=-1;
185 item->color_white.r = 0xffff;
186 item->color_white.g = 0xffff;
187 item->color_white.b = 0xffff;
188 item->color_white.a = 0xffff;
189 item->text_color.r = 0xffff;
190 item->text_color.g = 0xffff;
191 item->text_color.b = 0xffff;
192 item->text_color.a = 0xffff;
194 item->color_bg.r = 0x0808;
195 item->color_bg.g = 0x0808;
196 item->color_bg.b = 0xf8f8;
197 item->color_bg.a = 0x0000;
199 item->color_bg.r = 0x0;
200 item->color_bg.g = 0x0;
201 item->color_bg.b = 0x0;
202 item->color_bg.a = 0x5fff;
205 attr=attr_search(attrs, NULL, attr_osd_configuration);
207 item->osd_configuration = attr->u.num;
209 attr=attr_search(attrs, NULL, attr_enable_expression);
211 item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL);
214 attr = attr_search(attrs, NULL, attr_w);
216 if (attr->u.num > ATTR_REL_MAXABS) {
217 item->rel_w = attr->u.num - ATTR_REL_RELSHIFT;
220 item->w = attr->u.num;
224 attr = attr_search(attrs, NULL, attr_h);
226 if (attr->u.num > ATTR_REL_MAXABS) {
227 item->rel_h = attr->u.num - ATTR_REL_RELSHIFT;
230 item->h = attr->u.num;
234 attr = attr_search(attrs, NULL, attr_x);
236 if (attr->u.num > ATTR_REL_MAXABS) {
237 item->rel_x = attr->u.num - ATTR_REL_RELSHIFT;
240 item->p.x = attr->u.num;
244 attr = attr_search(attrs, NULL, attr_y);
246 if (attr->u.num > ATTR_REL_MAXABS) {
247 item->rel_y = attr->u.num - ATTR_REL_RELSHIFT;
250 item->p.y = attr->u.num;
254 attr = attr_search(attrs, NULL, attr_font_size);
256 item->font_size = attr->u.num;
258 attr=attr_search(attrs, NULL, attr_background_color);
260 item->color_bg=*attr->u.color;
261 attr = attr_search(attrs, NULL, attr_command);
263 item->command = g_strdup(attr->u.str);
264 attr=attr_search(attrs, NULL, attr_text_color);
266 item->text_color=*attr->u.color;
267 attr=attr_search(attrs, NULL, attr_flags);
269 item->attr_flags=attr->u.num;
270 attr=attr_search(attrs, NULL, attr_accesskey);
272 item->accesskey = g_strdup(attr->u.str);
273 attr=attr_search(attrs, NULL, attr_font);
275 item->font_name = g_strdup(attr->u.str);
279 osd_std_config(struct osd_item *item, struct navit *navit)
283 if (item->enable_cs) {
284 item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
285 command_saved_set_cb(item->enable_cs, item->reconfig_cb);
287 if (!command_saved_error(item->enable_cs)) {
288 item->configured = !! command_saved_get_int(item->enable_cs);
290 dbg(0, "Error in saved command: %i.\n", command_saved_error(item->enable_cs));
293 if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
295 item->configured = !!(attr.u.num & item->osd_configuration);
297 if (item->gr && !(item->flags & 16))
298 graphics_overlay_disable(item->gr, !item->configured);
302 osd_set_std_config(struct navit *nav, struct osd_item *item)
304 item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
305 navit_add_callback(nav, item->cb);
306 osd_std_config(item, nav);
310 osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv)
312 struct graphics *navit_gr;
314 navit_gr = navit_get_graphics(nav);
315 item->gr = graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 65535, 1);
317 item->graphic_bg = graphics_gc_new(item->gr);
318 graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
319 graphics_background_gc(item->gr, item->graphic_bg);
321 item->graphic_fg_white = graphics_gc_new(item->gr);
322 graphics_gc_set_foreground(item->graphic_fg_white, &item->color_white);
324 if (item->flags & 2) {
325 item->font = graphics_named_font_new(item->gr, item->font_name, item->font_size, 1);
326 item->graphic_fg_text = graphics_gc_new(item->gr);
327 graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
330 osd_set_std_config(nav, item);
332 item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes), attr_resize, item, priv);
333 graphics_add_callback(navit_gr, item->resize_cb);
334 dbg(0,"accesskey %s\n",item->accesskey);
335 if (item->accesskey) {
336 item->keypress_cb=callback_new_attr_2(callback_cast(osd_std_keypress), attr_keypress, item, nav);
337 graphics_add_callback(navit_gr, item->keypress_cb);
343 osd_std_draw(struct osd_item *item)
346 int flags=item->attr_flags;
348 graphics_draw_mode(item->gr, draw_mode_begin);
351 graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
355 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
359 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
363 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
367 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);