static gboolean size_determined;
static struct image_info*
-load_image_in_cache(glui32 image, gint width, gint height)
+load_image_from_blorb(giblorb_result_t resource, glui32 image, gint width, gint height)
{
ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
- giblorb_err_t blorb_error = 0;
- giblorb_result_t resource;
GError *pixbuf_error = NULL;
guchar *buffer;
- /* Lookup the proper resource */
- if(!glk_data->resource_map) {
- WARNING("No resource map has been loaded yet.");
- return NULL;
- }
- blorb_error = giblorb_load_resource(glk_data->resource_map, giblorb_method_FilePos, &resource, giblorb_ID_Pict, image);
- if(blorb_error != giblorb_err_None) {
- WARNING_S( "Error loading resource", giblorb_get_error_message(blorb_error) );
- return NULL;
- }
-
struct image_info *info = g_new0(struct image_info, 1);
info->resource_number = image;
}
g_mutex_unlock(glk_data->resource_lock);
+ info->pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ gdk_pixbuf_ref(info->pixbuf);
+
+ g_object_unref(loader);
+ return info;
+}
+
+static struct image_info *
+load_image_from_file(const gchar *filename, glui32 image, gint width, gint height)
+{
+ GError *err = NULL;
+
+ struct image_info *info = g_new0(struct image_info, 1);
+ info->resource_number = image;
+
+ if(width > 0 && height > 0) {
+ info->scaled = TRUE;
+ info->pixbuf = gdk_pixbuf_new_from_file_at_size(filename, width, height, &err);
+ } else {
+ info->pixbuf = gdk_pixbuf_new_from_file(filename, &err);
+ }
+ if(!info->pixbuf) {
+ IO_WARNING("Error loading resource from alternative location", filename, err->message);
+ g_error_free(err);
+ g_free(info);
+ return NULL;
+ }
+ gdk_pixbuf_ref(info->pixbuf);
+
+ return info;
+}
+
+static struct image_info*
+load_image_in_cache(glui32 image, gint width, gint height)
+{
+ ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+ struct image_info *info = NULL;
+
+ /* Lookup the proper resource */
+ if(!glk_data->resource_map) {
+ if(!glk_data->resource_load_callback) {
+ WARNING("No resource map has been loaded yet.");
+ return NULL;
+ }
+ gchar *filename = glk_data->resource_load_callback(CHIMARA_RESOURCE_IMAGE, image, glk_data->resource_load_callback_data);
+ if(!filename) {
+ WARNING("Error loading resource from alternative location");
+ return NULL;
+ }
+ info = load_image_from_file(filename, image, width, height);
+ g_free(filename);
+ } else {
+ giblorb_result_t resource;
+ giblorb_err_t blorb_error = giblorb_load_resource(glk_data->resource_map, giblorb_method_FilePos, &resource, giblorb_ID_Pict, image);
+ if(blorb_error != giblorb_err_None) {
+ WARNING_S( "Error loading resource", giblorb_get_error_message(blorb_error) );
+ return NULL;
+ }
+ info = load_image_from_blorb(resource, image, width, height);
+ }
+
+ if(info == NULL)
+ return NULL;
+
/* Store the image in the cache */
gdk_threads_enter();
g_free(head);
glk_data->image_cache = g_slist_remove_link(glk_data->image_cache, glk_data->image_cache);
}
- info->pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
- gdk_pixbuf_ref(info->pixbuf);
info->width = gdk_pixbuf_get_width(info->pixbuf);
info->height = gdk_pixbuf_get_height(info->pixbuf);
glk_data->image_cache = g_slist_prepend(glk_data->image_cache, info);
gdk_threads_leave();
-
- g_object_unref(loader);
return info;
}
* @height: Pointer to a location at which to store the image's height.
*
* This gets information about the image resource with the given identifier. It
- * returns %TRUE if there is such an image, and %FALSE if not. You can also pass
- * pointers to width and height variables; if the image exists, the variables
- * will be filled in with the width and height of the image, in pixels. (You can
- * pass %NULL for either width or height if you don't care about that
- * information.)
+ * returns %TRUE (1) if there is such an image, and %FALSE (0) if not. You can
+ * also pass pointers to width and height variables; if the image exists, the
+ * variables will be filled in with the width and height of the image, in
+ * pixels. (You can pass %NULL for either width or height if you don't care
+ * about that information.)
*
* <note><para>
* You should always use this function to measure the size of images when you
glui32
draw_image_common(winid_t win, GdkPixbuf *pixbuf, glsi32 val1, glsi32 val2)
{
- GdkPixmap *canvas;
- gdk_threads_enter();
-
switch(win->type) {
case wintype_Graphics:
{
+ GdkPixmap *canvas;
+
+ gdk_threads_enter();
+
gtk_image_get_pixmap( GTK_IMAGE(win->widget), &canvas, NULL );
if(canvas == NULL) {
WARNING("Could not get pixmap");
/* Update the screen */
gtk_widget_queue_draw(win->widget);
+
+ gdk_threads_leave();
}
break;
case wintype_TextBuffer:
{
+ flush_window_buffer(win);
+
+ gdk_threads_enter();
+
GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
GtkTextIter end, start;
gtk_text_buffer_get_end_iter(buffer, &end);
- start = end;
- flush_window_buffer(win);
gtk_text_buffer_insert_pixbuf(buffer, &end, pixbuf);
+ start = end;
gtk_text_iter_forward_char(&end);
gint height = 0;
GtkTextTag *tag = gtk_text_buffer_create_tag(buffer, NULL, "rise", PANGO_SCALE * (-height), NULL);
gtk_text_buffer_apply_tag(buffer, tag, &start, &end);
}
+
+ gdk_threads_leave();
}
break;
-
}
-
- gdk_threads_leave();
return TRUE;
}