Mercurial > dwindows
comparison gtk3/dw.c @ 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 | 2accf180bcfe |
children | 4293f5ba4330 |
comparison
equal
deleted
inserted
replaced
1068:efaa9ceeb253 | 1069:a1deca9b0876 |
---|---|
3170 | 3170 |
3171 DW_MUTEX_LOCK; | 3171 DW_MUTEX_LOCK; |
3172 tmp = gtk_image_new(); | 3172 tmp = gtk_image_new(); |
3173 gtk_widget_show(tmp); | 3173 gtk_widget_show(tmp); |
3174 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 3174 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
3175 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", tmp); | |
3175 DW_MUTEX_UNLOCK; | 3176 DW_MUTEX_UNLOCK; |
3176 return tmp; | 3177 return tmp; |
3177 } | 3178 } |
3178 | 3179 |
3179 /* | 3180 /* |
3847 | 3848 |
3848 if(bitmap) | 3849 if(bitmap) |
3849 { | 3850 { |
3850 dw_window_set_bitmap(bitmap, id, NULL); | 3851 dw_window_set_bitmap(bitmap, id, NULL); |
3851 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 3852 gtk_container_add (GTK_CONTAINER(tmp), bitmap); |
3853 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); | |
3852 } | 3854 } |
3853 gtk_widget_show(tmp); | 3855 gtk_widget_show(tmp); |
3854 if(text) | 3856 if(text) |
3855 { | 3857 { |
3856 gtk_widget_set_tooltip_text(tmp, text); | 3858 gtk_widget_set_tooltip_text(tmp, text); |
3883 | 3885 |
3884 /* Create box for image and label */ | 3886 /* Create box for image and label */ |
3885 box = gtk_hbox_new (FALSE, 0); | 3887 box = gtk_hbox_new (FALSE, 0); |
3886 gtk_container_set_border_width (GTK_CONTAINER (box), 2); | 3888 gtk_container_set_border_width (GTK_CONTAINER (box), 2); |
3887 | 3889 |
3890 /* Create a new button */ | |
3891 button = gtk_button_new(); | |
3888 /* Now on to the image stuff */ | 3892 /* Now on to the image stuff */ |
3889 bitmap = dw_bitmap_new(id); | 3893 bitmap = dw_bitmap_new(id); |
3890 if(bitmap) | 3894 if(bitmap) |
3891 { | 3895 { |
3892 dw_window_set_bitmap( bitmap, 0, filename ); | 3896 dw_window_set_bitmap( bitmap, 0, filename ); |
3893 /* Pack the image into the box */ | 3897 /* Pack the image into the box */ |
3894 gtk_box_pack_start( GTK_BOX(box), bitmap, TRUE, FALSE, 3 ); | 3898 gtk_box_pack_start( GTK_BOX(box), bitmap, TRUE, FALSE, 3 ); |
3895 gtk_widget_show( bitmap ); | 3899 gtk_widget_show( bitmap ); |
3900 g_object_set_data(G_OBJECT(button), "_dw_bitmap", bitmap); | |
3896 } | 3901 } |
3897 if(label_text) | 3902 if(label_text) |
3898 { | 3903 { |
3899 /* Create a label for the button */ | 3904 /* Create a label for the button */ |
3900 label = gtk_label_new( label_text ); | 3905 label = gtk_label_new( label_text ); |
3901 /* Pack the label into the box */ | 3906 /* Pack the label into the box */ |
3902 gtk_box_pack_start( GTK_BOX(box), label, TRUE, FALSE, 3 ); | 3907 gtk_box_pack_start( GTK_BOX(box), label, TRUE, FALSE, 3 ); |
3903 gtk_widget_show( label ); | 3908 gtk_widget_show( label ); |
3904 } | 3909 } |
3905 /* Create a new button */ | |
3906 button = gtk_button_new(); | |
3907 | 3910 |
3908 /* Pack and show all our widgets */ | 3911 /* Pack and show all our widgets */ |
3909 gtk_widget_show( box ); | 3912 gtk_widget_show( box ); |
3910 gtk_container_add( GTK_CONTAINER(button), box ); | 3913 gtk_container_add( GTK_CONTAINER(button), box ); |
3911 gtk_widget_show( button ); | 3914 gtk_widget_show( button ); |
3939 | 3942 |
3940 if ( bitmap ) | 3943 if ( bitmap ) |
3941 { | 3944 { |
3942 dw_window_set_bitmap_from_data(bitmap, 0, data, len); | 3945 dw_window_set_bitmap_from_data(bitmap, 0, data, len); |
3943 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 3946 gtk_container_add (GTK_CONTAINER(tmp), bitmap); |
3947 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); | |
3944 } | 3948 } |
3945 gtk_widget_show(tmp); | 3949 gtk_widget_show(tmp); |
3946 if(text) | 3950 if(text) |
3947 { | 3951 { |
3948 gtk_widget_set_tooltip_text(tmp, text); | 3952 gtk_widget_set_tooltip_text(tmp, text); |
8010 * pad: Number of pixels of padding around the item. | 8014 * pad: Number of pixels of padding around the item. |
8011 */ | 8015 */ |
8012 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 8016 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
8013 { | 8017 { |
8014 int warn = FALSE, _locked_by_me = FALSE; | 8018 int warn = FALSE, _locked_by_me = FALSE; |
8015 GtkWidget *tmp, *tmpitem; | 8019 GtkWidget *tmp, *tmpitem, *image = NULL; |
8016 | 8020 |
8017 if(!box) | 8021 if(!box) |
8018 return; | 8022 return; |
8019 | 8023 |
8020 /* | 8024 /* |
8034 | 8038 |
8035 if(!item) | 8039 if(!item) |
8036 { | 8040 { |
8037 item = gtk_label_new(""); | 8041 item = gtk_label_new(""); |
8038 gtk_widget_show_all(item); | 8042 gtk_widget_show_all(item); |
8043 } | |
8044 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) | |
8045 { | |
8046 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); | |
8047 | |
8048 if(pixbuf) | |
8049 { | |
8050 int pwidth = gdk_pixbuf_get_width(pixbuf); | |
8051 int pheight = gdk_pixbuf_get_height(pixbuf); | |
8052 | |
8053 if(pwidth > width || pheight > height) | |
8054 { | |
8055 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); | |
8056 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); | |
8057 } | |
8058 } | |
8039 } | 8059 } |
8040 | 8060 |
8041 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); | 8061 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); |
8042 | 8062 |
8043 if(GTK_IS_TABLE(box)) | 8063 if(GTK_IS_TABLE(box)) |
9404 if (!item) | 9424 if (!item) |
9405 { | 9425 { |
9406 item = gtk_label_new(""); | 9426 item = gtk_label_new(""); |
9407 gtk_widget_show_all(item); | 9427 gtk_widget_show_all(item); |
9408 } | 9428 } |
9429 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) | |
9430 { | |
9431 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); | |
9432 | |
9433 if(pixbuf) | |
9434 { | |
9435 int pwidth = gdk_pixbuf_get_width(pixbuf); | |
9436 int pheight = gdk_pixbuf_get_height(pixbuf); | |
9437 | |
9438 if(pwidth > width || pheight > height) | |
9439 { | |
9440 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); | |
9441 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); | |
9442 } | |
9443 } | |
9444 } | |
9409 | 9445 |
9410 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); | 9446 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); |
9411 | 9447 |
9412 if (GTK_IS_TABLE(box)) | 9448 if (GTK_IS_TABLE(box)) |
9413 { | 9449 { |