Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Transparent Shell
Transparent Shell [message #1015785] Sat, 02 March 2013 14:15
Glenn Puckett is currently offline Glenn Puckett
Messages: 1
Registered: March 2013
Junior Member
I know this subject is beat on often. But evidently I have a bit of a unique challenge. When I search for this topic usually what I find is a way to handle an image in a label and force a transparent background. I need to do the same thing with buttons or labels on the shell, for both images as well as text.

After a lot of investigating I have been able to develop an SWT image label with a transparent background. It creates a mask(Region) from the image to determine what is painted.

Is it possible to access the entire shell and determine which pixels have the background color and which do not? If that information is available should it not be possible to create a mask for the entire shell to control what is drawn?

Here is the code I use for the transparent label:

private void paintControl(PaintEvent event) {
        ImageData imgData = this.labelImage.getImageData();
        Region region = new Region();
        if (imgData.alphaData != null) {
            Rectangle pixel = new Rectangle(0, 0, 1, 1);
            for (int y = 0; y < imgData.height; y++) {
                for (int x = 0; x < imgData.width; x++) {
                    if (imgData.getAlpha(x, y) == 255) {
                        pixel.x = imgData.x + x;
                        pixel.y = imgData.y + y;
                        region.add(pixel);
                    }
                }
            }
        } else {
            ImageData mask = imgData.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 = imgData.x + x;
                        pixel.y = imgData.y + y;
                        region.add(pixel);
                    }
                }
            }
        }
        this.setRegion(region);
        event.gc.drawImage(labelImage, 0, 0);
        region.dispose();
    }


I would like to perform a similar function on the entire shell. The objective is to enclose the transparent button in a shell so I can float the button over other components. The only way I can manage to do that now is to create a new shell and changes it's alpha value. But that turns everything that transparency. I want to set the shell's alpha at zero then modify the alphas of the labels back to 255. As you can see the current label paint process sets it to 255 but evidently the shell's alpha value is overriding the alpha of the label. So I need to manage that at the shell level.

Also I need to perform the same function with text. I have not been able to determine how to obtain a mask of text values. Any help along that line would be greatly appreciated.

Thank you.
Previous Topic:Setting specific background and border colors to buttons
Next Topic:SWT Browser (IE9) F12 Developer Tools
Goto Forum:
  


Current Time: Wed Aug 27 13:14:54 EDT 2014

Powered by FUDForum. Page generated in 0.01746 seconds