asciiblaster- draw irc art in your web browser |
git clone git://git.acid.vegas/asciiblaster.git |
Log | Files | Refs | Archive | README |
letters.js (2134B)
1 var letters = (function(){ 2 3 var last_charset = "" 4 var charset_index = 0 5 var charsets = [ 6 'Basic Latin', 7 'Latin-1 Supplement', 8 'Box Drawing', 9 'Block Elements', 10 ] 11 12 var letters = new Matrix (1, 1, function(x,y){ 13 var lex = new Lex (x,y) 14 return lex 15 }) 16 17 letters.charset = "" 18 19 letters.repaint = function(charset){ 20 letters.charset = charset = charset || last_charset 21 last_charset = charset 22 var chars = unicode.block(charset, 32) 23 if (chars[0] != " ") chars.unshift(" ") 24 if (canvas.vertical) { 25 letters.resize( Math.ceil( chars.length / 16 ), 16 ) 26 } 27 else { 28 letters.resize( 32, Math.ceil( chars.length / 32 ) ) 29 } 30 31 var i = 0 32 33 letters.forEach(function(lex,x,y){ 34 if (canvas.vertical) { x=x^y;y=x^y;x=x^y } 35 var char = chars[i++] 36 if (palette.chars.indexOf(brush.char) > 1) { 37 lex.bg = brush.fg 38 lex.fg = brush.bg 39 } 40 else { 41 lex.bg = colors.black 42 lex.fg = brush.fg == fillColor ? colors.black : brush.fg 43 } 44 lex.char = char 45 lex.opacity = 1 46 lex.build() 47 }) 48 } 49 50 letters.bind = function(){ 51 letters.forEach(function(lex,x,y){ 52 if (lex.bound) return 53 lex.bound = true 54 55 lex.span.addEventListener('mousedown', function(e){ 56 e.preventDefault() 57 if (e.shiftKey) { 58 charset_index = (charset_index+1) % charsets.length 59 letters.repaint(charsets[charset_index]) 60 return 61 } 62 else if (e.ctrlKey || e.which == 3) { 63 brush.char = lex.char 64 brush.bg = brush.fg 65 brush.fg = fillColor 66 } 67 else { 68 brush.char = lex.char 69 if (lex.char == " ") { 70 brush.bg = brush.fg 71 } 72 else if (brush.bg != fillColor) { 73 brush.fg = brush.bg 74 brush.bg = fillColor 75 } 76 } 77 if (! brush.modified) { 78 brush.generate() 79 } 80 palette.repaint() 81 }) 82 lex.span.addEventListener('contextmenu', function(e){ 83 e.preventDefault() 84 }) 85 }) 86 } 87 88 return letters 89 })()