summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/app.js30
-rw-r--r--js/lex.js4
2 files changed, 19 insertions, 15 deletions
diff --git a/js/app.js b/js/app.js
index 1e975ea..9db7895 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1,7 +1,7 @@
var contentType = 'text/plain;charset=utf-8'
-var cols = 200
-var rows = 200
+var cols = 80
+var rows = 24
var dragging = false
var drawing = true
var erasing = false
@@ -84,7 +84,13 @@ function build () {
}
controls.text.generate = function(){
}
-
+
+ controls.clear = new Tool (clear_el)
+ controls.clear.use = function(){
+ canvas.clear()
+ }
+
+
controls.width = new Lex (width_el)
controls.height = new Lex (height_el)
controls.canvas_width = new Lex (canvas_width_el)
@@ -108,18 +114,14 @@ function bind () {
erasing = (e.which == "3" || e.ctrlKey)
draw(lex, x, y, erasing)
}
- else {
- lex.focus()
- }
+ lex.focus()
})
lex.span.addEventListener("mousemove", function(){
if (! dragging) return
if (drawing) {
draw(lex, x, y, erasing)
}
- else {
- lex.focus()
- }
+ lex.focus()
})
})
palette.forEach(function(lex, x, y){
@@ -149,7 +151,7 @@ function bind () {
})
});
- [controls.square, controls.circle, controls.text].forEach(function(tool){
+ [controls.square, controls.circle, controls.text, controls.clear].forEach(function(tool){
tool.span.addEventListener('mousedown', function(e){
tool.focus()
})
@@ -171,22 +173,20 @@ function bind () {
})
controls.canvas_width.key = int_key(function(n, keyCode){
+ controls.canvas_width.read()
if (controls.canvas_width.char.length == 1) {
n = parseInt(controls.canvas_width.char) * 10 + n
}
- controls.canvas_width.blur()
controls.canvas_width.char = ""+n
controls.canvas_width.build()
canvas.w = n
canvas.rebuild()
})
controls.canvas_height.key = int_key(function(n, keyCode){
- console.log(controls.canvas_height.char.length)
- console.log(controls.canvas_height.char,n)
+ controls.canvas_height.read()
if (controls.canvas_height.char.length == 1) {
n = parseInt(controls.canvas_height.char) * 10 + n
}
- controls.canvas_height.blur()
controls.canvas_height.char = ""+n
controls.canvas_height.build()
canvas.h = n
@@ -221,7 +221,7 @@ function bind () {
function int_key (f) {
return function (key, keyCode) {
var n = parseInt(key)
- n && f(n)
+ ! isNaN(n) && f(n)
}
}
diff --git a/js/lex.js b/js/lex.js
index f235672..086fc90 100644
--- a/js/lex.js
+++ b/js/lex.js
@@ -21,6 +21,10 @@ Lex.prototype.css = function(){
Lex.prototype.html = function(){
return this.char == " " ? " " : this.char || " "
}
+Lex.prototype.read = function(){
+ this.char = this.span.innerHTML
+ return this.char
+}
Lex.prototype.irc = function(){
var char = this.char == "%" ? '%%' : this.char || " "
if (this.bg == 1 && this.fg == 0) {