-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the possiblity to have three anchors points (left, middle and right). To make that possible the displayed position is now moved above the line (under the question). The relative position of the question was also changed to allow multiple line questions.
- Loading branch information
Showing
1 changed file
with
75 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,23 @@ | |
%SLIDESCALE This funtion draws a slide scale on a PSYCHTOOLOX 3 screen and returns the | ||
% position of the slider spaced between -100 and 100 as well as the rection time and if an answer was given. | ||
% | ||
% Usage: [position, secs] = slideScale(ScreenPointer, question, center, rect, anchors, varargin) | ||
% Usage: [position, secs] = slideScale(ScreenPointer, question, center, rect, endPoints, varargin) | ||
% Mandatory input: | ||
% ScreenPointer -> Pointer to the window. | ||
% question -> Text string containing the question. | ||
% rect -> Double contatining the screen size. | ||
% Obtained with [myScreen, rect] = Screen('OpenWindow', 0); | ||
% anchors -> Cell containg the two or three text strings of the left (, middle) and right | ||
% end of the scala. Exampe: anchors = {'left', 'middle', 'right'} | ||
% end of the scale. Exampe: anchors = {'left', 'middle', 'right'} | ||
% | ||
% Varargin: | ||
% 'linelength' -> An integer specifying the lengths of the ticks in | ||
% pixels. The default is 10. | ||
% 'width' -> An integer specifying the width of the scala line in | ||
% 'width' -> An integer specifying the width of the scale line in | ||
% pixels. The default is 3. | ||
% 'range' -> An integer specifying the type of range. If 1, | ||
% then the range is from -100 to 100. If 2, then the | ||
% range is from 0 to 100. Default is 1. | ||
% 'startposition' -> Choose 'right', 'left' or 'center' start position. | ||
% Default is center. | ||
% 'scalalength' -> Double value between 0 and 1 for the length of the | ||
|
@@ -24,15 +27,18 @@ | |
% scale. 0 is top and 1 is bottom. Default is 0.8. | ||
% 'device' -> A string specifying the response device. Either 'mouse' | ||
% or 'keyboard'. The default is 'mouse'. | ||
% 'responsekey' -> String containing name of the key from the keyboard to log the | ||
% response. The default is 'return'. | ||
% 'slidecolor' -> Vector for the color value of the slider [r g b] | ||
% from 0 to 255. The dedult is red [255 0 0]. | ||
% 'responsekeys' -> Vector containing keyCodes of the keys from the keyboard to log the | ||
% response and move the slider to the right and left. | ||
% The default is [KbName('return') KbName('LeftArrow') KbName('RightArrow')]. | ||
% 'stepSize' -> An integer specifying the number of pixel the | ||
% slider moves with each step. Default is 1. | ||
% 'slidercolor' -> Vector for the color value of the slider [r g b] | ||
% from 0 to 255. The default is red [255 0 0]. | ||
% 'scalacolor' -> Vector for the color value of the scale [r g b] | ||
% from 0 to 255.The dedult is black [0 0 0]. | ||
% from 0 to 255.The default is black [0 0 0]. | ||
% 'aborttime' -> Double specifying the time in seconds after which | ||
% the function should be aborted. In this case no | ||
% answer is saved. The default is 8 secs. | ||
% answer is saved. The default is Inf. | ||
% 'image' -> An image saved in a uint8 matrix. Use | ||
% imread('image.png') to load an image file. | ||
% 'displayposition' -> If true, the position of the slider is displayed. | ||
|
@@ -47,7 +53,7 @@ | |
% variable is 1. | ||
% | ||
% Author: Joern Alexander Quent | ||
% e-mail: [email protected] | ||
% e-mail: [email protected] | ||
% Version history: | ||
% 1.0 - 4th January 2016 - First draft | ||
% 1.1 - 18. Feburary 2016 - Added abort time and option to | ||
|
@@ -68,7 +74,14 @@ | |
% not properly in windowed mode. | ||
% 1.9 - 7th December 2017 - If an image is drawn, the | ||
% corresponding texture is deleted at the end. | ||
% 1.10 - 13rd January 2020 - Added the possiblity of | ||
% 1.10 - 28th December 2017 - Added the possibility to | ||
% choose the type of range (0 to 100 or -100 to 100). | ||
% 1.11 - 7th May 2019 - Added the possibility to control | ||
% the slider with keys only. Use keyboard as devices and | ||
% select this keys for this function. In addition, | ||
% default for aborttime was changed to Inf and one bug | ||
% with slidercolor was fixed. | ||
% 1.12 - 13rd January 2020 - Added the possiblity to | ||
% have three anchors points (left, middle and right). To | ||
% make that possible the displayed position is now moved | ||
% above the line (under the question). The relative | ||
|
@@ -84,12 +97,14 @@ | |
sliderColor = [255 0 0]; | ||
scaleColor = [0 0 0]; | ||
device = 'mouse'; | ||
aborttime = 8; | ||
responseKey = KbName('return'); | ||
aborttime = Inf; | ||
responseKeys = [KbName('return') KbName('LeftArrow') KbName('RightArrow')]; | ||
GetMouseIndices; | ||
drawImage = 0; | ||
startPosition = 'center'; | ||
displayPos = false; | ||
rangeType = 1; | ||
stepSize = 1; | ||
|
||
i = 1; | ||
while(i<=length(varargin)) | ||
|
@@ -102,6 +117,10 @@ | |
i = i + 1; | ||
width = varargin{i}; | ||
i = i + 1; | ||
case 'range' | ||
i = i + 1; | ||
rangeType = varargin{i}; | ||
i = i + 1; | ||
case 'startposition' | ||
i = i + 1; | ||
startPosition = varargin{i}; | ||
|
@@ -116,15 +135,19 @@ | |
i = i + 1; | ||
case 'device' | ||
i = i + 1; | ||
device = varargin{i}; | ||
device = varargin{i}; | ||
i = i + 1; | ||
case 'responsekeys' | ||
i = i + 1; | ||
case 'responsekey' | ||
responseKeys = varargin{i}; | ||
i = i + 1; | ||
responseKey = KbName(varargin{i}); | ||
case 'stepsize' | ||
i = i + 1; | ||
case 'slidecolor' | ||
stepSize = varargin{i}; | ||
i = i + 1; | ||
sliderColor = varargin{i}; | ||
case 'slidercolor' | ||
i = i + 1; | ||
sliderColor = varargin{i}; | ||
i = i + 1; | ||
case 'scalacolor' | ||
i = i + 1; | ||
|
@@ -150,7 +173,7 @@ | |
|
||
% Sets the default key depending on choosen device | ||
if strcmp(device, 'mouse') | ||
responseKey = 1; % X mouse button | ||
mouseButton = 1; % X mouse button | ||
end | ||
|
||
%% Checking number of screens and parsing size of the global screen | ||
|
@@ -199,7 +222,21 @@ | |
t0 = GetSecs; | ||
answer = 0; | ||
while answer == 0 | ||
[x,y,buttons,focus,valuators,valinfo] = GetMouse(screenPointer, 1); | ||
% Parse user input for x location | ||
if strcmp(device, 'mouse') | ||
[x,~,buttons,~,~,~] = GetMouse(screenPointer, 1); | ||
elseif strcmp(device, 'keyboard') | ||
[~, ~, keyCode] = KbCheck; | ||
if keyCode(responseKeys(2)) == 1 | ||
x = x - stepSize; % Goes stepSize pixel to the left | ||
elseif keyCode(responseKeys(3)) == 1 | ||
x = x + stepSize; % Goes stepSize pixel to the right | ||
end | ||
else | ||
error('Unknown device'); | ||
end | ||
|
||
% Stop at upper and lower bound | ||
if x > rect(3)*scalaLength | ||
x = rect(3)*scalaLength; | ||
elseif x < rect(3)*(1-scalaLength) | ||
|
@@ -214,7 +251,7 @@ | |
% Drawing the question as text | ||
DrawFormattedText(screenPointer, question, 'center', rect(4)*(scalaPosition - 0.16)); | ||
|
||
% Drawing the end points of the scala as text | ||
% Drawing the anchors of the scale as text | ||
if length(anchors) == 2 | ||
% Only left and right anchors | ||
DrawFormattedText(screenPointer, anchors{1}, leftTick(1, 1) - textBounds(1, 3)/2, rect(4)*scalaPosition+40, [],[],[],[],[],[],[]); % Left point | ||
|
@@ -224,10 +261,9 @@ | |
DrawFormattedText(screenPointer, anchors{1}, leftTick(1, 1) - textBounds(1, 3)/2, rect(4)*scalaPosition+40, [],[],[],[],[],[],[]); % Left point | ||
DrawFormattedText(screenPointer, anchors{2}, 'center', rect(4)*scalaPosition+40, [],[],[],[],[],[],[]); % Middle point | ||
DrawFormattedText(screenPointer, anchors{3}, rightTick(1, 1) - textBounds(2, 3)/2, rect(4)*scalaPosition+40, [],[],[],[],[],[],[]); % Right point | ||
|
||
end | ||
|
||
% Drawing the scala | ||
% Drawing the scale | ||
Screen('DrawLine', screenPointer, scaleColor, midTick(1), midTick(2), midTick(3), midTick(4), width); % Mid tick | ||
Screen('DrawLine', screenPointer, scaleColor, leftTick(1), leftTick(2), leftTick(3), leftTick(4), width); % Left tick | ||
Screen('DrawLine', screenPointer, scaleColor, rightTick(1), rightTick(2), rightTick(3), rightTick(4), width); % Right tick | ||
|
@@ -237,30 +273,34 @@ | |
Screen('DrawLine', screenPointer, sliderColor, x, rect(4)*scalaPosition - lineLength, x, rect(4)*scalaPosition + lineLength, width); | ||
|
||
% Caculates position | ||
position = round((x)-mean(scaleRange)); % Shift the x value according to the new scale | ||
position = (position/max(scaleRangeShifted))*100; % Converts the value to percentage | ||
if rangeType == 1 | ||
position = round((x)-mean(scaleRange)); % Calculates the deviation from the center | ||
position = (position/max(scaleRangeShifted))*100; % Converts the value to percentage | ||
elseif rangeType == 2 | ||
position = round((x)-min(scaleRange)); % Calculates the deviation from 0. | ||
position = (position/(max(scaleRange)-min(scaleRange)))*100; % Converts the value to percentage | ||
end | ||
|
||
|
||
% Display position | ||
if displayPos | ||
DrawFormattedText(screenPointer, num2str(round(position)), 'center', rect(4)*(scalaPosition - 0.05)); | ||
end | ||
|
||
% Flip screen | ||
onsetStimulus = Screen('Flip', screenPointer); | ||
Screen('Flip', screenPointer); | ||
|
||
% Check if answer has been given | ||
if strcmp(device, 'mouse') | ||
secs = GetSecs; | ||
if buttons(responseKey) == 1 | ||
if buttons(mouseButton) == 1 | ||
answer = 1; | ||
end | ||
elseif strcmp(device, 'keyboard') | ||
[keyIsDown, secs, keyCode] = KbCheck; | ||
if keyCode(responseKey) == 1 | ||
[~, secs, keyCode] = KbCheck; | ||
if keyCode(responseKeys(1)) == 1 | ||
answer = 1; | ||
end | ||
else | ||
error('Unknown device'); | ||
end | ||
|
||
% Abort if answer takes too long | ||
|
@@ -275,5 +315,6 @@ | |
Screen('Close', stimuli); | ||
end | ||
%% Calculating the rection time and the position | ||
RT = (secs - t0)*1000; % converting RT to millisecond | ||
end | ||
RT = (secs - t0)*1000; % converting RT to millisecond | ||
end | ||
|