Skip to content

Commit 089abb1

Browse files
committed
update aperture function to deal with circle and wedge
1 parent fce7479 commit 089abb1

File tree

1 file changed

+60
-29
lines changed

1 file changed

+60
-29
lines changed

apertureTexture.m

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,90 @@
11
function cfg = apertureTexture(action, cfg, thisEvent)
2-
2+
33
transparent = [0 0 0 0];
4-
4+
55
switch action
6-
6+
77
case 'init'
8-
9-
% we take the screen height as maximum aperture width if not
10-
% specified.
11-
if ~isfield(cfg.aperture, 'width') || isempty(cfg.aperture.width)
12-
cfg.aperture.width = cfg.screen.winRect(4) / cfg.screen.ppd;
8+
9+
switch cfg.aperture.type
10+
11+
case 'circle'
12+
% we take the screen height as maximum aperture width if not
13+
% specified.
14+
if ~isfield(cfg.aperture, 'width') || isempty(cfg.aperture.width)
15+
cfg.aperture.width = cfg.screen.winRect(4) / cfg.screen.ppd;
16+
end
17+
cfg.aperture = degToPix('width', cfg.aperture, cfg);
1318
end
14-
cfg.aperture = degToPix('width', cfg.aperture, cfg);
15-
19+
1620
cfg.aperture.texture = Screen('MakeTexture', cfg.screen.win, ...
1721
cfg.color.background(1) * ones(cfg.screen.winRect([4 3])));
18-
22+
1923
case 'make'
20-
24+
25+
xCenter = cfg.screen.center(1);
26+
yCenter = cfg.screen.center(2);
27+
2128
switch cfg.aperture.type
22-
29+
2330
case 'none'
24-
31+
2532
Screen('Fillrect', cfg.aperture.texture, transparent);
26-
33+
2734
case 'circle'
28-
35+
2936
diameter = cfg.aperture.widthPix;
30-
31-
xPos = cfg.screen.center(1);
32-
yPos = cfg.screen.center(2);
37+
3338
if isfield(cfg.aperture, 'xPosPix')
34-
xPos = cfg.screen.center(1) + cfg.aperture.xPosPix;
39+
xCenter = cfg.screen.center(1) + cfg.aperture.xPosPix;
3540
end
3641
if isfield(cfg.aperture, 'yPosPix')
37-
yPos = cfg.screen.center(2) + cfg.aperture.yPosPix;
42+
yCenter = cfg.screen.center(2) + cfg.aperture.yPosPix;
3843
end
39-
44+
4045
Screen('FillOval', cfg.aperture.texture, transparent, ...
4146
CenterRectOnPoint([0 0 repmat(diameter, 1, 2)], ...
42-
xPos, yPos));
47+
xCenter, yCenter));
48+
49+
case 'ring'
50+
51+
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
52+
53+
Screen('FillOval', cfg.aperture.texture, transparent, ...
54+
CenterRectOnPoint( ...
55+
[0 0 repmat(cfg.ring.outerRimPix, 1, 2)], ...
56+
xCenter, yCenter));
57+
58+
Screen('FillOval', cfg.aperture.texture, [cfg.color.background 255], ...
59+
CenterRectOnPoint( ...
60+
[0 0 repmat(cfg.ring.innerRimPix, 1, 2)], ...
61+
xCenter, yCenter));
62+
63+
case 'wedge'
64+
65+
Screen('Fillrect', cfg.aperture.texture, cfg.color.background);
66+
67+
Screen('FillArc', cfg.aperture.texture, transparent, ...
68+
CenterRect( ...
69+
[0 0 repmat(cfg.stimRect(4), 1, 2)], ...
70+
cfg.screen.winRect), ...
71+
thisEvent.angle, ... % start angle
72+
cfg.aperture.width); % arc angle
73+
4374

4475
otherwise
4576

4677
error('unknown aperture type: %s.', cfg.aperture.type);
47-
78+
4879
end
49-
80+
5081
case 'draw'
51-
82+
5283
Screen('DrawTexture', cfg.screen.win, cfg.aperture.texture);
53-
84+
5485
% Screen('DrawTexture', cfg.screen.win, apertureTexture, ...
5586
% cfg.screen.winRect, cfg.screen.winRect, current.apertureAngle - 90);
56-
87+
5788
end
58-
89+
5990
end

0 commit comments

Comments
 (0)