Skip to content

Commit

Permalink
New overrides feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Marstall committed Jul 28, 2017
1 parent 66ecbfd commit 8734cff
Showing 1 changed file with 47 additions and 34 deletions.
81 changes: 47 additions & 34 deletions FocusEngine.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
fe.debug = true
###

overrides =
up: null
down: null
left: null
right: null

# all layers receive default empty overrides
Layer::overrides = overrides

exports.debug = false

# focus store
Expand All @@ -89,6 +98,7 @@ exports.focusStyle =
shadowY: 0
shadowSpread: 0

# unfocus style
exports.unfocusStyle =
shadowBlur: 20
shadowColor: "rgba(0,0,0,0)"
Expand Down Expand Up @@ -181,40 +191,43 @@ exports.changeFocus = Utils.throttle 0.1, (direction) ->
# if we've lost all focus, reset
if exports.focus == null or exports.focus == undefined
exports.placeFocus(exports.initialFocus)
focusMidX = exports.focus.screenFrame.x + exports.focus.screenFrame.width/2
focusMidY = exports.focus.screenFrame.y + exports.focus.screenFrame.height/2
if direction == "up"
for layer in exports.focusable
layerMidY = layer.screenFrame.y + layer.screenFrame.height/2
if layerMidY < focusMidY and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "down"
for layer in exports.focusable
layerMidY = layer.screenFrame.y + layer.screenFrame.height/2
if layerMidY > focusMidY and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "left"
for layer in exports.focusable
layerMidX = layer.screenFrame.x + layer.screenFrame.width/2
if layerMidX < focusMidX and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "right"
for layer in exports.focusable
layerMidX = layer.screenFrame.x + layer.screenFrame.width/2
if layerMidX > focusMidX and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "select"
exports.focus.emit "selected"
if tempArray.length == 0
return
targetLayer = tempArray[0]
shortestDistance = measureDistance(targetLayer, direction)
for layer in tempArray
distance = measureDistance(layer, direction)
if distance < shortestDistance
targetLayer = layer
shortestDistance = distance
exports.placeFocus(targetLayer)
if exports.focus.overrides?[direction] != undefined and exports.focus.overrides?[direction] != null # override
exports.placeFocus(exports.focus.overrides[direction])
else
focusMidX = exports.focus.screenFrame.x + exports.focus.screenFrame.width/2
focusMidY = exports.focus.screenFrame.y + exports.focus.screenFrame.height/2
if direction == "up"
for layer in exports.focusable
layerMidY = layer.screenFrame.y + layer.screenFrame.height/2
if layerMidY < focusMidY and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "down"
for layer in exports.focusable
layerMidY = layer.screenFrame.y + layer.screenFrame.height/2
if layerMidY > focusMidY and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "left"
for layer in exports.focusable
layerMidX = layer.screenFrame.x + layer.screenFrame.width/2
if layerMidX < focusMidX and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "right"
for layer in exports.focusable
layerMidX = layer.screenFrame.x + layer.screenFrame.width/2
if layerMidX > focusMidX and checkVisible(layer) == true
tempArray.push(layer)
else if direction == "select"
exports.focus.emit "selected"
if tempArray.length == 0
return
targetLayer = tempArray[0]
shortestDistance = measureDistance(targetLayer, direction)
for layer in tempArray
distance = measureDistance(layer, direction)
if distance < shortestDistance
targetLayer = layer
shortestDistance = distance
exports.placeFocus(targetLayer)

measureDistance = (target, direction) ->
focusTopCenter =
Expand Down

0 comments on commit 8734cff

Please sign in to comment.