Converting a lot of stuff to GObject and adding gtk-doc support
authorAndy Spencer <andy753421@gmail.com>
Sat, 9 May 2009 09:20:59 +0000 (09:20 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 9 May 2009 09:20:59 +0000 (09:20 +0000)
21 files changed:
Makefile.am
autogen.sh
configure.ac
docs/Makefile.am [new file with mode: 0644]
docs/api/Makefile.am [new file with mode: 0644]
src/Makefile.am
src/aweather-gui.c [new file with mode: 0644]
src/aweather-gui.h [new file with mode: 0644]
src/aweather-plugin.c [moved from src/aweather.h with 100% similarity]
src/aweather-plugin.h [new file with mode: 0644]
src/aweather-view.c [new file with mode: 0644]
src/aweather-view.h [new file with mode: 0644]
src/main.c [moved from src/aweather.c with 54% similarity]
src/opengl.c
src/opengl.h
src/plugin-example.c
src/plugin-example.h
src/plugin-radar.c
src/plugin-radar.h
src/plugin-ridge.c
src/plugin-ridge.h

index 39555ef..7f458d8 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = data src
+SUBDIRS = src data docs
 
 test: all
        LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \
index 6a30e13..52c7bc9 100755 (executable)
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+gtkdocize
 aclocal
 autoheader
 automake -a -c
index 73b7685..6f9aedf 100644 (file)
@@ -6,9 +6,10 @@ AC_CONFIG_HEADERS([config.h])
 # Check for required programs
 AC_PROG_CC
 PKG_PROG_PKG_CONFIG
+GTK_DOC_CHECK(1.9)
 
 # Check for required packages
-PKG_CHECK_MODULES(GTK,  gtk+-2.0 gmodule-export-2.0 gtkglext-1.0)
+PKG_CHECK_MODULES(GTK,  gtk+-2.0 gtkglext-1.0 gmodule-export-2.0 gobject-2.0)
 PKG_CHECK_MODULES(CURL, libcurl)
 
 # Define odd RSL install location
@@ -18,7 +19,9 @@ AC_SUBST(RSL_LIBS,   "-L/usr/local/trmm/GVBOX/lib/ -lrsl")
 # Output 
 AC_CONFIG_FILES([
        Makefile
-       data/Makefile
        src/Makefile
+       data/Makefile
+       docs/Makefile
+       docs/api/Makefile
 ])
 AC_OUTPUT
diff --git a/docs/Makefile.am b/docs/Makefile.am
new file mode 100644 (file)
index 0000000..e998555
--- /dev/null
@@ -0,0 +1,4 @@
+SUBDIRS = api
+
+maintainer-clean-local:
+       rm -f Makefile.in
diff --git a/docs/api/Makefile.am b/docs/api/Makefile.am
new file mode 100644 (file)
index 0000000..755262f
--- /dev/null
@@ -0,0 +1,17 @@
+AM_CPPFLAGS=$(GTK_CFLAGS)
+GTKDOC_LIBS=$(GTK_LIBS) $(RSL_LIBS) $(CURL_LIBS) \
+       ../../src/aweather-gui.o \
+       ../../src/aweather-view.o \
+       ../../src/location.o \
+       ../../src/opengl.o \
+       ../../src/plugin-example.o \
+       ../../src/plugin-radar.o \
+       ../../src/plugin-ridge.o
+DOC_MODULE=aweather
+DOC_SOURCE_DIR=../../src/
+DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
+MKDB_OPTIONS=--sgml-mode --output-format=xml
+include $(top_srcdir)/gtk-doc.make
+maintainer-clean-local:
+       rm -f Makefile.in aweather-docs.sgml aweather-overrides.txt aweather.types
+       rm -rf html/ tmpl/ 
index 8940848..4454da8 100644 (file)
@@ -3,8 +3,9 @@ AM_CFLAGS    = -O3 -Wall -Werror --std=gnu99
 AM_LDFLAGS   = -Wl,--export-dynamic
 bin_PROGRAMS = aweather
 
-aweather_SOURCES  = \
-       aweather.c       aweather.h       \
+aweather_SOURCES  = main.c \
+       aweather-gui.c   aweather-gui.h   \
+       aweather-view.c  aweather-view.h  \
        location.c       location.h       \
        opengl.c         opengl.h         \
        plugin-radar.c   plugin-radar.h   \
@@ -16,3 +17,7 @@ aweather_LDADD    = $(RSL_LIBS) $(GTK_LIBS) $(CURL_LIBS)
 test: all
        LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \
        ./aweather
+
+debug: all
+       LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \
+       gdb ./aweather
diff --git a/src/aweather-gui.c b/src/aweather-gui.c
new file mode 100644 (file)
index 0000000..99b950e
--- /dev/null
@@ -0,0 +1,114 @@
+#include <config.h>
+#include <gtk/gtk.h>
+#include <gtk/gtkgl.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "aweather-gui.h"
+#include "aweather-view.h"
+
+/****************
+ * GObject code *
+ ****************/
+G_DEFINE_TYPE(AWeatherGui, aweather_gui, G_TYPE_OBJECT);
+
+/* Constructor / destructors */
+static void aweather_gui_init(AWeatherGui *gui)
+{
+       g_message("aweather_gui_init");
+       /* Default values */
+       gui->view    = NULL;
+       gui->builder = NULL;
+       gui->window  = NULL;
+       gui->tabs    = NULL;
+       gui->drawing = NULL;
+}
+
+static GObject *aweather_gui_constructor(GType gtype, guint n_properties,
+               GObjectConstructParam *properties)
+{
+       g_message("aweather_gui_constructor");
+       GObjectClass *parent_class = G_OBJECT_CLASS(aweather_gui_parent_class);
+       return  parent_class->constructor(gtype, n_properties, properties);
+}
+
+static void aweather_gui_dispose (GObject *gobject)
+{
+       g_message("aweather_gui_dispose");
+       AWeatherGui *gui = AWEATHER_GUI(gobject);
+       g_object_unref(gui->view   );
+       g_object_unref(gui->builder);
+       g_object_unref(gui->window );
+       g_object_unref(gui->tabs   );
+       g_object_unref(gui->drawing);
+       G_OBJECT_CLASS(aweather_gui_parent_class)->dispose(gobject);
+}
+
+static void aweather_gui_finalize(GObject *gobject)
+{
+       g_message("aweather_gui_finalize");
+       G_OBJECT_CLASS(aweather_gui_parent_class)->finalize(gobject);
+}
+
+static void aweather_gui_class_init(AWeatherGuiClass *klass)
+{
+       g_message("aweather_gui_class_init");
+       GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+       gobject_class->constructor  = aweather_gui_constructor;
+       gobject_class->dispose      = aweather_gui_dispose;
+       gobject_class->finalize     = aweather_gui_finalize;
+}
+
+/* Methods */
+AWeatherGui *aweather_gui_new()
+{
+       g_message("aweather_gui_new");
+       GError *error = NULL;
+
+       AWeatherGui *gui = g_object_new(AWEATHER_TYPE_GUI, NULL);
+
+       gui->builder = gtk_builder_new();
+       if (!gtk_builder_add_from_file(gui->builder, DATADIR "/aweather/aweather.xml", &error))
+               g_error("Failed to create gtk builder: %s", error->message);
+       gui->view    = aweather_view_new();
+       gui->window  = GTK_WINDOW      (gtk_builder_get_object(gui->builder, "window"));
+       gui->tabs    = GTK_NOTEBOOK    (gtk_builder_get_object(gui->builder, "tabs")); 
+       gui->drawing = GTK_DRAWING_AREA(gtk_builder_get_object(gui->builder, "drawing"));
+       gtk_builder_connect_signals(gui->builder, NULL);
+       return gui;
+}
+AWeatherView *aweather_gui_get_view(AWeatherGui *gui)
+{
+       return gui->view;
+}
+GtkBuilder *aweather_gui_get_builder(AWeatherGui *gui)
+{
+       return gui->builder;
+}
+GtkWindow *aweather_gui_get_window(AWeatherGui *gui)
+{
+       return gui->window;
+}
+GtkNotebook *aweather_gui_get_tabs(AWeatherGui *gui)
+{
+       return gui->tabs;
+}
+GtkDrawingArea *aweather_gui_get_drawing(AWeatherGui *gui)
+{
+       return gui->drawing;
+}
+
+//void aweather_gui_register_plugin(AWeatherGui *gui, AWeatherPlugin *plugin);
+
+/************************
+ * GtkBuilder callbacks *
+ ************************/
+gboolean on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
+{
+       if (event->keyval == GDK_q)
+               gtk_main_quit();
+       return TRUE;
+}
+
+void on_site_changed() {
+       g_message("site changed");
+}
diff --git a/src/aweather-gui.h b/src/aweather-gui.h
new file mode 100644 (file)
index 0000000..5d153ee
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef __AWEATHER_GUI_H__
+#define __AWEATHER_GUI_H__
+
+#include <gtk/gtk.h>
+#include <glib-object.h>
+#include "aweather-view.h"
+
+/* Type macros */
+#define AWEATHER_TYPE_GUI            (aweather_gui_get_type())
+#define AWEATHER_GUI(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   AWEATHER_TYPE_GUI, AWeatherGui))
+#define AWEATHER_IS_GUI(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   AWEATHER_TYPE_GUI))
+#define AWEATHER_GUI_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), AWEATHER_TYPE_GUI, AWeatherGuiClass))
+#define AWEATHER_IS_GUI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), AWEATHER_TYPE_GUI))
+#define AWEATHER_GUI_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   AWEATHER_TYPE_GUI, AWeatherGuiClass))
+
+typedef struct _AWeatherGui      AWeatherGui;
+typedef struct _AWeatherGuiClass AWeatherGuiClass;
+
+struct _AWeatherGui {
+       GObject parent_instance;
+
+       /* instance members */
+       AWeatherView   *view;
+       GtkBuilder     *builder;
+       GtkWindow      *window;
+       GtkNotebook    *tabs;
+       GtkDrawingArea *drawing;
+};
+
+struct _AWeatherGuiClass {
+       GObjectClass parent_class;
+       
+       /* class members */
+};
+
+GType aweather_gui_get_type(void);
+
+/* Methods */
+AWeatherGui    *aweather_gui_new();
+AWeatherView   *aweather_gui_get_view(AWeatherGui *gui);
+GtkBuilder     *aweather_gui_get_builder(AWeatherGui *gui);
+GtkWindow      *aweather_gui_get_window(AWeatherGui *gui);
+GtkNotebook    *aweather_gui_get_tabs(AWeatherGui *gui);
+GtkDrawingArea *aweather_gui_get_drawing(AWeatherGui *gui);
+
+//void aweather_gui_register_plugin(AWeatherGui *gui, AWeatherPlugin *plugin);
+
+#endif
similarity index 100%
rename from src/aweather.h
rename to src/aweather-plugin.c
diff --git a/src/aweather-plugin.h b/src/aweather-plugin.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/aweather-view.c b/src/aweather-view.c
new file mode 100644 (file)
index 0000000..c8fc01b
--- /dev/null
@@ -0,0 +1,156 @@
+#include <glib.h>
+
+#include "aweather-view.h"
+
+G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
+
+enum {
+       PROP_0,
+       PROP_TIME,
+       PROP_LOCATION,
+};
+
+enum {
+       SIG_TIME_CHANGED,
+       SIG_LOCATION_CHANGED,
+       NUM_SIGNALS,
+};
+
+static guint signals[NUM_SIGNALS];
+
+/* Constructor / destructors */
+static void aweather_view_init(AWeatherView *self)
+{
+       g_message("aweather_view_init");
+       /* Default values */
+       self->time     = 0;
+       self->location = g_strdup("IND");
+}
+
+static GObject *aweather_view_constructor(GType gtype, guint n_properties,
+               GObjectConstructParam *properties)
+{
+       g_message("aweather_view_constructor");
+       GObjectClass *parent_class = G_OBJECT_CLASS(aweather_view_parent_class);
+       return  parent_class->constructor(gtype, n_properties, properties);
+}
+
+static void aweather_view_dispose (GObject *gobject)
+{
+       g_message("aweather_view_dispose");
+       /* Drop references to other GObjects */
+       G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
+}
+
+static void aweather_view_finalize(GObject *gobject)
+{
+       g_message("aweather_view_finalize");
+       AWeatherView *self = AWEATHER_VIEW(gobject);
+       g_free(self->location);
+       G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
+}
+
+static void aweather_view_set_property(GObject *object, guint property_id,
+               const GValue *value, GParamSpec *pspec)
+{
+       g_message("aweather_view_set_property");
+       AWeatherView *self = AWEATHER_VIEW(object);
+       switch (property_id) {
+       case PROP_TIME:     aweather_view_set_time    (self, g_value_get_int   (value)); break;
+       case PROP_LOCATION: aweather_view_set_location(self, g_value_get_string(value)); break;
+       default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+       }
+}
+
+static void aweather_view_get_property(GObject *object, guint property_id,
+               GValue *value, GParamSpec *pspec)
+{
+       g_message("aweather_view_get_property");
+       AWeatherView *self = AWEATHER_VIEW(object);
+       switch (property_id) {
+       case PROP_TIME:     g_value_set_int   (value, aweather_view_get_time    (self)); break;
+       case PROP_LOCATION: g_value_set_string(value, aweather_view_get_location(self)); break;
+       default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+       }
+}
+
+static void aweather_view_class_init(AWeatherViewClass *klass)
+{
+       g_message("aweather_view_class_init");
+       GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+       gobject_class->constructor  = aweather_view_constructor;
+       gobject_class->dispose      = aweather_view_dispose;
+       gobject_class->finalize     = aweather_view_finalize;
+       gobject_class->get_property = aweather_view_get_property;
+       gobject_class->set_property = aweather_view_set_property;
+       g_object_class_install_property(gobject_class, PROP_TIME,
+               g_param_spec_int(
+                       "time",
+                       "time of the current frame",
+                       "(format unknown)", 
+                       G_MININT32, G_MAXINT32, 0,
+                       G_PARAM_READWRITE));
+       g_object_class_install_property(gobject_class, PROP_LOCATION,
+               g_param_spec_pointer(
+                       "location",
+                       "location seen by the viewport",
+                       "Location of the viewport. Currently this is the name of the radar site.", 
+                       G_PARAM_READWRITE));
+       signals[SIG_TIME_CHANGED] = g_signal_new(
+                       "time-changed",
+                       G_TYPE_FROM_CLASS(gobject_class),
+                       G_SIGNAL_RUN_LAST,
+                       0,
+                       NULL,
+                       NULL,
+                       g_cclosure_marshal_VOID__INT,
+                       G_TYPE_NONE,
+                       1,
+                       G_TYPE_INT);
+       signals[SIG_LOCATION_CHANGED] = g_signal_new(
+                       "location-changed",
+                       G_TYPE_FROM_CLASS(gobject_class),
+                       G_SIGNAL_RUN_LAST,
+                       0,
+                       NULL,
+                       NULL,
+                       g_cclosure_marshal_VOID__STRING,
+                       G_TYPE_NONE,
+                       1,
+                       G_TYPE_GSTRING);
+
+}
+
+/* Methods */
+AWeatherView *aweather_view_new()
+{
+       g_message("aweather_view_new");
+       return g_object_new(AWEATHER_TYPE_VIEW, NULL);
+}
+
+void aweather_view_set_time(AWeatherView *view, int time)
+{
+       g_message("aweather_view_set_time");
+       view->time = time;
+       g_signal_emit(view, signals[SIG_TIME_CHANGED], 0, time);
+}
+
+int aweather_view_get_time(AWeatherView *view)
+{
+       g_message("aweather_view_get_time");
+       return view->time;
+}
+
+void aweather_view_set_location(AWeatherView *view, const gchar *location)
+{
+       g_message("aweather_view_set_location");
+       g_free(view->location);
+       view->location = g_strdup(location);
+       g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, view->location);
+}
+
+gchar *aweather_view_get_location(AWeatherView *view)
+{
+       g_message("aweather_view_get_location");
+       return view->location;
+}
diff --git a/src/aweather-view.h b/src/aweather-view.h
new file mode 100644 (file)
index 0000000..0dc58fd
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __AWEATHER_VIEW_H__
+#define __AWEATHER_VIEW_H__
+
+#include <glib-object.h>
+
+/* Type macros */
+#define AWEATHER_TYPE_VIEW            (aweather_view_get_type())
+#define AWEATHER_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   AWEATHER_TYPE_VIEW, AWeatherView))
+#define AWEATHER_IS_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   AWEATHER_TYPE_VIEW))
+#define AWEATHER_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), AWEATHER_TYPE_VIEW, AWeatherViewClass))
+#define AWEATHER_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), AWEATHER_TYPE_VIEW))
+#define AWEATHER_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   AWEATHER_TYPE_VIEW, AWeatherViewClass))
+
+typedef struct _AWeatherView      AWeatherView;
+typedef struct _AWeatherViewClass AWeatherViewClass;
+
+struct _AWeatherView {
+       GObject parent_instance;
+
+       /* instance members */
+       gint   time;
+       gchar *location;
+};
+
+struct _AWeatherViewClass {
+       GObjectClass parent_class;
+       
+       /* class members */
+};
+
+GType aweather_view_get_type(void);
+
+/* Methods */
+AWeatherView *aweather_view_new();
+void aweather_view_set_time(AWeatherView *view, gint time);
+gint aweather_view_get_time(AWeatherView *view);
+
+void aweather_view_set_location(AWeatherView *view, const gchar *location);
+gchar *aweather_view_get_location(AWeatherView *view);
+
+#endif
similarity index 54%
rename from src/aweather.c
rename to src/main.c
index f6f4341..c598223 100644 (file)
@@ -1,28 +1,14 @@
 #include <config.h>
 #include <gtk/gtk.h>
 #include <gtk/gtkgl.h>
