38 |
#define SAT_WIDTH 330 |
#define SAT_WIDTH 330 |
39 |
#define SAT_HEIGHT 60 |
#define SAT_HEIGHT 60 |
40 |
|
|
41 |
/* http://www.gtk.org/tutorial1.2/gtk_tut-30.html */ |
#ifdef ESPEAK |
|
/* http://developer.gimp.org/api/2.0/gdk/gdk-Drawing-Primitives.html */ |
|
42 |
|
|
43 |
|
#endif |
44 |
|
|
45 |
static float rad2deg(float rad) { |
static float rad2deg(float rad) { |
46 |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
88 |
/* draw the locked/unlocked icon */ |
/* draw the locked/unlocked icon */ |
89 |
gdk_draw_pixbuf(context->gotoc.compass_pixmap, |
gdk_draw_pixbuf(context->gotoc.compass_pixmap, |
90 |
widget->style->fg_gc[GTK_STATE_NORMAL], |
widget->style->fg_gc[GTK_STATE_NORMAL], |
91 |
icon_get(ICON_MISC, context->appdata->compass_locked?1:2), |
icon_get(ICON_MISC, context->appdata->compass_locked?0:1), |
92 |
0, 0, (width-diameter)/2 + diameter/32, |
0, 0, (width-diameter)/2 + diameter/32, |
93 |
(height+diameter)/2 - 16 - diameter/32 , 16, 16, |
(height+diameter)/2 - 16 - diameter/32 , 16, 16, |
94 |
GDK_RGB_DITHER_NONE,0,0); |
GDK_RGB_DITHER_NONE,0,0); |
452 |
return TRUE; // fire again |
return TRUE; // fire again |
453 |
} |
} |
454 |
|
|
|
static gint waypoint_changed_event(GtkWidget *widget, gpointer data ) { |
|
|
cache_context_t *context = (cache_context_t*)data; |
|
|
int wpt_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); |
|
|
|
|
|
/* get position of selected waypoint */ |
|
|
if(wpt_idx == 0) |
|
|
context->gotoc.pos = context->appdata->geomath; |
|
|
else if(wpt_idx == 1) |
|
|
// context->gotoc.pos = gpx_cache_pos(context->cache); |
|
|
context->gotoc.pos = notes_get_pos(context); |
|
|
else { |
|
|
wpt_t *wpt = context->cache->wpt; |
|
|
while(wpt_idx > 2) { |
|
|
g_assert(wpt != NULL); |
|
|
wpt = wpt->next; |
|
|
wpt_idx--; |
|
|
} |
|
|
context->gotoc.pos = wpt->pos; |
|
|
} |
|
|
|
|
|
char str[32]; |
|
|
pos_lat_str(str, sizeof(str), context->gotoc.pos.lat); |
|
|
gtk_label_set_text(GTK_LABEL(context->gotoc.lat_lbl), str); |
|
|
pos_lon_str(str, sizeof(str), context->gotoc.pos.lon); |
|
|
gtk_label_set_text(GTK_LABEL(context->gotoc.lon_lbl), str); |
|
|
|
|
|
goto_update(context); |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static void manual_pos_update(cache_context_t *context) { |
|
|
context->gotoc.pos.lat = context->appdata->manual_goto.lat; |
|
|
context->gotoc.pos.lon = context->appdata->manual_goto.lon; |
|
|
|
|
|
char str[32]; |
|
|
pos_lat_str(str, sizeof(str), context->gotoc.pos.lat); |
|
|
gtk_label_set_text(GTK_LABEL(context->gotoc.lat_lbl), str); |
|
|
pos_lon_str(str, sizeof(str), context->gotoc.pos.lon); |
|
|
gtk_label_set_text(GTK_LABEL(context->gotoc.lon_lbl), str); |
|
|
|
|
|
goto_update(context); |
|
|
} |
|
|
|
|
|
static void on_posedit_clicked(GtkWidget *button, gpointer data) { |
|
|
cache_context_t *context = (cache_context_t*)data; |
|
|
|
|
|
GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Edit Position"), |
|
|
GTK_WINDOW(context->appdata->window), GTK_DIALOG_MODAL, |
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); |
|
|
|
|
|
GtkWidget *lat, *lon, *label; |
|
|
GtkWidget *table = gtk_table_new(2, 2, FALSE); |
|
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
label = gtk_label_new(_("Latitude:")), 0, 1, 0, 1); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
lat = lat_entry_new(context->appdata->manual_goto.lat), |
|
|
1, 2, 0, 1); |
|
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
label = gtk_label_new(_("Longitude:")), 0, 1, 1, 2); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
lon = lon_entry_new(context->appdata->manual_goto.lon), |
|
|
1, 2, 1, 2); |
|
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table); |
|
|
|
|
|
gtk_widget_show_all(dialog); |
|
|
|
|
|
if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { |
|
|
if(isnan(lat_get(lat)) || isnan(lon_get(lon))) |
|
|
errorf(_("Ignoring invalid position")); |
|
|
else { |
|
|
context->appdata->manual_goto.lat = lat_get(lat); |
|
|
context->appdata->manual_goto.lon = lon_get(lon); |
|
|
|
|
|
manual_pos_update(context); |
|
|
} |
|
|
} |
|
|
gtk_widget_destroy(dialog); |
|
|
} |
|
|
|
|
|
static gint radio_changed_event(GtkWidget *widget, gpointer data ) { |
|
|
cache_context_t *context = (cache_context_t*)data; |
|
|
|
|
|
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { |
|
|
manual_pos_update(context); |
|
|
gtk_widget_set_sensitive(context->gotoc.edit_but, TRUE); |
|
|
} else { |
|
|
waypoint_changed_event(context->gotoc.cbox, data); |
|
|
gtk_widget_set_sensitive(context->gotoc.edit_but, FALSE); |
|
|
} |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
#ifdef ENABLE_MAEMO_MAPPER |
|
|
static void on_mm_button_clicked(GtkButton *button, gpointer data) { |
|
|
cache_context_t *context = (cache_context_t*)data; |
|
|
|
|
|
dbus_mm_set_position(context->appdata, &context->gotoc.pos); |
|
|
} |
|
|
#endif |
|
|
|
|
455 |
static gboolean compass_clicked_event(GtkWidget *widget, GdkEventButton *event, |
static gboolean compass_clicked_event(GtkWidget *widget, GdkEventButton *event, |
456 |
gpointer user_data) { |
gpointer user_data) { |
457 |
cache_context_t *context = (cache_context_t*)user_data; |
cache_context_t *context = (cache_context_t*)user_data; |
471 |
return FALSE; |
return FALSE; |
472 |
} |
} |
473 |
|
|
474 |
|
static void pos_modified(GtkWidget *widget, gpointer data ) { |
475 |
|
cache_context_t *context = (cache_context_t*)data; |
476 |
|
|
477 |
|
/* extract position from entries */ |
478 |
|
context->gotoc.pos.lat = lat_entry_get(context->gotoc.lat_entry); |
479 |
|
context->gotoc.pos.lon = lon_entry_get(context->gotoc.lon_entry); |
480 |
|
|
481 |
|
goto_update(context); |
482 |
|
} |
483 |
|
|
484 |
|
#ifdef ESPEAK |
485 |
|
static void espeak_clicked(GtkWidget *widget, gpointer data) { |
486 |
|
appdata_t *appdata = (appdata_t*)data; |
487 |
|
|
488 |
|
GtkWidget *icon = gtk_button_get_image(GTK_BUTTON(widget)); |
489 |
|
gtk_widget_destroy(icon); |
490 |
|
appdata->espeak.enabled = !appdata->espeak.enabled; |
491 |
|
gtk_button_set_image(GTK_BUTTON(widget), icon_get_widget(ICON_MISC, |
492 |
|
appdata->espeak.enabled?6:7)); |
493 |
|
} |
494 |
|
#endif |
495 |
|
|
496 |
GtkWidget *goto_cache(cache_context_t *context) { |
GtkWidget *goto_cache(cache_context_t *context) { |
497 |
int i; |
int i; |
498 |
|
|
502 |
|
|
503 |
context->gotoc.pos = gpx_cache_pos(context->cache); |
context->gotoc.pos = gpx_cache_pos(context->cache); |
504 |
|
|
505 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 32); |
506 |
|
|
507 |
context->gotoc.compass_area = gtk_drawing_area_new(); |
context->gotoc.compass_area = gtk_drawing_area_new(); |
508 |
gtk_drawing_area_size(GTK_DRAWING_AREA(context->gotoc.compass_area), |
gtk_drawing_area_size(GTK_DRAWING_AREA(context->gotoc.compass_area), |
521 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->gotoc.compass_area); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->gotoc.compass_area); |
522 |
|
|
523 |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
524 |
GtkWidget *table = gtk_table_new(8, 2, FALSE); |
GtkWidget *table = gtk_table_new(5, 3, FALSE); |
525 |
|
|
526 |
/* ---------- combo box containing waypoint names ------- */ |
/* ---------- destination coordinates ------- */ |
|
GtkWidget *radio = gtk_radio_button_new_with_label(NULL, _("Waypoint:")); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), radio, 0,1,0,1); |
|
|
|
|
|
context->gotoc.cbox = gtk_combo_box_new_text(); |
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(context->gotoc.cbox), _("Geomath")); |
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(context->gotoc.cbox), |
|
|
context->cache->id); |
|
|
|
|
|
wpt_t *wpt = context->cache->wpt; |
|
|
while(wpt) { |
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(context->gotoc.cbox), wpt->id); |
|
|
wpt = wpt->next; |
|
|
} |
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(context->gotoc.cbox), 1); |
|
|
gtk_signal_connect(GTK_OBJECT(context->gotoc.cbox), "changed", |
|
|
(GtkSignalFunc)waypoint_changed_event, context); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.cbox, 1,2,0,1); |
|
|
|
|
|
/* -------------- manual entry field ------------------------- */ |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), |
|
|
gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), |
|
|
_("Manual:")), 0,1,1,2); |
|
|
gtk_signal_connect(GTK_OBJECT(radio), "clicked", |
|
|
(GtkSignalFunc)radio_changed_event, context); |
|
|
|
|
|
context->gotoc.edit_but = gtk_button_new_with_label(_("Edit")); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.edit_but, 1,2,1,2); |
|
|
gtk_signal_connect(GTK_OBJECT(context->gotoc.edit_but), "clicked", |
|
|
(GtkSignalFunc)on_posedit_clicked, context); |
|
|
gtk_widget_set_sensitive(context->gotoc.edit_but, FALSE); |
|
|
|
|
|
#if 0 |
|
|
context->gotoc.man_lat = entry_new(); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.man_lat, 1,2,1,2); |
|
|
pos_lat_str(str, sizeof(str), context->appdata->manual_goto.lat); |
|
|
gtk_entry_set_text(GTK_ENTRY(context->gotoc.man_lat), str); |
|
|
textbox_disable(context->gotoc.man_lat); |
|
|
context->gotoc.man_lon = entry_new(); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.man_lon, 1,2,2,3); |
|
|
pos_lon_str(str, sizeof(str), context->appdata->manual_goto.lon); |
|
|
gtk_entry_set_text(GTK_ENTRY(context->gotoc.man_lon), str); |
|
|
textbox_disable(context->gotoc.man_lon); |
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(context->gotoc.man_lat), "changed", |
|
|
(GtkSignalFunc)entry_changed_event, context); |
|
|
gtk_signal_connect(GTK_OBJECT(context->gotoc.man_lon), "changed", |
|
|
(GtkSignalFunc)entry_changed_event, context); |
|
|
#endif |
|
|
|
|
|
gtk_table_set_row_spacing(GTK_TABLE(table), 2, 16); |
|
527 |
|
|
|
/* -------------- waypoint coordinates ------------------------- */ |
|
528 |
/* SIZE_SMALL doesn't work here as setting the label returns to normal */ |
/* SIZE_SMALL doesn't work here as setting the label returns to normal */ |
529 |
context->gotoc.lat_lbl = pos_lat(context->gotoc.pos.lat, SIZE_NORMAL, |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Latitude:")), 0,1,0,1); |
530 |
STRIKETHROUGH_NONE); |
context->gotoc.lat_entry = lat_entry_new(context->gotoc.pos.lat); |
531 |
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.lat_lbl,0,1,3,4); |
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.lat_entry, 1,2,0,1); |
532 |
context->gotoc.lon_lbl = pos_lon(context->gotoc.pos.lon, SIZE_NORMAL, |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Longitude:")), 0,1,1,2); |
533 |
STRIKETHROUGH_NONE); |
context->gotoc.lon_entry = lon_entry_new(context->gotoc.pos.lon); |
534 |
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.lon_lbl,1,2,3,4); |
gtk_table_attach_defaults(GTK_TABLE(table), context->gotoc.lon_entry, 1,2,1,2); |
535 |
|
|
536 |
|
g_signal_connect(G_OBJECT(context->gotoc.lat_entry), "changed", |
537 |
|
G_CALLBACK(pos_modified), context); |
538 |
|
g_signal_connect(G_OBJECT(context->gotoc.lon_entry), "changed", |
539 |
|
G_CALLBACK(pos_modified), context); |
540 |
|
|
541 |
|
gtk_table_attach_defaults(GTK_TABLE(table), preset_coordinate_picker(context->appdata, |
542 |
|
context->gotoc.lat_entry, context->gotoc.lon_entry), 2,3,0,1); |
543 |
|
|
544 |
|
gtk_table_attach_defaults(GTK_TABLE(table), goto_coordinate(context->appdata, |
545 |
|
context->gotoc.lat_entry, context->gotoc.lon_entry), 2,3,1,2); |
546 |
|
|
547 |
|
gtk_table_set_row_spacing(GTK_TABLE(table), 1, 16); |
548 |
|
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
549 |
|
|
550 |
/* -------------- distance label ------------------------- */ |
/* -------------- distance label ------------------------- */ |
551 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Distance:")), 0,1,2,3); |
|
gtk_label_new(_("Distance:")), 0,1,4,5); |
|
552 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
553 |
(context->gotoc.distance_label = gtk_label_new("-----")), 1,2,4,5); |
(context->gotoc.distance_label = gtk_label_new("-----")), 1,2,2,3); |
554 |
|
|
555 |
/* -------------- bearing label ------------------------- */ |
/* -------------- bearing label ------------------------- */ |
556 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Bearing:")), 0,1,3,4); |
|
gtk_label_new(_("Bearing:")), 0,1,5,6); |
|
557 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
558 |
(context->gotoc.bearing_label = gtk_label_new("-----")), 1,2,5,6); |
(context->gotoc.bearing_label = gtk_label_new("-----")), 1,2,3,4); |
559 |
|
|
560 |
/* -------------- error label ------------------------- */ |
/* -------------- error label ------------------------- */ |
561 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Est. error:")), 0,1,4,5); |
|
gtk_label_new(_("Est. error:")), 0,1,6,7); |
|
562 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
563 |
(context->gotoc.eph_label = gtk_label_new("-----")), 1,2,6,7); |
(context->gotoc.eph_label = gtk_label_new("-----")), 1,2,4,5); |
564 |
|
|
565 |
gtk_table_set_row_spacing(GTK_TABLE(table), 6, 16); |
gtk_table_set_row_spacing(GTK_TABLE(table), 4, 16); |
566 |
|
|
567 |
/* -------------- sat view box ------------------------- */ |
/* -------------- sat view box ------------------------- */ |
568 |
GtkWidget *ihbox = gtk_hbox_new(FALSE,0); |
GtkWidget *ihbox = gtk_hbox_new(FALSE,0); |
580 |
|
|
581 |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
582 |
|
|
583 |
#ifdef ENABLE_MAEMO_MAPPER |
#ifdef ESPEAK |
584 |
GtkWidget *mm_button = gtk_button_new(); |
GtkWidget *ivbox = gtk_vbox_new(FALSE, 0); |
585 |
gtk_button_set_image(GTK_BUTTON(mm_button), icon_get_widget(ICON_MISC, 0)); |
GtkWidget *button = button_new(); |
586 |
gtk_signal_connect(GTK_OBJECT(mm_button), "clicked", |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, |
587 |
(GtkSignalFunc)on_mm_button_clicked, context); |
context->appdata->espeak.enabled?6:7)); |
588 |
gtk_box_pack_start(GTK_BOX(ihbox), mm_button, 1,0,0); |
gtk_signal_connect (GTK_OBJECT(button), "clicked", |
589 |
|
GTK_SIGNAL_FUNC(espeak_clicked), context->appdata); |
590 |
|
if(context->appdata->espeak.sample_rate < 0) |
591 |
|
gtk_widget_set_sensitive(button, FALSE); |
592 |
|
|
593 |
|
gtk_box_pack_start(GTK_BOX(ivbox), button, 1,0,0); |
594 |
|
gtk_box_pack_start(GTK_BOX(ihbox), ivbox, 1,0,0); |
595 |
#endif |
#endif |
596 |
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,2,7,8); |
|
597 |
|
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,3,5,6); |
598 |
|
|
599 |
/* ------------------------------------------------------- */ |
/* ------------------------------------------------------- */ |
600 |
|
|
601 |
gtk_box_pack_start(GTK_BOX(vbox), table, 1,0,0); |
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, FALSE, 0); |
602 |
gtk_box_pack_start(GTK_BOX(hbox), vbox, 1,0,0); |
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); |
603 |
|
|
604 |
context->gotoc.handler_id = gtk_timeout_add(UPDATE_MS, |
context->gotoc.handler_id = |
605 |
goto_update, context); |
gtk_timeout_add(UPDATE_MS, goto_update, context); |
606 |
|
|
607 |
return hbox; |
return hbox; |
608 |
} |
} |
609 |
|
|
610 |
void goto_coordinate_update(cache_context_t *context) { |
void goto_coordinate_update(cache_context_t *context) { |
611 |
|
static pos_t pos = { 0.0, 0.0 }; |
612 |
|
|
613 |
if(!context->notes.modified) |
if(!context->notes.modified) |
614 |
return; |
return; |
615 |
|
|
616 |
waypoint_changed_event(context->gotoc.cbox, context); |
pos_t npos = notes_get_pos(context); |
617 |
|
if(pos_differ(&npos, &pos)) { |
618 |
|
pos = npos; |
619 |
|
|
620 |
|
lat_entry_set(context->gotoc.lat_entry, npos.lat); |
621 |
|
lon_entry_set(context->gotoc.lon_entry, npos.lon); |
622 |
|
} |
623 |
} |
} |