]> Pileus Git - grits/blob - src/gis-object.c
bd6c5c95800287f906693d7ff744b26a56f3d788
[grits] / src / gis-object.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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 /* GisMarker */
44 GisMarker *gis_marker_new(const gchar *label)
45 {
46         static const int RADIUS =   4;
47         static const int WIDTH  = 100;
48         static const int HEIGHT =  20;
49
50         GisMarker *self = g_new0(GisMarker, 1);
51         GIS_OBJECT(self)->type = GIS_TYPE_MARKER;
52         self->xoff  = RADIUS;
53         self->yoff  = HEIGHT-RADIUS;
54         self->label = g_strdup(label);
55         self->cairo = cairo_create(cairo_image_surface_create(
56                                 CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT));
57         cairo_set_source_rgba(self->cairo, 1, 1, 1, 1);
58         cairo_arc(self->cairo, self->xoff, self->yoff, RADIUS, 0, 2*G_PI);
59         cairo_fill(self->cairo);
60         cairo_move_to(self->cairo, self->xoff+4, self->yoff-8);
61         cairo_set_font_size(self->cairo, 10);
62         cairo_show_text(self->cairo, self->label);
63         return self;
64 }
65
66 void gis_marker_free(GisMarker *self)
67 {
68         cairo_surface_destroy(cairo_get_target(self->cairo));
69         cairo_destroy(self->cairo);
70         g_free(self->label);
71         g_free(self);
72 }
73
74
75 /* GisCallback */
76 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data)
77 {
78         GisCallback *self = g_new0(GisCallback, 1);
79         GIS_OBJECT(self)->type = GIS_TYPE_CALLBACK;
80         self->callback  = callback;
81         self->user_data = user_data;
82         return self;
83 }
84
85 void gis_callback_free(GisCallback *self)
86 {
87         g_free(self);
88 }