Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev_kevin' into v2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed May 3, 2020
2 parents 5e40aaa + 648fd0b commit 98887dd
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 99 deletions.
57 changes: 36 additions & 21 deletions +hw/+ptb/Window.m
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,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 @@ -565,9 +568,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 @@ -580,23 +586,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

0 comments on commit 98887dd

Please sign in to comment.