MCPcopy Create free account
hub / github.com/Barrior/JParticles / drawText

Method drawText

src/wave-loading.ts:168–188  ·  view source on GitHub ↗

* 绘制进度文本

()

Source from the content-addressed store, hash-verified

166 * 绘制进度文本
167 */
168 private drawText() {
169 const { ctx, canvasWidth, halfCH, progress } = this
170 const { font, textFormatter, textColor } = this.options
171
172 if (!isString(textFormatter) || !textFormatter) return
173
174 // 替换文本模板真实值
175 const text = textFormatter.replace(/%d/g, String(Math.floor(progress)))
176
177 ctx.save()
178 ctx.font = font
179
180 const textWidth = ctx.measureText(text).width
181 const x = (canvasWidth - textWidth) / 2
182
183 ctx.textBaseline = 'middle'
184 ctx.fillStyle = textColor
185 ctx.font = font
186 ctx.fillText(text, x, halfCH)
187 ctx.restore()
188 }
189
190 /**
191 * 计算进度值

Callers 1

mainDrawingMethod · 0.95

Calls 1

isStringFunction · 0.90

Tested by

no test coverage detected