home *** CD-ROM | disk | FTP | other *** search
- /* macdialog.c
- *
- * A collection of routines for the handling of the various settings and dialog boxes which
- * are used to "Mac"ify rayshade.
- *
- */
-
- #include <MacHeaders>
- #include <Dialogs.h>
- #include <Picker.h>
-
- #include "geom.h"
- #include "rayshade.h"
- #include "options.h"
- #include "viewing.h"
-
- #include "macdialog.h"
-
- short magx = 1, magy = 1 ;
-
- extern DialogPtr editorDialog ;
- extern RSOptions Options ;
- extern Geom *CreateProtoObject(short type, char *name) ;
- extern Geom *GetCurrentParent() ;
- extern Vector crosshair;
-
- void aboutDialog()
- {
- DialogPtr aboutDialog;
- short i ;
- char done = FALSE;
-
- aboutDialog = GetNewDialog(aboutboxR, NULL, (WindowPtr)-1);
- ShowWindow(aboutDialog);
- DrawDialog(aboutDialog) ;
- SetPort(aboutDialog);
- GetClick();
- DisposDialog(aboutDialog);
- }
-
- char GetGridSize(int *x, int *y, int *z)
- {
- DialogPtr sizeDialog ;
- short hitItem ;
-
- sizeDialog = GetNewDialog(gridsizeR, 0L, (WindowPtr)-1);
-
- SetIntEditText(sizeDialog,gridxBU,0) ;
- SetIntEditText(sizeDialog,gridyBU,0) ;
- SetIntEditText(sizeDialog,gridzBU,0) ;
- DrawDialog(sizeDialog) ;
- DrawHilite(sizeDialog, griduseBU) ;
- do {
- ModalDialog(NULL, &hitItem);
- switch(hitItem) {
- case griduseBU:
- if(GetIntEditText(sizeDialog, gridxBU, x) &&
- GetIntEditText(sizeDialog, gridyBU, y) &&
- GetIntEditText(sizeDialog, gridzBU, z) &&
- (*x >0) && (*y >0) && (*z >0)) {
- DisposDialog(sizeDialog);
- return 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- }
- } while (1);
- }
-
- char GetFrameRange(int *start, int *end)
- {
- DialogPtr frameDialog ;
- short hitItem ;
- int ns,ne ;
-
- ns = Options.startframe ;
- ne = Options.endframe ;
-
- frameDialog = GetNewDialog(framessetR, 0L, (WindowPtr)-1);
-
- SetIntEditText(frameDialog,framestartET,ns) ;
- SetIntEditText(frameDialog,frameendET,ne) ;
- DrawDialog(frameDialog) ;
- DrawHilite(frameDialog, frameuseBU) ;
- do {
- ModalDialog(NULL, &hitItem);
- switch(hitItem) {
- case frameuseBU:
- if(GetIntEditText(frameDialog, framestartET, &ns) &&
- GetIntEditText(frameDialog, frameendET, &ne) &&
- (ne >= ns) &&
- (ns >= Options.startframe) &&
- (ne <= Options.endframe)) {
- *start = ns ;
- *end = ne ;
- DisposDialog(frameDialog);
- return 1 ;
- }
- else
- SysBeep(1) ;
- break ;
- case framecancelBU:
- *start = Options.startframe ;
- *end = Options.endframe ;
- DisposDialog(frameDialog);
- return 0 ;
- break ;
- }
- } while (1);
- }
-
- /* Use the Macintosh ColorPicker to modify a Rayshade colour */
- void PickColour(Color *col)
- {
- RGBColor in, out ;
- static Point pickerPos = { 50,50 } ;
-
- in.red = (unsigned short) (col->r * 65535.) ;
- in.green = (unsigned short) (col->g * 65535.) ;
- in.blue = (unsigned short) (col->b * 65535.) ;
- out = in ;
- if(GetColor(pickerPos,"\pPick a new value", &in, &out)) {
- col->r = ((Float) out.red) /65535.0 ;
- col->g = ((Float) out.green) /65535.0 ;
- col->b = ((Float) out.blue) /65535.0 ;
- }
- }
-
- void CreateNewObject()
- {
- static Str255 name ;
- ControlHandle handle ;
- Handle tempHandle ;
- DialogPtr myDialog = 0L;
- Rect tempRect ;
- static short namenumber = 0 ;
- short hitItem = 0, tempItem, tempType;
- Geom *obj, *parent ;
- char exit = 0 ;
- GrafPtr currPort;
-
- myDialog = GetNewDialog(newobjectR, 0L, (WindowPtr)-1);
-
- sprintf(&name[1],"object%d",namenumber) ;
- name[0] = strlen(&name[1]) ;
- GetDItem(myDialog,objectnameET,&tempType,&tempHandle,&tempRect) ;
- SetIText(tempHandle,&name) ;
-
- SelIText(myDialog, objectnameET, 0, 700) ;
- GetPort(&currPort);
- SetPort(myDialog);
- DrawDialog(myDialog);
- DrawHilite(myDialog,objectcancelBU) ;
- do {
- ModalDialog(NULL, &hitItem);
- switch(hitItem) {
- case objectcreateBU:
- handle = SnatchHandle(myDialog,objecttypeCI) ;
- GetIText(SnatchHandle(myDialog,objectnameET), name) ;
- parent = GetCurrentParent() ;
- name[name[0]+1] = '\0' ;
- obj = CreateProtoObject(GetCtlValue(handle),&name[1]) ;
- if(obj && parent) {
- LinkObject(obj,parent) ;
- ReComputeBounds(obj);
- }
- namenumber++;
- exit = 1 ;
- break ;
- case objectcancelBU:
- exit = 1 ;
- break ;
- }
- } while (!exit);
- DisposDialog(myDialog);
- if(editorDialog) {
- SetPort(editorDialog);
- InvalRect(&editorDialog->portRect) ;
- }
- SetPort(currPort);
- }
-
- /*
- * Set the camera angle, tree depth, rays per pixel, and jittering from a dialog box
- * This function is equivalent to the command line parameters on the unix
- */
- void SetRenderOptions()
- {
- ControlHandle handle ;
- Handle tempHandle ;
- Rect r, tempRect ;
- short itype ;
- Point pos ;
- int jitter, samples, partcode, shadows, maxdepth, barcode ;
- Str255 message ;
- Str31 myStr ;
- DialogPtr myDialog = 0L;
- ControlHandle temp ;
- short hitItem = 0, tempItem;
- char exit = 0 ;
-
- if(Options.samples < 1) Options.samples = 1 ;
- if(Options.samples > 8) Options.samples = 8 ;
- if(Options.maxdepth > 9) Options.maxdepth = 9 ;
- if(Options.maxdepth < 0) Options.maxdepth = 0 ;
-
- shadows = !Options.no_shadows ;
- maxdepth = Options.maxdepth ;
- jitter = Options.jitter ;
- samples = Options.samples ;
-
- myDialog = GetNewDialog(renderoptionsR, 0L, (WindowPtr)-1);
- /* Set switches to correct values */
- SetCtlMin(SnatchHandle(myDialog,rayspixelSB),1) ;
- SetCtlMax(SnatchHandle(myDialog,rayspixelSB),8) ;
-
- SetCtlValue(SnatchHandle(myDialog,jitterCB),(short)jitter) ;
- SetCtlValue(SnatchHandle(myDialog,shadowsCB),(short)shadows) ;
- SetCtlValue(SnatchHandle(myDialog,treedepthSB),(short)maxdepth) ;
- SetCtlValue(SnatchHandle(myDialog,rayspixelSB),(short)samples) ;
-
- GetDItem(myDialog,treedepthET,&itype,&tempHandle,&r) ;
- message[0] = 1 ; message[1] = (char) maxdepth + '0' ;
- SetIText(tempHandle,&message) ;
- GetDItem(myDialog,rayspixelET,&itype,&tempHandle,&r) ;
- message[0] = 1 ; message[1] = (char) samples + '0' ;
- SetIText(tempHandle,&message) ;
-
- DrawDialog(myDialog);
- DrawHilite(myDialog,useBU) ;
- do {
- ModalDialog((ModalFilterProcPtr)renderoptionsfilter, &hitItem);
- switch(hitItem) {
- case rayspixelET:
- GetDItem(myDialog, rayspixelET, &tempItem, &tempHandle, &tempRect) ;
- GetIText(tempHandle, myStr) ;
- samples = myStr[0] ? myStr[1] - '0' : 1 ;
- SetCtlValue(SnatchHandle(myDialog,rayspixelSB), samples) ;
- break ;
- case treedepthET:
- GetDItem(myDialog, treedepthET, &tempItem, &tempHandle, &tempRect) ;
- GetIText(tempHandle, myStr) ;
- maxdepth = myStr[0] ? myStr[1] - '0' : 0 ;
- SetCtlValue(SnatchHandle(myDialog,treedepthSB), maxdepth) ;
- break ;
- case jitterCB:
- jitter = (jitter) ? 0 : 1 ;
- SetCtlValue(SnatchHandle(myDialog,jitterCB), jitter) ;
- break ;
- case shadowsCB:
- shadows = (shadows) ? 0 : 1 ;
- SetCtlValue(SnatchHandle(myDialog,shadowsCB), shadows) ;
- break ;
- case screenBU:
- SetScreenOptions() ;
- DrawHilite(myDialog,useBU) ;
- break ;
- case cameraBU:
- SetCameraOptions() ;
- DrawHilite(myDialog,useBU) ;
- break ;
- case cancelBU:
- /* Easy this one... */
- exit = 1 ;
- break ;
- case rayspixelSB:
- GetMouse(&pos) ;
- handle = SnatchHandle(myDialog,rayspixelSB) ;
- partcode = TestControl(handle,pos) ;
- switch(partcode) {
- case inUpButton: SetCtlValue(handle,GetCtlValue(handle)-1) ; break ;
- case inDownButton: SetCtlValue(handle,GetCtlValue(handle)+1) ; break ;
- case inPageUp: SetCtlValue(handle,GetCtlValue(handle)-1) ; break ;
- case inPageDown: SetCtlValue(handle,GetCtlValue(handle)+1) ; break ;
- }
- samples = GetCtlValue(handle) ;
- SetIntEditText(myDialog,rayspixelET,samples) ;
- break ;
- case treedepthSB:
- GetMouse(&pos) ;
- handle = SnatchHandle(myDialog,treedepthSB) ;
- partcode = TestControl(handle,pos) ;
- switch(partcode) {
- case inUpButton: SetCtlValue(handle,GetCtlValue(handle)-1) ; break ;
- case inDownButton: SetCtlValue(handle,GetCtlValue(handle)+1) ; break ;
- case inPageUp: SetCtlValue(handle,GetCtlValue(handle)-1) ; break ;
- case inPageDown: SetCtlValue(handle,GetCtlValue(handle)+1) ; break ;
- }
- maxdepth = GetCtlValue(handle) ;
- SetIntEditText(myDialog,treedepthET,maxdepth) ;
- break ;
- case defaultBU:
- /* Stick some default options into RSOptions */
- Options.no_shadows = TRUE;
- Options.maxdepth = 0;
- Options.maxdepth_set = TRUE;
- Options.jitter = TRUE;
- Options.jitter_set = TRUE;
- Options.samples = 1;
- Options.samples_set = TRUE;
- case useBU:
- Options.no_shadows = !shadows;
- Options.maxdepth = maxdepth;
- Options.maxdepth_set = TRUE;
- Options.jitter = jitter;
- Options.jitter_set = TRUE;
- Options.samples = samples;
- Options.samples_set = TRUE;
- exit = 1 ;
- break ;
- } ;
- } while (!exit);
- DisposDialog(myDialog);
- }
-
- pascal Boolean
- renderoptionsfilter(DialogPtr dialer, EventRecord *myDialogEvent, short *theDialogItem)
- {
- WindowPtr temp;
- char theKey;
- Rect tempRect;
- short tempItem, myItem;
- Handle tempHandle;
- long tilticks;
- Boolean returnVal = false;
- Str31 myStr;
- short myitem ;
-
- GetPort(&temp);
- SetPort(dialer);
- myItem = ((DialogPeek)dialer)->editField + 1 ;
- /* Some key filtering schemes follow. The first is the standard filter to
- * recognize 'return' as Use and 'ESC' as Cancel.
- */
-
- if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey)) {
- theKey = myDialogEvent->message & charCodeMask;
- switch (theKey) {
- case kReturnKey:
- case kEnterKey:
- *theDialogItem = useBU ;
- HiliteControl(SnatchHandle(dialer, useBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, useBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kEscKey:
- *theDialogItem = cancelBU;
- HiliteControl(SnatchHandle(dialer, cancelBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, cancelBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kTabKey:
- returnVal = false ;
- break ;
- default:
- /* All non numeric key presses are removed here and a beep is sounded */
- if((myItem == rayspixelET) || (myItem == treedepthET)) {
- if((myItem == rayspixelET) && (!isdigit(theKey) || (theKey == '9') ||
- (theKey=='0')) && !IsEditKey(theKey)) {
- SysBeep(1);
- returnVal = true ;
- }
- else if((myItem == treedepthET) && !isdigit(theKey) && !IsEditKey(theKey)) {
- SysBeep(1);
- returnVal = true ;
- }
- else {
- GetDItem(dialer, myItem, &tempItem, &tempHandle, &tempRect);
- GetIText(tempHandle, myStr);
-
- if (myStr[0] > 0) {
- if (IsEditKey(theKey))
- returnVal = false;
- else {
- SysBeep(1);
- returnVal = true;
- }
- }
-
- }
- }
- break ;
- }
- }
- return(returnVal);
- }
-
- void SetMagnificationButtons(DialogPtr myDialog, short mx, short my)
- {
- SetCtlValue(SnatchHandle(myDialog,onebyonemagRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twobytwomagRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,fourbyfourmagRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,eightbyeightmagRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,sixteenbysixteenmagRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,thirtytwobythirtytwomagRB), 0) ;
-
- if((mx==1)&&(my==1))
- SetCtlValue(SnatchHandle(myDialog,onebyonemagRB), 1) ;
- else if((mx==2)&&(my==2))
- SetCtlValue(SnatchHandle(myDialog,twobytwomagRB), 1) ;
- else if((mx==4)&&(my==4))
- SetCtlValue(SnatchHandle(myDialog,fourbyfourmagRB), 1) ;
- else if((mx==8)&&(my==8))
- SetCtlValue(SnatchHandle(myDialog,eightbyeightmagRB), 1) ;
- else if((mx==16)&&(my==16))
- SetCtlValue(SnatchHandle(myDialog,sixteenbysixteenmagRB), 1) ;
- else
- SetCtlValue(SnatchHandle(myDialog,thirtytwobythirtytwomagRB), 1) ;
- }
-
- /*
- * Set the screen rendering dimensions
- */
- void SetScreenOptions()
- {
- ControlHandle handle ;
- Handle tempHandle ;
- Rect r, tempRect ;
- short itype ;
- Str255 output ;
- DialogPtr myDialog = 0L;
- ControlHandle temp ;
- short hitItem = 0, tempItem, mx, my;
- int screenx, screeny, tmpx, tmpy ;
- char myStr[30] ;
- char exit = 0 ;
-
- mx = magx ; my = magy ;
- if(!Options.resolution_set) {
- screenx = 50 ;
- screeny = 50 ;
- }
- else {
- screenx = Screen.xres ;
- screeny = Screen.yres;
- }
- myDialog = GetNewDialog(screenoptionsR, 0L, (WindowPtr)-1);
-
- /* Set all radios buttons to zero... */
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 0) ;
-
- SetIntEditText(myDialog, customxET, screenx) ;
- SetIntEditText(myDialog, customyET, screeny) ;
-
- /* Now set correct radio button for screen dimensions */
- if((screenx == 50) && (screeny == 50))
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 1) ;
- else if((screenx == 100) && (screeny == 100))
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 1) ;
- else if((screenx == 200) && (screeny == 200))
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 1) ;
- else {
- /* Set radio button here and also set editable text fields correctly */
- SetCtlValue(SnatchHandle(myDialog,customRB), 1) ;
- }
-
- SetMagnificationButtons(myDialog, mx, my) ;
-
- DrawDialog(myDialog);
- DrawHilite(myDialog,screenuseBU) ;
- do {
- ModalDialog((ModalFilterProcPtr)screenoptionsfilter, &hitItem);
-
- switch(hitItem) {
- case onebyonemagRB:
- mx = 1 ; my = 1 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case twobytwomagRB:
- mx = 2 ; my = 2 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case fourbyfourmagRB:
- mx = 4 ; my = 4 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case eightbyeightmagRB:
- mx = 8 ; my = 8 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case sixteenbysixteenmagRB:
- mx = 16 ; my = 16 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case thirtytwobythirtytwomagRB:
- mx = 32 ; my = 32 ;
- SetMagnificationButtons(myDialog, mx, my) ;
- break ;
- case fiftybyfiftyRB:
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 1) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 0) ;
- screenx = 50 ; screeny = 50 ;
- SetIntEditText(myDialog, customxET, screenx) ;
- SetIntEditText(myDialog, customyET, screeny) ;
- break ;
- case hundredbyhundredRB:
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 1) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 0) ;
- screenx = 100 ; screeny = 100 ;
- SetIntEditText(myDialog, customxET, screenx) ;
- SetIntEditText(myDialog, customyET, screeny) ;
- break ;
- case twohundredbytwohundredRB:
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 1) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 0) ;
- screenx = 200 ; screeny = 200 ;
- SetIntEditText(myDialog, customxET, screenx) ;
- SetIntEditText(myDialog, customyET, screeny) ;
- break ;
- case customRB:
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 1) ;
- GetDItem(myDialog,customxET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; screenx = atoi(&output[1]);
- GetDItem(myDialog,customyET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; screeny = atoi(&output[1]);
- break ;
- case customxET:
- case customyET:
- GetDItem(myDialog,customxET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; tmpx = atoi(&output[1]);
- GetDItem(myDialog,customyET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; tmpy = atoi(&output[1]);
- if((tmpy != screeny) || (tmpx != screenx)) {
- screenx = tmpx ;
- screeny = tmpy ;
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 0) ;
- SetCtlValue(SnatchHandle(myDialog,customRB), 0) ;
- if((screenx == 50) && (screeny == 50))
- SetCtlValue(SnatchHandle(myDialog,fiftybyfiftyRB), 1) ;
- else if((screenx == 100) && (screeny == 100))
- SetCtlValue(SnatchHandle(myDialog,hundredbyhundredRB), 1) ;
- else if((screenx == 200) && (screeny == 200))
- SetCtlValue(SnatchHandle(myDialog,twohundredbytwohundredRB), 1) ;
- else
- SetCtlValue(SnatchHandle(myDialog,customRB), 1) ;
- }
- break ;
- case screencancelBU:
- /* Easy this one... */
- exit = 1 ;
- break ;
- case screenuseBU:
- GetDItem(myDialog,customxET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; screenx = atoi(&output[1]);
- GetDItem(myDialog,customyET,&itype,&tempHandle,&r) ;
- GetIText(tempHandle, output) ;
- output[output[0]+1] = '\0' ; screeny = atoi(&output[1]);
- Screen.xres = screenx ;
- Screen.yres = screeny ;
- Options.resolution_set = TRUE;
- magx = mx ;
- magy = my ;
- exit = 1 ;
- break ;
- } ;
- } while (!exit);
- DisposDialog(myDialog);
- }
-
- pascal Boolean
- screenoptionsfilter(DialogPtr dialer, EventRecord *myDialogEvent, short *theDialogItem)
- {
- WindowPtr temp;
- char theKey;
- Rect tempRect;
- short tempItem, myItem;
- Handle tempHandle;
- long tilticks;
- Boolean returnVal = false;
- Str31 myStr;
- short myitem ;
-
- GetPort(&temp);
- SetPort(dialer);
- myItem = ((DialogPeek)dialer)->editField + 1 ;
- /* Some key filtering schemes follow. The first is the standard filter to
- * recognize 'return' as Use and 'ESC' as Cancel.
- */
-
- if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey)) {
- theKey = myDialogEvent->message & charCodeMask;
- switch (theKey) {
- case kReturnKey:
- case kEnterKey:
- *theDialogItem = screenuseBU ;
- HiliteControl(SnatchHandle(dialer, screenuseBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, screenuseBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kEscKey:
- *theDialogItem = screencancelBU;
- HiliteControl(SnatchHandle(dialer, screencancelBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, screencancelBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kTabKey:
- returnVal = false ;
- break ;
- default:
- /* All non numeric key presses are removed here and a beep is sounded */
- if((myItem == customxET) || (myItem == customyET)) {
- if(!isdigit(theKey) && !IsEditKey(theKey)) {
- SysBeep(1);
- returnVal = true ;
- }
- else {
- GetDItem(dialer, myItem, &tempItem, &tempHandle, &tempRect);
- GetIText(tempHandle, myStr);
-
- if (myStr[0] > 4) {
- if (IsEditKey(theKey))
- returnVal = false;
- else {
- SysBeep(1);
- returnVal = true;
- }
- }
-
- }
- }
- break ;
- }
- }
- return(returnVal);
- }
-
- /*
- * Set the camera position and direction
- */
- void SetCameraOptions()
- {
- GrafPtr currPort;
- ControlHandle handle ;
- Handle tempHandle ;
- Rect r, tempRect ;
- int itype ;
- Str255 output ;
- DialogPtr myDialog = 0L;
- ControlHandle temp ;
- short hitItem = 0, tempItem;
- char exit = 0 ;
- Vector pos, lookp, up, lookdir ;
- Float aperture, fov, focaldist ;
-
- pos = Camera.pos ;
- lookp = Camera.lookp ;
- up = Camera.up ;
- aperture = Camera.aperture ;
- fov = Camera.hfov ;
- focaldist = Camera.focaldist ;
-
- myDialog = GetNewDialog(cameraoptionsR, 0L, (WindowPtr)-1);
-
- SetFloatEditText(myDialog,observerxET,pos.x) ;
- SetFloatEditText(myDialog,observeryET,pos.y) ;
- SetFloatEditText(myDialog,observerzET,pos.z) ;
-
- SetFloatEditText(myDialog,targetxET,lookp.x) ;
- SetFloatEditText(myDialog,targetyET,lookp.y) ;
- SetFloatEditText(myDialog,targetzET,lookp.z) ;
-
- SetFloatEditText(myDialog,upvectorxET,up.x) ;
- SetFloatEditText(myDialog,upvectoryET,up.y) ;
- SetFloatEditText(myDialog,upvectorzET,up.z) ;
-
- SetFloatEditText(myDialog,apertureET,aperture) ;
- SetFloatEditText(myDialog,fieldofvisionET,fov) ;
- SetFloatEditText(myDialog,focaldistanceET,focaldist) ;
-
- GetPort(&currPort);
- SetPort(myDialog);
- DrawDialog(myDialog);
- DrawHilite(myDialog,camerauseBU) ;
- do {
- ModalDialog((ModalFilterProcPtr)cameraoptionsfilter, &hitItem);
-
- switch(hitItem) {
- case crosshair2observerBU:
- SetFloatEditText(myDialog,observerxET,crosshair.x) ;
- SetFloatEditText(myDialog,observeryET,crosshair.y) ;
- SetFloatEditText(myDialog,observerzET,crosshair.z) ;
- break;
- case crosshair2targetBU:
- SetFloatEditText(myDialog,targetxET,crosshair.x) ;
- SetFloatEditText(myDialog,targetyET,crosshair.y) ;
- SetFloatEditText(myDialog,targetzET,crosshair.z) ;
- break;
- case crosshair2upvectorBU:
- SetFloatEditText(myDialog,upvectorxET,crosshair.x) ;
- SetFloatEditText(myDialog,upvectoryET,crosshair.y) ;
- SetFloatEditText(myDialog,upvectorzET,crosshair.z) ;
- break;
- case cameracancelBU:
- /* Easy this one... */
- exit = 1 ;
- break ;
- case camerauseBU:
- if(GetFloatEditText(myDialog,observerxET,&pos.x) &&
- GetFloatEditText(myDialog,observeryET,&pos.y) &&
- GetFloatEditText(myDialog,observerzET,&pos.z) &&
- GetFloatEditText(myDialog,targetxET,&lookp.x) &&
- GetFloatEditText(myDialog,targetyET,&lookp.y) &&
- GetFloatEditText(myDialog,targetzET,&lookp.z) &&
- GetFloatEditText(myDialog,upvectorxET,&up.x) &&
- GetFloatEditText(myDialog,upvectoryET,&up.y) &&
- GetFloatEditText(myDialog,upvectorzET,&up.z) &&
- GetFloatEditText(myDialog,apertureET,&Camera.aperture) &&
- GetFloatEditText(myDialog,focaldistanceET,&Camera.focaldist) &&
- GetFloatEditText(myDialog,fieldofvisionET,&Camera.hfov)) {
- lookdir.x = lookp.x-pos.x;
- lookdir.y = lookp.y-pos.y;
- lookdir.z = lookp.z-pos.z;
- VecNormalize(&up);
- VecNormalize(&lookdir);
- if(equal(lookdir.x,up.x) && equal(lookdir.y,up.y) && equal(lookdir.z,up.z)) {
- RLerror(RL_WARN,"Look direction and up vector are identical !",0,0,0);
- break;
- }
- Camera.pos = pos;
- Camera.lookp = lookp;
- Camera.up = up;
- exit = 1 ;
- }
- else
- SysBeep(1);
- break ;
- } ;
- } while (!exit);
- DisposDialog(myDialog);
- if(editorDialog) {
- SetPort(editorDialog);
- InvalRect(&editorDialog->portRect) ;
- }
- SetPort(currPort);
- }
-
- pascal Boolean
- cameraoptionsfilter(DialogPtr dialer, EventRecord *myDialogEvent, short *theDialogItem)
- {
- WindowPtr temp;
- char theKey;
- Rect tempRect;
- short tempItem, myItem;
- Handle tempHandle;
- long tilticks;
- Boolean returnVal = false;
- Str31 myStr;
- short myitem ;
-
- GetPort(&temp);
- SetPort(dialer);
- myItem = ((DialogPeek)dialer)->editField + 1 ;
- /* Some key filtering schemes follow. The first is the standard filter to
- * recognize 'return' as Use and 'ESC' as Cancel.
- */
-
- if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey)) {
- theKey = myDialogEvent->message & charCodeMask;
- switch (theKey) {
- case kReturnKey:
- case kEnterKey:
- *theDialogItem = camerauseBU ;
- HiliteControl(SnatchHandle(dialer, camerauseBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, camerauseBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kEscKey:
- *theDialogItem = cameracancelBU;
- HiliteControl(SnatchHandle(dialer, cameracancelBU), inButton);
- Delay(8, &tilticks);
- HiliteControl(SnatchHandle(dialer, cameracancelBU), false);
- SetPort(temp);
- returnVal = true;
- break;
- case kTabKey:
- returnVal = false ;
- break ;
- default:
- /* All non numeric key presses are removed here and a beep is sounded */
- if(!isdigit(theKey) && !IsEditKey(theKey) && (theKey != '.') && (theKey != '-')) {
- SysBeep(1);
- returnVal = true ;
- }
- else {
- GetDItem(dialer, myItem, &tempItem, &tempHandle, &tempRect);
- GetIText(tempHandle, myStr);
-
- if (myStr[0] > 10) {
- if (IsEditKey(theKey))
- returnVal = false;
- else {
- SysBeep(1);
- returnVal = true;
- }
- }
- }
- break ;
- }
- }
- return(returnVal);
- }
-
- void RSAlert(type, pat, arg1, arg2, arg3)
- char *type, *pat, *arg1, *arg2, *arg3;
- {
- Str255 message ;
- DialogPtr alertDialog = 0L;
- Handle temp ;
- short hitItem = 0;
- Rect r ;
- short itype ;
-
- sprintf(&message[1], pat, arg1, arg2, arg3);
- message[0] = strlen(&message[1]) ;
- if(message[message[0]] == '\n') message[0]-- ;
- alertDialog = GetNewDialog(erroralertR, 0L, (WindowPtr)-1);
- DrawDialog(alertDialog);
- GetDItem(alertDialog,3,&itype,&temp,&r) ;
- SetIText(temp,&message) ;
- DrawHilite(alertDialog,1) ;
- do {
- ModalDialog(0L, &hitItem);
- } while (hitItem != 1);
- DisposDialog(alertDialog);
- }
-
- /* Dialog toolbox routines */
-
- /* Highlight a dialog item with a rounded rectangle */
- pascal void DrawHilite(DialogPtr theDialog, short itemNo)
- {
- PenState saveState;
- short itemType;
- Handle itemHandle;
- Rect itemBox;
- GrafPtr currPort ;
-
- GetPort(&currPort);
- SetPort(theDialog);
- GetDItem(theDialog, itemNo, &itemType, &itemHandle, &itemBox);
- GetPenState(&saveState);
- PenSize(3,3);
- InsetRect(&itemBox, -4, -4);
- FrameRoundRect(&itemBox, 16, 16);
- SetPenState(&saveState);
- SetPort(currPort) ;
- }
-
- /* Get the control handle for a dialog item */
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
- {
- short itemtype;
- Rect itemrect;
- Handle thandle;
-
- GetDItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
- return((ControlHandle)thandle);
- }
-
- /* Check to see if key is left arrow, delete, backspace etc */
- Boolean IsEditKey(char theKey)
- {
- register qq;
- char editChars[5] = {
- kLeftArrow, kUpArrow, kRightArrow, kDownArrow, kBackSpace
- };
- for (qq = 0; qq < 5; qq++) {
- if (theKey == editChars[qq])
- return(true);
- }
- return(false);
- }
-
- void SetFloatEditText(DialogPtr myDialog, short itemno, Float value)
- {
- Str255 number ;
- Rect itemRect ;
- ControlHandle itemHandle ;
- long itemType ;
-
- sprintf(&number[1],"%.3f",(float)value) ;
- number[0] = strlen(&number[1]) ;
- GetDItem(myDialog,itemno,&itemType,&itemHandle,&itemRect) ;
- SetIText(itemHandle,&number) ;
- }
-
- void SetFloatStringText(DialogPtr myDialog, short itemno, char *str, Float value)
- {
- Str255 number ;
- Rect itemRect ;
- ControlHandle itemHandle ;
- long itemType ;
-
- sprintf(&number[1],"%s %.3f",str,(float)value) ;
- number[0] = strlen(&number[1]) ;
- GetDItem(myDialog,itemno,&itemType,&itemHandle,&itemRect) ;
- SetIText(itemHandle,&number) ;
- }
-
-
- char GetFloatEditText(DialogPtr myDialog, short theItem, Float *value)
- {
- Str255 number ;
-
- GetIText(SnatchHandle(myDialog,theItem), number) ;
- return StrtoFloat(number,value) ;
- }
-
- char GetIntEditText(DialogPtr myDialog, short theItem, int *value)
- {
- Str255 number ;
-
- GetIText(SnatchHandle(myDialog,theItem), number) ;
- if(number[0]==0)
- return 0;
- else {
- StringToNum(number,value) ;
- return 1;
- }
- }
-
- void SetIntEditText(DialogPtr myDialog, short itemno, int value)
- {
- Str255 number ;
- Rect itemRect ;
- ControlHandle itemHandle ;
- long itemType ;
-
- sprintf(&number[1],"%d",value) ;
- number[0] = strlen(&number[1]) ;
- GetDItem(myDialog,itemno,&itemType,&itemHandle,&itemRect) ;
- SetIText(itemHandle,&number) ;
- }
-
- void SetIntStringText(DialogPtr myDialog, short itemno, char *str, int value)
- {
- Str255 number ;
- Rect itemRect ;
- ControlHandle itemHandle ;
- long itemType ;
-
- sprintf(&number[1],"%s %d",str,value) ;
- number[0] = strlen(&number[1]) ;
- GetDItem(myDialog,itemno,&itemType,&itemHandle,&itemRect) ;
- SetIText(itemHandle,&number) ;
- }
-
- int StrtoFloat(Str255 num, Float *result)
- {
- char *number;
- char len ;
-
- len = num[0] ;
- if(len == 0) return 0;
- number = &num[1] ;
- number[len] = '\0' ;
- return(sscanf(number,"%lf", result));
- }
-
- char ValidFloat(Float min, Float Max, Str255 num)
- {
- Float realnum;
-
- return (StrtoFloat(num, &realnum));
- }
-
- /* Wait for a mouse click from the user */
- void GetClick()
- {
- EventRecord e;
-
- while (!GetNextEvent(mDownMask, &e)) ;
- while (WaitMouseUp()) ;
- }