X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fplugins%2Ftest.c;h=8d12dc1172faec9fe1736cc3b919af511077c821;hp=b7435ab3f8b521bd6bc91594d914bb270287cdae;hb=67a63167629adc48ff31530dd58ece577f3d7460;hpb=f54436e90fe38ef17e85dbdfea64a8916ceae872 diff --git a/src/plugins/test.c b/src/plugins/test.c index b7435ab..8d12dc1 100644 --- a/src/plugins/test.c +++ b/src/plugins/test.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Andy Spencer + * Copyright (C) 2009-2011 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 @@ -25,31 +25,30 @@ #include -#include -#include - #include #include #include "test.h" -static void on_poly_enter(GritsPoly *poly) +static gboolean on_poly_enter(GritsPoly *poly) { - g_debug("on_poly_enter"); + g_debug("GritsPluginTest: on_poly_enter"); poly->color[3] = 0.50; grits_object_queue_draw(GRITS_OBJECT(poly)); + return FALSE; } -static void on_poly_leave(GritsPoly *poly) +static gboolean on_poly_leave(GritsPoly *poly) { - g_debug("on_poly_leave"); + g_debug("GritsPluginTest: on_poly_leave"); poly->color[3] = 0.2; grits_object_queue_draw(GRITS_OBJECT(poly)); + return FALSE; } -static void on_poly_button(GritsPoly *poly, GdkEventButton *event) +static gboolean on_poly_button(GritsPoly *poly, GdkEventButton *event) { - g_debug("on_poly_button"); + g_debug("GritsPluginTest: on_poly_button"); static int i = 0; gdouble colors[][3] = { {1, 0, 0}, {1, 1, 0}, @@ -59,42 +58,32 @@ static void on_poly_button(GritsPoly *poly, GdkEventButton *event) int idx = i++ % G_N_ELEMENTS(colors); memcpy(poly->color, colors[idx], sizeof(gdouble)*3); grits_object_queue_draw(GRITS_OBJECT(poly)); + return TRUE; } -static void on_poly_key(GritsPoly *poly, GdkEventKey *event) +static gboolean on_poly_key(GritsPoly *poly, GdkEventKey *event) { - g_debug("on_poly_key"); + g_debug("GritsPluginTest: on_poly_key - %d", event->keyval); gdouble colors[0xff][3] = { - [GDK_r] {1, 0, 0}, - [GDK_g] {0, 1, 0}, - [GDK_b] {0, 0, 1}, + [GDK_KEY_r] {1, 0, 0}, + [GDK_KEY_g] {0, 1, 0}, + [GDK_KEY_b] {0, 0, 1}, }; + if (event->keyval >= G_N_ELEMENTS(colors)) + return FALSE; int key = event->keyval; memcpy(poly->color, colors[key], sizeof(gdouble)*3); grits_object_queue_draw(GRITS_OBJECT(poly)); + return TRUE; } -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) +static gboolean on_marker_button(GritsMarker *marker, GdkEventButton *event) { - g_debug("on_marker_button"); + g_debug("GritsPluginTest: 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)); + return TRUE; } /*********** @@ -106,15 +95,10 @@ void _load_marker(GritsPluginTest *test) 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; + GRITS_OBJECT(test->marker)->lod = EARTH_R*3; + grits_object_set_cursor(GRITS_OBJECT(test->marker), GDK_HAND2); + grits_viewer_add(test->viewer, GRITS_OBJECT(test->marker), GRITS_LEVEL_HUD, FALSE); + g_signal_connect(test->marker, "clicked", G_CALLBACK(on_marker_button), test->viewer); } void _load_poly(GritsPluginTest *test) @@ -126,11 +110,26 @@ void _load_poly(GritsPluginTest *test) test->poly->color[3] = 0.2; test->poly->border[3] = 1; test->poly->width = 6; - 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); + grits_viewer_add(test->viewer, GRITS_OBJECT(test->poly), GRITS_LEVEL_OVERLAY, FALSE); + 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, "clicked", G_CALLBACK(on_poly_button), NULL); + g_signal_connect(test->poly, "key-press", G_CALLBACK(on_poly_key), NULL); +} + +void _load_line(GritsPluginTest *test) +{ + test->line = grits_line_parse("30,-80 30,-120 50,-120 50,-80", "\t", " ", ","); + test->line->color[0] = 1; + test->line->color[1] = 0; + test->line->color[2] = 0; + test->line->color[3] = 1; + test->line->width = 8; + grits_viewer_add(test->viewer, GRITS_OBJECT(test->line), GRITS_LEVEL_OVERLAY, FALSE); + g_signal_connect(test->line, "enter", G_CALLBACK(on_poly_enter), NULL); + g_signal_connect(test->line, "leave", G_CALLBACK(on_poly_leave), NULL); + g_signal_connect(test->line, "button-press", G_CALLBACK(on_poly_button), NULL); + g_signal_connect(test->line, "key-press", G_CALLBACK(on_poly_key), NULL); } /** @@ -148,6 +147,7 @@ GritsPluginTest *grits_plugin_test_new(GritsViewer *viewer) test->viewer = g_object_ref(viewer); _load_marker(test); _load_poly(test); + _load_line(test); return test; } @@ -175,9 +175,12 @@ static void grits_plugin_test_dispose(GObject *_test) g_debug("GritsPluginTest: dispose"); GritsPluginTest *test = GRITS_PLUGIN_TEST(_test); if (test->viewer) { - grits_viewer_remove(test->viewer, GRITS_OBJECT(test->marker)); - g_object_unref(test->viewer); + GritsViewer *viewer = test->viewer; test->viewer = NULL; + grits_object_destroy_pointer(&test->marker); + grits_object_destroy_pointer(&test->poly); + grits_object_destroy_pointer(&test->line); + g_object_unref(viewer); } G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test); }