Question

so I'd like to draw a coloured (red) area over the top of an existing canvas drawing, like a red tinted lens being placed over it, so the original image is still visible underneath.

The problem is that I am extending a canvas that draws it's own image and I am drawing over the top of it.

How can I do this?

Était-ce utile?

La solution

In your Canvas paint() method,

  1. draw image
  2. gc.setAlpha(100) //decide your value
  3. gc.fillRectangle(rect) //rect is client area of the canvas

I believe you should get what you are looking for.

Autres conseils

The naive solution is to add a SWT.Paint event listener to the Canvas, as that can run into problems as we don't know the sequence of calls to listeners (have a look at EventTable.hook() which will reuse an old slot in the listener table before adding to the end of the table...). Thus the original listener might run before or after your listener.

A better solution - which I have not tried, but believe to work - whould be to add a new Composite on top of the original Canvas and then add your listener to this widget, as any Paint listener of the new Composite is guaranteed to run after all listeners on the Canvasitself. Remember to

  • add a Size listener to the Canvas to make sure the size of the Composite is always correct
  • use setBackgroundMode(SWT.INHERIT_FORCE) on the Canvas

setting the alpha value to a canvas only dims the color and does not make it transparent. Actual transparent gui in possible only with shell by using shell.setAlpha(x);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top