home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV-Ray
-
- Version: 3
-
- File: FilePrefs.c
-
- Description: File/rendering preferences dialog handling code
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 941230 [esp] Created
- 950514 [esp] Fixed outfile popup not being inited.
- 951014 [esp] Added a bunch of 3.0b2 fields.
- 960405 [esp] Added Restore Default button from user request (3.0b6c)
- 960518 [esp] Fixed bug where Animation not always updated properly
- ==============================================================================*/
-
- #define FILEPREFS_C
-
- #include "FilePrefs.h"
-
- /*==== Macintosh-specific headers ====*/
- #include <errors.h> /* dupFNErr, etc */
- #include <Resources.h>
- #include <Controls.h>
-
- #include "AppPrefs.h"
- #include "ScreenUtils.h" // ForceRectOnScreen
- #include "DialogUtils.h" // FlashDItem
- #include "Animate.h"
-
- // ---------------------------------------------------------------------
- //
- // Rendering Options Dialog items
- //
- #define kNoItemHit -1
- // Base DITL items, these never change
- #define kDLOG_RenderPrefsMain 3000 // base dialog/DITL ID
- #define kPU_Settings 4
- #define kCB_SaveAsDefault 5
- #define kPB_RestoreDefault 6
- #define kST_Filename 7
- #define kPC_SubBorder 15 // used to position sub-ditl relative
- #define kMainItem_Max kPC_SubBorder // used to figure ShortenDITL
-
- #define KDITL_RPInput kDLOG_RenderPrefsMain+1
- #define kPU_LangVersion kMainItem_Max+1
-
- #define KDITL_RPQuality KDITL_RPInput+1
- #define kPU_RenderQuality kMainItem_Max+1
- #define kPU_PreviewStart kMainItem_Max+2
- #define kPU_PreviewEnd kMainItem_Max+3
- #define kCB_DoAntiAlias kMainItem_Max+4
- #define kET_AntiAliasThresh kMainItem_Max+5
- #define kET_AntialiasDepth kMainItem_Max+6
- #define kET_AntiJitterScale kMainItem_Max+7
- #define kPU_AntialiasMethod kMainItem_Max+8
- #define kST_AntiAliasThresh kMainItem_Max+9
- #define kST_AntialiasDepth kMainItem_Max+10
- #define kST_AntiJitterScale kMainItem_Max+11
- #define kCB_RadQuality kMainItem_Max+12
-
- #define KDITL_RPOptimiz KDITL_RPQuality+1
- #define kPU_MaxBounds kMainItem_Max+1
- #define kCB_UseLBuffer kMainItem_Max+2
- #define kCB_UseVBuffer kMainItem_Max+3
- #define kCB_UseVDraw kMainItem_Max+4
- #define kCB_SplitUnions kMainItem_Max+5
- #define kCB_RemoveUnused kMainItem_Max+6
-
- #define KDITL_RPInfo KDITL_RPOptimiz+1
- #define kPU_Progress kMainItem_Max+1
- #define kCB_DoCreateIni kMainItem_Max+2
-
- #define KDITL_RPOutputSize KDITL_RPInfo+1
- #define kPU_ImageSize kMainItem_Max+1
- #define kET_ImageWidth kMainItem_Max+2
- #define kET_ImageHeight kMainItem_Max+3
- #define kET_ColFrom kMainItem_Max+4
- #define kET_ColTo kMainItem_Max+5
- #define kET_RowFrom kMainItem_Max+6
- #define kET_RowTo kMainItem_Max+7
-
- #define KDITL_RPOutputFile KDITL_RPOutputSize+1
- #define kET_PICTSig kMainItem_Max+1
- #define kPU_OutfileType kMainItem_Max+2
- #define kCB_ContinueFromTarga kMainItem_Max+3
- #define kET_TargaSig kMainItem_Max+4
- #define kPU_OutfileBuffSize kMainItem_Max+5
- #define kCB_DoHistFile kMainItem_Max+6
- #define kPU_HistFileType kMainItem_Max+7
- #define kPU_BitsPerColor kMainItem_Max+8
- #define kCB_DoAlphaChannel kMainItem_Max+9
-
- #define KDITL_RPAnimate KDITL_RPOutputFile+1
- #define kCB_Animate kMainItem_Max+1
- #define kST_FrameVal0 kMainItem_Max+2
- #define kET_FrameValS kMainItem_Max+3
- #define kET_FrameValE kMainItem_Max+4
- #define kET_FrameValN kMainItem_Max+5
- #define kET_ClockVal0 kMainItem_Max+6
- #define kST_ClockValS kMainItem_Max+7
- #define kST_ClockValE kMainItem_Max+8
- #define kET_ClockValN kMainItem_Max+9
- #define kPU_FieldRender kMainItem_Max+10
-
- // orphans for now...
- #define kCB_DoPICTCmp kMainItem_Max+1
- #define kBT_PICTCmpSettings kMainItem_Max+1
-
-
-
- /*==== globals ====*/
- file_prefs_hdl_t gFilePrefs_h = NULL; // each file has its own prefs
- file_prefs_hdl_t gPrefs2Use_h = NULL; // points to file or default prefs
-
- /*==== locals ====*/
- static short gSrcResRefNum = kRsrcFileClosed;
- static short gCurrDITLID = KDITL_RPOutputSize; // which pane are we in
- static short gPrevItemHit; // tracks previous item hit in dialog
-
- static short gSrc_wdrefnum;
- static StringPtr gSrc_fname;
- static file_prefs_rec_t gOrigPrefs; // remember old prefs in case of cancel
-
-
- // ---------------------------------------------------------------------
- // Should move this to DialogUtils...
- static void ShowHideDItem(DialogRef theDialog, short itemNo, Boolean showIt)
- {
- if (showIt)
- ShowDialogItem(theDialog, itemNo);
- else
- HideDialogItem(theDialog, itemNo);
- }
-
- // ---------------------------------------------------------------------
- // Determine height and width from item# of Image menu passed
- static void GetImageSizeOfItem(MenuRef imageMenuRef, short pItemNumber, short * pWidth, short * pHeight)
- {
- char itemText[63];
- char *itemTextPtr;
-
- // set the width/height invalid until properly read
- *pWidth = -1;
- *pHeight = -1;
-
- // get the text of the menu item as a C string
- GetMenuItemText(imageMenuRef, pItemNumber, (StringPtr)itemText);
- p2cstr((StringPtr)itemText);
- // convert the first ASCII number to a number
- *pWidth = atoi(itemText);
- // find the position of the second number (right after the "x")
- itemTextPtr = strchr(itemText, 'x');
- if (itemTextPtr != NULL)
- {
- // convert second ASCII number to a number
- itemTextPtr++; // skip the space after the 'x'
- *pHeight = atoi(itemTextPtr);
- }
- }
-
-
- // ---------------------------------------------------------------------
- // Determine closest index in the image menu to the h/v passed
- static short GetClosestImageSizeItem(WindowPtr dlgWindPtr, short pWidth, short pHeight)
- {
- short numItems=0;
- ControlHandle popupControlH;
- MenuRef imageMenuRef;
- int k;
-
- // get the popup menu control, then get menu handle from it
- popupControlH = (ControlHandle)GrabDItemHandle(dlgWindPtr, kPU_ImageSize);
- // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
- if (popupControlH)
- imageMenuRef = (MenuRef) (**(Handle**)(**popupControlH).contrlData);
-
- // go down the list & find a match
- if (imageMenuRef)
- numItems = CountMenuItems(imageMenuRef);
- for (k=1; k<=numItems; k++)
- {
- short itemWidth, itemHeight;
- // what's the size of this item?
- GetImageSizeOfItem(imageMenuRef, k, &itemWidth, &itemHeight);
- // if this item is just bigger than the user's item, return this index
- if ((itemWidth >= pWidth) && (itemHeight >= pHeight))
- return k; // return item #
- }
-
- // no match, return max
- return numItems;
- }
-
-
- // ---------------------------------------------------------------------
- // Open a source file's resource fork for getting/putting settings info
- static void FilePrefs_Open(short src_wdrefnum, StringPtr src_fname)
- {
- if (src_wdrefnum != 0) // if there is a file open..
- {
- SetVol(NULL, src_wdrefnum);
- if (gSrcResRefNum != kRsrcFileClosed)
- printf("## ERROR! opening already-opened rsrc file: OpenFilePrefs()\n");
- gSrcResRefNum = OpenResFile(src_fname);
- if (gSrcResRefNum == kRsrcFileClosed)
- {
- CreateResFile(src_fname);
- gSrcResRefNum = OpenResFile(src_fname);
- }
- }
- } // FilePrefs_Open
-
-
-
- // ---------------------------------------------------------------------
- // Close the source file's resource fork
- static void FilePrefs_Close(void)
- {
- if (gSrcResRefNum != kRsrcFileClosed)
- CloseResFile(gSrcResRefNum);
- gSrcResRefNum = kRsrcFileClosed;
- } // FilePrefs_Close
-
-
-
- // ---------------------------------------------------------------------
- // Update the source file's settings info
- void FilePrefs_Write(short src_wdrefnum, StringPtr src_fname)
- {
- short oldRefNum;
- file_prefs_hdl_t tmpFilePrefsHandle;
-
- oldRefNum = CurResFile();
- if (gSrcResRefNum == kRsrcFileClosed)
- FilePrefs_Open(src_wdrefnum, src_fname);
-
- if (gSrcResRefNum != kRsrcFileClosed)
- {
- /* switch over to our open file */
- UseResFile(gSrcResRefNum);
-
- /* as long as there are old file prefs resources, delete them */
- do {
- tmpFilePrefsHandle = (file_prefs_hdl_t)Get1IndResource(kFilePrefsRsrc, 1);
- if (tmpFilePrefsHandle != NULL)
- {
- RemoveResource((Handle)tmpFilePrefsHandle);
- UpdateResFile(gSrcResRefNum);
- DisposeHandle((Handle)tmpFilePrefsHandle);
- }
- } while (tmpFilePrefsHandle != NULL);
-
- /* Create a new resource to add */
- tmpFilePrefsHandle = (file_prefs_hdl_t)NewHandle(sizeof(file_prefs_rec_t));
-
- /* Fill it up and add it to file */
- if (tmpFilePrefsHandle != NULL)
- {
- **tmpFilePrefsHandle = **gFilePrefs_h;
- AddResource((Handle)tmpFilePrefsHandle, kFilePrefsRsrc, kFilePrefs_rsrcID, "\pPOV-Ray File Prefs");
- WriteResource((Handle)tmpFilePrefsHandle);
- ReleaseResource((Handle)tmpFilePrefsHandle);
- }
- FilePrefs_Close();
- UseResFile(oldRefNum);
- } // if opened
- } // FilePrefs_Write
-
-
-
- // ---------------------------------------------------------------------
- // Read the setting info from the source file
- void FilePrefs_Read(short src_wdrefnum, StringPtr src_fname)
- {
- short oldRefNum;
- file_prefs_hdl_t tmpFilePrefsHandle = NULL;
-
- oldRefNum = CurResFile();
- if (gSrcResRefNum == kRsrcFileClosed)
- FilePrefs_Open(src_wdrefnum, src_fname);
-
- if (gSrcResRefNum != kRsrcFileClosed)
- tmpFilePrefsHandle = (file_prefs_hdl_t)Get1Resource(kFilePrefsRsrc, kFilePrefs_rsrcID);
-
- if (tmpFilePrefsHandle != NULL)
- {
- /* Is it the wrong version? */
- if ((**tmpFilePrefsHandle).prefsVersion != kFilePrefs_Vers)
- { /* old version, delete & create new one below! */
- RemoveResource((Handle)tmpFilePrefsHandle);
- UpdateResFile(gSrcResRefNum);
- DisposeHandle((Handle)tmpFilePrefsHandle);
- tmpFilePrefsHandle = NULL; /* flag code below to add new */
- }
- /* Still got it? Use it! */
- if (tmpFilePrefsHandle != NULL)
- {
- **gFilePrefs_h = **tmpFilePrefsHandle;
- /* make sure our windows are on THIS MACHINE'S screens */
- ForceRectOnScreen(&(**gFilePrefs_h).srcWind_pos);
- ForceRectOnScreen(&(**gFilePrefs_h).statWind_pos);
- ForceRectOnScreen(&(**gFilePrefs_h).imageWind_pos);
-
- if ((**gDefltFilePrefs_h).progress >= eProgDebug)
- {
- printf("-d GetFilePrefs():\n");
- printf("-d ImageWind = <%d, %d, %d, %d>\n",
- (**gFilePrefs_h).imageWind_pos.left,
- (**gFilePrefs_h).imageWind_pos.top,
- (**gFilePrefs_h).imageWind_pos.right,
- (**gFilePrefs_h).imageWind_pos.bottom);
- printf("-d srcWind = <%d, %d, %d, %d>\n",
- (**gFilePrefs_h).srcWind_pos.left,
- (**gFilePrefs_h).srcWind_pos.top,
- (**gFilePrefs_h).srcWind_pos.right,
- (**gFilePrefs_h).srcWind_pos.bottom);
- }
-
- }
- }
-
- /* create a new one if can't read or use the old one */
- if (tmpFilePrefsHandle == NULL)
- {
- **gFilePrefs_h = **gDefltFilePrefs_h; // get default settings
- FilePrefs_Write(src_wdrefnum, src_fname);
- }
- else
- {
- ReleaseResource((Handle)tmpFilePrefsHandle);
- FilePrefs_Close();
- }
- UseResFile(oldRefNum);
- } // FilePrefs_Read
-
-
- // ---------------------------------------------------------------------
- // Pin the value x between a and b, i.e. a <= x <= b
- static long PinValue(long x, long a, long b)
- {
- long r = x;
- if (r < a)
- r = a;
- else
- if (r > b)
- r = b;
- return r;
- } // PinValue
-
-
-
- // ---------------------------------------------------------------------
- // clear a rectangular area of a window
- static void erase_TE_rect(WindowPtr dlgWindPtr, Rect *pRect)
- {
- #pragma unused (dlgWindPtr)
- PenState thePen;
- Rect outerRect;
-
- // Save and restore the pen state so we don't mess things up
- // for other drawing routines
- GetPenState(&thePen);
-
- outerRect = *pRect;
- InsetRect(&outerRect, -3, -3); // border outside TE item
- ForeColor(whiteColor);
- FrameRect(&outerRect);
-
- SetPenState(&thePen);
- ForeColor(blackColor);
- }
-
-
- // ---------------------------------------------------------------------
- // dim a rectangular area of a window
- static void dim_rect(WindowPtr dlgWindPtr, Rect *pRect)
- {
- #pragma unused (dlgWindPtr)
- PenState thePen;
-
- // Save and restore the pen state so we don't mess things up
- // for other drawing routines
- GetPenState(&thePen);
- PenMode(notPatBic);
-
- PenPat((ConstPatternParam)&qd.gray);
- PaintRect(pRect);
-
- SetPenState(&thePen);
- }
-
-
- // ---------------------------------------------------------------------
- // dim/enable the aa edit text fields
- static void update_edit_text(WindowPtr dlgWindPtr, short theTEItemID, Boolean isActive)
- {
- short int itemType;
- GrafPtr saveGP;
- Rect aRect;
- Handle theTEControlH;
-
- GetPort(&saveGP);
- SetPort(dlgWindPtr);
-
- // Get the actual TE item
- GetDialogItem(dlgWindPtr, theTEItemID, &itemType, &theTEControlH, &aRect);
-
- // dim/enable the TE item
- if (isActive)
- { // set to enabled EditText item
- GetDialogItem(dlgWindPtr, theTEItemID, &itemType, &theTEControlH, &aRect);
- SetDialogItem(dlgWindPtr, theTEItemID, editText, theTEControlH, &aRect);
- // invalidate TEs so they are redrawn
- InsetRect(&aRect, -5, -5); // just outside TE item
- InvalRect(&aRect);
- }
- else
- { // aa is OFF, disable & dim TE item
- // make it think it is a static text item, not EditText
- GetDialogItem(dlgWindPtr, theTEItemID, &itemType, &theTEControlH, &aRect);
- erase_TE_rect(dlgWindPtr, &aRect);
- SetDialogItem(dlgWindPtr, theTEItemID, statText+itemDisable, theTEControlH, &aRect);
-
- InsetRect(&aRect, -5, -5); // just outside TE item
- InvalRect(&aRect);
- } // else off
-
- SetPort(saveGP);
- } // update_edit_text
-
-
- // ---------------------------------------------------------------------
- static void SlideInNewDITL(DialogPtr myDialog)
- {
- short numDITLs2Remove;
- gCurrDITLID = kDLOG_RenderPrefsMain + GetDialogItemValue(myDialog, kPU_Settings);
- // First Remove previous DITL items, if any...
- numDITLs2Remove = CountDITL(myDialog) - kMainItem_Max;
- if (numDITLs2Remove>0)
- ShortenDITL(myDialog, numDITLs2Remove);
- // Now add new ones on
- OverlayDITLOnDialog(myDialog, gCurrDITLID, kPU_Settings);
- } // SlideInNewDITL
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPInput(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- // Set the Language Version popup
- if (thePrefs->languageVersion < eMinLangVersion)
- thePrefs->languageVersion = eMinLangVersion;
- else if (thePrefs->languageVersion > eMaxLangVersion)
- thePrefs->languageVersion = eMaxLangVersion;
- SetDialogItemValue(myDialog, kPU_LangVersion, thePrefs->languageVersion);
-
- } // SetupDitls_RPInput
-
-
- static void ItemHit_RPInput(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- #pragma unused(itemHit)
- thePrefs->languageVersion = GetDialogItemValue(myDialog, kPU_LangVersion);
- }
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPQuality(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- char buff[128];
-
- // Set the Image Quality popup
- if (thePrefs->renderQuality > 9)
- thePrefs->renderQuality = 9;
- SetDialogItemValue(myDialog, kPU_RenderQuality, thePrefs->renderQuality+1);
-
- // Set the Radiosity Quality popup
- // If render quality is less than 8, then Radiosity MUST BE OFF
- if (thePrefs->renderQuality < 8)
- {
- thePrefs->radQuality = 0;
- }
-
- SetDialogItemValue(myDialog, kCB_RadQuality, thePrefs->radQuality!=0);
-
- // Set the Preview Start popup
- if ((thePrefs->previewStart <= 0) || (thePrefs->previewEnd <= 0))
- {
- thePrefs->previewStart = 0; // OFF
- thePrefs->previewEnd = 0;
- }
- SetDialogItemValue(myDialog, kPU_PreviewStart, thePrefs->previewStart+1);
-
- // Set the Preview End popup
- if (thePrefs->previewEnd > thePrefs->previewStart)
- thePrefs->previewEnd = thePrefs->previewStart;
- SetDialogItemValue(myDialog, kPU_PreviewEnd, thePrefs->previewEnd+1);
-
- // Set the Anti alias checkbox
- SetDialogItemValue(myDialog, kCB_DoAntiAlias, thePrefs->doAntialias);
-
- SetDialogItemValue(myDialog, kPU_AntialiasMethod, thePrefs->antialiasMethod);
-
- sprintf(buff, "%.2f", thePrefs->antialiasThreshold);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntiAliasThresh), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->antialiasDepth);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntialiasDepth), (StringPtr)buff );
-
- sprintf(buff, "%.2f", thePrefs->antiJitterScale);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntiJitterScale), (StringPtr)buff );
-
- // Enable/disable the related fields, depending on AA setting
- /* this is gross, so don't do it... [esp]
- ShowHideDItem(myDialog, kPU_AntialiasMethod, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntiAliasThresh, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntialiasDepth, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntiJitterScale, thePrefs->doAntialias);
- */
- } // SetupDitls_RPQuality
-
-
- static void ItemHit_RPQuality(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- int itChanged=0;
- char buff[128];
-
- thePrefs->renderQuality = GetDialogItemValue(myDialog, kPU_RenderQuality)-1;
-
- // See if radiosity flag is on or off
- if (itemHit == kCB_RadQuality)
- SetDialogItemValue(myDialog, kCB_RadQuality, !GetDialogItemValue(myDialog, kCB_RadQuality));
- thePrefs->radQuality = GetDialogItemValue(myDialog, kCB_RadQuality);
-
- // If render quality is less than 8, then Radiosity MUST BE OFF
- if (thePrefs->renderQuality < 8)
- {
- thePrefs->radQuality = 0;
- // redraw it, in case it changed
- SetDialogItemValue(myDialog, kCB_RadQuality, thePrefs->radQuality!=0);
- }
-
- thePrefs->previewStart = GetDialogItemValue(myDialog, kPU_PreviewStart)-1;
- if (thePrefs->previewStart < thePrefs->previewEnd)
- {
- itChanged++;
- thePrefs->previewEnd = thePrefs->previewStart;
- }
- if (thePrefs->previewStart==0)
- {
- itChanged++;
- thePrefs->previewEnd = 0; // Both OFF
- }
- if ((thePrefs->previewStart > 0) && (thePrefs->previewEnd == 0))
- {
- itChanged++;
- thePrefs->previewEnd = 2; // Start is on, so turn End on too, to two x two :-)
- }
- // if either preview item changed, redisplay both at their new settings
- if (itChanged)
- {
- SetDialogItemValue(myDialog, kPU_PreviewStart, thePrefs->previewStart+1);
- SetDialogItemValue(myDialog, kPU_PreviewEnd, thePrefs->previewEnd+1);
- }
-
- thePrefs->previewEnd = GetDialogItemValue(myDialog, kPU_PreviewEnd)-1;
- if (thePrefs->previewEnd > thePrefs->previewStart)
- { // bump start up to match
- itChanged++;
- thePrefs->previewStart = thePrefs->previewEnd;
- }
- if (thePrefs->previewEnd==0)
- {
- itChanged++;
- thePrefs->previewStart = 0; // Both OFF
- }
- // if either preview item changed, re-display both at their new settings
- if (itChanged)
- {
- SetDialogItemValue(myDialog, kPU_PreviewStart, thePrefs->previewStart+1);
- SetDialogItemValue(myDialog, kPU_PreviewEnd, thePrefs->previewEnd+1);
- }
-
- if (itemHit == kCB_DoAntiAlias)
- SetDialogItemValue(myDialog, kCB_DoAntiAlias, !GetDialogItemValue(myDialog, kCB_DoAntiAlias));
- thePrefs->doAntialias = GetDialogItemValue(myDialog, kCB_DoAntiAlias);
-
- thePrefs->antialiasMethod = GetDialogItemValue(myDialog, kPU_AntialiasMethod);
-
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntiAliasThresh), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->antialiasThreshold = atof(buff);
- if (thePrefs->antialiasThreshold > 2.0)
- thePrefs->antialiasThreshold = 2.0;
- else if (thePrefs->antialiasThreshold < 0.0)
- thePrefs->antialiasThreshold = 0.0;
-
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntialiasDepth), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->antialiasDepth = atoi(buff);
- thePrefs->antialiasDepth = PinValue(thePrefs->antialiasDepth, 1, 9);
-
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_AntiJitterScale), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->antiJitterScale = atof(buff);
- if (thePrefs->antiJitterScale > 2.0)
- thePrefs->antiJitterScale = 2.0;
- else if (thePrefs->antiJitterScale < 0.0)
- thePrefs->antiJitterScale = 0.0;
-
- // Enable/disable the related fields, depending on AA setting
- /* this is gross... [esp]
- ShowHideDItem(myDialog, kPU_AntialiasMethod, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntiAliasThresh, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntialiasDepth, thePrefs->doAntialias);
- ShowHideDItem(myDialog, kET_AntiJitterScale, thePrefs->doAntialias);
- */
- } // ItemHit_RPQuality
-
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPOptimiz(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- // Set the Max Bounds popup
- SetDialogItemValue(myDialog, kPU_MaxBounds,
- thePrefs->doBoundSlabs ? 3 + (thePrefs->boundSlabThreshold / 5) : 1);
-
- SetDialogItemValue(myDialog, kCB_UseLBuffer, thePrefs->doLightBuffer);
- SetDialogItemValue(myDialog, kCB_UseVBuffer, thePrefs->doVistaBuffer);
- SetDialogItemValue(myDialog, kCB_UseVDraw, thePrefs->doVistaDraw);
-
- SetDialogItemValue(myDialog, kCB_SplitUnions, thePrefs->doSplitUnions);
- SetDialogItemValue(myDialog, kCB_RemoveUnused, thePrefs->removeBounds);
- } // SetupDitls_RPOptimiz
-
-
- static void ItemHit_RPOptimiz(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- // if popup is not at position 1 (off) then it must be on! :-)
- thePrefs->doBoundSlabs = (GetDialogItemValue(myDialog, kPU_MaxBounds) > 1);
- // off, ---, 1, 5, 10, 15, ...
- thePrefs->boundSlabThreshold = (GetDialogItemValue(myDialog, kPU_MaxBounds)-3)*5;
- // if popup was at position 1,2, set to 0...
- if (thePrefs->boundSlabThreshold < 0)
- thePrefs->boundSlabThreshold = 0;
- else // if at 3, set the value to 1
- if (thePrefs->boundSlabThreshold == 0)
- thePrefs->boundSlabThreshold = 1;
-
- if (itemHit == kCB_UseLBuffer)
- SetDialogItemValue(myDialog, kCB_UseLBuffer, !GetDialogItemValue(myDialog, kCB_UseLBuffer));
- thePrefs->doLightBuffer = GetDialogItemValue(myDialog, kCB_UseLBuffer);
-
- if (itemHit == kCB_UseVBuffer)
- SetDialogItemValue(myDialog, kCB_UseVBuffer, !GetDialogItemValue(myDialog, kCB_UseVBuffer));
- thePrefs->doVistaBuffer = GetDialogItemValue(myDialog, kCB_UseVBuffer);
-
- if (itemHit == kCB_UseVDraw)
- SetDialogItemValue(myDialog, kCB_UseVDraw, !GetDialogItemValue(myDialog, kCB_UseVDraw));
- thePrefs->doVistaDraw = GetDialogItemValue(myDialog, kCB_UseVDraw);
-
- if (itemHit == kCB_SplitUnions)
- SetDialogItemValue(myDialog, kCB_SplitUnions, !GetDialogItemValue(myDialog, kCB_SplitUnions));
- thePrefs->doSplitUnions = GetDialogItemValue(myDialog, kCB_SplitUnions);
-
- if (itemHit == kCB_RemoveUnused)
- SetDialogItemValue(myDialog, kCB_RemoveUnused, !GetDialogItemValue(myDialog, kCB_RemoveUnused));
- thePrefs->removeBounds = GetDialogItemValue(myDialog, kCB_RemoveUnused);
-
- } // ItemHit_RPOptimiz
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPInfo(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- // Set the Progress popup
- if (thePrefs->progress < eProgNone)
- thePrefs->progress = eProgNone;
- else if (thePrefs->progress > eProgMax)
- thePrefs->progress = eProgMax;
- SetDialogItemValue(myDialog, kPU_Progress, thePrefs->progress+1);
- // Set the Create INI checkbox
- SetDialogItemValue(myDialog, kCB_DoCreateIni, thePrefs->doCreateINI);
- } // SetupDitls_RPInfo
-
-
- static void ItemHit_RPInfo(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- thePrefs->progress = GetDialogItemValue(myDialog, kPU_Progress)-1;
- if (itemHit == kCB_DoCreateIni)
- SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
- thePrefs->doCreateINI = GetDialogItemValue(myDialog, kCB_DoCreateIni);
- } // ItemHit_RPInfo
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPOutputSize(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- char buff[128];
-
- // Set the Image Size Presets popup
- SetDialogItemValue(myDialog, kPU_ImageSize,
- GetClosestImageSizeItem(myDialog, thePrefs->imageWidth, thePrefs->imageHeight));
-
- sprintf(buff, "%d", thePrefs->imageWidth);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageWidth), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->imageHeight);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageHeight), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->selectionArea.top);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowFrom), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->selectionArea.bottom);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowTo), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->selectionArea.left);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColFrom), (StringPtr)buff );
-
- sprintf(buff, "%d", thePrefs->selectionArea.right);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColTo), (StringPtr)buff );
-
- } // SetupDitls_RPOutputSize
-
-
- static void UpdatePrefsWithImageSize(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- char buff[128];
-
- // width
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageWidth), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->imageWidth = atoi(buff);
- thePrefs->imageWidth = PinValue(thePrefs->imageWidth, 1, 30000);
-
- // height
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageHeight), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->imageHeight = atoi(buff);
- thePrefs->imageHeight = PinValue(thePrefs->imageHeight, 1, 30000);
-
- // from top
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowFrom), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->selectionArea.top = atoi(buff);
- thePrefs->selectionArea.top = PinValue(thePrefs->selectionArea.top, 1, thePrefs->imageHeight);
-
- // to bottom
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowTo), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->selectionArea.bottom = atoi(buff);
- thePrefs->selectionArea.bottom = PinValue(thePrefs->selectionArea.bottom, 1, thePrefs->imageHeight);
-
- // from left
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColFrom), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->selectionArea.left = atoi(buff);
- thePrefs->selectionArea.left = PinValue(thePrefs->selectionArea.left,
- 1, thePrefs->imageWidth);
-
- // to right
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColTo), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->selectionArea.right = atoi(buff);
- thePrefs->selectionArea.right = PinValue(thePrefs->selectionArea.right,
- 1, thePrefs->imageWidth);
-
- } // UpdatePrefsWithImageSize
-
-
- static void ItemHit_RPOutputSize(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- short index;
- short itemWidth=0, itemHeight=0;
- MenuRef imageMenuRef;
- char buff[128];
-
- // if popup hit, fill in related fields
- if (itemHit == kPU_ImageSize)
- {
- ControlHandle popupControlH;
-
- // get the popup menu control, then get menu handle from it
- popupControlH = (ControlHandle)GrabDItemHandle(myDialog,kPU_ImageSize);
- // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
- imageMenuRef = (MenuRef) (**(Handle**)(**popupControlH).contrlData);
-
- // get index of popup menu item chosen from image size popup
- index = GetDialogItemValue(myDialog, itemHit);
-
- // Find w/h of the item chosen
- GetImageSizeOfItem(imageMenuRef, index, &itemWidth, &itemHeight);
-
- // from top (always 1)
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowFrom), (StringPtr)"\p1");
- // from left (always 1)
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColFrom), (StringPtr)"\p1");
-
- // width
- sprintf(buff, "%d", itemWidth); // X (width)
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageWidth), (StringPtr)buff);
- // to right
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ColTo), (StringPtr)buff);
-
- // height
- sprintf(buff, "%d", itemHeight); // Y (height)
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ImageHeight), (StringPtr)buff);
- // to bottom
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_RowTo), (StringPtr)buff);
-
- // re-select first item (its size may have changed)
- SelectDialogItemText(myDialog, kET_ImageWidth, 0, -1);
- }
-
- // refill prefs record with new image size values
- UpdatePrefsWithImageSize(myDialog, thePrefs);
-
- // update/repaint text fields in dialog?
- // NOTE the "gPrevItemHit != kNoItemHit" check keeps us from updating the partial fields on first typing.
- if (((itemHit != gPrevItemHit) && (gPrevItemHit != kNoItemHit))
- || (itemHit == kPU_ImageSize))
- SetupDitls_RPOutputSize(myDialog, thePrefs);
-
- } // ItemHit_RPOutputSize
-
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPOutputFile(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- short menuValue;
- char buff4[6];
- Str255 menuItemString;
-
- // Set PICT signature (make into a Pascal string)
- buff4[0] = 4; // length byte
- BlockMove(&thePrefs->pictFileCreator, &buff4[1], 4);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_PICTSig), (StringPtr)buff4);
-
- // Set Targa signature (make into a Pascal string)
- buff4[0] = 4; // length byte
- BlockMove(&thePrefs->targaFileCreator, &buff4[1], 4);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_TargaSig), (StringPtr)buff4);
-
- // Set the output file type (pict, pict+targa, etc.)
- thePrefs->outfileType = PinValue(thePrefs->outfileType, eOutfNone, eOutfMax);
- SetDialogItemValue(myDialog, kPU_OutfileType, thePrefs->outfileType+1);
-
- // enable the control only if they have chosen some non-PICT output file
- // Technically the user could resume a render in PICT-only mode, however,
- // I got many bug reports of people trying to ALWAYS turn on resume, that I
- // went back to the 2.2 UI way, and only allow resuming if they are creating a file.
- SetDialogItemValue(myDialog, kCB_ContinueFromTarga, thePrefs->continueTarga&&(thePrefs->outfileType>0));
- HiliteControl(GrabDItemHandle(myDialog, kCB_ContinueFromTarga),
- (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
-
- // Set the output file buffer size
- if (thePrefs->outfileBuffSize < 0)
- thePrefs->outfileBuffSize = 0;
- else if (thePrefs->outfileBuffSize > kMaxOutfileBuffSize)
- thePrefs->outfileBuffSize = kMaxOutfileBuffSize;
- // set it to 1, 2, 3, etc.
- SetDialogItemValue(myDialog, kPU_OutfileBuffSize, thePrefs->outfileBuffSize+1);
-
- // set Histogram stuff.
- SetDialogItemValue(myDialog, kCB_DoHistFile, thePrefs->doHistogram);
- SetDialogItemValue(myDialog, kPU_HistFileType, thePrefs->histogramType);
- HiliteControl(GrabDItemHandle(myDialog, kCB_DoHistFile), kControlInactivePart); // disable for now..
- HiliteControl(GrabDItemHandle(myDialog, kPU_HistFileType), kControlInactivePart); // disable for now..
-
- // set bits/color
- if (thePrefs->bitsPerColor < kMinBitsPerColor)
- thePrefs->bitsPerColor = kMinBitsPerColor; // PNG minimum limitation
- else if (thePrefs->bitsPerColor > kMaxBitsPerColor)
- thePrefs->bitsPerColor = kMaxBitsPerColor;
- // brute force, find menu index for number
- {
- short menuItem;
- ControlHandle mcontrol;
- MenuRef bitsPerColorMenu;
- mcontrol = GrabDItemHandle(myDialog, kPU_BitsPerColor);
- // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
- bitsPerColorMenu = (MenuRef) (**(Handle**)(**mcontrol).contrlData);
- // how many items on menu?
- menuItem = CountMenuItems(bitsPerColorMenu);
- // are we there yet? loop down through items looking for a match
- do {
- // get the menu item text
- GetMenuItemText(bitsPerColorMenu, menuItem, menuItemString);
- // convert it to a number (just the first part)
- // StringToNum((StringPtr)menuItemString, &menuValue);
- menuValue = atoi((char*)&menuItemString[1]);
- // if it matches, we found it, drop out
- if (menuValue == thePrefs->bitsPerColor)
- break;
- // nope, keep looking
- menuItem--;
- } while (menuItem>1);
- // set menu to the menu item found
- SetDialogItemValue(myDialog, kPU_BitsPerColor, menuItem);
- }
- // disable this item if no special output file is used
- // (PICTs are always 24-bit in 3.0)
- HiliteControl(GrabDItemHandle(myDialog, kPU_BitsPerColor),
- (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
-
- // set alpha channel stuff.
- SetDialogItemValue(myDialog, kCB_DoAlphaChannel, thePrefs->doAlphaChannel);
- // disable this item if no special output file is used
- // (nope, allow turning PICT alpha channel on and off! 3.0.1 late beta [esp])
- // HiliteControl(GrabDItemHandle(myDialog, kCB_DoAlphaChannel),
- // (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
-
- } // SetupDitls_RPOutputFile
-
-
- // ---------------------------------------------------------------------
- static void ItemHit_RPOutputFile(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- short menuValue;
- char buff[128];
- Str255 menuItemString;
-
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_PICTSig), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->pictFileCreator = *(OSType*)buff; // grab 1st 4 bytes as if they were a long int
-
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_TargaSig), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- thePrefs->targaFileCreator = *(OSType*)buff; // grab 1st 4 bytes as if they were a long int
-
- thePrefs->outfileType = GetDialogItemValue(myDialog, kPU_OutfileType)-1;
-
- if (itemHit == kCB_ContinueFromTarga)
- SetDialogItemValue(myDialog, kCB_ContinueFromTarga, !GetDialogItemValue(myDialog, kCB_ContinueFromTarga));
- // enable the control only if they have chosen some non-PICT output file
- // Technically the user could resume a render in PICT-only mode, however,
- // I got many bug reports of people trying to ALWAYS turn on resume, that I
- // went back to the 2.2 UI way, and only allow resuming if they are creating a Targa/PNG file.
- if (thePrefs->outfileType==eOutfNone)
- SetDialogItemValue(myDialog, kCB_ContinueFromTarga, 0);
- thePrefs->continueTarga = GetDialogItemValue(myDialog, kCB_ContinueFromTarga);
- HiliteControl(GrabDItemHandle(myDialog, kCB_ContinueFromTarga),
- (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
-
- thePrefs->outfileBuffSize = GetDialogItemValue(myDialog, kPU_OutfileBuffSize)-1;
-
- // histogram
- if (itemHit == kCB_DoHistFile)
- SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
- thePrefs->doHistogram = GetDialogItemValue(myDialog, kCB_DoHistFile);
- thePrefs->histogramType = GetDialogItemValue(myDialog, kPU_HistFileType);
-
- // set bits/color to N from menu
- {
- short menuItem;
- ControlHandle mcontrol;
- MenuRef bitsPerColorMenu;
- menuItem = GetDialogItemValue(myDialog, kPU_BitsPerColor);
- mcontrol = GrabDItemHandle(myDialog, kPU_BitsPerColor);
- // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
- bitsPerColorMenu = (MenuRef) (**(Handle**)(**mcontrol).contrlData);
- GetMenuItemText(bitsPerColorMenu, menuItem, menuItemString);
- // convert it to a number (just the first part)
- // StringToNum((StringPtr)menuItemString, &menuValue);
- menuValue = atoi((char*)&menuItemString[1]);
- // set bits/color to that value
- thePrefs->bitsPerColor = menuValue;
- }
- // disable this item if no special output file is used
- // (PICTs are always 24-bit in 3.0)
- HiliteControl(GrabDItemHandle(myDialog, kPU_BitsPerColor),
- (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
-
- // set alpha channel stuff.
- SetDialogItemValue(myDialog, kCB_DoAlphaChannel, thePrefs->doAlphaChannel);
- // if checkbox clicked, invert it
- if (itemHit == kCB_DoAlphaChannel)
- SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
- // get it's current setting
- thePrefs->doAlphaChannel = GetDialogItemValue(myDialog, kCB_DoAlphaChannel);
- /*
- // disable this item if no special output file is used
- HiliteControl(GrabDItemHandle(myDialog, kCB_DoAlphaChannel),
- (thePrefs->outfileType>eOutfNone)?kControlNoPart:kControlInactivePart);
- */
-
- /*
- // pict compression button
- thePrefs->doCompression = GetDialogItemValue(myDialog, kCB_DoPICTCmp);
- if (thePrefs->doCompression)
- (void)SCGetInfo(gtheSCComponent, scSpatialSettingsType, &(**gDefltFilePrefs_h).sc_DialogParams);
- */
- } // ItemHit_RPOutputFile
-
-
- // ---------------------------------------------------------------------
- static void SetupDitls_RPAnimate(DialogPtr myDialog, file_prefs_ptr_t thePrefs)
- {
- float fval;
- char buff[128];
-
- SetDialogItemValue(myDialog, kCB_Animate, thePrefs->doAnimation!=0);
-
- // Initial Frame
- sprintf(buff, "%d", thePrefs->animRec.frameVal0); // always starts at frame 1
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kST_FrameVal0), (StringPtr)buff);
-
- // Start Frame
- sprintf(buff, "%d", thePrefs->animRec.frameValS);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValS), (StringPtr)buff);
-
- // End Frame
- sprintf(buff, "%d", thePrefs->animRec.frameValE);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValE), (StringPtr)buff);
-
- // Final Frame
- sprintf(buff, "%d", thePrefs->animRec.frameValN);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValN), (StringPtr)buff);
-
- // Initial Clock
- sprintf(buff, "%g", thePrefs->animRec.clockVal0);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ClockVal0), (StringPtr)buff);
-
- // Start Clock
- fval = CalcClockVal(&thePrefs->animRec, thePrefs->animRec.frameValS);
- sprintf(buff, "%g", fval);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kST_ClockValS), (StringPtr)buff);
-
- // End Clock
- fval = CalcClockVal(&thePrefs->animRec, thePrefs->animRec.frameValE);
- sprintf(buff, "%g", fval);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kST_ClockValE), (StringPtr)buff);
-
- // Final Clock
- sprintf(buff, "%g", thePrefs->animRec.clockValN);
- c2pstr(buff);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ClockValN), (StringPtr)buff);
-
- // Field rendering popup
- if (!thePrefs->doFieldRender)
- SetDialogItemValue(myDialog, kPU_FieldRender, 1); // 1=OFF
- else
- SetDialogItemValue(myDialog, kPU_FieldRender, 2+thePrefs->doOddField); // 2=Even, 3=Odd
-
- } // SetupDitls_RPAnimate
-
-
- static void ItemHit_RPAnimate(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs)
- {
- char buff[32];
-
- if (itemHit == kCB_Animate)
- {
- SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
- thePrefs->doAnimation = GetDialogItemValue(myDialog, itemHit);
- }
- else
- {
- //
- // Initial Frame = 1 always
- thePrefs->animRec.frameVal0 = 1;
-
- //
- // Final Frame
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValN), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- if (buff[0] == 0) // null string
- thePrefs->animRec.frameValN = thePrefs->animRec.frameVal0;
- else
- thePrefs->animRec.frameValN = atoi(buff);
- // Final must be greater than or equal to Initial
- if (thePrefs->animRec.frameValN < thePrefs->animRec.frameVal0)
- thePrefs->animRec.frameValN = thePrefs->animRec.frameVal0;
-
- //
- // Start Frame
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValS), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- if (buff[0] == 0) // null string
- thePrefs->animRec.frameValS = thePrefs->animRec.frameVal0;
- else
- thePrefs->animRec.frameValS = atoi(buff);
- if ((thePrefs->animRec.frameValS < thePrefs->animRec.frameVal0)
- || (thePrefs->animRec.frameValS > thePrefs->animRec.frameValN))
- thePrefs->animRec.frameValS = thePrefs->animRec.frameVal0;
-
- //
- // End Frame
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_FrameValE), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- if (buff[0] == 0) // null string
- thePrefs->animRec.frameValE = thePrefs->animRec.frameValN;
- else
- thePrefs->animRec.frameValE = atoi(buff);
- // End must be greater than start...
- if (thePrefs->animRec.frameValE < thePrefs->animRec.frameVal0)
- thePrefs->animRec.frameValE = thePrefs->animRec.frameValN;
- // If End is greater than Final, bump final up
- if (thePrefs->animRec.frameValE > thePrefs->animRec.frameValN)
- thePrefs->animRec.frameValN = thePrefs->animRec.frameValE;
-
- //
- // Do Start & End Frame overlap?
- if (thePrefs->animRec.frameValE < thePrefs->animRec.frameValS)
- thePrefs->animRec.frameValE = thePrefs->animRec.frameValS;
-
- //
- // Initial Clock Val
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ClockVal0), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- if (buff[0] == 0) // null string
- thePrefs->animRec.clockVal0 = 0.0;
- else
- thePrefs->animRec.clockVal0 = atof(buff);
-
- //
- // Final Clock Val
- GetDialogItemText((Handle)GrabDItemHandle(myDialog,kET_ClockValN), (StringPtr)buff);
- p2cstr((StringPtr)buff);
- if (buff[0] == 0) // null string
- thePrefs->animRec.clockValN = 1.0;
- else
- thePrefs->animRec.clockValN = atof(buff);
-
- //
- // Final & Initial clock are too close, change Final
- if (fabs(thePrefs->animRec.clockValN-thePrefs->animRec.clockVal0) < 1.0e-9)
- {
- thePrefs->animRec.clockValN = thePrefs->animRec.clockVal0 + 1.0;
- SysBeep(4);
- }
-
- //
- // Field Rendering setting ( 1=off, 2=even, 3=odd)
- thePrefs->doFieldRender = GetDialogItemValue(myDialog, kPU_FieldRender) > 1; // >1 means it is ON
- thePrefs->doOddField = GetDialogItemValue(myDialog, kPU_FieldRender) == 3; // 3 = Odd field
-
- }
-
- // Force a redraw of everything since we've updated fields
- if (itemHit != gPrevItemHit)
- SetupDitls_RPAnimate(myDialog, thePrefs);
-
- }
-
-
- // ---------------------------------------------------------------------
- static void DoInitDitl(DialogPtr myDialog, file_prefs_ptr_t thePrefs, short currDITLID)
- {
- switch (currDITLID)
- {
- case KDITL_RPInput:
- SetupDitls_RPInput(myDialog, thePrefs);
- break;
- case KDITL_RPQuality:
- SetupDitls_RPQuality(myDialog, thePrefs);
- break;
- case KDITL_RPOptimiz:
- SetupDitls_RPOptimiz(myDialog, thePrefs);
- break;
- case KDITL_RPInfo:
- SetupDitls_RPInfo(myDialog, thePrefs);
- break;
- case KDITL_RPOutputSize:
- SetupDitls_RPOutputSize(myDialog, thePrefs);
- break;
- case KDITL_RPOutputFile:
- SetupDitls_RPOutputFile(myDialog, thePrefs);
- break;
- case KDITL_RPAnimate:
- SetupDitls_RPAnimate(myDialog, thePrefs);
- break;
- }
- } // DoInitDitl
-
-
- // ---------------------------------------------------------------------
- static void DoItemHit(DialogPtr myDialog, short itemHit, file_prefs_ptr_t thePrefs, short currDITLID)
- {
- switch (currDITLID)
- {
- case KDITL_RPInput:
- ItemHit_RPInput(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPQuality:
- ItemHit_RPQuality(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPOptimiz:
- ItemHit_RPOptimiz(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPInfo:
- ItemHit_RPInfo(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPOutputSize:
- ItemHit_RPOutputSize(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPOutputFile:
- ItemHit_RPOutputFile(myDialog, itemHit, thePrefs);
- break;
- case KDITL_RPAnimate:
- ItemHit_RPAnimate(myDialog, itemHit, thePrefs);
- break;
- }
- } // DoItemHit
-
-
- // ---------------------------------------------------------------------
- // Prompt the user to change the File Preferences, handle clicks in the dialog
- static void FilePrefs_HandleEvents(EventRecord * theEventPtr)
- {
- short itemHit;
- Boolean gotItem;
- WindowPtr myDialog;
- Rect dRect;
-
- gotItem = false;
- myDialog = GetCurrMModalDialog();
-
- // handle activate events
- if (theEventPtr->what == activateEvt)
- {
- // enable or disable our main buttons on activate/deactivate
- HiliteControl(GrabDItemHandle(myDialog, ok), (theEventPtr->modifiers & 1)?kControlNoPart:kControlInactivePart);
- HiliteControl(GrabDItemHandle(myDialog, cancel), (theEventPtr->modifiers & 1)?kControlNoPart:kControlInactivePart);
- }
-
- // Handle CR/ESC ourselves
- if (theEventPtr->what == keyDown)
- {
- char theKey = theEventPtr->message & charCodeMask;
- if ((theKey == 13) || (theKey == 3)) // CR or ENTER
- {
- itemHit = ok;
- gotItem = true;
- FlashDItem(myDialog, itemHit);
- }
- if ((theKey == 27) || // escape key
- ((theKey == '.') && (theEventPtr->modifiers & cmdKey))) // <cmd>-period
- {
- itemHit = cancel;
- gotItem = true;
- FlashDItem(myDialog, itemHit);
- }
- }
-
- // look for other events
- if (!gotItem)
- gotItem = DialogSelect(theEventPtr, &myDialog, &itemHit);
-
- if (gotItem)
- {
- switch (itemHit)
- {
- case ok:
- // NOTE: We are already writing straight into prefs record,
- // so we don't need to do anything on OK, just cancel.
-
- // Remember where we parked
- GetGlobalWindowRect(myDialog, &dRect); // ScreenUtils.c
- APSet_FilePrefsDlgPos(&dRect);
-
- // save prefs in file
- FilePrefs_Write(gSrc_wdrefnum, gSrc_fname);
-
- CloseMModalDialog();
- EnableMenus(); // re-enable menus
- break;
-
- case cancel:
- **gFilePrefs_h = gOrigPrefs; // restore original values
- CloseMModalDialog();
- EnableMenus(); // re-enable menus
- break;
-
- case kPU_Settings:
- // only slide in another pane if we chose one other than the current pane
- if (gCurrDITLID != kDLOG_RenderPrefsMain + GetDialogItemValue(myDialog, kPU_Settings))
- {
- // if switching old pane out, fake one last hit to grab current settings
- // before tearing it down
- DoItemHit(myDialog, kNoItemHit, *gFilePrefs_h, gCurrDITLID);
- // now slide in new pane
- SlideInNewDITL(myDialog);
- // force a redraw
- InvalRect(&myDialog->portRect); // full redraw, yuck
- // reset prev item hit
- gPrevItemHit = kNoItemHit;
- // set up the sub-panel's control values
- DoInitDitl(myDialog, *gFilePrefs_h, gCurrDITLID);
- }
- break;
-
- case kCB_SaveAsDefault:
- // save these values as defaults
- **gDefltFilePrefs_h = **gFilePrefs_h;
- break;
-
- case kPB_RestoreDefault:
- // push app default values into this file's settings
- **gFilePrefs_h = **gDefltFilePrefs_h;
- // reset/reread the sub-panel's control values
- DoInitDitl(myDialog, *gFilePrefs_h, gCurrDITLID);
- break;
-
- // otherwise, it is one of the specialized items, dispatch to appropriate handler
- default:
- DoItemHit(myDialog, itemHit, *gFilePrefs_h, gCurrDITLID);
- // remember item for next time through
- gPrevItemHit = itemHit;
- break;
- } // switch
- } // if
- } // FilePrefs_HandleEvents
-
-
- // ---------------------------------------------------------------------
- // Prompt the user to change the File Preferences, Start the dialog
- void FilePrefs_Prompt_Init(short src_wdrefnum, StringPtr src_fname)
- {
- Rect aRect;
- DialogPtr myDialog;
-
- // retrieve dialog from resource
- myDialog = GetMModalDialog(kDLOG_RenderPrefsMain);
- if (!myDialog)
- {
- SysBeep(3);
- return;
- }
-
- // set this as current dialog and event handler
- SetCurrMModalDialog(myDialog, &FilePrefs_HandleEvents); // dialogutils
-
- // remember temporary prefs record until user clicks OK!
- gOrigPrefs = **gFilePrefs_h;
- gSrc_wdrefnum = src_wdrefnum;
- gSrc_fname = src_fname;
- gPrevItemHit = 0;
-
- // Set the Settings popup to wherever we are
- SetDialogItemValue(myDialog, kPU_Settings, gCurrDITLID-kDLOG_RenderPrefsMain);
-
- // Set dialog's File name display
- SetDialogItemText((Handle)GrabDItemHandle(myDialog,kST_Filename), src_fname);
-
- // set up appropriate dialog items in pane
- SlideInNewDITL(myDialog);
-
- // init other stuff here
- DoInitDitl(myDialog, *gFilePrefs_h, gCurrDITLID);
-
- // position our dialog where user last left it
- APGet_FilePrefsDlgPos(&aRect);
- if ((aRect.left==0) && (aRect.top==0))
- PositionWindow(myDialog, ewcDoCentering, eSameAsPassedWindow, (WindowPtr)gp2wWindow);
- else
- {
- // make sure our windows are visible on THIS MACHINE'S screens
- ForceRectOnScreen(&aRect);
- MoveWindow(myDialog, aRect.left, aRect.top, true);
- }
-
- // set the standard action for OK/cancel buttons
- InstallUserDrawProc(myDialog, kDefaultOutlineItem, &OutlineButtonDrawProc);
-
- // show it
- ShowMModalDialog();
-
- } // FilePrefs_Prompt_Init
-
-
-