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

added proper orientation setter that also updates the rotation of labels;

This commit is contained in:
lgtst 2022-05-25 23:19:09 +03:00
parent 8a3c6c0a28
commit 43e516d7a6

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: // the internal response clock, used to time the marker change events:
this._responseClock = new Clock(); this._responseClock = new Clock();
this._pixiLabels = [];
if (this._autoLog) if (this._autoLog)
{ {
@ -421,6 +422,28 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
this._setAttribute("rating", rating, log); 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 */ /** Let `borderColor` alias `lineColor` to parallel PsychoPy */
set borderColor(color) set borderColor(color)
{ {
@ -1185,6 +1208,7 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
_setupLabels() _setupLabels()
{ {
const labelTextStyle = this._getTextStyle(); const labelTextStyle = this._getTextStyle();
this._pixiLabels = new Array(this._labels.length);
for (let l = 0; l < this._labels.length; ++l) for (let l = 0; l < this._labels.length; ++l)
{ {
@ -1194,6 +1218,7 @@ export class Slider extends util.mix(VisualStim).with(ColorMixin, WindowMixin)
labelText.rotation = -(this._ori + this._labelOri) * Math.PI / 180; labelText.rotation = -(this._ori + this._labelOri) * Math.PI / 180;
labelText.anchor = this._labelAnchor; labelText.anchor = this._labelAnchor;
labelText.alpha = 1; labelText.alpha = 1;
this._pixiLabels[l] = labelText;
this._pixi.addChild(labelText); this._pixi.addChild(labelText);
} }