Add freeform input tool for mobile, now at 100% mobile support parity

This commit is contained in:
Lewis Hemens 2014-03-23 12:25:03 +00:00
parent 1ebf356aae
commit acc2584779
4 changed files with 31 additions and 14 deletions

View File

@ -240,6 +240,8 @@ textarea {
<button id="text-tool-close">Close</button> <button id="text-tool-close">Close</button>
</div> </div>
<textarea id="freeform-tool-input"></textarea>
<canvas id="ascii-canvas"></canvas> <canvas id="ascii-canvas"></canvas>
<script src="https://apis.google.com/js/api.js"></script> <script src="https://apis.google.com/js/api.js"></script>

View File

@ -130,11 +130,11 @@ function B(a, b) {
d = d || "+"; d = d || "+";
var g = Math.min(b.x, c.x), k = Math.min(b.y, c.y), h = Math.max(b.x, c.x), s = Math.max(b.y, c.y), t = e ? c.x : b.x; var g = Math.min(b.x, c.x), k = Math.min(b.y, c.y), h = Math.max(b.x, c.x), s = Math.max(b.y, c.y), t = e ? c.x : b.x;
for (e = e ? b.y : c.y;g++ < h;) { for (e = e ? b.y : c.y;g++ < h;) {
var O = new l(g, e), E = a.getContext(new l(g, e)); var P = new l(g, e), E = a.getContext(new l(g, e));
" " == d && 2 == E.m + E.j || H(a, O, d); " " == d && 2 == E.m + E.j || H(a, P, d);
} }
for (;k++ < s;) { for (;k++ < s;) {
O = new l(t, k), E = a.getContext(new l(t, k)), " " == d && 2 == E.left + E.right || H(a, O, d); P = new l(t, k), E = a.getContext(new l(t, k)), " " == d && 2 == E.left + E.right || H(a, P, d);
} }
I(a, b, d); I(a, b, d);
I(a, c, d); I(a, c, d);
@ -184,6 +184,11 @@ M.prototype.e = function() {
function N(a, b) { function N(a, b) {
this.state = a; this.state = a;
this.value = b; this.value = b;
f && ($("#freeform-tool-input").val(""), $("#freeform-tool-input").hide(0, function() {
$("#freeform-tool-input").show(0, function() {
$("#freeform-tool-input").focus();
});
}));
} }
N.prototype.start = function(a) { N.prototype.start = function(a) {
I(this.state, a, this.value); I(this.state, a, this.value);
@ -198,32 +203,33 @@ N.prototype.l = function() {
return "crosshair"; return "crosshair";
}; };
N.prototype.e = function(a) { N.prototype.e = function(a) {
f && (this.value = $("#freeform-tool-input").val().substr(0, 1), $("#freeform-tool-input").blur(), $("#freeform-tool-input").hide(0));
1 == a.length && (this.value = a); 1 == a.length && (this.value = a);
}; };
function P(a) { function O(a) {
this.state = a; this.state = a;
this.a = null; this.a = null;
} }
P.prototype.start = function(a) { O.prototype.start = function(a) {
L(this.state); L(this.state);
$("#text-tool-input").val(""); $("#text-tool-input").val("");
this.a = a; this.a = a;
a = w(D(this.state, this.a)); a = w(D(this.state, this.a));
I(this.state, this.a, null == a ? "\u2009" : a); I(this.state, this.a, null == a ? "\u2009" : a);
}; };
P.prototype.move = function() { O.prototype.move = function() {
}; };
P.prototype.end = function() { O.prototype.end = function() {
null != this.a && (this.g = this.a, this.a = null, $("#text-tool-widget").hide(0, function() { null != this.a && (this.g = this.a, this.a = null, $("#text-tool-widget").hide(0, function() {
$("#text-tool-widget").show(0, function() { $("#text-tool-widget").show(0, function() {
$("#text-tool-input").focus(); $("#text-tool-input").focus();
}); });
})); }));
}; };
P.prototype.l = function() { O.prototype.l = function() {
return "pointer"; return "pointer";
}; };
P.prototype.e = function() { O.prototype.e = function() {
var a = $("#text-tool-input").val(); var a = $("#text-tool-input").val();
K(this.state); K(this.state);
for (var b = 0, c = 0, e = 0;e < a.length;e++) { for (var b = 0, c = 0, e = 0;e < a.length;e++) {
@ -471,7 +477,7 @@ W.prototype.n = function() {
"freeform-button" == a && (this.c = new N(this.state, "+")); "freeform-button" == a && (this.c = new N(this.state, "+"));
"erase-button" == a && (this.c = new Q(this.state)); "erase-button" == a && (this.c = new Q(this.state));
"move-button" == a && (this.c = new R(this.state)); "move-button" == a && (this.c = new R(this.state));
"text-button" == a && (this.c = new P(this.state)); "text-button" == a && (this.c = new O(this.state));
L(this.state); L(this.state);
this.view.canvas.focus(); this.view.canvas.focus();
}.bind(this)); }.bind(this));
@ -529,10 +535,10 @@ W.prototype.n = function() {
39 == a.keyCode && (c = "<right>"); 39 == a.keyCode && (c = "<right>");
null != c && this.c.e(c); null != c && this.c.e(c);
}.bind(this)); }.bind(this));
$("#text-tool-input").keyup(function() { $("#text-tool-input, #freeform-tool-input").keyup(function() {
this.c.e(""); this.c.e("");
}.bind(this)); }.bind(this));
$("#text-tool-input").change(function() { $("#text-tool-input, #freeform-tool-input").change(function() {
this.c.e(""); this.c.e("");
}.bind(this)); }.bind(this));
$("#text-tool-close").click(function() { $("#text-tool-close").click(function() {

View File

@ -140,10 +140,10 @@ ascii.Controller.prototype.installBindings = function() {
}.bind(this)); }.bind(this));
// Bit of a hack, just triggers the text tool to get a new value. // Bit of a hack, just triggers the text tool to get a new value.
$('#text-tool-input').keyup(function(){ $('#text-tool-input, #freeform-tool-input').keyup(function(){
this.drawFunction.handleKey(''); this.drawFunction.handleKey('');
}.bind(this)); }.bind(this));
$('#text-tool-input').change(function(){ $('#text-tool-input, #freeform-tool-input').change(function(){
this.drawFunction.handleKey(''); this.drawFunction.handleKey('');
}.bind(this)); }.bind(this));
$('#text-tool-close').click(function(){ $('#text-tool-close').click(function(){

View File

@ -150,6 +150,10 @@ ascii.DrawLine.prototype.handleKey = function(value) {};
ascii.DrawFreeform = function(state, value) { ascii.DrawFreeform = function(state, value) {
this.state = state; this.state = state;
this.value = value; this.value = value;
if (TOUCH_ENABLED) {
$('#freeform-tool-input').val('');
$('#freeform-tool-input').hide(0, function() {$('#freeform-tool-input').show(0, function() {$('#freeform-tool-input').focus();});});
}
}; };
/** @inheritDoc */ /** @inheritDoc */
@ -174,6 +178,11 @@ ascii.DrawFreeform.prototype.getCursor = function(position) {
/** @inheritDoc */ /** @inheritDoc */
ascii.DrawFreeform.prototype.handleKey = function(value) { ascii.DrawFreeform.prototype.handleKey = function(value) {
if (TOUCH_ENABLED) {
this.value = $('#freeform-tool-input').val().substr(0, 1);
$('#freeform-tool-input').blur();
$('#freeform-tool-input').hide(0);
}
if (value.length == 1) { if (value.length == 1) {
// The value is not a special character, so lets use it. // The value is not a special character, so lets use it.
this.value = value; this.value = value;