Specifying the Figure Pointer

Predefined Figure Pointer Symbols

The MATLAB® software indicates the position of the pointer (cursor) within the figure window using a graphical symbol. You can select a pointer from 15 predefined symbols (see table below) or you can define your own symbol. By convention, each of the predefined symbols has a purpose associated with it (although MATLAB enforces no rules for the use of any symbols).

You specify the pointer symbol by setting the value of the figure Pointer property. For example, this statement sets the pointer in the current figure (gcf) to an arrow.

set(gcf,'Pointer','arrow')

The following table shows the predefined symbols, the associated specifier, and describes typical use.

Purpose

Specifier

Typical Symbol

Use for editing text

ibeam

Locate a point on a graphics object

crosshair

Select a point anywhere in the figure

arrow

Indicate the system is busy

watch

Resize an object from the top-left corner

topl

Resize an object from the top-right corner

topr

Resize an object from the bottom-left corner

botl

Resize an object from the bottom-right corner

botr

View the actual hot spot

circle

Locate a point

cross

Use as popular symbol

fleur

Resize an object from the left side

left

Resize an object from the right side

right

Resize an object from the top

top

Resize an object from the bottom

bottom

Align a point with other objects on the display

fullcross

See the next section for information on defining your own pointer shape

custom

 

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 correspond 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.

P = ones(16)+1;
P(1,:) = 1; P(16,:) = 1;
P(:,1) = 1; P(:,16) = 1;
P(1:4,8:9) = 1; P(13:16,8:9) = 1;
P(8:9,1:4) = 1; P(8:9,13:16) = 1;
P(5:12,5:12) = NaN; 				% Create a transparent region in the center
set(gcf,'Pointer','custom','PointerShapeCData',P,...
        'PointerShapeHotSpot',[9 9])

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

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

g = 0:.2:20;
[X,Y] = meshgrid(g);
Z = 2*sin(sqrt(X.^2 + Y.^2));
mesh(Z);

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.

g = linspace(0,20,16);
[X,Y] = meshgrid(g);
Z = 2*sin(sqrt(X.^2 + Y.^2));
set(gcf,'Pointer','custom',...
        'PointerShapeCData',flipud((Z>0) + 1))

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

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS