Re: Drawing graphics and responding to events

samir parekh <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
I quiet forgot...there were graphics/drawing objects in VB (must be activex components/controls) which provided the same functionality...I had  used them for a similar situation in one of my projects...

Y dont u use them...straight out of the box...

thanks
samir

samir parekh <[email protected]> wrote: I think you need to track the mouse coordinates...


there is a possible solution


keep track of all the mid-points of circles on the form...

then on mouse move check whether the distance detween two points
( mouse coordinates and centre (1--- till the end of the array))
 is > the radius of the circle

there you go

if you like you can also use derivatives formulas ( dy/dx , we used to study them...they seem to be simpler as far as the calculations are concerned... )

to find whether a point belongs to a particular circle or not...


thanks & regards
samir

Peter Osucha
 wrote: John,

Thanks for the reply.  The case I have is a very simple one - all the
shapes are on a grid and there is no overlap.  The circles cannot be
moved at runtime.  As far as the bounding rectangles go, I'm not sure I
follow you.  If the mouse moves over the area of a bounding rectangle
that is outside a circle - you know, the area between the bounding
rectangle corner and the circle edge - than no circle should be
'selected'.

As far as the GraphicsPath thing goes, you are right in that it does not
seem to be that responsive.  Of course, it depends to some extent on the
number of circles in the grid (its obviously faster if I have a grid of
4x4 circles instead of a grid of 20x20 circles).

As far as UI constraints, yes, flicker is about the only thing (well,
responsiveness is important, of course).

The user will interact with this 'grid' by selecting circles they want
to include for further processing.  They should be able to 'select' a
circle by either clicking on it or by 'dragging a border around a group
of circles.

Peter

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
John Brett
Sent: Wednesday, April 25, 2007 5:04 AM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Drawing graphics and responding to events

This may be an obvious comment, but it is worth caching the last
selected Circle object and optimizing the very common case in which
the mouse has moved but is still within the same circle.

You don't state any of the constraints on the locations of your
circles - are they
static locations or can they move at run-time? Do the circles ever
overlap their
bounding rectangles, or overlap each other?

If the locations of the circles is static, then you should be able to
speed up the searching process by designating bounding rectangles
around discrete sets of circles - e.g if the circles are approximately
on a grid, then put 20 bounding rectangles around rows of 20 circles.
You can then search the outer bounding rectangles to find the row to
search, and then search only that. This would cut down the number of
comparisons from ~(20*20)/2 to ~(20+20)/2.

If your circles don't ever overlap their bounding rectangles, then
testing the point for inclusion within the rectangle is going to be
the easiest option.

If the bounding rectangles can overlap, then you can determine whether
a point is within a circle by calculating the distance between the
point and the centre, and comparing it with the radius.


PointF circlePos;
PointF mousePos;

double distX= (circlePos.X - mousePos.X);
double distY= (circlePos.Y - mousePos.Y);
double distSquared= distX*distX + distY*distY;

if (distSquared < radiusSquared)
{
   // point within circle.
}


If the circles can overlap then you need to manage some sort of
Z-order & arbitration if the mouse is over two or more circles.

Using a GraphicsPath gives aesthetically pleasing code, but I doubt
it's going to be as quick as comparing co-ordinates (given that it has
to deal with arbitrarily complex shapes, and you're working with about
the easiest shape to optimise).
BTW - what are your efficiency constraints? Given that this is appears
to be a UI issue, then I'd suggest that the only criteria that matters
is whether the user perceives any flickering or delay whilst moving
the mouse.

John










---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.











---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.