{
GtkCompassPriv *priv=GTK_COMPASS_GET_PRIVATE(compass);
-compass->width=300;
-compass->height=300;
+compass->heading=0;
-priv->gc_h=NULL;
-priv->gc_d=NULL;
-priv->gc_w=NULL;
priv->esid=0;
priv->dest_valid=FALSE;
priv->way_valid=FALSE;
compass=g_object_new(GTK_COMPASS_TYPE, NULL);
widget=GTK_WIDGET(compass);
compass->data=data;
-compass->heading=0;
return widget;
}
compass=GTK_COMPASS(widget);
-requisition->width=400;
-requisition->height=300;
-compass->width=400;
-compass->height=300;
+requisition->width=64;
+requisition->height=64;
}
static void
allocation->width, allocation->height);
}
-compass->width=allocation->width;
-compass->height=allocation->height;
-
compass->size = MIN(widget->allocation.width, widget->allocation.height);
if (widget->allocation.width > widget->allocation.height) {
compass->xoffset = (widget->allocation.width - widget->allocation.height) / 2;
compass->yoffset = 0;
-} else {
+} else if (widget->allocation.width < widget->allocation.height) {
compass->xoffset = 0;
compass->yoffset = (widget->allocation.height - widget->allocation.width) / 2;
+} else {
+ compass->xoffset = 0;
+ compass->yoffset = 0;
}
}
pango_layout_set_font_description(priv->layout, priv->fontdesc);
pango_layout_set_alignment(priv->layout, PANGO_ALIGN_CENTER);
-if (!priv->gc_h) {
- color.red=0x0000;
- color.green=0x0000;
- color.blue=0x0000;
- priv->gc_h=gdk_gc_new(widget->window);
- gdk_gc_set_rgb_fg_color(priv->gc_h, &color);
- gdk_gc_set_line_attributes(priv->gc_h, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
-}
-
-if (!priv->gc_d) {
- color.red=0xffff;
- color.green=0x0000;
- color.blue=0xffff;
- priv->gc_d=gdk_gc_new(widget->window);
- gdk_gc_set_rgb_fg_color(priv->gc_d, &color);
- gdk_gc_set_line_attributes(priv->gc_d, 6, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
-}
-
-if (!priv->gc_w) {
- color.red=0x0000;
- color.green=0xffff;
- color.blue=0x0000;
- priv->gc_w=gdk_gc_new(widget->window);
- gdk_gc_set_rgb_fg_color(priv->gc_w, &color);
- gdk_gc_set_line_attributes(priv->gc_w, 6, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
-}
-
-priv->esid=g_timeout_add(300,(GSourceFunc)gtk_compass_refresh_cb, compass);
+color.red=0x0000;
+color.green=0x0000;
+color.blue=0x0000;
+priv->gc_h=gdk_gc_new(widget->window);
+gdk_gc_set_rgb_fg_color(priv->gc_h, &color);
+gdk_gc_set_line_attributes(priv->gc_h, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
+
+color.red=0xffff;
+color.green=0x0000;
+color.blue=0xffff;
+priv->gc_d=gdk_gc_new(widget->window);
+gdk_gc_set_rgb_fg_color(priv->gc_d, &color);
+gdk_gc_set_line_attributes(priv->gc_d, 6, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
+
+color.red=0x0000;
+color.green=0xffff;
+color.blue=0x0000;
+priv->gc_w=gdk_gc_new(widget->window);
+gdk_gc_set_rgb_fg_color(priv->gc_w, &color);
+gdk_gc_set_line_attributes(priv->gc_w, 6, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
}
static void
gtk_compass_expose(GtkWidget *widget, GdkEventExpose *event)
{
GtkCompass *compass;
+GtkCompassPriv *priv;
g_return_val_if_fail(GTK_IS_COMPASS(widget), FALSE);
g_return_val_if_fail(event != NULL, FALSE);
compass=GTK_COMPASS(widget);
+priv=GTK_COMPASS_GET_PRIVATE(compass);
+if (priv->esid==0) {
+ priv->esid=g_timeout_add(300,(GSourceFunc)gtk_compass_refresh_cb, compass);
+}
gtk_compass_paint(compass);
return TRUE;
}
gtk_compass_refresh_cb(GtkWidget *widget)
{
GtkCompass *compass;
+GtkCompassPriv *priv;
gfloat tmp;
g_return_val_if_fail(GTK_IS_COMPASS(widget), FALSE);
compass=GTK_COMPASS(widget);
+priv=GTK_COMPASS_GET_PRIVATE(compass);
if ((GTK_WIDGET_MAPPED(widget)==FALSE) || (GTK_WIDGET_VISIBLE(widget)==FALSE)) {
compass->heading=compass->data->heading;
+ if (priv->esid!=0) {
+ g_source_remove(priv->esid);
+ priv->esid=0;
+ }
return TRUE;
}
+if (priv->esid==0)
+ priv->esid=g_timeout_add(300,(GSourceFunc)gtk_compass_refresh_cb, compass);
+
if (compass->heading==compass->data->heading)
return TRUE;
tmp=fabsf(compass->heading-compass->data->heading);
-if (tmp>5)
+if (tmp>5) {
tmp=tmp/2.2;
-else
+ if (compass->heading<compass->data->heading)
+ compass->heading+=tmp;
+ else if (compass->heading>compass->data->heading)
+ compass->heading-=tmp;
+} else {
compass->heading=compass->data->heading;
+}
-if (compass->heading<compass->data->heading)
- compass->heading+=tmp;
-
-if (compass->heading>compass->data->heading)
- compass->heading-=tmp;
-
-gtk_widget_queue_draw_area(widget, 0, 0, compass->width, compass->height);
+gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, widget->allocation.height);
return TRUE;
}
void
gtk_compass_refresh(GtkWidget *widget)
{
-GtkCompass *compass;
-
g_return_if_fail(GTK_IS_COMPASS(widget));
-
-compass=GTK_COMPASS(widget);
-gtk_widget_queue_draw_area(widget, 0, 0, compass->width, compass->height);
+gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
void
priv->way_valid=valid;
compass->way_heading=heading;
-gtk_widget_queue_draw_area(widget, 0, 0, compass->width, compass->height);
+gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
void
priv->dest_valid=valid;
compass->dest_heading=heading;
-compass=GTK_COMPASS(widget);
-gtk_widget_queue_draw_area(widget, 0, 0, compass->width, compass->height);
+gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
-