From 197752cd55c34797a67be02e684ad276d0eefb99 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Nov 2014 17:20:06 -0500 Subject: splitting up ui code --- js/ui/canvas.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 js/ui/canvas.js (limited to 'js/ui/canvas.js') 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 + +})() -- cgit v1.2.3-70-g09d2