home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / mandp.h < prev    next >
C/C++ Source or Header  |  1989-05-30  |  16KB  |  605 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this is the include file for MandelVroom standard includes.
  25.  */
  26.  
  27. #include <exec/types.h>
  28. #include <exec/lists.h>
  29. #include <exec/nodes.h>
  30. #include <exec/memory.h>
  31. #include <exec/execbase.h>
  32. #include <exec/semaphores.h>
  33.  
  34. #include <graphics/display.h>
  35. #include <graphics/gfxbase.h>
  36. #include <graphics/gfx.h>
  37. #include <graphics/gfxmacros.h>
  38.  
  39. #include <intuition/intuition.h>
  40. #include <intuition/intuitionbase.h>
  41.  
  42. #include <workbench/startup.h>
  43. #include <workbench/workbench.h>
  44.  
  45. #include <libraries/dosextens.h>
  46.  
  47. #include <iff/ilbm.h>
  48.  
  49. #include <stdio.h>
  50. #include <functions.h>
  51.  
  52. /**************************************************************************
  53.  *
  54.  * color cycling stuff
  55.  *
  56.  *************************************************************************/
  57.  
  58. #define EXDepth 6        /* Maximum depth (6=HAM) */
  59. #define maxColorReg 32
  60. #define maxCycles   4
  61. #define RNG_NORATE  36   /* Dpaint uses this rate to mean non-active */
  62.  
  63. #define REVERSE 0x2
  64.  
  65. typedef struct {
  66.    WORD  pad1;   /* future exp - store 0 here */
  67.    WORD  rate;   /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */
  68.    WORD  active; /* lo bit 0=no cycle, 1=yes; next bit 1=rvs */
  69.    UBYTE low;    /* range lower */
  70.    UBYTE high;   /* range upper */
  71.    } CrngChunk;
  72.  
  73. /*
  74.  * Mandelvroom uses the gadget ID's to decode the meaning of
  75.  * gadget related messages.  It uses a special encoding to indicate
  76.  * what window, and function this gadget is associated with.
  77.  *
  78.  * I split the gadget id into three fields:
  79.  *
  80.  *    window type - indicates how the window is being used (e.g.
  81.  *      contour or palette)
  82.  *
  83.  *    gadget type - general classification of gadget within the window
  84.  *
  85.  *    gadget number - in the case of an array of gadgets (like the pens
  86.  *      in the color palette) this is the array index.
  87.  */
  88.  
  89. /*
  90.  * This defines the bit positions of the fields within the gadget ID
  91.  */
  92.  
  93. #define WINDTYPEBITS 11
  94. #define TYPEBITS  6
  95.  
  96. /*
  97.  * These masks are used for extracting the fields from gadgetIDs
  98.  * when messages are received.
  99.  */
  100.  
  101. #define WINDMASK 0xffff
  102. #define TYPEMASK 0xf
  103. #define NUMMASK 0x3f
  104.  
  105. #define WIND_TYPE(g) ((g) >> WINDTYPEBITS & WINDMASK)
  106. #define GADG_TYPE(g) ((g) >> TYPEBITS & TYPEMASK)
  107. #define GADG_NUM(g)  ((g) & NUMMASK)
  108. #define CNT_NUM(a)   ((a)==CONTLAST ? NUMCONTS-1 : (a)+FirstContour)
  109.  
  110. /*
  111.  * These are the window types
  112.  */
  113.  
  114. #define PALTYPE   0 /* gadgetID indicates palette gadget */
  115. #define CONTYPE   1 /* gadgetID indicates contour gadget */
  116. #define PICTTYPE  2 /* gadgetID indicates picture gadget */
  117. #define HELPTYPE  3 /* gadgetID indicates help gadget */
  118. #define CYCTYPE   4 /* gadgetID indicates color cycling gadget */
  119. #define ORBTTYPE  5 /* gadgetID indicates orbit gadget */
  120.  
  121. /*
  122.  * These are the general classifications for palette gadgets
  123.  */
  124.  
  125. #define PALPENS  0   /* pen gadget in the palette */
  126. #define PALPOTS  1   /* Red, Green, Blue potentiometer gadgets */
  127. #define PALCNTLS 2   /* Controls (commands like copy, blend, exchange) */
  128.  
  129. /*
  130.  * Basis for individual ID expansion
  131.  */
  132.  
  133. #define PALPEN   (PALTYPE << WINDTYPEBITS | PALPENS  << TYPEBITS)
  134. #define PALPOT   (PALTYPE << WINDTYPEBITS | PALPOTS  << TYPEBITS)
  135. #define PALCNTL  (PALTYPE << WINDTYPEBITS | PALCNTLS << TYPEBITS)
  136.  
  137. /*
  138.  * These are the IDs for the command gadgets
  139.  */
  140.  
  141. #define PALCOPY  (PALCNTL | 0)
  142. #define PALRANGE (PALCNTL | 1)
  143. #define PALEXCG  (PALCNTL | 2)
  144.  
  145. /*
  146.  * Now we define the contour gadget IDs
  147.  *
  148.  * Start with the gadget types
  149.  */
  150.  
  151. #define CONTSELS  0  /* Contour window Pens */
  152. #define CONTUPS   1  /* Contour window increment gadget */
  153. #define CONTDOWNS 2  /* Contour window decrement gadget */
  154. #define CONTPOTS  3  /* Contour window potentiometer gadget */
  155. #define CONTCNTLS 4  /* Contour window controls */
  156.  
  157. /*
  158.  * Shift everything over so we can or in the specifics
  159.  */
  160.  
  161. #define CONTSEL  (CONTYPE << WINDTYPEBITS | CONTSELS  << TYPEBITS)
  162. #define CONTUP   (CONTYPE << WINDTYPEBITS | CONTUPS   << TYPEBITS)
  163. #define CONTDOWN (CONTYPE << WINDTYPEBITS | CONTDOWNS << TYPEBITS)
  164. #define CONTPOT  (CONTYPE << WINDTYPEBITS | CONTPOTS  << TYPEBITS)
  165. #define CONTCNTL (CONTYPE << WINDTYPEBITS | CONTCNTLS << TYPEBITS)
  166.  
  167. #define CONTLAST  (CONTSEL | 32)
  168.  
  169. /*
  170.  * Make up the command gadgets IDs for the contour window
  171.  */
  172.  
  173. #define CONTRECOL (CONTCNTL | 0)
  174. #define CONTSET   (CONTCNTL | 1)
  175. #define CONTSMTH  (CONTCNTL | 2)
  176. #define CONTCUT   (CONTCNTL | 3)
  177. #define CONTCOPY  (CONTCNTL | 4)
  178. #define CONTPASTE (CONTCNTL | 5)
  179. #define CONTCEIL  (CONTCNTL | 9)
  180. #define CONTBAR   (CONTCNTL | 10)
  181.  
  182. /*
  183.  * Shift everything over so we can or in the specifics
  184.  */
  185.  
  186. #define PICTCUR   (PICTTYPE << WINDTYPEBITS | 0)
  187. #define PICTGEN   (PICTTYPE << WINDTYPEBITS | 1)
  188. #define PICTIN    (PICTTYPE << WINDTYPEBITS | 2)
  189. #define PICTOUT   (PICTTYPE << WINDTYPEBITS | 3)
  190. #define PICTJULIA (PICTTYPE << WINDTYPEBITS | 4)
  191.  
  192. #define HELPUP     (HELPTYPE << WINDTYPEBITS | 0)
  193. #define HELPDOWN   (HELPTYPE << WINDTYPEBITS | 1)
  194. #define HELPSCROLL (HELPTYPE << WINDTYPEBITS | 2)
  195.  
  196. /*
  197.  * These are the general classifications for cycle gadgets
  198.  */
  199.  
  200. #define CYCRNUMS 0   /* cycle range indicators */
  201. #define CYCCNTLS 1   /* Controls (Range changer, direction, and speed) */
  202.  
  203. /*
  204.  * Basis for individual ID expansion
  205.  */
  206.  
  207. #define CYCRNUM  (CYCTYPE << WINDTYPEBITS | CYCRNUMS << TYPEBITS)
  208. #define CYCCNTL  (CYCTYPE << WINDTYPEBITS | CYCCNTLS << TYPEBITS)
  209.  
  210. /*
  211.  * These are the IDs for the command gadgets
  212.  */
  213.  
  214. #define CYCRANGE (CYCCNTL | 0)
  215. #define CYCDIR   (CYCCNTL | 1)
  216. #define CYCSPEED (CYCCNTL | 2)
  217. #define CYCON    (CYCCNTL | 3)
  218.  
  219. #define ORBTCNTLS 0 /* controls (go into orbit mode) */
  220. #define ORBTMODE  (ORBTCNTLS | 0)
  221.  
  222. /*
  223.  * Now for some miscelaneous definitions
  224.  *
  225.  * Define the number of contours the system allows.
  226.  */
  227.  
  228. #define NUMCONTS    256  /* This is total number of contours */
  229. #define DISPCONTS    32  /* This is how many are displayable */
  230.  
  231. #define VERSION 200
  232.  
  233. /*
  234.  * These definitions help us identify menu item selections.
  235.  */
  236.  
  237. /* Menu Project's, Items */
  238. #define NEWITEM      0
  239. #define CURITEM      1
  240. #define LOADITEM     2
  241. #define SAVEPROJ     3
  242. #define CLOSEPROJ    4
  243. #define SAVEILBM     5
  244. #define HELPITEM     6
  245. #define CANCELITEM   7
  246. #define QUITITEM     8
  247.  
  248. /* Display Menu's Items */
  249. #define COLORITEM     0
  250. #define CYCLEITEM     1
  251. #define CONTOURITEM   2
  252. #define AUTOCNTRITEM  3
  253. #define HISTOGRAMITEM 4
  254. #define BORDERITEM    5
  255. #define DEPTHITEM     6
  256. #define VIEWMODEITEM  7
  257. #define SCREENITEM    8
  258.  
  259. /* Menu: Edit, Item: ViewMode's, SubItems */
  260. #define HIRESSUB 0
  261. #define INTERLACESUB 1
  262. #define HALFBRITESUB 2
  263.  
  264. /* Menu: Edit, Item: Depth's, SubItems */
  265. #define BITPLANE1SUB  0
  266. #define BITPLANES2SUB 1
  267. #define BITPLANES3SUB 2
  268. #define BITPLANES4SUB 3
  269. #define BITPLANES5SUB 4
  270. #define BITPLANES6SUB 5
  271.  
  272. /* Menu: Edit, Item: Screen's SubItem */
  273.  
  274. #define WBENCHSUB  0
  275. #define STANDARD   1
  276.  
  277. /* Calculate Menu's Items */
  278. #define GENERATEITEM   0
  279. #define ZOOMITEM       1
  280. #define SCROLLITEM     2
  281. #define LENSITEM       3
  282. #define GENERATORITEM  4
  283. #define COUNTITEM      5
  284. #define STATSITEM      6
  285.  
  286. /* Menu: Edit, Item: ZoomIn's, SubItems */
  287. #define ZOOMIN    0
  288. #define ZOOMOUT   1
  289. #define ZOOMOFF   2
  290. #define ZOOMJULIA 3
  291.  
  292. /* Menu: Project, Item: Generate SubItems */
  293. #define STARTGEN     0
  294. #define STOPGEN      1
  295. #define CONTGEN      2
  296.  
  297. /* Menu: Project, Item: Scroll SubItems */
  298. #define SETSCROLL    0
  299. #define GENSCROLL    1
  300. #define CANCELSCROLL 2
  301.  
  302. /* Menu: Edit, Item: Generator, SubItems */
  303. #define INTGENERATOR   0
  304. #define FLOATGENERATOR 1
  305. #define IEEEGENERATOR  2
  306. #define INTIIGENERATOR 3
  307. #define _81GENERATOR   4
  308.  
  309. /* Special Menu's Items */
  310. #define PRESETITEM     0
  311. #define ORBITITEM      1
  312. #define ORBITMATHITEM  2
  313. #define MAXORBITEM     3
  314.  
  315. /* Menu: Special, Item: OrbitMode, subitems */
  316. #define INTORBIT  0
  317. #define FFPORBIT  1
  318. #define IEEEORBIT 2
  319.  
  320. /* Menu Entries */
  321. #define PROJECTMENU    0
  322. #define DISPLAYMENU    1
  323. #define CALCULATEMENU  2
  324. #define SPECIALMENU    3
  325.  
  326. #define TOGGLED11 0x0200
  327.  
  328. /* State definitions */
  329.  
  330. #define COPYRIGHTSTATE    0
  331. #define IDLESTATE         1
  332. #define COPYRGBSTATE      2
  333. #define SPREADRGBSTATE    3
  334. #define XCHGRGBSTATE      4
  335. #define SLIDERGBSTATE     5
  336. #define SETHEIGHTSTATE    6
  337. #define SETCONTSTATE      7
  338. #define SMOOTHCONTSTATE   8
  339. #define CUTCONTSTATE      9
  340. #define COPYCONTSTATE    10
  341. #define PASTECONTSTATE   11
  342. #define CEILINGSTATE     12
  343. #define SLIDEBARSTATE    13
  344. #define ORBITSTATE       14
  345. #define ZOOMINSTATE      15
  346. #define RESIZEZOOMSTATE  16
  347. #define PROPRESIZESTATE  17
  348. #define ZOOMDRAGSTATE    18
  349. #define QUERYHEIGHTSTATE 19
  350. #define SETJULIASTATE    20
  351. #define SLIDESPEEDSTATE  21
  352. #define CYCLERANGESTATE  22
  353. #define HELPSTATE        23
  354. #define SCROLLHELPSTATE  24
  355. #define SCROLLPICTSTATE  25
  356.  
  357. #define PARSEOK      0
  358. #define PARSEBAD     1
  359.  
  360. #define ZOOMCLOSEHIT  0
  361. #define ZOOMDRAGHIT   1
  362. #define ZOOMRESIZEHIT 2
  363. #define PROPRESIZEHIT 3
  364. #define NOTHINGHIT    4
  365.  
  366. /***************************************************************************
  367.  *
  368.  *  Structure for Mandelbrot and Julia Pictures
  369.  *
  370.  **************************************************************************/
  371.  
  372. struct Rect {
  373.   int Left, Top, Right, Bot;
  374. };
  375.  
  376. struct Picture {
  377.   struct Node pNode;          /* for a linked list of pictures */
  378.  
  379.   struct List    zList;       /* Pictures that have zoom     */
  380.                               /* open in this picture        */
  381.   struct Node    zNode;       /* Used to maintain the above  */
  382.  
  383.   struct Picture *DrawPict;   /* Picture that zoom box is in */
  384.  
  385.   UBYTE  ZoomType;            /* Zoom In or Out              */
  386.   int    NavTop,  NavBot;     /* Zoom box location and size  */
  387.   int    NavLeft, NavRight;
  388.  
  389.  
  390.   struct NewWindow *NewWind;  /* NewWindow structure         */
  391.   struct Window    *Window;   /* Open Intuition window       */
  392.  
  393.   struct RastPort ScrollRp;   /* rastport for saved image during scroll */
  394.   struct BitMap   ScrollBitMap; /* bitmap for saved image */
  395.  
  396.                               /* Window origin for scroll*/
  397.   struct Rect ImageLoc;       /* Scroll's image location in Pict->Window*/
  398.   struct Rect ClipImage;      /* location after clipping to Window */
  399.   struct Rect DataClip;       /* clipping also reflected in data */
  400.  
  401.   struct Gadget    *SizingGadget; /* sizing place            */
  402.                               /* Sempahore for window        */
  403.   struct SignalSemaphore WindowSemi;
  404.  
  405.   struct Gadget    *Gadgets;
  406.  
  407.   char   Title[40];           /* Window Title                */
  408.  
  409.   SHORT *Counts;              /* Pointer to data area. One   */
  410.   LONG   CountsSize;          /* SHORT per pixel.            */
  411.                               /* CountX * CountY * sizeof( SHORT ) */
  412.  
  413.   ULONG  Flags;               /* Flags regarding Picture specifics */
  414.  
  415.   int    LeftMarg,  TopMarg;
  416.   int    RightMarg, BotMarg;
  417.  
  418.   struct Task     *gTask;     /* Task that generates this    */
  419.   LONG   gSigBit, gSigMask;   /* Signal to free up paused tasks */
  420.   UBYTE  GenState;            /* Task state                  */
  421.   UBYTE  GenChildState;       /* Task state                  */
  422.   int    CurLine;             /* Index of Line generator is on */
  423.  
  424.   struct Task     *cTask;     /* Task for Recolor Slow       */
  425.   UBYTE  ColorState;          /* Task state                  */
  426.   UBYTE  ColorChildState;          /* Task state                  */
  427.  
  428.   struct Histogram *Hist;     /* Projects Histogram structure */
  429.  
  430.   SHORT OldMaxIter;           /* used for recalc */
  431.   LONG   TimeStamp[3];        /* Time stamp for calculation */
  432.  
  433.   /***********************************************************/
  434.  
  435.   double Real,     Imag;      /* For Julia only (Julia Seed) */
  436.                               /* Set it to 0.0 for Mand      */
  437.   double RealLow,  ImagLow;   /* Screen Boundaries for Julia */
  438.   double RealHigh, ImagHigh;  /* Complex Plane Origin for Mand */
  439.   double RealGap,  ImagGap;   /* Real and Imaginary parts of */
  440.  
  441.   SHORT  LeftEdge, TopEdge;   /* Window position on screen   */
  442.   SHORT  CountX, CountY;      /* Picture dimensions          */
  443.  
  444.   SHORT  MaxIteration;
  445.   UBYTE  MathMode;            /* Int32, FFP, IEEE            */
  446.  
  447.   SHORT  Heights[256];        /* Contours' heights and pens  */
  448.   UBYTE  Pens[256];
  449.  
  450.   UBYTE  ClrXlate[1024];      /* There are MaxIteration entries */
  451.  
  452.   SHORT  RGBs[32];            /* Red, Green, Blue values     */
  453.   USHORT ViewModes;
  454.   SHORT  Depth;
  455.  
  456.   SHORT  CycleOn;             /* Color Cycling stuff */
  457.   CrngChunk Crngs[maxCycles];
  458. };
  459.  
  460. /* Picture.Types */
  461.  
  462. #define JULIAPICT 1
  463. #define MANDPICT  2
  464.  
  465. /* Picture Flags */
  466.  
  467. #define NO_RAM_GENERATE 0x00000001
  468. #define LENS_DISPLAYED  0x00000002
  469. #define ZOOM_BOX_OPEN   0x00000004
  470. #define SCROLL_HAPPENED 0x00000008
  471. #define PROJECT_CHANGED 0x00000010
  472. #define BORDERLESS_PROJ 0x00000020
  473.  
  474. #define GENPENDSTATE    1
  475. #define CONTINUESTATE   2
  476. #define GENERATESTATE   3
  477. #define PAUSESTATE      4
  478. #define FINISHEDSTATE   5
  479. #define KILLSTATE       6
  480.  
  481. #define RECOLORINCOMPLETE 0
  482. #define RECOLORCOMPLETE   1
  483.  
  484. #define GENINCOMPLETE 0
  485. #define GENCOMPLETE   1
  486. #define NOSIGSTATE    2
  487.  
  488. #define INT1632MATH 0
  489. #define FFPMATH     1
  490. #define IEEEMATH    2
  491. #define INT3232MATH 3
  492. #define M68881MATH  4
  493.  
  494. #define INTORBMATH  0
  495. #define FFPORBMATH  1
  496. #define IEEEORBMATH 2
  497.  
  498. /***************************************************************************
  499.  *
  500.  *  External variables
  501.  *
  502.  **************************************************************************/
  503.  
  504. /* These are global system variables */
  505.  
  506. extern struct Picture *CurPict;
  507.  
  508. extern int CurContour;
  509. extern SHORT  NumContours;
  510.  
  511. extern LONG   TopMarg, BotMarg, LeftMarg, RightMarg;
  512.  
  513. extern struct Screen *screen;
  514. extern struct ViewPort *vp;
  515. extern int Num_vp_Colors;
  516.  
  517. extern struct Window *PalWind, *ContWind, *StatsWind, *HelpWind;
  518. extern struct Window *HistWind,*CycWind, *OrbitWind;
  519. extern struct Window *CurWind, *CurPlot, *ClosedWind, *BackWind;
  520.  
  521. extern struct Menu Menu[];
  522.  
  523. extern SHORT  XScale, YScale;
  524. extern SHORT  MouseX, MouseY;
  525.  
  526. extern LONG CurPen;
  527.  
  528. extern UBYTE  ClosePlot;
  529. extern UBYTE  QuitScreen;
  530.  
  531. extern LONG   mSigBit,mSigMask;
  532. extern struct Task *mTask;
  533.  
  534. extern BYTE FromWB;
  535.  
  536. extern BYTE State, SubState, Parse_rc;
  537.  
  538. struct Window *OpenMyWind();
  539.  
  540. struct Gadget *MakeBool(), *MakePot(), *MakeString();
  541. struct IntuiText *MakeIntui(), *ShadowIntui();
  542. struct Border *ShadowBorder();
  543.  
  544. #define AddSemaphore myAddSemaphore
  545.  
  546. /*
  547.  * Picture window ( Julia and Mandlebrot windows ) margins
  548.  */
  549.  
  550. #define TOPMARG   TopMarg
  551. #define BOTMARG   BotMarg
  552. #define LEFTMARG  LeftMarg
  553. #define RIGHTMARG RightMarg
  554.  
  555. #define SUCCESSFUL   0
  556. #define UNSUCCESSFUL -1
  557.  
  558. #define ChildPause(Pict) {if(Pict->GenState==PAUSESTATE)ChildSignal(Pict);}
  559.  
  560. /**************************************************************************
  561.  *
  562.  * Histogram stuff
  563.  *
  564.  *************************************************************************/
  565.  
  566. struct Histogram {
  567.   int *Table;
  568.   int  TableSize;
  569. };
  570.  
  571. #define AllocHistStruct() (struct Histogram *)safeAllocMem(sizeof(struct Histogram), MEMF_CLEAR)
  572. #define FreeHistStruct(p) FreeMem(p,sizeof(struct Histogram))
  573.  
  574. #define AllocHistTable(s) (int *)safeAllocMem(s*sizeof(int), MEMF_CLEAR)
  575. #define FreeHistTable(p)  FreeMem(p->Table,p->TableSize*sizeof(int))
  576.  
  577. #define AddHead(List,Node) safeAddHead(List,Node,__FILE__,__LINE__,__FUNC__)
  578. #define Remove(Node)       safeRemove(Node,__FILE__,__LINE__,__FUNC__)
  579.  
  580. /**************************************************************************
  581.  *
  582.  * standard stuff
  583.  *
  584.  *************************************************************************/
  585.  
  586. #define BEVELEDUP    0
  587. #define BEVELEDDOWN  1
  588.  
  589. #define NORMALPEN    1
  590. #define SHADOWPEN    3
  591. #define MEDIUMPEN    2
  592. #define HIGHLIGHTPEN 2
  593. #define POTPEN       3
  594.  
  595. #ifdef MEM_DEBUG
  596.  
  597. #include "safeallocmem.h"
  598.  
  599. #else
  600.  
  601. APTR safeAllocMem();
  602.  
  603. #endif
  604.  
  605.