X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=examples%2Fplugin%2Fteapot.c;h=445c15771aeb584221bd5056f428ec20bc4b3b44;hp=9ecfd88cd21d3c7d3c2bb56f38c2cc3605aa7d21;hb=c2e39b9d64035038a19d753129cc2124b4ed1382;hpb=ac7156bd84aef88b712f117f7e2f3d847d371719 diff --git a/examples/plugin/teapot.c b/examples/plugin/teapot.c index 9ecfd88..445c157 100644 --- a/examples/plugin/teapot.c +++ b/examples/plugin/teapot.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 @@ -18,7 +18,7 @@ #include #include -#include +#include #include "teapot.h" @@ -30,31 +30,12 @@ static gboolean rotate(gpointer _self) GisPluginTeapot *self = _self; if (gtk_toggle_button_get_active(self->button)) { self->rotation += 1.0; - gis_opengl_redraw(self->opengl); + gtk_widget_queue_draw(GTK_WIDGET(self->viewer)); } return TRUE; } - -/*********** - * Methods * - ***********/ -GisPluginTeapot *gis_plugin_teapot_new(GisWorld *world, GisView *view, GisOpenGL *opengl) -{ - g_debug("GisPluginTeapot: new"); - GisPluginTeapot *self = g_object_new(GIS_TYPE_PLUGIN_TEAPOT, NULL); - self->opengl = opengl; - - return self; -} - -static GtkWidget *gis_plugin_teapot_get_config(GisPlugin *_self) -{ - GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self); - return GTK_WIDGET(self->button); -} - -static void gis_plugin_teapot_expose(GisPlugin *_self) +static gpointer expose(GisCallback *callback, gpointer _self) { GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self); g_debug("GisPluginTeapot: expose"); @@ -79,6 +60,31 @@ static void gis_plugin_teapot_expose(GisPlugin *_self) glColor4f(0.9, 0.9, 0.7, 1.0); glDisable(GL_CULL_FACE); gdk_gl_draw_teapot(TRUE, 0.25); + + return NULL; +} + + +/*********** + * Methods * + ***********/ +GisPluginTeapot *gis_plugin_teapot_new(GisViewer *viewer, GisPrefs *prefs) +{ + g_debug("GisPluginTeapot: new"); + GisPluginTeapot *self = g_object_new(GIS_TYPE_PLUGIN_TEAPOT, NULL); + self->viewer = viewer; + + /* Add renderers */ + GisCallback *callback = gis_callback_new(expose, self); + gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_WORLD, 0); + + return self; +} + +static GtkWidget *gis_plugin_teapot_get_config(GisPlugin *_self) +{ + GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(_self); + return GTK_WIDGET(self->button); } @@ -94,7 +100,6 @@ static void gis_plugin_teapot_plugin_init(GisPluginInterface *iface) { g_debug("GisPluginTeapot: plugin_init"); /* Add methods to the interface */ - iface->expose = gis_plugin_teapot_expose; iface->get_config = gis_plugin_teapot_get_config; } /* Class/Object init */ @@ -105,7 +110,6 @@ static void gis_plugin_teapot_init(GisPluginTeapot *self) self->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate")); self->rotate_id = g_timeout_add(1000/60, rotate, self); self->rotation = 30.0; - self->opengl = NULL; } static void gis_plugin_teapot_dispose(GObject *gobject) { @@ -115,18 +119,9 @@ static void gis_plugin_teapot_dispose(GObject *gobject) /* Drop references */ G_OBJECT_CLASS(gis_plugin_teapot_parent_class)->dispose(gobject); } -static void gis_plugin_teapot_finalize(GObject *gobject) -{ - g_debug("GisPluginTeapot: finalize"); - GisPluginTeapot *self = GIS_PLUGIN_TEAPOT(gobject); - /* Free data */ - G_OBJECT_CLASS(gis_plugin_teapot_parent_class)->finalize(gobject); - -} static void gis_plugin_teapot_class_init(GisPluginTeapotClass *klass) { g_debug("GisPluginTeapot: class_init"); GObjectClass *gobject_class = (GObjectClass*)klass; gobject_class->dispose = gis_plugin_teapot_dispose; - gobject_class->finalize = gis_plugin_teapot_finalize; }