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;
39 osd_new(struct attr *parent, struct attr **attrs)
42 struct osd_priv *(*new)(struct navit *nav, struct osd_methods *meth, struct attr **attrs);
43 struct attr *type=attr_search(attrs, NULL, attr_type);
47 new=plugin_get_osd_type(type->u.str);
50 o=g_new0(struct osd, 1);
51 o->priv=new(parent->u.navit, &o->meth, attrs);
56 osd_wrap_point(struct point *p, struct navit *nav)
59 p->x += navit_get_width(nav);
61 p->y += navit_get_height(nav);
66 osd_std_click(struct osd_item *this, struct navit *nav, int pressed, int button, struct point *p)
68 struct point bp = this->p;
69 osd_wrap_point(&bp, nav);
70 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)
74 if (!!pressed == !!this->pressed)
76 if (navit_ignore_button(nav))
78 this->pressed = pressed;
79 if (pressed && this->command) {
81 navit.type=attr_navit;
83 dbg(0, "calling command '%s'\n", this->command);
84 command_evaluate(&navit, this->command);
89 osd_std_resize(struct osd_item *item)
91 graphics_overlay_resize(item->gr, &item->p, item->w, item->h, 65535, 1);
95 osd_std_calculate_sizes(struct osd_item *item, struct osd_priv *priv, int w, int h)
97 struct attr vehicle_attr;
100 item->w = (item->rel_w * w) / 100;
104 item->h = (item->rel_h * h) / 100;
108 item->p.x = (item->rel_x * w) / 100;
112 item->p.y = (item->rel_y * h) / 100;
115 osd_std_resize(item);
116 if (item->meth.draw) {
117 if (navit_get_attr(item->navit, attr_vehicle, &vehicle_attr, NULL)) {
118 item->meth.draw(priv, item->navit, vehicle_attr.u.vehicle);
124 osd_std_reconfigure(struct osd_item *item, struct command_saved *cs)
126 if (!command_saved_error(cs)) {
127 graphics_overlay_disable(item->gr, !command_saved_get_int(cs));
129 dbg(0, "Error in saved command: %i\n", command_saved_error(cs));
134 osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags)
139 item->osd_configuration=-1;
140 item->color_white.r = 0xffff;
141 item->color_white.g = 0xffff;
142 item->color_white.b = 0xffff;
143 item->color_white.a = 0xffff;
144 item->text_color.r = 0xffff;
145 item->text_color.g = 0xffff;
146 item->text_color.b = 0xffff;
147 item->text_color.a = 0xffff;
149 item->color_bg.r = 0x0808;
150 item->color_bg.g = 0x0808;
151 item->color_bg.b = 0xf8f8;
152 item->color_bg.a = 0x0000;
154 item->color_bg.r = 0x0;
155 item->color_bg.g = 0x0;
156 item->color_bg.b = 0x0;
157 item->color_bg.a = 0x5fff;
160 attr=attr_search(attrs, NULL, attr_osd_configuration);
162 item->osd_configuration = attr->u.num;
164 attr=attr_search(attrs, NULL, attr_enable_expression);
166 item->enable_cs = command_saved_new(attr->u.str, item->navit, NULL);
169 attr = attr_search(attrs, NULL, attr_w);
171 if (attr->u.num > ATTR_REL_MAXABS) {
172 item->rel_w = attr->u.num - ATTR_REL_RELSHIFT;
175 item->w = attr->u.num;
179 attr = attr_search(attrs, NULL, attr_h);
181 if (attr->u.num > ATTR_REL_MAXABS) {
182 item->rel_h = attr->u.num - ATTR_REL_RELSHIFT;
185 item->h = attr->u.num;
189 attr = attr_search(attrs, NULL, attr_x);
191 if (attr->u.num > ATTR_REL_MAXABS) {
192 item->rel_x = attr->u.num - ATTR_REL_RELSHIFT;
195 item->p.x = attr->u.num;
199 attr = attr_search(attrs, NULL, attr_y);
201 if (attr->u.num > ATTR_REL_MAXABS) {
202 item->rel_y = attr->u.num - ATTR_REL_RELSHIFT;
205 item->p.y = attr->u.num;
209 attr = attr_search(attrs, NULL, attr_font_size);
211 item->font_size = attr->u.num;
213 attr=attr_search(attrs, NULL, attr_background_color);
215 item->color_bg=*attr->u.color;
216 attr = attr_search(attrs, NULL, attr_command);
218 item->command = g_strdup(attr->u.str);
219 attr=attr_search(attrs, NULL, attr_text_color);
221 item->text_color=*attr->u.color;
222 attr=attr_search(attrs, NULL, attr_flags);
224 item->attr_flags=attr->u.num;
228 osd_std_config(struct osd_item *item, struct navit *navit)
232 if (item->enable_cs) {
233 item->reconfig_cb = callback_new_1(callback_cast(osd_std_reconfigure), item);
234 command_saved_set_cb(item->enable_cs, item->reconfig_cb);
236 if (!command_saved_error(item->enable_cs)) {
237 item->configured = !! command_saved_get_int(item->enable_cs);
239 dbg(0, "Error in saved command: %i.\n", command_saved_error(item->enable_cs));
242 if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL))
244 item->configured = !!(attr.u.num & item->osd_configuration);
246 graphics_overlay_disable(item->gr, !item->configured);
250 osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv)
252 struct graphics *navit_gr;
254 navit_gr = navit_get_graphics(nav);
255 item->gr = graphics_overlay_new(navit_gr, &item->p, item->w, item->h, 65535, 1);
257 item->graphic_bg = graphics_gc_new(item->gr);
258 graphics_gc_set_foreground(item->graphic_bg, &item->color_bg);
259 graphics_background_gc(item->gr, item->graphic_bg);
261 item->graphic_fg_white = graphics_gc_new(item->gr);
262 graphics_gc_set_foreground(item->graphic_fg_white, &item->color_white);
264 if (item->flags & 2) {
265 item->font = graphics_font_new(item->gr, item->font_size, 1);
266 item->graphic_fg_text = graphics_gc_new(item->gr);
267 graphics_gc_set_foreground(item->graphic_fg_text, &item->text_color);
270 item->cb = callback_new_attr_2(callback_cast(osd_std_config), attr_osd_configuration, item, nav);
271 navit_add_callback(nav, item->cb);
273 item->resize_cb = callback_new_attr_2(callback_cast(osd_std_calculate_sizes), attr_resize, item, priv);
274 graphics_add_callback(navit_gr, item->resize_cb);
276 osd_std_config(item, nav);
280 osd_std_draw(struct osd_item *item)
283 int flags=item->attr_flags;
285 graphics_draw_mode(item->gr, draw_mode_begin);
288 graphics_draw_rectangle(item->gr, item->graphic_bg, p, item->w, item->h);
292 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
296 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
300 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
304 graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);