]> Pileus Git - grits/blobdiff - src/gis-object.c
Convert GisObject to GObject
[grits] / src / gis-object.c
index 8c041b7a706bc08da491ea800dbc18e12c8374fe..4eca0774ccb8d1ed2c6ba0d2e2c98fe1ac90672f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "gis-object.h"
 #include "gis-util.h"
 
-/* TODO
- *   - Manage normals for GisPoint
- */
-
 /* GisPoint */
 GisPoint *gis_point_new()
 {
@@ -36,123 +32,70 @@ void gis_point_set_lle(GisPoint *self, gdouble lat, gdouble lon, gdouble elev)
        self->lat  = lat;
        self->lon  = lon;
        self->elev = elev;
-       lle2xyz(self->lat, self->lon, self->elev,
-                       &self->x, &self->y, &self->z);
 }
 
-void gis_point_set_xyz(GisPoint *self, gdouble x, gdouble y, gdouble z)
+void gis_point_free(GisPoint *self)
 {
-       self->x = x;
-       self->y = y;
-       self->z = z;
+       g_free(self);
 }
 
-void gis_point_set_coords(GisPoint *self, gdouble x, gdouble y)
-{
-       self->cx = x;
-       self->cy = y;
-}
 
-void gis_point_project(GisPoint *self, GisProjection *proj)
-{
-       gluProject(self->x, self->y, self->z,
-                  proj->model, proj->proj, proj->view,
-                  &self->px, &self->py, &self->pz);
-}
+/* GisObject */
+G_DEFINE_TYPE(GisObject, gis_object, G_TYPE_OBJECT);
+static void gis_object_init(GisObject *self) { }
+static void gis_object_class_init(GisObjectClass *klass) { }
 
-GisPoint *gis_point_ref(GisPoint *self)
-{
-       self->refs++;
-       return self;
-}
-
-void gis_point_unref(GisPoint *self)
-{
-       self->refs--;
-       if (self->refs <= 0)
-               g_free(self);
-}
 
+/* GisMarker */
+G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
+static void gis_marker_init(GisMarker *self) { }
 
-/* GisTriangle */
-GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex)
+static void gis_marker_finalize(GObject *_self);
+static void gis_marker_class_init(GisMarkerClass *klass)
 {
-       GisTriangle *self = g_new0(GisTriangle, 1);
-       GIS_OBJECT(self)->type = GIS_TYPE_TRIANGLE;
-       gis_point_set_xyz(&GIS_OBJECT(self)->center,
-               (a->x + b->x + c->x)/3,
-               (a->y + b->y + c->y)/3,
-               (a->z + b->z + c->z)/3);
-       self->verts[0] = gis_point_ref(a);
-       self->verts[1] = gis_point_ref(b);
-       self->verts[2] = gis_point_ref(c);
-       self->tex      = tex;
-       return self;
+       G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;
 }
 
-void gis_triangle_free(GisTriangle *self)
-{
-       gis_point_unref(self->verts[0]);
-       gis_point_unref(self->verts[1]);
-       gis_point_unref(self->verts[2]);
-       g_free(self);
-}
-
-
-/* GisQuad */
-GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex)
+GisMarker *gis_marker_new(const gchar *label)
 {
-       GisQuad *self = g_new0(GisQuad, 1);
-       GIS_OBJECT(self)->type = GIS_TYPE_QUAD;
-       gis_point_set_xyz(&GIS_OBJECT(self)->center,
-               (a->x + b->x + c->x + d->x)/4,
-               (a->y + b->y + c->y + d->y)/4,
-               (a->z + b->z + c->z + d->z)/4);
-       self->verts[0] = gis_point_ref(a);
-       self->verts[1] = gis_point_ref(b);
-       self->verts[2] = gis_point_ref(c);
-       self->verts[3] = gis_point_ref(d);
-       self->tex      = tex;
+       static const int RADIUS =   4;
+       static const int WIDTH  = 100;
+       static const int HEIGHT =  20;
+
+       GisMarker *self = g_object_new(GIS_TYPE_MARKER, NULL);
+       self->xoff  = RADIUS;
+       self->yoff  = HEIGHT-RADIUS;
+       self->label = g_strdup(label);
+       self->cairo = cairo_create(cairo_image_surface_create(
+                               CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT));
+       cairo_set_source_rgba(self->cairo, 1, 1, 1, 1);
+       cairo_arc(self->cairo, self->xoff, self->yoff, RADIUS, 0, 2*G_PI);
+       cairo_fill(self->cairo);
+       cairo_move_to(self->cairo, self->xoff+4, self->yoff-8);
+       cairo_set_font_size(self->cairo, 10);
+       cairo_show_text(self->cairo, self->label);
        return self;
 }
 
-void gis_quad_free(GisQuad *self)
+static void gis_marker_finalize(GObject *_self)
 {
-       gis_point_unref(self->verts[0]);
-       gis_point_unref(self->verts[1]);
-       gis_point_unref(self->verts[2]);
-       gis_point_unref(self->verts[3]);
+       GisMarker *self = GIS_MARKER(_self);
+       cairo_surface_destroy(cairo_get_target(self->cairo));
+       cairo_destroy(self->cairo);
+       g_free(self->label);
        g_free(self);
 }
 
 
 /* GisCallback */
+G_DEFINE_TYPE(GisCallback, gis_callback, GIS_TYPE_OBJECT);
+static void gis_callback_init(GisCallback *self) { }
+static void gis_callback_class_init(GisCallbackClass *klass) { }
+
 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data)
 {
-       GisCallback *self = g_new0(GisCallback, 1);
-       GIS_OBJECT(self)->type = GIS_TYPE_CALLBACK;
+       GisCallback *self = g_object_new(GIS_TYPE_CALLBACK, NULL);
        self->callback  = callback;
        self->user_data = user_data;
        return self;
 }
-
-void gis_callback_free(GisCallback *self)
-{
-       g_free(self);
-}
-
-
-/* GisCallback */
-GisMarker *gis_marker_new(const gchar *label)
-{
-       GisMarker *self = g_new0(GisMarker, 1);
-       GIS_OBJECT(self)->type = GIS_TYPE_MARKER;
-       self->label = g_strdup(label);;
-       return self;
-}
-
-void gis_marker_free(GisMarker *self)
-{
-       g_free(self->label);
-       g_free(self);
-}