X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fplugins%2Ftest.c;h=c051806a0b392dc79616ca39c96666b4eb8243b9;hp=94995b01f7979623922b38ff8fb1bba8c80d51c4;hb=07448c519e963bae1cfde4f1ff353478dd28136c;hpb=a15a1829ffbf0176930601ee9ac7cc0c07fa2d06 diff --git a/src/plugins/test.c b/src/plugins/test.c index 94995b0..c051806 100644 --- a/src/plugins/test.c +++ b/src/plugins/test.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Andy Spencer + * Copyright (C) 2009-2010 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,79 +15,48 @@ * along with this program. If not, see . */ -#include +/** + * SECTION:test + * @short_description: Testing plugin + * + * #GritsPluginTest is a testing plugin used during development and as an example + * for how to create a plugin. + */ + #include #include -#include +#include #include "test.h" /*********** * Methods * ***********/ -GisPluginTest *gis_plugin_test_new(GisViewer *viewer) +gboolean _load_marker(gpointer _test) { - g_debug("GisPluginTest: new"); - GisPluginTest *self = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL); - self->viewer = viewer; - return self; + GritsPluginTest *test = _test; + GritsMarker *marker = grits_marker_new("St. Charles"); + grits_point_set_lle(grits_object_center(marker), 38.841847, -90.491982, 0); + GRITS_OBJECT(marker)->lod = EARTH_R; + test->marker = grits_viewer_add(test->viewer, GRITS_OBJECT(marker), GRITS_LEVEL_OVERLAY, 0); + return FALSE; } - -static void gis_plugin_test_expose(GisPlugin *_self) +/** + * grits_plugin_test_new: + * @viewer: the #GritsViewer to use for drawing + * + * Create a new instance of the testing plugin. + * + * Returns: the new #GritsPluginTest + */ +GritsPluginTest *grits_plugin_test_new(GritsViewer *viewer) { - GisPluginTest *self = GIS_PLUGIN_TEST(_self); - g_debug("GisPluginTest: expose"); - - double width = GTK_WIDGET(self->viewer)->allocation.width; - double height = GTK_WIDGET(self->viewer)->allocation.height; - - // St. Charles - // lat = 38.841847 - // lon = -90.491982 - gdouble px, py, pz; - gis_viewer_project(self->viewer, - 38.841847, -90.491982, 0, &px, &py, &pz); - py = height-py; - - //cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - //cairo_t *cairo = cairo_create(surface); - //cairo_set_source_rgba(cairo, 1, 1, 1, 1); - //cairo_arc(cairo, px, py, 4, 0, 2*G_PI); - //cairo_fill(cairo); - //cairo_move_to(cairo, px+4, py-8); - //cairo_set_font_size(cairo, 10); - //cairo_show_text(cairo, "Marker!"); - - //guint tex; - //glEnable(GL_TEXTURE_2D); - //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - //glPixelStorei(GL_PACK_ALIGNMENT, 1); - //glGenTextures(1, &tex); - //glBindTexture(GL_TEXTURE_2D, tex); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, - // cairo_image_surface_get_data(surface)); - //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - //glMatrixMode(GL_PROJECTION); - //glLoadIdentity(); - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); - - //glDisable(GL_COLOR_MATERIAL); - //glDisable(GL_CULL_FACE); - //glDisable(GL_DEPTH_TEST); - //glDisable(GL_LIGHTING); - //glBegin(GL_QUADS); - //glTexCoord2d(0, 0); glVertex3f(-1, 1, 1); - //glTexCoord2d(1, 0); glVertex3f( 1, 1, 1); - //glTexCoord2d(1, 1); glVertex3f( 1, -1, 1); - //glTexCoord2d(0, 1); glVertex3f(-1, -1, 1); - //glEnd(); - //glDeleteTextures(1, &tex); - //cairo_destroy(cairo); - //cairo_surface_destroy(surface); + g_debug("GritsPluginTest: new"); + GritsPluginTest *test = g_object_new(GRITS_TYPE_PLUGIN_TEST, NULL); + test->viewer = g_object_ref(viewer); + _load_marker(test); + return test; } @@ -95,22 +64,34 @@ static void gis_plugin_test_expose(GisPlugin *_self) * GObject code * ****************/ /* Plugin init */ -static void gis_plugin_test_plugin_init(GisPluginInterface *iface); -G_DEFINE_TYPE_WITH_CODE(GisPluginTest, gis_plugin_test, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN, - gis_plugin_test_plugin_init)); -static void gis_plugin_test_plugin_init(GisPluginInterface *iface) +static void grits_plugin_test_plugin_init(GritsPluginInterface *iface); +G_DEFINE_TYPE_WITH_CODE(GritsPluginTest, grits_plugin_test, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN, + grits_plugin_test_plugin_init)); +static void grits_plugin_test_plugin_init(GritsPluginInterface *iface) { - g_debug("GisPluginTest: plugin_init"); + g_debug("GritsPluginTest: plugin_init"); /* Add methods to the interface */ - iface->expose = gis_plugin_test_expose; } /* Class/Object init */ -static void gis_plugin_test_init(GisPluginTest *self) +static void grits_plugin_test_init(GritsPluginTest *test) +{ + g_debug("GritsPluginTest: init"); +} +static void grits_plugin_test_dispose(GObject *_test) { - g_debug("GisPluginTest: init"); + g_debug("GritsPluginTest: dispose"); + GritsPluginTest *test = GRITS_PLUGIN_TEST(_test); + if (test->viewer) { + grits_viewer_remove(test->viewer, test->marker); + g_object_unref(test->viewer); + test->viewer = NULL; + } + G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test); } -static void gis_plugin_test_class_init(GisPluginTestClass *klass) +static void grits_plugin_test_class_init(GritsPluginTestClass *klass) { - g_debug("GisPluginTest: class_init"); + g_debug("GritsPluginTest: class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + gobject_class->dispose = grits_plugin_test_dispose; }