+
+
+/****************
+ * GObject code *
+ ****************/
+G_DEFINE_TYPE(GisOpenGL, gis_opengl, GTK_TYPE_DRAWING_AREA);
+static void gis_opengl_init(GisOpenGL *self)
+{
+ g_debug("GisOpenGL: init");
+ /* OpenGL setup */
+ GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(
+ GDK_GL_MODE_RGBA | GDK_GL_MODE_DEPTH |
+ GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA);
+ if (!glconfig)
+ g_error("Failed to create glconfig");
+ if (!gtk_widget_set_gl_capability(GTK_WIDGET(self),
+ glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
+ g_error("GL lacks required capabilities");
+ g_object_unref(glconfig);
+
+ gtk_widget_set_size_request(GTK_WIDGET(self), 600, 550);
+ gtk_widget_set_events(GTK_WIDGET(self),
+ GDK_BUTTON_PRESS_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_KEY_PRESS_MASK);
+ g_object_set(self, "can-focus", TRUE, NULL);
+
+#ifndef ROAM_DEBUG
+ self->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33, (GSourceFunc)on_idle, self, NULL);
+ self->sm_source[1] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+10, 500, (GSourceFunc)on_idle, self, NULL);
+#endif
+
+ g_signal_connect(self, "realize", G_CALLBACK(on_realize), NULL);
+ g_signal_connect(self, "configure-event", G_CALLBACK(on_configure), NULL);
+ g_signal_connect(self, "expose-event", G_CALLBACK(on_expose), NULL);
+
+ g_signal_connect(self, "button-press-event", G_CALLBACK(on_button_press), NULL);
+ g_signal_connect(self, "enter-notify-event", G_CALLBACK(on_button_press), NULL);
+ g_signal_connect(self, "key-press-event", G_CALLBACK(on_key_press), NULL);
+}
+static GObject *gis_opengl_constructor(GType gtype, guint n_properties,
+ GObjectConstructParam *properties)
+{
+ g_debug("GisOpengl: constructor");
+ GObjectClass *parent_class = G_OBJECT_CLASS(gis_opengl_parent_class);
+ return parent_class->constructor(gtype, n_properties, properties);
+}
+static void gis_opengl_dispose(GObject *_self)
+{
+ g_debug("GisOpenGL: dispose");
+ GisOpenGL *self = GIS_OPENGL(_self);
+ if (self->sm_source[0]) {
+ g_source_remove(self->sm_source[0]);
+ self->sm_source[0] = 0;
+ }
+ if (self->sm_source[1]) {
+ g_source_remove(self->sm_source[1]);
+ self->sm_source[1] = 0;
+ }
+ if (self->sphere) {
+ roam_sphere_free(self->sphere);
+ self->sphere = NULL;
+ }
+ if (self->world) {
+ g_object_unref(self->world);
+ self->world = NULL;
+ }
+ if (self->view) {
+ g_object_unref(self->view);
+ self->view = NULL;
+ }
+ G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_self);
+}
+static void gis_opengl_finalize(GObject *_self)
+{
+ g_debug("GisOpenGL: finalize");
+ GisOpenGL *self = GIS_OPENGL(_self);
+ G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_self);
+}
+static void gis_opengl_class_init(GisOpenGLClass *klass)
+{
+ g_debug("GisOpenGL: class_init");
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->constructor = gis_opengl_constructor;
+ gobject_class->dispose = gis_opengl_dispose;
+ gobject_class->finalize = gis_opengl_finalize;
+}