close all;
clear;
PsychDefaultSetup(2);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = GrayIndex(screenNumber);
darkGrey = grey * 0.8;
red = [white 0 0];
green = [0 white 0];
blue = [0 0 white];
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black,...
[], [], [], [], [], kPsychNeedRetinaResolution);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
textSize = 90;
smallTextSize = 60;
Screen('TextSize', window, textSize);
HideCursor;
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
ifi = Screen('GetFlipInterval', window);
[xCenter, yCenter] = RectCenter(windowRect);
scaleLengthPix = screenYpixels / 1.5;
scaleHLengthPix = scaleLengthPix / 2;
leftEnd = [xCenter - scaleHLengthPix yCenter];
rightEnd = [xCenter + scaleHLengthPix yCenter];
scaleLineCoords = [leftEnd' rightEnd'];
scaleLineWidth = 10;
SetMouse(xCenter, yCenter, window);
numScalePoints = 7;
xPosScalePoints = linspace(xCenter - scaleHLengthPix, xCenter + scaleHLengthPix, numScalePoints);
yPosScalePoints = repmat(yCenter, 1, numScalePoints);
xyScalePoints = [xPosScalePoints; yPosScalePoints];
sliderLabels = {'Not Cool', 'Cool'};
textBoundsAll = nan(2, 4);
for i = 1:2
[~, ~, textBoundsAll(i, :)] = DrawFormattedText(window, sliderLabels{i}, 0, 0, white);
end
textWidths = textBoundsAll(:, 3)';
halfTextWidths = textWidths / 2;
textHeights = range([textBoundsAll(:, 2) textBoundsAll(:, 4)], 2)';
halfTextHeights = textHeights / 2;
Screen('TextSize', window, smallTextSize);
numBoundsAll = nan(numScalePoints, 4);
for i = 1:numScalePoints
[~, ~, numBoundsAll(i, :)] = DrawFormattedText(window, num2str(i), 0, 0, white);
end
Screen('TextSize', window, textSize);
numWidths = numBoundsAll(:, 3)';
halfNumWidths = numWidths / 2;
numHeights = [range([numBoundsAll(:, 2) numBoundsAll(:, 4)], 2)]';
halfNumHeights = numHeights / 2;
dim = 40;
hDim = dim / 2;
textPixGap = 50;
leftTextPosX = xCenter - scaleHLengthPix - hDim - textWidths(1) - textPixGap;
rightTextPosX = xCenter + scaleHLengthPix + hDim + textPixGap;
leftTextPosY = yCenter + halfTextHeights(1);
rightTextPosY = yCenter + halfTextHeights(2);
numShiftDownPix = 80;
xNumText = xPosScalePoints - halfNumWidths;
yNumText = yPosScalePoints + halfNumHeights + numShiftDownPix;
br = linspace(0, 1, numScalePoints);
bg = zeros(1, numScalePoints);
bb = abs(1 - br);
bRGB = [br; bg; bb];
waitframes = 1;
Screen('FillRect', window, black)
vbl = Screen('Flip', window);
while ~KbCheck(-1)
[mx, my, buttons] = GetMouse(window);
inCircles = sqrt((xPosScalePoints - mx).^2 + (yPosScalePoints - my).^2) < hDim;
weInCircle = sum(inCircles) > 0;
if weInCircle == 1
[~, posCircle] = max(inCircles);
coordsCircle = xyScalePoints(:, posCircle);
end
Screen('DrawLines', window, scaleLineCoords, scaleLineWidth, grey);
DrawFormattedText(window, sliderLabels{1}, leftTextPosX, leftTextPosY, blue);
DrawFormattedText(window, sliderLabels{2}, rightTextPosX, rightTextPosY, red);
DrawFormattedText(window, 'Coolness Rating Scale', 'center', screenYpixels * 0.25, white);
if weInCircle == 1
Screen('DrawDots', window, coordsCircle, dim * 1.2, white, [], 2);
end
Screen('DrawDots', window, xyScalePoints, dim, darkGrey, [], 2);
if weInCircle == 1 && sum(buttons) > 0
Screen('DrawDots', window, coordsCircle, dim * 1.2, bRGB(:, posCircle), [], 2);
DrawFormattedText(window, ['Button ' num2str(posCircle) ' being pressed'], 'center', screenYpixels * 0.75, bRGB(:, posCircle));
end
Screen('TextSize', window, smallTextSize);
for thisNum = 1:numScalePoints
DrawFormattedText(window, num2str(thisNum), xNumText(thisNum), yNumText(thisNum), white);
end
Screen('TextSize', window, textSize);
Screen('DrawDots', window, [mx my], 10, white, [], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
sca;