<commit_before>game.square = me.Renderable.extend({	
	init:function (x, y) {
		// call the constructor
		this.parent(new me.Vector2d(x, y) , 100, 100);
		
		// selected flag
		this.selected = false;
		
		// to memorize where we grab the square
		this.grabOffset = new me.Vector2d(0,0);
		
		// white : unselected
		// red : selected
		this.color = "white";
		
		// store the id of the corresponding 
		// touch event (when selected)
		this.pointerId = null;
		
		// register required events
		me.event.subscribe("mousemove", this.onMoveEvent.bind(this));
		me.input.registerMouseEvent('mousedown', this, this.onStartEvent.bind(this));
		me.input.registerMouseEvent('mouseup', this, this.onEndEvent.bind(this));

	},

	/**
	 * return the corresponding "local" touch position
	 */	
	getTouchPosition : function (pointerId) {
		for(var i=0, l=me.input.changedTouches.length; i<l; i++) {
			if (me.input.changedTouches[i].id === pointerId) {
				return me.input.changedTouches[i];
			}
		}
		return null;
	},
	
	/**
	 * callback for move event
	 */
	onMoveEvent : function(e) {
		if (this.selected === true) {
			if (this.pointerId === e.pointerId) {
				// follow the mouse/finger
				this.pos.setV(this.getTouchPosition(e.pointerId));
				this.pos.sub(this.grabOffset);
				// don't propagate this event furthemore
				return false;
			}
		}
	},
	
	/**
	 * callback for event click
	 */
	onStartEvent : function(e) {
		if (this.selected === false) {
			this.pointerId = e.pointerId;
			this.selected = true;
			this.color = "red";
			this.grabOffset.setV(this.getTouchPosition(e.pointerId));
			this.grabOffset.sub(this.pos);
			// don't propagate this event furthemore
			return false;
		}
	},

	/**
	 * callback for event click
	 */
	onEndEvent : function(e) {
		if (this.selected === true) {
			this.pointerId = undefined;
			this.selected = false;
			this.color = "white";
			// don't propagate this event furthemore
			return false;
		}
	},
	
	/**
	 * update function
	 */
	update : function () {
		return true;
	},
	
	/**
	 * draw the square
	 */
	draw : function (context) {
      context.fillStyle = this.color;
      context.fillRect (this.pos.x,this.pos.y,this.width,this.height);
	},
	
	/**
	 * called when the object is destroyed
	 */
	destroy : function() {
		// unregister events
		me.input.releaseMouseEvent('mousedown', this);
		me.input.releaseMouseEvent('mouseup', this);
	}
});<commit_msg>Updated the multitouch example to reflect last changes<commit_after>game.square = me.Renderable.extend({	
	init:function (x, y) {
		// call the constructor
		this.parent(new me.Vector2d(x, y) , 100, 100);
		
		// selected flag
		this.selected = false;
		
		// to memorize where we grab the square
		this.grabOffset = new me.Vector2d(0,0);
		
		// white : unselected
		// red : selected
		this.color = "white";
		
		// store the id of the corresponding 
		// touch event (when selected)
		this.pointerId = null;
		
		// register required events
		this.moveCallback = this.onMoveEvent.bind(this);
		me.event.subscribe("mousemove", this.moveCallback);
		me.input.registerMouseEvent('mousedown', this, this.onStartEvent.bind(this));
		me.input.registerMouseEvent('mouseup', this, this.onEndEvent.bind(this));

	},

	/**
	 * callback for move event
	 */
	onMoveEvent : function(e) {
		if (this.selected === true) {
			if (this.pointerId === e.pointerId) {
				// follow the mouse/finger
				// e.localX/e.localY are in screen coordinates
				this.pos.set(e.localX, e.localY);
				this.pos.sub(this.grabOffset);
				// don't propagate this event furthemore
				return false;
			}
		}
	},
	
	/**
	 * callback for event click
	 */
	onStartEvent : function(e) {
		if (this.selected === false) {
			this.pointerId = e.pointerId;
			this.selected = true;
			this.color = "red";
			// e.localX/e.localY are in screen coordinates
			this.grabOffset.set(e.localX, e.localY);
			this.grabOffset.sub(this.pos);
			// don't propagate this event furthemore
			return false;
		}
	},

	/**
	 * callback for event click
	 */
	onEndEvent : function(e) {
		if (this.selected === true) {
			this.pointerId = undefined;
			this.selected = false;
			this.color = "white";
			// don't propagate this event furthemore
			return false;
		}
	},
	
	/**
	 * update function
	 */
	update : function () {
		return true;
	},
	
	/**
	 * draw the square
	 */
	draw : function (context) {
      context.fillStyle = this.color;
      context.fillRect (this.pos.x,this.pos.y,this.width,this.height);
	},
	
	/**
	 * called when the object is destroyed
	 */
	destroy : function() {
		// unregister events
		me.event.unsubscribe("mousemove", this.moveCallback);
		me.input.releaseMouseEvent('mousedown', this);
		me.input.releaseMouseEvent('mouseup', this);
	}
});
{'fraction_non_alphanumeric': 0.14681616247091178, 'fraction_numerical': 0.0044425639940765815, 'mean_word_length': 2.983150800336984, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6428619', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1560, 'n_words': 356}