]> Pileus Git - grits/blobdiff - src/gis-object.h
Convert GisObject to GObject
[grits] / src / gis-object.h
index f5ab5a8c13c310094e3cbef5ef7cab333a6c16a4..acc425506451c0f876c58db9178bbc32405cfd3f 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
 #define __GIS_OBJECT_H__
 
 #include <glib.h>
+#include <glib-object.h>
+#include <cairo.h>
+
+
+/* Take that GLib boilerplate! */
+#define GOBJECT_HEAD( \
+               MAM, BAR, \
+               Mam, Bar, \
+               mam, bar) \
+GType mam##_##bar##_get_type(void); \
+typedef struct _##Mam##Bar Mam##Bar; \
+typedef struct _##Mam##Bar##Class Mam##Bar##Class; \
+static inline Mam##Bar *MAM##_##BAR(gpointer obj) { \
+       return G_TYPE_CHECK_INSTANCE_CAST(obj, MAM##_TYPE_##BAR, Mam##Bar); \
+} \
+static inline gboolean MAM##_IS_##BAR(gpointer obj) { \
+       return G_TYPE_CHECK_INSTANCE_TYPE(obj, MAM##_TYPE_##BAR); \
+} \
+static inline Mam##Bar##Class *MAM##_##BAR##_CLASS(gpointer klass) { \
+       return G_TYPE_CHECK_CLASS_CAST(klass, MAM##_TYPE_##BAR, Mam##Bar##Class); \
+} \
+static inline gboolean MAM##_IS_##BAR##_CLASS(gpointer klass) { \
+       return G_TYPE_CHECK_CLASS_TYPE(klass, MAM##_TYPE_##BAR); \
+} \
+static inline Mam##Bar##Class *MAM##_##BAR##_GET_CLASS(gpointer obj) { \
+       return G_TYPE_INSTANCE_GET_CLASS(obj, MAM##_TYPE_##BAR, Mam##Bar##Class); \
+}
+
+#define GOBJECT_BODY( \
+               parent_type, \
+               MAM, BAR, \
+               Mam, Bar, \
+               mam, bar) \
+G_DEFINE_TYPE(Mam##Bar, mam##_##bar, parent_type); \
+static void mam##_##bar##_init(Mam##Bar *self) { \
+} \
+static void mam##_##bar##_class_init(Mam##Bar##Class *klass) { \
+} \
+static Mam##Bar *mam##_##bar##_new() { \
+       return g_object_new(MAM##_TYPE_##BAR, NULL); \
+}
+
+
+/* GisPoint */
+typedef struct _GisPoint GisPoint;
 
-/* Base types */
-typedef struct _GisProjection GisProjection;
-typedef struct _GisPoint      GisPoint;
-
-struct _GisProjection {
-       gdouble model[16];
-       gdouble proj[16];
-       gint    view[4];
-};
 struct _GisPoint {
-       union {
-               gdouble lle[3];
-               struct { gdouble lat, lon, elev; };
-       };
-       union {
-               gdouble xyz[3];
-               struct { gdouble x, y, z; };
-       };
-       union {
-               gdouble proj[3];
-               struct { gdouble px, py, pz; };
-       };
-       union {
-               gdouble norm[3];
-               struct { gdouble nx, ny, nz; };
-       };
-       union {
-               gdouble coords[2];
-               struct { gdouble cx, cy, xz; };
-       };
-       gint refs;
+       gdouble lat, lon, elev;
 };
 
-/* Objects */
-#define GIS_OBJECT(object)     ((GisObject  *)object)
-#define GIS_TRIANGLE(triangle) ((GisTriangle*)triangle)
-#define GIS_QUAD(quad)         ((GisQuad    *)quad)
-#define GIS_CALLBACK(callback) ((GisCallback*)callback)
-#define GIS_MARKER(marker)     ((GisMarker  *)marker)
-
-typedef enum {
-       GIS_TYPE_TRIANGLE,
-       GIS_TYPE_QUAD,
-       GIS_TYPE_CALLBACK,
-       GIS_TYPE_MARKER,
-       GIS_NUM_TYPES,
-} GisObjectType;
-
-typedef struct _GisObject   GisObject;
-typedef struct _GisTriangle GisTriangle;
-typedef struct _GisQuad     GisQuad;
-typedef struct _GisCallback GisCallback;
-typedef struct _GisMarker   GisMarker;
+GisPoint *gis_point_new();
+void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
+void gis_point_free(GisPoint *point);
 
-typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
+
+/* GisObject */
+#define GIS_TYPE_OBJECT (gis_object_get_type())
+
+GOBJECT_HEAD(
+       GIS, OBJECT,
+       Gis, Object,
+       gis, object);
 
 struct _GisObject {
-       GisObjectType  type;
-       GisPoint       center;
-       GisProjection *proj;
-       gdouble        lod;
+       GObject parent_instance;
+       GisPoint center;
+       gdouble  lod;
+};
+
+struct _GisObjectClass {
+       GObjectClass parent_class;
 };
-struct _GisTriangle {
-       GisObject  parent;
-       GisPoint  *verts[3];
+
+static inline GisPoint *gis_object_center(GisObject *object)
+{
+       return &GIS_OBJECT(object)->center;
+}
+
+
+/* GisMarker */
+#define GIS_TYPE_MARKER (gis_marker_get_type())
+
+GOBJECT_HEAD(
+       GIS, MARKER,
+       Gis, Marker,
+       gis, marker);
+
+struct _GisMarker {
+       GisObject  parent_instance;
+       gint       xoff, yoff;
+       gchar     *label;
+       cairo_t   *cairo;
        guint      tex;
 };
-struct _GisQuad {
-       GisObject  parent;
-       GisPoint  *verts[4];
-       guint     tex;
+
+struct _GisMarkerClass {
+       GisObjectClass parent_class;
 };
+
+GisMarker *gis_marker_new(const gchar *label);
+
+
+/* GisCallback */
+#define GIS_TYPE_CALLBACK (gis_callback_get_type())
+
+GOBJECT_HEAD(
+       GIS, CALLBACK,
+       Gis, Callback,
+       gis, callback);
+
+typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
+
 struct _GisCallback {
        GisObject       parent;
        GisCallbackFunc callback;
        gpointer        user_data;
 };
-struct _GisMarker   {
-       GisObject  parent;
-       gchar     *label;
-};
 
-/* Support functions */
-#define gis_object_center(object) \
-       (&GIS_OBJECT(object)->center)
-
-GisPoint *gis_point_new();
-void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
-void gis_point_set_xyz(GisPoint *point, gdouble x, gdouble y, gdouble z);
-void gis_point_set_coords(GisPoint *point, gdouble x, gdouble y);
-void gis_point_project(GisPoint *point, GisProjection *proj);
-GisPoint *gis_point_ref(GisPoint *point);
-void gis_point_unref(GisPoint *point);
-
-GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex);
-void gis_triangle_free(GisTriangle *tri);
-
-GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex);
-void gis_quad_free(GisQuad *quad);
+struct _GisCallbackClass {
+       GisObjectClass parent_class;
+};
 
 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
-void gis_callback_free(GisCallback *cb);
-
-GisMarker *gis_marker_new(const gchar *label);
-void gis_marker_free(GisMarker *marker);
 
 #endif