From dabfd95fc0df6c9e61a2eff79ccfa4aaf3252943 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 1 Oct 2007 14:25:44 +0300 Subject: [PATCH] Some more work on the gps widgets. - Rotate compass labels - Don't display text labels when the sky view is small --- src/gtkcompass.c | 8 +++++- src/gtkgps.c | 66 +++++++++++++++++++++++------------------------- src/gtkgps.h | 1 + 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/gtkcompass.c b/src/gtkcompass.c index 682e2ab..62bf9ee 100644 --- a/src/gtkcompass.c +++ b/src/gtkcompass.c @@ -101,7 +101,7 @@ compass->gc_d=NULL; compass->gc_w=NULL; compass->dest_valid=FALSE; compass->way_valid=FALSE; -compass->width=400; +compass->width=300; compass->height=300; } @@ -299,6 +299,8 @@ widget=GTK_WIDGET(compass); size=compass->size; hsize=size/2; +pango_context_set_matrix (compass->context, NULL); + g_snprintf(htext, 8, "%3.0f°", compass->data->heading); pango_layout_set_text(compass->layout, htext, -1); pango_layout_get_pixel_size(compass->layout, &x, &y); @@ -345,6 +347,7 @@ gdk_draw_line(widget->window, compass->xoffset + size / 2, compass->yoffset + size - y - 8); for (i = 0; i < 5; i++) { + PangoMatrix matrix = PANGO_MATRIX_INIT; dir = (gint) (compass->data->heading / 45) * 45 + angle[i]; switch (dir) { @@ -394,6 +397,9 @@ for (i = 0; i < 5; i++) { > abs((guint) (compass->data->heading / 45) * 45 + 45 - compass->data->heading) && (i > 0)) x = fsize[i - 1]; + pango_matrix_rotate (&matrix, dir); + pango_context_set_matrix (compass->context, &matrix); + pango_font_description_set_size(compass->fontdesc, (10 + x) * PANGO_SCALE); pango_layout_set_font_description(compass->layout, compass->fontdesc); pango_layout_set_text(compass->layout, text, -1); diff --git a/src/gtkgps.c b/src/gtkgps.c index 4535dee..b1ea99c 100644 --- a/src/gtkgps.c +++ b/src/gtkgps.c @@ -68,7 +68,9 @@ static void gtk_gps_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GtkGps *gps; + g_return_if_fail(GTK_IS_GPS(object)); + gps=GTK_GPS(object); switch (prop_id) { default: @@ -81,7 +83,9 @@ static void gtk_gps_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GtkGps *gps; + g_return_if_fail(GTK_IS_GPS(object)); + gps=GTK_GPS(object); switch (prop_id) { default: @@ -98,8 +102,9 @@ g_printf("%s()\n", __PRETTY_FUNCTION__); gps->gc1=NULL; gps->gc2=NULL; gps->gc3=NULL; -gps->width=400; +gps->width=300; gps->height=300; +gps->size=300; } static gboolean @@ -107,7 +112,6 @@ gtk_gps_cb_button_press(GtkWidget * widget, GdkEventButton * event) { GtkGps *gps; -printf("%s()\n", __PRETTY_FUNCTION__); gps=GTK_GPS(widget); if (event->button==1) { @@ -136,6 +140,15 @@ gps->display_mode=display_mode; gps->data=data; widget=GTK_WIDGET(gps); g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_gps_cb_button_press), NULL); + +gps->context=gtk_widget_get_pango_context(widget); +gps->layout=pango_layout_new(gps->context); +gps->fontdesc=pango_font_description_new(); +pango_font_description_set_family(gps->fontdesc, "Sans Serif"); +pango_font_description_set_size(gps->fontdesc, 10*PANGO_SCALE); +pango_layout_set_font_description(gps->layout, gps->fontdesc); +pango_layout_set_alignment(gps->layout, PANGO_ALIGN_CENTER); + return GTK_WIDGET(gps); } @@ -144,8 +157,6 @@ gtk_gps_finalize(GObject *object) { GtkGps *gps; -g_printf("%s()\n", __PRETTY_FUNCTION__); - g_return_if_fail(GTK_IS_GPS(object)); gps=GTK_GPS(object); @@ -164,22 +175,22 @@ GtkGps *gps; g_printf("%s()\n", __PRETTY_FUNCTION__); g_return_if_fail(GTK_IS_GPS(widget)); -g_return_if_fail(requisition != NULL); +g_return_if_fail(requisition!=NULL); gps = GTK_GPS (widget); -requisition->width=400; +requisition->width=300; requisition->height=300; -gps->width=400; +gps->width=300; gps->height=300; +gps->size=300; } static void gtk_gps_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkGps *gps; - -g_printf("%s()\n", __PRETTY_FUNCTION__); +gint fs; g_return_if_fail(GTK_IS_GPS(widget)); g_return_if_fail(allocation!=NULL); @@ -194,9 +205,15 @@ if (GTK_WIDGET_REALIZED (widget)) { allocation->width, allocation->height); } - gps->width=allocation->width; gps->height=allocation->height; +gps->size=MIN(gps->width, gps->height); + +gps->fs=gps->size/20; +BOUND(gps->fs,8,20); + +pango_font_description_set_size(gps->fontdesc, gps->fs*PANGO_SCALE); +pango_layout_set_font_description(gps->layout, gps->fontdesc); } static void @@ -207,8 +224,6 @@ GdkColor color; GdkWindowAttr attributes; gint attributes_mask; -g_printf("%s()\n", __PRETTY_FUNCTION__); - g_return_if_fail (GTK_IS_GPS(widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); gps=GTK_GPS(widget); @@ -231,14 +246,6 @@ widget->style=gtk_style_attach(widget->style, widget->window); gdk_window_set_user_data(widget->window, widget); gtk_style_set_background(widget->style, widget->window, GTK_STATE_ACTIVE); -gps->context=gtk_widget_get_pango_context(widget); -gps->layout=pango_layout_new(gps->context); -gps->fontdesc=pango_font_description_new(); -pango_font_description_set_family(gps->fontdesc, "Sans Serif"); -pango_font_description_set_size(gps->fontdesc, 10*PANGO_SCALE); -pango_layout_set_font_description(gps->layout, gps->fontdesc); -pango_layout_set_alignment(gps->layout, PANGO_ALIGN_CENTER); - if (!gps->gc1) { color.red=0; color.green=0; @@ -270,7 +277,7 @@ gtk_gps_paint_sky(GtkGps *gps) GdkGC *gc; GtkWidget *widget; guint i, x, y, size, halfsize, xoffset, yoffset; -guint x1, y1, x0, y0; +guint x1, y1, x0, y0, ds; gfloat tmp; gchar buffer[16]; guint line[12]={0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330}; @@ -287,7 +294,7 @@ if (!GTK_WIDGET_MAPPED(widget)) x0=0; y0=0; -size=MIN(gps->width, gps->height); +size=gps->size; halfsize=size/2; if (gps->width>gps->height) { xoffset=x0+(gps->width-gps->height-PADDING)/2; @@ -297,14 +304,6 @@ if (gps->width>gps->height) { yoffset=y0+(gps->height-gps->width-PADDING)/2; } -if (size<200) { - pango_font_description_set_size(gps->fontdesc, 10*PANGO_SCALE); - pango_layout_set_font_description(gps->layout, gps->fontdesc); -} else { - pango_font_description_set_size(gps->fontdesc, 12*PANGO_SCALE); - pango_layout_set_font_description(gps->layout, gps->fontdesc); -} - gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_NONE, @@ -342,6 +341,7 @@ for (i = 0; i < 6; i++) { yoffset + halfsize + (halfsize - 2) * cosf(tmp)); } +if (size > 140) { for (i = 0; i < 12; i++) { tmp = (line[i] * (1.f / 180.f)) * G_PI; /* azimuth */ @@ -376,6 +376,7 @@ 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, gps->layout); +} for (i=0;idata->satinview;i++) { /* Sat used or not */ @@ -385,7 +386,7 @@ for (i=0;idata->satinview;i++) { x = xoffset + halfsize + (90 - gps->data->sat[i].elevation) * halfsize / 90 * sinf(tmp); y = yoffset + halfsize - (90 - gps->data->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-gps->fs, y-gps->fs, gps->fs+3, gps->fs+3, 0, 64 * 360); g_snprintf(buffer, 6, "%02d", gps->data->sat[i].prn); pango_layout_set_text(gps->layout, buffer, -1); @@ -393,7 +394,6 @@ for (i=0;idata->satinview;i++) { gdk_draw_layout(widget->window, gps->gc3, x - x1 / 2, y - y1 / 2, gps->layout); } -g_printf("%s(): return\n", __PRETTY_FUNCTION__); return; } @@ -406,8 +406,6 @@ guint step, i, snr_height, bymargin, xoffset, yoffset; guint x, y, x1, y1; gchar tmp[32]; -g_printf("%s()\n", __PRETTY_FUNCTION__); - widget=GTK_WIDGET(gps); if (!GTK_WIDGET_MAPPED(widget)) diff --git a/src/gtkgps.h b/src/gtkgps.h index c032db3..07cce89 100644 --- a/src/gtkgps.h +++ b/src/gtkgps.h @@ -47,6 +47,7 @@ struct _GtkGps { GdkGC *gc3; gint width, height; gint size; + gint fs; GtkGpsMode display_mode; PangoContext *context; -- 2.39.5