-
Notifications
You must be signed in to change notification settings - Fork 0
/
seRectangle.m
148 lines (101 loc) · 5.01 KB
/
seRectangle.m
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
classdef seRectangle < handle
%seRectangle Stim Engine circle object that can then be drawn to the screen
% via Psychtoolbox
%
% obj = seRectangle(locationPoint, width, height, frameWidth, frameColor, fillColor)
%
% Example:
% rectangleObject = seRectangle([500 200],200,100,10,'green', 'red');
% rectangleObject.show();
%
properties
location
width; % Maximum width of a seRectangle object's in pixels
height; % Maximum height of a seRectangle object's in pixels
frameWidth; % Width of a seRectangle object's frame in pixels
frameColor; % Color word of a seRectangle object's frame
fillColor; % Color word of a seRectangle object's fill (i.e. inner color)
end
properties(SetAccess = protected, Hidden = true)
% In Psychtoolbox, cartesian coordinates (i.e. location-points)
% are defined as a two-element array with the following structure:
%
% [ x-coordinate y-coordinate ]
%
X = 1; % array index for x-coordinates
Y = 2; % array index for x-coordinates
end
methods
function obj = seRectangle(varargin)
switch(nargin)
case 0 % Default values if called with no arguments
obj.location = [500 500];
obj.width = 50;
obj.height = 50;
obj.frameWidth = 6;
obj.frameColor = 'black';
obj.fillColor = 'green';
case 1
obj.location = varargin{1};
obj.width = 50;
obj.height = 50;
obj.frameWidth = 6;
obj.frameColor = 'black';
obj.fillColor = 'red';
case 2
obj.location = varargin{1};
obj.width = 50;
obj.height = 50;
obj.frameWidth = 6;
obj.frameColor = 'black';
obj.fillColor = varargin{2};
case 6
obj.location = varargin{1};
obj.width = varargin{2};
obj.height = varargin{3};
obj.frameWidth = varargin{4};
obj.frameColor = varargin{5};
obj.fillColor = varargin{6};
otherwise
error('Wrong number of input arguments');
end
end % constructor method
function draw(obj, varargin)
switch nargin
case 2
winPtr = varargin{1};
case 3
winPtr = varargin{1};
obj.location = varargin{2};
otherwise
error('Wrong number in input arguments');
end
% Set the circle object's RECT
frameRect = [0 0 obj.height obj.width ]; % Instead of filling one oval, you can also specify a list of multiple ovals to be
fillRect = [0 0 obj.height-obj.frameWidth obj.width-obj.frameWidth]; % filled - this is much faster when you need to draw many objects per frame.
% Set the circle object's LOCATION
frameRect = CenterRectOnPoint(frameRect, obj.location(obj.X), obj.location(obj.Y));
fillRect = CenterRectOnPoint(fillRect , obj.location(obj.X), obj.location(obj.Y));
Screen('FillRect', winPtr ...
, [seColor2RGB(obj.frameColor)' seColor2RGB(obj.fillColor)' ] ...
, [frameRect' fillRect' ] );
end % method
function show(obj)
try
[winPtr] = seSetupScreen(seColor2RGB('white'));
Priority(MaxPriority(winPtr));
tic;
obj.draw(winPtr);
toc;
Screen('Flip', winPtr); % flip/draw buffer to display monitor
KbWait;
Screen('CloseAll'); % close psychtoolbox screen
Priority(0);
catch matlab_err
ShowCursor;
Screen('CloseAll'); % close psychtoolbox screen
display(getReport(matlab_err));
end
end % method
end % methods
end