Eclipse RCP Draw2d Transparency (setAlpha) makes borders / outline invisible

965 Views Asked by At

We are providing users option to make figures drawn on canvas transparent. To achieve this we are using method setAlpha(0). But this makes figure completely invisible.

Our requirement is that outline / border should be shown on transparent figures if user wishes to have borders.

We tried using method setOpaque(false). But it does not work. We are using Ubuntu 9.1 OS.

Any suggestion to achieve this will be really helpful.

Regards, Pankaj Sharma

2

There are 2 best solutions below

0
On

You could extend the Shape you are using like this:

public class TranslucentRoundedRectangle extends RoundedRectangle
{
  @Override
  protected void fillShape(Graphics graphics)
  {
    int oldAlpha = graphics.getAlpha();

    graphics.setAlpha(128);
    super.fillShape(graphics);
    graphics.setAlpha(oldAlpha);
  }
}

This way you can set the alpha value for the filling independently of the outline.

0
On

setAlpha is applied to the whole figure, that is why it doesn't work for you. What you should probably do is create two figures one inside the other and change the alpha of the inner figure only. I can't think of another way to do it. Good luck