Skip to content

Commit 98887dd

Browse files
committed
Merge remote-tracking branch 'origin/dev_kevin' into v2.6
2 parents 5e40aaa + 648fd0b commit 98887dd

File tree

6 files changed

+316
-99
lines changed

6 files changed

+316
-99
lines changed

+hw/+ptb/Window.m

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,17 @@ function fillRect(obj, colour, rect)
547547
Screen('PreloadTextures', obj.PtbHandle, tex);
548548
end
549549

550-
function [nx, ny] = drawText(obj, text, x, y, colour, vSpacing, wrapAt)
550+
function [nx, ny] = drawText(obj, text, varargin)
551551
% DRAWTEXT Draw some text to the screen
552+
% [NX, NY] = DRAWTEXT(OBJ, TEXT, X, Y, COLOUR, TEXTSIZE, VSPACING, WRAPAT)
552553
% The outputs may be used as the new start positions to draw further
553554
% text to the screen.
554555
%
555556
% Inputs:
556557
% text (char) - The text to be written to screen. May contain
557558
% newline characters '\n'.
559+
%
560+
% Inputs (Optional):
558561
% x (numerical|char) - The top-left x coordinate of the text in
559562
% px. If empty the left-most area part of the screen is used.
560563
% May also be one of the following string options: 'center',
@@ -565,9 +568,12 @@ function fillRect(obj, colour, rect)
565568
% color - The CLUT index for the text (scalar, RGB or RGBA vector)
566569
% If color is left out, the current text color from previous
567570
% text drawing commands is used.
568-
% vSpacing - The spacing between the lines in px. Defaults to 1.
569-
% wrapAt (char) - automatically break text longer than this string
570-
% into newline separated strings of roughly the same length
571+
% textSize (numerical) - The size of the text in px. Defaults to
572+
% PTB current setting (usually the system default).
573+
% vSpacing (numerical) - The spacing between the lines in px.
574+
% Defaults to 1.
575+
% wrapAt (numerical) - Automatically break text longer than this
576+
% number of chars.
571577
%
572578
% Outputs:
573579
% nx - The approximate x-coordinate of the 'cursor position' in px
@@ -580,23 +586,32 @@ function fillRect(obj, colour, rect)
580586
% obj.flip()
581587
%
582588
% See also DRAWFORMATTEDTEXT, DRAWTEXTURE, WRAPSTRING
583-
if nargin < 7
584-
wrapAt = [];
585-
end
586-
if nargin < 6
587-
vSpacing = [];
588-
end
589-
if nargin < 5
590-
colour = [];
591-
end
592-
if nargin < 4
593-
y = [];
594-
end
595-
if nargin < 3
596-
x = [];
597-
end
598-
[nx, ny] = DrawFormattedText(obj.PtbHandle, text, x, y, colour, wrapAt, [], [],...
599-
vSpacing);
589+
590+
p = inputParser;
591+
p.addRequired('text', @ischar)
592+
p.addOptional('x', [], @(x) ischar(x) || isnumeric(x))
593+
p.addOptional('y', [], @(x) ischar(x) || isnumeric(x))
594+
p.addOptional('colour', [], @isnumeric)
595+
p.addOptional('textSize', ...
596+
Screen('TextSize', obj.PtbHandle), ...
597+
@(x) isnumeric(x) || isscalar(x))
598+
p.addOptional('vSpacing', [], @(x) isnumeric(x) || isscalar(x))
599+
p.addOptional('wrapAt', [], @isnumeric)
600+
p.parse(text, varargin{:})
601+
p = p.Results;
602+
603+
% Set text size or restore to default on exit
604+
oldTextSize = Screen('TextSize', obj.PtbHandle, p.textSize);
605+
mess = onCleanup(@() Screen('TextSize', obj.PtbHandle, oldTextSize));
606+
607+
% Draw the text to screen
608+
[nx, ny] = DrawFormattedText(...
609+
obj.PtbHandle, ...
610+
p.text, ...
611+
p.x, p.y, ...
612+
p.colour, ...
613+
p.wrapAt, [], [],...
614+
p.vSpacing);
600615
% Screen('DrawText', obj.PtbHandle, text, x, y, colour, [], real(yPosIsBaseline));
601616
end
602617

+hw/debugWindow.m

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,54 @@
33
% Uses Psychtoolbox to open and control an on-screen window that is
44
% useful for debugging. Also returns a dummy viewing model.
55
%
6+
% Input (Optional):
7+
% open (logical): Immediately open the PTB window after instantiating.
8+
% Default true.
9+
%
10+
% Outputs:
11+
% window (hw.ptb.Window): A Window object configured for a 800x600
12+
% stimulus screen, with PTB warning and sync tests supressed.
13+
% viewingModel (hw.BasicScreenViewingModel): A ViewingModel object
14+
% configured for a subject positioned squarely in front of the
15+
% window, 7cm away.
16+
%
17+
% Example:
18+
% % Open a window for testing and set to middle grey
19+
% win = hw.debugWindow;
20+
% win.BackgroundColour = 255/2;
21+
% win.flip();
22+
%
23+
% Example:
24+
% % Save the debug window and model into a test rig's hardware file
25+
% [stimWindow, stimViewingModel] = hw.debugWindow(false);
26+
% hwPath = getOr(dat.paths('testRig', 'rigConfig'));
27+
% save(fullfile(hwPath, 'hardware.mat'), 'stim*', '-append')
28+
%
29+
% See also hw.ptb.Window, PsychDebugWindowConfiguration
30+
%
631
% Part of Rigbox
732

833
% 2012-10 CB created
934

10-
if nargin < 1
11-
open = true;
12-
end
35+
% Default is to immediately open the window
36+
if nargin < 1, open = true; end
1337

38+
% Set some reasonable parameters for the window (800x600 resolution)
1439
pixelWidth = 800;
1540
pixelHeight= 600;
16-
viewWidth = 0.2;
41+
viewWidth = 0.2; % Assume window is 200mm wide on the screen
1742
viewHeight = viewWidth*pixelHeight/pixelWidth;
1843

19-
% oldSyncTests = Screen('Preference', 'SkipSyncTests', 2);
20-
% oldVerbosity = Screen('Preference', 'Verbosity', 0);
21-
% cleanup1 = onCleanup(@() Screen('Preference', 'SkipSyncTests', oldSyncTests));
22-
% cleanup2 = onCleanup(@() Screen('Preference', 'Verbosity', oldVerbosity));
23-
44+
% Create the window object
2445
window = hw.ptb.Window;
25-
window.PtbVerbosity = 0;
26-
window.PtbSyncTests = 2;
46+
window.PtbVerbosity = 0; % Supress warnings
47+
window.PtbSyncTests = 2; % Supress sync tests (always fail when windowed)
2748
window.OpenBounds = SetRect(50, 50, pixelWidth+50, pixelHeight+50);
49+
if open, window.open(); end % Open now if open == true
2850

29-
if open
30-
window.open();
31-
end
32-
33-
51+
% Create the viewing model
3452
viewingModel = hw.BasicScreenViewingModel;
3553
viewingModel.ScreenWidthPixels = pixelWidth;
3654
viewingModel.ScreenWidthMetres = viewWidth;
3755
viewingModel.SubjectPos = [.5*viewWidth .5*viewHeight .07];
3856

39-
end
40-

0 commit comments

Comments
 (0)