home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / performance / memory / tinymeter / source / tinymeter_main / display.c next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  5.9 KB  |  246 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/cghooks.h>
  11. #include <intuition/icclass.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/sghooks.h>
  14. #include <intuition/screens.h>
  15. #include <datatypes/datatypesclass.h>
  16. #include <datatypes/datatypes.h>
  17. #include <datatypes/pictureclass.h>
  18. #include <libraries/SysInfo.h>
  19. #include <graphics/gfxbase.h>
  20. #include <graphics/text.h>
  21. #include <graphics/gfxmacros.h>
  22. #include <utility/tagitem.h>
  23. #include <utility/hooks.h>
  24. #include <string.h>
  25. #include <clib/macros.h>
  26. #include "gaugeclass.h"
  27. #include "tinymeter.h"
  28.  
  29. extern struct Library *RetinaBase;
  30.  
  31. /* the only two globals */
  32.  
  33. extern ULONG    maximum,
  34.         idle;
  35.  
  36. drawBackground(struct tm_sys_set *set,struct tm_data *data)
  37. {
  38.     struct RastPort *rp=data->win->RPort;
  39.     UWORD  x,y;
  40.  
  41.     x=data->win->Width-1;
  42.     y=data->win->Height-1;
  43.  
  44.     if(data->bg_bm)
  45.     {
  46.     BltBitMapRastPort(data->bg_bm,0,0,rp,0,0,x+1,y+1,0xc0);
  47.     }
  48.     else
  49.     {
  50.     SetAPen(rp,data->bg_color);
  51.     RectFill(rp,0,0,x,y);
  52.     }
  53.  
  54.     SetAPen(rp,data->bright_color);
  55.     switch (set->bd_type)
  56.     {
  57.     case    bd_simple:
  58.         RectFill(rp,0,0,x,0);
  59.         RectFill(rp,0,0,0,y);
  60.         RectFill(rp,x,0,x,y);
  61.         RectFill(rp,0,y,x,y);
  62.         break;
  63.     case    bd_standard:
  64.         RectFill(rp,0,0,x,0);
  65.         RectFill(rp,0,0,0,y);
  66.         SetAPen(rp,data->dark_color);
  67.         RectFill(rp,x,1,x,y);
  68.         RectFill(rp,1,y,x,y);
  69.         break;
  70.     case    bd_double:
  71.         SetAPen(rp,data->dark_color);
  72.         RectFill(rp,0,0,x,0);
  73.         RectFill(rp,0,0,0,y);
  74.         RectFill(rp,1,y-1,x-1,y-1);
  75.         RectFill(rp,x-1,2,x-1,y-1);
  76.         SetAPen(rp,data->bright_color);
  77.         RectFill(rp,x,1,x,y);
  78.         RectFill(rp,1,y,x,y);
  79.         RectFill(rp,1,1,x-1,1);
  80.         RectFill(rp,1,1,1,y-1);
  81.         break;
  82.     }
  83. }
  84.  
  85. allocGadgets(struct tm_sys_set *set, struct tm_data *data, Class *gclass)
  86. {
  87.     struct tm_gau_set *many;
  88.     ULONG  i,max,cur,y_pos,j,tmp,voltype;
  89.     
  90.     for(i=0,many=data->list;i<data->num_of_gaug;i++)
  91.     {
  92.     voltype=0;
  93.     switch (many->type)
  94.     {
  95.         case    typ_all:
  96.             max=AvailMem(MEMF_TOTAL);
  97.             cur=AvailMem(0L);
  98.             break;
  99.         case    typ_chip:
  100.             max=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  101.             cur=AvailMem(MEMF_CHIP);
  102.             break;
  103.         case    typ_fast:
  104.             max=AvailMem(MEMF_FAST|MEMF_TOTAL);
  105.             cur=AvailMem(MEMF_FAST);
  106.             break;
  107.         case    typ_largest_total:
  108.             max=AvailMem(MEMF_TOTAL);
  109.             cur=AvailMem(MEMF_LARGEST);
  110.             break;
  111.         case    typ_largest_chip:
  112.             max=AvailMem(MEMF_TOTAL|MEMF_CHIP);
  113.             cur=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  114.             break;
  115.         case    typ_largest_fast:
  116.             max=AvailMem(MEMF_TOTAL|MEMF_FAST);
  117.             cur=AvailMem(MEMF_LARGEST|MEMF_FAST);
  118.             break;
  119.         case    typ_largest_retina:
  120.             if(RetinaBase)
  121.             {
  122.             max=Retina_AvailMem(MEMF_TOTAL);
  123.             cur=Retina_AvailMem(MEMF_LARGEST);
  124.             }
  125.             else
  126.             {
  127.             max=0L;
  128.             cur=GAU_err_notavail;
  129.             }
  130.             break;
  131.         case    typ_volume:
  132.             getVolsize(data,&many->expansion[0]);
  133.             max=data->volmax;
  134.             cur=data->volcur;
  135.             voltype=data->voltype;
  136.             break;
  137.         case    typ_idle:
  138.             switch (data->executive)
  139.             {
  140.             case    idle_none:
  141.                 max=0L;
  142.                 cur=GAU_err_notavail;
  143.                 break;
  144.             case    idle_executive:
  145.                 GetCpuUsage(data->si,&data->cpu);
  146.                 max=(data->cpu.used_cputime_lastsec_hz)<<8;
  147.                 cur=(data->cpu.used_cputime_lastsec_hz-data->cpu.used_cputime_lastsec)<<8;
  148.                 break;
  149.             case    idle_own:
  150.                 max=maximum;
  151.                 cur=idle;
  152.                 break;
  153.             }
  154.             break;
  155.         case    typ_retina:
  156.             if(RetinaBase)
  157.             {
  158.             max=Retina_AvailMem(MEMF_TOTAL);
  159.             cur=Retina_AvailMem(0L);
  160.             }
  161.             else
  162.             {
  163.             max=0L;
  164.             cur=GAU_err_notavail;
  165.             }
  166.             break;
  167.         case    typ_clock_:
  168.             many->gauge_type=typ_clock;
  169.             break;
  170.         case    typ_image:
  171.             break;
  172.         case    typ_none:
  173.             data->gdg[i]=0L;
  174.             goto typ_none_1;
  175.             break;
  176.     }
  177.  
  178.     tmp=i/set->colums;
  179.     if(set->lay_falling)
  180.     {
  181.         y_pos=set->win_border_y+(tmp*set->win_space_y);
  182.         for(j=(i-(tmp*set->colums));j<i;j+=set->colums) y_pos+=data->gauge_y_size_falling[j];
  183.     }
  184.     else
  185.     {
  186.         y_pos= set->win_border_y+(tmp*set->win_space_y)+((data->gauge_y_size[tmp]-data->gauge_y_size_falling[i])>>1);
  187.         for(j=0;j<tmp;j++) y_pos+=data->gauge_y_size[j];
  188.     }
  189.     data->gdg[i]=(struct Gadget *)NewObject(gclass, NULL,
  190.             GA_ID,          i,
  191.             GA_Top,         y_pos,
  192.             GA_Left,        set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x,
  193.             GA_Width,       data->gauge_x_size,
  194.             GA_Height,      data->gauge_y_size_falling[i],
  195.             GAU_Type,       many->gauge_type,
  196.             GAU_Current,    cur,
  197.             GAU_Max,        max,
  198.             GAU_Base,       cur,
  199.             GAU_VolType,    voltype,
  200.             GAU_Label,      many->label,
  201.             GAU_TextFormat, many->format,
  202.             GAU_TextFont,   data->Font[i],
  203.             GAU_LabelPos,   data->labelpos,
  204.             GAU_FmtIndent,  many->indent,
  205.  
  206.             GAU_3D,         many->sty_3d,
  207.             GAU_Border,     many->sty_border,
  208.             GAU_Background, many->sty_bg,
  209.             GAU_ShadowLabel,many->sty_shadow,
  210.             GAU_NoGauge,    many->sty_nogauge,
  211.             GAU_NoFormat,   many->sty_noformat,
  212.             GAU_NoBase,     many->sty_nobase,
  213.  
  214.             GAU_ColLabel,   &many->Colors[col_label],
  215.             GAU_ColFormat,  &many->Colors[col_format],
  216.             GAU_ColBase,    &many->Colors[col_base],
  217.             GAU_ColCurrent, &many->Colors[col_current],
  218.             GAU_ColNegative,&many->Colors[col_negative],
  219.             GAU_ColBrightEdg,&many->Colors[col_bright],
  220.             GAU_ColDarkEdg, &many->Colors[col_dark],
  221.             GAU_ColBackground,&many->Colors[col_bg],
  222.  
  223.             TAG_DONE);
  224.     if(!data->gdg[i]) show("Gadget creation failed!");
  225.     else
  226.     {
  227.         SetGadgetAttrs(data->gdg[i],data->win,NULL,TAG_DONE);
  228.         RefreshGList  (data->gdg[i],data->win,NULL,1);
  229.     }
  230.     typ_none_1:
  231.     many=many->next;
  232.     }
  233. }
  234.  
  235. removeGadgets(struct tm_sys_set *set, struct tm_data *data)
  236. {
  237.     int i;
  238.  
  239.     for(i=0;i<data->num_of_gaug;i++)
  240.     if(data->gdg[i])
  241.     {
  242.         DisposeObject(data->gdg[i]);
  243.         data->gdg[i]=0L;
  244.     }
  245. }
  246.