Community
Participate
Working Groups
Hi SWT developers, my requirement is to display a image on Shell ,to expect the shell's background is transparency and the image of png formate need to display. but using alpha everything is affected, the shell it self and all its content. but i only want to set the transparency for the background and not for the widgets on it.
Created attachment 281452 [details] the source png image
Created attachment 281453 [details] use swt to display
here is my code as follows: package com.imi.soya.ui; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.wb.swt.SWTResourceManager; public class LoginUI extends Shell { /** * Launch the application. * * @param args */ public static void main(String args[]) { try { Display display = Display.getDefault(); LoginUI shell = new LoginUI(display); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } catch (Exception e) { e.printStackTrace(); } } /** * Create the shell. * * @param display */ public LoginUI(Display display) { super(display, SWT.NO_TRIM); this.setBackgroundMode(SWT.INHERIT_DEFAULT); createContents(); } /** * Create contents of the shell. */ protected void createContents() { setText("SWT Application"); Image image = SWTResourceManager.getImage(this.getClass(), "/resource/assets/login/login_bg.png"); Region region = new Region(); final ImageData imageData = image.getImageData(); if (imageData.alphaData != null) { Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < imageData.height; y++) { for (int x = 0; x < imageData.width; x++) { if (imageData.getAlpha(x, y) >0) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add(pixel); } } } } else { ImageData mask = imageData.getTransparencyMask(); Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { if (mask.getPixel(x, y) != 0) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add(pixel); } } } } this.setRegion(region); final Shell shell = this; Listener listener = new Listener() { /** The x/y of the MouseDown, relative to top-left of the shell. */ int startX, startY; @Override public void handleEvent(Event e) { if (e.type == SWT.MouseDown) { Point p = shell.toDisplay(e.x, e.y); Point loc = shell.getLocation(); startX = p.x - loc.x; startY = p.y - loc.y; } if (e.type == SWT.MouseMove && (e.stateMask) != 0) { Point p = shell.toDisplay(e.x, e.y); p.x -= startX; p.y -= startY; shell.setLocation(p); } if (e.type == SWT.Paint) { //e.gc.setAdvanced(true); //e.gc.setAntialias(SWT.ON); e.gc.drawImage(image, imageData.x, imageData.y); } } }; this.addListener(SWT.Paint, listener); shell.addListener(SWT.KeyDown, listener); shell.addListener(SWT.MouseDown, listener); shell.addListener(SWT.MouseMove, listener); shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TRANSPARENT)); setSize(450, 419); } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } }
my requirement as same as https://bugs.eclipse.org/bugs/show_bug.cgi?id=530152
I have meet same problemn as follows: https://bugs.eclipse.org/bugs/show_bug.cgi?id=285026
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.