/*
   This program may be freely
  distributed , copied,and modified so long
as a fee is not charged. However,
I reserve all rights available to
me under The Copyright Act.
If you find any bugs please feel free to contact me.
  David DeGeorge
  Princeton,New Jersey
  March 1987

USENET:  ....princeton!idacrd!dld
COMPUSERVE: 74176,3210
GENIE: DEGEORGE
*/

#ifdef GEM     /* if not defined compiles into nothing */
#include "makersh.h"
#include <vdibind.h>
#include <aesbind.h>
#include <osbind.h>

static *labels[]={
	"strings   ",
	"objects   ",
	"images    ",
	"bitblocks ",
	"iconblks  ",
	"tedinfos  ",
	"trees     ",
	"free strgs",
	"free imgs "
};
#define NITEM 9
typedef struct ditem {
	char *label;
	GRECT rect;
	int  *nptr;
} ITEM;
ITEM items[NITEM];

#define XOFFSET  (2*8 +  2)
#define YOFFSET  (3*8 +  1)
#define WIDTH  60*8     
#define SPACE  1*8
#define HITE   1*8

static int lenstrs;
static int lenimg;
makeitems()
{      
        int i;
        lenstrs = rheader.rsh_imdata - rheader.rsh_string; 
        lenimg =  rheader.rsh_nbb + 2*(rheader.rsh_nib);
        items[0].nptr  = &lenstrs;
	items[1].nptr  = &rheader.rsh_nobs;
	items[2].nptr  = &lenimg;
        items[3].nptr  = &rheader.rsh_nbb;
        items[4].nptr  = &rheader.rsh_nib;
        items[5].nptr  = &rheader.rsh_nted;
        items[6].nptr  = &rheader.rsh_ntree;
        items[7].nptr  = &rheader.rsh_nstring;
        items[8].nptr  = &rheader.rsh_nimages;
        for ( i = 0 ; i < NITEM ; i++)items[i].label = labels[i];
        for ( i = 0 ; i < NITEM ; i++) {
           items[i].rect.g_x = XOFFSET + 8*(strlen(items[i].label)+1);
           items[i].rect.g_y = YOFFSET + i*(HITE + SPACE) ;
           items[i].rect.g_w = WIDTH;
           items[i].rect.g_h = HITE;
        }
}
        
 display()
 { 
       int i,hin,vin ;
       int pxy[4];
       v_hide_c(handle);
       v_clrwk(handle);
       hin = 0;
       vin = 3;
       vst_alignment(handle,hin,vin,&i,&i);
       pxy[0] = 8;
       pxy[1] = 8;
       pxy[2]= 631;
       pxy[3] = 191;
       vsf_perimeter(handle,1);
       vsf_interior(handle,2);
       vsf_style(handle,IP_1PATT);
       vsf_color(handle,GREEN);
       v_bar(handle,pxy);
       vsf_interior(handle,IP_HOLLOW);
       vsf_color(handle,RED);
       vst_color(handle,BLACK);
       for ( i = 0 ; i < NITEM ; i++ ) {
         char temp[80];int pxy[4];int t1;
         if( *(items[i].nptr) == 0)
                      vst_effects(handle,2); /* shadowed */
              else
                     vst_effects(handle,0);
         
         t1 = items[i].rect.g_y+items[i].rect.g_h;
         vswr_mode(handle,2);
         v_gtext(handle,XOFFSET,t1,items[i].label);	 
         vswr_mode(handle,1);         	
        vsf_interior(handle,2);
        vsf_style(handle,22);
        vsf_color(handle,GREEN);
         pxy[0] = items[i].rect.g_x;
         pxy[1] = items[i].rect.g_y;
         pxy[2] = items[i].rect.g_x + items[i].rect.g_w;
         pxy[3] = items[i].rect.g_y + items[i].rect.g_h;
         v_bar(handle,pxy);
         sprintf(temp,"%d",*(items[i].nptr));
         vswr_mode(handle,2);         
        v_gtext(handle,pxy[2] + 8,t1,temp);
         vswr_mode(handle,1);         
        
       }
}

progress(i,num)
int i ;     /* item number */
int num;
{
      int todo,pxy[4];	
      long  inc ;    
 
              pxy[0] = items[i].rect.g_x;
              pxy[1] = items[i].rect.g_y;
              pxy[3] = pxy[1] + items[i].rect.g_h;
              todo  = *(items[i].nptr);
              inc = ( WIDTH  * (long)num)/(long)todo;  
              pxy[2] = pxy[0] + (int)inc;
              vsf_perimeter(handle,0);
              vsf_color(handle,RED);
              vsf_interior(handle,2);
              vsf_style(handle,3);
              v_bar(handle,pxy);              
}

imgprog(num)  /* This is special because non free images are made
               at various places */
int num;
{        
        int  pxy[4];
        int todo,inc;
           
               pxy[0] = items[2].rect.g_x;
               pxy[1] = items[2].rect.g_y;
               pxy[3] = pxy[1] +  items[2].rect.g_h;
               todo  = *(items[2].nptr) ;
               inc =  (WIDTH * num)/todo;        
               pxy[2] = pxy[0] + inc;
               vsf_color(handle,RED);
               vsf_interior(handle,2);
               vsf_style(handle,3);              
               v_bar(handle,pxy);                       		
}



open_work()
 {      int i;
        appl_init();
        handle = graf_handle(&i,&i,&i,&i);
        for ( i=0 ; i <10 ; work_in[i++]=1 );
        work_in[10]=2;
        v_opnvwk(work_in,&handle,work_out);
}

close_work()
{
	v_clsvwk(handle);
	appl_exit();
}


flee()
{    
     vst_color(handle,RED);
     vst_effects(handle,1);   /* bold face */
     v_gtext(handle,XOFFSET,184,"PRESS ANY KEY TO EXIT");
     Bconin(2);
     leave();
}
#endif
