% GetImageTest
%
% Exercise Screen 'GetImage'.

% 12/12/95	jdt Wrote it.
% 12/14/95	dhb Added comments.
% 2/4/97    dhb Modernized and improved user interface.
% 3/12/98   dgp Use Ask.

% Open screen
whichScreen = 0;
[window,screenRect] = Screen(0,'OpenWindow',0);
HideCursor;

% Set up some text for user interface.
Screen(window,'TextFont','Helvetica');
Screen(window,'TextSize',18);
Screen(window,'TextStyle',0);
Screen(window,'TextMode','srcOr');

% Some sizes
midx = screenRect(RectRight) / 2;
midy = screenRect(RectBottom) / 2;

% Clear the screen to black
Screen(window,'FillRect',0,screenRect);

% Draw a rect
rect = SetRect(midx-5,midy-15,midx+5,midy);
Screen(window,'FillRect',220,rect);
rect = SetRect(midx-5,midy,midx+5,midy+15);
Screen(window,'FillRect',120,rect);
Ask(window,'Click mouse to proceed',255,0);

% Get the rect into Matlab as a rectangle and as a square
rect = SetRect(midx-5,midy-15,midx+5,midy+15);
s = Screen(window,'GetImage',rect);
rect = SetRect(midx-20,midy-20,midx+20,midy+20);
s1 = Screen(window,'GetImage',rect);

% Clear the screen to almost grey
Screen(window,'FillRect',100,screenRect)
Ask(window,'Click mouse to proceed',255,100);

% Put rectangle back in center
Screen(window,'PutImage',s);
Ask(window,'Click mouse to proceed',255,100);

% Move a rectangle along
[m,n] = size(s1);
for i=100:400
	rect = SetRect(i,i,i+n,i+m);
	Screen(window,'PutImage',s1,rect);
end
Ask(window,'Click mouse to exit',255,100);

% Close up
Screen(window,'Close');
ShowCursor;
