3
% ___________________________________________________________________
5
% Draw a curve with the mouse. Same as MouseTraceDemo, but asks
6
% Screen('Flip') to not clear the framebuffer after flip. This way,
7
% we don't need to redraw the whole mouse trace in each frame.
8
% Uses imaging pipeline via PsychImaging for optimal performance
9
% on modern hardware, as opposed to old style method shown in
10
% MouseTraceDemo2, which was appropriate before the year 2007.
11
% ___________________________________________________________________
13
% See also: PsychDemos, MouseTraceDemo, GetMouse.
17
% 4/1/2013 mk Derived from MouseTraceDemo2.
20
% Open up a window on the screen and clear it.
21
whichScreen = max(Screen('Screens'));
22
PsychImaging('PrepareConfiguration');
23
PsychImaging('AddTask', 'General', 'UseVirtualFramebuffer');
24
[theWindow,theRect] = PsychImaging('OpenWindow', whichScreen, 0);
26
% Move the cursor to the center of the screen
27
theX = theRect(RectRight)/2;
28
theY = theRect(RectBottom)/2;
31
% Wait for a click and hide the cursor
32
Screen(theWindow,'TextSize',24);
33
Screen(theWindow,'DrawText','Drag mouse (i.e. hold button down) to draw',50,50,255);
34
Screen('Flip', theWindow);
36
[x,y,buttons] = GetMouse(theWindow);
41
Screen(theWindow,'DrawText','Release button to finish',50,50,255);
45
% Loop and track the mouse, drawing the contour
46
[theX,theY] = GetMouse(theWindow);
47
thePoints = [theX theY];
48
Screen(theWindow,'DrawLine',255,theX,theY,theX,theY);
49
% Set the 'dontclear' flag of Flip to 1 to prevent erasing the
51
Screen('Flip', theWindow, 0, 1);
53
[x,y,buttons] = GetMouse(theWindow);
57
if (x ~= theX || y ~= theY)
58
thePoints = [thePoints ; x y]; %#ok<AGROW>
59
[numPoints, two]=size(thePoints);
60
% Only draw the most recent line segment: This is possible,
62
Screen(theWindow,'DrawLine',128,thePoints(numPoints-1,1),thePoints(numPoints-1,2),thePoints(numPoints,1),thePoints(numPoints,2));
63
% ...we ask Flip to not clear the framebuffer after flipping:
64
Screen('Flip', theWindow, 0, 1);
70
Screen(theWindow,'DrawText','Click mouse to finish',50,50,255);
72
Screen(theWindow,'Close');
74
% Plot the contour in a Matlab figure
75
plot(thePoints(:,1),theRect(RectBottom)-thePoints(:,2));
79
psychrethrow(psychlasterror);