]> Pileus Git - aweather/commitdiff
Converting Ridge and Radar plugins to use GObject
authorAndy Spencer <andy753421@gmail.com>
Sun, 24 May 2009 08:15:06 +0000 (08:15 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 24 May 2009 08:15:06 +0000 (08:15 +0000)
12 files changed:
TODO
docs/api/Makefile.am
docs/api/aweather-sections.txt [new file with mode: 0644]
src/Makefile.am
src/aweather-gui.c
src/main.c
src/plugin-example.c
src/plugin-example.h
src/plugin-radar.c
src/plugin-radar.h
src/plugin-ridge.c
src/plugin-ridge.h

diff --git a/TODO b/TODO
index 94e5c6c2b064ee7609e959aeb83a18203608bf3c..5227409160848f2106bc77e6fda5344c4edce520 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,7 +4,7 @@ Road plan
   * Fix all memory leaks
   * Asynchronous IO and data loading
   * Pre-load textures and polys in OpenGL
-  * GObject integration (plugin object/interface)
+  * Get rid of global `self' references in plugins
 
 0.x - Volume scans
   * Display iso surfaces of volume scans
index d1d7704c2acfcd2e329fff313a9fe7ce7afbcd94..8139ca846ff36a7796e828fd805f961f7de4ccfc 100644 (file)
@@ -9,5 +9,5 @@ DOC_SOURCE_DIR=../../src/
 DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
 MKDB_OPTIONS=--sgml-mode --output-format=xml
 MAINTAINERCLEANFILES= \
-       Makefile.in aweather-docs.sgml aweather-overrides.txt aweather.types 
+       tmpl/* Makefile.in aweather-docs.sgml aweather-overrides.txt aweather.types 
 include $(top_srcdir)/gtk-doc.make
diff --git a/docs/api/aweather-sections.txt b/docs/api/aweather-sections.txt
new file mode 100644 (file)
index 0000000..e93755a
--- /dev/null
@@ -0,0 +1,68 @@
+<SECTION>
+<FILE>aweather-gui</FILE>
+<TITLE>AWeatherGui</TITLE>
+AWeatherGui
+aweather_gui_new
+aweather_gui_get_view
+aweather_gui_get_builder
+aweather_gui_get_window
+aweather_gui_get_tabs
+aweather_gui_get_drawing
+<SUBSECTION Standard>
+AWEATHER_GUI
+AWEATHER_IS_GUI
+AWEATHER_TYPE_GUI
+aweather_gui_get_type
+AWEATHER_GUI_CLASS
+AWEATHER_IS_GUI_CLASS
+AWEATHER_GUI_GET_CLASS
+</SECTION>
+
+<SECTION>
+<FILE>aweather-view</FILE>
+<TITLE>AWeatherView</TITLE>
+AWeatherView
+aweather_view_new
+aweather_view_set_time
+aweather_view_get_time
+aweather_view_set_location
+aweather_view_get_location
+<SUBSECTION Standard>
+AWEATHER_VIEW
+AWEATHER_IS_VIEW
+AWEATHER_TYPE_VIEW
+aweather_view_get_type
+AWEATHER_VIEW_CLASS
+AWEATHER_IS_VIEW_CLASS
+AWEATHER_VIEW_GET_CLASS
+</SECTION>
+
+<SECTION>
+<FILE>plugin-radar</FILE>
+radar_init
+</SECTION>
+
+<SECTION>
+<FILE>plugin-ridge</FILE>
+ridge_init
+</SECTION>
+
+<SECTION>
+<FILE>location</FILE>
+city_t
+</SECTION>
+
+<SECTION>
+<FILE>aweather-plugin</FILE>
+</SECTION>
+
+<SECTION>
+<FILE>plugin-example</FILE>
+example_init
+</SECTION>
+
+<SECTION>
+<FILE>opengl</FILE>
+opengl_init
+</SECTION>
+
index 705df0e19f69ca36897d94b0ad98b5c0246f2ffe..d05c4fbbeac4f2801f5fc2121a485ca06330ac5d 100644 (file)
@@ -20,6 +20,9 @@ aweather_CPPFLAGS = $(RSL_CFLAGS) $(GTK_CFLAGS) -DDATADIR="\"$(datadir)\""
 wsr88ddec         = wsr88ddec.c
 wsr88ddec_LDADD   = -lbz2
 
+CLEANFILES = gmon.out valgrind.out
+MAINTAINERCLEANFILES = Makefile.in
+
 .list.c:
        glib-genmarshal --prefix=aweather_cclosure_marshal --body   $< > $@
 .list.h:
@@ -42,4 +45,4 @@ memcheck:
                 --num-callers=50               \
                 --suppressions=gtk.suppression \
                 ./aweather                     \
-       2> memcheck.log
+       2> valgrind.out
index 7adecf0c054cd6510b70c478dd491d6eeddeecb2..4c5bff2df636f2e5de381a6d5de05bb788c7911d 100644 (file)
@@ -190,16 +190,16 @@ gboolean on_configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
        double rad  = atan((height/2)/500);
        double deg  = (rad*180)/M_PI;
 
-       //gluPerspective(deg*2, width/height, -z-20, -z+20);
-       gluPerspective(deg*2, width/height, 1, 500*1000);
+       gluPerspective(deg*2, width/height, -z-20, -z+20);
+       //gluPerspective(deg*2, width/height, 1, 500*1000);
 
        aweather_gui_gl_end(gui);
        return FALSE;
 }
 
-gboolean on_expose_begin(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
+gboolean on_expose(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
 {
-       g_message("aweather:expose_begin");
+       g_message("aweather:expose - begin");
        aweather_gui_gl_begin(gui);
 
        double x, y, z;
@@ -218,13 +218,9 @@ gboolean on_expose_begin(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
                aweather_plugin_expose(plugin);
        }
 
-       return FALSE;
-}
-gboolean on_expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
-{
-       g_message("aweather:expose_end\n");
        aweather_gui_gl_end(gui);
        aweather_gui_gl_flush(gui);
+       g_message("aweather:expose - end\n");
        return FALSE;
 }
 
@@ -372,10 +368,9 @@ static void opengl_setup(AWeatherGui *gui)
                g_error("GL lacks required capabilities");
 
        /* Set up OpenGL Stuff, glade doesn't like doing these */
-       g_signal_connect      (drawing, "map-event",       G_CALLBACK(on_map),          gui);
-       g_signal_connect      (drawing, "configure-event", G_CALLBACK(on_configure),    gui);
-       g_signal_connect      (drawing, "expose-event",    G_CALLBACK(on_expose_begin), gui);
-       g_signal_connect_after(drawing, "expose-event",    G_CALLBACK(on_expose_end),   gui);
+       g_signal_connect(drawing, "map-event",       G_CALLBACK(on_map),       gui);
+       g_signal_connect(drawing, "configure-event", G_CALLBACK(on_configure), gui);
+       g_signal_connect(drawing, "expose-event",    G_CALLBACK(on_expose),    gui);
 }
 
 
index 773b0337059e327809ec7a7038e2c2c14b06d6bb..343b6b9849bd6ed8e7101f9716c89c806c84084a 100644 (file)
@@ -37,11 +37,9 @@ int main(int argc, char *argv[])
        //AWeatherView *view = aweather_gui_get_view(gui);
 
        /* Load plugins */
-       //example_init(gui);
-        //ridge_init(gui);
-       //radar_init(gui);
-
        aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_example_new(gui)));
+       aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_ridge_new(gui)));
+       aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_radar_new(gui)));
 
        gtk_widget_show_all(aweather_gui_get_widget(gui, "window"));
        gtk_main();
index 553dd3d6acb6aabe90ed74905e2d271e50461f8e..26be63a0c81c571658e9e142b9ba4938d9921b88 100644 (file)
@@ -21,7 +21,6 @@
 #include <GL/gl.h>
 
 #include "aweather-gui.h"
-#include "aweather-plugin.h"
 #include "plugin-example.h"
 
 /****************
@@ -75,7 +74,7 @@ AWeatherExample *aweather_example_new(AWeatherGui *gui)
        GtkWidget *config  = aweather_gui_get_widget(gui, "tabs");
 
        /* Add configuration tab */
-       GtkWidget *label = gtk_label_new("example");
+       GtkWidget *label = gtk_label_new("Example");
        example->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate"));
        gtk_notebook_append_page(GTK_NOTEBOOK(config), GTK_WIDGET(example->button), label);
 
index 5e52f6e53c44940f49a814b3ca26d1c490a1bcc4..4ffc78ae7c772a37ee1da0a096b6fd4b3b424a43 100644 (file)
@@ -43,7 +43,7 @@ struct _AWeatherExampleClass {
        GObjectClass parent_class;
 };
 
-GType aweather_example_get_type (void);
+GType aweather_example_get_type();
 
 /* Methods */
 AWeatherExample *aweather_example_new(AWeatherGui *gui);
index c1e122ef4153d1e2672d5c8fe744a05c5188bf54..46e73d4a0ee73b4e1f9ed35235a749be2a85f845 100644 (file)
 #include <gtk/gtkgl.h>
 #include <GL/gl.h>
 #include <math.h>
-
-#include "rsl.h"
+#include <rsl.h>
 
 #include "aweather-gui.h"
 #include "plugin-radar.h"
 #include "data.h"
 
-GtkWidget *drawing;
-GtkWidget *config_body;
-static Sweep *cur_sweep = NULL;  // make this not global
-//static int nred, ngreen, nblue;
-//static char red[256], green[256], blue[256];
-static colormap_t *colormap;
-static guint sweep_tex = 0;
-static Radar *radar = NULL;
+/****************
+ * GObject code *
+ ****************/
+static void aweather_radar_plugin_init(AWeatherPluginInterface *iface);
+static void aweather_radar_expose(AWeatherPlugin *_radar);
+G_DEFINE_TYPE_WITH_CODE(AWeatherRadar, aweather_radar, G_TYPE_OBJECT,
+               G_IMPLEMENT_INTERFACE(AWEATHER_TYPE_PLUGIN,
+                       aweather_radar_plugin_init));
+static void aweather_radar_class_init(AWeatherRadarClass *klass)
+{
+       GObjectClass *object_class = (GObjectClass*)klass;
+}
+static void aweather_radar_plugin_init(AWeatherPluginInterface *iface)
+{
+       /* Add methods to the interface */
+       iface->expose = aweather_radar_expose;
+}
+static void aweather_radar_init(AWeatherRadar *radar)
+{
+       /* Set defaults */
+       radar->gui = NULL;
+}
 
-static AWeatherGui *gui = NULL;
+/* TODO: User parameters or user data or something */
+static AWeatherRadar *self = NULL;
 
 /**************************
  * Data loading functions *
@@ -61,10 +75,10 @@ static void bscan_sweep(Sweep *sweep, guint8 **data, int *width, int *height)
                        //guint val   = dz_f(ray->range[bi]);
                        guint8 val   = (guint8)ray->h.f(ray->range[bi]);
                        guint  buf_i = (ri*max_bins+bi)*4;
-                       buf[buf_i+0] = colormap->data[val][0];
-                       buf[buf_i+1] = colormap->data[val][1];
-                       buf[buf_i+2] = colormap->data[val][2];
-                       buf[buf_i+3] = colormap->data[val][3];
+                       buf[buf_i+0] = self->cur_colormap->data[val][0];
+                       buf[buf_i+1] = self->cur_colormap->data[val][1];
+                       buf[buf_i+2] = self->cur_colormap->data[val][2];
+                       buf[buf_i+3] = self->cur_colormap->data[val][3];
                        if (val == BADVAL     || val == RFVAL      || val == APFLAG ||
                            val == NOTFOUND_H || val == NOTFOUND_V || val == NOECHO) {
                                buf[buf_i+3] = 0x00; // transparent
@@ -82,20 +96,20 @@ static void load_color_table(char *table)
 {
        for (int i = 0; colormaps[i].name; i++)
                if (g_str_equal(colormaps[i].name, table))
-                       colormap = &colormaps[i];
+                       self->cur_colormap = &colormaps[i];
 }
 
 /* Load a sweep as the active texture */
 static void load_sweep(Sweep *sweep)
 {
-       aweather_gui_gl_begin(gui);
-       cur_sweep = sweep;
+       aweather_gui_gl_begin(self->gui);
+       self->cur_sweep = sweep;
        int height, width;
        guint8 *data;
        bscan_sweep(sweep, &data, &width, &height);
-       glDeleteTextures(1, &sweep_tex);
-       glGenTextures(1, &sweep_tex);
-       glBindTexture(GL_TEXTURE_2D, sweep_tex);
+       glDeleteTextures(1, &self->cur_sweep_tex);
+       glGenTextures(1, &self->cur_sweep_tex);
+       glBindTexture(GL_TEXTURE_2D, self->cur_sweep_tex);
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -103,15 +117,15 @@ static void load_sweep(Sweep *sweep)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
                        GL_RGBA, GL_UNSIGNED_BYTE, data);
        g_free(data);
-       aweather_gui_gl_redraw(gui);
-       aweather_gui_gl_end(gui);
+       aweather_gui_gl_redraw(self->gui);
+       aweather_gui_gl_end(self->gui);
 }
 
 /* Add selectors to the config area for the sweeps */
 static void load_radar_gui(Radar *radar)
 {
        /* Clear existing items */
-       GtkWidget *child = gtk_bin_get_child(GTK_BIN(config_body));
+       GtkWidget *child = gtk_bin_get_child(GTK_BIN(self->config_body));
        if (child)
                gtk_widget_destroy(child);
 
@@ -174,7 +188,7 @@ static void load_radar_gui(Radar *radar)
                                        G_CALLBACK(load_sweep), sweep);
                }
        }
-       gtk_container_add(GTK_CONTAINER(config_body), table);
+       gtk_container_add(GTK_CONTAINER(self->config_body), table);
        gtk_widget_show_all(table);
 }
 
@@ -190,12 +204,12 @@ static void load_radar_rsl(GPid pid, gint status, gpointer _path)
        char *site = g_path_get_basename(dir);
        g_free(dir);
        RSL_read_these_sweeps("all", NULL);
-       if (radar) {
+       if (self->cur_radar) {
                g_message("Freeing radar");
-               RSL_free_radar(radar);
+               RSL_free_radar(self->cur_radar);
        }
        g_message("Allocating radar");
-       radar = RSL_wsr88d_to_radar(path, site);
+       Radar *radar = self->cur_radar = RSL_wsr88d_to_radar(path, site);
        if (radar == NULL) {
                g_warning("fail to load radar: path=%s, site=%s", path, site);
                g_free(path);
@@ -275,7 +289,7 @@ static void update_times(char *site, char **last_time)
                return;
        }
        gchar **lines = g_strsplit(data, "\n", -1);
-       GtkTreeView  *tview  = GTK_TREE_VIEW(aweather_gui_get_widget(gui, "time"));
+       GtkTreeView  *tview  = GTK_TREE_VIEW(aweather_gui_get_widget(self->gui, "time"));
        GtkListStore *lstore = GTK_LIST_STORE(gtk_tree_view_get_model(tview));
        gtk_list_store_clear(lstore);
        GtkTreeIter iter;
@@ -299,18 +313,84 @@ static void update_times(char *site, char **last_time)
 /*************
  * Callbacks *
  *************/
-static gboolean on_expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
+static void on_time_changed(AWeatherView *view, char *time, gpointer user_data)
+{
+       g_message("radar:setting time");
+       // format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323
+       char *site = aweather_view_get_site(view);
+       char *base = "http://mesonet.agron.iastate.edu/data/";
+       char *path = g_strdup_printf("nexrd2/raw/K%s/K%s_%s", site, site, time);
+
+       self->cur_radar = NULL;
+       self->cur_sweep = NULL; // Clear radar
+       aweather_gui_gl_redraw(self->gui);
+
+       cache_file(base, path, AWEATHER_AUTOMATIC, load_radar, NULL);
+       g_free(path);
+}
+
+static void on_site_changed(AWeatherView *view, char *site, gpointer user_data)
+{
+       g_message("Loading wsr88d list for %s", site);
+       char *time = NULL;
+       update_times(site, &time);
+       aweather_view_set_time(view, time);
+
+       g_free(time);
+}
+
+static void on_refresh(AWeatherView *view, gpointer user_data)
+{
+       char *site = aweather_view_get_site(view);
+       char *time = NULL;
+       update_times(site, &time);
+       aweather_view_set_time(view, time);
+       g_free(time);
+}
+
+
+
+/***********
+ * Methods *
+ ***********/
+AWeatherRadar *aweather_radar_new(AWeatherGui *gui)
+{
+       //g_message("aweather_view_new");
+       AWeatherRadar *radar = g_object_new(AWEATHER_TYPE_RADAR, NULL);
+       radar->gui = gui;
+
+       self = radar;
+
+       GtkWidget    *config  = aweather_gui_get_widget(gui, "tabs");
+       AWeatherView *view    = aweather_gui_get_view(gui);
+
+       /* Add configuration tab */
+       self->config_body = gtk_alignment_new(0, 0, 1, 1);
+       gtk_container_set_border_width(GTK_CONTAINER(self->config_body), 5);
+       gtk_container_add(GTK_CONTAINER(self->config_body), gtk_label_new("No radar loaded"));
+       gtk_notebook_prepend_page(GTK_NOTEBOOK(config), self->config_body, gtk_label_new("Radar"));
+
+       /* Set up OpenGL Stuff */
+       g_signal_connect(view,    "site-changed", G_CALLBACK(on_site_changed), NULL);
+       g_signal_connect(view,    "time-changed", G_CALLBACK(on_time_changed), NULL);
+       g_signal_connect(view,    "refresh",      G_CALLBACK(on_refresh),      NULL);
+
+       return radar;
+}
+
+static void aweather_radar_expose(AWeatherPlugin *_radar)
 {
+       AWeatherRadar *radar = AWEATHER_RADAR(_radar);
        g_message("radar:expose");
-       if (cur_sweep == NULL)
-               return FALSE;
-       Sweep *sweep = cur_sweep;
+       if (self->cur_sweep == NULL)
+               return;
+       Sweep *sweep = self->cur_sweep;
 
        /* Draw the rays */
 
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
-       glBindTexture(GL_TEXTURE_2D, sweep_tex);
+       glBindTexture(GL_TEXTURE_2D, self->cur_sweep_tex);
        glEnable(GL_TEXTURE_2D);
        glDisable(GL_ALPHA_TEST);
        glColor4f(1,1,1,1);
@@ -362,10 +442,10 @@ static gboolean on_expose(GtkWidget *da, GdkEventExpose *event, gpointer user_da
        glBegin(GL_QUADS);
        int i;
        for (i = 0; i < 256; i++) {
-               glColor4ub(colormap->data[i][0],
-                          colormap->data[i][1],
-                          colormap->data[i][2],
-                          colormap->data[i][3]);
+               glColor4ub(self->cur_colormap->data[i][0],
+                          self->cur_colormap->data[i][1],
+                          self->cur_colormap->data[i][2],
+                          self->cur_colormap->data[i][3]);
                glVertex3f(-1.0, (float)((i  ) - 256/2)/(256/2), 0.0); // bot left
                glVertex3f(-1.0, (float)((i+1) - 256/2)/(256/2), 0.0); // top left
                glVertex3f(-0.9, (float)((i+1) - 256/2)/(256/2), 0.0); // top right
@@ -376,63 +456,4 @@ static gboolean on_expose(GtkWidget *da, GdkEventExpose *event, gpointer user_da
        glEnable(GL_ALPHA_TEST);
         glMatrixMode(GL_PROJECTION); glPopMatrix(); 
        glMatrixMode(GL_MODELVIEW ); glPopMatrix();
-       return FALSE;
-}
-
-static void on_time_changed(AWeatherView *view, char *time, gpointer user_data)
-{
-       g_message("radar:setting time");
-       // format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323
-       char *site = aweather_view_get_site(view);
-       char *base = "http://mesonet.agron.iastate.edu/data/";
-       char *path = g_strdup_printf("nexrd2/raw/K%s/K%s_%s", site, site, time);
-
-       radar = NULL;
-       cur_sweep = NULL; // Clear radar
-       aweather_gui_gl_redraw(gui);
-
-       cache_file(base, path, AWEATHER_AUTOMATIC, load_radar, NULL);
-       g_free(path);
-}
-
-static void on_site_changed(AWeatherView *view, char *site, gpointer user_data)
-{
-       g_message("Loading wsr88d list for %s", site);
-       char *time = NULL;
-       update_times(site, &time);
-       aweather_view_set_time(view, time);
-
-       g_free(time);
-}
-
-static void on_refresh(AWeatherView *view, gpointer user_data)
-{
-       char *site = aweather_view_get_site(view);
-       char *time = NULL;
-       update_times(site, &time);
-       aweather_view_set_time(view, time);
-       g_free(time);
-}
-
-/* Init */
-gboolean radar_init(AWeatherGui *_gui)
-{
-       gui = _gui;
-       drawing = aweather_gui_get_widget(gui, "drawing");
-       GtkWidget    *config  = aweather_gui_get_widget(gui, "tabs");
-       AWeatherView *view    = aweather_gui_get_view(gui);
-
-       /* Add configuration tab */
-       config_body = gtk_alignment_new(0, 0, 1, 1);
-       gtk_container_set_border_width(GTK_CONTAINER(config_body), 5);
-       gtk_container_add(GTK_CONTAINER(config_body), gtk_label_new("No radar loaded"));
-       gtk_notebook_prepend_page(GTK_NOTEBOOK(config), config_body, gtk_label_new("Radar"));
-
-       /* Set up OpenGL Stuff */
-       g_signal_connect(drawing, "expose-event", G_CALLBACK(on_expose),       NULL);
-       g_signal_connect(view,    "site-changed", G_CALLBACK(on_site_changed), NULL);
-       g_signal_connect(view,    "time-changed", G_CALLBACK(on_time_changed), NULL);
-       g_signal_connect(view,    "refresh",      G_CALLBACK(on_refresh),      NULL);
-
-       return TRUE;
 }
index 2bc422aac026402874201be0256a230358a22345..5cc5011b42cd822d98e445a93b30931382b35654 100644 (file)
 #ifndef __RADAR_H__
 #define __RADAR_H__
 
-gboolean radar_init(AWeatherGui *gui);
+#include <glib-object.h>
+#include <rsl.h>
 
+/* TODO: convert */
 typedef struct {
        char *name;
        guint8 data[256][4];
 } colormap_t;
-
 extern colormap_t colormaps[];
 
+#define AWEATHER_TYPE_RADAR            (aweather_radar_get_type ())
+#define AWEATHER_RADAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   AWEATHER_TYPE_RADAR, AWeatherRadar))
+#define AWEATHER_IS_RADAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   AWEATHER_TYPE_RADAR))
+#define AWEATHER_RADAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), AWEATHER_TYPE_RADAR, AWeatherRadarClass))
+#define AWEATHER_IS_RADAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), AWEATHER_TYPE_RADAR))
+#define AWEATHER_RADAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   AWEATHER_TYPE_RADAR, AWeatherRadarClass))
+
+typedef struct _AWeatherRadar        AWeatherRadar;
+typedef struct _AWeatherRadarClass   AWeatherRadarClass;
+
+struct _AWeatherRadar {
+       GObject parent_instance;
+
+       /* instance members */
+       AWeatherGui *gui;
+       GtkWidget   *config_body;
+       Radar       *cur_radar;
+       Sweep       *cur_sweep; // make this not global
+       colormap_t  *cur_colormap;
+       guint        cur_sweep_tex;
+};
+
+struct _AWeatherRadarClass {
+       GObjectClass parent_class;
+};
+
+GType aweather_radar_get_type();
+
+/* Methods */
+AWeatherRadar *aweather_radar_new(AWeatherGui *gui);
+
 #endif
index 9e519fe557f5de0d0244c66496c3caaeffc9d998..b099a08b6cfea32fcb7c3ca91e04fe95a68a5e85 100644 (file)
 #include <stdio.h>
 
 #include "aweather-gui.h"
+#include "plugin-ridge.h"
 #include "data.h"
 
+/****************
+ * GObject code *
+ ****************/
+static void aweather_ridge_plugin_init(AWeatherPluginInterface *iface);
+static void aweather_ridge_expose(AWeatherPlugin *_ridge);
+G_DEFINE_TYPE_WITH_CODE(AWeatherRidge, aweather_ridge, G_TYPE_OBJECT,
+               G_IMPLEMENT_INTERFACE(AWEATHER_TYPE_PLUGIN,
+                       aweather_ridge_plugin_init));
+static void aweather_ridge_class_init(AWeatherRidgeClass *klass)
+{
+       GObjectClass *object_class = (GObjectClass*)klass;
+}
+static void aweather_ridge_plugin_init(AWeatherPluginInterface *iface)
+{
+       /* Add methods to the interface */
+       iface->expose = aweather_ridge_expose;
+}
+static void aweather_ridge_init(AWeatherRidge *ridge)
+{
+       /* Set defaults */
+       ridge->gui = NULL;
+}
+
+
+/***********
+ * Helpers *
+ ***********/
 enum {
        LAYER_TOPO,
        LAYER_COUNTY,
@@ -50,7 +78,8 @@ static layer_t layers[] = {
        [LAYER_CITY]     = {"Cities",   "Overlays/Cities/Short/%s_City_Short.gif",       TRUE,  6, 0},
 };
 
-static AWeatherGui *gui = NULL;
+/* TODO: Remove this */
+AWeatherGui *old_gui = NULL;
 
 /**
  * Load an image into an OpenGL texture
@@ -60,7 +89,7 @@ static AWeatherGui *gui = NULL;
 void load_texture(gchar *filename, gboolean updated, gpointer _layer)
 {
        layer_t *layer = _layer;
-       aweather_gui_gl_begin(gui);
+       aweather_gui_gl_begin(old_gui);
 
        /* Load image */
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
@@ -88,15 +117,15 @@ void load_texture(gchar *filename, gboolean updated, gpointer _layer)
                base);
        g_free(base);
 
-       aweather_gui_gl_end(gui);
+       aweather_gui_gl_end(old_gui);
 
        g_object_unref(pixbuf);
 
        /* Redraw */
-       aweather_gui_gl_redraw(gui);
+       aweather_gui_gl_redraw(old_gui);
 }
 
-static void set_site(AWeatherView *view, gchar *site, gpointer user_data)
+static void set_site(AWeatherView *view, gchar *site, AWeatherRidge *ridge)
 {
        g_message("site changed to %s", site);
        for (int i = 0; i < LAYER_COUNT; i++) {
@@ -107,39 +136,21 @@ static void set_site(AWeatherView *view, gchar *site, gpointer user_data)
        }
 }
 
-static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
-{
-       g_message("ridge:expose");
-       glPushMatrix();
-       glEnable(GL_TEXTURE_2D);
-       glColor4f(1,1,1,1);
-
-       for (int i = 0; i < LAYER_COUNT; i++) {
-               if (!layers[i].enabled)
-                       continue;
-               glBindTexture(GL_TEXTURE_2D, layers[i].tex);
-               glBegin(GL_POLYGON);
-               glTexCoord2f(0.0, 0.0); glVertex3f(240*1000*-1.0, 282*1000* 1.0, layers[i].z);
-               glTexCoord2f(0.0, 1.0); glVertex3f(240*1000*-1.0, 282*1000*-1.0, layers[i].z);
-               glTexCoord2f(1.0, 1.0); glVertex3f(240*1000* 1.0, 282*1000*-1.0, layers[i].z);
-               glTexCoord2f(1.0, 0.0); glVertex3f(240*1000* 1.0, 282*1000* 1.0, layers[i].z);
-               glEnd();
-       }
-
-       glPopMatrix();
-       return FALSE;
-}
-
 void toggle_layer(GtkToggleButton *check, gpointer _layer)
 {
        layer_t *layer = _layer;
        layer->enabled = gtk_toggle_button_get_active(check);
-       aweather_gui_gl_redraw(gui);
+       aweather_gui_gl_redraw(old_gui);
 }
 
-gboolean ridge_init(AWeatherGui *_gui)
+/***********
+ * Methods *
+ ***********/
+AWeatherRidge *aweather_ridge_new(AWeatherGui *gui)
 {
-       gui = _gui;
+       AWeatherRidge *ridge = g_object_new(AWEATHER_TYPE_RIDGE, NULL);
+       ridge->gui = old_gui = gui;
+
        AWeatherView *view    = aweather_gui_get_view(gui);
        GtkWidget    *drawing = aweather_gui_get_widget(gui, "drawing");
        GtkWidget    *config  = aweather_gui_get_widget(gui, "tabs");
@@ -157,9 +168,31 @@ gboolean ridge_init(AWeatherGui *_gui)
        gtk_container_add(GTK_CONTAINER(body), hbox);
        gtk_notebook_append_page(GTK_NOTEBOOK(config), body, tab);
 
-       /* Set up OpenGL Stuff */
-       g_signal_connect(drawing, "expose-event", G_CALLBACK(expose),    NULL);
-       g_signal_connect(view,    "site-changed", G_CALLBACK(set_site),  NULL);
+       g_signal_connect(view,    "site-changed", G_CALLBACK(set_site),  ridge);
+
+       return ridge;
+}
+
+static void aweather_ridge_expose(AWeatherPlugin *_ridge)
+{
+       AWeatherRidge *ridge = AWEATHER_RIDGE(_ridge);
+
+       g_message("ridge:expose");
+       glPushMatrix();
+       glEnable(GL_TEXTURE_2D);
+       glColor4f(1,1,1,1);
+
+       for (int i = 0; i < LAYER_COUNT; i++) {
+               if (!layers[i].enabled)
+                       continue;
+               glBindTexture(GL_TEXTURE_2D, layers[i].tex);
+               glBegin(GL_POLYGON);
+               glTexCoord2f(0.0, 0.0); glVertex3f(240*1000*-1.0, 282*1000* 1.0, layers[i].z);
+               glTexCoord2f(0.0, 1.0); glVertex3f(240*1000*-1.0, 282*1000*-1.0, layers[i].z);
+               glTexCoord2f(1.0, 1.0); glVertex3f(240*1000* 1.0, 282*1000*-1.0, layers[i].z);
+               glTexCoord2f(1.0, 0.0); glVertex3f(240*1000* 1.0, 282*1000* 1.0, layers[i].z);
+               glEnd();
+       }
 
-       return TRUE;
+       glPopMatrix();
 }
index 9d5ca04bb3c4150d1c2437b2d1faf5147fcfff1f..7c31ee66737dd18b2d5e94fa73391d5c7f7824a7 100644 (file)
 #ifndef __RIDGE_H__
 #define __RIDGE_H__
 
-gboolean ridge_init(AWeatherGui *gui);
+#include <glib-object.h>
+
+#define AWEATHER_TYPE_RIDGE            (aweather_ridge_get_type ())
+#define AWEATHER_RIDGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   AWEATHER_TYPE_RIDGE, AWeatherRidge))
+#define AWEATHER_IS_RIDGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   AWEATHER_TYPE_RIDGE))
+#define AWEATHER_RIDGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), AWEATHER_TYPE_RIDGE, AWeatherRidgeClass))
+#define AWEATHER_IS_RIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), AWEATHER_TYPE_RIDGE))
+#define AWEATHER_RIDGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   AWEATHER_TYPE_RIDGE, AWeatherRidgeClass))
+
+typedef struct _AWeatherRidge      AWeatherRidge;
+typedef struct _AWeatherRidgeClass AWeatherRidgeClass;
+
+struct _AWeatherRidge {
+       GObject parent_instance;
+
+       /* instance members */
+       AWeatherGui *gui;
+};
+
+struct _AWeatherRidgeClass {
+       GObjectClass parent_class;
+};
+
+GType aweather_ridge_get_type();
+
+/* Methods */
+AWeatherRidge *aweather_ridge_new(AWeatherGui *gui);
 
 #endif