% SAMPLEMOUSE.M - Demonstrates how mouse can be used to update display

config_mouse(10);   %polling mode with 10 msec sampling interval
config_display(0);  %640x480 Windowed-mode
start_cogent;


map = getmousemap; %variable map to contain current information about mouse
x = 0;   %initialize cursor x-position
y = 0;   %initialize cursor y-position

%infinite mouse scanning loop
%exit via 'break' command
while 1
   
   % Draw text at position defined by mouse (0,0 at first).
   clearpict( 1 );   %clear screen buffer #1
   preparestring( 'SQUEEK!', 1, x, y );  %draw 'cursor' at (x,y) in screen buffer #1
   drawpict( 1 );  %display contents of screen buffer #1
   
   %capture mouse activity
   readmouse;     
   
   %fetch delta-x and delta-y values of latest mouse activity
   x = x + sum( getmouse(map.X) );
   y = y - sum( getmouse(map.Y) );
   
   %exit if right mouse button changes state
   %(i.e., EVENTS array returned by GETMOUSE contains any 0 (DOWN) or 128 (UP) codes)
   [events,map_ids,times]=getmouse(map.Button2);
   if( ~isempty(events) & any(events) )
      break;
   end
   
end %end of while(1) loop

stop_cogent;   
