Added text that zooms vis font size changes,

This commit is contained in:
2019-03-28 09:49:21 +01:00
parent df0c2fea3a
commit 909c67cfba
3 changed files with 85 additions and 4 deletions
+42 -1
View File
@@ -130,6 +130,47 @@ export class Hypenate {
}
}
class TextLabel extends PIXI.Text {
/**
*Creates an instance of TextLabel.
* @param {string} text - The string that you would like the text to display
* @param {object PIXI.TextStyle optional} style - The style parameters
* @param {canvas}
* @memberof TextLabel
*/
constructor(text, style=null, canvas=null, { minZoom = 0.1, maxZoom = 10} = {}) {
super(text, style, canvas )
this.normFontSize = this.style.fontSize
this.minZoom = minZoom
this.maxZoom = maxZoom
}
zoom(factor) {
let oldValue = parseFloat(this.style.fontSize) / this.normFontSize
let value = oldValue * factor
this.setZoom(value)
}
setZoom(value) {
let oldValue = parseFloat(this.style.fontSize) / this.normFontSize
if (value > this.maxZoom) {
value = this.maxZoom
}
if (value < this.minZoom) {
value = this.minZoom
}
if (value != oldValue) {
this.style.fontSize = Math.max(value * this.normFontSize, 1)
}
}
setZoomAndScale(scale) {
this.scale.set(1 / scale)
this.setZoom(scale)
}
}
/**
* A specialization of the PIXI.Graphics class that allows to
* resuse and place labels across different layout variants
@@ -151,7 +192,7 @@ export class LabeledGraphics extends PIXI.Graphics {
}
_createText(label, fontInfo) {
return new PIXI.Text(label, fontInfo)
return new TextLabel(label, fontInfo)
}