Nevron Forum

Mouse Hit Test and NPaintCallback

https://www.nevron.com/Forum/Topic5565.aspx

By Raul Kist - Friday, September 9, 2011

Hi!

Does anyone knows how can I get a Hit Test result different from Axis when clicking over a NPaintCallback drawn polygon?

Or how can I identify this polygon without having to calculate if the mouse is inside or outside?

Thanks a lot =]
Raul Kist
By Nevron Support - Monday, September 12, 2011

Hi Raul,

Can you post the code you're currently using?

By Raul Kist - Monday, September 12, 2011

The problem is that if I draw something using a "public override void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)" from NPaintCallback the HitTest always returns a Axis as result.

This way I can't know what am I clicking on.

I already solved this using this code to calculate if the point is In or Out the polygon:

private static bool pointInPolygon(PointF point, List polygon)
{
int polySides = polygon.Count;
float x = point.X;
float y = point.Y;
int i, j = polySides - 1;
bool oddNodes = false;

for (i = 0; i < polySides; i++)
{
if ((polygon[i].Y < y && polygon[j].Y >= y || polygon[j].Y < y && polygon[i].Y >= y) && (polygon[i].X <= x || polygon[j].X <= x))
{
if (polygon[i].X + (y - polygon[i].Y) / (polygon[j].Y - polygon[i].Y) * (polygon[j].X - polygon[i].X) < x)
{
oddNodes = !oddNodes;
}
}
j = i;
}

return oddNodes;
}

The problem I'm having now is how to make the chart data appear over the OnAfterPaint drawn polygon...
By Nevron Support - Tuesday, September 13, 2011

Hi Raul,

Did you try to move the code in BeforePaint?

By Raul Kist - Thursday, September 15, 2011

Sure =]

But it disappears as I draw more stuff in the chart (in the wall).

By Nevron Support - Monday, September 19, 2011

Hi Raul,

We see - we're currently thinking to introduce a custom paint series - this will allow you to hook the painting before or after the build in series - will that help?

By Raul Kist - Monday, September 19, 2011

I do think so =]

Anything that allows me to order the painting or the layers.

Another good thing is the possibility to identify what are you painting with a HitTest (it always return Axis).

This kind of thing allows one to build custom and more complex interactions on the charts.
By Nevron Support - Monday, January 23, 2012

With the next major version of the Chart control we will implement Custom Paint Series for 2D.