File: TestTextBounds.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (36 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
% TestTextBounds - Test function of the TextBounds() function.

% History:
% 16-Dec-2015  dgp  Written.

x=50;
y=98;
textSize = 48;
string = 'Click to quit';

w=Screen('OpenWindow',0,255);
woff=Screen('OpenOffscreenWindow',w,[],[0 0 2*textSize*length(string) 2*textSize]);
Screen(woff,'TextFont','Arial');
Screen(woff,'TextSize',textSize);
for yPositionIsBaseline=0:1
    textSize=48;
    if yPositionIsBaseline
        string='Origin at baseline. ';
    else
        string='Origin at upper left.';
    end
    t=GetSecs;
    bounds=TextBounds(woff,string,yPositionIsBaseline);
    fprintf('TextBounds took %.3f seconds.\n',GetSecs-t);
    Screen(w,'TextFont','Arial');
    Screen(w,'TextSize',textSize);
    [newX,newY]=Screen('DrawText',w,string,x,y,0,255,yPositionIsBaseline);
    Screen('FrameRect',w,0,InsetRect(OffsetRect(bounds,x,y),-1,-1));
    x=newX;
    y=newY;
end
Screen('Close',woff);
DrawFormattedText(w, 'Click to quit', 'center', 'center');
Screen('Flip',w);
GetClicks;
Screen('Close',w);