Skip to content
Snippets Groups Projects
Commit 1d239b44 authored by mcmlxxix's avatar mcmlxxix
Browse files

fixed center(). fixed putmsg() to properly handle CRLF. move(), moveTo(),...

fixed center(). fixed putmsg() to properly handle CRLF. move(), moveTo(), refresh(), top(), bottom() now apply to child frames. (e.g. parent "car" moves, child "passenger" moves with it)
parent 99512352
No related branches found
No related tags found
No related merge requests found
...@@ -25,14 +25,13 @@ METHODS: ...@@ -25,14 +25,13 @@ METHODS:
frame.close(); //removes frame contents from character canvas frame.close(); //removes frame contents from character canvas
frame.draw(); //draws the characters occupied by 'frame' coords/dimensions frame.draw(); //draws the characters occupied by 'frame' coords/dimensions
frame.cycle(); //checks the display matrix for updated characters and displays them frame.cycle(); //checks the display matrix for updated characters and displays them
frame.load(filename): //loads a binary graphic (.BIN) or ANSI graphic (.ANS) file into the frame frame.load(filename): //loads a binary graphic (.BIN) or ANSI graphic (.ANS) file
frame.bottom(); //push frame to bottom of display stack frame.bottom(); //push frame to bottom of display stack
frame.top(); //pull frame to top of display stack frame.top(); //pull frame to top of display stack
frame.scroll(dir); //scroll frame one line in either direction ***NOT YET IMPLEMENTED*** frame.scroll(dir); //scroll frame one line in either direction ***NOT YET IMPLEMENTED***
frame.move(x,y); //move frame one space where x = -1,0,1 and y = -1,0,1 frame.move(x,y); //move frame one space where x = -1,0,1 and y = -1,0,1
frame.moveTo(x,y); //move frame to absolute position frame.moveTo(x,y); //move frame to absolute position
frame.clearline(attr); //see http://synchro.net/docs/jsobjs.html#console
frame.clearline(attr); //see http://synchro.net/docs/jsobjs.html#console
frame.cleartoeol(attr); frame.cleartoeol(attr);
frame.putmsg(str); frame.putmsg(str);
frame.clear(attr); frame.clear(attr);
...@@ -54,7 +53,7 @@ METHODS: ...@@ -54,7 +53,7 @@ METHODS:
//add a new frame within the frame object that will display on top at position 10,10 //add a new frame within the frame object that will display on top at position 10,10
var subframe = new Frame(10,10,10,10,BG_GREEN,frame); var subframe = new Frame(10,10,10,10,BG_GREEN,frame);
.//beware this sample infinite loop //beware this sample infinite loop
while(!js.terminated) { while(!js.terminated) {
//on first call this will draw the entire initial frame //on first call this will draw the entire initial frame
...@@ -247,8 +246,8 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -247,8 +246,8 @@ function Frame(x,y,width,height,attr,frame) {
pointer = canvas.data[x][y]; pointer = canvas.data[x][y];
if(pointer instanceof Coord) { if(pointer instanceof Coord) {
ch = canvas.frame.getData(pointer).ch; ch = canvas.frame.getData(pointer.x,pointer.y).ch;
attr = canvas.frame.getData(pointer).attr; attr = canvas.frame.getData(pointer.x,pointer.y).attr;
} }
console.attributes = attr; console.attributes = attr;
...@@ -259,6 +258,13 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -259,6 +258,13 @@ function Frame(x,y,width,height,attr,frame) {
else else
console.write(ch); console.write(ch);
} }
function getTop(canvas,x,y) {
var last = undefined;
for each(var c in canvas)
if(c.data[x][y])
last = c;
return last;
}
/* initialize display properties */ /* initialize display properties */
this.x = x; this.x = x;
...@@ -389,28 +395,34 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -389,28 +395,34 @@ function Frame(x,y,width,height,attr,frame) {
}); });
/* public methods */ /* public methods */
this.getData = function(pointer) { this.getData = function(x,y) {
return properties.data[pointer.x + position.offset.x][pointer.y + position.offset.y]; return properties.data[x + position.offset.x][y + position.offset.y];
} }
this.setData = function(pointer,ch,attr) { this.setData = function(x,y,ch,attr) {
properties.data properties.data[x + position.offset.x][y + position.offset.y].ch = ch;
[pointer.x + position.offset.x] properties.data[x + position.offset.x][y + position.offset.y].attr = attr;
[pointer.y + position.offset.y].ch = ch;
properties.data
[pointer.x + position.offset.x]
[pointer.y + position.offset.y].attr = attr;
} }
this.bottom = function() { this.bottom = function() {
for each(var c in relations.child)
c.bottom();
properties.display.bottom(this); properties.display.bottom(this);
} }
this.top = function() { this.top = function() {
properties.display.top(this); properties.display.top(this);
for each(var c in relations.child)
c.top();
} }
this.open = function() { this.open = function() {
properties.display.add(this); properties.display.add(this);
for each(var c in relations.child) for each(var c in relations.child)
c.open(); c.open();
} }
this.refresh = function() {
properties.canvas.updateFrame(this);
for each(var c in relations.child)
c.refresh();
}
this.close = function() { this.close = function() {
for each(var c in relations.child) for each(var c in relations.child)
c.close(); c.close();
...@@ -423,6 +435,8 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -423,6 +435,8 @@ function Frame(x,y,width,height,attr,frame) {
if(this.y+y < properties.display.y || if(this.y+y < properties.display.y ||
this.y+y + this.height > properties.display.y + properties.display.height) this.y+y + this.height > properties.display.y + properties.display.height)
return false; return false;
for each(var c in relations.child)
c.move(x,y);
properties.display.updateFrame(this); properties.display.updateFrame(this);
properties.x += x; properties.x += x;
properties.y += y; properties.y += y;
...@@ -433,13 +447,16 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -433,13 +447,16 @@ function Frame(x,y,width,height,attr,frame) {
return false; return false;
if(y < properties.display.y || y + this.height > properties.display.y + properties.display.height) if(y < properties.display.y || y + this.height > properties.display.y + properties.display.height)
return false; return false;
for each(var c in relations.child)
c.moveTo(x + (c.x - this.x), y + (c.y - this.y));
properties.display.updateFrame(this); properties.display.updateFrame(this);
properties.x = x; properties.x = x;
properties.y = y; properties.y = y;
properties.display.add(this); properties.display.add(this);
} }
this.draw = function() { this.draw = function() {
properties.display.draw(this); this.refresh();
this.cycle();
} }
this.cycle = function() { this.cycle = function() {
return properties.display.cycle(); return properties.display.cycle();
...@@ -651,18 +668,8 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -651,18 +668,8 @@ function Frame(x,y,width,height,attr,frame) {
var control_a = false; var control_a = false;
var curattr = this.attr; var curattr = this.attr;
var pos = position.cursor; var pos = position.cursor;
var off = position.offset;
while(str.length > 0) { while(str.length > 0) {
if(pos.x >= this.width) {
pos.x=0;
pos.y++;
}
if(pos.y >= this.height) {
this.scroll();
pos.y--;
}
var ch = str.shift(); var ch = str.shift();
if(control_a) { if(control_a) {
var k = ch; var k = ch;
...@@ -670,8 +677,7 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -670,8 +677,7 @@ function Frame(x,y,width,height,attr,frame) {
k = k.toUpperCase(); k = k.toUpperCase();
switch(k) { switch(k) {
case '\1': /* A "real" ^A code */ case '\1': /* A "real" ^A code */
this.setData(position.cursor,ch,curattr); putChar.call(this,ch,curattr);
properties.display.updateChar(this,pos.x,pos.y);
pos.x++; pos.x++;
break; break;
case 'K': /* Black */ case 'K': /* Black */
...@@ -769,8 +775,7 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -769,8 +775,7 @@ function Frame(x,y,width,height,attr,frame) {
pos.y++; pos.y++;
break; break;
default: default:
this.setData(position.cursor,ch,curattr); putChar.call(this,ch,curattr);
properties.display.updateChar(this,pos.x,pos.y);
pos.x++; pos.x++;
break; break;
} }
...@@ -778,7 +783,7 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -778,7 +783,7 @@ function Frame(x,y,width,height,attr,frame) {
} }
} }
this.center = function(str) { this.center = function(str) {
position.cursor.x = Math.ceil(this.width/2) - Math.ceil(console.strlen(str)/2) + 1; position.cursor.x = Math.ceil(this.width/2) - Math.ceil(console.strlen(strip_ctrl(str))/2);
if(position.cursor.x < 0) if(position.cursor.x < 0)
position.cursor.x = 0; position.cursor.x = 0;
this.putmsg(str); this.putmsg(str);
...@@ -806,12 +811,22 @@ function Frame(x,y,width,height,attr,frame) { ...@@ -806,12 +811,22 @@ function Frame(x,y,width,height,attr,frame) {
} }
/* private functions */ /* private functions */
function getTop(canvas,x,y) { function putChar(ch,attr) {
var last = undefined; if(position.cursor.x >= this.width) {
for each(var c in canvas) position.cursor.x=0;
if(c.data[x][y]) position.cursor.y++;
last = c; }
return last; if(position.cursor.y >= this.height) {
this.scroll();
position.cursor.y--;
}
properties.data
[position.cursor.x + position.offset.x]
[position.cursor.y + position.offset.y].ch = ch;
properties.data
[position.cursor.x + position.offset.x]
[position.cursor.y + position.offset.y].attr = attr;
properties.display.updateChar(this,position.cursor.x,position.cursor.y);
} }
function init(x,y,width,height,attr,frame) { function init(x,y,width,height,attr,frame) {
if(frame instanceof Frame) { if(frame instanceof Frame) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment