/**
 *
 * @param dis
 * @param zoomCenter 是否设定中心缩放，默认true，为了自行确定锚点的对象
 */
import DisplayObject = FYGE.DisplayObject;
import MouseEvent = FYGE.MouseEvent;
import Tween = FYGE.Tween;

export function addClickZoom(dis: DisplayObject, zoomCenter: boolean = true) {
	if (zoomCenter) {
		dis.anchorX = dis.width / 2;
		dis.anchorY = dis.height / 2;
	}
	dis.addEventListener("onMouseDown", _mouseEvent, dis)
		.addEventListener("onMouseUp", _mouseEvent, dis)
		.addEventListener("onMouseOut", _mouseEvent, dis);
	let s = dis;

	function _mouseEvent(e: MouseEvent) {
		if (e.type == MouseEvent.MOUSE_DOWN) {
			Tween.removeTweens(s);
			Tween.get(s).to({ scaleX: 0.9, scaleY: 0.9 }, 50);
		} else {
			Tween.removeTweens(s);
			Tween.get(s).to({ scaleX: 1, scaleY: 1 }, 50);
		}
	}
	return dis;
}
