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