-#include <gdk/gdkkeysyms.h>
 
+#include "aweather-gui.h"
 #include "location.h"
 #include "opengl.h"
 #include "plugin-radar.h"
 #include "plugin-ridge.h"
 #include "plugin-example.h"
 
-/************************
- * GtkBuilder callbacks *
- ************************/
-gboolean on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
-{
-       if (event->keyval == GDK_q)
-               gtk_main_quit();
-       return TRUE;
-}
-
-void on_site_changed() {
-       g_message("site changed");
-}
-
 /*****************
  * Setup helpers *
  *****************/
@@ -33,7 +19,7 @@ static void combo_sensitive(GtkCellLayout *cell_layout, GtkCellRenderer *cell,
        g_object_set(cell, "sensitive", sensitive, NULL);
 }
 
-static void site_setup(GtkBuilder *builder)
+static void site_setup(AWeatherGui *gui)
 {
        GtkTreeIter state, city;
        GtkTreeStore *store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
@@ -49,6 +35,7 @@ static void site_setup(GtkBuilder *builder)
                }
        }
 
+       GtkBuilder      *builder  = aweather_gui_get_builder(gui);
        GtkWidget       *combo    = GTK_WIDGET(gtk_builder_get_object(builder, "site"));
        GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE);
@@ -61,11 +48,12 @@ static void site_setup(GtkBuilder *builder)
        //gtk_box_pack_start(GTK_BOX(selectors), loc_sel,  FALSE, FALSE, 0);
 }
 
