added text shape
This commit is contained in:
parent
c451375ba3
commit
bac8f3dc0b
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
class shape {
|
class shape {
|
||||||
constructor(type,coordinates,dimentions,rotation,fColor,bColor,bStyle,extraObject) {
|
constructor(type,coordinates,dimentions,rotation,fColor,bColor,bStyle,extraObject) {
|
||||||
this.type = "string" == typeof type ? (["rect","elipse","image"].includes(type) ? type : "rect") : "rect";
|
this.type = "string" == typeof type ? (["rect","elipse","image","text"].includes(type) ? type : "rect") : "rect";
|
||||||
this.coordinates = coordinates instanceof vector ? coordinates : new vector([0,0]);
|
this.coordinates = coordinates instanceof vector ? coordinates : new vector([0,0]);
|
||||||
this.dimentions = dimentions instanceof vector ? dimentions : new vector([1,1]);
|
this.dimentions = dimentions instanceof vector ? dimentions : new vector([1,1]);
|
||||||
this.rotation = rotation instanceof vector ? rotation : new vector([1,0]);
|
this.rotation = rotation instanceof vector ? rotation : new vector([1,0]);
|
||||||
@ -30,6 +30,11 @@ class shape {
|
|||||||
]),3,3);
|
]),3,3);
|
||||||
this.image = createImageBitmap(this.imageData);
|
this.image = createImageBitmap(this.imageData);
|
||||||
}
|
}
|
||||||
|
if ("text" == this.type) {
|
||||||
|
this.text =
|
||||||
|
"string" == typeof this.extraObject.text ?
|
||||||
|
this.extraObject.text : "No Text";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +70,13 @@ class shape {
|
|||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
ctx.drawImage(image,origin.d[0],origin.d[0],this.dimentions.d[0],this.dimentions.d[1]);
|
ctx.drawImage(image,origin.d[0],origin.d[0],this.dimentions.d[0],this.dimentions.d[1]);
|
||||||
});
|
});
|
||||||
|
} else if ("text" == this.type) {
|
||||||
|
var oldFont = ctx.font+"";
|
||||||
|
if (this.extraObject.font) {
|
||||||
|
ctx.font = this.extraObject.font+"";
|
||||||
|
}
|
||||||
|
ctx.fillText(this.text, origin.d[0], origin.d[1], this.dimentions.d[0]);
|
||||||
|
ctx.font = oldFont+"";
|
||||||
}
|
}
|
||||||
// restore context defaults
|
// restore context defaults
|
||||||
ctx.translate(origin.d[0],origin.d[1]);
|
ctx.translate(origin.d[0],origin.d[1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user