]> Pileus Git - grits/blob - src/objects/gis-object.h
Update API docs
[grits] / src / objects / gis-object.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GIS_OBJECT_H__
19 #define __GIS_OBJECT_H__
20
21 #include <glib.h>
22 #include <glib-object.h>
23 #include <cairo.h>
24
25
26 /* Take that GLib boilerplate! */
27 #define GOBJECT_HEAD( \
28                 MAM, BAR, \
29                 Mam, Bar, \
30                 mam, bar) \
31 GType mam##_##bar##_get_type(void); \
32 typedef struct _##Mam##Bar Mam##Bar; \
33 typedef struct _##Mam##Bar##Class Mam##Bar##Class; \
34 static inline Mam##Bar *MAM##_##BAR(gpointer obj) { \
35         return G_TYPE_CHECK_INSTANCE_CAST(obj, MAM##_TYPE_##BAR, Mam##Bar); \
36 } \
37 static inline gboolean MAM##_IS_##BAR(gpointer obj) { \
38         return G_TYPE_CHECK_INSTANCE_TYPE(obj, MAM##_TYPE_##BAR); \
39 } \
40 static inline Mam##Bar##Class *MAM##_##BAR##_CLASS(gpointer klass) { \
41         return G_TYPE_CHECK_CLASS_CAST(klass, MAM##_TYPE_##BAR, Mam##Bar##Class); \
42 } \
43 static inline gboolean MAM##_IS_##BAR##_CLASS(gpointer klass) { \
44         return G_TYPE_CHECK_CLASS_TYPE(klass, MAM##_TYPE_##BAR); \
45 } \
46 static inline Mam##Bar##Class *MAM##_##BAR##_GET_CLASS(gpointer obj) { \
47         return G_TYPE_INSTANCE_GET_CLASS(obj, MAM##_TYPE_##BAR, Mam##Bar##Class); \
48 }
49
50 #define GOBJECT_BODY( \
51                 parent_type, \
52                 MAM, BAR, \
53                 Mam, Bar, \
54                 mam, bar) \
55 G_DEFINE_TYPE(Mam##Bar, mam##_##bar, parent_type); \
56 static void mam##_##bar##_init(Mam##Bar *self) { \
57 } \
58 static void mam##_##bar##_class_init(Mam##Bar##Class *klass) { \
59 } \
60 static Mam##Bar *mam##_##bar##_new() { \
61         return g_object_new(MAM##_TYPE_##BAR, NULL); \
62 }
63
64
65 /* GisPoint */
66 typedef struct _GisPoint GisPoint;
67
68 struct _GisPoint {
69         gdouble lat, lon, elev;
70 };
71
72 GisPoint *gis_point_new();
73 void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
74 void gis_point_free(GisPoint *point);
75
76
77 /* GisObject */
78 #define GIS_TYPE_OBJECT (gis_object_get_type())
79
80 GOBJECT_HEAD(
81         GIS, OBJECT,
82         Gis, Object,
83         gis, object);
84
85 struct _GisObject {
86         GObject parent_instance;
87         GisPoint center;
88         gdouble  lod;
89 };
90
91 struct _GisObjectClass {
92         GObjectClass parent_class;
93 };
94
95 static inline GisPoint *gis_object_center(GisObject *object)
96 {
97         return &GIS_OBJECT(object)->center;
98 }
99
100
101 /* GisMarker */
102 #define GIS_TYPE_MARKER (gis_marker_get_type())
103
104 GOBJECT_HEAD(
105         GIS, MARKER,
106         Gis, Marker,
107         gis, marker);
108
109 struct _GisMarker {
110         GisObject  parent_instance;
111         gint       xoff, yoff;
112         gchar     *label;
113         cairo_t   *cairo;
114         guint      tex;
115 };
116
117 struct _GisMarkerClass {
118         GisObjectClass parent_class;
119 };
120
121 GisMarker *gis_marker_new(const gchar *label);
122
123
124 /* GisCallback */
125 #define GIS_TYPE_CALLBACK (gis_callback_get_type())
126
127 GOBJECT_HEAD(
128         GIS, CALLBACK,
129         Gis, Callback,
130         gis, callback);
131
132 typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
133
134 struct _GisCallback {
135         GisObject       parent;
136         GisCallbackFunc callback;
137         gpointer        user_data;
138 };
139
140 struct _GisCallbackClass {
141         GisObjectClass parent_class;
142 };
143
144 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
145
146 #endif