123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- function Label (x = 0, y = 0) {
- this.x = x
- this.y = y
- this._text=""
- this._fillStyle ="#ffffff"
- this._textAlign ="left"
- this._font ="Helvetica"
- this._fontSize="30px"
- this._baseLine ="middle"
- this._name=""
- this._globalAlpha = 1;
- this.visible = true
- }
- Label.prototype={
- set name(tex) {
- this._name = tex;
- },
- get name() {
- return this._name;
- },
- set text(tex) {
- this._text = tex;
- },
- get text() {
- return this._text;
- },
- set fillStyle(tex) {
- this._fillStyle = tex;
- },
- get fillStyle() {
- return this._fillStyle;
- },
- set textAlign(tex) {
- this._textAlign = tex;
- },
- get textAlign() {
- return this._textAlign;
- },
- set font(tex) {
- this._font = tex;
- },
- get font() {
- return this._font;
- },
- set fontSize(tex) {
- this._fontSize = tex;
- },
- get fontSize() {
- return this._fontSize;
- },
- set baseLine(tex) {
- this._baseLine = tex;
- },
- get baseLine() {
- return this._baseLine;
- },
- get globalAlpha() {
- return this._globalAlpha;
- },
- set globalAlpha(tex) {
- this._globalAlpha = tex;
- },
- }
- Label.prototype.position = function(x,y){
- this.x = x;
- this.y = y;
- }
- /**
- * 将文字绘制在canvas上
- */
- Label.prototype.drawToCanvas=function(ctx){
- if (!this.visible)
- return
- ctx.globalAlpha = this.globalAlpha;
- ctx.fillStyle = this.fillStyle;
- ctx.textAlign = this.textAlign;
- ctx.baseLine = this.baseLine;
- ctx.font = `${this.fontSize} ${this.font}`;
- ctx.fillText(this.text, this.x, this.y);
- }
- module.exports.Label = Label;
|