In your Canvas paint()
method,
- draw image
gc.setAlpha(100)
//decide your valuegc.fillRectangle(rect)
//rect is client area of the canvas
I believe you should get what you are looking for.
Frage
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?
Lösung
In your Canvas paint()
method,
gc.setAlpha(100)
//decide your valuegc.fillRectangle(rect)
//rect is client area of the canvasI believe you should get what you are looking for.
Andere Tipps
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 Canvas
itself. Remember to
Size
listener to the Canvas
to make sure the size of the Composite
is always correctsetBackgroundMode(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);