summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-08-22 22:52:05 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-08-22 22:52:05 +0000
commit72d1c444f816cfe8e4a6f4ef0efca85b7cf7b3d4 (patch)
treeac8158ed9ebf2c5a35b2b3be55e2491d16ade0a2 /navit
parentb528bc2fd554f10eb997009817c8abc586734be7 (diff)
downloadnavit-72d1c444f816cfe8e4a6f4ef0efca85b7cf7b3d4.tar.gz
Add:Core:Make it possible to add more commands to osd buttons
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1306 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/callback.c6
-rw-r--r--navit/callback.h3
-rw-r--r--navit/gui/internal/gui_internal.c84
-rw-r--r--navit/navit.c37
-rw-r--r--navit/navit.h3
-rw-r--r--navit/osd/core/osd_core.c14
6 files changed, 102 insertions, 45 deletions
diff --git a/navit/callback.c b/navit/callback.c
index 9392be714..d1b0fd843 100644
--- a/navit/callback.c
+++ b/navit/callback.c
@@ -66,6 +66,12 @@ callback_new(void (*func)(void), int pcount, void **p)
}
void
+callback_destroy(struct callback *cb)
+{
+ g_free(cb);
+}
+
+void
callback_set_arg(struct callback *cb, int arg, void *p)
{
if (arg < 0 || arg > cb->pcount)
diff --git a/navit/callback.h b/navit/callback.h
index e816a78f2..93e0696bd 100644
--- a/navit/callback.h
+++ b/navit/callback.h
@@ -31,8 +31,9 @@ enum attr_type;
struct callback;
struct callback_list;
struct callback_list *callback_list_new(void);
-struct callback * callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p);
+struct callback *callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p);
struct callback *callback_new(void (*func)(void), int pcount, void **p);
+void callback_destroy(struct callback *cb);
void callback_set_arg(struct callback *cb, int arg, void *p);
void callback_list_add(struct callback_list *l, struct callback *cb);
struct callback *callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p);
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index 204f58ba1..43c411c05 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -164,7 +164,7 @@ struct gui_priv {
struct widget *highlighted;
struct widget *highlighted_menu;
struct widget *list;
- int vehicle_valid;
+ int clickp_valid, vehicle_valid;
struct pcoord clickp, vehiclep;
struct search_list *sl;
};
@@ -1955,14 +1955,16 @@ gui_internal_cmd_actions(struct gui_priv *this, struct widget *wm)
gui_internal_button_new_with_callback(this, "Bookmarks",
image_new_l(this, "gui_bookmark"), gravity_center|orientation_vertical,
gui_internal_cmd_bookmarks, NULL));
- coord=coordinates(&this->clickp, '\n');
- gui_internal_widget_append(w,
- wc=gui_internal_button_new_with_callback(this, coord,
- image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
- gui_internal_cmd_position, NULL));
- wc->name=g_strdup("Map Point");
- wc->c=this->clickp;
- g_free(coord);
+ if (this->clickp_valid) {
+ coord=coordinates(&this->clickp, '\n');
+ gui_internal_widget_append(w,
+ wc=gui_internal_button_new_with_callback(this, coord,
+ image_new_l(this, "gui_map"), gravity_center|orientation_vertical,
+ gui_internal_cmd_position, NULL));
+ wc->name=g_strdup("Map Point");
+ wc->c=this->clickp;
+ g_free(coord);
+ }
if (this->vehicle_valid) {
coord=coordinates(&this->vehiclep, '\n');
gui_internal_widget_append(w,
@@ -2138,6 +2140,39 @@ static void gui_internal_menu_root(struct gui_priv *this)
gui_internal_menu_render(this);
}
+static void
+gui_internal_cmd_menu(struct gui_priv *this, struct point *p)
+{
+ struct graphics *gra=this->gra;
+ struct transformation *trans;
+ struct coord c;
+ struct attr attr,attrp;
+
+ navit_block(this->nav, 1);
+ graphics_overlay_disable(gra, 1);
+ trans=navit_get_trans(this->nav);
+ if (p) {
+ transform_reverse(trans, p, &c);
+ dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
+ this->clickp.pro=transform_get_projection(trans);
+ this->clickp.x=c.x;
+ this->clickp.y=c.y;
+ this->clickp_valid=1;
+ }
+ if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
+ && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp)) {
+ this->vehiclep.pro=transform_get_projection(trans);
+ transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
+ this->vehiclep.x=c.x;
+ this->vehiclep.y=c.y;
+ this->vehicle_valid=1;
+ }
+ // draw menu
+ this->root.p.x=0;
+ this->root.p.y=0;
+ this->root.background=this->background;
+ gui_internal_menu_root(this);
+}
//##############################################################################################################
//# Description: Function to handle mouse clicks and scroll wheel movement
@@ -2148,37 +2183,13 @@ static void gui_internal_button(void *data, int pressed, int button, struct poin
{
struct gui_priv *this=data;
struct graphics *gra=this->gra;
- struct transformation *trans;
- struct attr attr,attrp;
- struct coord c;
// if still on the map (not in the menu, yet):
if (!this->root.children) {
// check whether the position of the mouse changed during press/release OR if it is the scrollwheel
if (!navit_handle_button(this->nav, pressed, button, p, NULL) || button >=4) // Maybe there's a better way to do this
return;
-
- navit_block(this->nav, 1);
- graphics_overlay_disable(gra, 1);
- trans=navit_get_trans(this->nav);
- transform_reverse(trans, p, &c);
- dbg(0,"x=0x%x y=0x%x\n", c.x, c.y);
- this->clickp.pro=transform_get_projection(trans);
- this->clickp.x=c.x;
- this->clickp.y=c.y;
- if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
- && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp)) {
- this->vehiclep.pro=transform_get_projection(trans);
- transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
- this->vehiclep.x=c.x;
- this->vehiclep.y=c.y;
- this->vehicle_valid=1;
- }
- // draw menu
- this->root.p.x=0;
- this->root.p.y=0;
- this->root.background=this->background;
- gui_internal_menu_root(this);
+ gui_internal_cmd_menu(this, p);
return;
}
@@ -2217,7 +2228,7 @@ static void gui_internal_resize(void *data, int w, int h)
struct gui_priv *this=data;
this->root.w=w;
this->root.h=h;
- dbg(0,"w=%d h=%d\n", w, h);
+ dbg(0,"w=%d h=%d children=%p\n", w, h, this->root.children);
navit_resize(this->nav, w, h);
if (this->root.children) {
gui_internal_prune_menu(this, NULL);
@@ -2340,7 +2351,8 @@ static struct gui_priv * gui_internal_new(struct navit *nav, struct gui_methods
*meth=gui_internal_methods;
this=g_new0(struct gui_priv, 1);
this->nav=nav;
-
+ navit_command_register(nav,"gui_internal_menu",callback_new_2(gui_internal_cmd_menu,this,NULL));
+ navit_command_register(nav,"gui_internal_fullscreen",callback_new_2(gui_internal_cmd_fullscreen,this,NULL));
return this;
}
diff --git a/navit/navit.c b/navit/navit.c
index babec6a37..4dadd2561 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -124,6 +124,7 @@ struct navit {
int destination_valid;
int blocked;
int w,h;
+ GHashTable *commands;
};
struct gui *main_loop_gui;
@@ -461,6 +462,9 @@ navit_new(struct attr *parent, struct attr **attrs)
this_->trans=transform_new();
transform_setup(this_->trans, &center, zoom, 0);
this_->displaylist=graphics_displaylist_new();
+ this_->commands=g_hash_table_new(g_str_hash, g_str_equal);
+ navit_command_register(this_, "zoom_in", callback_new_3(navit_zoom_in, this_, 2, NULL));
+ navit_command_register(this_, "zoom_out", callback_new_3(navit_zoom_out, this_, 2, NULL));
return this_;
}
@@ -1714,12 +1718,45 @@ navit_block(struct navit *this_, int block)
return 0;
}
+int
+navit_command_register(struct navit *this_, char *command, struct callback *cb)
+{
+ dbg(0,"registering '%s'\n", command);
+ g_hash_table_insert(this_->commands, command, cb);
+
+ return 0;
+}
+
+struct callback *
+navit_command_unregister(struct navit *this_, char *command)
+{
+ struct callback *ret=g_hash_table_lookup(this_->commands, command);
+ if (ret) {
+ g_hash_table_remove(this_->commands, command);
+ }
+
+ return ret;
+}
+
+int
+navit_command_call(struct navit *this_, char *command)
+{
+ struct callback *cb=g_hash_table_lookup(this_->commands, command);
+ dbg(0,"calling callback %p for '%s'\n", cb, command);
+ if (! cb)
+ return 1;
+ callback_call_1(cb, command);
+}
+
void
navit_destroy(struct navit *this_)
{
/* TODO: destroy objects contained in this_ */
main_remove_navit(this_);
navit_write_center_to_file(this_, "center.txt");
+ callback_destroy(navit_command_unregister(this_, "zoom_in"));
+ callback_destroy(navit_command_unregister(this_, "zoom_out"));
+ g_hash_table_destroy(this_->commands);
g_free(this_);
}
diff --git a/navit/navit.h b/navit/navit.h
index c13c87ba7..1cf91fb84 100644
--- a/navit/navit.h
+++ b/navit/navit.h
@@ -89,6 +89,9 @@ struct route *navit_get_route(struct navit *this_);
struct navigation *navit_get_navigation(struct navit *this_);
struct displaylist *navit_get_displaylist(struct navit *this_);
int navit_block(struct navit *this_, int block);
+int navit_command_register(struct navit *this_, char *command, struct callback *cb);
+struct callback *navit_command_unregister(struct navit *this_, char *command);
+int navit_command_call(struct navit *this_, char *command);
void navit_destroy(struct navit *this_);
/* end of prototypes */
#ifdef __cplusplus
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index ee8b04c64..53ceac8ae 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -594,6 +594,7 @@ struct osd_button {
struct callback *navit_init_cb;
struct callback *draw_cb;
struct graphics_image *img;
+ int pressed;
char *src;
char *command;
};
@@ -613,17 +614,14 @@ osd_button_click(struct osd_button *this, struct navit *nav, int pressed, int bu
{
struct point bp=this->p;
wrap_point(&bp, this->nav);
- if (p->x < bp.x || p->y < bp.y || p->x > bp.x+this->img->width || p->y > bp.y+this->img->height)
+ dbg(0,"%d,%d-%d,%d %d,%d\n", bp.x, bp.y, bp.x+this->img->width, bp.y+this->img->height, p->x, p->y);
+ if ((p->x < bp.x || p->y < bp.y || p->x > bp.x+this->img->width || p->y > bp.y+this->img->height) && !this->pressed)
return;
navit_ignore_button(nav);
+ this->pressed=pressed;
if (pressed) {
- dbg(0,"enter\n");
- if (! strcmp(this->command, "zoom_in")) {
- navit_zoom_in(nav, 2, NULL);
- }
- if (! strcmp(this->command, "zoom_out")) {
- navit_zoom_out(nav, 2, NULL);
- }
+ dbg(0,"calling command '%s'\n", this->command);
+ navit_command_call(nav, this->command);
}
}