mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
276 lines
8.6 KiB
HTML
276 lines
8.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: core/MinimalStim.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: core/MinimalStim.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
* Base class for all stimuli.
|
|
*
|
|
* @author Alain Pitiot
|
|
* @version 2020.5
|
|
* @copyright (c) 2018-2020 Ilixa Ltd. (http://ilixa.com) (c) 2020 Open Science Tools Ltd. (https://opensciencetools.org)
|
|
* @license Distributed under the terms of the MIT License
|
|
*/
|
|
|
|
|
|
import {PsychObject} from '../util/PsychObject';
|
|
import {PsychoJS} from './PsychoJS';
|
|
import * as util from '../util/Util';
|
|
|
|
|
|
|
|
/**
|
|
* <p>MinimalStim is the base class for all stimuli.</p>
|
|
*
|
|
* @name module:core.MinimalStim
|
|
* @class
|
|
* @extends PsychObject
|
|
* @param {Object} options
|
|
* @param {String} options.name - the name used when logging messages from this stimulus
|
|
* @param {module:core.Window} options.win - the associated Window
|
|
* @param {boolean} [options.autoDraw= false] - whether or not the stimulus should be automatically drawn on every frame flip
|
|
* @param {boolean} [options.autoLog= win.autoLog] - whether or not to log
|
|
*/
|
|
export class MinimalStim extends PsychObject
|
|
{
|
|
constructor({name, win, autoDraw, autoLog} = {})
|
|
{
|
|
super(win._psychoJS, name);
|
|
|
|
// the PIXI representation of the stimulus:
|
|
this._pixi = undefined;
|
|
|
|
this._addAttribute(
|
|
'win',
|
|
win,
|
|
undefined
|
|
);
|
|
this._addAttribute(
|
|
'autoDraw',
|
|
autoDraw,
|
|
false
|
|
);
|
|
this._addAttribute(
|
|
'autoLog',
|
|
autoLog,
|
|
(typeof win !== 'undefined' && win !== null) ? win.autoLog : false
|
|
);
|
|
|
|
this._needUpdate = false;
|
|
this.status = PsychoJS.Status.NOT_STARTED;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Setter for the autoDraw attribute.
|
|
*
|
|
* @name module:core.MinimalStim#setAutoDraw
|
|
* @function
|
|
* @public
|
|
* @param {boolean} autoDraw - the new value
|
|
* @param {boolean} [log= false] - whether or not to log
|
|
*/
|
|
setAutoDraw(autoDraw, log = false)
|
|
{
|
|
this._setAttribute('autoDraw', autoDraw, log);
|
|
|
|
// autoDraw = true: add the stimulus to the draw list if it's not there already
|
|
if (this._autoDraw)
|
|
{
|
|
this.draw();
|
|
}
|
|
|
|
// autoDraw = false: remove the stimulus from the draw list (and from the root container if it's already there)
|
|
else
|
|
{
|
|
this.hide();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Draw this stimulus on the next frame draw.
|
|
*
|
|
* @name module:core.MinimalStim#draw
|
|
* @function
|
|
* @public
|
|
*/
|
|
draw()
|
|
{
|
|
if (this.win)
|
|
{
|
|
const index = this._win._drawList.indexOf(this);
|
|
|
|
// if the stimulus is not already in the draw list:
|
|
if (index < 0)
|
|
{
|
|
// update the stimulus if need be before we add its PIXI representation to the window container:
|
|
this._updateIfNeeded();
|
|
if (typeof this._pixi === 'undefined')
|
|
{
|
|
this.psychoJS.logger.warn('the Pixi.js representation of this stimulus is undefined.');
|
|
}// throw Object.assign(response, { error: 'the PIXI representation of the stimulus is unavailable'});
|
|
else
|
|
{
|
|
this.win._rootContainer.addChild(this._pixi);
|
|
this.win._drawList.push(this);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// the stimulus is already in the list, if it needs to be updated, we remove it
|
|
// from the window container, update it, then put it back:
|
|
if (this._needUpdate && typeof this._pixi !== 'undefined')
|
|
{
|
|
this.win._rootContainer.removeChild(this._pixi);
|
|
this._updateIfNeeded();
|
|
this.win._rootContainer.addChild(this._pixi);
|
|
}
|
|
}
|
|
}
|
|
|
|
this.status = PsychoJS.Status.STARTED;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Hide this stimulus on the next frame draw.
|
|
*
|
|
* @name module:core.MinimalStim#hide
|
|
* @function
|
|
* @public
|
|
*/
|
|
hide()
|
|
{
|
|
if (this._win)
|
|
{
|
|
const index = this._win._drawList.indexOf(this);
|
|
if (index >= 0)
|
|
{
|
|
this._win._drawList.splice(index, 1);
|
|
|
|
// if the stimulus has a pixi representation, remove it from the root container:
|
|
if (typeof this._pixi !== 'undefined')
|
|
{
|
|
this._win._rootContainer.removeChild(this._pixi);
|
|
}
|
|
}
|
|
this.status = PsychoJS.Status.STOPPED;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Determine whether an object is inside this stimulus.
|
|
*
|
|
* @name module:core.MinimalStim#contains
|
|
* @function
|
|
* @abstract
|
|
* @public
|
|
* @param {Object} object - the object
|
|
* @param {String} units - the stimulus units
|
|
*/
|
|
contains(object, units)
|
|
{
|
|
throw {
|
|
origin: 'MinimalStim.contains',
|
|
context: `when determining whether stimulus: ${this._name} contains object: ${util.toString(object)}`,
|
|
error: 'this method is abstract and should not be called.'
|
|
};
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Release the PIXI representation, if there is one.
|
|
*
|
|
* @name module:core.MinimalStim#release
|
|
* @function
|
|
* @public
|
|
*
|
|
* @param {boolean} [log= false] - whether or not to log
|
|
*/
|
|
release(log = false)
|
|
{
|
|
this._setAttribute('autoDraw', false, log);
|
|
this.status = PsychoJS.Status.STOPPED;
|
|
|
|
if (typeof this._pixi !== 'undefined')
|
|
{
|
|
this._pixi.destroy(true);
|
|
this._pixi = undefined;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Update the stimulus, if necessary.
|
|
*
|
|
* Note: this is an abstract function, which should not be called.
|
|
*
|
|
* @name module:core.MinimalStim#_updateIfNeeded
|
|
* @function
|
|
* @abstract
|
|
* @private
|
|
*/
|
|
_updateIfNeeded()
|
|
{
|
|
throw {
|
|
origin: 'MinimalStim._updateIfNeeded',
|
|
context: 'when updating stimulus: ' + this._name,
|
|
error: 'this method is abstract and should not be called.'
|
|
};
|
|
}
|
|
}
|
|
</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>
|