aweather_SOURCES = main.c \
aweather-gui.c aweather-gui.h \
aweather-view.c aweather-view.h \
+ data.c data.h \
location.c location.h \
plugin-radar.c plugin-radar.h \
plugin-ridge.c plugin-ridge.h \
//aweather_view_set_time(view, site);
}
-static gboolean configure_start(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
+static gboolean map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
{
+ //g_message("map:map");
AWeatherView *view = aweather_gui_get_view(gui);
aweather_view_set_location(view, "IND");
- //g_message("opengl:configure_start");
- GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
- GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
-
- if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
- g_assert_not_reached();
-
- double width = da->allocation.width;
- double height = da->allocation.height;
- double dist = 500*1000; // 500 km
-
/* Misc */
- glViewport(0, 0, width, height);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.8f, 0.8f, 1.0f, 0.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
+ aweather_gui_gl_end(gui);
+ return FALSE;
+}
+
+static gboolean configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
+{
+ aweather_gui_gl_begin(gui);
+
+ double width = da->allocation.width;
+ double height = da->allocation.height;
+ double dist = 500*1000; // 500 km
+
+ glViewport(0, 0, width, height);
+
/* Perspective */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(0.0, 0.0, -dist);
//glRotatef(-45, 1, 0, 0);
-
+ aweather_gui_gl_end(gui);
return FALSE;
}
-static gboolean configure_end(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
+
+static gboolean expose_begin(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
{
- //g_message("opengl:configure_end");
- GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
- gdk_gl_drawable_gl_end(gldrawable);
+ aweather_gui_gl_begin(gui);
return FALSE;
}
static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
{
+ g_message("aweather:espose_end\n");
+ aweather_gui_gl_end(gui);
aweather_gui_gl_flush(gui);
return FALSE;
}
g_error("GL lacks required capabilities");
/* Set up OpenGL Stuff */
- g_signal_connect (drawing, "configure-event", G_CALLBACK(configure_start), gui);
- g_signal_connect_after(drawing, "configure-event", G_CALLBACK(configure_end), gui);
- g_signal_connect_after(drawing, "expose-event", G_CALLBACK(expose_end), gui);
+ g_signal_connect (drawing, "map-event", G_CALLBACK(map), gui);
+ g_signal_connect (drawing, "configure-event", G_CALLBACK(configure), gui);
+ g_signal_connect (drawing, "expose-event", G_CALLBACK(expose_begin), gui);
+ g_signal_connect_after(drawing, "expose-event", G_CALLBACK(expose_end), gui);
return TRUE;
}
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,
--- /dev/null
+#include <config.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "data.h"
+
+typedef struct {
+ AWeatherCacheDoneCallback callback;
+ gchar *src;
+ gchar *dst;
+ gchar *user_data;
+} cache_file_end_t;
+
+static void cache_file_cb(GObject *source_object, GAsyncResult *res, gpointer _info)
+{
+ cache_file_end_t *info = _info;
+ GError *error = NULL;
+ g_file_copy_finish(G_FILE(source_object), res, &error);
+ if (error) {
+ g_message("error copying file ([%s]->[%s]): %s",
+ info->src, info->dst, error->message);
+ } else {
+ info->callback(info->dst, info->user_data);
+ }
+ g_free(info->src);
+ g_free(info->dst);
+ g_free(info);
+}
+
+/**
+ * Cache a image from Ridge to the local disk
+ * \param path Path to the Ridge file, starting after /ridge/
+ * \return The local path to the cached image
+ */
+void cache_file(char *base, char *path, AWeatherCacheDoneCallback callback, gpointer user_data)
+{
+ gchar *url = g_strconcat(base, path, NULL);
+ gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL);
+ if (g_file_test(local, G_FILE_TEST_EXISTS)) {
+ callback(local, user_data);
+ } else {
+ if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR))
+ g_mkdir_with_parents(g_path_get_dirname(local), 0755);
+ cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t));
+ info->callback = callback;
+ info->src = url;
+ info->dst = local;
+ info->user_data = user_data;
+ GFile *src = g_file_new_for_uri(url);
+ GFile *dst = g_file_new_for_path(local);
+ g_file_copy_async(src, dst,
+ G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags,
+ 0, // int io_priority,
+ NULL, // GCancellable *cancellable,
+ NULL, // GFileProgressCallback progress_callback,
+ NULL, // gpointer progress_callback_data,
+ cache_file_cb, // GAsyncReadyCallback callback,
+ info); // gpointer user_data
+ }
+}
--- /dev/null
+#ifndef __DATA_H__
+#define __DATA_H__
+
+typedef void (*AWeatherCacheDoneCallback)(const gchar *file, gpointer user_data);
+
+void cache_file(char *base, char *path, AWeatherCacheDoneCallback callback, gpointer user_data);
+
+#endif
/* Load plugins */
radar_init (gui);
ridge_init (gui);
- example_init(gui);
+ //example_init(gui);
gtk_widget_show_all(GTK_WIDGET(aweather_gui_get_window(gui)));
gtk_main();
static char red[256], green[256], blue[256];
static guint sweep_tex = 0;
-Radar *radar = NULL;
+static AWeatherGui *gui = NULL;
+static Radar *radar = NULL;
static guint8 get_alpha(guint8 db)
{
else return 255;
}
-//#ifdef USE_TWO_BYTE_PRECISION
-//#define F_FACTOR 100.0
-//#define F_DR_FACTOR 1000.0
-//#define F_DZ_RANGE_OFFSET 50
-//#else
-//#define F_FACTOR 2.0
-//#define F_DR_FACTOR 10.0
-//#define F_DZ_RANGE_OFFSET 32
-//#endif
-//#define F_OFFSET 4
-//static float dz_f(Range x)
-//{
-// if (x >= F_OFFSET)
-// return (((float)x-F_OFFSET)/F_FACTOR - F_DZ_RANGE_OFFSET);
-// if (x == 0) return BADVAL;
-// if (x == 1) return RFVAL;
-// if (x == 2) return APFLAG;
-// if (x == 3) return NOECHO;
-// return BADVAL;
-//}
-
/* Convert a sweep to an 2d array of data points */
static void bscan_sweep(Sweep *sweep, guint8 **data, int *width, int *height)
{
}
/* Load the default sweep */
-static gboolean configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
+static gboolean map(GtkWidget *da, GdkEvent *event, gpointer user_data)
{
- //g_message("radar:configure");
+ g_message("radar:map");
aweather_gui_gl_begin(gui);
Sweep *first = radar->v[0]->sweep[0];
if (cur_sweep == NULL)
return FALSE;
}
-static gboolean expose(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
+static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
{
- //g_message("radar:expose");
- aweather_gui_gl_begin(gui);
+ g_message("radar:expose");
Sweep *sweep = cur_sweep;
/* Draw the rays */
glEnd();
glMatrixMode(GL_PROJECTION); glPopMatrix();
glMatrixMode(GL_MODELVIEW ); glPopMatrix();
-
- aweather_gui_gl_end(gui);
return FALSE;
}
-gboolean radar_init(AWeatherGui *gui)
+//static void set_site(AWeatherView *view, char *site, gpointer user_data)
+//{
+// g_message("location changed to %s", site);
+//}
+
+gboolean radar_init(AWeatherGui *_gui)
{
+ gui = _gui;
drawing = GTK_WIDGET(aweather_gui_get_drawing(gui));
GtkNotebook *config = aweather_gui_get_tabs(gui);
gtk_notebook_append_page(GTK_NOTEBOOK(config), scroll, label);
/* Set up OpenGL Stuff */
- g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), gui);
- g_signal_connect(drawing, "configure-event", G_CALLBACK(configure), gui);
+ g_signal_connect(drawing, "map-event", G_CALLBACK(map), NULL);
+ g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), NULL);
return TRUE;
}
#include <stdio.h>
#include "aweather-gui.h"
+#include "data.h"
enum {
LAYER_TOPO,
LAYER_COUNT
};
-static struct {
- char *fmt;
+typedef struct {
+ gchar *fmt;
float z;
guint tex;
-} layers[] = {
+} layer_t;
+
+static layer_t layers[] = {
[LAYER_TOPO] = { "Overlays/" "Topo/" "Short/" "%s_Topo_Short.jpg", 1, 0 },
[LAYER_COUNTY] = { "Overlays/" "County/" "Short/" "%s_County_Short.gif", 3, 0 },
[LAYER_RIVERS] = { "Overlays/" "Rivers/" "Short/" "%s_Rivers_Short.gif", 4, 0 },
[LAYER_CITY] = { "Overlays/" "Cities/" "Short/" "%s_City_Short.gif", 6, 0 },
};
-static CURL *curl_handle;
-
-/**
- * Cache a image from Ridge to the local disk
- * \param path Path to the Ridge file, starting after /ridge/
- * \return The local path to the cached image
- */
-char *cache_image(char *path)
-{
- gchar base[] = "http://radar.weather.gov/ridge/";
- gchar *url = g_strconcat(base, path, NULL);
- gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL);
- if (!g_file_test(local, G_FILE_TEST_EXISTS)) {
- if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) {
- //g_printerr("Making directory %s\n", g_path_get_dirname(local));
- g_mkdir_with_parents(g_path_get_dirname(local), 0755);
- }
- //g_printerr("Fetching image %s -> %s\n", url, local);
- long http_code;
- FILE *cached_image = fopen(local, "w+");
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, cached_image);
- curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, NULL);
- curl_easy_perform(curl_handle);
- curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
- fflush(cached_image);
- if (http_code != 200) {
- g_message("http %ld while fetching %s", http_code, url);
- remove(local);
- return NULL;
- }
- }
- return local;
-}
+static AWeatherGui *gui = NULL;
/**
* Load an image into an OpenGL texture
* \param filename Path to the image file
* \return The OpenGL identifier for the texture
*/
-guint load_texture(char *filename)
+void load_texture(const gchar *filename, gpointer _layer)
{
+ layer_t *layer = _layer;
+ aweather_gui_gl_begin(gui);
+
/* Load image */
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
+ if (!pixbuf)
+ g_warning("Failed to load texture: %s", filename);
guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
int width = gdk_pixbuf_get_width(pixbuf);
int height = gdk_pixbuf_get_height(pixbuf);
int format = gdk_pixbuf_get_has_alpha(pixbuf) ? GL_RGBA : GL_RGB;
/* Create Texture */
- guint id;
- glGenTextures(1, &id);
- glBindTexture(GL_TEXTURE_2D, id); // 2d texture (x and y size)
+ glGenTextures(1, &layer->tex);
+ glBindTexture(GL_TEXTURE_2D, layer->tex); // 2d texture (x and y size)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
g_message("loaded image: w=%-3d h=%-3d fmt=%x px=(%02x,%02x,%02x,%02x) img=%s",
width, height, format, pixels[0], pixels[1], pixels[2], pixels[3],
g_path_get_basename(filename));
- return id;
+
+ aweather_gui_gl_end(gui);
+
+ /* Redraw */
+ gtk_widget_queue_draw(GTK_WIDGET(aweather_gui_get_drawing(gui)));
}
-static void set_site(AWeatherView *view, char *site, AWeatherGui *gui)
+static void set_site(AWeatherView *view, gchar *site, gpointer user_data)
{
g_message("location changed to %s", site);
- aweather_gui_gl_begin(gui);
for (int i = 0; i < LAYER_COUNT; i++) {
- if (layers[i].tex != 0)
- continue;
- char *path = g_strdup_printf(layers[i].fmt, site);
- char *local = cache_image(path);
- layers[i].tex = load_texture(local);
- g_free(local);
+ gchar *base = "http://radar.weather.gov/ridge/";
+ gchar *path = g_strdup_printf(layers[i].fmt, site);
+ cache_file(base, path, load_texture, &layers[i]);
g_free(path);
}
- aweather_gui_gl_end(gui);
}
-static gboolean expose(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
+static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
{
- //g_message("ridge:expose");
- aweather_gui_gl_begin(gui);
+ g_message("ridge:expose");
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glColor4f(1,1,1,1);
}
glPopMatrix();
- aweather_gui_gl_end(gui);
return FALSE;
}
-gboolean ridge_init(AWeatherGui *gui)
+gboolean ridge_init(AWeatherGui *_gui)
{
+ gui = _gui;
GtkDrawingArea *drawing = aweather_gui_get_drawing(gui);
- AWeatherView *view = aweather_gui_get_view(gui);
+ AWeatherView *view = aweather_gui_get_view(gui);
/* Set up OpenGL Stuff */
- g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), gui);
- g_signal_connect(view, "location-changed", G_CALLBACK(set_site), gui);
-
- curl_global_init(CURL_GLOBAL_ALL);
- curl_handle = curl_easy_init();
+ g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), NULL);
+ g_signal_connect(view, "location-changed", G_CALLBACK(set_site), NULL);
return TRUE;
}