Question

I have a problem with the Mouse events!

I have subscribed to the event MouseEnter and MouseLeave. If my mouse cursor example is in the exact center of the panel, the MouseEnter and MouseLeave event triggered, why?

My goal would be to sense, starting from when the mouse cursor is on the 3D PlotCube and when not.

Code:

scene.MouseEnter += ILSurface_MouseEnter;
scene.MouseLeave += ILSurface_MouseLeave;
Was it helpful?

Solution

A plot cube catches events for the whole area of its ScreenRect rectangle. In a standard setup, this rectangle is set to (0,0,1,1) which fills the whole panel. So, unless you have multiple plot cubes / cameras on your panel, the mouse will basically always be on the plot cube.

In order to show the functioning of the MouseEnter and MouseLeave events nevertheless, I'll post an example which acts on a plot within the plot cube instead. It writes "On Plot" in the title bar of the form when the mouse enteres the plot. "Off Plot" is written as soon as the mouse leaves the plot.

Start with a fresh panel and setup ILNumerics as shown here: http://ilnumerics.net/visualization-api-quick-start-guide.html

Drag an ILPanel onto form1 and double click on it in order to switch to the code of the auto generated ilPanel1_Load event handler. Replace the handler with the following code:

private void ilPanel1_Load(object sender, EventArgs e) {

    var surfPlot = new ILSurface(ILMath.tosingle(ILSpecialData.sincf(50, 40))) {
        Colormap = Colormaps.Prism
    }; 

    var pc = ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
        surfPlot
    });

    surfPlot.MouseEnter += (_s, _a) => {
        if (!_a.DirectionUp)
            Text = "On Plot - Target: " + _a.Target.ToString();
    };
    surfPlot.MouseLeave += (_s, _a) => {
        if (!_a.DirectionUp)
            Text = "Off Plot - Target: " + _a.Target.ToString();
    };
}

This would produce a result similar to the following image: Hadling Mouse Enter and Mouse Leave in ILNumerics

The title of the form now reflects, if the mouse is on the plot or not. Note, that this is working regardless of the rotation / shape of the plot. The full documentation of the mouse event handling in ILNumerics is found here: http://ilnumerics.net/mouse-events.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top