From cb8ae16bf1a0c8f83224683aec74d110c3f9fa10 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 11 Oct 2007 12:42:42 +0300 Subject: [PATCH] Small optimizations to gps sky/signal widget --- src/gtkgps.c | 62 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/gtkgps.c b/src/gtkgps.c index dc494ed..730e7b2 100644 --- a/src/gtkgps.c +++ b/src/gtkgps.c @@ -97,8 +97,6 @@ switch (prop_id) { static void gtk_gps_init(GtkGps *gps) { -g_printf("%s()\n", __PRETTY_FUNCTION__); - gps->gc_w=NULL; gps->gc_s=NULL; gps->gc_sf=NULL; @@ -172,8 +170,6 @@ gtk_gps_size_request(GtkWidget *widget, GtkRequisition *requisition) { GtkGps *gps; -g_printf("%s()\n", __PRETTY_FUNCTION__); - g_return_if_fail(GTK_IS_GPS(widget)); g_return_if_fail(requisition!=NULL); @@ -281,8 +277,6 @@ gfloat tmp; gchar buffer[16]; guint line[12]={0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330}; -g_printf("%s()\n", __PRETTY_FUNCTION__); - widget=GTK_WIDGET(gps); g_return_if_fail(gps->data); @@ -323,21 +317,24 @@ gdk_draw_arc(widget->window, xoffset + size / 6 * 2, yoffset + size / 6 * 2, size / 6 * 2, size / 6 * 2, 0, 64 * 360); -for (i = 0; i < 6; i++) { - /* line */ +for (i = 0; i < 12; i++) { + gfloat sint, cost; + tmp = (line[i] * (1.f / 180.f)) * G_PI; + sint=sinf(tmp); + cost=cosf(tmp); + /* line */ 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)); -} + xoffset + halfsize + (halfsize - 2) * sint, + yoffset + halfsize - (halfsize - 2) * cost, + xoffset + halfsize - (halfsize - 2) * sint, + yoffset + halfsize + (halfsize - 2) * cost); + + /* Skip angle text if there is no space */ + if (size<100) + continue; -if (size>100) { -for (i = 0; i < 12; i++) { - tmp = (line[i] * (1.f / 180.f)) * G_PI; - /* azimuth */ if (line[i] == 0) g_snprintf(buffer, 16, "N"); else @@ -345,27 +342,28 @@ for (i = 0; i < 12; i++) { pango_layout_set_text(gps->layout, buffer, -1); pango_layout_get_pixel_size(gps->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, + (xoffset + halfsize + (halfsize - size / 12) * sint) - x / 2, + (yoffset + halfsize - (halfsize - size / 12) * cost) - y / 2, gps->layout); + } -/* elevation 30 */ -tmp = (30 * (1.f / 180.f)) * G_PI; -g_snprintf(buffer, 16, "30°"); -pango_layout_set_text(gps->layout, buffer, -1); -pango_layout_get_pixel_size(gps->layout, &x, &y); -gdk_draw_layout(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], +if (size>100) { + tmp = (30 * (1.f / 180.f)) * G_PI; + /* elevation 30 */ + g_snprintf(buffer, 16, "30°"); + pango_layout_set_text(gps->layout, buffer, -1); + pango_layout_get_pixel_size(gps->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, gps->layout); -/* elevation 60 */ -tmp = (30 * (1.f / 180.f)) * G_PI; -g_snprintf(buffer, 16, "60°"); -pango_layout_set_text(gps->layout, buffer, -1); -pango_layout_get_pixel_size(gps->layout, &x, &y); -gdk_draw_layout(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], + /* elevation 60 */ + g_snprintf(buffer, 16, "60°"); + pango_layout_set_text(gps->layout, buffer, -1); + pango_layout_get_pixel_size(gps->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, gps->layout); @@ -508,5 +506,5 @@ GtkGps *gps; g_return_if_fail(GTK_IS_GPS(widget)); gps=GTK_GPS(widget); -gtk_gps_paint_by_mode(gps); +gtk_widget_queue_draw_area(widget, 0, 0, gps->width, gps->height); } -- 2.39.5