changeset 1069:a1deca9b0876

Attempt at scaling bitmaps if they are too big for where they are packed on GTK3.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 25 Jun 2011 02:05:11 +0000
parents efaa9ceeb253
children 4293f5ba4330
files gtk3/dw.c
diffstat 1 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gtk3/dw.c	Fri Jun 24 04:22:39 2011 +0000
+++ b/gtk3/dw.c	Sat Jun 25 02:05:11 2011 +0000
@@ -3172,6 +3172,7 @@
    tmp = gtk_image_new();
    gtk_widget_show(tmp);
    g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
+   g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", tmp);
    DW_MUTEX_UNLOCK;
    return tmp;
 }
@@ -3849,6 +3850,7 @@
    {
       dw_window_set_bitmap(bitmap, id, NULL);
       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
+      g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
    }
    gtk_widget_show(tmp);
    if(text)
@@ -3885,6 +3887,8 @@
    box = gtk_hbox_new (FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (box), 2);
 
+   /* Create a new button */
+   button = gtk_button_new();
    /* Now on to the image stuff */
    bitmap = dw_bitmap_new(id);
    if(bitmap)
@@ -3893,6 +3897,7 @@
       /* Pack the image into the box */
       gtk_box_pack_start( GTK_BOX(box), bitmap, TRUE, FALSE, 3 );
       gtk_widget_show( bitmap );
+      g_object_set_data(G_OBJECT(button), "_dw_bitmap", bitmap);
    }
    if(label_text)
    {
@@ -3902,8 +3907,6 @@
       gtk_box_pack_start( GTK_BOX(box), label, TRUE, FALSE, 3 );
       gtk_widget_show( label );
    }
-   /* Create a new button */
-   button = gtk_button_new();
 
    /* Pack and show all our widgets */
    gtk_widget_show( box );
@@ -3941,6 +3944,7 @@
    {
       dw_window_set_bitmap_from_data(bitmap, 0, data, len);
       gtk_container_add (GTK_CONTAINER(tmp), bitmap);
+      g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
    }
    gtk_widget_show(tmp);
    if(text)
@@ -8012,7 +8016,7 @@
 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
 {
    int warn = FALSE, _locked_by_me = FALSE;
-   GtkWidget *tmp, *tmpitem;
+   GtkWidget *tmp, *tmpitem, *image = NULL;
 
    if(!box)
       return;
@@ -8037,6 +8041,22 @@
       item = gtk_label_new("");
       gtk_widget_show_all(item);
    }
+   else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
+   {
+      GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); 
+		  
+      if(pixbuf)
+      {
+         int pwidth = gdk_pixbuf_get_width(pixbuf);
+         int pheight = gdk_pixbuf_get_height(pixbuf);
+
+         if(pwidth > width || pheight > height)
+         {
+            pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
+            gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
+         }
+      }
+   }
 
    tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
 
@@ -9406,6 +9426,22 @@
       item = gtk_label_new("");
       gtk_widget_show_all(item);
    }
+   else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
+   {
+      GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); 
+		  
+      if(pixbuf)
+      {
+         int pwidth = gdk_pixbuf_get_width(pixbuf);
+         int pheight = gdk_pixbuf_get_height(pixbuf);
+
+         if(pwidth > width || pheight > height)
+         {
+            pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
+            gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
+         }
+      }
+   }
 
    tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");