Skip to content
Snippets Groups Projects
Commit 56878033 authored by deuce's avatar deuce
Browse files

Add (untested) disabled property to each item object.

parent fd3932cd
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,8 @@ if(this.SYS_CLOSED==undefined) ...@@ -26,6 +26,8 @@ if(this.SYS_CLOSED==undefined)
* bg: Background colour of a non-current item * bg: Background colour of a non-current item
* hfg: Foreground colour of a current item * hfg: Foreground colour of a current item
* hbg: Background colour of a current item * hbg: Background colour of a current item
* dfg: Foreground colour of a disabled item
* dbg: Background colour of a disabled item
* kfg: Hotkey forground colour for non-current item * kfg: Hotkey forground colour for non-current item
* khfg: Hotkey foreground colour for current item * khfg: Hotkey foreground colour for current item
* current: Index of currently highlighted item * current: Index of currently highlighted item
...@@ -49,6 +51,8 @@ function Lightbar(items) ...@@ -49,6 +51,8 @@ function Lightbar(items)
this.direction=0; this.direction=0;
this.hfg=1; this.hfg=1;
this.hbg=7; this.hbg=7;
this.hfg=8;
this.hbg=1;
this.kfg=15; this.kfg=15;
this.khfg=15; this.khfg=15;
this.current=0; this.current=0;
...@@ -69,7 +73,7 @@ function Lightbar(items) ...@@ -69,7 +73,7 @@ function Lightbar(items)
this.items=items; this.items=items;
} }
function Lightbar_additem(txt, retval, width, lpadding, rpadding) function Lightbar_additem(txt, retval, width, lpadding, rpadding, disabled)
{ {
var item=new Object; var item=new Object;
...@@ -86,6 +90,8 @@ function Lightbar_additem(txt, retval, width, lpadding, rpadding) ...@@ -86,6 +90,8 @@ function Lightbar_additem(txt, retval, width, lpadding, rpadding)
item.lpadding=lpadding; item.lpadding=lpadding;
if(rpadding!=undefined) if(rpadding!=undefined)
item.rpadding=rpadding; item.rpadding=rpadding;
if(disabled!=undefined)
item.disabled=disabled;
this.items.push(item); this.items.push(item);
} }
...@@ -122,6 +128,7 @@ function Lightbar_getval(current) ...@@ -122,6 +128,7 @@ function Lightbar_getval(current)
{ {
var attr=this.bg<<4|this.fg; var attr=this.bg<<4|this.fg;
var cattr=this.hbg<<4|this.hfg; var cattr=this.hbg<<4|this.hfg;
var dattr=this.dbg<<4|this.dfg;
var kattr=this.bg<<4|this.kfg; var kattr=this.bg<<4|this.kfg;
var kcattr=this.hbg<<4|this.khfg; var kcattr=this.hbg<<4|this.khfg;
var ret=undefined; var ret=undefined;
...@@ -155,7 +162,7 @@ function Lightbar_getval(current) ...@@ -155,7 +162,7 @@ function Lightbar_getval(current)
return(null); return(null);
} }
var orig_cur=this.current; var orig_cur=this.current;
while(this.items[this.current].retval==undefined) { while(this.items[this.current].retval==undefined || this.items[this.current].disabled) {
this.current++; this.current++;
if(this.current==this.items.length) if(this.current==this.items.length)
this.current=0; this.current=0;
...@@ -250,16 +257,24 @@ function Lightbar_getval(current) ...@@ -250,16 +257,24 @@ function Lightbar_getval(current)
if(this.align==1) { if(this.align==1) {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
for(;k<width-cleaned.length;k++) for(;k<width-cleaned.length;k++)
console.write(' '); console.write(' ');
} }
if(this.align==2) { if(this.align==2) {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
for(;k<(width-cleaned.length)/2;k++) for(;k<(width-cleaned.length)/2;k++)
console.write(' '); console.write(' ');
} }
...@@ -268,25 +283,35 @@ function Lightbar_getval(current) ...@@ -268,25 +283,35 @@ function Lightbar_getval(current)
if(width > -1 && k > width) if(width > -1 && k > width)
break; break;
if(this.items[i].text.substr(j,1)=='|') { if(this.items[i].text.substr(j,1)=='|') {
if(!this.items[i].disabled) {
if(this.current==i) if(this.current==i)
console.attributes=kcattr; console.attributes=kcattr;
else else
console.attributes=kattr; console.attributes=kattr;
}
j++; j++;
} }
else { else {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
} }
}
console.write(this.items[i].text.substr(j,1)); console.write(this.items[i].text.substr(j,1));
k++; k++;
} }
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
while(k<width) { while(k<width) {
console.write(" "); console.write(" ");
k++; k++;
...@@ -324,7 +349,7 @@ function Lightbar_getval(current) ...@@ -324,7 +349,7 @@ function Lightbar_getval(current)
if(this.current==0) if(this.current==0)
this.current=this.items.length; this.current=this.items.length;
this.current--; this.current--;
} while(this.items[this.current].retval==undefined); } while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined);
} }
break; break;
case KEY_DOWN: case KEY_DOWN:
...@@ -333,7 +358,7 @@ function Lightbar_getval(current) ...@@ -333,7 +358,7 @@ function Lightbar_getval(current)
this.current++; this.current++;
if(this.current==this.items.length) if(this.current==this.items.length)
this.current=0; this.current=0;
} while(this.items[this.current].retval==undefined); } while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined);
} }
break; break;
case KEY_LEFT: case KEY_LEFT:
...@@ -342,7 +367,7 @@ function Lightbar_getval(current) ...@@ -342,7 +367,7 @@ function Lightbar_getval(current)
if(this.current==0) if(this.current==0)
this.current=this.items.length; this.current=this.items.length;
this.current--; this.current--;
} while(this.items[this.current].retval==undefined); } while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined);
} }
break; break;
case KEY_RIGHT: case KEY_RIGHT:
...@@ -351,12 +376,12 @@ function Lightbar_getval(current) ...@@ -351,12 +376,12 @@ function Lightbar_getval(current)
this.current++; this.current++;
if(this.current==this.items.length) if(this.current==this.items.length)
this.current=0; this.current=0;
} while(this.items[this.current].retval==undefined); } while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined);
} }
break; break;
case KEY_HOME: case KEY_HOME:
this.current=0; this.current=0;
while(this.items[this.current].retval==undefined) { while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined) {
this.current++; this.current++;
if(this.current==this.items.length) if(this.current==this.items.length)
this.current=0; this.current=0;
...@@ -364,7 +389,7 @@ function Lightbar_getval(current) ...@@ -364,7 +389,7 @@ function Lightbar_getval(current)
break; break;
case KEY_END: case KEY_END:
this.current=this.items.length-1; this.current=this.items.length-1;
while(this.items[this.current].retval==undefined) { while(this.items[this.current]!=disabled || this.items[this.current].retval==undefined) {
if(this.current==0) if(this.current==0)
this.current=this.items.length; this.current=this.items.length;
this.current--; this.current--;
...@@ -378,7 +403,7 @@ function Lightbar_getval(current) ...@@ -378,7 +403,7 @@ function Lightbar_getval(current)
break; break;
default: default:
for(i=0; i<this.items.length; i++) { for(i=0; i<this.items.length; i++) {
if(this.items[i].text.indexOf('|'+key)!=-1 || this.items[i].text.indexOf('|'+key.toLowerCase())!=-1) { if((!this.items[i].disabled) && (this.items[i].text.indexOf('|'+key)!=-1 || this.items[i].text.indexOf('|'+key.toLowerCase())!=-1)) {
if(this.items[i].retval==undefined) if(this.items[i].retval==undefined)
continue; continue;
this.current=i; this.current=i;
...@@ -396,6 +421,7 @@ function Lightbar_draw(current) ...@@ -396,6 +421,7 @@ function Lightbar_draw(current)
{ {
var attr=this.bg<<4|this.fg; var attr=this.bg<<4|this.fg;
var cattr=this.hbg<<4|this.hfg; var cattr=this.hbg<<4|this.hfg;
var dattr=this.dbg<<4|this.dfg;
var kattr=this.bg<<4|this.kfg; var kattr=this.bg<<4|this.kfg;
var kcattr=this.hbg<<4|this.khfg; var kcattr=this.hbg<<4|this.khfg;
var ret=undefined; var ret=undefined;
...@@ -428,7 +454,7 @@ function Lightbar_draw(current) ...@@ -428,7 +454,7 @@ function Lightbar_draw(current)
return; return;
} }
var orig_cur=this.current; var orig_cur=this.current;
while(this.items[this.current].retval==undefined) { while(this.items[this.current].retval==undefined || this.items[this.current].disabled) {
this.current++; this.current++;
if(this.current==this.items.length) if(this.current==this.items.length)
this.current=0; this.current=0;
...@@ -519,16 +545,24 @@ function Lightbar_draw(current) ...@@ -519,16 +545,24 @@ function Lightbar_draw(current)
if(this.align==1) { if(this.align==1) {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
for(;k<width-cleaned.length;k++) for(;k<width-cleaned.length;k++)
console.write(' '); console.write(' ');
} }
if(this.align==2) { if(this.align==2) {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
for(;k<(width-cleaned.length)/2;k++) for(;k<(width-cleaned.length)/2;k++)
console.write(' '); console.write(' ');
} }
...@@ -537,25 +571,35 @@ function Lightbar_draw(current) ...@@ -537,25 +571,35 @@ function Lightbar_draw(current)
if(width > -1 && k > width) if(width > -1 && k > width)
break; break;
if(this.items[i].text.substr(j,1)=='|') { if(this.items[i].text.substr(j,1)=='|') {
if(!this.items[i].disabled) {
if(this.current==i) if(this.current==i)
console.attributes=kcattr; console.attributes=kcattr;
else else
console.attributes=kattr; console.attributes=kattr;
}
j++; j++;
} }
else { else {
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
} }
}
console.write(this.items[i].text.substr(j,1)); console.write(this.items[i].text.substr(j,1));
k++; k++;
} }
if(this.current==i) if(this.current==i)
console.attributes=cattr; console.attributes=cattr;
else {
if(this.items[i].disabled)
console.attributes=dattr;
else else
console.attributes=attr; console.attributes=attr;
}
while(k<width) { while(k<width) {
console.write(" "); console.write(" ");
k++; k++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment