pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
75 lines (71 loc) • 1.99 kB
JavaScript
;
var Matrix = require('../../../../maths/matrix/Matrix.js');
var uid = require('../../../../utils/data/uid.js');
;
const repetitionMap = {
repeat: {
addressModeU: "repeat",
addressModeV: "repeat"
},
"repeat-x": {
addressModeU: "repeat",
addressModeV: "clamp-to-edge"
},
"repeat-y": {
addressModeU: "clamp-to-edge",
addressModeV: "repeat"
},
"no-repeat": {
addressModeU: "clamp-to-edge",
addressModeV: "clamp-to-edge"
}
};
class FillPattern {
constructor(texture, repetition) {
/**
* unique id for this fill pattern
* @internal
*/
this.uid = uid.uid("fillPattern");
/** The transform matrix applied to the pattern */
this.transform = new Matrix.Matrix();
this._styleKey = null;
this.texture = texture;
this.transform.scale(
1 / texture.frame.width,
1 / texture.frame.height
);
if (repetition) {
texture.source.style.addressModeU = repetitionMap[repetition].addressModeU;
texture.source.style.addressModeV = repetitionMap[repetition].addressModeV;
}
}
/**
* Sets the transform for the pattern
* @param transform - The transform matrix to apply to the pattern.
* If not provided, the pattern will use the default transform.
*/
setTransform(transform) {
const texture = this.texture;
this.transform.copyFrom(transform);
this.transform.invert();
this.transform.scale(
1 / texture.frame.width,
1 / texture.frame.height
);
this._styleKey = null;
}
/**
* Gets a unique key representing the current state of the pattern.
* Used internally for caching.
* @returns Unique string key
*/
get styleKey() {
if (this._styleKey)
return this._styleKey;
this._styleKey = `fill-pattern-${this.uid}-${this.texture.uid}-${this.transform.toArray().join("-")}`;
return this._styleKey;
}
}
exports.FillPattern = FillPattern;
//# sourceMappingURL=FillPattern.js.map