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

add resize() method (destructive)

parent 41a0f79c
Branches
Tags
No related merge requests found
...@@ -24,12 +24,12 @@ function Graphic(w,h,attr,ch) ...@@ -24,12 +24,12 @@ function Graphic(w,h,attr,ch)
else else
this.width=w; this.width=w;
this.data=new Array(w);
this.scrollback=500; this.scrollback=500;
this.loop=false; this.loop=false;
this.length=0; this.length=0;
this.index=0; this.index=0;
this.data=new Array(w);
for(var y=0; y<this.height; y++) { for(var y=0; y<this.height; y++) {
for(var x=0; x<this.width; x++) { for(var x=0; x<this.width; x++) {
if(y==0) { if(y==0) {
...@@ -51,6 +51,7 @@ function Graphic(w,h,attr,ch) ...@@ -51,6 +51,7 @@ function Graphic(w,h,attr,ch)
this.write=Graphic_write; this.write=Graphic_write;
this.scroll=Graphic_scroll; this.scroll=Graphic_scroll;
this.putmsg=Graphic_putmsg; this.putmsg=Graphic_putmsg;
this.resize=Graphic_resize;
} }
function Graphic_sector(ch,attr) function Graphic_sector(ch,attr)
{ {
...@@ -137,8 +138,11 @@ function Graphic_drawslow(xpos,ypos,width,height,xoff,yoff) ...@@ -137,8 +138,11 @@ function Graphic_drawslow(xpos,ypos,width,height,xoff,yoff)
// Do not draw to the bottom left corner of the screen-would scroll // Do not draw to the bottom left corner of the screen-would scroll
if(xpos+x != console.screen_columns if(xpos+x != console.screen_columns
|| ypos+y != console.screen_rows) { || ypos+y != console.screen_rows) {
console.attributes=this.data[x+xoff][y+yoff].attr; console.attributes=this.data[x+xoff][this.index+y+yoff].attr;
console.write(this.data[x+xoff][y+yoff].ch); var ch=this.data[x+xoff][this.index+y+yoff].ch;
if(ch == "\r" || ch == "\n" || !ch)
ch=this.ch;
console.write(ch);
} }
mswait(2); mswait(2);
} }
...@@ -176,7 +180,7 @@ function Graphic_drawfx(xpos,ypos,width,height,xoff,yoff) ...@@ -176,7 +180,7 @@ function Graphic_drawfx(xpos,ypos,width,height,xoff,yoff)
placeholder[x]=new Array(height); placeholder[x]=new Array(height);
for(y=0;y<placeholder[x].length;y++) for(y=0;y<placeholder[x].length;y++)
{ {
placeholder[x][y]={'x':xoff+x,'y':yoff+y}; placeholder[x][y]={'x':xoff+x,'y':this.index+yoff+y};
} }
} }
while(placeholder.length) while(placeholder.length)
...@@ -188,7 +192,10 @@ function Graphic_drawfx(xpos,ypos,width,height,xoff,yoff) ...@@ -188,7 +192,10 @@ function Graphic_drawfx(xpos,ypos,width,height,xoff,yoff)
|| position.y != console.screen_rows) { || position.y != console.screen_rows) {
console.gotoxy(xpos+position.x,ypos+position.y); console.gotoxy(xpos+position.x,ypos+position.y);
console.attributes=this.data[position.x][position.y].attr; console.attributes=this.data[position.x][position.y].attr;
console.write(this.data[position.x][position.y].ch); var ch=this.data[position.x][position.y].ch;
if(ch == "\r" || ch == "\n" || !ch)
ch=this.ch;
console.write(ch);
mswait(1); mswait(1);
} }
placeholder[randx].splice(randy,1); placeholder[randx].splice(randy,1);
...@@ -238,7 +245,10 @@ function Graphic_write(filename) ...@@ -238,7 +245,10 @@ function Graphic_write(filename)
} }
function Graphic_end() function Graphic_end()
{ {
this.index=this.data[0].length-this.height; var newindex=this.data[0].length-this.height;
if(newindex == this.index) return false;
this.index=newindex;
return true;
} }
function Graphic_pgup() function Graphic_pgup()
{ {
...@@ -254,7 +264,9 @@ function Graphic_pgdn() ...@@ -254,7 +264,9 @@ function Graphic_pgdn()
} }
function Graphic_home() function Graphic_home()
{ {
if(this.index == 0) return false;
this.index=0; this.index=0;
return true;
} }
function Graphic_scroll(dir) function Graphic_scroll(dir)
{ {
...@@ -281,10 +293,23 @@ function Graphic_scroll(dir) ...@@ -281,10 +293,23 @@ function Graphic_scroll(dir)
this.length++; this.length++;
break; break;
} }
return true;
} }
function Graphic_resize(w,h) function Graphic_resize(w,h)
{ {
/* ToDo: Figure out this complicated bullshit */ this.data=new Array(w);
this.width=w;
this.height=h;
this.index=0;
this.length=0;
for(var y=0; y<h; y++) {
for(var x=0; x<w; x++) {
if(y==0) {
this.data[x]=new Array(h);
}
this.data[x][y]=new Graphic_sector(this.ch,this.attribute);
}
}
} }
/* 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)
...@@ -437,13 +462,9 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll) ...@@ -437,13 +462,9 @@ function Graphic_putmsg(xpos, ypos, txt, attr, scroll)
case '\7': /* Beep */ case '\7': /* Beep */
break; break;
case '\r': case '\r':
// ToDo: possibly retain \r\n data for resizing of graphic
//this.data[x][y]=new Graphic_sector(ch,curattr);
x=0; x=0;
break; break;
case '\n': case '\n':
// ToDo: possibly retain \r\n data for resizing of graphic
//this.data[x][y]=new Graphic_sector(ch,curattr);
this.length++; this.length++;
if(p<txt.length-1) { if(p<txt.length-1) {
y++; y++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment