Skip to content

Commit

Permalink
support static image layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinir committed May 31, 2020
1 parent f370418 commit 03df29a
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions js/module/GamepadRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,33 @@ class GamepadRenderer {

const altMessage = `a layer of canvas to display inputs of gamepad ${slot}`
for (let l = 0; l < config.layer.length; l++) {
const layer = GamepadRenderer.newCanvasLayer(
config.layer[l].width,
config.layer[l].height,
config.layer[l].x,
config.layer[l].y
)
layer.innerHTML = altMessage
const layerData = config.layer[l]

const isStatic =
layerData.hasOwnProperty('background') &&
typeof layerData.background === 'number'

let layer
if (isStatic) {
layer = document.createElement('div')
layer.style.backgroundImage = 'url(' + skinSlot.src[layerData.background].src + ')'
layer.style.width = layerData.width + 'px'
layer.style.height = layerData.height + 'px'
layer.style.left = layerData.x + 'px'
layer.style.top = layerData.y + 'px'
skinSlot.ctx.push(null)
} else {
layer = GamepadRenderer.newCanvasLayer(
layerData.width,
layerData.height,
layerData.x,
layerData.y
)
layer.innerHTML = altMessage
skinSlot.ctx.push(layer.getContext('2d'))
}

skinSlot.layer.push(layer)
skinSlot.ctx.push(layer.getContext('2d'))
canvas.appendChild(layer)
}

Expand Down

0 comments on commit 03df29a

Please sign in to comment.