2 * Copyright (C) 2009-2011 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/>.
20 * @short_description: Testing plugin
22 * #GritsPluginTest is a testing plugin used during development and as an example
23 * for how to create a plugin.
28 #include <gdk/gdkkeysyms.h>
33 static void on_poly_enter(GritsPoly *poly)
35 g_debug("on_poly_enter");
36 poly->color[3] = 0.50;
37 grits_object_queue_draw(GRITS_OBJECT(poly));
40 static void on_poly_leave(GritsPoly *poly)
42 g_debug("on_poly_leave");
44 grits_object_queue_draw(GRITS_OBJECT(poly));
47 static void on_poly_button(GritsPoly *poly, GdkEventButton *event)
49 g_debug("on_poly_button");
51 gdouble colors[][3] = {
56 int idx = i++ % G_N_ELEMENTS(colors);
57 memcpy(poly->color, colors[idx], sizeof(gdouble)*3);
58 grits_object_queue_draw(GRITS_OBJECT(poly));
61 static void on_poly_key(GritsPoly *poly, GdkEventKey *event)
63 g_debug("on_poly_key");
64 gdouble colors[0xff][3] = {
69 int key = event->keyval;
70 memcpy(poly->color, colors[key], sizeof(gdouble)*3);
71 grits_object_queue_draw(GRITS_OBJECT(poly));
74 static void on_marker_enter(GritsMarker *marker, GritsViewer *viewer)
76 g_debug("on_marker_enter");
77 GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer));
78 GdkCursor *cursor = gdk_cursor_new(GDK_HAND1);
79 gdk_window_set_cursor(window, cursor);
82 static void on_marker_leave(GritsMarker *marker, GritsViewer *viewer)
84 g_debug("on_marker_leave");
85 GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer));
86 gdk_window_set_cursor(window, NULL);
89 static void on_marker_button(GritsMarker *marker, GdkEventButton *event)
91 g_debug("on_marker_button");
92 GtkWidget *dialog = gtk_dialog_new_with_buttons(
93 "St. Charles!", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
94 gtk_dialog_run(GTK_DIALOG(dialog));
100 void _load_marker(GritsPluginTest *test)
102 test->marker = grits_marker_new("St. Charles");
103 GRITS_OBJECT(test->marker)->center.lat = 38.841847;
104 GRITS_OBJECT(test->marker)->center.lon = -90.491982;
105 GRITS_OBJECT(test->marker)->center.elev = 0.0;
106 GRITS_OBJECT(test->marker)->lod = EARTH_R;
107 grits_viewer_add(test->viewer, GRITS_OBJECT(test->marker), GRITS_LEVEL_OVERLAY, FALSE);
108 /* These do not work on marker yet */
109 //g_signal_connect(test->marker, "enter", G_CALLBACK(on_marker_enter), NULL);
110 //g_signal_connect(test->marker, "leave", G_CALLBACK(on_marker_leave), NULL);
111 //g_signal_connect(test->marker, "button-press", G_CALLBACK(on_marker_button), NULL);
112 (void)on_marker_enter;
113 (void)on_marker_leave;
114 (void)on_marker_button;
117 void _load_poly(GritsPluginTest *test)
119 test->poly = grits_poly_parse("35,-90 35,-110 45,-110 45,-90", "\t", " ", ",");
120 test->poly->color[0] = test->poly->border[0] = 1;
121 test->poly->color[1] = test->poly->border[1] = 0;
122 test->poly->color[2] = test->poly->border[2] = 0;
123 test->poly->color[3] = 0.2;
124 test->poly->border[3] = 1;
125 test->poly->width = 6;
126 grits_viewer_add(test->viewer, GRITS_OBJECT(test->poly), GRITS_LEVEL_OVERLAY, TRUE);
127 g_signal_connect(test->poly, "enter", G_CALLBACK(on_poly_enter), NULL);
128 g_signal_connect(test->poly, "leave", G_CALLBACK(on_poly_leave), NULL);
129 g_signal_connect(test->poly, "button-press", G_CALLBACK(on_poly_button), NULL);
130 g_signal_connect(test->poly, "key-press", G_CALLBACK(on_poly_key), NULL);
134 * grits_plugin_test_new:
135 * @viewer: the #GritsViewer to use for drawing
137 * Create a new instance of the testing plugin.
139 * Returns: the new #GritsPluginTest
141 GritsPluginTest *grits_plugin_test_new(GritsViewer *viewer)
143 g_debug("GritsPluginTest: new");
144 GritsPluginTest *test = g_object_new(GRITS_TYPE_PLUGIN_TEST, NULL);
145 test->viewer = g_object_ref(viewer);
156 static void grits_plugin_test_plugin_init(GritsPluginInterface *iface);
157 G_DEFINE_TYPE_WITH_CODE(GritsPluginTest, grits_plugin_test, G_TYPE_OBJECT,
158 G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN,
159 grits_plugin_test_plugin_init));
160 static void grits_plugin_test_plugin_init(GritsPluginInterface *iface)
162 g_debug("GritsPluginTest: plugin_init");
163 /* Add methods to the interface */
165 /* Class/Object init */
166 static void grits_plugin_test_init(GritsPluginTest *test)
168 g_debug("GritsPluginTest: init");
170 static void grits_plugin_test_dispose(GObject *_test)
172 g_debug("GritsPluginTest: dispose");
173 GritsPluginTest *test = GRITS_PLUGIN_TEST(_test);
175 grits_viewer_remove(test->viewer, GRITS_OBJECT(test->marker));
176 g_object_unref(test->viewer);
179 G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test);
181 static void grits_plugin_test_class_init(GritsPluginTestClass *klass)
183 g_debug("GritsPluginTest: class_init");
184 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
185 gobject_class->dispose = grits_plugin_test_dispose;