mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 18:50:54 +00:00
Proper rendering for progress bar.
This commit is contained in:
parent
aabd9fd43d
commit
2688e8e3e0
@ -10,7 +10,7 @@ export class Progress extends VisualStim
|
|||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
win,
|
win,
|
||||||
units,
|
units = "pix",
|
||||||
ori,
|
ori,
|
||||||
opacity,
|
opacity,
|
||||||
depth,
|
depth,
|
||||||
@ -61,8 +61,7 @@ export class Progress extends VisualStim
|
|||||||
if (this._pixi !== undefined)
|
if (this._pixi !== undefined)
|
||||||
{
|
{
|
||||||
this._pixi.clear();
|
this._pixi.clear();
|
||||||
const size_px = util.to_px(this.size, this.units, this.win);
|
const size_px = util.to_px(this._size, this._units, this._win);
|
||||||
const pos_px = util.to_px(this.pos, this.units, this.win);
|
|
||||||
const progressWidth = size_px[0] * this._progress;
|
const progressWidth = size_px[0] * this._progress;
|
||||||
if (this._fillTexture)
|
if (this._fillTexture)
|
||||||
{
|
{
|
||||||
@ -80,11 +79,12 @@ export class Progress extends VisualStim
|
|||||||
{
|
{
|
||||||
this._pixi.beginFill(new Color(this._fillColor).int, this._opacity);
|
this._pixi.beginFill(new Color(this._fillColor).int, this._opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._type === PROGRESS_TYPES.BAR)
|
if (this._type === PROGRESS_TYPES.BAR)
|
||||||
{
|
{
|
||||||
this._pixi.drawRect(pos_px[0], pos_px[1], progressWidth, size_px[1]);
|
this._pixi.drawRect(0, 0, progressWidth, size_px[1]);
|
||||||
}
|
}
|
||||||
// TODO: check out beginTextureFill(). Perhaps it will allow to use images as filling for progress.
|
|
||||||
this._pixi.endFill();
|
this._pixi.endFill();
|
||||||
|
|
||||||
// TODO: is there a better way to ensure anchor works?
|
// TODO: is there a better way to ensure anchor works?
|
||||||
@ -92,6 +92,26 @@ export class Progress extends VisualStim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate the bounding box.
|
||||||
|
*
|
||||||
|
* @override
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
_estimateBoundingBox()
|
||||||
|
{
|
||||||
|
let boundingBox = new PIXI.Rectangle(0, 0, 0, 0);
|
||||||
|
const anchorNum = this._anchorTextToNum(this._anchor);
|
||||||
|
const pos_px = util.to_px(this._pos, this._units, this._win);
|
||||||
|
const size_px = util.to_px(this._size, this._units, this._win);
|
||||||
|
boundingBox.x = pos_px[ 0 ] - anchorNum[ 0 ] * size_px[ 0 ];
|
||||||
|
boundingBox.y = pos_px[ 1 ] - anchorNum[ 1 ] * size_px[ 1 ];
|
||||||
|
boundingBox.width = size_px[ 0 ];
|
||||||
|
boundingBox.height = size_px[ 1 ];
|
||||||
|
|
||||||
|
this._boundingBox = boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the stimulus, if necessary.
|
* Update the stimulus, if necessary.
|
||||||
*
|
*
|
||||||
@ -128,9 +148,10 @@ export class Progress extends VisualStim
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set polygon position and rotation:
|
// set polygon position and rotation:
|
||||||
// TODO: what's the difference bw to_px and to_pixiPoint?
|
this._pixi.position = to_pixiPoint(this._pos, this._units, this._win);
|
||||||
this._pixi.position = to_pixiPoint(this.pos, this.units, this.win);
|
|
||||||
this._pixi.rotation = -this.ori * Math.PI / 180.0;
|
this._pixi.rotation = -this.ori * Math.PI / 180.0;
|
||||||
|
|
||||||
|
this._estimateBoundingBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user