home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / drive_utils / benchmark / diskspeed / standardgadgets.c < prev    next >
C/C++ Source or Header  |  1990-02-03  |  11KB  |  356 lines

  1. /*
  2.  *                          DiskSpeed v3.0
  3.  *                                by
  4.  *                           Michael Sinz
  5.  *
  6.  *             Copyright (c) 1989 by MKSoft Development
  7.  *
  8.  *            MKSoft Development
  9.  *            163 Appledore Drive
  10.  *            Downingtown, PA 19335
  11.  *
  12.  * Yes, this is yet another disk speed testing program, but with a few
  13.  * differences.  It was designed to give the most accurate results of the
  14.  * true disk performance in the system.  For this reason many of
  15.  * DiskSpeed's results may look either lower or higher than current disk
  16.  * performance tests.
  17.  *
  18.  * This program was thrown together in a few hours because I needed more
  19.  * accurate and consistent results for disk performance as seen from the
  20.  * application's standpoint.  This program has now served its purpose and
  21.  * I am now giving it to the rest of the Amiga world to play with as long
  22.  * as all of the files remain together in unmodified form.  (That is, the
  23.  * files DiskSpeed, DiskSpeed.info, DiskSpeed.c, DiskSpeedWindow.c,
  24.  * DiskSpeedWindow.h, MakeBoxes.c, MakeBoxes.h, StandardGadgets.c,
  25.  * StandardGadgets.h, RenderInfo.c, RenderInfo.h, DiskSpeed.doc, and
  26.  * MakeFile)
  27.  *
  28.  * Version 2.0 of this program added a few features and cleaned up the
  29.  * user interface.  I hope you like this...
  30.  *
  31.  * Version 3.0 of this program added the performance stress and cleaned up
  32.  * some parts of the older code.  (Fix to RenderInfo.c)
  33.  *
  34.  ******************************************************************************
  35.  *                                          *
  36.  *    Reading legal mush can turn your brain into guacamole!              *
  37.  *                                          *
  38.  *        So here is some of that legal mush:                  *
  39.  *                                          *
  40.  * Permission is hereby granted to distribute this program's source          *
  41.  * executable, and documentation for non-commercial purposes, so long as the  *
  42.  * copyright notices are not removed from the sources, executable or          *
  43.  * documentation.  This program may not be distributed for a profit without   *
  44.  * the express written consent of the author Michael Sinz.              *
  45.  *                                          *
  46.  * This program is not in the public domain.                      *
  47.  *                                          *
  48.  * Fred Fish is expressly granted permission to distribute this program's     *
  49.  * source and executable as part of the "Fred Fish freely redistributable     *
  50.  * Amiga software library."                              *
  51.  *                                          *
  52.  * Permission is expressly granted for this program and it's source to be     *
  53.  * distributed as part of the Amicus Amiga software disks, and the          *
  54.  * First Amiga User Group's Hot Mix disks.                      *
  55.  *                                          *
  56.  ******************************************************************************
  57.  *
  58.  * This file contains the code needed to add standard gadgets to a
  59.  * window.  These are the Close/Front/Back/Drag gadgets...
  60.  *
  61.  * Current limitations:  Gadgets are not rel-size/pos so they only
  62.  * work on fixed sized windows...
  63.  *
  64.  * The drag gadget does not show window Active/Inactive...  :-( :-(
  65.  */
  66.  
  67. #include    <exec/types.h>
  68. #include    <exec/memory.h>
  69. #include    <intuition/intuition.h>
  70.  
  71. #include    <proto/exec.h>
  72. #include    <proto/intuition.h>
  73.  
  74. #include    "RenderInfo.h"
  75. #include    "MakeBoxes.h"
  76. #include    "StandardGadgets.h"
  77.  
  78. static char fontnam[11]="topaz.font";
  79. static struct TextAttr TOPAZ80={fontnam,TOPAZ_EIGHTY,0,0};
  80.  
  81. #define    CLOSE_WIDTH    24
  82. #define    CLOSE_HEIGHT    12
  83.  
  84. static    SHORT    CloseBorderVectors1[8*2]=
  85. {
  86.     4,2,    4,9,    19,9,    19,2,    5,2,    5,9,    18,9,    18,3
  87. };
  88.  
  89. static    SHORT    CloseBorderVectors2[4*2]=
  90. {
  91.     10,5,    13,5,    13,6,    10,6
  92. };
  93.  
  94. struct CloseGadget
  95. {
  96. struct    Gadget    gad;
  97. struct    Window    *win;
  98. struct    Border    Borders[6];
  99.     SHORT    BorderV1[5*2];
  100.     SHORT    BorderV2[5*2];
  101. };
  102.  
  103. struct Gadget *AddCloseGadget(struct Window *Window,struct RenderInfo *ri,SHORT x,SHORT y)
  104. {
  105. register    struct    CloseGadget    *gad;
  106. register        SHORT        loop;
  107.  
  108.     if (gad=AllocMem(sizeof(struct CloseGadget),MEMF_PUBLIC|MEMF_CLEAR))
  109.     {
  110.         gad->win=Window;
  111.  
  112.         gad->gad.LeftEdge=x;
  113.         gad->gad.TopEdge=y;
  114.         gad->gad.Width=CLOSE_WIDTH;
  115.         gad->gad.Height=CLOSE_HEIGHT;
  116.         gad->gad.Flags=GADGHIMAGE;
  117.         gad->gad.Activation=RELVERIFY;
  118.         gad->gad.GadgetType=CLOSE|SYSGADGET;
  119.         gad->gad.GadgetRender=(APTR)&(gad->Borders[0]);
  120.         gad->gad.SelectRender=(APTR)&(gad->Borders[4]);
  121.  
  122.         /* Standard render path... */
  123.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  124.         gad->Borders[1].NextBorder=&(gad->Borders[2]);
  125.         gad->Borders[2].NextBorder=&(gad->Borders[3]);
  126.  
  127.         /* These point back... */
  128.         gad->Borders[4].NextBorder=&(gad->Borders[5]);
  129.         gad->Borders[5].NextBorder=&(gad->Borders[2]);
  130.  
  131.         /* Border sizes... */
  132.         gad->Borders[0].Count=5;
  133.         gad->Borders[1].Count=5;
  134.         gad->Borders[2].Count=8;
  135.         gad->Borders[3].Count=4;
  136.         gad->Borders[4].Count=5;
  137.         gad->Borders[5].Count=5;
  138.  
  139.         for (loop=0;loop<6;loop++)
  140.         {
  141.             gad->Borders[loop].DrawMode=JAM1;
  142.             gad->Borders[loop].FrontPen=ri->Highlight;
  143.         }
  144.         gad->Borders[1].FrontPen=ri->Shadow;
  145.         gad->Borders[4].FrontPen=ri->Shadow;
  146.  
  147.         gad->Borders[4].XY=gad->Borders[0].XY=gad->BorderV1;
  148.         gad->Borders[5].XY=gad->Borders[1].XY=gad->BorderV2;
  149.         gad->Borders[2].XY=CloseBorderVectors1;
  150.         gad->Borders[3].XY=CloseBorderVectors2;
  151.  
  152.         FillTopLeft_Border(&(gad->Borders[0]),CLOSE_WIDTH,CLOSE_HEIGHT);
  153.         FillBottomRight_Border(&(gad->Borders[1]),CLOSE_WIDTH,CLOSE_HEIGHT);
  154.  
  155.         AddGadget(Window,&(gad->gad),NULL);
  156.         Window->Flags|=WINDOWCLOSE;
  157.         RefreshGList(&(gad->gad),Window,NULL,1L);
  158.     }
  159.     return((struct Gadget *)gad);
  160. }
  161.  
  162. VOID RemCloseGadget(struct Gadget *TheGadget)
  163. {
  164. register    struct    CloseGadget    *gad;
  165.  
  166.     gad=(struct CloseGadget *)TheGadget;
  167.     RemoveGadget(gad->win,&(gad->gad));
  168.     gad->win->Flags^=WINDOWCLOSE;
  169.     FreeMem(gad,sizeof(struct CloseGadget));
  170. }
  171.  
  172. #define    BACK_WIDTH    26
  173. #define    BACK_HEIGHT    12
  174.  
  175. struct FrontBackGadget
  176. {
  177. struct    Gadget    Back_gad;
  178. struct    Gadget    Front_gad;
  179. struct    Window    *win;
  180. struct    Border    Borders[12];
  181.     SHORT    BorderV1[5*2];
  182.     SHORT    BorderV2[5*2];
  183. };
  184.  
  185. static    SHORT    FrontBackBorderVectors1[10*2]=
  186. {
  187.     6,3,  6,7,  7,7,  7,3,  17,3,  17,2,  4,2,  4,7,  5,7,  5,3
  188. };
  189.  
  190. static    SHORT    FrontBackBorderVectors2[12*2]=
  191. {
  192.     8,4,  21,4,  21,9,  8,9,  8,5,  20,5,  20,8,  9,8,  9,6,  19,6,  19,7,  10,7
  193. };
  194.  
  195. struct Gadget *AddFrontBackGadget(struct Window *Window,struct RenderInfo *ri,SHORT x,SHORT y)
  196. {
  197. register    struct    FrontBackGadget    *gad;
  198. register        SHORT        loop;
  199.  
  200.     if (gad=AllocMem(sizeof(struct FrontBackGadget),MEMF_PUBLIC|MEMF_CLEAR))
  201.     {
  202.         gad->win=Window;
  203.  
  204.         gad->Back_gad.LeftEdge=x;
  205.         gad->Back_gad.TopEdge=y;
  206.         gad->Back_gad.Width=BACK_WIDTH;
  207.         gad->Back_gad.Height=BACK_HEIGHT;
  208.         gad->Back_gad.Flags=GADGHIMAGE;
  209.         gad->Back_gad.Activation=RELVERIFY;
  210.         gad->Back_gad.GadgetType=WDOWNBACK|SYSGADGET;
  211.         gad->Back_gad.GadgetRender=(APTR)&(gad->Borders[0]);
  212.         gad->Back_gad.SelectRender=(APTR)&(gad->Borders[4]);
  213.  
  214.         /* Standard render path... */
  215.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  216.         gad->Borders[1].NextBorder=&(gad->Borders[2]);
  217.         gad->Borders[2].NextBorder=&(gad->Borders[3]);
  218.  
  219.         /* These point back... */
  220.         gad->Borders[4].NextBorder=&(gad->Borders[5]);
  221.         gad->Borders[5].NextBorder=&(gad->Borders[2]);
  222.  
  223.         gad->Front_gad.LeftEdge=x+BACK_WIDTH;
  224.         gad->Front_gad.TopEdge=y;
  225.         gad->Front_gad.Width=BACK_WIDTH;
  226.         gad->Front_gad.Height=BACK_HEIGHT;
  227.         gad->Front_gad.Flags=GADGHIMAGE;
  228.         gad->Front_gad.Activation=RELVERIFY;
  229.         gad->Front_gad.GadgetType=WUPFRONT|SYSGADGET;
  230.         gad->Front_gad.GadgetRender=(APTR)&(gad->Borders[0+6]);
  231.         gad->Front_gad.SelectRender=(APTR)&(gad->Borders[4+6]);
  232.  
  233.         /* Standard render path... */
  234.         gad->Borders[0+6].NextBorder=&(gad->Borders[1+6]);
  235.         gad->Borders[1+6].NextBorder=&(gad->Borders[2+6]);
  236.         gad->Borders[2+6].NextBorder=&(gad->Borders[3+6]);
  237.  
  238.         /* These point back... */
  239.         gad->Borders[4+6].NextBorder=&(gad->Borders[5+6]);
  240.         gad->Borders[5+6].NextBorder=&(gad->Borders[2+6]);
  241.  
  242.         /* Border sizes... */
  243.         for (loop=0;loop<12;loop++) gad->Borders[loop].Count=5;
  244.         gad->Borders[2+6].Count=gad->Borders[2].Count=10;
  245.         gad->Borders[3+6].Count=gad->Borders[3].Count=12;
  246.  
  247.         /* Pen colours... */
  248.         for (loop=0;loop<12;loop++)
  249.         {
  250.             gad->Borders[loop].DrawMode=JAM1;
  251.             gad->Borders[loop].FrontPen=ri->Highlight;
  252.         }
  253.         gad->Borders[1].FrontPen=ri->Shadow;
  254.         gad->Borders[2].FrontPen=ri->Shadow;
  255.         gad->Borders[4].FrontPen=ri->Shadow;
  256.         gad->Borders[1+6].FrontPen=ri->Shadow;
  257.         gad->Borders[3+6].FrontPen=ri->Shadow;
  258.         gad->Borders[4+6].FrontPen=ri->Shadow;
  259.  
  260.         gad->Borders[4+6].XY=gad->Borders[0+6].XY=gad->Borders[4].XY=gad->Borders[0].XY=gad->BorderV1;
  261.         gad->Borders[5+6].XY=gad->Borders[1+6].XY=gad->Borders[5].XY=gad->Borders[1].XY=gad->BorderV2;
  262.         gad->Borders[2+6].XY=gad->Borders[2].XY=FrontBackBorderVectors1;
  263.         gad->Borders[3+6].XY=gad->Borders[3].XY=FrontBackBorderVectors2;
  264.         FillTopLeft_Border(&(gad->Borders[0]),BACK_WIDTH,BACK_HEIGHT);
  265.         FillBottomRight_Border(&(gad->Borders[1]),BACK_WIDTH,BACK_HEIGHT);
  266.  
  267.         AddGadget(Window,&(gad->Back_gad),NULL);
  268.         RefreshGList(&(gad->Back_gad),Window,NULL,1L);
  269.  
  270.         AddGadget(Window,&(gad->Front_gad),NULL);
  271.         Window->Flags|=WINDOWDEPTH;
  272.         RefreshGList(&(gad->Front_gad),Window,NULL,1L);
  273.     }
  274.     return((struct Gadget *)gad);
  275. }
  276.  
  277. VOID RemFrontBackGadget(struct Gadget *TheGadget)
  278. {
  279. register    struct    FrontBackGadget    *gad;
  280.  
  281.     gad=(struct FrontBackGadget *)TheGadget;
  282.     RemoveGadget(gad->win,&(gad->Back_gad));
  283.     RemoveGadget(gad->win,&(gad->Front_gad));
  284.     gad->win->Flags^=WINDOWDEPTH;
  285.     FreeMem(gad,sizeof(struct FrontBackGadget));
  286. }
  287.  
  288. #define    DRAG_HEIGHT    12
  289.  
  290. struct DragGadget
  291. {
  292. struct    Gadget        gad;
  293. struct    Window        *win;
  294. struct    IntuiText    iText;
  295. struct    Border        Borders[2];
  296.     SHORT        BorderV1[5*2];
  297.     SHORT        BorderV2[5*2];
  298. };
  299.  
  300. struct Gadget *AddDragGadget(struct Window *Window,struct RenderInfo *ri,char *text,SHORT x,SHORT y,SHORT xSize)
  301. {
  302. register    struct    DragGadget    *gad;
  303.  
  304.     if (gad=AllocMem(sizeof(struct DragGadget),MEMF_PUBLIC|MEMF_CLEAR))
  305.     {
  306.         gad->win=Window;
  307.  
  308.         gad->gad.LeftEdge=x;
  309.         gad->gad.TopEdge=y;
  310.         gad->gad.Width=xSize;
  311.         gad->gad.Height=CLOSE_HEIGHT;
  312.         gad->gad.Flags=GADGHNONE;
  313.         gad->gad.Activation=RELVERIFY;
  314.         gad->gad.GadgetType=WDRAGGING|SYSGADGET;
  315.         gad->gad.GadgetRender=(APTR)&(gad->Borders[0]);
  316.         gad->gad.GadgetText=&(gad->iText);
  317.  
  318.         gad->iText.FrontPen=ri->TextPen;
  319.         gad->iText.DrawMode=JAM1;
  320.         gad->iText.TopEdge=2;
  321.         gad->iText.ITextFont=&TOPAZ80;
  322.         gad->iText.IText=text;
  323.         gad->iText.LeftEdge=(xSize-IntuiTextLength(&(gad->iText))) >> 1;
  324.  
  325.         /* Standard render path... */
  326.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  327.  
  328.         /* Border sizes... */
  329.         gad->Borders[0].Count=gad->Borders[1].Count=5;
  330.  
  331.         gad->Borders[0].DrawMode=gad->Borders[1].DrawMode=JAM1;
  332.         gad->Borders[0].FrontPen=ri->Shadow;
  333.         gad->Borders[1].FrontPen=ri->Highlight;
  334.  
  335.         gad->Borders[0].XY=gad->BorderV1;
  336.         gad->Borders[1].XY=gad->BorderV2;
  337.         FillTopLeft_Border(&(gad->Borders[0]),xSize,DRAG_HEIGHT);
  338.         FillBottomRight_Border(&(gad->Borders[1]),xSize,DRAG_HEIGHT);
  339.  
  340.         AddGadget(Window,&(gad->gad),NULL);
  341.         Window->Flags|=WINDOWDRAG;
  342.         RefreshGList(&(gad->gad),Window,NULL,1L);
  343.     }
  344.     return((struct Gadget *)gad);
  345. }
  346.  
  347. VOID RemDragGadget(struct Gadget *TheGadget)
  348. {
  349. register    struct    DragGadget    *gad;
  350.  
  351.     gad=(struct DragGadget *)TheGadget;
  352.     RemoveGadget(gad->win,&(gad->gad));
  353.     gad->win->Flags^=WINDOWDRAG;
  354.     FreeMem(gad,sizeof(struct DragGadget));
  355. }
  356.