2018-10-24 11:14:46 -04:00
|
|
|
var brush = (function(){
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
var brush = new Matrix (5, 5, function(x,y){
|
|
|
|
var lex = new Lex (x,y)
|
|
|
|
lex.build()
|
|
|
|
return lex
|
|
|
|
})
|
|
|
|
|
|
|
|
brush.modified = false
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
brush.mask = blit.circle
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
brush.generate = function(){
|
|
|
|
brush.fill(brush)
|
|
|
|
brush.mask(brush)
|
|
|
|
}
|
|
|
|
|
|
|
|
brush.bind = function(){
|
|
|
|
|
|
|
|
var last_point = [0,0]
|
|
|
|
var dragging = false
|
|
|
|
var erasing = false
|
|
|
|
|
|
|
|
brush.forEach(function(lex, x, y){
|
|
|
|
|
|
|
|
if (lex.bound) return
|
|
|
|
lex.bound = true
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
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 {
|
|
|
|
fillColor = brush.bg
|
|
|
|
lex.assign(brush)
|
|
|
|
}
|
|
|
|
brush.focus(x, y)
|
|
|
|
})
|
|
|
|
lex.span.addEventListener('mousemove', function(e){
|
|
|
|
e.preventDefault()
|
|
|
|
if (! dragging) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
erasing = (e.which == "3" || e.ctrlKey)
|
|
|
|
if (erasing) {
|
|
|
|
lex.clear()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lex.assign(brush)
|
|
|
|
}
|
|
|
|
brush.focus(x, y)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
window.addEventListener('mouseup', function(e){
|
|
|
|
dragging = erasing = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
brush.resize = function(w, h){
|
|
|
|
w = this.w = clamp(w, this.min, this.max)
|
|
|
|
h = this.h = clamp(h, this.min, this.max)
|
|
|
|
brush.rebuild()
|
|
|
|
controls.brush_w.char = "" + w
|
|
|
|
controls.brush_w.build()
|
|
|
|
controls.brush_h.char = "" + h
|
|
|
|
controls.brush_h.build()
|
|
|
|
}
|
|
|
|
brush.size_add = function(w, h){
|
|
|
|
brush.resize(brush.w + w, brush.h + h)
|
|
|
|
}
|
|
|
|
brush.expand = function(i){
|
|
|
|
brush.size_add(i, i)
|
|
|
|
}
|
|
|
|
brush.contract = function(i){
|
|
|
|
brush.size_add(-i, -i)
|
|
|
|
}
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
brush.load = function(lex){
|
|
|
|
brush.char = lex.char
|
|
|
|
brush.fg = lex.fg
|
|
|
|
brush.bg = lex.bg
|
|
|
|
brush.opacity = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
brush.min = 1
|
|
|
|
brush.max = 100
|
|
|
|
|
|
|
|
brush.char = " "
|
|
|
|
brush.fg = 0
|
|
|
|
brush.bg = 1
|
|
|
|
brush.opacity = 1
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
brush.draw_fg = true
|
|
|
|
brush.draw_bg = true
|
|
|
|
brush.draw_char = true
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-10-24 11:14:46 -04:00
|
|
|
return brush
|
|
|
|
|
|
|
|
})()
|
2018-11-24 02:38:52 -05:00
|
|
|
|
|
|
|
var custom = (function(){
|
|
|
|
|
|
|
|
var exports = {}
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-11-24 02:38:52 -05:00
|
|
|
exports.clone = function (){
|
|
|
|
var new_brush = brush.clone()
|
2018-11-25 05:57:06 -05:00
|
|
|
var wrapper = document.createElement("div")
|
|
|
|
wrapper.className = "custom"
|
|
|
|
new_brush.append(wrapper)
|
|
|
|
custom_wrapper.appendChild(wrapper)
|
2018-11-24 02:38:52 -05:00
|
|
|
// store in localstorage?
|
2018-11-25 05:57:06 -05:00
|
|
|
wrapper.addEventListener("click", function(e){
|
2018-11-24 02:38:52 -05:00
|
|
|
if (e.shiftKey) {
|
2018-11-25 05:57:06 -05:00
|
|
|
wrapper.parentNode.removeChild(wrapper)
|
2018-11-24 02:38:52 -05:00
|
|
|
delete new_brush
|
|
|
|
} else {
|
|
|
|
// load this brush
|
|
|
|
exports.load(new_brush)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-11-24 02:38:52 -05:00
|
|
|
exports.load = function(new_brush){
|
|
|
|
brush.assign( new_brush )
|
|
|
|
}
|
2018-11-24 02:49:02 -05:00
|
|
|
|
2018-11-24 02:38:52 -05:00
|
|
|
return exports
|
|
|
|
|
|
|
|
})()
|