home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / bit_blt / amiga / gadgets.c < prev    next >
C/C++ Source or Header  |  1987-04-24  |  7KB  |  218 lines

  1. /*
  2.  *   Gadgets for BlitLab.  We have something like 40 gadgets here.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   To make things nice, we build the gadgets up, one by one.  First,
  7.  *   the externals we use.
  8.  */
  9. extern struct Window *mywindow ;
  10. extern char *bufarr[] ;
  11. extern char strings[] ;
  12. extern void *allocmem() ;
  13. extern struct Gadget *gadgets[] ;
  14. /*
  15.  *   This routine allocates a border description.
  16.  */
  17. static struct Border *givebox(xsize, ysize)
  18. int xsize, ysize ;
  19. {
  20.    register struct Border *bp ;
  21.    register short *r ;
  22.  
  23.    bp = allocmem((long)sizeof(struct Border), MEMF_CLEAR) ;
  24.    r = allocmem(20L, MEMF_CLEAR) ;
  25.    r[2] = xsize ;
  26.    r[4] = xsize ;
  27.    r[5] = ysize ;
  28.    r[7] = ysize ;
  29.    bp->FrontPen = WHITE ;
  30.    bp->DrawMode = JAM2 ;
  31.    bp->Count = 5 ;
  32.    bp->XY = r ;
  33.    return(bp) ;
  34. }
  35. /*
  36.  *   This routine allocates an intuitext structure, with a string
  37.  *   centered in it.
  38.  */
  39. static struct IntuiText *centertext(size, s)
  40. int size ;
  41. char *s ;
  42. {
  43.    register struct IntuiText *itp ;
  44.  
  45.    itp = allocmem((long)sizeof(struct IntuiText), MEMF_CLEAR) ;
  46.    itp->FrontPen = WHITE ;
  47.    itp->DrawMode = JAM2 ;
  48.    itp->TopEdge = 2 ;
  49.    itp->LeftEdge = (size - strlen(s) * 8) / 2 ;
  50.    itp->IText = (UBYTE *)s ;
  51.    return(itp) ;
  52. }
  53. /*
  54.  *   This routine builds a simple hit gadget, given an id, x and
  55.  *   y locations, xsize and ysize, and a string label.
  56.  */
  57. static buildhit(id, x, y, xsize, ysize, s)
  58. int id ;
  59. int x, y, xsize, ysize ;
  60. char *s ;
  61. {
  62.    register struct Gadget *gp ;
  63.  
  64.    gp = allocmem((long)sizeof(struct Gadget), MEMF_CLEAR) ;
  65.    gp->LeftEdge = x ;
  66.    gp->TopEdge = y ;
  67.    gp->Width = xsize ;
  68.    gp->Height = ysize ;
  69.    gp->Flags = GADGHCOMP ;
  70.    gp->Activation = RELVERIFY ;
  71.    gp->GadgetType = BOOLGADGET ;
  72.    gp->GadgetRender = (APTR)givebox(xsize, ysize) ;
  73.    gp->GadgetText = centertext(xsize, s) ;
  74.    gp->GadgetID = id ;
  75.    gadgets[id] = gp ;
  76.    AddGadget(mywindow, gp, 0) ;
  77. }
  78. /*
  79.  *   This routine builds a gadget with two possible strings.  It is up
  80.  *   to the user to flip the strings when it is selected; this means
  81.  *   taking it off the list and putting it back on.
  82.  */
  83. static buildtoggle(id, x, y, xsize, ysize, s1, s2)
  84. int id ;
  85. int x, y, xsize, ysize ;
  86. char *s1, *s2 ;
  87. {
  88.    register struct Gadget *gp ;
  89.  
  90.    gp = allocmem((long)sizeof(struct Gadget), MEMF_CLEAR) ;
  91.    gp->LeftEdge = x ;
  92.    gp->TopEdge = y ;
  93.    gp->Width = xsize ;
  94.    gp->Height = ysize ;
  95.    gp->Flags = GADGHNONE ;
  96.    gp->Activation = GADGIMMEDIATE ;
  97.    gp->GadgetType = BOOLGADGET ;
  98.    gp->GadgetRender = (APTR)givebox(xsize, ysize) ;
  99.    gp->GadgetText = centertext(xsize, s1) ;
  100.    gp->GadgetID = id ;
  101.    gp->UserData = (APTR)centertext(xsize, s2) ;
  102.    gadgets[id] = gp ;
  103.    AddGadget(mywindow, gp, 0) ;
  104. }
  105. /*
  106.  *   This routine builds a simple string gadget.  We allocate pieces
  107.  *   of the `strings' array as we do the gadgets.  `p' holds a pointer
  108.  *   to the next available chunk; we have to be careful to initialize.
  109.  *   We also allow a label parameter which lives to the left of the
  110.  *   string gadget.
  111.  */
  112. static char undobuf[100] ;
  113. static char *p ;
  114. static buildstring(id, x, y, width, init, rmax, lab)
  115. int id ;
  116. int x, y ;
  117. int width ;
  118. char *init ;
  119. int rmax ;
  120. char *lab ;
  121. {
  122.    register struct Gadget *gp ;
  123.    register struct StringInfo *sip ;
  124.    register struct Border *bp ;
  125.    int ysize ;
  126.    int xsize ;
  127.    int chars ;
  128.  
  129.    if (lab != NULL) {
  130.       drawtext(x + 4, y + 2, lab) ;
  131.       x += 8 + strlen(lab) * 8 ;
  132.       width -= 8 + strlen(lab) * 8 ;
  133.    }
  134.    chars = ( width - 4 ) / 8 ;
  135.    ysize = VSTRSIZE ;
  136.    xsize = HSTRSIZE(chars) ;
  137.    bufarr[id] = p ;
  138.    strcpy(p, init) ;
  139.    gp = allocmem((long)sizeof(struct Gadget), MEMF_CLEAR) ;
  140.    sip = allocmem((long)sizeof(struct StringInfo), MEMF_CLEAR) ;
  141.    sip->Buffer = (UBYTE *)p ;
  142.    p += rmax ;
  143.    sip->UndoBuffer = (UBYTE *)undobuf ;
  144.    sip->MaxChars = rmax ;
  145.    gp->LeftEdge = x + 2 ;
  146.    gp->TopEdge = y + 2 ;
  147.    gp->Width = xsize ;
  148.    gp->Height = ysize - 3 ;
  149.    gp->Flags = GADGHCOMP ;
  150.    gp->Activation = RELVERIFY ;
  151.    gp->GadgetType = STRGADGET ;
  152.    bp = givebox(xsize - 2, ysize - 2) ;
  153.    bp->XY[0] = -2 ;
  154.    bp->XY[1] = -2 ;
  155.    bp->XY[3] = -2 ;
  156.    bp->XY[6] = -2 ;
  157.    bp->XY[8] = -2 ;
  158.    bp->XY[9] = -2 ;
  159.    gp->GadgetRender = (APTR)bp ;
  160.    gp->GadgetText = NULL ;
  161.    gp->SpecialInfo = (APTR)sip ;
  162.    gp->GadgetID = id ;
  163.    gadgets[id] = gp ;
  164.    AddGadget(mywindow, gp, 0) ;
  165. }
  166. /*
  167.  *   This routine actually creates all of the gadgets.  Wish
  168.  *   us luck placing all of these correctly!
  169.  */
  170. buildgadgets() {
  171.    int i ;
  172.  
  173.    p = strings ;
  174.    buildhit(GDGGO, HGOSTART, VGOSTART, HGOSIZE, VGOSIZE, "GO") ;
  175.    buildhit(GDGSETUP, HMG3START, VMG2START, HMGSIZE, VMGSIZE, "Setup") ;
  176.    buildhit(GDGCALC, HLMGSTART, VLMG5, HLMGSIZE, VLMGSIZE, "Calc") ;
  177.    buildtoggle(GDGPNTREG, HLMGSTART, VLMG1, HLMGSIZE, VLMGSIZE, "Point",
  178.       " Box ") ;
  179.    buildtoggle(GDGCLRSET, HLMGSTART, VLMG2, HLMGSIZE, VLMGSIZE, "Clear",
  180.       " Set ") ;
  181.    buildtoggle(GDGLINE, HMG3START, VMG1START, HMGSIZE, VMGSIZE, "(line)",
  182.       " LINE ") ;
  183.    buildtoggle(GDGDESC, HMG6START, VMG1START, HMGSIZE, VMGSIZE, "(desc)", 
  184.       " DESC ") ;
  185.    buildtoggle(GDGFCI, HMG7START, VMG1START, HMGSIZE, VMGSIZE, "(fci)", 
  186.       " FCI ") ;
  187.    buildtoggle(GDGIFE, HMG8START, VMG1START, HMGSIZE, VMGSIZE, "(ife)",
  188.       " IFE ") ;
  189.    buildtoggle(GDGEFE, HMG9START, VMG1START, HMGSIZE, VMGSIZE, "(efe)",
  190.       " EFE ") ;
  191.    for (i=0; i<4; i++)
  192.       buildtoggle(GDGUSEA+i, HRVC8, VRG1 + 11 * i, 24, VSTRSIZE, "N", "Y") ;
  193.    buildstring(GDGSX, HMG1START, VMG1START, HMGSIZE, "0", 20, "SX") ;
  194.    buildstring(GDGSY, HMG2START, VMG1START, HMGSIZE, "0", 20, "SY") ;
  195.    buildstring(GDGEX, HMG1START, VMG2START, HMGSIZE, "0", 20, "EX") ;
  196.    buildstring(GDGEY, HMG2START, VMG2START, HMGSIZE, "0", 20, "EY") ;
  197.    buildstring(GDGH, HMG4START, VMG1START, HMGSIZE, "0", 20, "W") ;
  198.    buildstring(GDGV, HMG5START, VMG1START, HMGSIZE, "0", 20, "H") ;
  199.    buildstring(GDGFUNC, HMG4START, VMG2START, 6 * HMGSIZE, "0", 100,
  200.       "Function") ;
  201.    for (i=0; i<4; i++)
  202.       buildstring(GDGAPT+i, HRVC9, VRG1 + 11 * i, HSTRSIZE(8), "0", 20, NULL) ;
  203.    for (i=0; i<4; i++)
  204.       buildstring(GDGAMOD+i, HRVC10, VRG1 + 11 * i, HSTRSIZE(6), "0", 20,
  205.          NULL) ;
  206.    for (i=0; i<3; i++)
  207.       buildstring(GDGADAT+i, HRVC11, VRG1 + 11 * i, HSTRSIZE(18), "0", 20,
  208.          NULL) ;
  209.    for (i=0; i<2; i++)
  210.       buildstring(GDGASH+i, HRVC12, VRG1 + 11 * i, HSTRSIZE(4), "0", 20,
  211.          NULL) ;
  212.    buildstring(GDGAFWM, HRVC11, VRG1 + 33, 180, "%1111111111111111", 20,
  213.       "FWM") ;
  214.    buildstring(GDGALWM, HRVC11, VRG1 + 44, 180, "%1111111111111111", 20,
  215.       "LWM") ;
  216.    RefreshGadgets(mywindow->FirstGadget, mywindow, NULL) ;
  217. }
  218.