Graphics    

Defining Custom Pointers

When you set the Pointer property to custom, MATLAB displays the pointer you define using the PointerShapeCData and the PointerShapeHotSpot properties. Custom pointers are 16-by-16 pixels, where each pixel can be either black, white, or transparent.

Specify the pointer by creating a 16-by-16 matrix containing elements that are:

Assign the matrix to the figure PointerShapeCData property. MATLAB displays the defined pointer whenever the pointer is in the figure window.

The PointerShapeHotSpot property specifies the pixel that indicates the pointer location. MATLAB then stores this location in the root PointerLocation property. Set the PointerShapeHotSpot property to a two-element vector specifying the row and column indices in the PointerShapeCData matrix that corresponds to the pixel specifying the location. The default value for this property is [1 1], which corresponds to the upper-left corner of the pointer.

Example - Two Custom Pointers

One way to create a custom pointer is to assign values to a 16-by-16 matrix by hand, as illustrated in the following example.

First, initialize the matrix, setting all values to 2. Create a black border 1 pixel wide. Add alignment marks.

The last statement sets the Pointer property to custom, assigns the matrix to the PointerShapeCData property, and selects the "hot spot" as element (9,9).

MATLAB now uses the custom pointer within the figure window.

Creating Pointers from Functions.   You can use a mathematical function to define the PointerShapeCData matrix. For example, evaluating the function,

produces an interesting surface.

Use the values of Z to create a pointer sampling fewer points so that Z is a 16-by-16 matrix.

The statement, flipud((Z>0) + 1) sets all values in Z that are greater than zero to two (in MATLAB, true + 1 = 2), less than zero to one (false + 1 = 1) and then flips the data around so that element (1,1) is the upper-left corner.


  Specifying the Figure Pointer Interactive Graphics