]> Pileus Git - grits/blobdiff - src/objects/grits-poly.c
Cast function pointers for gluTessCallback
[grits] / src / objects / grits-poly.c
index 2b62997e249c7a85ba5d6998dda27e46e0ed71b2..357afaefb84cc426b19bb40e1667ddb3989f0e82 100644 (file)
@@ -23,8 +23,7 @@
  */
 
 #include <config.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
+#include "gtkgl.h"
 #include "grits-poly.h"
 
 /* Drawing */
@@ -32,9 +31,9 @@ static void grits_poly_tess(gdouble (**points)[3])
 {
        //g_debug("GritsPoly: tess");
        GLUtesselator *tess = gluNewTess();
-       gluTessCallback(tess, GLU_TESS_BEGIN,  (_GLUfuncptr)glBegin);
-       gluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)glVertex3dv);
-       gluTessCallback(tess, GLU_TESS_END,    (_GLUfuncptr)glEnd);
+       gluTessCallback(tess, GLU_TESS_BEGIN,  G_CALLBACK(glBegin));
+       gluTessCallback(tess, GLU_TESS_VERTEX, G_CALLBACK(glVertex3dv));
+       gluTessCallback(tess, GLU_TESS_END,    G_CALLBACK(glEnd));
        for (int pi = 0; points[pi]; pi++) {
                gluTessBeginPolygon(tess, NULL);
                gluTessBeginContour(tess);
@@ -153,7 +152,7 @@ static void grits_poly_pick(GritsObject *_poly, GritsOpenGL *opengl)
 
 static gboolean grits_poly_delete(gpointer list)
 {
-       glDeleteLists((guint)list, 1);
+       glDeleteLists((guintptr)list, 1);
        return FALSE;
 }
 
@@ -174,55 +173,17 @@ GritsPoly *grits_poly_new(gdouble (**points)[3])
        return poly;
 }
 
-static void _free_points(gdouble (**points)[3])
-{
-       for (int i = 0; points[i]; i++)
-               g_free(points[i]);
-       g_free(points);
-}
-
 GritsPoly *grits_poly_parse(const gchar *str,
                const gchar *poly_sep, const gchar *point_sep, const gchar *coord_sep)
 {
-       /* Split and count polygons */
-       gchar **spolys = g_strsplit(str, poly_sep, -1);
-       int     npolys = g_strv_length(spolys);
-
-       GritsBounds bounds = {-90, 90, -180, 180};
-       gdouble (**polys)[3] = (gpointer)g_new0(double*, npolys+1);
-       for (int pi = 0; pi < npolys; pi++) {
-               /* Split and count coordinates */
-               gchar **scoords = g_strsplit(spolys[pi], point_sep, -1);
-               int     ncoords = g_strv_length(scoords);
-
-               /* Create binary coords */
-               gdouble (*coords)[3] = (gpointer)g_new0(gdouble, 3*(ncoords+1));
-               for (int ci = 0; ci < ncoords; ci++) {
-                       gdouble lat, lon;
-                       sscanf(scoords[ci], "%lf,%lf", &lat, &lon);
-                       if (lat > bounds.n) bounds.n = lat;
-                       if (lat < bounds.s) bounds.s = lat;
-                       if (lon > bounds.e) bounds.e = lon;
-                       if (lon < bounds.w) bounds.w = lon;
-                       lle2xyz(lat, lon, 0,
-                                       &coords[ci][0],
-                                       &coords[ci][1],
-                                       &coords[ci][2]);
-               }
-
-               /* Insert coords into poly array */
-               polys[pi] = coords;
-               g_strfreev(scoords);
-       }
-       g_strfreev(spolys);
+       GritsPoint center;
+       gdouble (**polys)[3] = parse_points(str,
+                       poly_sep, point_sep, coord_sep, NULL, &center);
 
-       /* Create GritsPoly */
        GritsPoly *poly = grits_poly_new(polys);
-       GRITS_OBJECT(poly)->center.lat  = (bounds.n + bounds.s)/2;
-       GRITS_OBJECT(poly)->center.lon  = lon_avg(bounds.e, bounds.w);
-       GRITS_OBJECT(poly)->center.elev = 0;
-       GRITS_OBJECT(poly)->skip        = GRITS_SKIP_CENTER;
-       g_object_weak_ref(G_OBJECT(poly), (GWeakNotify)_free_points, polys);
+       GRITS_OBJECT(poly)->center = center;
+       GRITS_OBJECT(poly)->skip   = GRITS_SKIP_CENTER;
+       g_object_weak_ref(G_OBJECT(poly), (GWeakNotify)free_points, polys);
        return poly;
 }
 
@@ -242,8 +203,8 @@ static void grits_poly_finalize(GObject *_poly)
 {
        //g_debug("GritsPoly: finalize");
        GritsPoly *poly = GRITS_POLY(_poly);
-       if (poly->list[0]) g_idle_add(grits_poly_delete, (gpointer)poly->list[0]);
-       if (poly->list[1]) g_idle_add(grits_poly_delete, (gpointer)poly->list[1]);
+       if (poly->list[0]) g_idle_add(grits_poly_delete, (gpointer)(guintptr)poly->list[0]);
+       if (poly->list[1]) g_idle_add(grits_poly_delete, (gpointer)(guintptr)poly->list[1]);
 }
 
 static void grits_poly_class_init(GritsPolyClass *klass)