Resolves #170, thang can be directly placed by dragging onto the map

This commit is contained in:
Jayant Jain 2014-05-21 04:50:24 +05:30 committed by Nick Winter
parent 02f8458dfe
commit c05780de4c
2 changed files with 10 additions and 3 deletions

View file

@ -103,6 +103,7 @@ module.exports = Surface = class Surface extends CocoClass
@stage.removeAllChildren() @stage.removeAllChildren()
@stage.removeEventListener 'stagemousemove', @onMouseMove @stage.removeEventListener 'stagemousemove', @onMouseMove
@stage.removeEventListener 'stagemousedown', @onMouseDown @stage.removeEventListener 'stagemousedown', @onMouseDown
@stage.removeEventListener 'stagemouseup', @onMouseUp
@stage.removeAllEventListeners() @stage.removeAllEventListeners()
@stage.enableDOMEvents false @stage.enableDOMEvents false
@stage.enableMouseOver 0 @stage.enableMouseOver 0
@ -416,6 +417,7 @@ module.exports = Surface = class Surface extends CocoClass
@stage.enableMouseOver(10) @stage.enableMouseOver(10)
@stage.addEventListener 'stagemousemove', @onMouseMove @stage.addEventListener 'stagemousemove', @onMouseMove
@stage.addEventListener 'stagemousedown', @onMouseDown @stage.addEventListener 'stagemousedown', @onMouseDown
@stage.addEventListener 'stagemouseup', @onMouseUp
@canvas.on 'mousewheel', @onMouseWheel @canvas.on 'mousewheel', @onMouseWheel
@hookUpChooseControls() if @options.choosing @hookUpChooseControls() if @options.choosing
createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED
@ -539,6 +541,11 @@ module.exports = Surface = class Surface extends CocoClass
onBackground = not @stage.hitTest e.stageX, e.stageY onBackground = not @stage.hitTest e.stageX, e.stageY
Backbone.Mediator.publish 'surface:stage-mouse-down', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e Backbone.Mediator.publish 'surface:stage-mouse-down', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e
onMouseUp: (e) =>
return if @disabled
onBackground = not @stage.hitTest e.stageX, e.stageY
Backbone.Mediator.publish 'surface:stage-mouse-up', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e
onMouseWheel: (e) => onMouseWheel: (e) =>
# https://github.com/brandonaaron/jquery-mousewheel # https://github.com/brandonaaron/jquery-mousewheel
e.preventDefault() e.preventDefault()

View file

@ -43,7 +43,7 @@ module.exports = class ThangsTabView extends View
'sprite:dragged': 'onSpriteDragged' 'sprite:dragged': 'onSpriteDragged'
'sprite:mouse-up': 'onSpriteMouseUp' 'sprite:mouse-up': 'onSpriteMouseUp'
'sprite:double-clicked': 'onSpriteDoubleClicked' 'sprite:double-clicked': 'onSpriteDoubleClicked'
'surface:stage-mouse-down': 'onStageMouseDown' 'surface:stage-mouse-up': 'onStageMouseUp'
events: events:
'click #extant-thangs-filter button': 'onFilterExtantThangs' 'click #extant-thangs-filter button': 'onFilterExtantThangs'
@ -108,7 +108,7 @@ module.exports = class ThangsTabView extends View
afterRender: -> afterRender: ->
super() super()
return unless @supermodel.finished() return unless @supermodel.finished()
$('.tab-content').click @selectAddThang $('.tab-content').mousedown @selectAddThang
$('#thangs-list').bind 'mousewheel', @preventBodyScrollingInThangList $('#thangs-list').bind 'mousewheel', @preventBodyScrollingInThangList
@$el.find('#extant-thangs-filter button:first').button('toggle') @$el.find('#extant-thangs-filter button:first').button('toggle')
$(window).resize @onWindowResize $(window).resize @onWindowResize
@ -185,7 +185,7 @@ module.exports = class ThangsTabView extends View
if e.originalEvent.nativeEvent.button == 2 if e.originalEvent.nativeEvent.button == 2
@onSpriteContextMenu e @onSpriteContextMenu e
onStageMouseDown: (e) -> onStageMouseUp: (e) ->
if @addThangSprite if @addThangSprite
# If we click on the background, we need to add @addThangSprite, but not if onSpriteMouseDown will fire. # If we click on the background, we need to add @addThangSprite, but not if onSpriteMouseDown will fire.
@backgroundAddClickTimeout = _.defer => @onExtantThangSelected {} @backgroundAddClickTimeout = _.defer => @onExtantThangSelected {}