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);
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);
}
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);
}
}
-static gint
-gtk_gps_paint(GtkGps *gps)
+static void
+gtk_gps_paint_sky(GtkGps *gps)
{
GdkGC *gc;
GtkWidget *widget;
widget=GTK_WIDGET(gps);
if (!GTK_WIDGET_MAPPED(widget))
- return TRUE;
+ return;
x0=0;
y0=0;
}
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;
}
sat=12;
gps->satinview=sat;
-gtk_gps_paint(gps);
+gtk_gps_paint_by_mode(gps);
g_printf("%s(): return\n", __PRETTY_FUNCTION__);
}