diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-22 17:20:06 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-22 17:20:06 -0500 |
| commit | 197752cd55c34797a67be02e684ad276d0eefb99 (patch) | |
| tree | 22427357590296fa6ba2c88f5ce4b0d0190d3051 /js/ui/canvas.js | |
| parent | 61ea379940152da18052a02185eb204fc7a9683d (diff) | |
splitting up ui code
Diffstat (limited to 'js/ui/canvas.js')
| -rw-r--r-- | js/ui/canvas.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/ui/canvas.js b/js/ui/canvas.js new file mode 100644 index 0000000..7e85fcf --- /dev/null +++ b/js/ui/canvas.js @@ -0,0 +1,42 @@ +var canvas = (function(){ + + var cols = 80 + var rows = 24 + + var exports = new Matrix (cols, rows, function(x,y){ + var lex = new Lex (x,y) +// lex.build() + return lex + }) + + exports.bind = function(){ + exports.forEach(function(lex, x, y){ + if (lex.bound) return + lex.bound = true + + lex.span.addEventListener('contextmenu', function(e){ + e.preventDefault() + }) + lex.span.addEventListener('mousedown', function(e){ + e.preventDefault() + dragging = true + if (drawing) { + erasing = (e.which == "3" || e.ctrlKey) + draw(lex, x, y, erasing) + } + lex.focus() + }) + lex.span.addEventListener("mousemove", function(){ + if (! dragging) return + if (drawing) { + draw(lex, x, y, erasing) + } + lex.focus() + }) + + }) + } + + return exports + +})() |
