summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/app.js6
-rw-r--r--js/ui/brush.js54
-rw-r--r--js/ui/canvas.js4
-rw-r--r--js/ui/controls.js3
-rw-r--r--js/ui/palette.js4
5 files changed, 65 insertions, 6 deletions
diff --git a/js/app.js b/js/app.js
index 715def9..919a39d 100644
--- a/js/app.js
+++ b/js/app.js
@@ -4,7 +4,7 @@ var drawing = true
var erasing = false
var focused
-var canvas, tools, palette, controls, brush, mode, current_tool
+var canvas, tools, palette, controls, brush, mode, current_tool, current_canvas
function init () {
build()
@@ -55,12 +55,14 @@ function bind () {
if (current_tool.name != "text") {
e.preventDefault()
brush.contract(1)
+ brush.modified = false
break
}
case 221: // ]
if (current_tool.name != "text") {
e.preventDefault()
brush.expand(1)
+ brush.modified = false
break
}
case 8:
@@ -120,7 +122,7 @@ function bind () {
if (focused && char) {
var y = focused.y, x = focused.x
focused.key(char, e.keyCode)
- canvas.focusLex(y + direction[0], focused.x + direction[1])
+ current_canvas.focusLex(y + direction[0], focused.x + direction[1])
}
})
diff --git a/js/ui/brush.js b/js/ui/brush.js
index 3055f54..a055a97 100644
--- a/js/ui/brush.js
+++ b/js/ui/brush.js
@@ -1,10 +1,12 @@
var brush = (function(){
-
+
var brush = new Matrix (5, 5, function(x,y){
var lex = new Lex (x,y)
lex.build()
return lex
})
+
+ brush.modified = false
brush.bind = function(){
brush.forEach(function(lex, x, y){
@@ -19,7 +21,55 @@ var brush = (function(){
})
}
-
+
+ brush.bind = function(){
+
+ var last_point = [0,0]
+ var dragging = false
+
+ brush.forEach(function(lex, x, y){
+
+ if (lex.bound) return
+ lex.bound = true
+
+ var point = [x,y]
+ lex.span.addEventListener('contextmenu', function(e){
+ e.preventDefault()
+ })
+ lex.span.addEventListener('mousedown', function(e){
+ e.preventDefault()
+ current_canvas = brush
+ brush.modified = true
+ dragging = true
+ erasing = (e.which == "3" || e.ctrlKey)
+ if (erasing) {
+ lex.clear()
+ }
+ else {
+ lex.fill(brush.fg, brush.bg)
+ }
+ lex.focus()
+ })
+ lex.span.addEventListener('mousemove', function(e){
+ e.preventDefault()
+ if (! dragging) {
+ return
+ }
+ erasing = (e.which == "3" || e.ctrlKey)
+ if (erasing) {
+ lex.clear()
+ }
+ else {
+ lex.fill(brush.fg, brush.bg)
+ }
+ lex.focus()
+ })
+ })
+ window.addEventListener("mouseup", function(){
+ dragging = false
+ })
+ }
+
brush.fg = 0
brush.bg = 1
diff --git a/js/ui/canvas.js b/js/ui/canvas.js
index 1ee6e1c..4b595a5 100644
--- a/js/ui/canvas.js
+++ b/js/ui/canvas.js
@@ -10,8 +10,11 @@ var canvas = (function(){
})
exports.bind = function(){
+
var last_point = [0,0]
+
exports.forEach(function(lex, x, y){
+
if (lex.bound) return
lex.bound = true
var point = [x,y]
@@ -21,6 +24,7 @@ var canvas = (function(){
lex.span.addEventListener('mousedown', function(e){
e.preventDefault()
dragging = true
+ current_canvas = canvas
if (drawing) {
erasing = (e.which == "3" || e.ctrlKey)
draw(lex, x, y, erasing)
diff --git a/js/ui/controls.js b/js/ui/controls.js
index a37ed16..dcd95b8 100644
--- a/js/ui/controls.js
+++ b/js/ui/controls.js
@@ -8,6 +8,7 @@ var controls = (function(){
brush.generate = controls.circle.generate
brush.generate()
drawing = true
+ brush.modified = false
}
controls.circle.generate = function(){
var fg = brush.fg, bg = brush.bg
@@ -28,7 +29,7 @@ var controls = (function(){
brush.generate = controls.square.generate
brush.generate()
drawing = true
- console.log('square')
+ brush.modified = false
}
controls.square.generate = function(){
var fg = brush.fg, bg = brush.bg
diff --git a/js/ui/palette.js b/js/ui/palette.js
index 2a648a8..69ccaa3 100644
--- a/js/ui/palette.js
+++ b/js/ui/palette.js
@@ -18,7 +18,9 @@ var palette = (function(){
erasing = e.which == "3"
brush.fg = lex.fg
brush.bg = lex.bg
- brush.generate()
+ if (! brush.modified) {
+ brush.generate()
+ }
})
})