1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-12 16:48:10 +00:00

Merge pull request #391 from apitiot/master

added the notion of dependent stimuli to Slider
This commit is contained in:
Alain Pitiot 2021-06-11 10:14:38 +02:00 committed by GitHub
commit 0da4e6ff66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 deletions

View File

@ -106,7 +106,7 @@ export class MinimalStim extends PsychObject
if (typeof this._pixi === 'undefined') if (typeof this._pixi === 'undefined')
{ {
this.psychoJS.logger.warn('the Pixi.js representation of this stimulus is 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 else
{ {
this.win._rootContainer.addChild(this._pixi); this.win._rootContainer.addChild(this._pixi);

View File

@ -359,7 +359,8 @@ export class Window extends PsychObject
this._renderer.backgroundColor = this._color.int; this._renderer.backgroundColor = this._color.int;
} }
// we also change the background color of the body since the dialog popup may be longer than the window's height: // we also change the background color of the body since
// the dialog popup may be longer than the window's height:
document.body.style.backgroundColor = this._color.hex; document.body.style.backgroundColor = this._color.hex;
this._needUpdate = false; this._needUpdate = false;
@ -378,7 +379,8 @@ export class Window extends PsychObject
{ {
this._updateIfNeeded(); this._updateIfNeeded();
// if a stimuli needs to be updated, we remove it from the window container, update it, then put it back // if a stimuli needs to be updated, we remove it from the window container,
// update it, then put it back
for (const stimulus of this._drawList) for (const stimulus of this._drawList)
{ {
if (stimulus._needUpdate && typeof stimulus._pixi !== 'undefined') if (stimulus._needUpdate && typeof stimulus._pixi !== 'undefined')

View File

@ -923,7 +923,9 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
this._visual.stimuliTotalHeight = stimulusOffset; this._visual.stimuliTotalHeight = stimulusOffset;
// scrollbar: // scrollbar
// note: we add this Form as a dependent stimulus such that the Form is redrawn whenever
// the slider is updated
this._scrollbar = new Slider({ this._scrollbar = new Slider({
win: this._win, win: this._win,
name: 'scrollbar', name: 'scrollbar',
@ -934,6 +936,7 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
size: [this._scrollbarWidth, this._size[1]], size: [this._scrollbarWidth, this._size[1]],
style: [Slider.Style.SLIDER], style: [Slider.Style.SLIDER],
ticks: [0, -this._visual.stimuliTotalHeight / this._size[1]], ticks: [0, -this._visual.stimuliTotalHeight / this._size[1]],
dependentStims: [this]
}); });
this._prevScrollbarMarkerPos = 0; this._prevScrollbarMarkerPos = 0;
this._scrollbar.setMarkerPos(this._prevScrollbarMarkerPos); this._scrollbar.setMarkerPos(this._prevScrollbarMarkerPos);
@ -968,7 +971,6 @@ export class Form extends util.mix(VisualStim).with(ColorMixin)
} }
this._needUpdate = false; this._needUpdate = false;
// calculate the edges of the form and various other sizes, in various units: // calculate the edges of the form and various other sizes, in various units:
this._leftEdge = this._pos[0] - this._size[0] / 2.0; this._leftEdge = this._pos[0] - this._size[0] / 2.0;
this._rightEdge = this._pos[0] + this._size[0] / 2.0; this._rightEdge = this._pos[0] + this._size[0] / 2.0;

View File

@ -59,6 +59,9 @@ import {PsychoJS} from "../core/PsychoJS";
* frame flip * frame flip
* @param {boolean} [options.autoLog= false] - whether or not to log * @param {boolean} [options.autoLog= false] - whether or not to log
* *
* @param {core.MinimalStim[]} [options.dependentStims = [] ] - the list of dependent stimuli,
* which must be updated when this Slider is updated, e.g. a Form.
*
* @todo check that parameters are valid, e.g. ticks are an array of numbers, etc. * @todo check that parameters are valid, e.g. ticks are an array of numbers, etc.
* @todo readOnly * @todo readOnly
* @todo complete setters, for instance setTicks should change this._isCategorical * @todo complete setters, for instance setTicks should change this._isCategorical
@ -66,7 +69,7 @@ import {PsychoJS} from "../core/PsychoJS";
*/ */
export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin) export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
{ {
constructor({name, win, pos, size, ori, units, color, markerColor, contrast, opacity, style, ticks, labels, granularity, flip, readOnly, font, bold, italic, fontSize, compact, clipMask, autoDraw, autoLog} = {}) constructor({name, win, pos, size, ori, units, color, markerColor, contrast, opacity, style, ticks, labels, granularity, flip, readOnly, font, bold, italic, fontSize, compact, clipMask, autoDraw, autoLog, dependentStims} = {})
{ {
super({name, win, units, ori, opacity, pos, size, clipMask, autoDraw, autoLog}); super({name, win, units, ori, opacity, pos, size, clipMask, autoDraw, autoLog});
@ -179,6 +182,14 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
this._onChange(true, false) this._onChange(true, false)
); );
this._addAttribute(
'dependentStims',
dependentStims,
[],
this._onChange(false, false)
);
// slider rating (which might be different from the visible marker rating): // slider rating (which might be different from the visible marker rating):
this._addAttribute('rating', undefined); this._addAttribute('rating', undefined);
@ -607,6 +618,12 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
this._pixi.position = this._getPosition_px(); this._pixi.position = this._getPosition_px();
this._pixi.alpha = this._opacity; this._pixi.alpha = this._opacity;
// make sure that the dependent Stimuli are also updated:
for (const dependentStim of this._dependentStims)
{
dependentStim.draw();
}
} }