CS 211 Lesson 27

Application Data, Finding Objects and Mouse Selection

Quote:

"Press on: nothing in the world can take place of perseverance. Talent will not; nothing is more common than unsuccessful men with talent. Education will not; the world is full of educated derelicts. Persistence and determination are alone omnipotent..."  Calvin Coolidge

Lesson Objectives:

Lesson:

I. MATLAB Concepts

A. Storing Application Data With Graphic Objects

B. Finding Objects

C. Selecting Objects with the Mouse

Key = ' ';
while Key ~= 'q'
  Button = waitforbuttonpress();

  if Button == 0 % A mouse button was pressed
    MouseButtonType     = get( gcf(), 'SelectionType');
    MouseFigureLocation = get( gcf(), 'CurrentPoint');
    MouseAxesLocation   = get( gca(), 'CurrentPoint');
    
    if strcmp(MouseButtonType, 'normal')
      fprintf('LEFT-button  ');
    elseif strcmp(MouseButtonType, 'extend')
      fprintf('MIDDLE-button');
    elseif strcmp(MouseButtonType, 'alt')
      fprintf('RIGHT-button ');
    elseif strcmp(MouseButtonType, 'open')
      fprintf('DOUBLE-CLICK ');
    end
    
    fprintf(' mouse click at Figure (%3d %3d) Axes (%6.4f %6.4f)\n', ...
            MouseFigureLocation(1), MouseFigureLocation(2), ...
            MouseAxesLocation(1,1), MouseAxesLocation(1,2) )
  else % Button == 1; A keyboard key was pressed
    Key = get( gcf(), 'CurrentCharacter');
    fprintf('The user hit the %c(%d) key\n', Key, Key);
  end
end
 

II. Good Programming Practices

III. Algorithms

Lab Work: Lab 27

References:  Chapman Textbook: section 9.5-9.7