home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / gfx / edit / tsmorph / tsmorph-prefs.c < prev    next >
C/C++ Source or Header  |  1993-12-21  |  38KB  |  1,478 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. //    $Author: M_J_Paddock $
  21. //    $Date: 1993/09/11 21:57:56 $
  22. //    $Revision: 1.2 $
  23.  
  24. // This code was written a bit quick and includes a
  25. // lot of hard coded stuff which should be #defined
  26.  
  27. // Include headers
  28. #include <proto/exec.h>
  29. #include <proto/gadtools.h>
  30. #include <proto/intuition.h>
  31. #include <proto/diskfont.h>
  32. #include <proto/graphics.h>
  33. #include <proto/utility.h>
  34. #include <proto/asl.h>
  35. #include <proto/icon.h>
  36. #include <proto/dos.h>
  37. #include <libraries/amigaguide.h>
  38. #include <clib/amigaguide_protos.h>
  39. #include <pragmas/amigaguide_pragmas.h>
  40.  
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44.  
  45. #include <intuition/gadgetclass.h>
  46.  
  47. // following not in 2.02 headers
  48. #if INCLUDE_VERSION < 37
  49. LONG Stricmp(UBYTE *string1,UBYTE *string2);
  50. #pragma libcall UtilityBase Stricmp A2 9802
  51. #endif
  52.  
  53. #include "Prefs.h"
  54.  
  55. struct Library *GadToolsBase;
  56. struct Library *UtilityBase;
  57. struct Library *AslBase;
  58. struct Library *AmigaGuideBase;
  59.  
  60. struct FileRequester     *filereq        = NULL;
  61. char TempFilename[257];
  62. AMIGAGUIDECONTEXT         handle         = NULL;
  63. struct NewAmigaGuide        nag     = {NULL};
  64. ULONG                            ASig            = 0;
  65.  
  66. /* Version string for CLI version */
  67. char *Version = "$VER: TSMorph-prefs 2.3 (6.10.93)";
  68.  
  69. // Help nodes
  70. unsigned char *context[] = {
  71.     "",                    //    0
  72.     "Main",                // 1
  73.     "P-KEEPSETTINGS",    // 2
  74.     "P-CHANGEPALETTE",//    3
  75.     "P-CREATEICONS",    // 4
  76.     "P-CREATEICONSP",    // 5
  77.     "P-OPENMODE",        // 6
  78.     "P-PUBSCREEN",        // 7
  79.     "P-ZOOM",            // 8
  80.     "P-CREATEICONSR",    // 9
  81.     "P-DEPTH",            // 10
  82.     "P-DX",                // 11
  83.     "P-DY",                // 12
  84.     "P-LOADSCRIPT",    // 13
  85.     "P-MODE",            // 14
  86.     "P-POSTSCRIPT",    // 15
  87.     "P-PRESCRIPT",        // 16
  88.     "P-PUBSCREENR",    // 17
  89.     "P-QUALITY",        // 18
  90.     "P-SAVEFORMAT",    // 19
  91.     "P-ANTIALIAS",        // 20
  92.     "P-HELP",            // 21
  93.     "P-PREVIEW",        // 22
  94.     "P-CUSTOMMODE",    // 23
  95.     "P-CUSTOMDEPTH",    // 24
  96.     "TSMP-Close",        // 25
  97.     "TSMP-Depth",        // 26
  98.     "TSMP-Zoom",        // 27
  99.     "TSMorph-prefs",    // 28
  100.     "TSMP-Save",        // 29
  101.     "TSMP-Use",            // 30
  102.     "TSMP-Cancel",        // 31
  103.     "TSMP-men-Project",// 32
  104.     "TSMP-men-P-Open",// 33
  105.     "TSMP-men-P-SaveAs",// 34
  106.     "TSMP-men-P-Quit",// 35
  107.     "TSMP-men-Edit",    // 36
  108.     "TSMP-men-E-ResetD",//37
  109.     "TSMP-men-E-LastS",//38
  110.     "TSMP-men-E-Restore",//39
  111.     "TSMP-men-Settings",//40
  112.     "TSMP-men-S-Icons",//41
  113.     "TSMP-men",            //42
  114. };
  115.  
  116. // Settings
  117. STRPTR CustomScreen[100] = {"NONE",NULL};    // table of modes - headed by none
  118. ULONG CustomMode = 0;
  119. ULONG CustomDepth = 4;
  120. ULONG DX = 0;
  121. ULONG DY = 0;
  122. ULONG RenderMode = 0;
  123. ULONG SaveFormat = 0;
  124. ULONG Quality = 75;
  125. BOOL AntiAlias = 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. void
  158. main(void) {
  159.     int running = 1;
  160.     struct NameInfo buff;
  161.     ULONG id = INVALID_ID;
  162.     int kount = 1;
  163.     struct Node *MyNode;
  164.     struct AmigaGuideMsg *agm;
  165.     ULONG Signals;
  166.  
  167.     // Initialise Custom list and add "NONE"
  168.     NewList(&NodeList);
  169.     FirstNode.ln_Name = CustomScreen[0];
  170.     AddTail(&NodeList,&FirstNode);
  171.     // try and open amigaguide
  172.     if (AmigaGuideBase = OpenLibrary ("amigaguide.library", 34L)) {
  173.         nag.nag_BaseName        = "TSMorph";
  174.         nag.nag_Name            = "TSMorph.guide";
  175.         nag.nag_ClientPort    = "TSMorph-prefs_HELP";
  176.         nag.nag_Context        = context;
  177.         nag.nag_Flags            = HTF_NOACTIVATE;
  178.         nag.nag_PubScreen        = NULL;
  179.         if (handle = OpenAmigaGuideAsync(&nag, NULL)) {
  180.             ASig = AmigaGuideSignal(handle);
  181.         }
  182.     }
  183.     // Open various libraries
  184.     if (IntuitionBase = OpenLibrary("intuition.library",37)) {
  185.         if (GadToolsBase = OpenLibrary("gadtools.library",37)) {
  186.             if (DiskfontBase = OpenLibrary("diskfont.library",36)) {
  187.                 if (GfxBase = OpenLibrary("graphics.library",37)) {
  188.                     // build up list of display modes (max ~100)
  189.                     id = NextDisplayInfo(id);
  190.                     while ((id != INVALID_ID) && (kount < 98)) {
  191.                         if (GetDisplayInfoData(NULL,(UBYTE *)&buff,sizeof(struct NameInfo),DTAG_NAME,id)) {
  192.                             if ((MyNode = (struct Node *)calloc(1,sizeof(struct Node))) &&
  193.                                  (CustomScreen[kount] = (STRPTR)strdup(buff.Name))) {
  194.                                 MyNode->ln_Name = CustomScreen[kount];
  195.                                 AddTail(&NodeList,MyNode);
  196.                                 kount++;
  197.                             }
  198.                         }
  199.                         id = NextDisplayInfo(id);
  200.                     }
  201.                     CustomScreen[kount] = NULL;
  202.                     // open other libraries
  203.                     if (UtilityBase = OpenLibrary("utility.library",37)) {
  204.                         if (AslBase = OpenLibrary("asl.library",37)) {
  205.                             if (IconBase = OpenLibrary("icon.library",37)) {
  206.                                 // get File requester and open window
  207.                                 if (filereq = (struct FileRequest *)AllocFileRequest()) {
  208.                                     if (!SetupScreen()) {
  209.                                         if (!OpenTSMorphPrefsWindow()) {
  210.                                             // Set up custom modes
  211.                                             GT_SetGadgetAttrs(TSMorphPrefsGadgets[GDX_CustomMode],TSMorphPrefsWnd,NULL,
  212.                                                 GTLV_Labels,&NodeList,
  213.                                                 TAG_END);
  214.                                             // Load settings from ENV:
  215.                                             LoadSettings("ENV:TSMorph/TSMorph.prefs");
  216.                                             // Loop until quit
  217.                                             while (running) {
  218.                                                 Signals = Wait((ASig) |
  219.                                                                     (1L << TSMorphPrefsWnd->UserPort->mp_SigBit));
  220.                                                 // amigaguide stuff
  221.                                                 if (Signals & ASig) {
  222.                                                     if (handle) {
  223.                                                         while (agm = GetAmigaGuideMsg(handle)) {
  224.                                                             switch (agm->agm_Type) {
  225.                                                             case ToolCmdReplyID:
  226.                                                                 break;
  227.                                                             case ToolStatusID:
  228.                                                                 break;
  229.                                                             default:
  230.                                                                 break;
  231.                                                             }
  232.                                                             ReplyAmigaGuideMsg(agm);
  233.                                                         }
  234.                                                     }
  235.                                                 }
  236.                                                 // Normal stuff
  237.                                                 if (Signals & (1L << TSMorphPrefsWnd->UserPort->mp_SigBit)) {
  238.                                                     running = HandleTSMorphPrefsIDCMP();
  239.                                                 }
  240.                                                 // Close everything down
  241.                                             }
  242.                                         }
  243.                                         CloseTSMorphPrefsWindow();
  244.                                     }
  245.                                     CloseDownScreen();
  246.                                     FreeFileRequest(filereq);
  247.                                 }
  248.                                 CloseLibrary(IconBase);
  249.                             }
  250.                             CloseLibrary(AslBase);
  251.                         }
  252.                         CloseLibrary(UtilityBase);
  253.                     }
  254.                     CloseLibrary(GfxBase);
  255.                 }
  256.                 CloseLibrary(DiskfontBase);
  257.             }
  258.             CloseLibrary(GadToolsBase);
  259.         }
  260.         CloseLibrary(IntuitionBase);
  261.     }
  262.     if (AmigaGuideBase) {
  263.         if (handle) {
  264.             CloseAmigaGuide(handle);
  265.         }
  266.         CloseLibrary(AmigaGuideBase);
  267.     }
  268. }
  269.  
  270. /* Display help using amigaguide (if available)
  271.  * based on a number
  272.  */
  273. void
  274. help(ULONG helpnum) {
  275.     if (handle) {
  276.         SetAmigaGuideContext(handle,helpnum,NULL);
  277.         SendAmigaGuideContext(handle,NULL);
  278.     }
  279. }
  280.  
  281.  
  282. int
  283. CustomDepthClicked( void ) {
  284.     /* routine when gadget "Depth" is clicked. */
  285.     CustomDepth = TSMorphPrefsMsg.Code;
  286.     return 1;
  287. }
  288.  
  289. int
  290. DXClicked( void ) {
  291.     /* routine when gadget "DX" is clicked. */
  292.     DX = TSMorphPrefsMsg.Code;
  293.     return 1;
  294. }
  295.  
  296. int DYClicked( void ) {
  297.     /* routine when gadget "DY" is clicked. */
  298.     DY = TSMorphPrefsMsg.Code;
  299.     return 1;
  300. }
  301.  
  302. int
  303. ModeClicked( void ) {
  304.     /* routine when gadget "(OPEN MODE)" is clicked. */
  305.     OpenMode = TSMorphPrefsMsg.Code;
  306.     return 1;
  307. }
  308.  
  309. int
  310. SaveFormatClicked( void ) {
  311.     /* routine when gadget "SAVEFORMAT" is