[1063] in java-interest

home help back first fref pref prev next nref lref last post

Re: Rubber-banding and XOR

daemon@ATHENA.MIT.EDU (Ed Anuff)
Thu Aug 17 21:59:35 1995

Date: Thu, 17 Aug 1995 11:00:06 -0800
To: java-interest@java.sun.com
From: edanuff@protagonist.com (Ed Anuff)
Cc: Michael.Gibbons@mcl.co.uk

There was an approach listed in an earlier post that involved making
changes to the sources.  I used a different approach for rubberbanding
while trying to build a mini draw program as an applet.  You can check this
out at http://www.protagonist.com/java/.  The source isn't there yet, but
will hopefully soon be, once I've finished it.  It only lets you resize
shapes right now, but hopefully it conveys the idea.  As you'll see, I
don't use XOR for handling the rubber band effect.  Under the current
drawing model, where drawing only takes place in the paint() method, its
difficult to implement this effect.

I'm sure that there are a number of ways to accomplish this, but what I did
was simply create a MouseThread class to handle the cursor tracking, and
have the calls to the applet's mouse methods (mouseDown, mouseDrag, etc.)
call corresponding methods in the thread object in order to update instance
variables containing the cursor's position, the button state, etc.  That
way, I can just subclass the MouseThread class and the run() method can be
very simple:

        public void run() {
                SizeObj.Select();

                while (button) {
                        SizeGrabHandle.SetPt(mouse_x, mouse_y);
                        parent.repaint();
                        sleep(100);
                }
                done = true;
        }

This way, I can also create different MouseThread subclasses to handle
different types of tracking tasks, like moving objects vs. resizing them.
The MouseThread class looks like this:

class MouseThread extends Thread{

        boolean done;
        boolean button;
        int anchor_x;
        int anchor_y;
        int mouse_x;
        int mouse_y;
        JavaDraw parent;

        MouseThread(JavaDraw parent_applet, int x, int y, boolean
button_state) {
                button = button_state;
                anchor_x = x;
                anchor_y = y;
                mouse_x = x;
                mouse_y = y;
                done = false;
                parent = parent_applet;

                start();
        }

        public void run() {
                while (button) {
                }
                done = true;
        }

        public void mouseDown(int x, int y) {
                button = true;
                mouse_x = x;
                mouse_y = y;
        }

        public void mouseDrag(int x, int y) {
                button = true;
                mouse_x = x;
                mouse_y = y;
        }

        public void mouseUp(int x, int y) {
                button = false;
                mouse_x = x;
                mouse_y = y;
        }

        public void mouseMove(int x, int y) {
                mouse_x = x;
                mouse_y = y;
        }

        public void mouseEnter() {}

        public void mouseExit() {}

}


Ed


Ed Anuff
edanuff@protagonist.com
http://www.protagonist.com/


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post