Bug 559056 - Transparent Shell's background but Opaque widget display on it
Summary: Transparent Shell's background but Opaque widget display on it
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.14   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-11 03:29 EST by Allen Jiang CLA
Modified: 2022-02-05 15:39 EST (History)
2 users (show)

See Also:


Attachments
the source png image (4.36 KB, image/png)
2020-01-11 03:30 EST, Allen Jiang CLA
no flags Details
use swt to display (246.30 KB, image/jpeg)
2020-01-11 03:30 EST, Allen Jiang CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Allen Jiang CLA 2020-01-11 03:29:05 EST
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.
Comment 1 Allen Jiang CLA 2020-01-11 03:30:11 EST
Created attachment 281452 [details]
the source png image
Comment 2 Allen Jiang CLA 2020-01-11 03:30:46 EST
Created attachment 281453 [details]
use swt to display
Comment 3 Allen Jiang CLA 2020-01-11 03:32:15 EST
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
	}

}
Comment 4 Allen Jiang CLA 2020-01-11 03:37:24 EST
my requirement as same as https://bugs.eclipse.org/bugs/show_bug.cgi?id=530152
Comment 5 Allen Jiang CLA 2020-01-11 04:06:27 EST
I have meet same problemn as follows:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=285026
Comment 6 Eclipse Genie CLA 2022-02-05 15:39:06 EST
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.