Skip to content
Snippets Groups Projects
Commit 3f1f60ad authored by echicken's avatar echicken
Browse files

A bunch of formatting changes made while refamiliarizing myself.

Added save_bin method.
Center the canvas inside the frame if it's smaller.
Some changes to how positions of menu, etc. are determined.
This is not great, but it'll do.
parent eaaa4658
No related branches found
No related tags found
No related merge requests found
...@@ -107,13 +107,8 @@ load("frame.js"); ...@@ -107,13 +107,8 @@ load("frame.js");
load("tree.js"); load("tree.js");
load("funclib.js"); load("funclib.js");
var ANSIEdit = function(options) { const characterSets = [
[ 49, 50, 51, 52, 53, 54, 55, 56, 57, 48 ],
var tree,
frames = {},
self = this,
characterSets = [
[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ],
[ 218, 191, 192, 217, 196, 179, 195, 180, 193, 194 ], [ 218, 191, 192, 217, 196, 179, 195, 180, 193, 194 ],
[ 201, 187, 200, 188, 205, 186, 204, 185, 202, 203 ], [ 201, 187, 200, 188, 205, 186, 204, 185, 202, 203 ],
[ 213, 184, 212, 190, 205, 179, 198, 181, 207, 209 ], [ 213, 184, 212, 190, 205, 179, 198, 181, 207, 209 ],
...@@ -129,23 +124,8 @@ var ANSIEdit = function(options) { ...@@ -129,23 +124,8 @@ var ANSIEdit = function(options) {
[ 245, 246, 247, 248, 249, 250, 251, 252, 253, 253 ] [ 245, 246, 247, 248, 249, 250, 251, 252, 253, 253 ]
]; ];
var state = {
'attr' : (typeof options.attr != "number") ? LIGHTGRAY : options.attr,
'inMenu' : false,
'cursor' : { 'x' : 1, 'y' : 1 },
'lastCursor' : { 'x' : 0, 'y' : 0 },
'charSet' : 6,
};
var settings = {
'vScroll' : (typeof options.vScroll != "boolean") ? false : options.vScroll,
'hScroll' : (typeof options.hScroll != "boolean") ? false : options.hScroll,
'showPosition' : (typeof options.showPosition != "boolean") ? false : true,
'menuHeading' : (typeof options.menuHeading != "string") ? "ANSI Editor" : options.menuHeading
};
// Map sbbsdefs.js console attributes to values usable in ANSI sequences // Map sbbsdefs.js console attributes to values usable in ANSI sequences
var attrMap = {}; const attrMap = {};
attrMap[HIGH] = 1; attrMap[HIGH] = 1;
attrMap[BLINK] = 5; attrMap[BLINK] = 5;
attrMap[BLACK] = 30; attrMap[BLACK] = 30;
...@@ -156,14 +136,14 @@ var ANSIEdit = function(options) { ...@@ -156,14 +136,14 @@ var ANSIEdit = function(options) {
attrMap[MAGENTA] = 35; attrMap[MAGENTA] = 35;
attrMap[CYAN] = 36; attrMap[CYAN] = 36;
attrMap[LIGHTGRAY] = 37; attrMap[LIGHTGRAY] = 37;
attrMap[DARKGRAY] = attrMap[BLACK]; attrMap[DARKGRAY] = 30;
attrMap[LIGHTRED] = attrMap[RED]; attrMap[LIGHTRED] = 31;
attrMap[LIGHTGREEN] = attrMap[GREEN]; attrMap[LIGHTGREEN] = 32;
attrMap[YELLOW] = attrMap[BROWN]; attrMap[YELLOW] = 33;
attrMap[LIGHTBLUE] = attrMap[BLUE]; attrMap[LIGHTBLUE] = 34;
attrMap[LIGHTMAGENTA] = attrMap[MAGENTA]; attrMap[LIGHTMAGENTA] = 35;
attrMap[LIGHTCYAN] = attrMap[CYAN]; attrMap[LIGHTCYAN] = 36;
attrMap[WHITE] = attrMap[LIGHTGRAY]; attrMap[WHITE] = 37;
attrMap[BG_BLACK] = 40; attrMap[BG_BLACK] = 40;
attrMap[BG_RED] = 41; attrMap[BG_RED] = 41;
attrMap[BG_GREEN] = 42; attrMap[BG_GREEN] = 42;
...@@ -173,59 +153,86 @@ var ANSIEdit = function(options) { ...@@ -173,59 +153,86 @@ var ANSIEdit = function(options) {
attrMap[BG_CYAN] = 46; attrMap[BG_CYAN] = 46;
attrMap[BG_LIGHTGRAY] = 47; attrMap[BG_LIGHTGRAY] = 47;
var initFrames = function() { var ANSIEdit = function(options) {
var tree,
frames = {},
self = this;
var state = {
attr : (typeof options.attr != 'number') ? LIGHTGRAY : options.attr,
inMenu : false,
cursor : { 'x' : 1, 'y' : 1 },
lastCursor : { 'x' : 0, 'y' : 0 },
charSet : 6,
};
var settings = {
vScroll : typeof options.vScroll != 'boolean' ? false : options.vScroll,
hScroll : typeof options.hScroll != 'boolean' ? false : options.hScroll,
showPosition : typeof options.showPosition != 'boolean' ? false : true,
menuHeading : (
typeof options.menuHeading != 'string'
? 'ANSI Editor'
: options.menuHeading
)
};
function initFrames() {
if (typeof options.canvas_width !== 'number') options.canvas_width = options.width;
if (typeof options.canvas_height !== 'number') options.canvas_height = options.height - 1;
frames.top = new Frame( frames.top = new Frame(
options.x, options.x,
options.y, options.y,
options.width, options.width,
options.height, options.height,
LIGHTGRAY, BG_BLUE|LIGHTGRAY,
options.parentFrame options.parentFrame
); );
frames.top.checkbounds = false;
if (options.width > options.canvas_width) {
var cx = options.x + Math.floor((options.width - options.canvas_width) / 2)
} else {
var cx = frames.top.x
}
if (options.height - 1 > options.canvas_height) {
var cy = options.y + Math.floor((options.height - options.canvas_height) / 2)
} else {
var cy = frames.top.y;
}
frames.canvas = new Frame( frames.canvas = new Frame(
frames.top.x, cx, cy,
frames.top.y, options.canvas_width, options.canvas_height,
frames.top.width, LIGHTGRAY, frames.top
frames.top.height - 1,
LIGHTGRAY,
frames.top
); );
frames.canvas.v_scroll = settings.vScroll; frames.canvas.v_scroll = settings.vScroll;
frames.canvas.h_scroll = settings.hScroll; frames.canvas.h_scroll = settings.hScroll;
frames.charSet = new Frame( frames.charSet = new Frame(
frames.top.x, frames.top.x, frames.top.y + frames.top.height - 1,
frames.canvas.y + frames.canvas.height, frames.top.width, 1,
50, state.attr, frames.top
1,
state.attr,
frames.top
); );
if (settings.showPosition) { if (settings.showPosition) {
frames.position = new Frame( frames.position = new Frame(
frames.charSet.x + frames.charSet.width + 1, frames.charSet.x + frames.charSet.width + 1, frames.charSet.y,
frames.charSet.y, frames.top.width - frames.charSet.width - 1, 1,
frames.top.width - frames.charSet.width - 1, state.attr, frames.top
1,
state.attr,
frames.top
); );
} }
frames.menu = new Frame( frames.menu = new Frame(
Math.floor((frames.top.width - 28) / 2), Math.floor((frames.top.width - 28) / 2), frames.top.y + 1,
frames.canvas.y + 1, 28, frames.top.height - 2,
28, BG_BLUE|WHITE, frames.top
frames.canvas.height - 2,
BG_BLUE|WHITE,
frames.top
); );
frames.menu.center(settings.menuHeading); frames.menu.center(settings.menuHeading);
frames.menu.gotoxy(1, frames.menu.height); frames.menu.gotoxy(1, frames.menu.height);
frames.menu.center("Press <TAB> to exit"); frames.menu.center('Press <TAB> to exit');
frames.subMenu = new Frame( frames.subMenu = new Frame(
frames.menu.x + 1, frames.menu.x + 1,
...@@ -238,83 +245,85 @@ var ANSIEdit = function(options) { ...@@ -238,83 +245,85 @@ var ANSIEdit = function(options) {
} }
var initMenu = function() { function initMenu() {
tree = new Tree(frames.subMenu); tree = new Tree(frames.subMenu);
tree.colors.fg = WHITE; tree.colors.fg = WHITE;
tree.colors.lfg = WHITE; tree.colors.lfg = WHITE;
tree.colors.lbg = BG_CYAN; tree.colors.lbg = BG_CYAN;
tree.colors.tfg = LIGHTCYAN; tree.colors.tfg = LIGHTCYAN;
tree.colors.xfg = LIGHTCYAN; tree.colors.xfg = LIGHTCYAN;
tree.addItem("Color Palette", setColour); tree.addItem('Color Palette', setColour);
var charSetTree = tree.addTree("Choose Character Set"); var charSetTree = tree.addTree('Choose Character Set');
charSetTree.addItem(characterSets[0].join(" "), drawCharSet, 0); characterSets.forEach(
for(var c = 1; c < characterSets.length; c++) { function (e, i) {
var line = []; var line = e.map(function (ee) { return ascii(ee); });
for(var cc in characterSets[c]) charSetTree.addItem(line.join(" "), drawCharSet, i);
line.push(ascii(characterSets[c][cc])); }
charSetTree.addItem(line.join(" "), drawCharSet, c); );
} var downloadTree = tree.addTree('Download this ANSI');
var downloadTree = tree.addTree("Download this ANSI"); downloadTree.addItem(' Binary', download, 'bin');
downloadTree.addItem(" Binary", download, "bin"); downloadTree.addItem(' ASCII', download, 'ascii');
downloadTree.addItem(" ASCII", download, "ascii"); downloadTree.addItem(' ANSI', download, 'ansi');
downloadTree.addItem(" ANSI", download, "ansi"); tree.addItem('Clear the Canvas', self.clear);
tree.addItem("Clear the Canvas", self.clear);
tree.open(); tree.open();
} }
var setColour = function() { function setColour() {
state.attr = colorPicker( state.attr = colorPicker(
frames.menu.x - 4, frames.top.x + Math.floor((frames.top.width - 36) / 2), //frames.menu.x - 4,
Math.floor((frames.menu.height - 6) / 2), frames.top.y + Math.floor((frames.top.height - 6) / 2),
frames.menu, frames.menu,
state.attr state.attr
); );
drawCharSet(); drawCharSet();
return "DONE"; return 'DONE'; // wat?
} }
var drawCharSet = function(n) { function drawCharSet(n) {
if(typeof n != "undefined") if (typeof n != 'undefined') state.charSet = n;
state.charSet = n;
frames.charSet.attr = state.attr; frames.charSet.attr = state.attr;
frames.charSet.clear(); frames.charSet.clear();
for(var c = 0; c < characterSets[state.charSet].length; c++) characterSets[state.charSet].forEach(
frames.charSet.putmsg(((c+1)%10) + ":" + ascii(characterSets[state.charSet][c]) + " "); function (e, i) {
frames.charSet.putmsg("<TAB> menu"); frames.charSet.putmsg(((i+1)%10) + ':' + ascii(e) + ' ');
return "DONE"; }
);
frames.charSet.putmsg('<TAB> menu');
return 'DONE'; // wat?
} }
var saveAscii = function() { function saveAscii() {
var lines = []; var lines = [];
log(frames.canvas.data_width); log(frames.canvas.data_width);
for (var y = 0; y < frames.canvas.data_height; y++) { for (var y = 0; y < frames.canvas.data_height; y++) {
var line = ""; var line = "";
for (var x = 0; x < frames.canvas.data_width; x++) { for (var x = 0; x < frames.canvas.data_width; x++) {
var ch = frames.canvas.getData(x, y); var ch = frames.canvas.getData(x, y);
line += (typeof ch.ch == "undefined" || ch.ch == "") ? " " : ch.ch; line += (
(typeof ch.ch == 'undefined' || ch.ch == '') ? ' ' : ch.ch
);
} }
lines.push(line); lines.push(line);
} }
var fn = system.data_dir + format("user/%04u.asc", user.number); var fn = system.data_dir + format('user/%04u.asc', user.number);
var f = new File(fn); var f = new File(fn);
f.open("w"); f.open('w');
f.writeAll(lines); f.writeAll(lines);
f.close(); f.close();
return fn; return fn;
} }
var saveAnsi = function() { function saveAnsi() {
var fgmask = (1<<0)|(1<<1)|(1<<2)|(1<<3); var fgmask = (1<<0)|(1<<1)|(1<<2)|(1<<3);
var bgmask = (1<<4)|(1<<5)|(1<<6); var bgmask = (1<<4)|(1<<5)|(1<<6);
var lines = [], fg = 7, bg = 0, hi = 0; var lines = [], fg = 7, bg = 0, hi = 0;
var line = format("%s[%s;%s;%sm", ascii(27), hi, fg, bg); var line = format('%s[%s;%s;%sm', ascii(27), hi, fg, bg);
for (var y = 0; y < frames.canvas.data_height; y++) { for (var y = 0; y < frames.canvas.data_height; y++) {
if(y > 0) if (y > 0) line = '';
line = "";
var blanks = 0; var blanks = 0;
for (var x = 0; x < frames.canvas.data_width; x++) { for (var x = 0; x < frames.canvas.data_width; x++) {
var ch = frames.canvas.getData(x, y); var ch = frames.canvas.getData(x, y);
if(typeof ch.attr != "undefined") { if (typeof ch.attr != 'undefined') {
var sequence = []; var sequence = [];
if ((ch.attr&fgmask) != fg) { if ((ch.attr&fgmask) != fg) {
fg = (ch.attr&fgmask); fg = (ch.attr&fgmask);
...@@ -331,15 +340,14 @@ var ANSIEdit = function(options) { ...@@ -331,15 +340,14 @@ var ANSIEdit = function(options) {
bg = (ch.attr&bgmask); bg = (ch.attr&bgmask);
sequence.push((bg == 0) ? 40 : attrMap[bg]); sequence.push((bg == 0) ? 40 : attrMap[bg]);
} }
sequence = format("%s[%sm", ascii(27), sequence.join(";")); sequence = format('%s[%sm', ascii(27), sequence.join(';'));
if(sequence.length > 3) if (sequence.length > 3) line += sequence;
line += sequence;
} }
if(typeof ch.ch == "undefined") { if (typeof ch.ch == 'undefined') {
blanks++; blanks++;
} else { } else {
if (blanks > 0) { if (blanks > 0) {
line += ascii(27) + "[" + blanks + "C"; line += ascii(27) + '[' + blanks + 'C';
blanks = 0; blanks = 0;
} }
line += ch.ch; line += ch.ch;
...@@ -347,51 +355,52 @@ var ANSIEdit = function(options) { ...@@ -347,51 +355,52 @@ var ANSIEdit = function(options) {
} }
lines.push(line); lines.push(line);
} }
var fn = system.data_dir + format("user/%04u.ans", user.number); var fn = system.data_dir + format('user/%04u.ans', user.number);
var f = new File(fn); var f = new File(fn);
f.open("w"); f.open('w');
f.writeAll(lines); f.writeAll(lines);
f.close(); f.close();
return fn; return fn;
} }
var saveBin = function() { function saveBin() {
var f = system.data_dir + format("user/%04u.bin", user.number); var f = system.data_dir + format('user/%04u.bin', user.number);
frames.canvas.screenShot(f, false); frames.canvas.screenShot(f, false);
return f; return f;
} }
var download = function(type) { function download(type) {
switch (type) { switch (type) {
case "bin": case 'bin':
var f = saveBin(); var f = saveBin();
break; break;
case "ansi": case 'ansi':
var f = saveAnsi(); var f = saveAnsi();
break; break;
case "ascii": case 'ascii':
var f = saveAscii(); var f = saveAscii();
break; break;
default: default:
break; break;
} }
if(typeof f != "undefined") { if (typeof f != 'undefined') {
console.clear(LIGHTGRAY); console.clear(LIGHTGRAY);
bbs.send_file(f, user.download_protocol); bbs.send_file(f, user.download_protocol);
if(typeof frames.top.parent != "undefined") if (typeof frames.top.parent != "undefined") {
frames.top.parent.invalidate(); frames.top.parent.invalidate();
else } else {
frames.top.invalidate(); frames.top.invalidate();
} }
return "DONE"; }
return 'DONE'; // wat?
} }
var raiseMenu = function() { function raiseMenu() {
state.inMenu = true; state.inMenu = true;
frames.menu.top(); frames.menu.top();
} }
var lowerMenu = function() { function lowerMenu() {
state.inMenu = false; state.inMenu = false;
frames.menu.bottom(); frames.menu.bottom();
self.cycle(true); self.cycle(true);
...@@ -411,8 +420,9 @@ var ANSIEdit = function(options) { ...@@ -411,8 +420,9 @@ var ANSIEdit = function(options) {
this.close = function() { this.close = function() {
tree.close(); tree.close();
frames.top.close(); frames.top.close();
if(typeof frames.top.parent != "undefined") if (typeof frames.top.parent != 'undefined') {
frames.top.parent.invalidate(); frames.top.parent.invalidate();
}
frames.top.delete(); frames.top.delete();
} }
...@@ -420,45 +430,49 @@ var ANSIEdit = function(options) { ...@@ -420,45 +430,49 @@ var ANSIEdit = function(options) {
frames.canvas.clear(); frames.canvas.clear();
state.cursor.x = frames.canvas.x; state.cursor.x = frames.canvas.x;
state.cursor.y = frames.canvas.y; state.cursor.y = frames.canvas.y;
return "CLEAR"; return 'CLEAR';
} }
this.putChar = function(ch) { this.putChar = function(ch) {
// Hacky workaround for something broken in Frame.scroll() // Hacky workaround for something broken in Frame.scroll()
if(frames.canvas.data_height > frames.canvas.height && frames.canvas.offset.y > 0) if (frames.canvas.data_height > frames.canvas.height &&
frames.canvas.offset.y > 0
) {
frames.canvas.refresh(); frames.canvas.refresh();
if(frames.canvas.data_width > frames.canvas.width && frames.canvas.offset.x > 0) }
if (frames.canvas.data_width > frames.canvas.width &&
frames.canvas.offset.x > 0
) {
frames.canvas.refresh(); frames.canvas.refresh();
}
frames.canvas.setData( frames.canvas.setData(
(typeof ch.x == "undefined") ? (state.cursor.x - frames.canvas.x) : ch.x, typeof ch.x == 'undefined' ? state.cursor.x - frames.canvas.x : ch.x,
(typeof ch.y == "undefined") ? (state.cursor.y - frames.canvas.y) : ch.y, typeof ch.y == 'undefined' ? state.cursor.y - frames.canvas.y : ch.y,
ch.ch, ch.ch,
(typeof ch.attr == "undefined") ? state.attr : ch.attr typeof ch.attr == 'undefined' ? state.attr : ch.attr
); );
if(typeof ch.x != "undefined") { if (typeof ch.x != 'undefined') {
this.cycle(true); this.cycle(true);
return; return;
} }
var ret = { var ret = {
'x' : state.cursor.x - frames.canvas.x, x : state.cursor.x - frames.canvas.x,
'y' : state.cursor.y - frames.canvas.y, y : state.cursor.y - frames.canvas.y,
'ch' : ch.ch, ch : ch.ch,
'attr' : state.attr attr : state.attr
}; };
if( settings.hScroll if (settings.hScroll ||
||
state.cursor.x < frames.canvas.x + frames.canvas.width - 1 state.cursor.x < frames.canvas.x + frames.canvas.width - 1
) { ) {
state.cursor.x++; state.cursor.x++;
} }
if( settings.hScroll if (settings.hScroll &&
&&
state.cursor.x - frames.canvas.offset.x > frames.canvas.width state.cursor.x - frames.canvas.offset.x > frames.canvas.width
) { ) {
frames.canvas.scroll(1, 0); frames.canvas.scroll(1, 0);
...@@ -471,169 +485,151 @@ var ANSIEdit = function(options) { ...@@ -471,169 +485,151 @@ var ANSIEdit = function(options) {
this.getcmd = function(userInput) { this.getcmd = function(userInput) {
if (userInput == "\x09") { if (userInput == "\x09") {
state.inMenu ? lowerMenu() : raiseMenu();
(state.inMenu) ? lowerMenu() : raiseMenu();
} else if(state.inMenu) { } else if(state.inMenu) {
var ret = tree.getcmd(userInput); var ret = tree.getcmd(userInput);
if(ret == "DONE" || ret == "CLEAR") if (ret == 'DONE' || ret == 'CLEAR') lowerMenu();
lowerMenu(); if (ret == 'CLEAR') {
if(ret == "CLEAR") {
var retval = { var retval = {
'x' : state.cursor.x - frames.canvas.x, x : state.cursor.x - frames.canvas.x,
'y' : state.cursor.y - frames.canvas.y, y : state.cursor.y - frames.canvas.y,
'ch' : "CLEAR", ch : 'CLEAR',
'attr' : state.attr attr : state.attr
} }
} }
} else if ( } else if (
userInput.match(/[\r]/) !== null userInput.search(/\r/) >= 0 &&
&&
(state.cursor.y < frames.canvas.y + frames.canvas.height - 1 || settings.vScroll) (state.cursor.y < frames.canvas.y + frames.canvas.height - 1 || settings.vScroll)
) { ) {
state.cursor.y++; state.cursor.y++;
state.cursor.x = frames.canvas.x; state.cursor.x = frames.canvas.x;
if (state.cursor.y - frames.canvas.offset.y > frames.canvas.height) { if (state.cursor.y - frames.canvas.offset.y > frames.canvas.height) {
// I don't know why I need to do this, especially not after looking at Frame.scroll() // I don't know why I need to do this, especially not after looking at Frame.scroll()
// but vertical Frame.scroll() won't work unless I do this // but vertical Frame.scroll() won't work unless I do this
if(typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == "undefined") { if (typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == 'undefined') {
frames.canvas.setData( frames.canvas.setData(
state.cursor.x - frames.canvas.x, state.cursor.x - frames.canvas.x,
state.cursor.y - frames.canvas.y, state.cursor.y - frames.canvas.y,
"", '',
0 0
); );
} }
frames.canvas.scroll(); frames.canvas.scroll();
} }
} else if (userInput == '\x08' && state.cursor.x > frames.canvas.x) {
} else if(userInput == "\x08" && state.cursor.x > frames.canvas.x) {
state.cursor.x--; state.cursor.x--;
var retval = this.putChar( { 'ch' : " " }); var retval = this.putChar({ ch : '' });
state.cursor.x--; state.cursor.x--;
} else if (userInput == '\x7F') {
} else if(userInput == "\x7F") { var retval = this.putChar({ ch : ' ' });
var retval = this.putChar({ 'ch' : " " });
state.cursor.x--; state.cursor.x--;
} else if (userInput.match(/[0-9]/) !== null) { } else if (userInput.match(/[0-9]/) !== null) {
userInput = (userInput == 0) ? 9 : userInput - 1; userInput = (userInput == 0) ? 9 : userInput - 1;
var retval = this.putChar( var retval = this.putChar(
{ 'ch' : ascii(characterSets[state.charSet][userInput]) } { ch : ascii(characterSets[state.charSet][userInput]) }
); );
} else if(userInput.match(/[\x20-\x7E]/) !== null) { } else if(userInput.match(/[\x20-\x7E]/) !== null) {
var retval = this.putChar({ ch : userInput });
var retval = this.putChar({ 'ch' : userInput });
} else { } else {
switch (userInput) { switch (userInput) {
case KEY_UP: case KEY_UP:
if(state.cursor.y > frames.canvas.y) if (state.cursor.y > frames.canvas.y) state.cursor.y--;
state.cursor.y--; if (settings.vScroll &&
if( settings.vScroll frames.canvas.offset.y > 0 &&
&&
frames.canvas.offset.y > 0
&&
state.cursor.y == frames.canvas.offset.y state.cursor.y == frames.canvas.offset.y
) { ) {
frames.canvas.scroll(0, -1); frames.canvas.scroll(0, -1);
} }
break; break;
case KEY_DOWN: case KEY_DOWN:
if(settings.vScroll || state.cursor.y < frames.canvas.y + frames.canvas.height - 1) if (settings.vScroll ||
state.cursor.y < frames.canvas.y + frames.canvas.height - 1
) {
state.cursor.y++; state.cursor.y++;
if( settings.vScroll }
&& if (settings.vScroll &&
state.cursor.y - frames.canvas.offset.y > frames.canvas.height state.cursor.y - frames.canvas.offset.y > frames.canvas.height
) { ) {
// I don't know why I need to do this, especially not after looking at Frame.scroll() // I don't know why I need to do this, especially not after looking at Frame.scroll()
// but vertical Frame.scroll() won't work unless I do this // but vertical Frame.scroll() won't work unless I do this
if(typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == "undefined") { if (typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == 'undefined') {
frames.canvas.setData( frames.canvas.setData(
state.cursor.x - frames.canvas.x, state.cursor.x - frames.canvas.x,
state.cursor.y - frames.canvas.y, state.cursor.y - frames.canvas.y,
"", '',
0 0
); );
} }
frames.canvas.scroll(); frames.canvas.scroll();
} }
break; break;
case KEY_LEFT: case KEY_LEFT:
if(state.cursor.x > frames.canvas.x) if (state.cursor.x > frames.canvas.x) state.cursor.x--;
state.cursor.x--; if (settings.hScroll &&
if( settings.hScroll frames.canvas.offset.x > 0 &&
&&
frames.canvas.offset.x > 0
&&
state.cursor.x == frames.canvas.offset.x state.cursor.x == frames.canvas.offset.x
) { ) {
frames.canvas.scroll(-1, 0); frames.canvas.scroll(-1, 0);
} }
break; break;
case KEY_RIGHT: case KEY_RIGHT:
if(settings.hScroll || state.cursor.x < frames.canvas.x + frames.canvas.width - 1) if (settings.hScroll ||
state.cursor.x < frames.canvas.x + frames.canvas.width - 1
) {
state.cursor.x++; state.cursor.x++;
if( settings.hScroll }
&& if (settings.hScroll &&
state.cursor.x - frames.canvas.offset.x > frames.canvas.width state.cursor.x - frames.canvas.offset.x > frames.canvas.width
) { ) {
// Hacky hack to populate entire frame data matrix // Hacky hack to populate entire frame data matrix
// Horizontal Frame.scroll() doesn't otherwise work in this situation // Horizontal Frame.scroll() doesn't otherwise work in this situation
for (var y = 0; y <= state.cursor.y - frames.canvas.y; y++) { for (var y = 0; y <= state.cursor.y - frames.canvas.y; y++) {
if(typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == "undefined") if (typeof frames.canvas.data[state.cursor.y - frames.canvas.y] == 'undefined') {
frames.canvas.setData(state.cursor.x - frames.canvas.x, y, "", 0); frames.canvas.setData(
state.cursor.x - frames.canvas.x, y, '', 0
);
}
for (var x = 0; x <= state.cursor.x - frames.canvas.x; x++) { for (var x = 0; x <= state.cursor.x - frames.canvas.x; x++) {
if(typeof frames.canvas.data[y][x] == "undefined") if (typeof frames.canvas.data[y][x] == 'undefined') {
frames.canvas.setData(x, y, "", 0); frames.canvas.setData(x, y, '', 0);
}
} }
} }
frames.canvas.scroll(1, 0); frames.canvas.scroll(1, 0);
} }
break; break;
case KEY_HOME: case KEY_HOME:
state.cursor.x = frames.canvas.x; state.cursor.x = frames.canvas.x;
break; break;
case KEY_END: case KEY_END:
state.cursor.x = frames.canvas.data_width; state.cursor.x = frames.canvas.data_width;
break; break;
default: default:
break; break;
} }
} }
this.cycle(); this.cycle();
return (typeof retval != "undefined") ? retval : ({ 'x' : state.cursor.x - frames.canvas.x, 'y' : state.cursor.y - frames.canvas.y, 'ch' : false, 'attr' : state.attr }); return (
typeof retval != 'undefined'
? retval
: { x : state.cursor.x - frames.canvas.x,
y : state.cursor.y - frames.canvas.y,
ch : false,
attr : state.attr
}
);
} }
this.cycle = function(force) { this.cycle = function(force) {
if(typeof parentFrame == "undefined") if (typeof parentFrame == 'undefined') frames.top.cycle();
frames.top.cycle();
if( (typeof force == "boolean" && force) if ((typeof force == 'boolean' && force) ||
|| ( state.cursor.x != state.lastCursor.x ||
( state.cursor.x != state.lastCursor.x
||
state.cursor.y != state.lastCursor.y state.cursor.y != state.lastCursor.y
) )
) { ) {
...@@ -644,18 +640,31 @@ var ANSIEdit = function(options) { ...@@ -644,18 +640,31 @@ var ANSIEdit = function(options) {
state.cursor.y - frames.canvas.offset.y state.cursor.y - frames.canvas.offset.y
); );
for(var c in state.cursor) for (var c in state.cursor) state.lastCursor[c] = state.cursor[c];
state.lastCursor[c] = state.cursor[c];
if(!settings.showPosition) if (!settings.showPosition) return;
return;
frames.position.clear(); frames.position.clear();
frames.position.attr = state.attr; frames.position.attr = state.attr;
frames.position.putmsg(format("(%s:%s)", state.cursor.x, state.cursor.y)); frames.position.putmsg(
format('(%s:%s)', state.cursor.x, state.cursor.y)
);
}
} }
this.save_bin = function (fn) {
var f = new File(fn);
f.open('wb');
for (var y = 0; y < frames.canvas.height; y++) {
for (var x = 0; x < frames.canvas.width; x++) {
var ch = frames.canvas.getData(x, y);
f.write(ch.ch ? ch.ch : ' ');
f.writeBin(ch.attr ? ch.attr : 0, 1);
}
}
f.close();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment