comic-bubbles
Version:
Animated comic bubbles - what else?
75 lines (62 loc) • 1.45 kB
JavaScript
export class Row {
constructor(parent) {
this.arrIdx = -1
this.canvas = document.createElement('canvas')
this.parent = parent
}
getPrefStr() {
return this.parent === undefined ? 'row' : this.parent.getPrefStr() + '.row'
}
wordArr = new Array()
addWord(word) {
word.parent = this
this.wordArr.push(word)
}
getX() {
return this.parent.getX()
}
getY() {
let y = this.parent.getY()
if (this.arrIdx > 0) {
for (let i = 0; i < this.arrIdx; i++) {
y += this.parent.row(this.arrIdx).getMaxLineSpacing()
}
}
return y
}
getWidth() {
let width = 0
for (let i = 0; i < this.wordArr.length; i++) {
let curWord = this.wordArr[i]
width += curWord.bounds.width
if (i > 0) {
let prevWord = this.wordArr[i - 1]
width += prevWord.spaceWidth
}
}
return width
}
getHeight() {
let height = 0
for (let i = 0; i < this.wordArr.length; i++) {
height = Math.max(height, this.wordArr[i].bounds.height)
}
return height
}
getMaxLineSpacing() {
let maxLineSpacing = 0
for (let i = 0; i < this.wordArr.length; i++) {
maxLineSpacing = Math.max(maxLineSpacing, this.wordArr[i].maxLineSpacing)
}
return maxLineSpacing
}
word(idx) {
return this.wordArr[idx]
}
getWordCount() {
return this.wordArr.length
}
ctx() {
return this.canvas.getContext('2d')
}
}