Mouse Events
In this tutorial we want to take a closer look at how mouse events can be applied in ILNumerics.
The first example displays a unit circle. While the radius adopts the position of the mouse inside the circle, the corresponding angle is computed. Furthermore, the radius is divided into its horizontal and vertical component.
To begin with the individual objects for the unit circle are created. It consists of a big circle, a small circle that moves on the circumference of the big circle, a line plot that is used to create the inner circle, lines that represent the radius, its components and the auxiliary lines. Furthermore, a screen object is added that contains a label. The label indicates the current angle in degrees. Next to the positions, the size and colors are specified for each object.
Next, the mouse event MouseMove of the big circle is specified. This mouse event is only triggered if the mouse is moved within the big circle.
Inside the mouse event the current position relative to the current viewport is extracted. The origin of the viewport's coordinate system is placed at the top left corner. While its X-Axis points to the right, the Y-Axis is oriented downward. For our purpose, we will have to move the origin of the coordinate system to the center of the big circle. On top of that the Y-Axis is modified to point upward.
On the basis of the transformed coordinates, we can then compute the current angle.
The angle is used to update the positions of the small circle on the circumference, the inner circle, the radius and its components.
Since the resulting angles either range from 0 to 180 or from 0 to -180, they have to be edited to create a continous inner circle.
After making changes, the method Configure() of each object must be called, in order to popuplate the modifications to the driver. On top of that, ilPanel1.Refresh() must be called.
Putting the code from above together, results in the following: