Code covered by the BSD License  

Highlights from
Mouse figure interaction

image thumbnail

Mouse figure interaction

by

 

This example shows how the mouse could be used to change how an image is displayed

mouseClicked(isDown)
% This function is an example on how to use mouse click callbacks on a
% figure
% To use this function, register the two callbacks by executing the two
% lines below
% set (gcf, 'WindowButtonUpFcn', @(object, eventdata)mouseClicked(false));
% set (gcf, 'WindowButtonDownFcn', @(object, eventdata)mouseClicked(true));
function mouseClicked(isDown)
    if isDown      
        switch get(gcf,'SelectionType')
            case {'normal', 'extend', 'alt', 'open'}
                set (gcf, 'WindowButtonMotionFcn', @(object, eventdata)mouseMove());                
            %case 'extend'                
            %case 'alt' 
            %case 'open'            
            otherwise
        end
    else
        set (gcf, 'WindowButtonMotionFcn', '');
    end
end


% if you want to react on a certain button extend the switch as following 
%
% switch get(gcf,'SelectionType')
%     case 'normal'
%         % do something for left-click
%     case 'extend'
%         % do something for center-click
%     case 'alt'
%         % do something for right-click
%     case 'open'
%         % do something for double-click
%     otherwise
%         % never happens
% end

% see also:
% http://www.mathworks.ch/ch/help/matlab/ref/figure_props.html#SelectionType

Contact us