I have an SWT Canvas with some image on it. I want my user to select parts of the image by clicking, holding the left mouse button and opening a selection box by moving the mouse. As a visual feedback I want to show the selected rectangle as a transparent overlay over my image.
The problem is I have not clue how to best achieve this? Can someone give me a hint?
There is another approach that native platform provides to do this. Use SWT
org.eclipse.swt.widgets.Tracker
How do I make it possible to resize a composite by dragging the corner
My answer is somehow similar to the one I gave here:
SWTChart mouse event handling
The code below should give you an idea on where to start. It basically remembers the location of a
MouseDown
event. Each time the mouse is then dragged, a rectangle is drawn from the starting location to the current location. OnceMouseUp
happens, everything stops.It looks like this: