home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / DOS_GUI.ZIP / DEMO.C < prev    next >
C/C++ Source or Header  |  1994-01-11  |  27KB  |  921 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* Copyright Plain Design Inc 1992,1993                                     */
  3. /*--------------------------------------------------------------------------*/
  4. /* Plain Design's Example program for the menu system  ; every available    */
  5. /* function has been demonstrated in this example.  Descriptions are        */
  6. /* available under the help facilities                                      */
  7. /* This is a shareware program; you may use this library to creat any       */
  8. /* program's free of charge.                                                */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*  Source Code price $29.00                                                */
  12. /*                                                                          */
  13. /*  Send inquiries to       :    Plain Design Inc.                          */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*--------------------------------------------------------------------------*/
  20. #include "gui.h"               /* required for use of the GR_MENU library   */
  21. #include "string.h"
  22. #include "stdio.h"
  23. #include "time.h"
  24. #include "dos.h"
  25. /*--------------------------------------------------------------------------*/
  26. /*                               PROTO TYPES                                */
  27. /*--------------------------------------------------------------------------*/
  28. int  show_window(int ,int ,int ,int ,char *,int );
  29. void one_button(char *,int ,int ,int ,int);
  30. void about(void);
  31. void ctxt(int ,char *,int );
  32. void alternate_menu_colors(void);
  33. void scroll_down_menu(void);
  34. void one_text_field(void);
  35. void five_text_fields(void);
  36. void one_binary_field(void);
  37. void five_binary_fields(void);
  38. void percent_bar(void);
  39. void scroll_bar_function(void);
  40. /*--------------------------------------------------------------------------*/
  41. /*                               Definitions                                */
  42. /*--------------------------------------------------------------------------*/
  43. #define TEST -10000
  44.  
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. /*-------------------------------*/
  48. /* FOR Borland   C COMPILER      */
  49. /*-------------------------------*/
  50. #ifdef BC
  51. extern unsigned _stklen=15000u;
  52. #endif
  53. /*-------------------------------*/
  54.  
  55.  
  56. void main(void)
  57. {
  58.   int  message;
  59.   int  break_loop=NO; // used to break out of a loop from a switch statement
  60.   int  h=-1;  // button handle
  61.   char button_string[20];
  62.   /*-----------------------------------------------------------*/
  63.   /* This library is designed for VGA 640X480X16 color display */
  64.   /* Mode must be changed to that first                        */
  65.   /*-----------------------------------------------------------*/
  66.   set_video_mode(18);
  67.   
  68.   /*--------------------------------------------------*/
  69.   /* to use this library you must initialize it first */
  70.   /*--------------------------------------------------*/
  71.   initdisplay();
  72.  
  73.   /*--------------------------------------------------*/
  74.   /* turn the mouse cursor on ;  this is important    */
  75.   /*--------------------------------------------------*/
  76.   show_mouse_cursor();
  77.  
  78.   /*---------------------------*/
  79.   /* paint the background gray */
  80.   /*---------------------------*/
  81.   gfillrect(0,0,639,479,8);
  82.  
  83.   /*--------------------------------------------------------------*/
  84.   /* to place a pull down menu, a menu file must be created first */
  85.   /* example 'MENUFILE' contains the format of this file          */
  86.   /* after creating it you must initialize it                     */
  87.   /*--------------------------------------------------------------*/
  88.   ch_menu_x(1);      /* default starts the menu bar at location 0 */
  89.   bar_menu(INIT);
  90.  
  91.   /*-----------------------------------------------------------*/
  92.   /* show the about dialog box in the beginning of the program */
  93.   /*-----------------------------------------------------------*/
  94.   about();
  95.  
  96.   /*-------------------------------------------------------------------*/
  97.   /* barmenu function will return the messages from the pull down menu */
  98.   /* and the keyboard; when pull down menu is invoked, barmenu takes   */
  99.   /* over the program.                                                 */
  100.   /*-------------------------------------------------------------------*/
  101.   while(1)      /* program's main message loop */
  102.   {
  103.     message=bar_menu(KEY_RETURN);
  104.     if(h!=-1)
  105.     {
  106.       message=check_button(message);
  107.     }
  108.  
  109.     switch(message)
  110.     {
  111.       case ESC:          /* exit the program */
  112.        break_loop=YES;
  113.        break;
  114. /*--------------------------------------------------------------------------*/
  115.       case 4005:   /* alternate menu colors    */
  116.        alternate_menu_colors();
  117.        break;
  118. /*--------------------------------------------------------------------------*/
  119.       case 4010:   /* Drawing a line           */
  120.        gr_line(20,20,300,300,4);
  121.        break;
  122. /*--------------------------------------------------------------------------*/
  123.       case 4020:   /* drawing an ellipse       */
  124.        ELLIPSE(320,200,50,70,3);
  125.        break;
  126. /*--------------------------------------------------------------------------*/
  127.       case 4030:   /* text mode rectangle      */
  128.        rect(10,10,20,20,0x4F);
  129.        break;
  130. /*--------------------------------------------------------------------------*/
  131.       case 4040:   /* graphics mode rectangle  */
  132.        grect(300,300,350,350,12);
  133.        break;
  134. /*--------------------------------------------------------------------------*/
  135.       case 4050:   /* text mode frect          */
  136.        frect(20,20,25,25,0x24,0);
  137.        break;
  138. /*--------------------------------------------------------------------------*/
  139.       case 4060:   /* graphics mode frect      */
  140.        gfillrect(220,220,320,330,13);
  141.        break;
  142. /*--------------------------------------------------------------------------*/
  143.       case 4070:   /* text write character     */
  144.        writechar(30,20,'X',0x24);
  145.        break;
  146. /*--------------------------------------------------------------------------*/
  147.       case 4080:   /* text write string        */
  148.        pls(30,21,"Text Write String",0x42);
  149.        break;
  150. /*--------------------------------------------------------------------------*/
  151.       case 4090:   /* graphics write character */
  152.        gwritechar(240,352,'Y',0x52);
  153.        break;
  154. /*--------------------------------------------------------------------------*/
  155.       case 4100:   /* graphics write string    */
  156.        gpls(240,368,"graphics write string",0x72);
  157.        break;
  158. /*--------------------------------------------------------------------------*/
  159.       case 4200:   /* scroll down menu         */
  160.        scroll_down_menu();
  161.        break;
  162. /*--------------------------------------------------------------------------*/
  163.       case 4210:   /* place 'test button       */
  164.        if(h!=-1)break; /* button is already placed */
  165.        strcpy(button_string,"^Test Button");
  166.        h=draw_button(button_string,65,28,strlen(button_string)*8+12,23,TEST,ALTT); /* show button */
  167.        break;
  168. /*--------------------------------------------------------------------------*/
  169.       case 4220:   /* remove 'test' button     */
  170.        if(h==-1) break;   /* cannot remove a button that does not exist */
  171.        disable_button2(h,8); /* disable_button2 will paint background to 8 */
  172.        h=-1;
  173.        break;
  174. /*--------------------------------------------------------------------------*/
  175.       case 4230:   /* place 1 text field       */
  176.        one_text_field();
  177.        break;
  178. /*--------------------------------------------------------------------------*/
  179.       case 4240:   /* place 3 text fields      */
  180.        five_text_fields();
  181.        break;
  182. /*--------------------------------------------------------------------------*/
  183.       case 4250:   /* place 1 binary field     */
  184.        one_binary_field();
  185.        break;
  186. /*--------------------------------------------------------------------------*/
  187.       case 4260:   /* place 3 binary fields    */
  188.        five_binary_fields();
  189.        break;
  190. /*--------------------------------------------------------------------------*/
  191.       case 4280:   /* percent display function */
  192.        percent_bar();
  193.        break;
  194. /*--------------------------------------------------------------------------*/
  195.       case 4290:   /* scroll bar function      */
  196.        scroll_bar_function();
  197.        break;
  198. /*--------------------------------------------------------------------------*/
  199.       case 4500:
  200.        help("Plain Design GUI Example Help","HELPFILE","How to Order Source Code"); 
  201.        break;
  202. /*--------------------------------------------------------------------------*/
  203.       case 5010:   /* help contents is invoked */
  204.        help("Plain Design GUI Example Help","HELPFILE","contents"); 
  205.        break;
  206. /*--------------------------------------------------------------------------*/
  207.       case 5020:   /* help on help  is invoked */
  208.        help("Plain Design GUI Example Help","HELPFILE","Help on Help"); 
  209.        break;
  210. /*--------------------------------------------------------------------------*/
  211.       case 5030:   /* about function */
  212.        about();
  213.        break;
  214. /*--------------------------------------------------------------------------*/
  215.       case TEST:
  216.        if(h==-1)break;
  217.        printf("\a");
  218.        pls(0,29,"Test Button was pressed",0x4F);
  219.        break;
  220.     }
  221.     if(break_loop==YES)break;
  222.   }
  223.  
  224.  
  225.   set_video_mode(3);   /* switch the video mode when done */
  226. }
  227. /*--------------------------------------------------------------------------*/
  228. void about(void)
  229. {
  230.   show_window(15,5,50,19,"About Demo",ON);
  231.  
  232.   ctxt(9,"GUI Library example program",0xF4);
  233.   ctxt(12,"Copyright Plain Design Inc.",0xF0);
  234.   ctxt(13,"1992 - 1994",0xF0);
  235.   ctxt(15,"GUI for DOS ",0xF8);
  236.   ctxt(16,"for C compilers  Borland,Microsoft,Powerc",0xF8);
  237.   ctxt(17,"This program demonstrates the capabilities of",0xF8);
  238.   ctxt(18,"Plain Design's GUI library tool kit",0xF8);
  239.  
  240.  
  241.   one_button("  OK  " ,36,21,ENTER,ESC);
  242.   show_window(15,10,50,15,"",OFF);
  243. }
  244. /*--------------------------------------------------------------------------*/
  245. /*                               show_window                                */
  246. /* x,y,xsize,ysize variables are in text mode ranges : 0 <=x<=79  0<=y<=29  */
  247. /* xsize and ysize are also in the same ranges.                             */
  248. /* each text block is 8*16 pixels.                                          */
  249. /* sw should be set to ON to display window and  OFF to remove it           */
  250. /*--------------------------------------------------------------------------*/
  251. int show_window(int x,int y,int xsize,int ysize,char *title,int sw)
  252.   static int wh;
  253.   int        i;
  254.  
  255.   switch(sw)
  256.   {    
  257.     case ON:
  258.      wh=messagebox(x,y,xsize,ysize,0xF0,0x08,YES);
  259.      grect(x*8+1,y*16+1,(x+xsize)*8-2,(y+ysize)*16-1,0);
  260.  
  261.      for(i=1;i<=5;i++)
  262.      {
  263.        grect(x*8+1+i,y*16+1+i,(x+xsize)*8-2-i,(y+ysize)*16-1-i,1);
  264.      }
  265.  
  266.      gfillrect(x*8+8,y*16+8,(x+xsize)*8-9,y*16+27,1);
  267.  
  268.      gpls( (x+(xsize/2)-strlen(title)/2)*8,(y+1)*16-5,title,0x1F);
  269.  
  270.      break;
  271.     case OFF:
  272.      destroy_messagebox(wh);
  273.      if(wh>0)wh--;
  274.      break;
  275.   }
  276.  
  277.   return wh;
  278. }
  279. /*--------------------------------------------------------------------------*/
  280. /* display button at x,y named 'string' activate button when key is pressed */
  281. /*--------------------------------------------------------------------------*/
  282. void one_button(char *string,int x,int y,int key,int acc)
  283. {
  284.  
  285.   int h;
  286.   int j,i;
  287.  
  288.   deactivate_activebuttons(); /* disable all other buttons */
  289.  
  290.   h=draw_button(string,x,y,strlen(string)*8+14,23,key,acc); /* show button */
  291.  
  292.   while(1)
  293.   {
  294.     j=getkey();
  295.     i=check_button(j);
  296.     gcurs(MOVE);
  297.  
  298.     if(i==key)break;
  299.   }
  300.  
  301.   disable_button(h);    /* remove button */
  302.  
  303.   reactivate_activebuttons();  /* reactivate all other buttons */
  304.  
  305. }
  306. /*--------------------------------------------------------------------------*/
  307. /* write text centered on the screen                                        */
  308. /*--------------------------------------------------------------------------*/
  309. void ctxt(int y,char *string,int color)
  310. {
  311.   gpls(320-strlen(string)*4,y*16,string,color);
  312. }
  313. /*--------------------------------------------------------------------------*/
  314. /* change the pull down menu colors                                         */
  315. /*--------------------------------------------------------------------------*/
  316. void alternate_menu_colors(void)
  317. {
  318.   bg_menu_color(BK_CYAN);              /* menu background to CYAN          */
  319.   fg_menu_color(FG_BLACK);             /* menu  forground to Black         */
  320.   bg_menu_hotkey_color(BK_CYAN);       /* Hotkey Back to CYAN              */
  321.   fg_menu_hotkey_color(FG_WHITE);      /* Hotkey Forground to Whit         */
  322.   bg_menu_sel_color(BK_BLUE);          /* Selected menu back to BLUE       */
  323.   fg_menu_sel_color(FG_BRIGHT_WHITE);  /* Selected menu forground to white */
  324.   bar_menu(DISPLAY);
  325. }
  326. /*--------------------------------------------------------------------------*/
  327. /* demonstrate a scroll down menu                                           */
  328. /*--------------------------------------------------------------------------*/
  329. void scroll_down_menu(void)
  330. {
  331.   char menu[20][40] ;        /* menu array                */
  332.   char buffer[30];
  333.   int  menu_ptr=4;
  334.  
  335.  
  336.   strcpy(menu[0]," Menu Entry Zero ");
  337.   strcpy(menu[1]," Menu Entry One ");
  338.   strcpy(menu[2]," Menu Entry Two   ");
  339.   strcpy(menu[3]," Menu Entry Three");
  340.   strcpy(menu[4]," Exit ");
  341.   
  342.   show_window(15,10,50,15,"Scroll Down Menu Demo",ON);
  343.  
  344.   while( (menu_ptr=menus(menu,5,20,13,0xF4,0x4F,menu_ptr,-1)) !=4)
  345.   {
  346.     if(menu_ptr < 0)continue;
  347.  
  348.     sprintf(buffer,"Menu item %d was selected   ",menu_ptr);
  349.     pls(16,22,buffer,0x2F);
  350.   }
  351.   show_window(15,10,50,15,"",OFF);
  352. }
  353. /*--------------------------------------------------------------------------*/
  354. void one_text_field(void)
  355. {
  356.  
  357.   int i;
  358.   char j;
  359.   int h1,h2;
  360.   char buffer[50];
  361.   struct xfield pf;
  362.  
  363.   show_window(20,7,40,9,"One Text Field",ON);
  364.  
  365.   pf.type=F_TEXT;              /* field types can be F_TEXT,F_DATE,F_TEL */
  366.   pf.xstart=0;                 /* first character for the cursor to show */
  367.   pf.f[0]=0;                   /* initial field content                  */
  368.   strcpy(pf.title,"Field");    /* field title                            */
  369.   pf.fcolor=0x70;              /* field color                            */
  370.   pf.tcolor=0xF4;              /* field title color                      */
  371.   pf.x=28;                     /* x location of field on the text screen */
  372.   pf.y=11;                     /* y location of field on the text screen */
  373.   pf.length=24;                /* field length in characters             */
  374.  
  375.   /*----------------------------------------------------------------------*/
  376.   /* alt control allows for alternate controls ; this way TAB will select */
  377.   /* buttons or fields besides the mouse                                  */
  378.   /*----------------------------------------------------------------------*/
  379.   alt_control(INIT,0);  // alt control must be initialized, before any field work
  380.  
  381.   i=text_field(&pf,INIT);
  382.  
  383.   deactivate_activebuttons();  
  384.  
  385.   h1=draw_button("^Continue",25,13,78,23,ALTC,ALTC);
  386.   h2=draw_button("Cancel",45,13,78,23,ESC,ESC  );
  387.  
  388.   check_button(TAB);   /* select the first button */
  389.  
  390.   while(1)
  391.   {
  392.     j=text_field(&pf,-2);
  393.     i=check_button(j);
  394.  
  395.     if ( i==ESC || i==ALTC)break;
  396.   }
  397.  
  398.   disable_button(h1);
  399.   disable_button(h2);
  400.  
  401.   reactivate_activebuttons();
  402.  
  403.   show_window(20,7,40,9,"One Text Field",OFF);
  404.   if(i==ALTC)
  405.   {
  406.     sprintf(buffer,"Field Content = %s",pf.f,0x4F);
  407.     pls(0,29,buffer,0x24);
  408.   }
  409.  
  410. }
  411. /*--------------------------------------------------------------------------*/
  412. void five_text_fields(void)
  413. {
  414. #ifdef MSC
  415.  struct dosdate_t date;
  416. #endif
  417.  
  418.   int    fret,fptr;
  419.  
  420.   struct  xfield pf[5];  
  421.   int    i;
  422.  
  423.  struct tm *time_now;
  424.  time_t secs_now;
  425.  int    break_val=NO;
  426.  int    h1,h2;
  427.  
  428.  show_window(20,6,40,13,"Five Text Field",ON);
  429.  
  430.  for(i=0;i<5;i++)
  431.  { pf[i].xstart=0;
  432.    strncpy(pf[i].f,"",sizeof(pf[i].f) );
  433.    pf[i].title[0]=0;
  434.    pf[i].fcolor=0x70;
  435.  }
  436.  
  437.  tzset();
  438.  time(&secs_now);
  439.  time_now=localtime(&secs_now);
  440.  
  441.  pf[0].type=F_DATE;
  442.  pf[0].x=27; pf[0].y=9; pf[0].length=8; pls(27,8,(unsigned char *)"Date1 :",0xF4);
  443.  
  444. #ifdef MSC
  445.  _dos_getdate(&date);
  446.  sprintf(pf[0].f,"%02d-%02d-%02d",date.month,date.day,date.year-1900);
  447. #else
  448.  strftime(pf[0].f,9,"%m-%d-%y",time_now);
  449. #endif
  450.  
  451.  pf[1].type=F_DATE;
  452.  pf[1].x=42; pf[1].y=9; pf[1].length=8; pls(42,8,(unsigned char *)"Date2 :",0xF4);
  453.  
  454. #ifdef MSC
  455.  _dos_getdate(&date);
  456.  sprintf(pf[1].f,"%02d-%02d-%02d",date.month,date.day,date.year-1900);
  457. #else
  458.  strftime(pf[1].f,9,"%m-%d-%y",time_now);
  459. #endif
  460.  
  461.  pf[2].type=F_TEXT;
  462.  pf[2].x=27; pf[2].y=11; pf[2].length=12; pls(27,10,(unsigned char *)"field 3 :",0xF4);
  463.  
  464.  pf[3].type=F_TEXT;
  465.  pf[3].x=42; pf[3].y=11; pf[3].length=11; pls(42,10,(unsigned char *)"field 4 :",0xF4);
  466.  
  467.  pf[4].type=F_TEXT;
  468.  pf[4].x=27; pf[4].y=13; pf[4].length=26; pls(27,12,(unsigned char *)"field 5 :",0xF4);
  469.  
  470.  alt_control(INIT,0);  // alt control must be initialized, before any field work
  471.  
  472.  for(i=0;i<5;i++)text_field(&pf[i],INIT);
  473.  
  474.  fptr=0;
  475.  
  476.  deactivate_activebuttons();
  477.  
  478.  
  479.  h1=draw_button("^Continue",26,16,78,23,ALTC,ALTC);
  480.  h2=draw_button("Cancel",44,16,78,23,ESC,ESC  );
  481.  
  482.  while(1)
  483.  { 
  484.    gcurs(MOVE);
  485.  
  486.    if(fptr!=-1)
  487.    {
  488.      i=text_field(&pf[fptr],-2);
  489.    }
  490.    else
  491.    {
  492.      i=getkey();
  493.    }
  494.  
  495.    fret=check_button(i);
  496.  
  497.    if(fptr==-1 && fret !=EOF)
  498.    {
  499.      fptr=0;
  500.    }
  501.  
  502.  
  503.    if(mouse_left_pressed()==YES)
  504.    {
  505.      get_mouse_location();
  506.      for(i=0;i<5;i++)
  507.      {
  508.        if(mouse_x>=pf[i].x && mouse_x<pf[i].x+pf[i].length && mouse_y==pf[i].y)
  509.        { 
  510.          fptr=i;
  511.          break;
  512.        }
  513.      }
  514.  
  515.    }
  516.  
  517.  
  518.    switch(fret)
  519.    {
  520.      case TAB   :
  521.       fptr++;
  522.       if(fptr>=5)
  523.       {
  524.         fptr=-1;
  525.         check_button(CONTROL);
  526.         check_button(TAB);
  527.       }
  528.       break;
  529.      case ENTER :
  530.      case RIGHTKEY :
  531.      case DOWNKEY  :
  532.       if(fptr==4 && fret==ENTER)
  533.       { break_val=YES;
  534.         break;
  535.       }
  536.       fptr++;
  537.       if(fptr>=5)fptr=0;
  538.       break;
  539.      case SHIFTTAB:
  540.      case UPKEY   :
  541.       fptr--;
  542.       if(fptr<0)fptr=4;
  543.       break;
  544.      case ESC :
  545.       disable_button(h1);
  546.       disable_button(h2);
  547.       reactivate_activebuttons();
  548.       show_window(20,6,40,13,"Three Text Field",OFF);
  549.       return;
  550.      case ALTC :
  551.       break_val=YES;
  552.       break;
  553.  
  554.    }
  555.    if(break_val==YES)break;
  556.  }
  557.  
  558.  disable_button(h1);
  559.  disable_button(h2);
  560.  
  561.  reactivate_activebuttons();
  562.  
  563.  show_window(20,6,40,13,"Three Text Field",OFF);
  564.  
  565.  pls(0,20,"Field Contents :",0x4F);
  566.  pls(0,22,pf[0].f,0x42);
  567.  pls(0,23,pf[1].f,0x42);
  568.  pls(0,24,pf[2].f,0x42);
  569.  pls(0,25,pf[3].f,0x42);
  570.  pls(0,26,pf[4].f,0x42);
  571.  
  572. }
  573. /*--------------------------------------------------------------------------*/
  574. /* place one binary field; use TAB to select fields with keyboard           */
  575. /*--------------------------------------------------------------------------*/
  576. void one_binary_field(void)
  577. {
  578.  
  579.   struct bfield bfield;
  580.   int           i;
  581.   int           fptr=0;
  582.   int           fret;
  583.   int           h1,h2;
  584.   int           break_loop=NO;
  585.  
  586.  
  587.  
  588.   bfield.fcolor=0xF7;
  589.   bfield.tcolor=0xF0;
  590.   bfield.x=25;
  591.   bfield.y=11;
  592.   bfield.content=NO;
  593.  
  594.   strcpy(bfield.title,"Binary Field");
  595.  
  596.  
  597.   show_window(20,7,40,10,"One Binary Field",ON);
  598.  
  599.   deactivate_activebuttons();
  600.  
  601.   h1=draw_button("^Continue",1206,14,84,23,ALTC,ALTC);
  602.   h2=draw_button("Cancel"  ,1350,14,84,23,ESC,ESC  );
  603.  
  604.   binary_field(&bfield,INIT,-1);
  605.  
  606.   while(1)
  607.   {
  608.     gcurs(MOVE);
  609.  
  610.     if(fptr!=-1) /* when fptr==-1 buttons have been selected */
  611.                  /* otherwise, binary field is selected      */
  612.     {
  613.       i=binary_field(&bfield,-2,-1);
  614.     }
  615.     else
  616.     {
  617.       i=getkey();
  618.     }
  619.  
  620.     fret=check_button(i);
  621.     
  622.     if(fptr==-1 && fret!=EOF)
  623.     {
  624.       fptr=0;
  625.     }
  626.  
  627.     switch(fret)
  628.     {
  629.       case ALTC:
  630.        break_loop=YES;
  631.        break;
  632.       case ESC:
  633.        break_loop=YES;
  634.        break;
  635.  
  636.     }
  637.  
  638.     if(break_loop==YES)break;
  639.   }
  640.  
  641.   disable_button2(h1,15);
  642.   disable_button2(h2,15);
  643.   reactivate_activebuttons();
  644.  
  645.   show_window(20,7,40,10,"One Binary Field",OFF);
  646.  
  647.   if(fret==ALTC)
  648.   {
  649.     if(bfield.content==YES)pls(0,20,"One Binary Field is Set     ",0xF4);
  650.     else                   pls(0,20,"One Binary Field is not Set ",0xF4);
  651.   }
  652.  
  653. }
  654. /*--------------------------------------------------------------------------*/
  655. void five_binary_fields(void)
  656. {
  657.   int           i;
  658.   int           break_loop=NO;
  659.   int           fptr=0;
  660.   int           fret;
  661.   int           h1,h2;
  662.   char          buffer[50];
  663.   struct bfield bfield[5];
  664.  
  665.  
  666.  
  667.   /*--------------------------*/
  668.   /* show a message box first */
  669.   /*--------------------------*/
  670.  
  671.   show_window(20,7,40,10,"Five Binary Fields",ON);
  672.  
  673.   bfield[0].x=22;
  674.   bfield[0].y=10;
  675.   strcpy(bfield[0].title," field zero");
  676.  
  677.   bfield[1].x=22;
  678.   bfield[1].y=11;
  679.   strcpy(bfield[1].title," field one");
  680.  
  681.   bfield[2].x=22;
  682.   bfield[2].y=12;
  683.   strcpy(bfield[2].title," field two");
  684.  
  685.   bfield[3].x=22;
  686.   bfield[3].y=13;
  687.   strcpy(bfield[3].title," field three");
  688.  
  689.   bfield[4].x=22;
  690.   bfield[4].y=14;
  691.   strcpy(bfield[4].title," field four");
  692.  
  693.  
  694.   for(i=0;i<=4;i++)
  695.   {
  696.     bfield[i].fcolor=0xF7;
  697.     bfield[i].tcolor=0xF0;
  698.     if(fptr!=i)bfield[i].content=NO;
  699.     else       bfield[i].content=YES;
  700.     binary_field(&bfield[i],INIT,-1);
  701.   }
  702.  
  703.  
  704.   deactivate_activebuttons();
  705.  
  706.   h1=draw_button("^Continue",  47,10,84,21,ALTC,ALTC);
  707.   h2=draw_button("Cancel",     47,12,84,21,ESC,ESC  );
  708.  
  709.   while(1)
  710.   {
  711.     gcurs(MOVE);
  712.  
  713.     if(fptr!=-1)
  714.     {
  715.       i=binary_field(&bfield[fptr],-2,-1);
  716.     }
  717.     else
  718.     {
  719.       i=getkey();
  720.     }
  721.  
  722.     fret=check_button(i);
  723.     
  724.     if(fptr==-1 && fret!=EOF)
  725.     {
  726.       fptr=0;
  727.     }
  728.  
  729.     
  730.     /*----------------------------------------*/
  731.     /* if this field is set, reset the reset  */
  732.     /*----------------------------------------*/
  733.  
  734.     for(i=0;i<=4;i++)
  735.     {
  736.       if(bfield[fptr].content==YES)
  737.       {
  738.         for(i=0;i<=4;i++)
  739.         { 
  740.           if(bfield[i].content==YES)
  741.           { if(i==fptr)continue;
  742.             bfield[i].content=NO;
  743.             binary_field(&bfield[i],INIT,-1);
  744.           }
  745.         }
  746.       }
  747.       else
  748.       {
  749.         break;
  750.       }
  751.     }
  752.  
  753.     mouse_state();
  754.     if(ms==PRESSED)
  755.     {
  756.       get_mouse_location();
  757. /*-------------------------------------------------------------------------*/
  758. /* the following loop will reset any field that is set after another field */
  759. /* is set.  This is necessary when only one field can be set at a time.    */
  760. /* if multiple fields can be set, remove the following loop                */
  761. /*-------------------------------------------------------------------------*/
  762.       for(i=0;i<=4;i++)
  763.       {
  764.         if(bfield[i].y==mouse_y && 
  765.                         mouse_x>=bfield[i].x && mouse_x<=bfield[i].x+2)
  766.         {
  767.           if(i!=fptr)
  768.           {
  769.             fptr=i;
  770.             binary_field(&bfield[i],INIT,-1);
  771.           }
  772.           break;
  773.         }
  774.       }  
  775.     }     
  776.  
  777.  
  778.  
  779.     switch(fret)
  780.     {
  781.       case ALTC:  // save the hcopy type
  782.  
  783.        break_loop=YES;
  784.        break;
  785.       case ESC:
  786.        break_loop=YES;
  787.        break;
  788.  
  789.       case TAB:
  790.        fptr++;
  791.        if(fptr>4)
  792.        {  
  793.          fptr=-1;
  794.          check_button(CONTROL);
  795.          check_button(TAB);
  796.        }
  797.        break;
  798.  
  799.       case SHIFTTAB:
  800.        fptr--;
  801.        if(fptr<0)fptr=4;
  802.        break;
  803.  
  804.     }
  805.  
  806.     if(break_loop==YES)break;
  807.   }
  808.  
  809.  
  810.   disable_button(h1);
  811.   disable_button(h2);
  812.  
  813.   show_window(20,7,40,10,"",OFF);
  814.  
  815.   reactivate_activebuttons();
  816.  
  817.   if(fret==ALTC)
  818.   {
  819.     strcpy(buffer,"No Field was selected    ");
  820.  
  821.     for(i=0;i<5;i++)
  822.     {
  823.       if(bfield[i].content==YES)
  824.       {
  825.         sprintf(buffer,"Field %d was selected",i);
  826.       }
  827.     }
  828.     pls(0,20,buffer,0xF2);
  829.   }
  830.  
  831. }
  832. /*--------------------------------------------------------------------------*/
  833. /* this function displays percentage of two numbers numerator, and          */
  834. /* denominator.  Whitin any loop as a number changes, the bar will change   */
  835. /* also, as a percentage of the two numbers.                                */
  836. /*--------------------------------------------------------------------------*/
  837. void percent_bar(void)
  838. {
  839.   int numerator=0;
  840.   int denominator=20000;
  841.  
  842.   show_window(20,7,40,10,"Percent Display Bar",ON);
  843.  
  844.   /*----------------------------------------------------------------*/
  845.   /* it is important that the first time show_percent_bar is called */
  846.   /* the numerator to be 0                                          */
  847.   /*----------------------------------------------------------------*/
  848.   while(1)
  849.   {
  850.     if(show_percent_bar(numerator,denominator,190,185,252,30,0,1,15)==-1) 
  851.     {
  852.       /*-------------------------*/
  853.       /* cancel has been pressed */
  854.       /* or ESC key pressed.     */
  855.       /*-------------------------*/
  856.       break;
  857.     }
  858.     if(numerator==denominator)break;
  859.     numerator++;
  860.   }
  861.  
  862.   show_percent_bar(-1,0,190,185,252,30,0,1,15);
  863.  
  864.   show_window(20,7,40,10,"",OFF);
  865. }
  866. /*--------------------------------------------------------------------------*/
  867. void scroll_bar_function(void)
  868. {
  869.   int maxnum=500;
  870.   int num=0;
  871.   int old_num=num;
  872.   int x1=420;
  873.   int y1=136;
  874.   int x2=439;
  875.   int y2=337;
  876.   int border_color=0;
  877.   int bar_color=7;
  878.   int ch;
  879.   int h1;
  880.   int h2;
  881.   char buffer[40];
  882.  
  883.  
  884.   show_window(15,5,50,19,"Scroll Bar Demo",ON);
  885.   scr_bar(INIT,0,maxnum,&num,x1,y1,x2,y2,border_color,bar_color,0);
  886.  
  887.   sprintf(buffer,"num=%d out of %d  ",num,maxnum);
  888.   gpls(200,200,buffer,0xF2);
  889.  
  890.   h1=draw_button(" Exit ",36,21,60,23,ESC,ENTER);
  891.   h2=draw_button("^Set Bar to 333",19,8,120,23,ALTS,'s');
  892.  
  893.   while(1)
  894.   {
  895.     ch=getkey();
  896.     ch=check_button(ch);
  897.  
  898.     ch=scr_bar(ACTION,ch,maxnum,&num,x1,y1,x2,y2,border_color,bar_color,0);
  899.  
  900.     if(num!=old_num)
  901.     {
  902.       sprintf(buffer,"num=%d out of %d  ",num,maxnum);
  903.       gpls(200,200,buffer,0xF2);
  904.       old_num=num;
  905.     }
  906.  
  907.     if(ch==ESC)break;
  908.     if(ch==ALTS)
  909.     {
  910.       num=333;
  911.     }
  912.   }
  913.  
  914.   disable_button(h1);
  915.   disable_button(h2);
  916.  
  917.   show_window(15,5,50,19,"",OFF);
  918. }
  919. /*--------------------------------------------------------------------------*/
  920.