static void gtk_compass_finalize (GObject *object);
static void gtk_compass_size_request (GtkWidget *widget, GtkRequisition *requisition);
static void gtk_compass_size_allocate (GtkWidget *widget, GtkAllocation *allocate);
-static gint gtk_compass_expose (GtkWidget *widget, GdkEventExpose *event);
+static gboolean gtk_compass_expose (GtkWidget *widget, GdkEventExpose *event);
static void gtk_compass_realize (GtkWidget *widget);
static void gtk_compass_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void gtk_compass_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
G_DEFINE_TYPE(GtkCompass, gtk_compass, GTK_TYPE_WIDGET);
-#define PADDING (15)
-
#define BOUND(x, a, b) { \
if((x) < (a)) \
(x) = (a); \
{
g_printf("%s()\n", __PRETTY_FUNCTION__);
-compass->heading=0;
compass->gc_h=NULL;
compass->gc_d=NULL;
compass->gc_w=NULL;
}
GtkWidget*
-gtk_compass_new(void)
+gtk_compass_new(GpsData *data)
{
GtkCompass *compass;
GtkWidget *widget;
compass=gtk_type_new(gtk_compass_get_type ());
widget=GTK_WIDGET(compass);
+compass->data=data;
g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_compass_cb_button_press), NULL);
return widget;
}
requisition->width=400;
requisition->height=300;
-compass->width=400 - 10;
-compass->height=300 - 10;
+compass->width=400;
+compass->height=300;
}
static void
allocation->width, allocation->height);
}
-compass->width=allocation->width-PADDING;
-compass->height=allocation->height-PADDING;
+compass->width=allocation->width;
+compass->height=allocation->height;
compass->size = MIN(widget->allocation.width, widget->allocation.height);
if (widget->allocation.width > widget->allocation.height) {
size=compass->size;
hsize=size/2;
-g_snprintf(htext, 8, "%3.0f°", compass->heading);
+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);
+gtk_paint_flat_box (widget->style,
+ widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+ NULL, widget, "trough", 0, 0,
+ compass->width, compass->height);
+
gdk_draw_layout(widget->window,
- widget->style->fg_gc[GTK_STATE_NORMAL],
- compass->xoffset+size/2-x/2,
- compass->yoffset+size-y-2, compass->layout);
+ widget->style->fg_gc[GTK_STATE_NORMAL],
+ compass->xoffset+size/2-x/2,
+ compass->yoffset+size-y-2, compass->layout);
gdk_draw_arc(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- FALSE,
- compass->xoffset, compass->yoffset+size/2, size, size, 0, 64 * 180);
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ FALSE,
+ compass->xoffset, compass->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)],
- compass->xoffset + size / 2 + 3,
- compass->yoffset + size - y - 5,
- compass->xoffset + size / 2, compass->yoffset + size / 2 + 5);
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ compass->xoffset + size / 2 + 3,
+ compass->yoffset + size - y - 5,
+ compass->xoffset + size / 2, compass->yoffset + size / 2 + 5);
gdk_draw_line(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- compass->xoffset + size / 2 - 3,
- compass->yoffset + size - y - 5,
- compass->xoffset + size / 2, compass->yoffset + size / 2 + 5);
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ compass->xoffset + size / 2 - 3,
+ compass->yoffset + size - y - 5,
+ compass->xoffset + size / 2, compass->yoffset + size / 2 + 5);
gdk_draw_line(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- compass->xoffset + size / 2 - 3,
- compass->yoffset + size - y - 5,
- compass->xoffset + size / 2, compass->yoffset + size - y - 8);
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ compass->xoffset + size / 2 - 3,
+ compass->yoffset + size - y - 5,
+ compass->xoffset + size / 2, compass->yoffset + size - y - 8);
gdk_draw_line(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- compass->xoffset + size / 2 + 3,
- compass->yoffset + size - y - 5,
- compass->xoffset + size / 2, compass->yoffset + size - y - 8);
+ widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
+ compass->xoffset + size / 2 + 3,
+ compass->yoffset + size - y - 5,
+ compass->xoffset + size / 2, compass->yoffset + size - y - 8);
for (i = 0; i < 5; i++) {
- dir = (gint) (compass->heading / 45) * 45 + angle[i];
+ dir = (gint) (compass->data->heading / 45) * 45 + angle[i];
switch (dir) {
case 0:
break;
}
- tmp = ((dir - compass->heading) * (1.f / 180.f)) * G_PI;
+ tmp = ((dir - compass->data->heading) * (1.f / 180.f)) * G_PI;
gdk_draw_line(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
compass->xoffset + size / 2 + ((size / 2 - 5) * sinf(tmp)),
compass->yoffset + size - ((size / 2 + 5) * cosf(tmp)));
x = fsize[i];
- if (abs((guint) (compass->heading / 45) * 45 - compass->heading)
- > abs((guint) (compass->heading / 45) * 45 + 45 - compass->heading) && (i > 0))
+ if (abs((guint) (compass->data->heading / 45) * 45 - compass->data->heading)
+ > abs((guint) (compass->data->heading / 45) * 45 + 45 - compass->data->heading) && (i > 0))
x = fsize[i - 1];
pango_font_description_set_size(compass->fontdesc, (10 + x) * PANGO_SCALE);
}
-static gint
+static gboolean
gtk_compass_expose(GtkWidget *widget, GdkEventExpose *event)
{
GtkCompass *compass;
}
void
-gtk_compass_set_heading(GtkWidget *widget, gfloat heading)
+gtk_compass_refresh(GtkWidget *widget)
{
GtkCompass *compass;
g_return_if_fail(GTK_IS_COMPASS(widget));
compass=GTK_COMPASS(widget);
-
-compass->heading=heading;
gtk_compass_paint(compass);
g_printf("%s(): return\n", __PRETTY_FUNCTION__);
static void gtk_gps_finalize (GObject *object);
static void gtk_gps_size_request (GtkWidget *widget, GtkRequisition *requisition);
static void gtk_gps_size_allocate (GtkWidget *widget, GtkAllocation *allocate);
-static gint gtk_gps_expose (GtkWidget *widget, GdkEventExpose *event);
+static gboolean 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 void
-gtk_gps_class_init (GtkGpsClass *class)
+gtk_gps_class_init(GtkGpsClass *class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
}
static void
-gtk_gps_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+gtk_gps_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
GtkGps *gps;
g_return_if_fail(GTK_IS_GPS(object));
}
static void
-gtk_gps_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+gtk_gps_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
GtkGps *gps;
g_return_if_fail(GTK_IS_GPS(object));
}
static void
-gtk_gps_init (GtkGps *gps)
+gtk_gps_init(GtkGps *gps)
{
g_printf("%s()\n", __PRETTY_FUNCTION__);
-gps->satinview=0;
-gps->satinuse=0;
gps->gc1=NULL;
gps->gc2=NULL;
gps->gc3=NULL;
}
GtkWidget*
-gtk_gps_new(GtkGpsMode display_mode)
+gtk_gps_new(GtkGpsMode display_mode, GpsData *data)
{
GtkGps *gps;
GtkWidget *widget;
gps=gtk_type_new(gtk_gps_get_type ());
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);
return GTK_WIDGET(gps);
requisition->width=400;
requisition->height=300;
-gps->width=400 - 10;
-gps->height=300 - 10;
+gps->width=400;
+gps->height=300;
}
static void
allocation->width, allocation->height);
}
-gps->width=allocation->width-PADDING;
-gps->height=allocation->height-PADDING;
+
+gps->width=allocation->width;
+gps->height=allocation->height;
}
static void
gdk_window_set_user_data(widget->window, widget);
gtk_style_set_background(widget->style, widget->window, GTK_STATE_ACTIVE);
-gps->sat_details_context=gtk_widget_get_pango_context(widget);
-gps->sat_details_layout=pango_layout_new(gps->sat_details_context);
-gps->sat_details_fontdesc=pango_font_description_new();
-pango_font_description_set_family(gps->sat_details_fontdesc, "Sans Serif");
-pango_font_description_set_size(gps->sat_details_fontdesc, 12*PANGO_SCALE);
-pango_layout_set_font_description(gps->sat_details_layout, gps->sat_details_fontdesc);
-pango_layout_set_alignment(gps->sat_details_layout, PANGO_ALIGN_CENTER);
+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;
{
GdkGC *gc;
GtkWidget *widget;
-guint i, j, x, y, size, halfsize, xoffset, yoffset;
+guint i, x, y, size, halfsize, xoffset, yoffset;
guint x1, y1, x0, y0;
gfloat tmp;
gchar buffer[16];
widget=GTK_WIDGET(gps);
+g_return_if_fail(gps->data);
+
if (!GTK_WIDGET_MAPPED(widget))
return;
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,
+ NULL, widget, "trough", 0, 0,
+ gps->width, gps->height);
+
/* 90 */
gdk_draw_arc(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
g_snprintf(buffer, 16, "N");
else
g_snprintf(buffer, 16, "%d°", line[i]);
- pango_layout_set_text(gps->sat_details_layout, buffer, -1);
- pango_layout_get_pixel_size(gps->sat_details_layout, &x, &y);
+ 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,
- gps->sat_details_layout);
+ gps->layout);
}
/* elevation 30 */
tmp = (30 * (1.f / 180.f)) * G_PI;
g_snprintf(buffer, 16, "30°");
-pango_layout_set_text(gps->sat_details_layout, buffer, -1);
-pango_layout_get_pixel_size(gps->sat_details_layout, &x, &y);
+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->sat_details_layout);
+ gps->layout);
/* elevation 60 */
tmp = (30 * (1.f / 180.f)) * G_PI;
g_snprintf(buffer, 16, "60°");
-pango_layout_set_text(gps->sat_details_layout, buffer, -1);
-pango_layout_get_pixel_size(gps->sat_details_layout, &x, &y);
+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->sat_details_layout);
+ gps->layout);
-for (i=0;i<gps->satinview;i++) {
+for (i=0;i<gps->data->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;
- }
- }
+ gc=(gps->data->sat[i].fix) ? gps->gc2 : gps->gc1;
- tmp = (gps->gps_sat[i].azimuth * (1.f / 180.f)) * G_PI;
- x = xoffset + halfsize + (90 - gps->gps_sat[i].elevation) * halfsize / 90 * sinf(tmp);
- y = yoffset + halfsize - (90 - gps->gps_sat[i].elevation) * halfsize / 90 * cosf(tmp);
+ tmp = (gps->data->sat[i].azimuth * (1.f / 180.f)) * G_PI;
+ 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);
- g_snprintf(buffer, 6, "%02d", gps->gps_sat[i].prn);
- pango_layout_set_text(gps->sat_details_layout, buffer, -1);
- pango_layout_get_pixel_size(gps->sat_details_layout, &x1, &y1);
- gdk_draw_layout(widget->window, gps->gc3, x - x1 / 2, y - y1 / 2, gps->sat_details_layout);
+ g_snprintf(buffer, 6, "%02d", gps->data->sat[i].prn);
+ pango_layout_set_text(gps->layout, buffer, -1);
+ pango_layout_get_pixel_size(gps->layout, &x1, &y1);
+ gdk_draw_layout(widget->window, gps->gc3, x - x1 / 2, y - y1 / 2, gps->layout);
}
g_printf("%s(): return\n", __PRETTY_FUNCTION__);
{
GdkGC *gc;
GtkWidget *widget;
-guint step, i, j, snr_height, bymargin, xoffset, yoffset;
+guint step, i, snr_height, bymargin, xoffset, yoffset;
guint x, y, x1, y1;
gchar tmp[32];
xoffset + 5, yoffset + bymargin - 1,
xoffset + gps->width - 10 - 2, yoffset + bymargin - 1);
-if (gps->satinview > 0) {
+if (gps->data->satinview > 0) {
/* Left margin - 5pix, Right margin - 5pix */
- step = (gps->width - 10) / gps->satinview;
+ step = (gps->width - 10) / gps->data->satinview;
- for (i = 0; i < gps->satinview; i++) {
+ for (i = 0; i < gps->data->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;
- }
- }
+ gc=(gps->data->sat[i].fix) ? gps->gc1 : gps->gc2;
x = 5 + i * step;
- snr_height = gps->gps_sat[i].snr * gps->height * 0.78f / 100;
+ snr_height = gps->data->sat[i].snr * gps->height * 0.78f / 100;
y = gps->height * 0.1f + (gps->height * 0.78f - snr_height);
/* draw sat rectangle... */
xoffset + x,
yoffset + y, step - 2, snr_height);
- if (gps->gps_sat[i].snr > 0) {
+ if (gps->data->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);
+ g_snprintf(tmp, 32, "%02d", gps->data->sat[i].snr);
+ pango_layout_set_text(gps->layout, tmp, 2);
+ pango_layout_get_pixel_size(gps->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);
+ gps->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);
+ g_snprintf(tmp, 32, "%02d", gps->data->sat[i].prn);
+ pango_layout_set_text(gps->layout, tmp, 2);
+ pango_layout_get_pixel_size(gps->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);
+ gps->layout);
}
}
static void
gtk_gps_paint_by_mode(GtkGps *gps)
{
+g_return_if_fail(GTK_IS_GPS(gps));
+
switch (gps->display_mode) {
case GTK_GPS_MODE_SIGNAL:
gtk_gps_paint_signals(gps);
}
}
-static gint
+static gboolean
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);
return TRUE;
}
-void
-gtk_gps_set_satellite_data(GtkWidget *widget, guint sat, gboolean fix, guint prn, guint elevation, guint azimuth, guint snr)
-{
-GtkGps *gps;
-
-g_printf("%s()\n", __PRETTY_FUNCTION__);
-g_return_if_fail(GTK_IS_GPS (widget));
-
-gps=GTK_GPS(widget);
-
-if (sat>12)
- sat=12;
-
-BOUND(elevation, 0, 90);
-BOUND(azimuth, 0, 360);
-BOUND(snr, 0, 99);
-gps->gps_sat[sat].prn=prn;
-gps->gps_sat[sat].elevation=elevation;
-gps->gps_sat[sat].azimuth=azimuth;
-gps->gps_sat[sat].snr=snr;
-if (fix)
- gps->satforfix[sat]=prn;
-else
- gps->satforfix[sat]=-1;
-g_printf("%s(): return\n", __PRETTY_FUNCTION__);
-}
-
void
-gtk_gps_set_satellite_in_view(GtkWidget *widget, guint sat)
+gtk_gps_refresh(GtkWidget *widget)
{
GtkGps *gps;
-g_printf("%s()\n", __PRETTY_FUNCTION__);
g_return_if_fail(GTK_IS_GPS(widget));
gps=GTK_GPS(widget);
-
-if (sat>12)
- sat=12;
-
-gps->satinview=sat;
gtk_gps_paint_by_mode(gps);
-
-g_printf("%s(): return\n", __PRETTY_FUNCTION__);
}