]> Pileus Git - grits/commitdiff
Add pointer code pointer
authorAndy Spencer <andy753421@gmail.com>
Sun, 20 Jan 2013 03:51:32 +0000 (03:51 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 05:24:59 +0000 (05:24 +0000)
src/grits-opengl.c
src/grits-viewer.c
src/grits-viewer.h
src/plugins/env.c

index 2bd00822cea22ace1b4776aba045d3cf6ac2f909..dbf0aea3ccda87529ce3ae67bc4c2e1e8dc63292 100644 (file)
@@ -530,11 +530,11 @@ static void grits_opengl_unproject(GritsViewer *_opengl,
                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,
index 1afd2eaece9be068a2f6cec0e9bb268019a69118..7dbab925d6c0a89e32e689187f27b15e85871d35 100644 (file)
@@ -389,6 +389,32 @@ void grits_viewer_rotate(GritsViewer *viewer, gdouble x, gdouble y, gdouble z)
        _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
index 581751edfa10369763e18bda7637c9252ef8c8e1..06caff840322512fd0753700b23274919ca5b43d 100644 (file)
@@ -166,6 +166,8 @@ void grits_viewer_set_rotation(GritsViewer *viewer, gdouble  x, gdouble  y, gdou
 void grits_viewer_get_rotation(GritsViewer *viewer, gdouble *x, gdouble *y, gdouble *z);
 void grits_viewer_rotate      (GritsViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
 
+gboolean grits_viewer_get_pointer(GritsViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev);
+
 void grits_viewer_refresh(GritsViewer *viewer);
 
 void grits_viewer_set_offline(GritsViewer *viewer, gboolean offline);
index 658881d3f5749cbe691c8e130cf050ea65e37f5a..e01ca63487cea546fc5e7db301af4fbc9c340310 100644 (file)
@@ -202,10 +202,7 @@ static void compass_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer
        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);
 
@@ -229,39 +226,30 @@ static void info_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer _e
        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);
@@ -299,6 +287,9 @@ static void info_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer _e
        glTexCoord2f(0, 1); glVertex3f(0    , height, 0); // 2 - |    |
        glTexCoord2f(0, 0); glVertex3f(0    , 0     , 0); // 3 - 2----1
        glEnd();
+
+       /* cleanup */
+       g_free(string);
 }
 
 /***********
@@ -333,10 +324,10 @@ GritsPluginEnv *grits_plugin_env_new(GritsViewer *viewer, GritsPrefs *prefs)
        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);