home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / gfx / edit / tsmorph / src / tsmorph-prefs.c < prev    next >
C/C++ Source or Header  |  1994-02-25  |  39KB  |  1,512 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. // This code was written a bit quick and includes a
  21. // lot of hard coded stuff which should be #defined
  22.  
  23. // Include headers
  24. #include <proto/exec.h>
  25. #include <proto/gadtools.h>
  26. #include <proto/intuition.h>
  27. #include <proto/diskfont.h>
  28. #include <proto/graphics.h>
  29. #include <proto/utility.h>
  30. #include <proto/asl.h>
  31. #include <proto/icon.h>
  32. #include <proto/dos.h>
  33. #include <libraries/amigaguide.h>
  34. #include <clib/amigaguide_protos.h>
  35. #include <pragmas/amigaguide_pragmas.h>
  36. #define LIBRARIES_MATHFFP_H    // Do not include other math stuff
  37. #include <clib/alib_protos.h>
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <stdlib.h>
  42.  
  43. #include <intuition/gadgetclass.h>
  44.  
  45. // following not in 2.02 headers
  46. #if INCLUDE_VERSION < 37
  47. LONG Stricmp(UBYTE *string1,UBYTE *string2);
  48. #pragma libcall UtilityBase Stricmp A2 9802
  49. #endif
  50.  
  51. #include "Prefs.h"
  52.  
  53. struct Library *GadToolsBase;
  54. struct Library *UtilityBase;
  55. struct Library *AslBase;
  56. struct Library *AmigaGuideBase;
  57.  
  58. struct FileRequester     *filereq        = NULL;
  59. char TempFilename[257];
  60. AMIGAGUIDECONTEXT         handle         = NULL;
  61. struct NewAmigaGuide        nag     = {NULL};
  62. ULONG                            ASig            = 0;
  63.  
  64. /* Version string for CLI version */
  65. char *Version = "$VER: TSMorph-prefs 3.0 (25.2.94)";
  66.  
  67. // Help nodes
  68. unsigned char *context[] = {
  69.     "",                    //    0
  70.     "Main",                // 1
  71.     "P-KEEPSETTINGS",    // 2
  72.     "P-CHANGEPALETTE",//    3
  73.     "P-CREATEICONS",    // 4
  74.     "P-CREATEICONSP",    // 5
  75.     "P-OPENMODE",        // 6
  76.     "P-PUBSCREEN",        // 7
  77.     "P-ZOOM",            // 8
  78.     "P-CREATEICONSR",    // 9
  79.     "P-DEPTH",            // 10
  80.     "P-DX",                // 11
  81.     "P-DY",                // 12
  82.     "P-LOADSCRIPT",    // 13
  83.     "P-MODE",            // 14
  84.     "P-POSTSCRIPT",    // 15
  85.     "P-PRESCRIPT",        // 16
  86.     "P-PUBSCREENR",    // 17
  87.     "P-QUALITY",        // 18
  88.     "P-SAVEFORMAT",    // 19
  89.     "P-ANTIALIAS",        // 20
  90.     "P-HELP",            // 21
  91.     "P-PREVIEW",        // 22
  92.     "P-CUSTOMMODE",    // 23
  93.     "P-CUSTOMDEPTH",    // 24
  94.     "TSMP-Close",        // 25
  95.     "TSMP-Depth",        // 26
  96.     "TSMP-Zoom",        // 27
  97.     "TSMorph-prefs",    // 28
  98.     "TSMP-Save",        // 29
  99.     "TSMP-Use",            // 30
  100.     "TSMP-Cancel",        // 31
  101.     "TSMP-men-Project",// 32
  102.     "TSMP-men-P-Open",// 33
  103.     "TSMP-men-P-SaveAs",// 34
  104.     "TSMP-men-P-Quit",// 35
  105.     "TSMP-men-Edit",    // 36
  106.     "TSMP-men-E-ResetD",//37
  107.     "TSMP-men-E-LastS",//38
  108.     "TSMP-men-E-Restore",//39
  109.     "TSMP-men-Settings",//40
  110.     "TSMP-men-S-Icons",//41
  111.     "TSMP-men",            //42
  112.     "P-INTEGER",        // 43
  113. };
  114.  
  115. // Settings
  116. STRPTR CustomScreen[100] = {"NONE",NULL};    // table of modes - headed by none
  117. ULONG CustomMode = 0;
  118. ULONG CustomDepth = 4;
  119. ULONG DX = 0;
  120. ULONG DY = 0;
  121. ULONG RenderMode = 0;
  122. ULONG SaveFormat = 0;
  123. ULONG Quality = 75;
  124. BOOL AntiAlias = FALSE;
  125. BOOL Integer = FALSE;
  126. ULONG Depth = 2;
  127. ULONG Zoom = 1;
  128. ULONG Palette = 0;
  129. ULONG OpenMode = 2;
  130. BOOL KeepPrefs = TRUE;
  131. BOOL Help = FALSE;
  132. BOOL ProjectI = TRUE;
  133. BOOL PrefsI = TRUE;
  134. BOOL RenderI = FALSE;
  135.  
  136. // Icons from this program
  137. BOOL Icons = TRUE;
  138.  
  139. // Prototypes
  140. void UpdateGadgets(void);
  141. void DisableWindow(void);
  142. void EnableWindow(void);
  143. void Error(char *ErrorMessage,char *extra);
  144. void SaveSettings(char *filename);
  145. void LoadSettings(char *filename);
  146. BOOL GetAFile(char *name,char *Prompt,ULONG flags);
  147. void InitParams(UBYTE *string);
  148. void help(ULONG helpnum);
  149.  
  150. // Is point in a rectangle
  151. #define PointInBox(x,y,mx,my,MX,MY) ((x>=mx)&&(y>=my)&&(x<=MX)&&(y<=MY))
  152.  
  153. struct List NodeList;            // Custom mode table
  154.  
  155. struct Node FirstNode = {0};
  156.  
  157. /* Disable CTRL-C checking    */
  158. int CXBRK(void) { return(0); }
  159. int chkabort(void) { return(0); }
  160. int __regargs __chkabort(void) { return(0); }
  161.  
  162. int
  163. main(void) {
  164.     int running = 1;
  165.     struct NameInfo buff;
  166.     ULONG id = INVALID_ID;
  167.     int kount = 1;
  168.     struct Node *MyNode;
  169.     struct AmigaGuideMsg *agm;
  170.     ULONG Signals;
  171.  
  172.     // Initialise Custom list and add "NONE"
  173.     NewList(&NodeList);
  174.     FirstNode.ln_Name = CustomScreen[0];
  175.     AddTail(&NodeList,&FirstNode);
  176.     // try and open amigaguide
  177.     if (AmigaGuideBase = OpenLibrary ("amigaguide.library", 34L)) {
  178.         nag.nag_BaseName        = "TSMorph";
  179.         nag.nag_Name            = "TSMorph.guide";
  180.         nag.nag_ClientPort    = "TSMorph-prefs_HELP";
  181.         nag.nag_Context        = context;
  182.         nag.nag_Flags            = HTF_NOACTIVATE;
  183.         nag.nag_PubScreen        = NULL;
  184.         if (handle = OpenAmigaGuideAsync(&nag, NULL)) {
  185.             ASig = AmigaGuideSignal(handle);
  186.         }
  187.     }
  188.     // Open various libraries
  189.     if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)) {
  190.         if (GadToolsBase = OpenLibrary("gadtools.library",37)) {
  191.             if (DiskfontBase = OpenLibrary("diskfont.library",36)) {
  192.                 if (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)) {
  193.                     // build up list of display modes (max ~100)
  194.                     id = NextDisplayInfo(id);
  195.                     while ((id != INVALID_ID) && (kount < 98)) {
  196.                         if (GetDisplayInfoData(NULL,(UBYTE *)&buff,sizeof(struct NameInfo),DTAG_NAME,id)) {
  197.                             if ((MyNode = (struct Node *)calloc(1,sizeof(struct Node))) &&
  198.                                  (CustomScreen[kount] = (STRPTR)strdup(buff.Name))) {
  199.                                 MyNode->ln_Name = CustomScreen[kount];
  200.                                 AddTail(&NodeList,MyNode);
  201.                                 kount++;
  202.                             }
  203.                         }
  204.                         id = NextDisplayInfo(id);
  205.                     }
  206.                     CustomScreen[kount] = NULL;
  207.                     // open other libraries
  208.                     if (UtilityBase = OpenLibrary("utility.library",37)) {
  209.                         if (AslBase = OpenLibrary("asl.library",37)) {
  210.                             if (IconBase = OpenLibrary("icon.library",37)) {
  211.                                 // get File requester and open window
  212.                                 if (filereq = (struct FileRequester *)AllocFileRequest()) {
  213.                                     if (!SetupScreen()) {
  214.                                         if (!OpenTSMorphPrefsWindow()) {
  215.                                             // Set up custom modes
  216.                                             GT_SetGadgetAttrs(TSMorphPrefsGadgets[GDX_CustomMode],TSMorphPrefsWnd,NULL,
  217.                                                 GTLV_Labels,&NodeList,
  218.                                                 TAG_END);
  219.                                             // Load settings from ENV:
  220.                                             LoadSettings("ENV:TSMorph/TSMorph.prefs");
  221.                                             // Loop until quit
  222.                                             while (running) {
  223.                                                 Signals = Wait((ASig) |
  224.                                                                     (1L << TSMorphPrefsWnd->UserPort->mp_SigBit));
  225.                                                 // amigaguide stuff
  226.                                                 if (Signals & ASig) {
  227.                                                     if (handle) {
  228.                                                         while (agm = GetAmigaGuideMsg(handle)) {
  229.                                                             switch (agm->agm_Type) {
  230.                                                             case ToolCmdReplyID:
  231.                                                                 break;
  232.                                                             case ToolStatusID:
  233.                                                                 break;
  234.                                                             default:
  235.                                                                 break;
  236.                                                             }
  237.                                                             ReplyAmigaGuideMsg(agm);
  238.                                                         }
  239.                                                     }
  240.                                                 }
  241.                                                 // Normal stuff
  242.                                                 if (Signals & (1L << TSMorphPrefsWnd->UserPort->mp_SigBit)) {
  243.                                                     running = HandleTSMorphPrefsIDCMP();
  244.                                                 }
  245.                                                 // Close everything down
  246.                                             }
  247.                                         }
  248.                                         CloseTSMorphPrefsWindow();
  249.                                     }
  250.                                     CloseDownScreen();
  251.                                     FreeFileRequest(filereq);
  252.                                 }
  253.                                 CloseLibrary(IconBase);
  254.                             }
  255.                             CloseLibrary(AslBase);
  256.                         }
  257.                         CloseLibrary(UtilityBase);
  258.                     }
  259.                     CloseLibrary((struct Library *)GfxBase);
  260.                 }
  261.                 CloseLibrary(DiskfontBase);
  262.             }
  263.             CloseLibrary(GadToolsBase);
  264.         }
  265.         CloseLibrary((struct Library *)IntuitionBase);
  266.     }
  267.     if (AmigaGuideBase) {
  268.         if (handle) {
  269.             CloseAmigaGuide(handle);
  270.         }
  271.         CloseLibrary(AmigaGuideBase);
  272.     }
  273.     return 0;
  274. }
  275.  
  276. /* Display help using amigaguide (if available)
  277.  * based on a number
  278.  */
  279. void
  280. help(ULONG helpnum) {
  281.     if (handle) {
  282.         SetAmigaGuideContext(handle,helpnum,NULL);
  283.         SendAmigaGuideContext(handle,NULL);
  284.     }
  285. }
  286.  
  287.  
  288. int
  289. CustomDepthClicked( void ) {
  290.     /* routine when gadget "Depth" is clicked. */
  291.     CustomDepth = TSMorphPrefsMsg.Code;
  292.     return 1;
  293. }
  294.  
  295. int
  296. DXClicked( void ) {
  297.     /* routine when gadget "DX" is clicked. */
  298.     DX = TSMorphPrefsMsg.Code;
  299.     return 1;
  300. }
  301.  
  302. int DYClicked( void