]> Pileus Git - grits/blob - src/gis-object.c
Convert GisObject to GObject
[grits] / src / gis-object.c
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 #include <glib.h>
19 #include <GL/glu.h>
20
21 #include "gis-object.h"
22 #include "gis-util.h"
23
24 /* GisPoint */
25 GisPoint *gis_point_new()
26 {
27         return g_new0(GisPoint, 1);
28 }
29
30 void gis_point_set_lle(GisPoint *self, gdouble lat, gdouble lon, gdouble elev)
31 {
32         self->lat  = lat;
33         self->lon  = lon;
34         self->elev = elev;
35 }
36
37 void gis_point_free(GisPoint *self)
38 {
39         g_free(self);
40 }
41
42
43 /* GisObject */
44 G_DEFINE_TYPE(GisObject, gis_object, G_TYPE_OBJECT);
45 static void gis_object_init(GisObject *self) { }
46 static void gis_object_class_init(GisObjectClass *klass) { }
47
48
49 /* GisMarker */
50 G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
51 static void gis_marker_init(GisMarker *self) { }
52
53 static void gis_marker_finalize(GObject *_self);
54 static void gis_marker_class_init(GisMarkerClass *klass)
55 {
56         G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;
57 }
58
59 GisMarker *gis_marker_new(const gchar *label)
60 {
61         static const int RADIUS =   4;
62         static const int WIDTH  = 100;
63         static const int HEIGHT =  20;
64
65         GisMarker *self = g_object_new(GIS_TYPE_MARKER, NULL);
66         self->xoff  = RADIUS;
67         self->yoff  = HEIGHT-RADIUS;
68         self->label = g_strdup(label);
69         self->cairo = cairo_create(cairo_image_surface_create(
70                                 CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT));
71         cairo_set_source_rgba(self->cairo, 1, 1, 1, 1);
72         cairo_arc(self->cairo, self->xoff, self->yoff, RADIUS, 0, 2*G_PI);
73         cairo_fill(self->cairo);
74         cairo_move_to(self->cairo, self->xoff+4, self->yoff-8);
75         cairo_set_font_size(self->cairo, 10);
76         cairo_show_text(self->cairo, self->label);
77         return self;
78 }
79
80 static void gis_marker_finalize(GObject *_self)
81 {
82         GisMarker *self = GIS_MARKER(_self);
83         cairo_surface_destroy(cairo_get_target(self->cairo));
84         cairo_destroy(self->cairo);
85         g_free(self->label);
86         g_free(self);
87 }
88
89
90 /* GisCallback */
91 G_DEFINE_TYPE(GisCallback, gis_callback, GIS_TYPE_OBJECT);
92 static void gis_callback_init(GisCallback *self) { }
93 static void gis_callback_class_init(GisCallbackClass *klass) { }
94
95 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data)
96 {
97         GisCallback *self = g_object_new(GIS_TYPE_CALLBACK, NULL);
98         self->callback  = callback;
99         self->user_data = user_data;
100         return self;
101 }