]> err.no Git - mapper/commitdiff
Add signal display mode.
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 27 Sep 2007 13:29:01 +0000 (16:29 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 27 Sep 2007 13:29:01 +0000 (16:29 +0300)
Copy the signal bar code here. Add simple click-to-change mode.

src/gtkgps.c
src/gtkgps.h

index 4f20b3d2f59ab37963626c5ac735c97e6003c946..0613efbfa639b6db05f01339f24dfbdadbb7a1fc 100644 (file)
@@ -32,7 +32,7 @@ static gint gtk_gps_expose (GtkWidget *widget, GdkEventExpose *event);
 static void gtk_gps_realize (GtkWidget *widget);
 static void gtk_gps_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void gtk_gps_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static gint gtk_gps_paint(GtkGps *gps);
+static void gtk_gps_paint_by_mode(GtkGps *gps);
 
 G_DEFINE_TYPE(GtkGps, gtk_gps, GTK_TYPE_WIDGET);
 
@@ -104,11 +104,39 @@ gps->width=400;
 gps->height=300;
 }
 
+static gboolean 
+gtk_gps_cb_button_press(GtkWidget * widget, GdkEventButton * event)
+{
+GtkGps *gps;
+
+printf("%s()\n", __PRETTY_FUNCTION__);
+gps=GTK_GPS(widget);
+
+if (event->button==1) {
+       switch (gps->display_mode) {
+       case GTK_GPS_MODE_SKY:
+               gps->display_mode=GTK_GPS_MODE_SIGNAL;
+       break;
+       case GTK_GPS_MODE_SIGNAL:
+       default:
+               gps->display_mode=GTK_GPS_MODE_SKY;
+       break;
+       }
+}
+gtk_gps_paint_by_mode(gps);
+return FALSE;
+}
+
 GtkWidget*
-gtk_gps_new(void)
+gtk_gps_new(GtkGpsMode display_mode)
 {
 GtkGps *gps;
-gps = gtk_type_new(gtk_gps_get_type ());
+GtkWidget *widget;
+
+gps=gtk_type_new(gtk_gps_get_type ());
+gps->display_mode=display_mode;
+widget=GTK_WIDGET(gps);
+g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_gps_cb_button_press), NULL);
 return GTK_WIDGET(gps);
 }
 
@@ -191,7 +219,7 @@ attributes.width=widget->allocation.width;
 attributes.height=widget->allocation.height;
 attributes.wclass=GDK_INPUT_OUTPUT;
 attributes.window_type=GDK_WINDOW_CHILD;
-attributes.event_mask=gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK ;
+attributes.event_mask=gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
 attributes.visual=gtk_widget_get_visual(widget);
 attributes.colormap=gtk_widget_get_colormap(widget);
 
@@ -236,8 +264,8 @@ if (!gps->gc3) {
 }
 }
 
