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

Added: "slow draw" effect, scroll up,

scroll down, page down, page up,
home, end
parent c6ef8bef
No related branches found
No related tags found
No related merge requests found
...@@ -25,32 +25,85 @@ function Graphic(w,h,attr,ch) ...@@ -25,32 +25,85 @@ function Graphic(w,h,attr,ch)
this.width=w; this.width=w;
this.data=new Array(w); this.data=new Array(w);
this.past=new Array(w);
this.future=new Array(w);
this.lines=0;
var x; var x;
var y; var y;
for(y=0; y<this.height; y++) { for(y=0; y<this.height; y++) {
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
if(y==0) { if(y==0) {
this.data[x]=new Array(h); this.data[x]=new Array(h);
this.past[x]=[];
this.future[x]=[];
} }
this.data[x][y]=new Object; this.data[x][y]=new Graphic_sector(this.ch,this.attribute);
this.data[x][y].ch=ch;
this.data[x][y].attr=attr;
} }
} }
this.home=Graphic_home;
this.end=Graphic_end;
this.pgup=Graphic_pgup;
this.pgdn=Graphic_pgdn;
this.draw=Graphic_draw; this.draw=Graphic_draw;
this.drawfx=Graphic_drawfx; this.drawfx=Graphic_drawfx;
this.drawslow=Graphic_drawslow;
this.save=Graphic_save; this.save=Graphic_save;
this.load=Graphic_load; this.load=Graphic_load;
this.write=Graphic_write; this.write=Graphic_write;
this.scroll=Graphic_scroll; this.scroll=Graphic_scroll;
this.putmsg=Graphic_putmsg; this.putmsg=Graphic_putmsg;
} }
function Graphic_sector(ch,attr)
{
this.ch=ch;
this.attr=attr;
}
function Graphic_draw(xpos,ypos,width,height,xoff,yoff) function Graphic_draw(xpos,ypos,width,height,xoff,yoff)
{ {
var x; var x;
var y; var y;
if(xpos==undefined)
xpos=1;
if(ypos==undefined)
ypos=1;
if(width==undefined)
width=this.width;
if(height==undefined)
height=this.height;
if(xoff==undefined)
xoff=0;
if(yoff==undefined)
yoff=0;
if(xoff+width > this.width || yoff+height > this.height) {
alert("Attempt to draw from outside of graphic: "+xoff+":"+yoff+" "+width+"x"+height+" "+this.width+"x"+this.height);
return(false)
}
if(xpos+width-1 > console.screen_columns || ypos+height-1 > console.screen_rows) {
alert("Attempt to draw outside of screen");
return(false);
}
for(y=0;y<height; y++) {
console.gotoxy(xpos,ypos+y);
for(x=0; x<width; x++) {
// Do not draw to the bottom left corner of the screen-would scroll
if(xpos+x != console.screen_columns
|| ypos+y != console.screen_rows) {
console.attributes=this.data[x+xoff][y+yoff].attr;
var ch=this.data[x+xoff][y+yoff].ch;
console.write(ch?ch:this.ch);
}
}
}
return(true);
}
function Graphic_drawslow(xpos,ypos,width,height,xoff,yoff)
{
var x;
var y;
if(xpos==undefined) if(xpos==undefined)
xpos=1; xpos=1;
if(ypos==undefined) if(ypos==undefined)
...@@ -80,6 +133,7 @@ function Graphic_draw(xpos,ypos,width,height,xoff,yoff) ...@@ -80,6 +133,7 @@ function Graphic_draw(xpos,ypos,width,height,xoff,yoff)
console.attributes=this.data[x+xoff][y+yoff].attr; console.attributes=this.data[x+xoff][y+yoff].attr;
console.write(this.data[x+xoff][y+yoff].ch); console.write(this.data[x+xoff][y+yoff].ch);
} }
mswait(2);
} }
} }
return(true); return(true);
...@@ -157,7 +211,6 @@ function Graphic_load(filename) ...@@ -157,7 +211,6 @@ function Graphic_load(filename)
} }
return(true); return(true);
} }
function Graphic_write(xpos, ypos, txt, attr) function Graphic_write(xpos, ypos, txt, attr)
{ {
var x=xpos-1; var x=xpos-1;
...@@ -175,29 +228,75 @@ function Graphic_write(xpos, ypos, txt, attr) ...@@ -175,29 +228,75 @@ function Graphic_write(xpos, ypos, txt, attr)
} }
} }
} }
function Graphic_end()
function Graphic_scroll(lines)
{ {
var x; while(this.future[0].length) {
var y; for(x=0; x<this.width; x++) {
this.past[x].push(this.data[x].shift());
if(lines<1) /* Do not (yet... ToDo) allow negative scroll */ this.data[x].push(this.future[x].shift());
return; }
}
for(y=lines; y<this.height; y++) { }
function Graphic_pgup()
{
var line=0;
while(this.past[0].length && line<this.height) {
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
this.data[x][y-lines].ch=this.data[x][y].ch; this.future[x].unshift(this.data[x].pop());
this.data[x][y-lines].attr=this.data[x][y].attr; this.data[x].unshift(this.past[x].pop());
} }
line++;
} }
for(y=this.height-lines; y<this.height; y++) { }
function Graphic_pgdn()
{
var line=0;
while(this.future[0].length && line<this.height) {
for(x=0; x<this.width; x++) { for(x=0; x<this.width; x++) {
this.data[x][y].ch=this.ch; this.past[x].push(this.data[x].shift());
this.data[x][y].attr=this.attribute; this.data[x].push(this.future[x].shift());
} }
line++;
}
}
function Graphic_home()
{
while(this.past[0].length) {
for(x=0; x<this.width; x++) {
this.future[x].unshift(this.data[x].pop());
this.data[x].unshift(this.past[x].pop());
}
}
}
function Graphic_scroll(dir)
{
switch(dir)
{
case 1:
if(this.future[0].length>0) {
for(x=0; x<this.width; x++) {
this.past[x].push(this.data[x].shift());
this.data[x].push(this.future[x].shift());
}
}
break;
case -1:
if(this.past[0].length>0) {
for(x=0; x<this.width; x++) {
this.future[x].unshift(this.data[x].pop());
this.data[x].unshift(this.past[x].pop());
}
}
break;
default:
for(x=0; x<this.width; x++) {
this.past[x].push(this.data[x].shift());
this.data[x].push(new Graphic_sector(this.ch,this.attribute));
}
if(this.lines<this.height) this.lines++;
break;
} }
} }
/* Converts a text string to binary format and appends it to a file */ /* Converts a text string to binary format and appends it to a file */
function Graphic_save(file,txt) function Graphic_save(file,txt)
{ {
...@@ -227,14 +326,13 @@ function Graphic_save(file,txt) ...@@ -227,14 +326,13 @@ function Graphic_save(file,txt)
else alert("Incompatible data type"); else alert("Incompatible data type");
binFile.close(); binFile.close();
} }
/* Returns the number of times scrolled */ /* Returns the number of times scrolled */
function Graphic_putmsg(xpos, ypos, txt, attr, scroll) function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
{ {
var curattr=attr; var curattr=attr;
var ch; var ch;
var x=xpos-1; var x=xpos?xpos-1:0;
var y=ypos-1; var y=ypos?ypos-1:this.lines;
var p=0; var p=0;
var scrolls=0; var scrolls=0;
...@@ -248,10 +346,15 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -248,10 +346,15 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
return bbs.atcode(code); return bbs.atcode(code);
} }
); );
if(scroll && y==this.height) {
scrolls++;
this.scroll();
y--;
};
/* 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) {
...@@ -267,7 +370,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -267,7 +370,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
y++; y++;
if(scroll && y>=this.height) { if(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(1); this.scroll();
y--; y--;
} }
} }
...@@ -344,7 +447,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -344,7 +447,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
y++; y++;
if(scroll && y>=this.height) { if(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(1); this.scroll();
y--; y--;
} }
break; break;
...@@ -362,11 +465,14 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -362,11 +465,14 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
x=0; x=0;
break; break;
case '\n': case '\n':
y++; if(this.lines<this.height) this.lines++;
if(scroll && y>=this.height) { if(p<txt.length-1) {
scrolls++; y++;
this.scroll(1); if(scroll && y>=this.height) {
y--; scrolls++;
this.scroll();
y--;
}
} }
break; break;
default: default:
...@@ -378,7 +484,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -378,7 +484,7 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
y++; y++;
if(scroll && y>=this.height) { if(scroll && y>=this.height) {
scrolls++; scrolls++;
this.scroll(1); 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