-static void time_setup(GtkBuilder *builder)
+static void time_setup(AWeatherGui *gui)
 {
-       GtkWidget         *view = GTK_WIDGET(gtk_builder_get_object(builder, "time"));
-       GtkCellRenderer   *rend = gtk_cell_renderer_text_new();
-       GtkTreeViewColumn *col  = gtk_tree_view_column_new_with_attributes(
+       GtkBuilder        *builder = aweather_gui_get_builder(gui);
+       GtkWidget         *view    = GTK_WIDGET(gtk_builder_get_object(builder, "time"));
+       GtkCellRenderer   *rend    = gtk_cell_renderer_text_new();
+       GtkTreeViewColumn *col     = gtk_tree_view_column_new_with_attributes(
                                        "Time", rend, 0, "text", NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
 
@@ -82,36 +70,20 @@ int main(int argc, char *argv[])
        gtk_init(&argc, &argv);
        gtk_gl_init(&argc, &argv);
 
-       GError *error = NULL;
-       GtkBuilder *builder = gtk_builder_new();
-       if (!gtk_builder_add_from_file(builder, DATADIR "/aweather/aweather.xml", &error))
-               g_error("Failed to create gtk builder: %s", error->message);
-       gtk_builder_connect_signals(builder, NULL);
-
-       GtkWidget  *window  = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
-       GtkWidget  *drawing = GTK_WIDGET(gtk_builder_get_object(builder, "drawing"));
-       GtkWidget  *tabs    = GTK_WIDGET(gtk_builder_get_object(builder, "tabs"));
-
-       /* Set up darwing area */
-       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(drawing, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
-               g_error("GL lacks required capabilities");
+       /* Set up AWeather */
+       AWeatherGui *gui = aweather_gui_new();
 
        /* Load components */
-       site_setup(builder);
-       time_setup(builder);
-       opengl_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tabs));
+       site_setup(gui);
+       time_setup(gui);
+       opengl_init(gui);
 
        /* Load plugins */
-       radar_init  (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tabs));
-       ridge_init  (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tabs));
-       example_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tabs));
+       radar_init  (gui);
+        ridge_init  (gui);
+       example_init(gui);
 
