2018-09-30 23:30:38 +00:00
|
|
|
# intermediate config
|
|
|
|
bcConf = Crafty.clone CONF.bigcard
|
|
|
|
|
|
|
|
################
|
|
|
|
# BigCard
|
|
|
|
################
|
|
|
|
Crafty.c 'BigCard',
|
|
|
|
# Mouse interactivity, Tween (animation smooth)
|
|
|
|
required: '2D, Canvas, Mouse, MouseWheel, Draggable, Tween'
|
|
|
|
|
|
|
|
# always in focus layer
|
|
|
|
init: ->
|
|
|
|
@z = CONF.layer.focus
|
|
|
|
return
|
|
|
|
|
|
|
|
events:
|
|
|
|
# copy attributes of target card
|
|
|
|
Copy: (target) ->
|
|
|
|
@target = target
|
|
|
|
@attr {
|
|
|
|
x: @target._x
|
|
|
|
y: @target._y
|
|
|
|
w: @target._w
|
|
|
|
h: @target._h
|
|
|
|
alpha: 0.5
|
|
|
|
}
|
2018-10-01 16:33:01 +00:00
|
|
|
@origin 'center'
|
2018-09-30 23:30:38 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# transition into zoom version
|
|
|
|
Enlarge: ->
|
2018-10-01 16:33:01 +00:00
|
|
|
# set new origin on finished animation
|
|
|
|
@one 'TweenEnd', ->
|
|
|
|
@origin 'center'
|
|
|
|
return
|
|
|
|
|
|
|
|
# start animation
|
2018-09-30 23:30:38 +00:00
|
|
|
@tween {
|
|
|
|
x: bcConf.x
|
|
|
|
y: bcConf.y
|
|
|
|
w: bcConf.w
|
|
|
|
h: bcConf.h
|
|
|
|
alpha: 1
|
|
|
|
}, CONF.anim.time, CONF.anim.func
|
|
|
|
return
|
|
|
|
|
|
|
|
# fade out and destroy
|
|
|
|
Fade: ->
|
|
|
|
# remove this on finished animation
|
|
|
|
@one 'TweenEnd', ->
|
|
|
|
@destroy()
|
|
|
|
return
|
|
|
|
|
2018-10-01 16:33:01 +00:00
|
|
|
# transition back to target card
|
2018-09-30 23:30:38 +00:00
|
|
|
@tween {
|
|
|
|
x: @target._x
|
|
|
|
y: @target._y
|
|
|
|
w: @target._w
|
|
|
|
h: @target._h
|
|
|
|
alpha: 0.5
|
|
|
|
}, CONF.anim.time, CONF.anim.func
|
|
|
|
return
|
|
|
|
|
|
|
|
# fade on right click, reset on middle click
|
|
|
|
MouseUp: (e) ->
|
|
|
|
switch e.mouseButton
|
|
|
|
when Crafty.mouseButtons.RIGHT
|
|
|
|
@trigger 'Fade'
|
|
|
|
when Crafty.mouseButtons.MIDDLE
|
2018-10-01 16:33:01 +00:00
|
|
|
# reset intermediate config, then reset zoom
|
2018-09-30 23:30:38 +00:00
|
|
|
bcConf = Crafty.clone CONF.bigcard
|
|
|
|
@trigger 'Enlarge'
|
|
|
|
return
|
|
|
|
|
|
|
|
# zoom in and out
|
|
|
|
MouseWheelScroll: (e) ->
|
|
|
|
if e.target == @
|
2018-10-01 16:33:01 +00:00
|
|
|
# save origin
|
|
|
|
origin =
|
|
|
|
x: @ox
|
|
|
|
y: @oy
|
|
|
|
|
2018-09-30 23:30:38 +00:00
|
|
|
# new attributes
|
|
|
|
@attr {
|
|
|
|
w: @_w * (1 + e.direction * 0.1)
|
|
|
|
h: @_h * (1 + e.direction * 0.1)
|
|
|
|
}
|
2018-10-01 16:33:01 +00:00
|
|
|
@origin 'center'
|
|
|
|
|
|
|
|
# restore origin
|
|
|
|
@attr {
|
|
|
|
ox: origin.x
|
|
|
|
oy: origin.y
|
|
|
|
}
|
|
|
|
|
2018-09-30 23:30:38 +00:00
|
|
|
# update intermediate config
|
2018-10-01 16:33:01 +00:00
|
|
|
bcConf.x = @_x
|
|
|
|
bcConf.y = @_y
|
2018-09-30 23:30:38 +00:00
|
|
|
bcConf.w = @_w
|
|
|
|
bcConf.h = @_h
|
|
|
|
return
|
|
|
|
|
|
|
|
StopDrag: ->
|
|
|
|
# update intermediate config
|
|
|
|
bcConf.x = @_x
|
|
|
|
bcConf.y = @_y
|
|
|
|
return
|