Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to display calibration plot within expServer #245

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions +hw/+ptb/Window.m
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,17 @@ function fillRect(obj, colour, rect)
Screen('PreloadTextures', obj.PtbHandle, tex);
end

function [nx, ny] = drawText(obj, text, x, y, colour, vSpacing, wrapAt)
function [nx, ny] = drawText(obj, text, varargin)
% DRAWTEXT Draw some text to the screen
% [NX, NY] = DRAWTEXT(OBJ, TEXT, X, Y, COLOUR, TEXTSIZE, VSPACING, WRAPAT)
% The outputs may be used as the new start positions to draw further
% text to the screen.
%
% Inputs:
% text (char) - The text to be written to screen. May contain
% newline characters '\n'.
%
% Inputs (Optional):
% x (numerical|char) - The top-left x coordinate of the text in
% px. If empty the left-most area part of the screen is used.
% May also be one of the following string options: 'center',
Expand All @@ -552,9 +555,12 @@ function fillRect(obj, colour, rect)
% color - The CLUT index for the text (scalar, RGB or RGBA vector)
% If color is left out, the current text color from previous
% text drawing commands is used.
% vSpacing - The spacing between the lines in px. Defaults to 1.
% wrapAt (char) - automatically break text longer than this string
% into newline separated strings of roughly the same length
% textSize (numerical) - The size of the text in px. Defaults to
% PTB current setting (usually the system default).
% vSpacing (numerical) - The spacing between the lines in px.
% Defaults to 1.
% wrapAt (numerical) - Automatically break text longer than this
% number of chars.
%
% Outputs:
% nx - The approximate x-coordinate of the 'cursor position' in px
Expand All @@ -567,23 +573,32 @@ function fillRect(obj, colour, rect)
% obj.flip()
%
% See also DRAWFORMATTEDTEXT, DRAWTEXTURE, WRAPSTRING
if nargin < 7
wrapAt = [];
end
if nargin < 6
vSpacing = [];
end
if nargin < 5
colour = [];
end
if nargin < 4
y = [];
end
if nargin < 3
x = [];
end
[nx, ny] = DrawFormattedText(obj.PtbHandle, text, x, y, colour, wrapAt, [], [],...
vSpacing);

p = inputParser;
p.addRequired('text', @ischar)
p.addOptional('x', [], @(x) ischar(x) || isnumeric(x))
p.addOptional('y', [], @(x) ischar(x) || isnumeric(x))
p.addOptional('colour', [], @isnumeric)
p.addOptional('textSize', ...
Screen('TextSize', obj.PtbHandle), ...
@(x) isnumeric(x) || isscalar(x))
p.addOptional('vSpacing', [], @(x) isnumeric(x) || isscalar(x))
p.addOptional('wrapAt', [], @isnumeric)
p.parse(text, varargin{:})
p = p.Results;

% Set text size or restore to default on exit
oldTextSize = Screen('TextSize', obj.PtbHandle, p.textSize);
mess = onCleanup(@() Screen('TextSize', obj.PtbHandle, oldTextSize));

% Draw the text to screen
[nx, ny] = DrawFormattedText(...
obj.PtbHandle, ...
p.text, ...
p.x, p.y, ...
p.colour, ...
p.wrapAt, [], [],...
p.vSpacing);
% Screen('DrawText', obj.PtbHandle, text, x, y, colour, [], real(yPosIsBaseline));
end

Expand Down
52 changes: 34 additions & 18 deletions +hw/debugWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,54 @@
% Uses Psychtoolbox to open and control an on-screen window that is
% useful for debugging. Also returns a dummy viewing model.
%
% Input (Optional):
% open (logical): Immediately open the PTB window after instantiating.
% Default true.
%
% Outputs:
% window (hw.ptb.Window): A Window object configured for a 800x600
% stimulus screen, with PTB warning and sync tests supressed.
% viewingModel (hw.BasicScreenViewingModel): A ViewingModel object
% configured for a subject positioned squarely in front of the
% window, 7cm away.
%
% Example:
% % Open a window for testing and set to middle grey
% win = hw.debugWindow;
% win.BackgroundColour = 255/2;
% win.flip();
%
% Example:
% % Save the debug window and model into a test rig's hardware file
% [stimWindow, stimViewingModel] = hw.debugWindow(false);
% hwPath = getOr(dat.paths('testRig', 'rigConfig'));
% save(fullfile(hwPath, 'hardware.mat'), 'stim*', '-append')
%
% See also hw.ptb.Window, PsychDebugWindowConfiguration
%
% Part of Rigbox

% 2012-10 CB created

if nargin < 1
open = true;
end
% Default is to immediately open the window
if nargin < 1, open = true; end

% Set some reasonable parameters for the window (800x600 resolution)
pixelWidth = 800;
pixelHeight= 600;
viewWidth = 0.2;
viewWidth = 0.2; % Assume window is 200mm wide on the screen
viewHeight = viewWidth*pixelHeight/pixelWidth;

% oldSyncTests = Screen('Preference', 'SkipSyncTests', 2);
% oldVerbosity = Screen('Preference', 'Verbosity', 0);
% cleanup1 = onCleanup(@() Screen('Preference', 'SkipSyncTests', oldSyncTests));
% cleanup2 = onCleanup(@() Screen('Preference', 'Verbosity', oldVerbosity));

% Create the window object
window = hw.ptb.Window;
window.PtbVerbosity = 0;
window.PtbSyncTests = 2;
window.PtbVerbosity = 0; % Supress warnings
window.PtbSyncTests = 2; % Supress sync tests (always fail when windowed)
window.OpenBounds = SetRect(50, 50, pixelWidth+50, pixelHeight+50);
if open, window.open(); end % Open now if open == true

if open
window.open();
end


% Create the viewing model
viewingModel = hw.BasicScreenViewingModel;
viewingModel.ScreenWidthPixels = pixelWidth;
viewingModel.ScreenWidthMetres = viewWidth;
viewingModel.SubjectPos = [.5*viewWidth .5*viewHeight .07];

end

Loading