// BtnDemo
include "BtnLib"
string day[7],mode[3];
int week;

initButtons()
{
  btnCreateBitmap(
"09000000000000000080000000000000000",1,148, 0x381);
  btnCreateBitmap(
"09000000000000000550000000000000000",-1,-1,0x81);
  btnCreateBitmap(
"09000000550000550000550000550000000",-1,-1, 0x81);
  btnCreate("WWW",36,147,25,2);
  btnCreate("About",67,-1,29,5);
  btnCreate("Quit",-1,-1,24,5);
  btnCreateBitmap(
"0b0000100300700f01f03f01f00f0070030010000",67,0,0);
  btnCreate("M",-1,1,-1,0x281);
  btnCreate("T",-1,-1,-1,0x81);
  btnCreate("W",-1,-1,-1,0x81);
  btnCreate("T",-1,-1,-1,0x181);
  btnCreate("F",-1,-1,-1,0x81);
  btnCreate("S",-1,-1,-1,0x81);
  btnCreate("S",-1,-1,-1,0x81);
  btnCreateBitmap(
"0b0001001801c01e01f01f81f01e01c0180100000",-1,0,0);
  btnCreateCheck(37,38,8);
  btnCreateCheck(37,50,8);
  btnCreateCheck(37,62,8);
}

initStrings()
{
  day[0]="Monday       ";
  day[1]="Tuesday       ";
  day[2]="Wednesday";
  day[3]="Thursday    ";
  day[4]="Friday           ";
  day[5]="Saturday     ";
  day[6]="Sunday         ";
  mode[0]="Day     ";
  mode[1]="Week  ";
  mode[2]="Month";
}

paint()
{
  text(50,38,
    "Week "+(week+1)+"  ");
  text(50,50,day[btnSelected(8)-8]);
  text(50,62,
    mode[btnSelected(1)-1]);
  btnPaintAll();
}

command(int c)
{
  string s;
  if(c==4)
  {
    s=gets("Enter value:");
    if(s)
      btnSetLabel(4,strleft(s,3));
    paint();
  }
  else if(c==5)
  {
    alert("BtnDemo 1.1\n\nThis program was devoloped using\nThomas Rfer's BtnLib.");
    paint();
  }
  else if(c==7)
  {
    week=(week+51)%52;
    text(50,38,
      "Week "+(week+1)+"  ");
  }
  else if(c==15)
  {
    week=(week+1)%52;
    text(50,38,
      "Week "+(week+1)+"  ");
  }
  else if(c>15&&c<19)
    btnHide(c-12,!btnChecked(c));
  else if(c>7&&c<15)
    text(50,50,day[c-8]);
  else if(c<4)
    text(50,62,mode[c-1]);
}

main()
{
  int b;
  clear();
  puts("Initializing...");
  initButtons();
  initStrings();
  graph_on();
  title("BtnDemo");
  paint();
  while(btnPressed()!=6)
  {
    btnEvent(event(1));
    if(b=btnPressed())
      command(b);
  }
  graph_off();
}