home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / VCDemo / Source / TestFunctions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-13  |  5.6 KB  |  235 lines  |  [TEXT/MPS ]

  1. /*
  2.     TestFunctions.c
  3.  
  4.     Functions for the Test menu commands.
  5.  
  6.     © 1995 Apple Computer, Inc.
  7. */
  8. #include <Types.h>
  9. #include <QuickDraw.h>
  10. #include <Dialogs.h>
  11. #include <Memory.h>
  12. #include <Windows.h>
  13.  
  14. #include <Files.h>
  15. #include <TextUtils.h>
  16. #include <ColorPicker.h>
  17.  
  18. #include "EventLoop.h"
  19. #include "MenuDispatch.h"
  20. #include "QD3DViewer.h"
  21.  
  22. PicHandle    gPicture;
  23. extern WindowPtr        MainView;
  24.  
  25. void    ChooseTest(short item);
  26. pascal void DrawPictureItem(WindowPtr theWindow, short itemNo);
  27. void    DoInfoDialog(Str255 str1, Str255 str2, Str255 str3, Str255 str4, Str255 strPrompt);
  28. void    DoBoundsInfoDialog(Rect *bounds, Str255 strPrompt);
  29.  
  30. enum
  31. {
  32.     tcItemOK        = 1,
  33.     tcItemText1,
  34.     tcItemText2,
  35.     tcItemPict
  36. };
  37.  
  38. void ChooseTest(short item)
  39. {
  40.     short            iType, itemHit;
  41.     Handle            iHandle;
  42.     Rect            iRect;
  43.     DialogPtr        testDialog;
  44.     OSErr            anErr = noErr;
  45.     unsigned long    width, height;
  46.     Str255            widthStr, heightStr;
  47.     Rect            bounds;
  48.     TVCDemoDataHdl    demoData;
  49.     TQ3ViewerObject    aViewer;
  50.  
  51.     if (FrontWindow() != MainView)
  52.         goto ExitChooseTest;
  53.     demoData = (TVCDemoDataHdl)GetWRefCon(MainView);
  54.     aViewer = (*demoData)->viewer1;
  55.     switch(item)
  56.     {
  57.         case cmdGetPicture:
  58.         {
  59.             PicHandle    aPicture;
  60.             UserItemUPP    userItemUPP;
  61.  
  62.             aPicture = Q3ViewerGetPict(aViewer);     /* get a picture of the view */
  63.             if (aPicture)
  64.             {
  65.                 gPicture = aPicture;
  66.     
  67.                     // Display the picture
  68.                 testDialog = GetNewDialog(GETINFO_ID, nil, (WindowPtr)-1);
  69.                 ParamText("\p", "\p", "\p", "\p");
  70.                 GetDialogItem(testDialog, tcItemText1, &iType, &iHandle, &iRect);
  71.                 SetDialogItemText(iHandle, "\pGet Picture");
  72.                 GetDialogItem(testDialog, tcItemPict, &iType, &iHandle, &iRect);
  73.                 userItemUPP = NewUserItemProc(DrawPictureItem);
  74.                 SetDialogItem(testDialog, tcItemPict, iType, (Handle)userItemUPP, &iRect);
  75.                 ShowWindow(testDialog);
  76.                 do
  77.                 {
  78.                     ModalDialog(nil, &itemHit);
  79.                 } while (itemHit != tcItemOK);
  80.                 DisposeDialog(testDialog);
  81.                 DisposeRoutineDescriptor(userItemUPP);
  82.                 KillPicture(aPicture);
  83.                 gPicture = nil;
  84.             }
  85.             break;
  86.         }
  87.  
  88.         case cmdGetDimensions:
  89.         {
  90.             anErr = Q3ViewerGetDimension(aViewer, &width, &height);
  91.  
  92.             NumToString(width, widthStr);
  93.             NumToString(height, heightStr);
  94.  
  95.             DoInfoDialog(widthStr, heightStr, "\p", "\p", "\pGet Dimensions (width, height)");
  96.             break;
  97.         }
  98.         
  99.         case cmdGetCameraRect:
  100.         {
  101.             anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonCamera, &bounds);
  102.             DoBoundsInfoDialog(&bounds, "\pGet Camera Button Rect (top, left, bottom, right)");
  103.             break;
  104.         }
  105.         case cmdGetTruckRect:
  106.         {
  107.             anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonTruck, &bounds);
  108.             DoBoundsInfoDialog(&bounds, "\pGet Truck Button Rect (top, left, bottom, right)");
  109.             break;
  110.         }
  111.         case cmdGetOrbitRect:
  112.         {
  113.             anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonOrbit, &bounds);
  114.             DoBoundsInfoDialog(&bounds, "\pGet Orbit Button Rect (top, left, bottom, right)");
  115.             break;
  116.         }
  117.         case cmdGetZoomRect:
  118.         {
  119.             anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonZoom, &bounds);
  120.             DoBoundsInfoDialog(&bounds, "\pGet Zoom Button Rect (top, left, bottom, right)");
  121.             break;
  122.         }
  123.         case cmdGetDollyRect:
  124.         {
  125.             anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonDolly, &bounds);
  126.             DoBoundsInfoDialog(&bounds, "\pGet Dolly Button Rect (top, left, bottom, right)");
  127.             break;
  128.         }
  129.         
  130.         case cmdGetBounds:
  131.         {
  132.             anErr = Q3ViewerGetBounds(aViewer, &bounds);
  133.             DoBoundsInfoDialog(&bounds, "\pGet Bounds (top, left, bottom, right)");
  134.             break;
  135.         }
  136.  
  137.         case cmdSetBounds:
  138.             break;
  139.  
  140.         case cmdGetBackgroundColor:
  141.             break;
  142.  
  143.         case cmdSetBackgroundColor:
  144.         {
  145.             Point            where = {-1, -1};
  146.             RGBColor        oldBColor, newBColor;
  147.             TQ3ColorARGB    qOldBColor, qNewBColor;
  148.  
  149.             Q3ViewerGetBackgroundColor(aViewer, &qOldBColor);
  150.             oldBColor.red = qOldBColor.r * 65535.0;
  151.             oldBColor.green = qOldBColor.g * 65535.0;
  152.             oldBColor.blue = qOldBColor.b * 65535.0;
  153.             if (GetColor(where, "\pPick a background color:", &oldBColor, &newBColor))
  154.             {
  155.                 qNewBColor.a = 1;
  156.                 qNewBColor.r = newBColor.red / 65535.0;
  157.                 qNewBColor.g = newBColor.green / 65535.0;
  158.                 qNewBColor.b = newBColor.blue / 65535.0;
  159.                 Q3ViewerSetBackgroundColor(aViewer, &qNewBColor);
  160.             }
  161.             break;
  162.         }
  163.  
  164.         case cmdUseBoxData:
  165.         case cmdUseGroupData:
  166.         case cmdVerifyGroupData:
  167.         case cmdResetPort:
  168.             break;
  169.         case cmdWriteHandle: 
  170.         {
  171.             Handle data;
  172.             unsigned long size;
  173.             
  174.             size = Q3ViewerWriteData (aViewer, (void **)&data);
  175.             size = GetHandleSize(data);
  176.             size = size+1;
  177.             break;
  178.         }
  179.         case cmdNormalMemory:
  180.         case cmdPig500:
  181.         case cmdPig100:
  182.             break;
  183.         default:            break;
  184.     }
  185. ExitChooseTest:
  186.     ;
  187. }
  188.  
  189.  
  190. pascal void DrawPictureItem(WindowPtr theWindow, short itemNo)
  191. {
  192.     short    iType;
  193.     Handle    iHandle;
  194.     Rect    iRect, picRect;
  195.  
  196.     GetDialogItem(theWindow, itemNo, &iType, &iHandle, &iRect);
  197.     picRect = (*gPicture)->picFrame;
  198.     OffsetRect(&picRect, -picRect.left, -picRect.top);
  199.     OffsetRect(&picRect, iRect.left, iRect.top);
  200.     DrawPicture(gPicture, &picRect);
  201. }
  202.  
  203. void    DoInfoDialog(Str255 str1, Str255 str2, Str255 str3, Str255 str4, Str255 strPrompt)
  204. {
  205.     short        iType, itemHit;
  206.     Handle        iHandle;
  207.     Rect        iRect;
  208.     DialogPtr    testDialog;
  209.     OSErr        anErr = noErr;
  210.  
  211.     testDialog = GetNewDialog(GETINFO_ID, nil, (WindowPtr)-1);
  212.     ParamText(str1, str2, str3, str4);
  213.     GetDialogItem(testDialog, tcItemText1, &iType, &iHandle, &iRect);
  214.     SetDialogItemText(iHandle, strPrompt);
  215.     ShowWindow(testDialog);
  216.     do
  217.         ModalDialog(nil, &itemHit);
  218.     while (itemHit != tcItemOK);
  219.     DisposeDialog(testDialog);
  220. }
  221.  
  222. void    DoBoundsInfoDialog(Rect *bounds, Str255 strPrompt)
  223. {
  224.     Str255        topStr, leftStr, rightStr, bottomStr;
  225.  
  226.     NumToString(bounds->top, topStr);
  227.     NumToString(bounds->left, leftStr);
  228.     NumToString(bounds->bottom, bottomStr);
  229.     NumToString(bounds->right, rightStr);
  230.  
  231.     DoInfoDialog(topStr, leftStr, bottomStr, rightStr, strPrompt);
  232. }
  233.  
  234. /* EOF */
  235.