X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fplugins%2Ftest.c;h=2e4cbf81f3a4cd2259833239b9ca2074bc3910f5;hp=92b588681e263803a515ab2ac843bb0502d3abb3;hb=992909706626d1e8ad8442ed76192d6bdd7869fa;hpb=aa51def2e3da1a15677bc8a3a85098a7c9a57577 diff --git a/src/plugins/test.c b/src/plugins/test.c index 92b5886..2e4cbf8 100644 --- a/src/plugins/test.c +++ b/src/plugins/test.c @@ -19,44 +19,135 @@ * SECTION:test * @short_description: Testing plugin * - * #GisPluginTest is a testing plugin used during development and as an example + * #GritsPluginTest is a testing plugin used during development and as an example * for how to create a plugin. */ -#include +#include + #include #include -#include +#include +#include #include "test.h" +static void on_poly_enter(GritsPoly *poly) +{ + g_debug("on_poly_enter"); + poly->color[3] = 0.50; + grits_object_queue_draw(GRITS_OBJECT(poly)); +} + +static void on_poly_leave(GritsPoly *poly) +{ + g_debug("on_poly_leave"); + poly->color[3] = 0.2; + grits_object_queue_draw(GRITS_OBJECT(poly)); +} + +static void on_poly_button(GritsPoly *poly, GdkEventButton *event) +{ + g_debug("on_poly_button"); + static int i = 0; + gdouble colors[][3] = { + {1, 0, 0}, {1, 1, 0}, + {0, 1, 0}, {0, 1, 1}, + {0, 0, 1}, {1, 0, 1}, + }; + int idx = i++ % G_N_ELEMENTS(colors); + memcpy(poly->color, colors[idx], sizeof(gdouble)*3); + grits_object_queue_draw(GRITS_OBJECT(poly)); +} + +static void on_poly_key(GritsPoly *poly, GdkEventKey *event) +{ + g_debug("on_poly_key"); + gdouble colors[0xff][3] = { + [GDK_r] {1, 0, 0}, + [GDK_g] {0, 1, 0}, + [GDK_b] {0, 0, 1}, + }; + int key = event->keyval; + memcpy(poly->color, colors[key], sizeof(gdouble)*3); + grits_object_queue_draw(GRITS_OBJECT(poly)); +} + +static void on_marker_enter(GritsMarker *marker, GritsViewer *viewer) +{ + g_debug("on_marker_enter"); + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer)); + GdkCursor *cursor = gdk_cursor_new(GDK_HAND1); + gdk_window_set_cursor(window, cursor); +} + +static void on_marker_leave(GritsMarker *marker, GritsViewer *viewer) +{ + g_debug("on_marker_leave"); + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer)); + gdk_window_set_cursor(window, NULL); +} + +static void on_marker_button(GritsMarker *marker, GdkEventButton *event) +{ + g_debug("on_marker_button"); + GtkWidget *dialog = gtk_dialog_new_with_buttons( + "St. Charles!", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + gtk_dialog_run(GTK_DIALOG(dialog)); +} + /*********** * Methods * ***********/ -gboolean _load_marker(gpointer _test) +void _load_marker(GritsPluginTest *test) +{ + test->marker = grits_marker_new("St. Charles"); + GRITS_OBJECT(test->marker)->center.lat = 38.841847; + GRITS_OBJECT(test->marker)->center.lon = -90.491982; + GRITS_OBJECT(test->marker)->center.elev = 0.0; + GRITS_OBJECT(test->marker)->lod = EARTH_R; + grits_viewer_add(test->viewer, GRITS_OBJECT(test->marker), GRITS_LEVEL_OVERLAY, FALSE); + /* These do not work on marker yet */ + //g_signal_connect(test->marker, "enter", G_CALLBACK(on_marker_enter), NULL); + //g_signal_connect(test->marker, "leave", G_CALLBACK(on_marker_leave), NULL); + //g_signal_connect(test->marker, "button-press", G_CALLBACK(on_marker_button), NULL); + (void)on_marker_enter; + (void)on_marker_leave; + (void)on_marker_button; +} + +void _load_poly(GritsPluginTest *test) { - GisPluginTest *test = _test; - GisMarker *marker = gis_marker_new("St. Charles"); - gis_point_set_lle(gis_object_center(marker), 38.841847, -90.491982, 0); - GIS_OBJECT(marker)->lod = EARTH_R; - test->marker = gis_viewer_add(test->viewer, GIS_OBJECT(marker), GIS_LEVEL_OVERLAY, 0); - return FALSE; + test->poly = grits_poly_parse("35,-90 35,-110 45,-110 45,-90", "\t", " ", ","); + test->poly->color[0] = test->poly->border[0] = 1; + test->poly->color[1] = test->poly->border[1] = 0; + test->poly->color[2] = test->poly->border[2] = 0; + test->poly->color[3] = 0.2; + test->poly->border[3] = 1; + test->poly->width = 10; + grits_viewer_add(test->viewer, GRITS_OBJECT(test->poly), GRITS_LEVEL_OVERLAY, TRUE); + g_signal_connect(test->poly, "enter", G_CALLBACK(on_poly_enter), NULL); + g_signal_connect(test->poly, "leave", G_CALLBACK(on_poly_leave), NULL); + g_signal_connect(test->poly, "button-press", G_CALLBACK(on_poly_button), NULL); + g_signal_connect(test->poly, "key-press", G_CALLBACK(on_poly_key), NULL); } + /** - * gis_plugin_test_new: - * @viewer: the #GisViewer to use for drawing + * grits_plugin_test_new: + * @viewer: the #GritsViewer to use for drawing * * Create a new instance of the testing plugin. * - * Returns: the new #GisPluginTest + * Returns: the new #GritsPluginTest */ -GisPluginTest *gis_plugin_test_new(GisViewer *viewer) +GritsPluginTest *grits_plugin_test_new(GritsViewer *viewer) { - g_debug("GisPluginTest: new"); - GisPluginTest *test = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL); + g_debug("GritsPluginTest: new"); + GritsPluginTest *test = g_object_new(GRITS_TYPE_PLUGIN_TEST, NULL); test->viewer = g_object_ref(viewer); - g_idle_add(_load_marker, test); + _load_marker(test); + _load_poly(test); return test; } @@ -65,34 +156,34 @@ GisPluginTest *gis_plugin_test_new(GisViewer *viewer) * 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 */ } /* Class/Object init */ -static void gis_plugin_test_init(GisPluginTest *test) +static void grits_plugin_test_init(GritsPluginTest *test) { - g_debug("GisPluginTest: init"); + g_debug("GritsPluginTest: init"); } -static void gis_plugin_test_dispose(GObject *_test) +static void grits_plugin_test_dispose(GObject *_test) { - g_debug("GisPluginTest: dispose"); - GisPluginTest *test = GIS_PLUGIN_TEST(_test); + g_debug("GritsPluginTest: dispose"); + GritsPluginTest *test = GRITS_PLUGIN_TEST(_test); if (test->viewer) { - gis_viewer_remove(test->viewer, test->marker); + grits_viewer_remove(test->viewer, test->marker); g_object_unref(test->viewer); test->viewer = NULL; } - G_OBJECT_CLASS(gis_plugin_test_parent_class)->finalize(_test); + 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 = gis_plugin_test_dispose; + gobject_class->dispose = grits_plugin_test_dispose; }