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

Merge pull request #504 from lightest/CU-2au7jeu_orientation_for_slider

Proper orientation setter for Slider
This commit is contained in:
Alain Pitiot 2022-06-10 11:57:34 +02:00 committed by GitHub
commit 4d6f1e631c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -244,6 +244,7 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
// the internal response clock, used to time the marker change events:
this._responseClock = new Clock();
this._pixiLabels = [];
if (this._autoLog)
{
@ -421,6 +422,28 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
this._setAttribute("rating", rating, log);
}
/**
* Setter for the orientation attribute.
*
* @name module:visual.Slider#setOri
* @public
* @param {number} ori - the orientation in degree with 0 as the vertical position, positive values rotate clockwise.
* @param {boolean} [log= false] - whether of not to log
*/
setOri (ori = 0, log = false)
{
const oriChanged = this._setAttribute("ori", ori, log);
if (oriChanged)
{
this._pixi.rotation = -this._ori * Math.PI / 180;
let i;
for (i = 0; i < this._pixiLabels.length; ++i)
{
this._pixiLabels[i].rotation = -(this._ori + this._labelOri) * Math.PI / 180;
}
}
}
/** Let `borderColor` alias `lineColor` to parallel PsychoPy */
set borderColor(color)
{
@ -1185,17 +1208,18 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
_setupLabels()
{
const labelTextStyle = this._getTextStyle();
this._pixiLabels = new Array(this._labels.length);
for (let l = 0; l < this._labels.length; ++l)
{
const labelText = new PIXI.Text(this._labels[l], labelTextStyle);
labelText.position.x = this._labelPositions_px[l][0];
labelText.position.y = this._labelPositions_px[l][1];
labelText.rotation = -(this._ori + this._labelOri) * Math.PI / 180;
labelText.anchor = this._labelAnchor;
labelText.alpha = 1;
this._pixiLabels[l] = new PIXI.Text(this._labels[l], labelTextStyle);
this._pixiLabels[l].position.x = this._labelPositions_px[l][0];
this._pixiLabels[l].position.y = this._labelPositions_px[l][1];
this._pixiLabels[l].rotation = -(this._ori + this._labelOri) * Math.PI / 180;
this._pixiLabels[l].anchor = this._labelAnchor;
this._pixiLabels[l].alpha = 1;
this._pixi.addChild(labelText);
this._pixi.addChild(this._pixiLabels[l]);
}
}