home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Biomorph 0.77 / Biomorph src / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-26  |  3.9 KB  |  197 lines  |  [TEXT/ALFA]

  1. #include <MacHeaders>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "constants.h"
  5. #include "mathtype.h"
  6. #include "globals.h"
  7.  
  8.  
  9. void ReadCoords(void)
  10. {
  11.     char s[256];    /* temporary string */
  12.     int itemType;
  13.     Handle h=NULL;
  14.     Rect box;
  15.     
  16.     GetDItem( gControlDialog, kETXMin, &itemType, &h, &box);
  17.         GetIText( h, s);
  18.         PtoCstr(s);
  19.         sscanf(s, "%lf", &gXmin);
  20.     GetDItem( gControlDialog, kETXMax, &itemType, &h, &box);
  21.         GetIText( h, s);
  22.         PtoCstr(s);
  23.         sscanf(s, "%lf", &gXmax);
  24.     GetDItem( gControlDialog, kETYMin, &itemType, &h, &box);
  25.         GetIText( h, s);
  26.         PtoCstr(s);
  27.         sscanf(s, "%lf", &gYmin);
  28.     GetDItem( gControlDialog, kETYMax, &itemType, &h, &box);
  29.         GetIText( h, s);
  30.         PtoCstr(s);
  31.         sscanf(s, "%lf", &gYmax);
  32.     GetDItem( gControlDialog, kETCreal, &itemType, &h, &box);
  33.         GetIText( h, s);
  34.         PtoCstr(s);
  35.         sscanf(s, "%lf", &gCreal);
  36.     GetDItem( gControlDialog, kETCimag, &itemType, &h, &box);
  37.         GetIText( h, s);
  38.         PtoCstr(s);
  39.         sscanf(s, "%lf", &gCimag);
  40.     
  41.     gCenterX = gXmax - (gXmax - gXmin)/2.0;
  42.     gCenterY = gYmax - (gYmax - gYmin)/2.0;
  43. }
  44.  
  45.  
  46. void WriteCoords(void)
  47. {
  48.     Str255 s;
  49.     int itemType;
  50.     Handle h;
  51.     Rect box;
  52.     
  53.     sprintf( (char*)s, "%lf", gXmin);
  54.     CtoPstr(s);
  55.     GetDItem( gControlDialog, kETXMin, &itemType, &h, &box);
  56.     SetIText( h, s);
  57.  
  58.     sprintf( (char*)s, "%lf", gXmax);
  59.     CtoPstr(s);
  60.     GetDItem( gControlDialog, kETXMax, &itemType, &h, &box);
  61.     SetIText( h, s);
  62.  
  63.     sprintf( (char*)s, "%lf", gYmin);
  64.     CtoPstr(s);
  65.     GetDItem( gControlDialog, kETYMin, &itemType, &h, &box);
  66.     SetIText( h, s);
  67.  
  68.     sprintf( (char*)s, "%lf", gYmax);
  69.     CtoPstr(s);
  70.     GetDItem( gControlDialog, kETYMax, &itemType, &h, &box);
  71.     SetIText( h, s);
  72.  
  73.     sprintf( (char*)s, "%lf", gCreal);
  74.     CtoPstr(s);
  75.     GetDItem( gControlDialog, kETCreal, &itemType, &h, &box);
  76.     SetIText( h, s);
  77.  
  78.     sprintf( (char*)s, "%lf", gCimag);
  79.     CtoPstr(s);
  80.     GetDItem( gControlDialog, kETCimag, &itemType, &h, &box);
  81.     SetIText( h, s);
  82.  
  83. } // WriteCoords()
  84.  
  85.  
  86.  
  87. // ----------------  dialog stuff here
  88.  
  89. void Error( int s1, int s2, int s3, int s4, int severity)
  90. // display error msgs.
  91. // All errors use the same ALRT resource (kErrAlrt)
  92. // and s1 - s4 are the STR# indices to use for ParamText()
  93. // severity is the icon # to use for the alert box
  94. {
  95.     Str255 p1, p2, p3, p4;
  96.     
  97.     GetIndString( &p1, kErrStrList, s1);
  98.     GetIndString( &p2, kErrStrList, s2);
  99.     GetIndString( &p3, kErrStrList, s3);
  100.     GetIndString( &p4, kErrStrList, s4);
  101.     ParamText( p1, p2, p3, p4);
  102.     switch (severity) {
  103.     case stopIcon:
  104.         (void)StopAlert( kErrAlertID, NULL);
  105.         break;
  106.     case cautionIcon:
  107.         (void)CautionAlert( kErrAlertID, NULL);
  108.         break;
  109.     case noteIcon:
  110.     default:
  111.         (void)NoteAlert( kErrAlertID, NULL);
  112.         break;
  113.     } // switch
  114.  
  115. } // Error()
  116.  
  117.  
  118. void UserItem(DialogPtr theDialog,short itemNum,void *theProc)
  119. {
  120.     short    aType;
  121.     Rect    aBox;
  122.     Handle    theItem;
  123.  
  124.     GetDItem(theDialog,itemNum,&aType,&theItem,&aBox);
  125.     SetDItem(theDialog,itemNum,aType,(Handle)theProc,&aBox);
  126. } // UserItem()
  127.  
  128.  
  129. pascal void BoxItem(WindowPtr theWindow,short itemNum)
  130. {
  131.     short    aType;
  132.     Rect    theBox;
  133.     Handle    aHandle;
  134.  
  135.     GetDItem(theWindow,itemNum,&aType,&aHandle,&theBox);
  136.     PenNormal();
  137.     ForeColor(blackColor);
  138.     
  139.     FrameRect(&theBox);
  140. }  // BoxItem()
  141.  
  142.  
  143. pascal void OutlineButton(DialogPtr theDialog, short itemNum)
  144. {
  145.     short    aType;
  146.     Rect    box;
  147.     Handle    h;
  148.     
  149.     GetDItem( theDialog, itemNum, &aType, &h, &box);
  150.     SetPort( (GrafPtr)theDialog);
  151.     PenNormal();
  152.     PenSize(3,3);
  153.     FrameRoundRect( &box, 16, 16);
  154. } // DefaultButton()
  155.  
  156.  
  157. // --------------------
  158. void Print(char *s)
  159. // prints the C string to the gSelectWindow
  160. {
  161.     static int y=0;
  162.     int maxy;
  163.     GrafPtr savedPort;
  164.  
  165.     GetPort(&savedPort);
  166.     SetPort(gSelectWindow);
  167.     
  168.     if (s == (char*)0)
  169.     {
  170.         y = 0;
  171.         EraseRect(&gSelectWindow->portRect);
  172.     }
  173.     else
  174.     {
  175.         maxy = gSelectWindow->portRect.bottom;
  176.         y += gPrintY;  // initial pen positions
  177.         if (y > maxy)
  178.         {    y=gPrintY;
  179.             EraseRect(&(gSelectWindow->portRect));
  180.         }
  181.         MoveTo(0,y);
  182.         DrawText(s, 0, strlen(s));
  183.     }
  184.     
  185.     SetPort(savedPort);
  186. } // Print()
  187.  
  188.  
  189. MathType dabs(MathType x)
  190. {
  191.     if (x < 0.0)
  192.         return 0.0-x;
  193.     else
  194.         return x;
  195. }
  196.  
  197.