function [already_on_object_requiring_new_pointer,saved_mouse_pointer] = ...
    updateCursor(fig,...
                 currently_on_object_requiring_new_pointer,...
                 already_on_object_requiring_new_pointer, ...
                 saved_mouse_pointer, ...
                 object_pointer);
%updateCursor Update cursor when entering and leaving an object.
%   updateCursor(FIG,...
%                CURRENTLY_ON_OBJECT_REQUIRING_NEW_POINTER,...    
%                ALREADY_ON_OBJECT_REQUIRING_NEW_POINTER, ...
%                SAVED_MOUSE_POINTER,...
%                OBJECT_POINTER) 
%
%   updateCursor updates the 'Pointer' of figure FIG to be the new
%   pointer OBJECT_POINTER when the mouse is over the object and
%   otherwise the cursor is restored to the cursor the figure had before
%   the mouse was moved over the object.
%
%   The function that calls updateCursor must determine if the mouse is
%   CURRENTLY_ON_OBJECT_REQUIRING_NEW_POINTER, must initialize and store the
%   boolean ALREADY_ON_OBJECT_REQUIRING_NEW_POINTER, and must store the
%   SAVED_MOUSE_POINTER. 
% 
%   This function is part of a pattern used by several functions to manage
%   cursors.

%   Copyright 2004 The MathWorks, Inc.
%   $Revision: 1.1.8.1 $  $Date: 2004/08/10 01:50:37 $

  entering = currently_on_object_requiring_new_pointer && ...
      ~already_on_object_requiring_new_pointer;

  leaving = ~currently_on_object_requiring_new_pointer && ...
      already_on_object_requiring_new_pointer;
  
  if entering % currently_on_object_requiring_new_pointer
          % entering object requiring new pointer:
          % save original pointer, change to new pointer
          already_on_object_requiring_new_pointer = true;
          saved_mouse_pointer = get(fig, 'Pointer');
          set(fig,'Pointer',object_pointer) 
  
  elseif leaving
          % leaving object requiring new pointer:             
          % restore pointer
          already_on_object_requiring_new_pointer = false;
          set(fig, 'Pointer', saved_mouse_pointer);
          
  end

end