Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Rubber-banding
Rubber-banding [message #445147] Wed, 27 October 2004 02:37 Go to next message
Keith Tingle is currently offline Keith TingleFriend
Messages: 3
Registered: July 2009
Junior Member
Hi-

I have been implementing a rubber-banding style selection box with the
basic algorithm below;

// MouseMoveListener overrides
public void mouseMove(MouseEvent e) {
if (_ptAnchor != null) {
GC gc = new GC(this);

// This is the same as a !XOR
gc.setXORMode(true);
gc.setForeground(gc.getBackground());

// Erase existing rectangle
if (_rectLast != null) {
gc.drawRectangle(_rectLast);

// Normalize
...

// Draw selection rectangle
gc.drawRectangle(x, y, width, height);

I was wondering if there is a cleaner way to do rubber-banding selection
boxes in SWT. Is there a way to access a NOTXOR-style drawing mode
instead of having to swap background and foreground colors with a
positive XOR?

Is this the best I can do? I get _some_ flicker and when the rectangle
overlaps itself I get a magenta color that I would rather avoid.

I tried the Tracker class, but it forces a change in the mouse pointer
style, I looked for the source of Tracker and couldn't locate it, is it
implemented natively?

Thanks for any assistance.
Re: Rubber-banding [message #445182 is a reply to message #445147] Wed, 27 October 2004 15:21 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You should try to use the Tracker class to do this kind of work. Can you
provide more detail (or better, some code) that shows why Tracker doesn't
cut it?

"Keith Tingle" <ktingle@bellsouth.net> wrote in message
news:cln1ar$lep$1@eclipse.org...
> Hi-
>
> I have been implementing a rubber-banding style selection box with the
> basic algorithm below;
>
> // MouseMoveListener overrides
> public void mouseMove(MouseEvent e) {
> if (_ptAnchor != null) {
> GC gc = new GC(this);
>
> // This is the same as a !XOR
> gc.setXORMode(true);
> gc.setForeground(gc.getBackground());
>
> // Erase existing rectangle
> if (_rectLast != null) {
> gc.drawRectangle(_rectLast);
>
> // Normalize
> ...
>
> // Draw selection rectangle
> gc.drawRectangle(x, y, width, height);
>
> I was wondering if there is a cleaner way to do rubber-banding selection
> boxes in SWT. Is there a way to access a NOTXOR-style drawing mode
> instead of having to swap background and foreground colors with a
> positive XOR?
>
> Is this the best I can do? I get _some_ flicker and when the rectangle
> overlaps itself I get a magenta color that I would rather avoid.
>
> I tried the Tracker class, but it forces a change in the mouse pointer
> style, I looked for the source of Tracker and couldn't locate it, is it
> implemented natively?
>
> Thanks for any assistance.
Previous Topic:Capturing key event F5 in TabFolder
Next Topic:Workaround for 69304 (table headers disappearing when inside a Form)
Goto Forum:
  


Current Time: Sun Oct 25 17:51:32 GMT 2020

Powered by FUDForum. Page generated in 0.02557 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top