From e778b406a21e31d79ca1cd599469bb4ddc3d6a1c Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 24 May 2009 08:15:06 +0000 Subject: [PATCH] Converting Ridge and Radar plugins to use GObject --- TODO | 2 +- docs/api/Makefile.am | 2 +- docs/api/aweather-sections.txt | 68 +++++++++++ src/Makefile.am | 5 +- src/aweather-gui.c | 21 ++-- src/main.c | 6 +- src/plugin-example.c | 3 +- src/plugin-example.h | 2 +- src/plugin-radar.c | 215 ++++++++++++++++++--------------- src/plugin-radar.h | 36 +++++- src/plugin-ridge.c | 103 ++++++++++------ src/plugin-ridge.h | 28 ++++- 12 files changed, 333 insertions(+), 158 deletions(-) create mode 100644 docs/api/aweather-sections.txt diff --git a/TODO b/TODO index 94e5c6c..5227409 100644 --- 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 diff --git a/docs/api/Makefile.am b/docs/api/Makefile.am index d1d7704..8139ca8 100644 --- a/docs/api/Makefile.am +++ b/docs/api/Makefile.am @@ -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 index 0000000..e93755a --- /dev/null +++ b/docs/api/aweather-sections.txt @@ -0,0 +1,68 @@ +
+aweather-gui +AWeatherGui +AWeatherGui +aweather_gui_new +aweather_gui_get_view +aweather_gui_get_builder +aweather_gui_get_window +aweather_gui_get_tabs +aweather_gui_get_drawing + +AWEATHER_GUI +AWEATHER_IS_GUI +AWEATHER_TYPE_GUI +aweather_gui_get_type +AWEATHER_GUI_CLASS +AWEATHER_IS_GUI_CLASS +AWEATHER_GUI_GET_CLASS +
+ +
+aweather-view +AWeatherView +AWeatherView +aweather_view_new +aweather_view_set_time +aweather_view_get_time +aweather_view_set_location +aweather_view_get_location + +AWEATHER_VIEW +AWEATHER_IS_VIEW +AWEATHER_TYPE_VIEW +aweather_view_get_type +AWEATHER_VIEW_CLASS +AWEATHER_IS_VIEW_CLASS +AWEATHER_VIEW_GET_CLASS +
+ +
+plugin-radar +radar_init +
+ +
+plugin-ridge +ridge_init +
+ +
+location +city_t +
+ +
+aweather-plugin +
+ +
+plugin-example +example_init +
+ +
+opengl +opengl_init +
+ diff --git a/src/Makefile.am b/src/Makefile.am index 705df0e..d05c4fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 7adecf0..4c5bff2 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -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); } diff --git a/src/main.c b/src/main.c index 773b033..343b6b9 100644 --- a/src/main.c +++ b/src/main.c @@ -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(); diff --git a/src/plugin-example.c b/src/plugin-example.c index 553dd3d..26be63a 100644 --- a/src/plugin-example.c +++ b/src/plugin-example.c @@ -21,7 +21,6 @@ #include #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); diff --git a/src/plugin-example.h b/src/plugin-example.h index 5e52f6e..4ffc78a 100644 --- a/src/plugin-example.h +++ b/src/plugin-example.h @@ -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); diff --git a/src/plugin-radar.c b/src/plugin-radar.c index c1e122e..46e73d4 100644 --- a/src/plugin-radar.c +++ b/src/plugin-radar.c @@ -20,23 +20,37 @@ #include #include #include - -#include "rsl.h" +#include #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; } diff --git a/src/plugin-radar.h b/src/plugin-radar.h index 2bc422a..5cc5011 100644 --- a/src/plugin-radar.h +++ b/src/plugin-radar.h @@ -18,13 +18,45 @@ #ifndef __RADAR_H__ #define __RADAR_H__ -gboolean radar_init(AWeatherGui *gui); +#include +#include +/* 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 diff --git a/src/plugin-ridge.c b/src/plugin-ridge.c index 9e519fe..b099a08 100644 --- a/src/plugin-ridge.c +++ b/src/plugin-ridge.c @@ -23,8 +23,36 @@ #include #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(); } diff --git a/src/plugin-ridge.h b/src/plugin-ridge.h index 9d5ca04..7c31ee6 100644 --- a/src/plugin-ridge.h +++ b/src/plugin-ridge.h @@ -18,6 +18,32 @@ #ifndef __RIDGE_H__ #define __RIDGE_H__ -gboolean ridge_init(AWeatherGui *gui); +#include + +#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 -- 2.43.2