-static gint
-gtk_gps_paint(GtkGps *gps)
+static void
+gtk_gps_paint_sky(GtkGps *gps)
 {
 GdkGC *gc;
 GtkWidget *widget;
@@ -252,7 +280,7 @@ g_printf("%s()\n", __PRETTY_FUNCTION__);
 widget=GTK_WIDGET(gps);
 
 if (!GTK_WIDGET_MAPPED(widget))
-       return TRUE;
+       return;
 
 x0=0;
 y0=0;
@@ -356,16 +384,115 @@ for (i=0;i<gps->satinview;i++) {
 }
 
 g_printf("%s(): return\n", __PRETTY_FUNCTION__);
-return TRUE;
+return;
+}
+
+static void
+gtk_gps_paint_signals(GtkGps *gps)
+{
+GdkGC *gc;
+GtkWidget *widget;
+guint step, i, j, 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))
+       return;
+
+xoffset = 0;
+yoffset = 0;
+
+/* Bootom margin - 12% */
+bymargin = gps->height * 0.88f;
+
+/* Bottom line */
+gdk_draw_line(widget->window,
+             widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+             xoffset + 5, yoffset + bymargin,
+             xoffset + gps->width - 10 - 2, yoffset + bymargin);
+gdk_draw_line(widget->window,
+             widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+             xoffset + 5, yoffset + bymargin - 1,
+             xoffset + gps->width - 10 - 2, yoffset + bymargin - 1);
+
+if (gps->satinview > 0) {
+       /* Left margin - 5pix, Right margin - 5pix */
+       step = (gps->width - 10) / gps->satinview;
+
+       for (i = 0; i < gps->satinview; i++) {
+               /* Sat used or not */
+               gc = gps->gc1;
+               for (j = 0; j < gps->satinuse; j++) {
+                       if (gps->satforfix[j] == gps->gps_sat[i].prn) {
+                               gc = gps->gc2;
+                               break;
+                       }
+               }
+
+               x = 5 + i * step;
+               snr_height = gps->gps_sat[i].snr * gps->height * 0.78f / 100;
+               y = gps->height * 0.1f + (gps->height * 0.78f - snr_height);
+
+               /* draw sat rectangle... */
+               gdk_draw_rectangle(widget->window,
+                                  gc, TRUE,
+                                  xoffset + x,
+                                  yoffset + y, step - 2, snr_height);
+
+               if (gps->gps_sat[i].snr > 0) {
+                       /* ...snr.. */
+                       g_snprintf(tmp, 32, "%02d", gps->gps_sat[i].snr);
+                       pango_layout_set_text(gps->sat_details_layout, tmp, 2);
+                       pango_layout_get_pixel_size(gps->sat_details_layout, &x1, &y1);
+                       gdk_draw_layout(widget->window,
+                                       widget->style->fg_gc[GTK_STATE_NORMAL],
+                                       xoffset + x + ((step - 2) - x1) / 2,
+                                               yoffset + y - 15,
+                                               gps->sat_details_layout);
+               }
+
+               /* ...and sat number */
+               g_snprintf(tmp, 32, "%02d", gps->gps_sat[i].prn);
+               pango_layout_set_text(gps->sat_details_layout, tmp, 2);
+               pango_layout_get_pixel_size(gps->sat_details_layout, &x1, &y1);
+               gdk_draw_layout(widget->window,
+                               widget->style->fg_gc[GTK_STATE_NORMAL],
+                               xoffset + x + ((step - 2) - x1) / 2,
+                               yoffset + bymargin + 1,
+                               gps->sat_details_layout);
+       }
+}
+
+return;
+}
+
+static void
+gtk_gps_paint_by_mode(GtkGps *gps)
+{
+switch (gps->display_mode) {
+       case GTK_GPS_MODE_SIGNAL:
+               gtk_gps_paint_signals(gps);
+       break;
+       case GTK_GPS_MODE_SKY:
+       default:
+               gtk_gps_paint_sky(gps);
+       break;
+}
 }
 
 static gint
 gtk_gps_expose(GtkWidget *widget, GdkEventExpose *event)
 {
+GtkGps *gps;
 g_return_val_if_fail(GTK_IS_GPS(widget), FALSE);
 g_return_val_if_fail(event != NULL, FALSE);
 
-gtk_gps_paint(GTK_GPS(widget));
+gps=GTK_GPS(widget);
+gtk_gps_paint_by_mode(gps);
 return TRUE;
 }
 
@@ -410,7 +537,7 @@ if (sat>12)
        sat=12;
 
 gps->satinview=sat;
-gtk_gps_paint(gps);
+gtk_gps_paint_by_mode(gps);
 
 g_printf("%s(): return\n", __PRETTY_FUNCTION__);
 }
index 6eb273e9e45862d2af0381e9b6bf6f610b0d3083..c19951f195ab1fab69f143fffe8eedb0ca33cbad 100644 (file)
@@ -40,6 +40,12 @@ struct _GtkGpsSatelliteData {
        guint snr;
 };
 
+typedef enum {
+       GTK_GPS_MODE_SKY,
+       GTK_GPS_MODE_SIGNAL,
+       GTK_GPS_MODE_COMBINED,
+} GtkGpsMode;
+
 struct _GtkGps {
        GtkWidget parent;
        GtkWidget widget;
@@ -47,6 +53,7 @@ struct _GtkGps {
        GdkGC *gc2;
        GdkGC *gc3;
        gint width, height;
+       GtkGpsMode display_mode;
 
        PangoContext *sat_details_context;
        PangoLayout *sat_details_layout;
@@ -66,7 +73,7 @@ struct _GtkGpsClass {
 };
 
 GType gtk_gps_get_type(void);
-GtkWidget* gtk_gps_new(void);
+GtkWidget* gtk_gps_new(GtkGpsMode display_mode);
 void gtk_gps_set_satellite_data(GtkWidget *widget, guint sat, gboolean fix, guint prn, guint elevation, guint azimuth, guint snr);
 void gtk_gps_set_satellite_in_view(GtkWidget *widget, guint sat);