summaryrefslogtreecommitdiff
path: root/js/ui/brush.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-22 21:57:25 -0500
committerJules Laplace <jules@okfoc.us>2014-11-22 21:57:25 -0500
commit323e8804ee13f70c35b2a58179cd1a43eea56bcf (patch)
treeb1c6aa6fd50f54d5c7c4976dc5f4e7a6560df254 /js/ui/brush.js
parentfbbbe8cc0457c2f3f77cfc8d9b8070a593938694 (diff)
editable brush
Diffstat (limited to 'js/ui/brush.js')
-rw-r--r--js/ui/brush.js54
1 files changed, 52 insertions, 2 deletions
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