@@ -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
0 commit comments