opengl->sphere->view->view,
&x, &y, &z);
xyz2lle(x, y, z, lat, lon, elev);
- //g_message("GritsOpenGL: unproject - "
- // "%4.0lf,%4.0lf,(%5.3lf) -> "
- // "%8.0lf,%8.0lf,%8.0lf -> "
- // "%6.2lf,%7.2lf,%4.0lf",
- // px, py, pz, x, y, z, *lat, *lon, *elev);
+ g_message("GritsOpenGL: unproject - "
+ "%4.0lf,%4.0lf,(%5.3lf) -> "
+ "%8.0lf,%8.0lf,%8.0lf -> "
+ "%6.2lf,%7.2lf,%4.0lf",
+ px, py, pz, x, y, z, *lat, *lon, *elev);
}
static void grits_opengl_set_height_func(GritsViewer *_opengl, GritsBounds *bounds,
_grits_viewer_emit_rotation_changed(viewer);
}
+/**
+ * grits_viewer_get_pointer:
+ * @viewer: the viewer
+ * @lat: the location to store the latitude
+ * @lon: the location to store the longitude
+ * @elev: the location to store the elevation
+ *
+ * Get the location of the mouse pointer
+ *
+ * Returns: true if the pointer over the viewer
+ */
+gboolean grits_viewer_get_pointer(GritsViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev)
+{
+ g_assert(GRITS_IS_VIEWER(viewer));
+ gint x, y;
+ GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer));
+ GdkWindow *other = gdk_window_get_pointer(window, &x, &y, NULL);
+ (void)other;
+ //if (window != other)
+ // return FALSE;
+ grits_viewer_unproject(viewer, x, y, -1, lat, lon, elev);
+ g_debug("GritsViewer: get_pointer - xy=%d,%d -> lle%.0f,%.0f,%.0f",
+ x, y, *lat, *lon, *elev);
+ return TRUE;
+}
+
/**
* grits_viewer_refresh:
* @viewer: the viewer
glTranslatef(alloc.width - offset, offset, 0);
/* Setup state */
- glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_LINE_SMOOTH);
GtkAllocation alloc;
gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc);
- /* Create cairo surface */
+ /* Create cairo surface */
guint tex = 0;
- const gchar *label0 = "Location: %7.3lf°, %8.3lf°, %4.0fm";
- const gchar *label1 = "Cursor: %7.3lf°, %8.3lf°, %4.0fm";
- gdouble width = 300;
+ gdouble width = 600;
gdouble height = 200;
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cairo = cairo_create(surface);
- /* Text */
- gdouble lat, lon, elev;
+ /* Setup text */
+ gdouble lat, lon, elev, plat=0, plon=0, pelev=0;
grits_viewer_get_location(GRITS_VIEWER(opengl), &lat, &lon, &elev);
- gchar *text0 = g_strdup_printf(label0, lat, lon, elev);
- gchar *text1 = g_strdup_printf(label1, lat, lon, elev);
-
- /* Draw outline */
- cairo_set_line_width(cairo, 3);
- cairo_set_source_rgba(cairo, 0, 0, 0, 0.75);
- cairo_move_to(cairo, 2, 20); cairo_text_path(cairo, text0);
- cairo_move_to(cairo, 2, 40); cairo_text_path(cairo, text1);
- cairo_stroke(cairo);
-
- /* Draw filler */
- cairo_set_source_rgba(cairo, 1, 1, 1, 1);
- cairo_move_to(cairo, 2, 20); cairo_show_text(cairo, text0);
- cairo_move_to(cairo, 2, 40); cairo_show_text(cairo, text1);
+ grits_viewer_get_pointer(GRITS_VIEWER(opengl), &plat, &plon, &pelev);
+ const gchar *template =
+ "Location: %7.3lf°, %8.3lf°, %4.0fm\n"
+ "Cursor: %7.3lf°, %8.3lf°, %4.0fm\n" ;
+ gchar *string = g_strdup_printf(template,
+ lat, lon, elev,
+ plat, plon, pelev);
/* Setup pango */
PangoLayout *layout = pango_cairo_create_layout(cairo);
- PangoFontDescription *font = pango_font_description_from_string("Mono 9");
+ PangoFontDescription *font = pango_font_description_from_string("Mono 14");
pango_layout_set_font_description(layout, font);
pango_font_description_free(font);
- pango_layout_set_text(layout, text0, -1);
+ pango_layout_set_text(layout, string, -1);
pango_cairo_update_layout(cairo, layout);
cairo_set_line_join(cairo, CAIRO_LINE_JOIN_ROUND);
cairo_move_to(cairo, 2, 40);
glTexCoord2f(0, 1); glVertex3f(0 , height, 0); // 2 - | |
glTexCoord2f(0, 0); glVertex3f(0 , 0 , 0); // 3 - 2----1
glEnd();
+
+ /* cleanup */
+ g_free(string);
}
/***********
env->refs = g_list_prepend(env->refs, compass);
/* Add info */
- //GritsCallback *info = grits_callback_new(info_expose, env);
- //grits_viewer_add(viewer, GRITS_OBJECT(info), GRITS_LEVEL_HUD, FALSE);
- //env->refs = g_list_prepend(env->refs, info);
- (void)info_expose;
+ GritsCallback *info = grits_callback_new(info_expose, env);
+ grits_viewer_add(viewer, GRITS_OBJECT(info), GRITS_LEVEL_HUD, TRUE);
+ env->refs = g_list_prepend(env->refs, info);
+ //(void)info_expose;
/* Add background */
//GritsTile *background = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);