home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / macabuse / src / netstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  3.8 KB  |  202 lines

  1. #include "netstat.hpp"
  2. #include "dprint.hpp"
  3. #include "cache.hpp"
  4. #include "jwindow.hpp"
  5.  
  6. extern palette *pal;
  7. static int old_xres;
  8.  
  9. extern window_manager *eh;
  10.  
  11. class net_status_node
  12. {
  13.   public :  
  14.   char *name;
  15.   net_status_node *next;
  16.   visual_object *show;
  17.   int last_update;
  18.  
  19.   net_status_node(char *Name, visual_object *Show, net_status_node *Next) 
  20.   { 
  21.       name=strcpy((char *)jmalloc(strlen(Name)+1,"status name"),Name); 
  22.     show=Show;
  23.     next=Next; 
  24.     last_update=0;
  25.   }
  26.   ~net_status_node() { jfree(name); if (show) delete show; }
  27. } ; 
  28.  
  29. net_status_manager::net_status_manager(char *graphic_file, 
  30.     int x1, int y1,
  31.     int x2, int y2,
  32.     int color1, int color2) : g_file(graphic_file), color1(color1), color2(color2)
  33.   first_x1=x1;
  34.   first_y1=y1;
  35.  
  36.  
  37.   if (x2-x1<y2-y1)
  38.   {
  39.     first_x2=(x1+x2)/2-1;
  40.     first_y2=y2;
  41.     second_x1=(x1+x2)/2+1;
  42.   } else
  43.   {
  44.     first_x2=x2;
  45.     first_y2=(y1+y2)/2-1;
  46.     second_x1=x1;
  47.     second_y1=(y1+y2)/2+1;
  48.   }
  49.   second_x2=x2;
  50.   second_y2=y2;
  51.  
  52.  
  53.   first=NULL; 
  54.   level=0; 
  55. }
  56.  
  57. void load_image_into_screen(char *filename, char *name, int &x_loaded, int &y_loaded);
  58.  
  59. void net_status_manager::push(char *name, visual_object *show)
  60. {
  61.  
  62.  
  63.   level++;
  64.   first=new net_status_node(name,show,first);
  65.   if (level==1)
  66.   {
  67.     screen->clear();
  68.     update_dirty(screen);   // make sure the screen is actually clear before we mess with the palette
  69.  
  70.     // save a copy of the old palette
  71.     if (pal)
  72.       old_pal=pal->copy();
  73.     else old_pal=0;
  74.     bFILE *fp=open_file(g_file,"rb");
  75.     if (fp->open_failure())
  76.     {
  77.       dprintf("Unable to open art/status.spe\n");
  78.       exit(0);
  79.     }
  80.  
  81.     old_xres=xres;
  82.     switch_mode(VMODE_640x480);
  83.  
  84.     spec_directory sd(fp);
  85.     spec_entry *se=sd.find(SPEC_PALETTE);  // find the palette used by this screen
  86.     fp->seek(se->offset,0);
  87.     palette new_pal(fp);
  88.     new_pal.load();
  89.     delete fp;
  90.  
  91.     // now load the status image direct into our back buffer so that
  92.     // another image is not allocated
  93.     int x,y;
  94.     load_image_into_screen(g_file,"status",x,y);
  95.     xp=x; yp=y;
  96.  
  97.     //    cash.img(cash.reg("art/status.spe","status", SPEC_IMAGE,1))->put_image(screen,0,0);
  98.     //    xp=0;
  99.     //    yp=0;
  100.  
  101.     update_dirty(screen);
  102.   }
  103.  
  104.  
  105.     
  106. }
  107.  
  108. void draw_bar(int x1, int y1, int x2, int y2, int percent, int color)
  109. {
  110.   int h=(y2-y1)*percent/100;
  111.   int w=(x2-x1)*percent/100;
  112.   
  113.   if (h>w)
  114.   {
  115.     screen->bar(x1,y2-h,x2,y2,color);
  116.     if (y2-h!=y1)
  117.       screen->bar(x1,y1,x2,y2-h-1,0);
  118.   } else
  119.   {
  120.     screen->bar(x1,y1,x1+w,y2,color);
  121.     if (x2-x1!=w)
  122.       screen->bar(x1+w+1,y1,x2,y2,0);
  123.   }
  124. }
  125.  
  126.  
  127. void net_status_manager::update(int percentage)
  128. {
  129.   if (level==last_level && percentage==last_percent)
  130.     return ;
  131.     
  132.   if (level==1)
  133.      first_percent=percentage;
  134.     
  135.   if (level==1 || level==2)
  136.   {
  137.      draw_bar(xp+first_x1,yp+first_y1,xp+first_x2,yp+first_y2,first_percent,color1);   
  138.   }
  139.   
  140.   if (level==2)
  141.   {
  142.     draw_bar(xp+second_x1,yp+second_y1,xp+second_x2,yp+second_y2,percentage,color2);
  143.   }
  144.     
  145.   last_percent=percentage;
  146.   last_level=level;
  147.   
  148.   update_dirty(screen);
  149. }
  150.  
  151.  
  152. void net_status_manager::pop()
  153. {
  154. //    return;
  155.  
  156.   level--;
  157.   if (level==0)
  158.   {
  159.  
  160.     screen->clear();
  161.     update_dirty(screen);
  162.  
  163.     if (old_xres<=320)
  164.       switch_mode(VMODE_320x200);
  165.  
  166.     if (eh)
  167.     {
  168.       event e,*ev=new event;
  169.  
  170.       ev->type=EV_REDRAW;
  171.       ev->redraw.x1=0;
  172.       ev->redraw.y1=0;
  173.       ev->redraw.x2=xres;
  174.       ev->redraw.y2=yres;
  175.  
  176.       eh->push_event(ev);
  177.       eh->get_event(e);   // cause the window manager to process this event
  178.     }
  179.  
  180.     if (old_pal)
  181.     {
  182.       old_pal->load();
  183.       delete old_pal;
  184.     }
  185.  
  186.   }
  187.  
  188.   net_status_node *p=first; 
  189.   first=first->next;
  190.   delete p;
  191.  
  192.   if (level==0)
  193.   {
  194.   }
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.