home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d170 / surf.lha / Surf / src / gadgetuse.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  6KB  |  238 lines

  1. /* this file contains definition for the screen */
  2.  
  3. #include "scrnio.ih"
  4. #include <exec/memory.h>
  5. #ifdef MANX
  6. #include <functions.h>
  7. #endif
  8.  
  9. #include "scrndef.h"
  10. #include "gadgetdef.h"
  11. #include "mytypes.h"
  12. #include "poly.h"
  13. #include "readilbm.h"
  14.  
  15. #define GetExtens(gei) ((struct GadExtens *)gei->UserData)
  16.  
  17.  
  18. void GadgetSetVal(gad)
  19.     struct Gadget *gad;
  20. {
  21.     struct GadExtens *vp;
  22.     struct PropInfo *prop;
  23.     long gadval;
  24.  
  25.     if( !(gad->GadgetType & PROPGADGET) ) {
  26.         return;
  27.     }
  28.  
  29.     if( !gad->GadgetRender ) {
  30.         gad->GadgetRender = (APTR) malloc(sizeof(struct Image));
  31.     }
  32.     if( !gad->SpecialInfo ) {
  33.         static struct PropInfo dummyprop = {
  34.             FREEHORIZ|AUTOKNOB,
  35.             0x8000, 1, /* HorizPot = initial value */
  36.             0xff, 0, /* not really of interest */
  37.             0,0,0,0,0,0
  38.         };
  39.  
  40.         gad->SpecialInfo = (APTR) malloc(sizeof(struct PropInfo));
  41.         *(struct PropInfo *)gad->SpecialInfo = dummyprop;
  42.     }
  43.  
  44.     vp = GetExtens( gad );
  45.     if(!vp)  {
  46.         return;
  47.     }
  48.     prop = (struct PropInfo *) gad->SpecialInfo;
  49.  
  50.     if( vp->isfloat ) {
  51.         gadval = (long)( (long)MAXPOT *
  52.             ( vp->curfval - vp->minfval )/(vp->maxfval - vp->minfval));
  53.         prop->HorizBody = MAXPOT /( 15 * 8 );
  54.     }
  55.     else {
  56.         gadval = ( (long)MAXPOT *
  57.             ( (long) vp->curival - vp->minival))/(vp->maxival - vp->minival);
  58.         prop->HorizBody = MAXPOT /( vp->maxival - vp->minival );
  59.     }
  60.  
  61.     prop->HorizPot = gadval;
  62. }
  63.  
  64.  
  65.  
  66. void GadgetUpdate(gad, exists)
  67.     struct Gadget *gad;
  68.     bool exists; /* has the gadget already been displayed? */
  69. {
  70.     struct GadExtens *vp;
  71.     long potvalue;
  72.     char dbuff[25];
  73.     char *tx, *dx;
  74.     struct IntuiText *it;
  75.  
  76.     if(!( gad->GadgetType & PROPGADGET) ) {
  77.         return;
  78.     }
  79.  
  80.     vp = GetExtens( gad );
  81.     if(!vp) return;
  82.  
  83.     potvalue = ((struct PropInfo *) gad->SpecialInfo)->HorizPot;
  84.  
  85.     if( vp->isfloat ) {
  86.         float temp;
  87.         temp = ( potvalue * (vp->maxfval - vp->minfval ))/ MAXPOT
  88.                 + vp->minfval;
  89.         vp->curfval = temp;
  90. #if !MANX
  91.         sprintf(dbuff,"%f   ", temp);
  92. #else
  93.         ftoa(temp, dbuff, sizeof(dbuff)-4, 1);
  94. #endif !MANX
  95.     }
  96.     else {
  97.         long temp;
  98.         temp = (long)( potvalue * (vp->maxival - vp->minival ))/ MAXPOT
  99.                 + vp->minival;
  100.         vp->curival = temp;
  101.         sprintf(dbuff,"%-12d", temp);
  102.     }
  103.     /*
  104.      * find '['
  105.      */
  106.     it = gad->GadgetText;
  107.     for( tx = (char *)it->IText; *tx && *tx != '['; tx++ ) {
  108.         ;
  109.     }
  110.     if( !*tx ) {
  111.         return; /* something screwy */
  112.     }
  113.     tx++; /* skip past opening bracket */
  114.     dx = dbuff;
  115.     while( *tx != ']' ) {
  116.         *tx++ = *dx++;
  117.     }
  118.  
  119.     if(exists){
  120.         long tempx, tempy;
  121.         tempx = it->LeftEdge + gad->LeftEdge;
  122.         tempy = it->TopEdge + gad->TopEdge + 6; /*fudge factor for baseline*/
  123.         Move( CntrlWin->RPort, tempx, tempy );
  124.         SetAPen(CntrlWin->RPort,it->FrontPen );
  125.         Text( CntrlWin->RPort, it->IText, strlen(it->IText ));
  126.     }
  127. }
  128.  
  129. SetHourGlass() {
  130.         SetPointer( SurfWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  131.         SetPointer( GadWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  132.         SetPointer( CntrlWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  133.  
  134. }
  135.  
  136. ClearHourGlass() {
  137.         ClearPointer(SurfWin);
  138.         ClearPointer(GadWin);
  139.         ClearPointer(CntrlWin);
  140. }
  141.  
  142. void GadgetHandler(gadaddr)
  143.     struct Gadget *gadaddr;
  144. {
  145.     short curival;
  146.     float curfval;
  147.  
  148.     if( gadaddr->UserData ) {
  149.         GadgetUpdate( gadaddr, true );
  150.         curival = ((struct GadExtens *) gadaddr->UserData)->curival;
  151.         curfval = ((struct GadExtens *) gadaddr->UserData)->curfval;
  152.     }
  153.  
  154.     switch( (enum GadgetName) gadaddr->GadgetID ) {
  155.     case N_PtLocX:
  156.         LightSrc.x = (float)curival;
  157.         break;
  158.     case N_PtLocY:
  159.         LightSrc.y = (float)curival;
  160.         break;
  161.     case N_BackPlane:
  162.         BackColor = curival;
  163.         break;
  164.     case N_PtLocZ:
  165.         LightSrc.z = (float)curival;
  166.         break;
  167.     case N_BkIntens:
  168.         Ambience = curfval;
  169.         break;
  170.     case N_PtIntens:
  171.         PtIntensity = curfval;
  172.         break;
  173.     case N_Kdiffuse:
  174.         Kd = curfval;
  175.         break;
  176.     case N_Kspec:
  177.         Ks = curfval;
  178.         break;
  179.     case N_Map:
  180.         /* ResetCurve(); */
  181.         SetHourGlass();
  182.         RevMap();
  183.         ClearHourGlass();
  184.         break;
  185.     case N_Wire:
  186.         SetHourGlass();
  187.         RevNoShade();
  188.         ClearHourGlass();
  189.         break;
  190.     case N_Shaded:
  191.         SetHourGlass();
  192.         RevShade();
  193.         ClearHourGlass();
  194.         break;
  195.     case N_EditBez:
  196.         SetFitBez();
  197.         break;
  198.     case N_DefLines:
  199.         SetPolyDraw();
  200.         break;
  201.     case N_RevAngle:
  202.         SetRotRange( curival );
  203.         break;
  204.     case N_RevStart:
  205.         SetRotStart( curival );
  206.         break;
  207.     case N_TiltAng:
  208.         SetSecAng( curival );
  209.         break;
  210.     case N_RevSlices:
  211.         SetRevMesh( curival );
  212.         break;
  213.     case N_BezSlices:
  214.         SetBezMesh( curival );
  215.         break;
  216.     case N_SurfDist:
  217.         SetSurfDist( curival);
  218.         break;
  219.     case N_RepV:
  220.         MapRepV = curival;
  221.         PrepImgPix();
  222.         break;
  223.     case N_RepH:
  224.         MapRepH = curival;
  225.         PrepImgPix();
  226.         break;
  227.     case N_GoSurf:
  228.         ScreenToFront( SurfScrn );
  229.         break;
  230.     case N_GoPanel:
  231.         WBenchToFront();
  232.         WindowToFront( CntrlWin );
  233.         break;
  234.     default:
  235.         break;
  236.     }
  237. }
  238.