From 74a2d758b956a76719291866ab96466b973ed55b Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 11 Jun 2007 16:37:15 +0300 Subject: [PATCH] Add function for loading icons. Use hash table to cache loaded icons. Always display time. Other misc changes. --- src/gps-panels.c | 876 +++++++++++++++++++++++------------------------ src/map-poi.c | 41 ++- 2 files changed, 461 insertions(+), 456 deletions(-) diff --git a/src/gps-panels.c b/src/gps-panels.c index 101d1d0..dd2e07c 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -23,515 +23,509 @@ void gps_display_data(void) { - gchar *buffer, litbuf[16]; - printf("%s()\n", __PRETTY_FUNCTION__); - - if (_gps.fix < 2) { - /* no fix no fun */ - gtk_label_set_label(GTK_LABEL(_text_lat), " --- "); - gtk_label_set_label(GTK_LABEL(_text_lon), " --- "); - gtk_label_set_label(GTK_LABEL(_text_speed), " --- "); - gtk_label_set_label(GTK_LABEL(_text_alt), " --- "); - gtk_label_set_label(GTK_LABEL(_text_time), " --:--:-- "); - } else { - gfloat speed = _gps.speed * UNITS_CONVERT[_units]; - - /* latitude */ - lat_format(_gps.lat, litbuf); - gtk_label_set_label(GTK_LABEL(_text_lat), litbuf); - - /* longitude */ - lon_format(_gps.lon, litbuf); - gtk_label_set_label(GTK_LABEL(_text_lon), litbuf); - - /* speed */ - switch (_units) { - case UNITS_MI: - buffer = g_strdup_printf("Spd: %.1f mph", speed); - break; - case UNITS_NM: - buffer = g_strdup_printf("Spd: %.1f kn", speed); - break; - default: - buffer = g_strdup_printf("Spd: %.1f km/h", speed); - break; - } - gtk_label_set_label(GTK_LABEL(_text_speed), buffer); - g_free(buffer); - - /* altitude */ - switch (_units) { - case UNITS_MI: - case UNITS_NM: - buffer = g_strdup_printf("Alt: %.1f ft", - _pos.altitude * 3.2808399f); - break; - default: - buffer = g_strdup_printf("Alt: %.1f m", _pos.altitude); - } - gtk_label_set_label(GTK_LABEL(_text_alt), buffer); - g_free(buffer); +gchar *buffer, litbuf[16]; +printf("%s()\n", __PRETTY_FUNCTION__); + +/* local time */ +strftime(litbuf, 15, "%X", localtime(&_pos.time)); +gtk_label_set_label(GTK_LABEL(_text_time), litbuf); + +if (_gps.fix < 2) { + /* no fix no fun */ + gtk_label_set_label(GTK_LABEL(_text_lat), " --- "); + gtk_label_set_label(GTK_LABEL(_text_lon), " --- "); + gtk_label_set_label(GTK_LABEL(_text_speed), " --- "); + gtk_label_set_label(GTK_LABEL(_text_alt), " --- "); +} else { + gfloat speed = _gps.speed * UNITS_CONVERT[_units]; + + /* latitude */ + lat_format(_gps.lat, litbuf); + gtk_label_set_label(GTK_LABEL(_text_lat), litbuf); + + /* longitude */ + lon_format(_gps.lon, litbuf); + gtk_label_set_label(GTK_LABEL(_text_lon), litbuf); + + /* speed */ + switch (_units) { + case UNITS_MI: + buffer = g_strdup_printf("Spd: %.1f mph", speed); + break; + case UNITS_NM: + buffer = g_strdup_printf("Spd: %.1f kn", speed); + break; + default: + buffer = g_strdup_printf("Spd: %.1f km/h", speed); + break; + } + gtk_label_set_label(GTK_LABEL(_text_speed), buffer); + g_free(buffer); - /* local time */ - strftime(litbuf, 15, "%X", localtime(&_pos.time)); - gtk_label_set_label(GTK_LABEL(_text_time), litbuf); + /* altitude */ + switch (_units) { + case UNITS_MI: + case UNITS_NM: + buffer = g_strdup_printf("Alt: %.1f ft", + _pos.altitude * 3.2808399f); + break; + default: + buffer = g_strdup_printf("Alt: %.1f m", _pos.altitude); } + gtk_label_set_label(GTK_LABEL(_text_alt), buffer); + g_free(buffer); +} - /* refresh sat panel */ - gtk_widget_queue_draw_area(GTK_WIDGET(_sat_panel), - 0, 0, - _sat_panel->allocation.width, - _sat_panel->allocation.height); +/* refresh sat panel */ +gtk_widget_queue_draw_area(GTK_WIDGET(_sat_panel), 0, 0, + _sat_panel->allocation.width, + _sat_panel->allocation.height); - /* refresh heading panel */ - gtk_widget_queue_draw_area(GTK_WIDGET(_heading_panel), - 0, 0, - _heading_panel->allocation.width, - _heading_panel->allocation.height); +/* refresh heading panel */ +gtk_widget_queue_draw_area(GTK_WIDGET(_heading_panel), 0, 0, + _heading_panel->allocation.width, + _heading_panel->allocation.height); - vprintf("%s(): return\n", __PRETTY_FUNCTION__); - return; +vprintf("%s(): return\n", __PRETTY_FUNCTION__); +return; } -void gps_hide_text(void) +void +gps_hide_text(void) { - printf("%s()\n", __PRETTY_FUNCTION__); +printf("%s()\n", __PRETTY_FUNCTION__); - /* Clear gps data */ - _gps.fix = 1; - _gps.satinuse = 0; - _gps.satinview = 0; +/* Clear gps data */ +_gps.fix = 1; +_gps.satinuse = 0; +_gps.satinview = 0; - if (_gps_info) - gps_display_data(); +if (_gps_info) + gps_display_data(); - vprintf("%s(): return\n", __PRETTY_FUNCTION__); +vprintf("%s(): return\n", __PRETTY_FUNCTION__); } void gps_show_info(void) { - printf("%s()\n", __PRETTY_FUNCTION__); +printf("%s()\n", __PRETTY_FUNCTION__); - if (_gps_info && _enable_gps) - gtk_widget_show_all(GTK_WIDGET(_gps_widget)); - else { - gps_hide_text(); - gtk_widget_hide_all(GTK_WIDGET(_gps_widget)); - } +if (_gps_info && _enable_gps) + gtk_widget_show_all(GTK_WIDGET(_gps_widget)); +else { + gps_hide_text(); + gtk_widget_hide_all(GTK_WIDGET(_gps_widget)); +} - vprintf("%s(): return\n", __PRETTY_FUNCTION__); +vprintf("%s(): return\n", __PRETTY_FUNCTION__); } static void draw_sat_info(GtkWidget * widget, guint x0, guint y0, guint width, guint height, gboolean showsnr) { - GdkGC *gc; - guint step, i, j, snr_height, bymargin, xoffset, yoffset; - guint x, y, x1, y1; - gchar *tmp = NULL; - printf("%s()\n", __PRETTY_FUNCTION__); - - xoffset = x0; - yoffset = y0; - /* Bootom margin - 12% */ - bymargin = height * 0.88f; +GdkGC *gc; +guint step, i, j, snr_height, bymargin, xoffset, yoffset; +guint x, y, x1, y1; +gchar *tmp = NULL; +printf("%s()\n", __PRETTY_FUNCTION__); + +xoffset = x0; +yoffset = y0; +/* Bootom margin - 12% */ +bymargin = height * 0.88f; + +/* Bottom line */ +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + 5, yoffset + bymargin, + xoffset + width - 10 - 2, yoffset + bymargin); +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + 5, yoffset + bymargin - 1, + xoffset + width - 10 - 2, yoffset + bymargin - 1); + +if (_gps.satinview > 0) { + /* Left margin - 5pix, Right margin - 5pix */ + step = (width - 10) / _gps.satinview; - /* Bottom line */ - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + 5, yoffset + bymargin, - xoffset + width - 10 - 2, yoffset + bymargin); - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + 5, yoffset + bymargin - 1, - xoffset + width - 10 - 2, yoffset + bymargin - 1); - - if (_gps.satinview > 0) { - /* Left margin - 5pix, Right margin - 5pix */ - step = (width - 10) / _gps.satinview; - - for (i = 0; i < _gps.satinview; i++) { - /* Sat used or not */ - gc = _sat_info_gc1; - for (j = 0; j < _gps.satinuse; j++) { - if (_gps.satforfix[j] == _gps_sat[i].prn) { - gc = _sat_info_gc2; - break; - } + for (i = 0; i < _gps.satinview; i++) { + /* Sat used or not */ + gc = _sat_info_gc1; + for (j = 0; j < _gps.satinuse; j++) { + if (_gps.satforfix[j] == _gps_sat[i].prn) { + gc = _sat_info_gc2; + break; } + } - x = 5 + i * step; - snr_height = _gps_sat[i].snr * height * 0.78f / 100; - y = height * 0.1f + (height * 0.78f - snr_height); - - /* draw sat rectangle... */ - gdk_draw_rectangle(widget->window, - gc, - TRUE, - xoffset + x, - yoffset + y, step - 2, snr_height); - - if (showsnr && _gps_sat[i].snr > 0) { - /* ...snr.. */ - tmp = g_strdup_printf("%02d", _gps_sat[i].snr); - pango_layout_set_text(_sat_info_layout, tmp, 2); - pango_layout_get_pixel_size(_sat_info_layout, - &x1, &y1); - gdk_draw_layout(widget->window, - widget->style-> - fg_gc[GTK_STATE_NORMAL], - xoffset + x + ((step - 2) - - x1) / 2, - yoffset + y - 15, - _sat_info_layout); - g_free(tmp); - } + x = 5 + i * step; + snr_height = _gps_sat[i].snr * height * 0.78f / 100; + y = height * 0.1f + (height * 0.78f - snr_height); + + /* draw sat rectangle... */ + gdk_draw_rectangle(widget->window, + gc, + TRUE, + xoffset + x, + yoffset + y, step - 2, snr_height); - /* ...and sat number */ - tmp = g_strdup_printf("%02d", _gps_sat[i].prn); + if (showsnr && _gps_sat[i].snr > 0) { + /* ...snr.. */ + tmp = g_strdup_printf("%02d", _gps_sat[i].snr); pango_layout_set_text(_sat_info_layout, tmp, 2); - pango_layout_get_pixel_size(_sat_info_layout, &x1, &y1); + pango_layout_get_pixel_size(_sat_info_layout, + &x1, &y1); gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - xoffset + x + ((step - 2) - x1) / 2, - yoffset + bymargin + 1, - _sat_info_layout); + widget->style-> + fg_gc[GTK_STATE_NORMAL], + xoffset + x + ((step - 2) - + x1) / 2, + yoffset + y - 15, + _sat_info_layout); g_free(tmp); } + + /* ...and sat number */ + tmp = g_strdup_printf("%02d", _gps_sat[i].prn); + pango_layout_set_text(_sat_info_layout, tmp, 2); + pango_layout_get_pixel_size(_sat_info_layout, &x1, &y1); + gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + xoffset + x + ((step - 2) - x1) / 2, + yoffset + bymargin + 1, + _sat_info_layout); + g_free(tmp); } +} - vprintf("%s(): return\n", __PRETTY_FUNCTION__); - return; +vprintf("%s(): return\n", __PRETTY_FUNCTION__); +return; } gboolean sat_panel_expose(GtkWidget * widget, GdkEventExpose * event) { - gchar *tmp = NULL; - guint x, y; - printf("%s()\n", __PRETTY_FUNCTION__); - - draw_sat_info(widget, - 0, 0, - widget->allocation.width, - widget->allocation.height, FALSE); - - /* Sat View/In Use */ - tmp = g_strdup_printf("%d/%d", _gps.satinuse, _gps.satinview); - pango_layout_set_text(_sat_panel_layout, tmp, -1); - pango_layout_set_alignment(_sat_panel_layout, PANGO_ALIGN_LEFT); - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - 20, 2, _sat_panel_layout); - g_free(tmp); - - switch (_gps.fix) { - case 2: - case 3: - tmp = g_strdup_printf("%dD fix", _gps.fix); - break; - default: - tmp = g_strdup_printf("nofix"); - break; - } - pango_layout_set_text(_sat_panel_layout, tmp, -1); - pango_layout_set_alignment(_sat_panel_layout, PANGO_ALIGN_RIGHT); - pango_layout_get_pixel_size(_sat_panel_layout, &x, &y); - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - widget->allocation.width - 20 - x, 2, - _sat_panel_layout); - g_free(tmp); +gchar *tmp = NULL; +guint x, y; +printf("%s()\n", __PRETTY_FUNCTION__); + +draw_sat_info(widget, + 0, 0, + widget->allocation.width, + widget->allocation.height, FALSE); + +/* Sat View/In Use */ +tmp = g_strdup_printf("%d/%d", _gps.satinuse, _gps.satinview); +pango_layout_set_text(_sat_panel_layout, tmp, -1); +pango_layout_set_alignment(_sat_panel_layout, PANGO_ALIGN_LEFT); +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + 20, 2, _sat_panel_layout); +g_free(tmp); + +switch (_gps.fix) { +case 2: +case 3: + tmp = g_strdup_printf("%dD fix", _gps.fix); +break; +default: + tmp = g_strdup_printf("nofix"); +break; +} - vprintf("%s(): return\n", __PRETTY_FUNCTION__); - return TRUE; +pango_layout_set_text(_sat_panel_layout, tmp, -1); +pango_layout_set_alignment(_sat_panel_layout, PANGO_ALIGN_RIGHT); +pango_layout_get_pixel_size(_sat_panel_layout, &x, &y); +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + widget->allocation.width - 20 - x, 2, + _sat_panel_layout); +g_free(tmp); + +vprintf("%s(): return\n", __PRETTY_FUNCTION__); +return TRUE; } gboolean heading_panel_expose(GtkWidget * widget, GdkEventExpose * event) { - guint size, xoffset, yoffset, i, x, y; - gint dir; - gfloat tmp; - gchar *text; - printf("%s()\n", __PRETTY_FUNCTION__); - - size = MIN(widget->allocation.width, widget->allocation.height); - if (widget->allocation.width > widget->allocation.height) { - xoffset = - (widget->allocation.width - widget->allocation.height) / 2; - yoffset = 0; - } else { - xoffset = 0; - yoffset = - (widget->allocation.height - widget->allocation.width) / 2; +guint size, xoffset, yoffset, i, x, y; +gint dir; +gfloat tmp; +gchar *text; +printf("%s()\n", __PRETTY_FUNCTION__); + +size = MIN(widget->allocation.width, widget->allocation.height); +if (widget->allocation.width > widget->allocation.height) { + xoffset = (widget->allocation.width - widget->allocation.height) / 2; + yoffset = 0; +} else { + xoffset = 0; + yoffset = (widget->allocation.height - widget->allocation.width) / 2; +} +pango_font_description_set_size(_heading_panel_fontdesc, + 12 * PANGO_SCALE); +pango_layout_set_font_description(_heading_panel_layout, + _heading_panel_fontdesc); +pango_layout_set_alignment(_heading_panel_layout, PANGO_ALIGN_CENTER); + +text = g_strdup_printf("%3.0f°", _gps.heading); +pango_layout_set_text(_heading_panel_layout, text, -1); +pango_layout_get_pixel_size(_heading_panel_layout, &x, &y); + +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + xoffset + size / 2 - x / 2, + yoffset + size - y - 2, _heading_panel_layout); +g_free(text); + +gdk_draw_arc(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + FALSE, + xoffset, yoffset + size / 2, size, size, 0, 64 * 180); + +/* Simple arrow for heading */ +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + size / 2 + 3, + yoffset + size - y - 5, + xoffset + size / 2, yoffset + size / 2 + 5); + +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + size / 2 - 3, + yoffset + size - y - 5, + xoffset + size / 2, yoffset + size / 2 + 5); + +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + size / 2 - 3, + yoffset + size - y - 5, + xoffset + size / 2, yoffset + size - y - 8); + +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + size / 2 + 3, + yoffset + size - y - 5, + xoffset + size / 2, yoffset + size - y - 8); + +gint angle[5] = { -90, -45, 0, 45, 90 }; +gint fsize[5] = { 0, 4, 10, 4, 0 }; +for (i = 0; i < 5; i++) { + dir = (gint) (_gps.heading / 45) * 45 + angle[i]; + + switch (dir) { + case 0: + case 360: + text = g_strdup("N"); + break; + case 45: + case 405: + text = g_strdup("NE"); + break; + case 90: + text = g_strdup("E"); + break; + case 135: + text = g_strdup("SE"); + break; + case 180: + text = g_strdup("S"); + break; + case 225: + text = g_strdup("SW"); + break; + case 270: + case -90: + text = g_strdup("W"); + break; + case 315: + case -45: + text = g_strdup("NW"); + break; + default: + text = g_strdup("??"); + break; } - pango_font_description_set_size(_heading_panel_fontdesc, - 12 * PANGO_SCALE); - pango_layout_set_font_description(_heading_panel_layout, - _heading_panel_fontdesc); - pango_layout_set_alignment(_heading_panel_layout, PANGO_ALIGN_CENTER); - text = g_strdup_printf("%3.0f°", _gps.heading); + tmp = ((dir - _gps.heading) * (1.f / 180.f)) * PI; + gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + size / 2 + ((size / 2 - 5) * sinf(tmp)), + yoffset + size - ((size / 2 - 5) * cosf(tmp)), + xoffset + size / 2 + ((size / 2 + 5) * sinf(tmp)), + yoffset + size - ((size / 2 + 5) * cosf(tmp))); + + x = fsize[i]; + if (abs((guint) (_gps.heading / 45) * 45 - _gps.heading) + > abs((guint) (_gps.heading / 45) * 45 + 45 - _gps.heading) + && (i > 0)) + x = fsize[i - 1]; + + pango_font_description_set_size(_heading_panel_fontdesc, (10 + x) * PANGO_SCALE); + pango_layout_set_font_description(_heading_panel_layout, _heading_panel_fontdesc); pango_layout_set_text(_heading_panel_layout, text, -1); pango_layout_get_pixel_size(_heading_panel_layout, &x, &y); - - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - xoffset + size / 2 - x / 2, - yoffset + size - y - 2, _heading_panel_layout); + x = xoffset + size / 2 + ((size / 2 + 15) * sinf(tmp)) - x / 2, + y = yoffset + size - ((size / 2 + 15) * cosf(tmp)) - y / 2, + gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + x, y, _heading_panel_layout); g_free(text); +} - gdk_draw_arc(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - FALSE, - xoffset, yoffset + size / 2, size, size, 0, 64 * 180); - - /* Simple arrow for heading */ - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + size / 2 + 3, - yoffset + size - y - 5, - xoffset + size / 2, yoffset + size / 2 + 5); - - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + size / 2 - 3, - yoffset + size - y - 5, - xoffset + size / 2, yoffset + size / 2 + 5); - - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + size / 2 - 3, - yoffset + size - y - 5, - xoffset + size / 2, yoffset + size - y - 8); - - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + size / 2 + 3, - yoffset + size - y - 5, - xoffset + size / 2, yoffset + size - y - 8); - - gint angle[5] = { -90, -45, 0, 45, 90 }; - gint fsize[5] = { 0, 4, 10, 4, 0 }; - for (i = 0; i < 5; i++) { - dir = (gint) (_gps.heading / 45) * 45 + angle[i]; - - switch (dir) { - case 0: - case 360: - text = g_strdup("N"); - break; - case 45: - case 405: - text = g_strdup("NE"); - break; - case 90: - text = g_strdup("E"); - break; - case 135: - text = g_strdup("SE"); - break; - case 180: - text = g_strdup("S"); - break; - case 225: - text = g_strdup("SW"); - break; - case 270: - case -90: - text = g_strdup("W"); - break; - case 315: - case -45: - text = g_strdup("NW"); - break; - default: - text = g_strdup("??"); - break; - } - - tmp = ((dir - _gps.heading) * (1.f / 180.f)) * PI; - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + size / 2 + ((size / 2 - 5) * sinf(tmp)), - yoffset + size - ((size / 2 - 5) * cosf(tmp)), - xoffset + size / 2 + ((size / 2 + 5) * sinf(tmp)), - yoffset + size - ((size / 2 + 5) * cosf(tmp))); - - x = fsize[i]; - if (abs((guint) (_gps.heading / 45) * 45 - _gps.heading) - > abs((guint) (_gps.heading / 45) * 45 + 45 - _gps.heading) - && (i > 0)) - x = fsize[i - 1]; - - pango_font_description_set_size(_heading_panel_fontdesc, - (10 + x) * PANGO_SCALE); - pango_layout_set_font_description(_heading_panel_layout, - _heading_panel_fontdesc); - pango_layout_set_text(_heading_panel_layout, text, -1); - pango_layout_get_pixel_size(_heading_panel_layout, &x, &y); - x = xoffset + size / 2 + ((size / 2 + 15) * sinf(tmp)) - x / 2, - y = yoffset + size - ((size / 2 + 15) * cosf(tmp)) - y / 2, - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - x, y, _heading_panel_layout); - g_free(text); - } - - vprintf("%s(): return\n", __PRETTY_FUNCTION__); - return TRUE; +vprintf("%s(): return\n", __PRETTY_FUNCTION__); +return TRUE; } static void draw_sat_details(GtkWidget * widget, guint x0, guint y0, guint width, guint height) { - guint i, j, x, y, size, halfsize, xoffset, yoffset; - guint x1, y1; - gfloat tmp; - GdkColor color; - GdkGC *gc1, *gc2, *gc3, *gc; - gchar *buffer = NULL; - printf("%s()\n", __PRETTY_FUNCTION__); - - size = MIN(width, height); - halfsize = size / 2; - if (width > height) { - xoffset = x0 + (width - height - 10) / 2; - yoffset = y0 + 5; - } else { - xoffset = x0 + 5; - yoffset = y0 + (height - width - 10) / 2; - } - - /* 90 */ - gdk_draw_arc(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - FALSE, - xoffset + 2, yoffset + 2, size - 4, size - 4, 0, 64 * 360); - - /* 60 */ - gdk_draw_arc(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - FALSE, - xoffset + size / 6, yoffset + size / 6, - size / 6 * 4, size / 6 * 4, 0, 64 * 360); - - /* 30 */ - gdk_draw_arc(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - FALSE, - xoffset + size / 6 * 2, yoffset + size / 6 * 2, - size / 6 * 2, size / 6 * 2, 0, 64 * 360); - - guint line[12] = - { 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330 }; - - for (i = 0; i < 6; i++) { - /* line */ - tmp = (line[i] * (1.f / 180.f)) * PI; - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - xoffset + halfsize + (halfsize - 2) * sinf(tmp), - yoffset + halfsize - (halfsize - 2) * cosf(tmp), - xoffset + halfsize - (halfsize - 2) * sinf(tmp), - yoffset + halfsize + (halfsize - 2) * cosf(tmp)); - } - - for (i = 0; i < 12; i++) { - tmp = (line[i] * (1.f / 180.f)) * PI; - /* azimuth */ - if (line[i] == 0) - buffer = g_strdup_printf("N"); - else - buffer = g_strdup_printf("%d°", line[i]); - pango_layout_set_text(_sat_details_layout, buffer, -1); - pango_layout_get_pixel_size(_sat_details_layout, &x, &y); - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - (xoffset + halfsize + - (halfsize - size / 12) * sinf(tmp)) - x / 2, - (yoffset + halfsize - - (halfsize - size / 12) * cosf(tmp)) - y / 2, - _sat_details_layout); - g_free(buffer); - } +guint i, j, x, y, size, halfsize, xoffset, yoffset; +guint x1, y1; +gfloat tmp; +GdkColor color; +GdkGC *gc1, *gc2, *gc3, *gc; +gchar *buffer = NULL; +guint line[12] = { 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330 }; + +printf("%s()\n", __PRETTY_FUNCTION__); + +size = MIN(width, height); +halfsize = size / 2; +if (width > height) { + xoffset = x0 + (width - height - 10) / 2; + yoffset = y0 + 5; +} else { + xoffset = x0 + 5; + yoffset = y0 + (height - width - 10) / 2; +} - /* elevation 30 */ - tmp = (30 * (1.f / 180.f)) * PI; - buffer = g_strdup_printf("30°"); - pango_layout_set_text(_sat_details_layout, buffer, -1); - pango_layout_get_pixel_size(_sat_details_layout, &x, &y); - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - (xoffset + halfsize + size / 6 * 2 * sinf(tmp)) - x / 2, - (yoffset + halfsize - size / 6 * 2 * cosf(tmp)) - y / 2, - _sat_details_layout); - g_free(buffer); +/* 90 */ +gdk_draw_arc(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + FALSE, + xoffset + 2, yoffset + 2, size - 4, size - 4, 0, 64 * 360); + +/* 60 */ +gdk_draw_arc(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + FALSE, + xoffset + size / 6, yoffset + size / 6, + size / 6 * 4, size / 6 * 4, 0, 64 * 360); + +/* 30 */ +gdk_draw_arc(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + FALSE, + xoffset + size / 6 * 2, yoffset + size / 6 * 2, + size / 6 * 2, size / 6 * 2, 0, 64 * 360); + +for (i = 0; i < 6; i++) { + /* line */ + tmp = (line[i] * (1.f / 180.f)) * PI; + gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + xoffset + halfsize + (halfsize - 2) * sinf(tmp), + yoffset + halfsize - (halfsize - 2) * cosf(tmp), + xoffset + halfsize - (halfsize - 2) * sinf(tmp), + yoffset + halfsize + (halfsize - 2) * cosf(tmp)); +} - /* elevation 60 */ - tmp = (30 * (1.f / 180.f)) * PI; - buffer = g_strdup_printf("60°"); +for (i = 0; i < 12; i++) { + tmp = (line[i] * (1.f / 180.f)) * PI; + /* azimuth */ + if (line[i] == 0) + buffer = g_strdup_printf("N"); + else + buffer = g_strdup_printf("%d°", line[i]); pango_layout_set_text(_sat_details_layout, buffer, -1); pango_layout_get_pixel_size(_sat_details_layout, &x, &y); gdk_draw_layout(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], - (xoffset + halfsize + size / 6 * sinf(tmp)) - x / 2, - (yoffset + halfsize - size / 6 * cosf(tmp)) - y / 2, + (xoffset + halfsize + + (halfsize - size / 12) * sinf(tmp)) - x / 2, + (yoffset + halfsize - + (halfsize - size / 12) * cosf(tmp)) - y / 2, _sat_details_layout); g_free(buffer); +} - color.red = 0; - color.green = 0; - color.blue = 0; - gc1 = gdk_gc_new(widget->window); - gdk_gc_set_rgb_fg_color(gc1, &color); - - color.red = 0; - color.green = 0; - color.blue = 0xffff; - gc2 = gdk_gc_new(widget->window); - gdk_gc_set_rgb_fg_color(gc2, &color); - - color.red = 0xffff; - color.green = 0xffff; - color.blue = 0xffff; - gc3 = gdk_gc_new(widget->window); - gdk_gc_set_rgb_fg_color(gc3, &color); - - for (i = 0; i < _gps.satinview; i++) { - /* Sat used or not */ - gc = gc1; - for (j = 0; j < _gps.satinuse; j++) { - if (_gps.satforfix[j] == _gps_sat[i].prn) { - gc = gc2; - break; - } +/* elevation 30 */ +tmp = (30 * (1.f / 180.f)) * PI; +buffer = g_strdup_printf("30°"); +pango_layout_set_text(_sat_details_layout, buffer, -1); +pango_layout_get_pixel_size(_sat_details_layout, &x, &y); +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + (xoffset + halfsize + size / 6 * 2 * sinf(tmp)) - x / 2, + (yoffset + halfsize - size / 6 * 2 * cosf(tmp)) - y / 2, + _sat_details_layout); +g_free(buffer); + +/* elevation 60 */ +tmp = (30 * (1.f / 180.f)) * PI; +buffer = g_strdup_printf("60°"); +pango_layout_set_text(_sat_details_layout, buffer, -1); +pango_layout_get_pixel_size(_sat_details_layout, &x, &y); +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_STATE_NORMAL], + (xoffset + halfsize + size / 6 * sinf(tmp)) - x / 2, + (yoffset + halfsize - size / 6 * cosf(tmp)) - y / 2, + _sat_details_layout); +g_free(buffer); + +color.red = 0; +color.green = 0; +color.blue = 0; +gc1 = gdk_gc_new(widget->window); +gdk_gc_set_rgb_fg_color(gc1, &color); + +color.red = 0; +color.green = 0; +color.blue = 0xffff; +gc2 = gdk_gc_new(widget->window); +gdk_gc_set_rgb_fg_color(gc2, &color); + +color.red = 0xffff; +color.green = 0xffff; +color.blue = 0xffff; +gc3 = gdk_gc_new(widget->window); +gdk_gc_set_rgb_fg_color(gc3, &color); + +for (i = 0; i < _gps.satinview; i++) { + /* Sat used or not */ + gc = gc1; + for (j = 0; j < _gps.satinuse; j++) { + if (_gps.satforfix[j] == _gps_sat[i].prn) { + gc = gc2; + break; } + } - tmp = (_gps_sat[i].azimuth * (1.f / 180.f)) * PI; - x = xoffset + halfsize - + (90 - _gps_sat[i].elevation) * halfsize / 90 * sinf(tmp); - y = yoffset + halfsize - - (90 - _gps_sat[i].elevation) * halfsize / 90 * cosf(tmp); + tmp = (_gps_sat[i].azimuth * (1.f / 180.f)) * PI; + x = xoffset + halfsize + + (90 - _gps_sat[i].elevation) * halfsize / 90 * sinf(tmp); + y = yoffset + halfsize + - (90 - _gps_sat[i].elevation) * halfsize / 90 * cosf(tmp); - gdk_draw_arc(widget->window, - gc, TRUE, x - 10, y - 10, 20, 20, 0, 64 * 360); + gdk_draw_arc(widget->window, + gc, TRUE, x - 10, y - 10, 20, 20, 0, 64 * 360); - buffer = g_strdup_printf("%02d", _gps_sat[i].prn); - pango_layout_set_text(_sat_details_layout, buffer, -1); - pango_layout_get_pixel_size(_sat_details_layout, &x1, &y1); - gdk_draw_layout(widget->window, - gc3, - x - x1 / 2, y - y1 / 2, _sat_details_layout); - g_free(buffer); - } - g_object_unref(gc1); - g_object_unref(gc2); - g_object_unref(gc3); + buffer = g_strdup_printf("%02d", _gps_sat[i].prn); + pango_layout_set_text(_sat_details_layout, buffer, -1); + pango_layout_get_pixel_size(_sat_details_layout, &x1, &y1); + gdk_draw_layout(widget->window, + gc3, + x - x1 / 2, y - y1 / 2, _sat_details_layout); + g_free(buffer); +} +g_object_unref(gc1); +g_object_unref(gc2); +g_object_unref(gc3); - vprintf("%s(): return\n", __PRETTY_FUNCTION__); - return; +vprintf("%s(): return\n", __PRETTY_FUNCTION__); +return; } static gboolean diff --git a/src/map-poi.c b/src/map-poi.c index 953c0e3..040dd63 100644 --- a/src/map-poi.c +++ b/src/map-poi.c @@ -29,6 +29,8 @@ fontdesc = pango_font_description_new(); pango_font_description_set_family(fontdesc,"Sans Serif"); pango_font_description_set_size(fontdesc, POI_FONT_SIZE*PANGO_SCALE); pango_layout_set_font_description (layout, fontdesc); +pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); +return TRUE; } static void map_poi_title(gint x, gint y,gchar *title) @@ -37,6 +39,26 @@ pango_layout_set_text(layout, title, -1); gdk_draw_layout(_map_pixmap, _gc[COLORABLE_POI], x, y, layout); } +static GdkPixbuf *map_poi_get_icon(gchar *icon) +{ +gchar buffer[100]; +GdkPixbuf *pixbuf = NULL; +GError *error = NULL; + +pixbuf = g_hash_table_lookup(poi_icon_hash, icon); +if (pixbuf) + return pixbuf; + +snprintf(buffer, sizeof(buffer),"%s/icons/%s.jpg", _curr_repo->cache_dir, icon); +pixbuf=gdk_pixbuf_new_from_file(buffer, &error); + +if (error) + return NULL; + +g_hash_table_insert(poi_icon_hash, g_strdup(icon), pixbuf); +return pixbuf; +} + /** * Render all the POI data. This should be done before rendering track data. */ @@ -44,10 +66,8 @@ void map_render_poi() { guint unitx, unity; gfloat lat1, lat2, lon1, lon2; -gchar buffer[100]; gint poix, poiy; GdkPixbuf *pixbuf = NULL; -GError *error = NULL; printf("%s()\n", __PRETTY_FUNCTION__); if (!_db) return; @@ -78,25 +98,17 @@ while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) { poix = unit2bufx(unitx); poiy = unit2bufy(unity); - /* Try to get icon for specific POI first. */ - snprintf(buffer, sizeof(buffer), "%s/poi/%s.jpg", _curr_repo->cache_dir, poi_label); - pixbuf = gdk_pixbuf_new_from_file(buffer, &error); - if (error) { - /* No icon for specific POI - try for category. */ - error = NULL; - snprintf(buffer, sizeof(buffer),"%s/poi/%s.jpg", _curr_repo->cache_dir, cat_label); - pixbuf = gdk_pixbuf_new_from_file(buffer, &error); - } - if (error) { + pixbuf=map_poi_get_icon(cat_label); + + if (!pixbuf) { /* No icon for POI or for category - draw default. */ - error = NULL; gdk_draw_rectangle(_map_pixmap, _gc[COLORABLE_POI], TRUE, poix - (gint) (1.5f * _draw_width), poiy - (gint) (1.5f * _draw_width), 3 * _draw_width, 3 * _draw_width); - map_poi_title(poix, poiy, poi_label); + map_poi_title(poix, poiy + 4, poi_label); } else { gdk_draw_pixbuf(_map_pixmap, _gc[COLORABLE_POI], @@ -106,7 +118,6 @@ while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) { poiy - gdk_pixbuf_get_height(pixbuf) / 2, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); - g_object_unref(pixbuf); } g_free(poi_label); -- 2.39.5