🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #4711

Re: Rubberbanding a rectangle

#4711
From: Robin Rosenberg INF
Date: Sun, 05 Aug 1990 16:26
55 lines
2560 bytes
Kari Sutela writes:

>Here is a small problem which I have been unable to solve:
>
>I need a function which would enable one to rubberband a rectangle
>with the mouse. The user should click in the top/left corner where
>he wants the rectangle to start. While holding down the left mouse
>button he then drags the mouse to the bottom/right corner of the
>rectangle. Now, this is simple.
>
>Nevertheless, I haven't found an acceptable method of preventing the user
>from dragging the bottom/right corner beyond the top/left corner. What I
>mean is that the bottom/right corner should always be to the right and
>below the top/left corner.

Why shouldn't the user be able to start with any corner. Forcing the user
to specify the topleft corner is not really necessary and it solves your 
problem. Using an input handler is quite farfetched. It is quite simple to
let the used specify any two points:

Write a function to take two points p1=the point the user selecte first and p2=the point represented by the current mouse position. Then it comes out with two new points such that 
p1fixed.x = min(p1.x,p2.x);
p2fixed.x = max(p1.x,p2.x);
p1fixed.y = min(p1.y,p2.y);
p2fiuxe.y = max(p1.y,p2.y);

For example the rectangle specfied using p1(2,5) and p2=(10,1) , i.e
p1 is the bottom left corner and p2 is the upper right corner. becomes
p1fixed=(2,1) and p2fixed=(10,5) which have the properties you said
you wanted.

Then p1fixed is above and left of p2fixed or at the same position.

Have another routine limit the values of p1fixed and p2fixed so they stay 
within the allowed area and yet another routine to draw a rectangle using the

	p1 = StartCoordinate;
	drawn=FALSE;
	while(dragging) {
		if (drawn)
			undrawrect(&p1fixed,&p2fixed);
		p2 = CurrentCoordinate;
		fixpoints(&p1,&p2,&p1fixed,&p2fixed);
		limit(&p1fixed,&p2fixed, minx,miny,maxx,maxy);
		drawrect(&p1fixed,&p2fixed);
		drawn = TRUE;
		...
	}
	undrawrect(&p1fixed,&p2fixed);

--
	Robin

disclaimer >nil:
Technical Details
Message-ID: <ROSENBER.90Aug5192630@ra.abo.fi>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uwm.edu!rpi!uupsi!sunic!tut!ra!rosenber
References: <1990Aug5.105804.16250@utu.fi>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uwm.edu!rpi!uupsi!sunic!tut!ra!rosenber
From: rosenber@ra.abo.fi (Robin Rosenberg INF)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Rubberbanding a rectangle
Message-ID: <ROSENBER.90Aug5192630@ra.abo.fi>
Date: 5 Aug 90 16:26:30 GMT
References: <1990Aug5.105804.16250@utu.fi>
Sender: rosenber@ra.abo.fi
Organization: Abo Akademi University, Finland
Lines: 55
In-reply-to: sutela@polaris.utu.fi's message of 5 Aug 90 10:58:04 GMT