-       gtk_widget_show_all(window);
+       gtk_widget_show_all(GTK_WIDGET(aweather_gui_get_window(gui)));
        gtk_main();
 
        return 0;
index e9d4a7e..c6a3b28 100644 (file)
@@ -5,6 +5,8 @@
 #include <GL/gl.h>
 #include <GL/glu.h>
 
+#include "aweather-gui.h"
+
 static gboolean expose_start(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 {
        g_message("opengl:expose_start");
@@ -37,6 +39,7 @@ static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, gpointer user_d
 }
 static gboolean configure_start(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
 {
+       g_message("opengl:configure_start");
        GdkGLContext  *glcontext  = gtk_widget_get_gl_context(da);
        GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
 
@@ -83,13 +86,24 @@ static gboolean configure_start(GtkWidget *da, GdkEventConfigure *event, gpointe
 }
 static gboolean configure_end(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
 {
+       g_message("opengl:configure_end");
        GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
        gdk_gl_drawable_gl_end(gldrawable);
        return FALSE;
 }
 
-gboolean opengl_init(GtkDrawingArea *drawing, GtkNotebook *config)
+gboolean opengl_init(AWeatherGui *gui)
 {
+       GtkDrawingArea *drawing = aweather_gui_get_drawing(gui);
+
+       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(drawing), glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
+               g_error("GL lacks required capabilities");
+
        /* Set up OpenGL Stuff */
        g_signal_connect      (drawing, "configure-event", G_CALLBACK(configure_start), NULL);
        g_signal_connect_after(drawing, "configure-event", G_CALLBACK(configure_end),   NULL);
index f0a631b..96637dd 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef OPENGL_H
 #define OPENGL_H
 
-gboolean opengl_init(GtkDrawingArea *drawing, GtkNotebook *config);
+gboolean opengl_init(AWeatherGui *gui);
 
 #endif
index bab69c4..16dbdd3 100644 (file)
@@ -3,15 +3,19 @@
 #include <gtk/gtkgl.h>
 #include <GL/gl.h>
 
+#include "aweather-gui.h"
+
 static GtkWidget *rotate_button;
 
 static float ang = 30.;
 
 static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 {
-       glPushMatrix();
        glDisable(GL_TEXTURE_2D);
-       glLoadIdentity();
+       glMatrixMode(GL_MODELVIEW ); glPushMatrix(); glLoadIdentity();
+       glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
+       //glOrtho(-1,1,-1,1,-10,10);
+
        glTranslatef(0.5, -0.5, -2);
 
        float light_ambient[]  = {0.1f, 0.1f, 0.0f};
@@ -34,7 +38,8 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
 
-       glPopMatrix();
+        glMatrixMode(GL_PROJECTION); glPopMatrix(); 
+       glMatrixMode(GL_MODELVIEW ); glPopMatrix();
        return FALSE;
 }
 
@@ -53,8 +58,11 @@ static gboolean rotate(gpointer user_data)
        return TRUE;
 }
 
-gboolean example_init(GtkDrawingArea *drawing, GtkNotebook *config)
+gboolean example_init(AWeatherGui *gui)
 {
+       GtkDrawingArea *drawing = aweather_gui_get_drawing(gui);
+       GtkNotebook    *config  = aweather_gui_get_tabs(gui);
+
        /* Add configuration tab */
        GtkWidget *label = gtk_label_new("example");
        rotate_button = gtk_toggle_button_new_with_label("Rotate");
index a896e64..85aa2d2 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef EXAMPLE_H
 #define EXAMPLE_H
 
-gboolean example_init(GtkDrawingArea *drawing, GtkNotebook *config);
+gboolean example_init(AWeatherGui *gui);
 
 #endif
index 6adcfa9..0722edd 100644 (file)
@@ -1,10 +1,12 @@
 #include <config.h>
 #include <gtk/gtk.h>
+#include <gtk/gtkgl.h>
 #include <GL/gl.h>
 #include <math.h>
 
 #include "rsl.h"
 
+#include "aweather-gui.h"
 #include "plugin-radar.h"
 
 GtkWidget *drawing;
@@ -102,6 +104,7 @@ static void load_sweep(Sweep *sweep)
 /* Load the default sweep */
 static gboolean configure(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
 {
+       g_message("radar:configure");
        Sweep *first = (Sweep*)user_data;
        if (cur_sweep == NULL)
                load_sweep(first);
@@ -157,28 +160,29 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        //glEnd();
 
        /* Print the color table */
-       //glDisable(GL_TEXTURE_2D);
-       //glMatrixMode(GL_MODELVIEW ); glPushMatrix(); glLoadIdentity();
-       //glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
-       //glBegin(GL_QUADS);
-       //int i;
-       //for (i = 0; i < nred; i++) {
-       //      glColor4ub(red[i], green[i], blue[i], get_alpha(i));
-       //      glVertex3f(-1.0, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot left
-       //      glVertex3f(-1.0, (float)((i+1) - nred/2)/(nred/2), 0.0); // top left
-       //      glVertex3f(-0.9, (float)((i+1) - nred/2)/(nred/2), 0.0); // top right
-       //      glVertex3f(-0.9, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot right
-       //}
-       //glEnd();
-        //glMatrixMode(GL_PROJECTION); glPopMatrix(); 
-       //glMatrixMode(GL_MODELVIEW ); glPopMatrix();
+       glDisable(GL_TEXTURE_2D);
+       glMatrixMode(GL_MODELVIEW ); glPushMatrix(); glLoadIdentity();
+       glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
+       glBegin(GL_QUADS);
+       int i;
+       for (i = 0; i < nred; i++) {
+               glColor4ub(red[i], green[i], blue[i], get_alpha(i));
+               glVertex3f(-1.0, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot left
+               glVertex3f(-1.0, (float)((i+1) - nred/2)/(nred/2), 0.0); // top left
+               glVertex3f(-0.9, (float)((i+1) - nred/2)/(nred/2), 0.0); // top right
+               glVertex3f(-0.9, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot right
+       }
+       glEnd();
+        glMatrixMode(GL_PROJECTION); glPopMatrix(); 
+       glMatrixMode(GL_MODELVIEW ); glPopMatrix();
 
        return FALSE;
 }
 
-gboolean radar_init(GtkDrawingArea *_drawing, GtkNotebook *config)
+gboolean radar_init(AWeatherGui *gui)
 {
-       drawing = GTK_WIDGET(_drawing);
+       drawing = GTK_WIDGET(aweather_gui_get_drawing(gui));
+       GtkNotebook    *config  = aweather_gui_get_tabs(gui);
 
        /* Parse hard coded file.. */
        RSL_read_these_sweeps("all", NULL);
index d6e85b2..9e293ec 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef RADAR_H
 #define RADAR_H
 
-gboolean radar_init(GtkDrawingArea *drawing, GtkNotebook *config);
+gboolean radar_init(AWeatherGui *gui);
 
 #endif
index 3e08d00..cede4f4 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <stdio.h>
 
+#include "aweather-gui.h"
+
 enum {
        LAYER_TOPO,
        LAYER_COUNTY,
@@ -129,8 +131,10 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, gpointer user
        return FALSE;
 }
 
-gboolean ridge_init(GtkDrawingArea *drawing, GtkNotebook *config)
+gboolean ridge_init(AWeatherGui *gui)
 {
+       GtkDrawingArea *drawing = aweather_gui_get_drawing(gui);
+
        /* Set up OpenGL Stuff */
        g_signal_connect(drawing, "expose-event",    G_CALLBACK(expose),    NULL);
        g_signal_connect(drawing, "configure-event", G_CALLBACK(configure), NULL);
index 62e69de..46f611b 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef RIDGE_H
 #define RIDGE_H
 
-gboolean ridge_init(GtkDrawingArea *drawing, GtkNotebook *config);
+gboolean ridge_init(AWeatherGui *gui);
 
 #endif