]> Pileus Git - grits/blob - src/objects/gis-marker.c
Split gis-object.{c,h} -> gis-{object,marker,callback}.{c,h}
[grits] / src / objects / gis-marker.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 <config.h>
19 #include "gis-marker.h"
20
21 /* GisMarker */
22 G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
23 static void gis_marker_init(GisMarker *self) { }
24
25 static void gis_marker_finalize(GObject *_self);
26 static void gis_marker_class_init(GisMarkerClass *klass)
27 {
28         G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;
29 }
30
31 GisMarker *gis_marker_new(const gchar *label)
32 {
33         static const int RADIUS =   4;
34         static const int WIDTH  = 100;
35         static const int HEIGHT =  20;
36
37         GisMarker *self = g_object_new(GIS_TYPE_MARKER, NULL);
38         self->xoff  = RADIUS;
39         self->yoff  = HEIGHT-RADIUS;
40         self->label = g_strdup(label);
41         self->cairo = cairo_create(cairo_image_surface_create(
42                                 CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT));
43         cairo_set_source_rgba(self->cairo, 1, 1, 1, 1);
44         cairo_arc(self->cairo, self->xoff, self->yoff, RADIUS, 0, 2*G_PI);
45         cairo_fill(self->cairo);
46         cairo_move_to(self->cairo, self->xoff+4, self->yoff-8);
47         cairo_set_font_size(self->cairo, 10);
48         cairo_show_text(self->cairo, self->label);
49         return self;
50 }
51
52 static void gis_marker_finalize(GObject *_self)
53 {
54         GisMarker *self = GIS_MARKER(_self);
55         cairo_surface_destroy(cairo_get_target(self->cairo));
56         cairo_destroy(self->cairo);
57         g_free(self->label);
58         g_free(self);
59 }