2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
19 #include "gis-marker.h"
22 GisMarker *gis_marker_new(const gchar *label)
24 //g_debug("GisMarker: new - %s", label);
25 static const int RADIUS = 4;
26 static const int WIDTH = 100;
27 static const int HEIGHT = 20;
29 GisMarker *marker = g_object_new(GIS_TYPE_MARKER, NULL);
30 marker->xoff = RADIUS;
31 marker->yoff = HEIGHT-RADIUS;
32 marker->label = g_strdup(label);
33 marker->cairo = cairo_create(cairo_image_surface_create(
34 CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT));
35 cairo_set_source_rgba(marker->cairo, 1, 1, 1, 1);
36 cairo_arc(marker->cairo, marker->xoff, marker->yoff, RADIUS, 0, 2*G_PI);
37 cairo_fill(marker->cairo);
38 cairo_move_to(marker->cairo, marker->xoff+4, marker->yoff-8);
39 cairo_set_font_size(marker->cairo, 10);
40 cairo_show_text(marker->cairo, marker->label);
44 G_DEFINE_TYPE(GisMarker, gis_marker, GIS_TYPE_OBJECT);
45 static void gis_marker_init(GisMarker *marker) { }
47 static void gis_marker_finalize(GObject *_marker)
49 GisMarker *marker = GIS_MARKER(_marker);
50 //g_debug("GisMarker: finalize - %s", marker->label);
51 cairo_surface_t *surface = cairo_get_target(marker->cairo);
52 cairo_surface_destroy(surface);
53 cairo_destroy(marker->cairo);
54 g_free(marker->label);
57 static void gis_marker_class_init(GisMarkerClass *klass)
59 G_OBJECT_CLASS(klass)->finalize = gis_marker_finalize;