mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
added more documentation
This commit is contained in:
parent
2eb38f0705
commit
0ccf2b872d
190
docs/TextInput.html
Normal file
190
docs/TextInput.html
Normal file
@ -0,0 +1,190 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Class: TextInput</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Class: TextInput</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
|
||||
<h2><span class="attribs"><span class="type-signature"></span></span>TextInput<span class="signature">()</span><span class="type-signature"></span></h2>
|
||||
|
||||
<div class="class-description">TextInput encapsulates an html <input> element into a PIXI Container.</div>
|
||||
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
<h2>Constructor</h2>
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="TextInput"><span class="type-signature"></span>new TextInput<span class="signature">()</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-author">Author:</dt>
|
||||
<dd class="tag-author">
|
||||
<ul>
|
||||
<li>'Mwni' (https://github.com/Mwni)</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
|
||||
|
||||
<dt class="tag-copyright">Copyright:</dt>
|
||||
<dd class="tag-copyright"><ul class="dummy"><li>(c) 2018 Mwni</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
<dt class="tag-license">License:</dt>
|
||||
<dd class="tag-license"><ul class="dummy"><li>Distributed under the terms of the MIT License</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="visual_TextInput.js.html">visual/TextInput.js</a>, <a href="visual_TextInput.js.html#line14">line 14</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Classes</h3>
|
||||
|
||||
<dl>
|
||||
<dt><a href="TextInput.html">TextInput</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.Keyboard.html">Keyboard</a></li><li><a href="module-core.KeyPress.html">KeyPress</a></li><li><a href="module-core.Logger.html">Logger</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.Form.html">Form</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Polygon.html">Polygon</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextBox.html">TextBox</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li><li><a href="TextInput.html">TextInput</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Thu Aug 20 2020 11:48:06 GMT+0200 (Central European Summer Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
2735
docs/module-visual.Form.html
Normal file
2735
docs/module-visual.Form.html
Normal file
File diff suppressed because it is too large
Load Diff
1622
docs/module-visual.TextBox.html
Normal file
1622
docs/module-visual.TextBox.html
Normal file
File diff suppressed because it is too large
Load Diff
1184
docs/visual_Form.js.html
Normal file
1184
docs/visual_Form.js.html
Normal file
File diff suppressed because it is too large
Load Diff
506
docs/visual_TextBox.js.html
Normal file
506
docs/visual_TextBox.js.html
Normal file
@ -0,0 +1,506 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: visual/TextBox.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: visual/TextBox.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* Editable TextBox Stimulus.
|
||||
*
|
||||
* @author Alain Pitiot
|
||||
* @version 2020.2
|
||||
* @copyright (c) 2020 Ilixa Ltd. ({@link http://ilixa.com})
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*/
|
||||
|
||||
|
||||
import {VisualStim} from './VisualStim';
|
||||
import {Color} from '../util/Color';
|
||||
import {ColorMixin} from '../util/ColorMixin';
|
||||
import {TextInput} from './TextInput';
|
||||
import * as util from '../util/Util';
|
||||
|
||||
// TODO finish documenting all options
|
||||
/**
|
||||
* @name module:visual.TextBox
|
||||
* @class
|
||||
* @extends VisualStim
|
||||
* @mixes ColorMixin
|
||||
* @param {Object} options
|
||||
* @param {String} options.name - the name used when logging messages from this stimulus
|
||||
* @param {Window} options.win - the associated Window
|
||||
* @param {string} [options.text=""] - the text to be rendered
|
||||
* @param {string} [options.font= "Arial"] - the font family
|
||||
* @param {Array.<number>} [options.pos= [0, 0]] - the position of the center of the text
|
||||
*
|
||||
* @param {Color} [options.color= Color('white')] the background color
|
||||
* @param {number} [options.opacity= 1.0] - the opacity
|
||||
* @param {number} [options.depth= 0] - the depth (i.e. the z order)
|
||||
* @param {number} [options.contrast= 1.0] - the contrast
|
||||
* @param {string} [options.units= "norm"] - the units of the text size and position
|
||||
* @param {number} [options.ori= 0.0] - the orientation (in degrees)
|
||||
* @param {number} [options.height= 0.1] - the height of the text
|
||||
* @param {boolean} [options.bold= false] - whether or not the text is bold
|
||||
* @param {boolean} [options.italic= false] - whether or not the text is italic
|
||||
* @param {string} [options.anchor = 'left'] - horizontal alignment
|
||||
*
|
||||
* @param {boolean} [options.flipHoriz= false] - whether or not to flip the text horizontally
|
||||
* @param {boolean} [options.lipVert= false] - whether or not to flip the text vertically
|
||||
* @param {PIXI.Graphics} [options.clipMask= null] - the clip mask
|
||||
* @param {boolean} [options.autoDraw= false] - whether or not the stimulus should be automatically drawn on every frame flip
|
||||
* @param {boolean} [options.autoLog= false] - whether or not to log
|
||||
*/
|
||||
export class TextBox extends util.mix(VisualStim).with(ColorMixin)
|
||||
{
|
||||
constructor({name, win, pos, anchor, size, units, ori, opacity, depth, text, font, letterHeight, bold, italic, alignment, color, contrast, flipHoriz, flipVert, fillColor, borderColor, borderWidth, padding, editable, clipMask, autoDraw, autoLog} = {})
|
||||
{
|
||||
super({name, win, pos, size, units, ori, opacity, depth, clipMask, autoDraw, autoLog});
|
||||
|
||||
this._addAttribute(
|
||||
'text',
|
||||
text,
|
||||
'',
|
||||
this._onChange(true, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'anchor',
|
||||
anchor,
|
||||
'center',
|
||||
this._onChange(false, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'flipHoriz',
|
||||
flipHoriz,
|
||||
false,
|
||||
this._onChange(false, false)
|
||||
);
|
||||
this._addAttribute(
|
||||
'flipVert',
|
||||
flipVert,
|
||||
false,
|
||||
this._onChange(false, false)
|
||||
);
|
||||
|
||||
// font:
|
||||
this._addAttribute(
|
||||
'font',
|
||||
font,
|
||||
'Arial',
|
||||
this._onChange(true, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'letterHeight',
|
||||
letterHeight,
|
||||
this._getDefaultLetterHeight(),
|
||||
this._onChange(true, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'bold',
|
||||
bold,
|
||||
false,
|
||||
this._onChange(true, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'italic',
|
||||
italic,
|
||||
false,
|
||||
this._onChange(true, true)
|
||||
);
|
||||
this._addAttribute(
|
||||
'alignment',
|
||||
alignment,
|
||||
'left',
|
||||
this._onChange(true, true)
|
||||
);
|
||||
|
||||
// colors:
|
||||
this._addAttribute(
|
||||
'color',
|
||||
color,
|
||||
'white',
|
||||
this._onChange(true, false)
|
||||
);
|
||||
this._addAttribute(
|
||||
'fillColor',
|
||||
fillColor,
|
||||
'lightgrey',
|
||||
this._onChange(true, false)
|
||||
);
|
||||
this._addAttribute(
|
||||
'borderColor',
|
||||
borderColor,
|
||||
'white',
|
||||
this._onChange(true, false)
|
||||
);
|
||||
this._addAttribute(
|
||||
'contrast',
|
||||
contrast,
|
||||
1.0,
|
||||
this._onChange(true, false)
|
||||
);
|
||||
|
||||
// default border width: 1px
|
||||
this._addAttribute(
|
||||
'borderWidth',
|
||||
borderWidth,
|
||||
util.to_unit([1, 0], 'pix', win, this._units)[0],
|
||||
this._onChange(true, true)
|
||||
);
|
||||
// default padding: half of the letter height
|
||||
this._addAttribute(
|
||||
'padding',
|
||||
padding,
|
||||
this._letterHeight / 2.0,
|
||||
this._onChange(true, true)
|
||||
);
|
||||
|
||||
this._addAttribute('editable', editable, false, this._onChange(true, true));
|
||||
// this._setAttribute({
|
||||
// name: 'vertices',
|
||||
// value: vertices,
|
||||
// assert: v => (v != null) && (typeof v !== 'undefined') && Array.isArray(v) )
|
||||
// log);
|
||||
|
||||
// estimate the bounding box:
|
||||
this._estimateBoundingBox();
|
||||
|
||||
if (this._autoLog)
|
||||
{
|
||||
this._psychoJS.experimentLogger.exp(`Created ${this.name} = ${this.toString()}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Setter for the size attribute.
|
||||
*
|
||||
* @name module:visual.TextBox#setSize
|
||||
* @public
|
||||
* @param {boolean} size - whether or not to wrap the text at the given width
|
||||
* @param {boolean} [log= false] - whether of not to log
|
||||
*/
|
||||
setSize(size, log)
|
||||
{
|
||||
// test with the size is undefined, or [undefined, undefined]:
|
||||
let isSizeUndefined = (
|
||||
(typeof size === 'undefined') || (size === null) ||
|
||||
( Array.isArray(size) && size.every( v => typeof v === 'undefined' || v === null) )
|
||||
);
|
||||
|
||||
if (isSizeUndefined)
|
||||
{
|
||||
size = TextBox._defaultSizeMap.get(this._units);
|
||||
|
||||
if (typeof size === 'undefined')
|
||||
{
|
||||
throw {
|
||||
origin: 'TextBox.setSize',
|
||||
context: 'when setting the size of TextBox: ' + this._name,
|
||||
error: 'no default size for unit: ' + this._units
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const hasChanged = this._setAttribute('size', size, log);
|
||||
|
||||
if (hasChanged)
|
||||
{
|
||||
this._needUpdate = true;
|
||||
this._needPixiUpdate = true;
|
||||
|
||||
// immediately estimate the bounding box:
|
||||
this._estimateBoundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the default letter height given the stimulus' units.
|
||||
*
|
||||
* @name module:visual.TextBox#_getDefaultLetterHeight
|
||||
* @return {number} - the letter height corresponding to this stimulus' units.
|
||||
* @protected
|
||||
*/
|
||||
_getDefaultLetterHeight()
|
||||
{
|
||||
const height = TextBox._defaultLetterHeightMap.get(this._units);
|
||||
|
||||
if (typeof height === 'undefined')
|
||||
{
|
||||
throw {
|
||||
origin: 'TextBox._getDefaultLetterHeight',
|
||||
context: 'when getting the default height of TextBox: ' + this._name,
|
||||
error: 'no default letter height for unit: ' + this._units
|
||||
};
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the TextInput options applied to the PIXI.TextInput.
|
||||
*
|
||||
* @name module:visual.TextBox#_getTextInputOptions
|
||||
* @private
|
||||
*/
|
||||
_getTextInputOptions()
|
||||
{
|
||||
const letterHeight_px = Math.round(this._getLengthPix(this._letterHeight));
|
||||
const padding_px = Math.round(this._getLengthPix(this._padding));
|
||||
const width_px = Math.round(this._getLengthPix(this._size[0]));
|
||||
const borderWidth_px = Math.round(this._getLengthPix(this._borderWidth));
|
||||
|
||||
return {
|
||||
input: {
|
||||
fontFamily: this._font,
|
||||
fontSize: letterHeight_px + 'px',
|
||||
color: new Color(this._color).hex,
|
||||
fontWeight: (this._bold) ? 'bold' : 'normal',
|
||||
fontStyle: (this._italic) ? 'italic' : 'normal',
|
||||
|
||||
padding: padding_px + 'px',
|
||||
width: (width_px - 2 * padding_px) + 'px'
|
||||
},
|
||||
box: {
|
||||
fill: new Color(this._fillColor).int,
|
||||
rounded: 5,
|
||||
stroke: {
|
||||
color: new Color(this._borderColor).int,
|
||||
width: borderWidth_px
|
||||
}
|
||||
/*default: {
|
||||
fill: new Color(this._fillColor).int,
|
||||
rounded: 5,
|
||||
stroke: {
|
||||
color: new Color(this._borderColor).int,
|
||||
width: borderWidth_px
|
||||
}
|
||||
},
|
||||
focused: {
|
||||
fill: new Color(this._fillColor).int,
|
||||
rounded: 5,
|
||||
stroke: {
|
||||
color: new Color(this._borderColor).int,
|
||||
width: borderWidth_px
|
||||
}
|
||||
},
|
||||
disabled: {
|
||||
fill: new Color(this._fillColor).int,
|
||||
rounded: 5,
|
||||
stroke: {
|
||||
color: new Color(this._borderColor).int,
|
||||
width: borderWidth_px
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Estimate the bounding box.
|
||||
*
|
||||
* @name module:visual.TextBox#_estimateBoundingBox
|
||||
* @function
|
||||
* @override
|
||||
* @protected
|
||||
*/
|
||||
_estimateBoundingBox()
|
||||
{
|
||||
// estimate the vertical size:
|
||||
const boxHeight = this._letterHeight + 2 * this._padding + 2 * this._borderWidth;
|
||||
|
||||
// take the alignment into account:
|
||||
const anchor = this._getAnchor();
|
||||
this._boundingBox = new PIXI.Rectangle(
|
||||
this._pos[0] - anchor[0] * this._size[0],
|
||||
this._pos[1] - anchor[1] * boxHeight,
|
||||
this._size[0],
|
||||
boxHeight
|
||||
);
|
||||
|
||||
// TODO take the orientation into account
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the stimulus, if necessary.
|
||||
*
|
||||
* @name module:visual.TextBox#_updateIfNeeded
|
||||
* @private
|
||||
*
|
||||
* @todo take size into account
|
||||
*/
|
||||
_updateIfNeeded()
|
||||
{
|
||||
if (!this._needUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._needUpdate = false;
|
||||
|
||||
// update the PIXI representation, if need be:
|
||||
if (this._needPixiUpdate)
|
||||
{
|
||||
this._needPixiUpdate = false;
|
||||
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
}
|
||||
this._pixi = new TextInput(this._getTextInputOptions());
|
||||
if (this._editable)
|
||||
{
|
||||
this._pixi.placeholder = this._text;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pixi.text = this._text;
|
||||
}
|
||||
}
|
||||
|
||||
this._pixi.disabled = !this._editable;
|
||||
|
||||
const anchor = this._getAnchor();
|
||||
this._pixi.pivot.x = anchor[0] * this._pixi.width;
|
||||
this._pixi.pivot.y = anchor[1] * this._pixi.height;
|
||||
|
||||
this._pixi.scale.x = this._flipHoriz ? -1 : 1;
|
||||
this._pixi.scale.y = this._flipVert ? 1 : -1;
|
||||
this._pixi.rotation = this._ori * Math.PI / 180;
|
||||
[this._pixi.x, this._pixi.y] = util.to_px(this._pos, this._units, this._win);
|
||||
|
||||
this._pixi.alpha = this._opacity;
|
||||
this._pixi.zIndex = this._depth;
|
||||
|
||||
// apply the clip mask:
|
||||
this._pixi.mask = this._clipMask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert the anchor attribute into numerical values.
|
||||
*
|
||||
* @name module:visual.TextBox#_getAnchor
|
||||
* @function
|
||||
* @protected
|
||||
* @return {number[]} - the anchor, as an array of numbers in [0,1]
|
||||
*/
|
||||
_getAnchor()
|
||||
{
|
||||
const anchor = [0.5, 0.5];
|
||||
|
||||
if (this._anchor.indexOf('left') > -1)
|
||||
{
|
||||
anchor[0] = 0;
|
||||
}
|
||||
else if (this._anchor.indexOf('right') > -1)
|
||||
{
|
||||
anchor[0] = 1;
|
||||
}
|
||||
if (this._anchor.indexOf('top') > -1)
|
||||
{
|
||||
anchor[1] = 0;
|
||||
}
|
||||
else if (this._anchor.indexOf('bottom') > -1)
|
||||
{
|
||||
anchor[1] = 1;
|
||||
}
|
||||
|
||||
return anchor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>This map associates units to default letter height.</p>
|
||||
*
|
||||
* @name module:visual.TextBox#_defaultLetterHeightMap
|
||||
* @readonly
|
||||
* @private
|
||||
*/
|
||||
TextBox._defaultLetterHeightMap = new Map([
|
||||
['cm', 1.0],
|
||||
['deg', 1.0],
|
||||
['degs', 1.0],
|
||||
['degFlatPos', 1.0],
|
||||
['degFlat', 1.0],
|
||||
['norm', 0.1],
|
||||
['height', 0.2],
|
||||
['pix', 20],
|
||||
['pixels', 20]
|
||||
]);
|
||||
|
||||
|
||||
/**
|
||||
* <p>This map associates units to default sizes.</p>
|
||||
*
|
||||
* @name module:visual.TextBox#_defaultSizeMap
|
||||
* @readonly
|
||||
* @private
|
||||
*/
|
||||
TextBox._defaultSizeMap = new Map([
|
||||
['cm', [15.0, -1]],
|
||||
['deg', [15.0, -1]],
|
||||
['degs', [15.0, -1]],
|
||||
['degFlatPos', [15.0, -1]],
|
||||
['degFlat', [15.0, -1]],
|
||||
['norm', [1, -1]],
|
||||
['height', [1, -1]],
|
||||
['pix', [500, -1]],
|
||||
['pixels', [500, -1]]
|
||||
]);
|
||||
</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.Keyboard.html">Keyboard</a></li><li><a href="module-core.KeyPress.html">KeyPress</a></li><li><a href="module-core.Logger.html">Logger</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.Form.html">Form</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Polygon.html">Polygon</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextBox.html">TextBox</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li><li><a href="TextInput.html">TextInput</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Thu Aug 20 2020 11:48:06 GMT+0200 (Central European Summer Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
903
docs/visual_TextInput.js.html
Normal file
903
docs/visual_TextInput.js.html
Normal file
@ -0,0 +1,903 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: visual/TextInput.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: visual/TextInput.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* TextInput encapsulates an html <input> element into a PIXI Container.
|
||||
*
|
||||
* @author 'Mwni' (https://github.com/Mwni)
|
||||
* @copyright (c) 2018 Mwni
|
||||
* @license Distributed under the terms of the MIT License
|
||||
*
|
||||
* @note TextInput was initially developed by 'Mwni' and is available under the MIT License.
|
||||
* We are currently using it almost as is but will be making modification in the near future.
|
||||
*/
|
||||
|
||||
export class TextInput extends PIXI.Container
|
||||
{
|
||||
constructor(styles)
|
||||
{
|
||||
super();
|
||||
this._input_style = Object.assign(
|
||||
{
|
||||
position: 'absolute',
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
outline: 'none',
|
||||
transformOrigin: '0 0',
|
||||
lineHeight: '1'
|
||||
},
|
||||
styles.input
|
||||
);
|
||||
|
||||
if (styles.box)
|
||||
{
|
||||
this._box_generator = typeof styles.box === 'function' ? styles.box : new DefaultBoxGenerator(styles.box);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._box_generator = null;
|
||||
}
|
||||
|
||||
if (this._input_style.hasOwnProperty('multiline'))
|
||||
{
|
||||
this._multiline = !!this._input_style.multiline;
|
||||
delete this._input_style.multiline;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._multiline = false;
|
||||
}
|
||||
|
||||
this._box_cache = {};
|
||||
this._previous = {};
|
||||
this._dom_added = false;
|
||||
this._dom_visible = true;
|
||||
this._placeholder = '';
|
||||
this._placeholderColor = 0xa9a9a9;
|
||||
this._selection = [0, 0];
|
||||
this._restrict_value = '';
|
||||
this._createDOMInput();
|
||||
this.substituteText = true;
|
||||
this._setState('DEFAULT');
|
||||
this._addListeners();
|
||||
}
|
||||
|
||||
|
||||
// GETTERS & SETTERS
|
||||
|
||||
get substituteText()
|
||||
{
|
||||
return this._substituted;
|
||||
}
|
||||
|
||||
set substituteText(substitute)
|
||||
{
|
||||
if (this._substituted == substitute)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._substituted = substitute;
|
||||
|
||||
if (substitute)
|
||||
{
|
||||
this._createSurrogate();
|
||||
this._dom_visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._destroySurrogate();
|
||||
this._dom_visible = true;
|
||||
}
|
||||
this.placeholder = this._placeholder;
|
||||
this._update();
|
||||
}
|
||||
|
||||
get placeholder()
|
||||
{
|
||||
return this._placeholder;
|
||||
}
|
||||
|
||||
set placeholder(text)
|
||||
{
|
||||
this._placeholder = text;
|
||||
if (this._substituted)
|
||||
{
|
||||
this._updateSurrogate();
|
||||
this._dom_input.placeholder = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dom_input.placeholder = text;
|
||||
}
|
||||
}
|
||||
|
||||
get disabled()
|
||||
{
|
||||
return this._disabled;
|
||||
}
|
||||
|
||||
set disabled(disabled)
|
||||
{
|
||||
this._disabled = disabled;
|
||||
this._dom_input.disabled = disabled;
|
||||
this._setState(disabled ? 'DISABLED' : 'DEFAULT');
|
||||
}
|
||||
|
||||
get maxLength()
|
||||
{
|
||||
return this._max_length;
|
||||
}
|
||||
|
||||
set maxLength(length)
|
||||
{
|
||||
this._max_length = length;
|
||||
this._dom_input.setAttribute('maxlength', length);
|
||||
}
|
||||
|
||||
get restrict()
|
||||
{
|
||||
return this._restrict_regex;
|
||||
}
|
||||
|
||||
set restrict(regex)
|
||||
{
|
||||
if (regex instanceof RegExp)
|
||||
{
|
||||
regex = regex.toString().slice(1, -1);
|
||||
|
||||
if (regex.charAt(0) !== '^')
|
||||
{
|
||||
regex = '^' + regex;
|
||||
}
|
||||
|
||||
if (regex.charAt(regex.length - 1) !== '$')
|
||||
{
|
||||
regex = regex + '$';
|
||||
}
|
||||
|
||||
regex = new RegExp(regex);
|
||||
}
|
||||
else
|
||||
{
|
||||
regex = new RegExp('^[' + regex + ']*$');
|
||||
}
|
||||
|
||||
this._restrict_regex = regex;
|
||||
}
|
||||
|
||||
get text()
|
||||
{
|
||||
return this._dom_input.value;
|
||||
}
|
||||
|
||||
set text(text)
|
||||
{
|
||||
this._dom_input.value = text;
|
||||
if (this._substituted)
|
||||
{
|
||||
this._updateSurrogate();
|
||||
}
|
||||
}
|
||||
|
||||
get htmlInput()
|
||||
{
|
||||
return this._dom_input;
|
||||
}
|
||||
|
||||
focus()
|
||||
{
|
||||
if (this._substituted && !this.dom_visible)
|
||||
{
|
||||
this._setDOMInputVisible(true);
|
||||
}
|
||||
|
||||
this._dom_input.focus();
|
||||
|
||||
}
|
||||
|
||||
blur()
|
||||
{
|
||||
this._dom_input.blur();
|
||||
}
|
||||
|
||||
select()
|
||||
{
|
||||
this.focus();
|
||||
this._dom_input.select();
|
||||
}
|
||||
|
||||
setInputStyle(key, value)
|
||||
{
|
||||
this._input_style[key] = value;
|
||||
this._dom_input.style[key] = value;
|
||||
|
||||
if (this._substituted && (key === 'fontFamily' || key === 'fontSize'))
|
||||
{
|
||||
this._updateFontMetrics();
|
||||
}
|
||||
|
||||
if (this._last_renderer)
|
||||
{
|
||||
this._update();
|
||||
}
|
||||
}
|
||||
|
||||
destroy(options)
|
||||
{
|
||||
this._destroyBoxCache();
|
||||
super.destroy(options);
|
||||
}
|
||||
|
||||
|
||||
// SETUP
|
||||
|
||||
_createDOMInput()
|
||||
{
|
||||
if (this._multiline)
|
||||
{
|
||||
this._dom_input = document.createElement('textarea');
|
||||
this._dom_input.style.resize = 'none';
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dom_input = document.createElement('input');
|
||||
this._dom_input.type = 'text';
|
||||
}
|
||||
|
||||
for (let key in this._input_style)
|
||||
{
|
||||
this._dom_input.style[key] = this._input_style[key];
|
||||
}
|
||||
}
|
||||
|
||||
_addListeners()
|
||||
{
|
||||
this.on('added', this._onAdded.bind(this));
|
||||
this.on('removed', this._onRemoved.bind(this));
|
||||
this._dom_input.addEventListener('keydown', this._onInputKeyDown.bind(this));
|
||||
this._dom_input.addEventListener('input', this._onInputInput.bind(this));
|
||||
this._dom_input.addEventListener('keyup', this._onInputKeyUp.bind(this));
|
||||
this._dom_input.addEventListener('focus', this._onFocused.bind(this));
|
||||
this._dom_input.addEventListener('blur', this._onBlurred.bind(this));
|
||||
}
|
||||
|
||||
_onInputKeyDown(e)
|
||||
{
|
||||
this._selection = [
|
||||
this._dom_input.selectionStart,
|
||||
this._dom_input.selectionEnd
|
||||
];
|
||||
|
||||
this.emit('keydown', e.keyCode);
|
||||
}
|
||||
|
||||
_onInputInput(e)
|
||||
{
|
||||
if (this._restrict_regex)
|
||||
{
|
||||
this._applyRestriction();
|
||||
}
|
||||
|
||||
if (this._substituted)
|
||||
{
|
||||
this._updateSubstitution();
|
||||
}
|
||||
|
||||
this.emit('input', this.text);
|
||||
}
|
||||
|
||||
_onInputKeyUp(e)
|
||||
{
|
||||
this.emit('keyup', e.keyCode);
|
||||
}
|
||||
|
||||
_onFocused()
|
||||
{
|
||||
this._setState('FOCUSED');
|
||||
this.emit('focus');
|
||||
}
|
||||
|
||||
_onBlurred()
|
||||
{
|
||||
this._setState('DEFAULT');
|
||||
this.emit('blur');
|
||||
}
|
||||
|
||||
_onAdded()
|
||||
{
|
||||
document.body.appendChild(this._dom_input);
|
||||
this._dom_input.style.display = 'none';
|
||||
this._dom_added = true;
|
||||
}
|
||||
|
||||
_onRemoved()
|
||||
{
|
||||
document.body.removeChild(this._dom_input);
|
||||
this._dom_added = false;
|
||||
}
|
||||
|
||||
_setState(state)
|
||||
{
|
||||
this.state = state;
|
||||
this._updateBox();
|
||||
if (this._substituted)
|
||||
{
|
||||
this._updateSubstitution();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// RENDER & UPDATE
|
||||
|
||||
// for pixi v4
|
||||
renderWebGL(renderer)
|
||||
{
|
||||
super.renderWebGL(renderer);
|
||||
this._renderInternal(renderer);
|
||||
}
|
||||
|
||||
// for pixi v4
|
||||
renderCanvas(renderer)
|
||||
{
|
||||
super.renderCanvas(renderer);
|
||||
this._renderInternal(renderer);
|
||||
}
|
||||
|
||||
// for pixi v5
|
||||
render(renderer)
|
||||
{
|
||||
super.render(renderer);
|
||||
this._renderInternal(renderer);
|
||||
}
|
||||
|
||||
_renderInternal(renderer)
|
||||
{
|
||||
this._resolution = renderer.resolution;
|
||||
this._last_renderer = renderer;
|
||||
this._canvas_bounds = this._getCanvasBounds();
|
||||
if (this._needsUpdate())
|
||||
{
|
||||
this._update();
|
||||
}
|
||||
}
|
||||
|
||||
_update()
|
||||
{
|
||||
this._updateDOMInput();
|
||||
if (this._substituted)
|
||||
{
|
||||
this._updateSurrogate();
|
||||
}
|
||||
this._updateBox();
|
||||
}
|
||||
|
||||
_updateBox()
|
||||
{
|
||||
if (!this._box_generator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._needsNewBoxCache())
|
||||
{
|
||||
this._buildBoxCache();
|
||||
}
|
||||
|
||||
if (this.state == this._previous.state && this._box == this._box_cache[this.state])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._box)
|
||||
{
|
||||
this.removeChild(this._box);
|
||||
}
|
||||
|
||||
this._box = this._box_cache[this.state];
|
||||
this.addChildAt(this._box, 0);
|
||||
this._previous.state = this.state;
|
||||
}
|
||||
|
||||
_updateSubstitution()
|
||||
{
|
||||
if (this.state === 'FOCUSED')
|
||||
{
|
||||
this._dom_visible = true;
|
||||
this._surrogate.visible = this.text.length === 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dom_visible = false;
|
||||
this._surrogate.visible = true;
|
||||
}
|
||||
this._updateDOMInput();
|
||||
this._updateSurrogate();
|
||||
}
|
||||
|
||||
_updateDOMInput()
|
||||
{
|
||||
if (!this._canvas_bounds)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._dom_input.style.top = (this._canvas_bounds.top || 0) + 'px';
|
||||
this._dom_input.style.left = (this._canvas_bounds.left || 0) + 'px';
|
||||
this._dom_input.style.transform = this._pixiMatrixToCSS(this._getDOMRelativeWorldTransform());
|
||||
this._dom_input.style.opacity = this.worldAlpha;
|
||||
this._setDOMInputVisible(this.worldVisible && this._dom_visible);
|
||||
|
||||
this._previous.canvas_bounds = this._canvas_bounds;
|
||||
this._previous.world_transform = this.worldTransform.clone();
|
||||
this._previous.world_alpha = this.worldAlpha;
|
||||
this._previous.world_visible = this.worldVisible;
|
||||
}
|
||||
|
||||
_applyRestriction()
|
||||
{
|
||||
if (this._restrict_regex.test(this.text))
|
||||
{
|
||||
this._restrict_value = this.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.text = this._restrict_value;
|
||||
this._dom_input.setSelectionRange(
|
||||
this._selection[0],
|
||||
this._selection[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// STATE COMPAIRSON (FOR PERFORMANCE BENEFITS)
|
||||
|
||||
_needsUpdate()
|
||||
{
|
||||
return (
|
||||
!this._comparePixiMatrices(this.worldTransform, this._previous.world_transform) ||
|
||||
!this._compareClientRects(this._canvas_bounds, this._previous.canvas_bounds) ||
|
||||
this.worldAlpha != this._previous.world_alpha ||
|
||||
this.worldVisible != this._previous.world_visible
|
||||
);
|
||||
}
|
||||
|
||||
_needsNewBoxCache()
|
||||
{
|
||||
let input_bounds = this._getDOMInputBounds();
|
||||
return (
|
||||
!this._previous.input_bounds ||
|
||||
input_bounds.width != this._previous.input_bounds.width ||
|
||||
input_bounds.height != this._previous.input_bounds.height
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// INPUT SUBSTITUTION
|
||||
|
||||
_createSurrogate()
|
||||
{
|
||||
this._surrogate_hitbox = new PIXI.Graphics();
|
||||
this._surrogate_hitbox.alpha = 0;
|
||||
this._surrogate_hitbox.interactive = true;
|
||||
this._surrogate_hitbox.cursor = 'text';
|
||||
this._surrogate_hitbox.on('pointerdown', this._onSurrogateFocus.bind(this));
|
||||
this.addChild(this._surrogate_hitbox);
|
||||
|
||||
this._surrogate_mask = new PIXI.Graphics();
|
||||
this.addChild(this._surrogate_mask);
|
||||
|
||||
this._surrogate = new PIXI.Text('', {});
|
||||
this.addChild(this._surrogate);
|
||||
|
||||
this._surrogate.mask = this._surrogate_mask;
|
||||
|
||||
this._updateFontMetrics();
|
||||
this._updateSurrogate();
|
||||
}
|
||||
|
||||
_updateSurrogate()
|
||||
{
|
||||
let padding = this._deriveSurrogatePadding();
|
||||
let input_bounds = this._getDOMInputBounds();
|
||||
|
||||
this._surrogate.style = this._deriveSurrogateStyle();
|
||||
this._surrogate.style.padding = Math.max.apply(Math, padding);
|
||||
this._surrogate.y = this._multiline ? padding[0] : (input_bounds.height - this._surrogate.height) / 2;
|
||||
this._surrogate.x = padding[3];
|
||||
this._surrogate.text = this._deriveSurrogateText();
|
||||
|
||||
switch (this._surrogate.style.align)
|
||||
{
|
||||
case 'left':
|
||||
this._surrogate.x = padding[3];
|
||||
break;
|
||||
|
||||
case 'center':
|
||||
this._surrogate.x = input_bounds.width * 0.5 - this._surrogate.width * 0.5;
|
||||
break;
|
||||
|
||||
case 'right':
|
||||
this._surrogate.x = input_bounds.width - padding[1] - this._surrogate.width;
|
||||
break;
|
||||
}
|
||||
|
||||
this._updateSurrogateHitbox(input_bounds);
|
||||
this._updateSurrogateMask(input_bounds, padding);
|
||||
}
|
||||
|
||||
_updateSurrogateHitbox(bounds)
|
||||
{
|
||||
this._surrogate_hitbox.clear();
|
||||
this._surrogate_hitbox.beginFill(0);
|
||||
this._surrogate_hitbox.drawRect(0, 0, bounds.width, bounds.height);
|
||||
this._surrogate_hitbox.endFill();
|
||||
this._surrogate_hitbox.interactive = !this._disabled;
|
||||
}
|
||||
|
||||
_updateSurrogateMask(bounds, padding)
|
||||
{
|
||||
this._surrogate_mask.clear();
|
||||
this._surrogate_mask.beginFill(0);
|
||||
this._surrogate_mask.drawRect(padding[3], 0, bounds.width - padding[3] - padding[1], bounds.height);
|
||||
this._surrogate_mask.endFill();
|
||||
}
|
||||
|
||||
_destroySurrogate()
|
||||
{
|
||||
if (!this._surrogate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.removeChild(this._surrogate);
|
||||
this.removeChild(this._surrogate_hitbox);
|
||||
|
||||
this._surrogate.destroy();
|
||||
this._surrogate_hitbox.destroy();
|
||||
|
||||
this._surrogate = null;
|
||||
this._surrogate_hitbox = null;
|
||||
}
|
||||
|
||||
_onSurrogateFocus()
|
||||
{
|
||||
this._setDOMInputVisible(true);
|
||||
//sometimes the input is not being focused by the mouseclick
|
||||
setTimeout(this._ensureFocus.bind(this), 10);
|
||||
}
|
||||
|
||||
_ensureFocus()
|
||||
{
|
||||
if (!this._hasFocus())
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
|
||||
_deriveSurrogateStyle()
|
||||
{
|
||||
let style = new PIXI.TextStyle();
|
||||
|
||||
for (const key in this._input_style)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 'color':
|
||||
style.fill = this._input_style.color;
|
||||
break;
|
||||
|
||||
case 'fontFamily':
|
||||
case 'fontSize':
|
||||
case 'fontWeight':
|
||||
case 'fontVariant':
|
||||
case 'fontStyle':
|
||||
style[key] = this._input_style[key];
|
||||
break;
|
||||
|
||||
case 'letterSpacing':
|
||||
style.letterSpacing = parseFloat(this._input_style.letterSpacing);
|
||||
break;
|
||||
|
||||
case 'textAlign':
|
||||
style.align = this._input_style.textAlign;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._multiline)
|
||||
{
|
||||
style.lineHeight = parseFloat(style.fontSize);
|
||||
style.wordWrap = true;
|
||||
style.wordWrapWidth = this._getDOMInputBounds().width;
|
||||
}
|
||||
|
||||
if (this._dom_input.value.length === 0)
|
||||
{
|
||||
style.fill = this._placeholderColor;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
_deriveSurrogatePadding()
|
||||
{
|
||||
let indent = this._input_style.textIndent ? parseFloat(this._input_style.textIndent) : 0;
|
||||
|
||||
if (this._input_style.padding && this._input_style.padding.length > 0)
|
||||
{
|
||||
let components = this._input_style.padding.trim().split(' ');
|
||||
|
||||
if (components.length == 1)
|
||||
{
|
||||
let padding = parseFloat(components[0]);
|
||||
return [padding, padding, padding, padding + indent];
|
||||
}
|
||||
else if (components.length == 2)
|
||||
{
|
||||
let paddingV = parseFloat(components[0]);
|
||||
let paddingH = parseFloat(components[1]);
|
||||
return [paddingV, paddingH, paddingV, paddingH + indent];
|
||||
}
|
||||
else if (components.length == 4)
|
||||
{
|
||||
let padding = components.map(component =>
|
||||
{
|
||||
return parseFloat(component);
|
||||
});
|
||||
padding[3] += indent;
|
||||
return padding;
|
||||
}
|
||||
}
|
||||
|
||||
return [0, 0, 0, indent];
|
||||
}
|
||||
|
||||
_deriveSurrogateText()
|
||||
{
|
||||
return this._dom_input.value.length === 0 ? this._placeholder : this._dom_input.value;
|
||||
}
|
||||
|
||||
_updateFontMetrics()
|
||||
{
|
||||
const style = this._deriveSurrogateStyle();
|
||||
const font = style.toFontString();
|
||||
|
||||
this._font_metrics = PIXI.TextMetrics.measureFont(font);
|
||||
}
|
||||
|
||||
|
||||
// CACHING OF INPUT BOX GRAPHICS
|
||||
|
||||
_buildBoxCache()
|
||||
{
|
||||
this._destroyBoxCache();
|
||||
|
||||
let states = ['DEFAULT', 'FOCUSED', 'DISABLED'];
|
||||
let input_bounds = this._getDOMInputBounds();
|
||||
|
||||
for (let i in states)
|
||||
{
|
||||
this._box_cache[states[i]] = this._box_generator(
|
||||
input_bounds.width,
|
||||
input_bounds.height,
|
||||
states[i]
|
||||
);
|
||||
}
|
||||
|
||||
this._previous.input_bounds = input_bounds;
|
||||
}
|
||||
|
||||
_destroyBoxCache()
|
||||
{
|
||||
if (this._box)
|
||||
{
|
||||
this.removeChild(this._box);
|
||||
this._box = null;
|
||||
}
|
||||
|
||||
for (let i in this._box_cache)
|
||||
{
|
||||
this._box_cache[i].destroy();
|
||||
this._box_cache[i] = null;
|
||||
delete this._box_cache[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// HELPER FUNCTIONS
|
||||
|
||||
_hasFocus()
|
||||
{
|
||||
return document.activeElement === this._dom_input;
|
||||
}
|
||||
|
||||
_setDOMInputVisible(visible)
|
||||
{
|
||||
this._dom_input.style.display = visible ? 'block' : 'none';
|
||||
}
|
||||
|
||||
_getCanvasBounds()
|
||||
{
|
||||
let rect = this._last_renderer.view.getBoundingClientRect();
|
||||
let bounds = {top: rect.top, left: rect.left, width: rect.width, height: rect.height};
|
||||
bounds.left += window.scrollX;
|
||||
bounds.top += window.scrollY;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
_getDOMInputBounds()
|
||||
{
|
||||
let remove_after = false;
|
||||
|
||||
if (!this._dom_added)
|
||||
{
|
||||
document.body.appendChild(this._dom_input);
|
||||
remove_after = true;
|
||||
}
|
||||
|
||||
let org_transform = this._dom_input.style.transform;
|
||||
let org_display = this._dom_input.style.display;
|
||||
this._dom_input.style.transform = '';
|
||||
this._dom_input.style.display = 'block';
|
||||
let bounds = this._dom_input.getBoundingClientRect();
|
||||
this._dom_input.style.transform = org_transform;
|
||||
this._dom_input.style.display = org_display;
|
||||
|
||||
if (remove_after)
|
||||
{
|
||||
document.body.removeChild(this._dom_input);
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
_getDOMRelativeWorldTransform()
|
||||
{
|
||||
let canvas_bounds = this._last_renderer.view.getBoundingClientRect();
|
||||
let matrix = this.worldTransform.clone();
|
||||
|
||||
matrix.scale(this._resolution, this._resolution);
|
||||
matrix.scale(canvas_bounds.width / this._last_renderer.width,
|
||||
canvas_bounds.height / this._last_renderer.height);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
_pixiMatrixToCSS(m)
|
||||
{
|
||||
return 'matrix(' + [m.a, m.b, m.c, m.d, m.tx, m.ty].join(',') + ')';
|
||||
}
|
||||
|
||||
_comparePixiMatrices(m1, m2)
|
||||
{
|
||||
if (!m1 || !m2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
m1.a == m2.a &&
|
||||
m1.b == m2.b &&
|
||||
m1.c == m2.c &&
|
||||
m1.d == m2.d &&
|
||||
m1.tx == m2.tx &&
|
||||
m1.ty == m2.ty
|
||||
);
|
||||
}
|
||||
|
||||
_compareClientRects(r1, r2)
|
||||
{
|
||||
if (!r1 || !r2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
r1.left == r2.left &&
|
||||
r1.top == r2.top &&
|
||||
r1.width == r2.width &&
|
||||
r1.height == r2.height
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function DefaultBoxGenerator(styles)
|
||||
{
|
||||
styles = styles || {fill: 0xcccccc};
|
||||
|
||||
if (styles.default)
|
||||
{
|
||||
styles.focused = styles.focused || styles.default;
|
||||
styles.disabled = styles.disabled || styles.default;
|
||||
}
|
||||
else
|
||||
{
|
||||
let temp_styles = styles;
|
||||
styles = {};
|
||||
styles.default = styles.focused = styles.disabled = temp_styles;
|
||||
}
|
||||
|
||||
return function (w, h, state)
|
||||
{
|
||||
let style = styles[state.toLowerCase()];
|
||||
let box = new PIXI.Graphics();
|
||||
|
||||
if (style.fill)
|
||||
{
|
||||
box.beginFill(style.fill);
|
||||
}
|
||||
|
||||
if (style.stroke)
|
||||
{
|
||||
box.lineStyle(
|
||||
style.stroke.width || 1,
|
||||
style.stroke.color || 0,
|
||||
style.stroke.alpha || 1
|
||||
);
|
||||
}
|
||||
|
||||
if (style.rounded)
|
||||
{
|
||||
box.drawRoundedRect(0, 0, w, h, style.rounded);
|
||||
}
|
||||
else
|
||||
{
|
||||
box.drawRect(0, 0, w, h);
|
||||
}
|
||||
|
||||
box.endFill();
|
||||
box.closePath();
|
||||
|
||||
return box;
|
||||
};
|
||||
}
|
||||
</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.Keyboard.html">Keyboard</a></li><li><a href="module-core.KeyPress.html">KeyPress</a></li><li><a href="module-core.Logger.html">Logger</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.Form.html">Form</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Polygon.html">Polygon</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextBox.html">TextBox</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li><li><a href="TextInput.html">TextInput</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Thu Aug 20 2020 11:48:06 GMT+0200 (Central European Summer Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user