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

added vertical looping (useful for lightbars perhaps?

think of the price is right wheel)
added indexing for relative position
parent 3bd18c37
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,8 @@ function Graphic(w,h,attr,ch) ...@@ -27,7 +27,8 @@ function Graphic(w,h,attr,ch)
this.data=new Array(w); this.data=new Array(w);
this.past=new Array(w); this.past=new Array(w);
this.future=new Array(w); this.future=new Array(w);
this.lines=0; this.length=0;
this.index=1;
var x; var x;
var y; var y;
...@@ -41,6 +42,8 @@ function Graphic(w,h,attr,ch) ...@@ -41,6 +42,8 @@ function Graphic(w,h,attr,ch)
this.data[x][y]=new Graphic_sector(this.ch,this.attribute); this.data[x][y]=new Graphic_sector(this.ch,this.attribute);
} }
} }
this.getxy=Graphic_getxy;
this.home=Graphic_home; this.home=Graphic_home;
this.end=Graphic_end; this.end=Graphic_end;
this.pgup=Graphic_pgup; this.pgup=Graphic_pgup;
...@@ -59,7 +62,13 @@ function Graphic_sector(ch,attr) ...@@ -59,7 +62,13 @@ function Graphic_sector(ch,attr)
this.ch=ch; this.ch=ch;
this.attr=attr; this.attr=attr;
} }
function Graphic_getxy()
{
if(this.length>=this.height) {
return this.height;
}
return this.length;
}
function Graphic_draw(xpos,ypos,width,height,xoff,yoff) function Graphic_draw(xpos,ypos,width,height,xoff,yoff)
{ {
var x; var x;
...@@ -268,32 +277,57 @@ function Graphic_home() ...@@ -268,32 +277,57 @@ function Graphic_home()
} }
} }
} }
function Graphic_scroll(dir) function Graphic_scroll(dir,loop)
{ {
switch(dir) switch(dir)
{ {
case 1: case 1:
if(this.index<this.length) this.index++;
else if(loop) this.index=1;
if(this.future[0].length>0) { if(this.future[0].length>0) {
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
this.past[x].push(this.data[x].shift()); this.past[x].push(this.data[x].shift());
this.data[x].push(this.future[x].shift()); this.data[x].push(this.future[x].shift());
} }
} else if(loop) {
for(x=0; x<this.width; x++) {
if(this.past[0].length>0) {
this.past[x].push(this.data[x].shift());
this.data[x].push(this.past[x].shift());
} else {
this.data[x].push(this.data[x].shift());
}
}
} }
break; break;
case -1: case -1:
if(this.index>1) this.index--;
else if(loop) this.index=this.length;
if(this.past[0].length>0) { if(this.past[0].length>0) {
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
this.future[x].unshift(this.data[x].pop()); this.future[x].unshift(this.data[x].pop());
this.data[x].unshift(this.past[x].pop()); this.data[x].unshift(this.past[x].pop());
} }
} else if(loop) {
for(x=0; x<this.width; x++) {
if(this.future[0].length) {
this.future[x].unshift(this.data[x].pop());
this.data[x].unshift(this.future[x].pop());
} else {
this.data[x].unshift(this.data[x].pop());
}
}
} }
break; break;
default: default:
this.end();
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
this.past[x].push(this.data[x].shift()); this.past[x].push(this.data[x].shift());
this.data[x].push(new Graphic_sector(this.ch,this.attribute)); this.data[x].push(new Graphic_sector(this.ch,this.attribute));
} }
if(this.lines<this.height) this.lines++; this.index=++this.length;
break; break;
} }
} }
...@@ -332,7 +366,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -332,7 +366,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
var curattr=attr; var curattr=attr;
var ch; var ch;
var x=xpos?xpos-1:0; var x=xpos?xpos-1:0;
var y=ypos?ypos-1:this.lines; var y=ypos?ypos-1:this.getxy();
var p=0; var p=0;
var scrolls=0; var scrolls=0;
...@@ -345,16 +379,18 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -345,16 +379,18 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
function (str, code, offset, s) { function (str, code, offset, s) {
return bbs.atcode(code); return bbs.atcode(code);
} }
); )
if(scroll && y==this.height) { if(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(); this.scroll();
y--; y--;
}; } else {
this.index++;
this.length++;
}
/* ToDo: Expand \1D, \1T, \1<, \1Z */ /* ToDo: Expand \1D, \1T, \1<, \1Z */
/* ToDo: "Expand" (ie: remove from string when appropriate) per-level/per-flag stuff */ /* ToDo: "Expand" (ie: remove from string when appropriate) per-level/per-flag stuff */
/* ToDo: Strip ANSI (I betcha @-codes can slap it in there) */ /* ToDo: Strip ANSI (I betcha @-codes can slap it in there) */
debug("placing text: " + txt);
while(p<txt.length && x<this.width && y<this.height) { while(p<txt.length && x<this.width && y<this.height) {
ch=txt.substr(p++,1); ch=txt.substr(p++,1);
switch(ch) { switch(ch) {
...@@ -444,12 +480,14 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -444,12 +480,14 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
x=0; x=0;
break; break;
case ']': /* LF */ case ']': /* LF */
if(p<txt.length-1) {
y++; y++;
if(scroll && y>=this.height) { while(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(); this.scroll();
y--; y--;
} }
}
break; break;
default: /* Other stuff... specifically, check for right movement */ default: /* Other stuff... specifically, check for right movement */
if(ch.charCodeAt(0)>127) { if(ch.charCodeAt(0)>127) {
...@@ -465,10 +503,9 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -465,10 +503,9 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
x=0; x=0;
break; break;
case '\n': case '\n':
if(this.lines<this.height) this.lines++;
if(p<txt.length-1) { if(p<txt.length-1) {
y++; y++;
if(scroll && y>=this.height) { while(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(); this.scroll();
y--; y--;
...@@ -476,13 +513,12 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -476,13 +513,12 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
} }
break; break;
default: default:
this.data[x][y].ch=ch; this.data[x][y]=new Graphic_sector(ch,curattr);
this.data[x][y].attr=curattr;
x++; x++;
if(x>=this.width) { if(x>=this.width) {
x=0; x=0;
y++; y++;
if(scroll && y>=this.height) { while(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(); this.scroll();
y--; y--;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment