Added basic mobile touch support. Needs a library.

This commit is contained in:
Lewis Hemens 2014-01-11 21:02:14 +00:00
parent 34a91e97c5
commit 5516665db1
2 changed files with 25 additions and 0 deletions

View File

@ -26,6 +26,7 @@ ascii.Controller = function(view, state) {
// TODO: Setup different bindings for tablet/mobile. // TODO: Setup different bindings for tablet/mobile.
this.installDesktopBindings(); this.installDesktopBindings();
this.installTouchBindings();
}; };
ascii.Controller.prototype.handlePress = function(x, y) { ascii.Controller.prototype.handlePress = function(x, y) {
@ -92,6 +93,7 @@ ascii.Controller.prototype.handleZoom = function(delta) {
ascii.Controller.prototype.installDesktopBindings = function() { ascii.Controller.prototype.installDesktopBindings = function() {
var controller = this; var controller = this;
$(this.view.canvas).bind('mousewheel', function(e) { $(this.view.canvas).bind('mousewheel', function(e) {
controller.handleZoom(e.originalEvent.wheelDelta); controller.handleZoom(e.originalEvent.wheelDelta);
}); });
$(this.view.canvas).mousedown(function(e) { $(this.view.canvas).mousedown(function(e) {
@ -105,3 +107,25 @@ ascii.Controller.prototype.installDesktopBindings = function() {
}); });
$(window).resize(function(e) { controller.view.resizeCanvas() }); $(window).resize(function(e) { controller.view.resizeCanvas() });
}; };
ascii.Controller.prototype.installTouchBindings = function() {
var controller = this;
$(this.view.canvas).bind("touchstart", function(e) {
e.stopPropagation();
controller.handlePress(
e.originalEvent.touches[0].clientX,
e.originalEvent.touches[0].clientY);
});
$(this.view.canvas).bind("touchend", function(e) {
e.stopPropagation();
controller.handleRelease(
e.originalEvent.touches[0].clientX,
e.originalEvent.touches[0].clientY);
});
$(this.view.canvas).bind("touchmove", function(e) {
e.stopPropagation();
controller.handleMove(
e.originalEvent.touches[0].clientX,
e.originalEvent.touches[0].clientY);
});
};

View File

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<title>asciiflow-2.0</title> <title>asciiflow-2.0</title>
</head> </head>
<body> <body>