diff options
author | Felipe Heidrich <fheidric> | 2005-05-09 17:54:20 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2005-05-09 17:54:20 +0000 |
commit | 1a6a67f9df122e586724d5c54e1a58995ea075df (patch) | |
tree | d739e4a3d933e180b9139371876cb8a1918105dc /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java | |
parent | dcd9f7243ae1ad05751547f983b76748a1e6687b (diff) | |
download | eclipse.platform.swt-1a6a67f9df122e586724d5c54e1a58995ea075df.tar.gz eclipse.platform.swt-1a6a67f9df122e586724d5c54e1a58995ea075df.tar.xz eclipse.platform.swt-1a6a67f9df122e586724d5c54e1a58995ea075df.zip |
94003
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java | 130 |
1 files changed, 73 insertions, 57 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java index 8f7919bf39..50a86675c3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java @@ -38,61 +38,6 @@ public int add (Image image) { if (images [index] == null) break; index++; } - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ colormap = OS.gdk_colormap_get_system (); - int /*long*/ pixbuf; - boolean hasMask = image.mask != 0; - if (hasMask) { - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - int /*long*/ gdkMaskImagePtr = OS.gdk_drawable_get_image (image.mask, 0, 0, w [0], h [0]); - if (gdkMaskImagePtr == 0) SWT.error (SWT.ERROR_NO_HANDLES); - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - if (OS.gdk_image_get_pixel (gdkMaskImagePtr, x, y) == 0) { - line [x*4+3] = 0; - } - } - OS.memmove (offset, line, stride); - } - OS.g_object_unref (gdkMaskImagePtr); - } else { - ImageData data = image.getImageData (); - boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - if (hasAlpha) { - byte [] alpha = data.alphaData; - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - line [x*4+3] = alpha [y*w [0]+x]; - } - OS.memmove (offset, line, stride); - } - } - } - if (width == -1 || height == -1) { - width = w [0]; - height = h [0]; - } - if (w [0] != width || h [0] != height) { - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR); - OS.g_object_unref (pixbuf); - pixbuf = scaledPixbuf; - } if (index == images.length) { Image [] newImages = new Image [images.length + 4]; System.arraycopy (images, 0, newImages, 0, images.length); @@ -101,8 +46,7 @@ public int add (Image image) { System.arraycopy (pixbufs, 0, newPixbufs, 0, pixbufs.length); pixbufs = newPixbufs; } - pixbufs [index] = pixbuf; - images [index] = image; + set (index, image); return index; } @@ -143,6 +87,18 @@ public boolean isDisposed () { return images == null; } +public void put (int index, Image image) { + int count = images.length; + if (!(0 <= index && index < count)) return; + if (image != null) { + set (index, image); + } else { + images [index] = null; + if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); + pixbufs [index] = 0; + } +} + public void remove (Image image) { if (image == null) return; for (int index=0; index<images.length; index++) { @@ -154,6 +110,66 @@ public void remove (Image image) { } } +void set (int index, Image image) { + int [] w = new int [1], h = new int [1]; + OS.gdk_drawable_get_size (image.pixmap, w, h); + int /*long*/ colormap = OS.gdk_colormap_get_system (); + int /*long*/ pixbuf; + boolean hasMask = image.mask != 0; + if (hasMask) { + pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); + if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); + int /*long*/ gdkMaskImagePtr = OS.gdk_drawable_get_image (image.mask, 0, 0, w [0], h [0]); + if (gdkMaskImagePtr == 0) SWT.error (SWT.ERROR_NO_HANDLES); + int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); + int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); + byte [] line = new byte [stride]; + for (int y = 0; y < h [0]; y++) { + int /*long*/ offset = pixels + (y * stride); + OS.memmove (line, offset, stride); + for (int x = 0; x < w [0]; x++) { + if (OS.gdk_image_get_pixel (gdkMaskImagePtr, x, y) == 0) { + line [x*4+3] = 0; + } + } + OS.memmove (offset, line, stride); + } + OS.g_object_unref (gdkMaskImagePtr); + } else { + ImageData data = image.getImageData (); + boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; + pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); + if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); + if (hasAlpha) { + byte [] alpha = data.alphaData; + int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); + int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); + byte [] line = new byte [stride]; + for (int y = 0; y < h [0]; y++) { + int /*long*/ offset = pixels + (y * stride); + OS.memmove (line, offset, stride); + for (int x = 0; x < w [0]; x++) { + line [x*4+3] = alpha [y*w [0]+x]; + } + OS.memmove (offset, line, stride); + } + } + } + if (width == -1 || height == -1) { + width = w [0]; + height = h [0]; + } + if (w [0] != width || h [0] != height) { + int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR); + OS.g_object_unref (pixbuf); + pixbuf = scaledPixbuf; + } + pixbufs [index] = pixbuf; + images [index] = image; +} + public int size () { int result = 0; for (int index=0; index<images.length; index++) { |