home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 329.lha / MultiPlot / source / physio.c < prev    next >
C/C++ Source or Header  |  1990-01-05  |  37KB  |  920 lines

  1. #include <graphics/display.h>
  2. #include <libraries/dosextens.h>
  3. #include <libraries/diskfont.h>
  4. #include <exec/exec.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <graphics/regions.h>
  7. #include <devices/keymap.h>
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <workbench/startup.h>
  11. #include <graphics/gfxmacros.h>
  12. #include <graphics/gfxbase.h>
  13. #include <math.h>
  14.  
  15. #include "struct.h"
  16. #include "plot.h"
  17.  
  18. extern int MAXVERT;
  19.  
  20. struct Window *OpenWindow();
  21. struct InputEvent *Intuition();
  22. struct Screen *OpenScreen();
  23. int WrtPlt();
  24.  
  25. struct RastPort *rp;
  26. struct ViewPort *vp;
  27. struct Window *window;
  28. struct IntuiMessage *msg;
  29. struct Screen *screen;
  30.  
  31. struct NewScreen newscreen = {
  32.         0,0,                    /* start pos.*/
  33.         MAXHORIZ,MaxVERT,4,     /* width height depth (4 bit planes) */
  34.         2,1,                    /* detail pen, block pen */
  35.         HIRES | LACE,           /* viewing mode (640x400 interlaced) */
  36.         CUSTOMSCREEN,           /* screen type */
  37.         NULL,                   /* font */
  38.         "MultiPlot XLN            © T Mooney 1986,1988 and © AG Baxter 1989",            /* screen title */
  39.         NULL                    /* gadget pointer */
  40.         };
  41.  
  42. struct NewWindow newwindow = {
  43.         0,0,                                    /* Starting corner */
  44.         MAXHORIZ,MaxVERT,                       /* Width, height */
  45.         1,14,                                   /* detail, block pens */
  46.         MENUPICK | MOUSEMOVE | MOUSEBUTTONS,    /* IDCMP flags */
  47.         ACTIVATE | BORDERLESS | NOCAREREFRESH | REPORTMOUSE,
  48.         NULL,                                   /* Pointer to first gadget */
  49.         NULL,                                   /* Pointer to checkmark */
  50.         NULL,                                   /* title */
  51.         NULL,                                   /* screen pointer */
  52.         NULL,                                   /* bitmap pointer */
  53.         0,0,0,0,                                /* sizing limits */
  54.         CUSTOMSCREEN                            /* type of screen */
  55.         };
  56.  
  57.  
  58. void InitColors()
  59. {
  60.    SetRGB4(vp,0,15,10,5);   SetRGB4(vp,1,0,0,0);    SetRGB4(vp,2,15,15,15);
  61.    SetRGB4(vp,3,15,0,0);    SetRGB4(vp,4,0,0,0);    SetRGB4(vp,5,15,0,0);
  62.    SetRGB4(vp,6,0,12,0);    SetRGB4(vp,7,0,5,15);   SetRGB4(vp,8,13,13,0);
  63.    SetRGB4(vp,9,0,13,13);   SetRGB4(vp,10,15,0,15); SetRGB4(vp,11,10,10,0);
  64.    SetRGB4(vp,12,8,8,8);    SetRGB4(vp,13,5,5,0);   SetRGB4(vp,14,0,10,15);
  65.    SetRGB4(vp,15,15,8,0);
  66. }
  67.  
  68.  
  69. struct IntuiText MText1 = {
  70.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  71.         0,0,    /* XY origin relative to container TopLeft */
  72.         NULL,   /* font pointer or NULL for default */
  73.         "White BG",     /* pointer to text */
  74.         NULL    /* next IntuiText structure */
  75. };
  76.  
  77. struct MenuItem Whitebg = {
  78.         NULL,   /* next MenuItem structure */
  79.         0,45,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  80.         120,8,  /* hit box width and height */
  81.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  82.         0,      /* each bit mutually-excludes a same-level Item */
  83.         (APTR)&MText1,  /* Item render  (IntuiText or Image or NULL) */
  84.         NULL,   /* Select render */
  85.         'w',    /* alternate command-key */
  86.         NULL,   /* SubItem list */
  87.         MENUNULL        /* filled in by Intuition for drag selections */
  88. };
  89. #define MI_WHITEBG 5
  90.  
  91. struct IntuiText MText2 = {
  92.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  93.         0,0,    /* XY origin relative to container TopLeft */
  94.         NULL,   /* font pointer or NULL for default */
  95.         "Axes", /* pointer to text */
  96.         NULL    /* next IntuiText structure */
  97. };
  98.  
  99. struct MenuItem Axes = {
  100.         &Whitebg,     /* next MenuItem structure */
  101.         0,36,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  102.         120,8,  /* hit box width and height */
  103.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  104.         0,      /* each bit mutually-excludes a same-level Item */
  105.         (APTR)&MText2,  /* Item render  (IntuiText or Image or NULL) */
  106.         NULL,   /* Select render */
  107.         'a',    /* alternate command-key */
  108.         NULL,   /* SubItem list */
  109.         MENUNULL        /* filled in by Intuition for drag selections */
  110. };
  111. #define MI_AXES 4
  112.  
  113. struct IntuiText MText3 = {
  114.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  115.         0,0,    /* XY origin relative to container TopLeft */
  116.         NULL,   /* font pointer or NULL for default */
  117.         "Grid", /* pointer to text */
  118.         NULL    /* next IntuiText structure */
  119. };
  120.  
  121. struct MenuItem Grid = {
  122.         &Axes,     /* next MenuItem structure */
  123.         0,27,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  124.         120,8,  /* hit box width and height */
  125.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  126.         0,      /* each bit mutually-excludes a same-level Item */
  127.         (APTR)&MText3,  /* Item render  (IntuiText or Image or NULL) */
  128.         NULL,   /* Select render */
  129.         's',    /* alternate command-key */
  130.         NULL,   /* SubItem list */
  131.         MENUNULL        /* filled in by Intuition for drag selections */
  132. };
  133. #define MI_GRID 3
  134.  
  135. struct IntuiText MText4 = {
  136.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  137.         0,0,    /* XY origin relative to container TopLeft */
  138.         NULL,   /* font pointer or NULL for default */
  139.         "Cross Hair",   /* pointer to text */
  140.         NULL    /* next IntuiText structure */
  141. };
  142.  
  143. struct MenuItem Crosshair = {
  144.         &Grid,     /* next MenuItem structure */
  145.         0,18,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  146.         120,8,  /* hit box width and height */
  147.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  148.         0,      /* each bit mutually-excludes a same-level Item */
  149.         (APTR)&MText4,  /* Item render  (IntuiText or Image or NULL) */
  150.         NULL,   /* Select render */
  151.         NULL,   /* alternate command-key */
  152.         NULL,   /* SubItem list */
  153.         MENUNULL        /* filled in by Intuition for drag selections */
  154. };
  155. #define MI_CROSSHAIR 2
  156.  
  157. struct IntuiText MText5 = {
  158.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  159.         0,0,    /* XY origin relative to container TopLeft */
  160.         NULL,   /* font pointer or NULL for default */
  161.         "Get How To",   /* pointer to text */
  162.         NULL    /* next IntuiText structure */
  163. };
  164.  
  165. struct MenuItem Gethowto = {
  166.         &Crosshair,     /* next MenuItem structure */
  167.         0,9,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  168.         120,8,  /* hit box width and height */
  169.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  170.         0,      /* each bit mutually-excludes a same-level Item */
  171.         (APTR)&MText5,  /* Item render  (IntuiText or Image or NULL) */
  172.         NULL,   /* Select render */
  173.         'g',    /* alternate command-key */
  174.         NULL,   /* SubItem list */
  175.         MENUNULL        /* filled in by Intuition for drag selections */
  176. };
  177. #define MI_GETHOWTO 1
  178.  
  179. struct IntuiText MText6 = {
  180.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  181.         0,0,    /* XY origin relative to container TopLeft */
  182.         NULL,   /* font pointer or NULL for default */
  183.         "Redraw",       /* pointer to text */
  184.         NULL    /* next IntuiText structure */
  185. };
  186.  
  187. struct MenuItem Redraw = {
  188.         &Gethowto,     /* next MenuItem structure */
  189.         0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  190.         120,8,  /* hit box width and height */
  191.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  192.         0,      /* each bit mutually-excludes a same-level Item */
  193.         (APTR)&MText6,  /* Item render  (IntuiText or Image or NULL) */
  194.         NULL,   /* Select render */
  195.         'r',    /* alternate command-key */
  196.         NULL,   /* SubItem list */
  197.         MENUNULL        /* filled in by Intuition for drag selections */
  198. };
  199. #define MI_REDRAW 0
  200.  
  201. struct Menu Options = {
  202.         NULL,   /* next Menu structure */
  203.         137,0,  /* XY origin of Menu hit box relative to screen TopLeft */
  204.         75,0,   /* Menu hit box width and height */
  205.         MENUENABLED,    /* Menu flags */
  206.         "Options",      /* text of Menu name */
  207.         &Redraw      /* MenuItem linked list pointer */
  208. };
  209. #define M_OPTIONS 2
  210.  
  211. struct IntuiText MText7 = {
  212.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  213.         0,0,   /* XY origin relative to container TopLeft */
  214.         NULL,   /* font pointer or NULL for default */
  215.         "XY Region",    /* pointer to text */
  216.         NULL    /* next IntuiText structure */
  217. };
  218.  
  219. struct MenuItem Xyregion = {
  220.         NULL,   /* next SubItem structure */
  221.         97,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  222.         72,8,   /* hit box width and height */
  223.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  224.         0,      /* each bit mutually-excludes a same-level Item */
  225.         (APTR)&MText7,  /* Item render  (IntuiText or Image or NULL) */
  226.         NULL,   /* Select render */
  227.         NULL,   /* alternate command-key */
  228.         NULL,   /* no SubItem list for SubItems */
  229.         MENUNULL        /* filled in by Intuition for drag selections */
  230. };
  231. #define SI_XYREGION 2
  232.  
  233. UBYTE YTextOff[]="Y Region";
  234. UBYTE YTextOn[]= "YLock on";
  235.  
  236. struct IntuiText MText8 = {
  237.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  238.         0,0,   /* XY origin relative to container TopLeft */
  239.         NULL,   /* font pointer or NULL for default */
  240.         YTextOff,     /* pointer to text */
  241.         NULL    /* next IntuiText structure */
  242. };
  243.  
  244. struct MenuItem Yregion = {
  245.         &Xyregion,      /* next SubItem structure */
  246.         97,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  247.         72,8,   /* hit box width and height */
  248.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  249.         0,      /* each bit mutually-excludes a same-level Item */
  250.         (APTR)&MText8,  /* Item render  (IntuiText or Image or NULL) */
  251.         NULL,   /* Select render */
  252.         NULL,   /* alternate command-key */
  253.         NULL,   /* no SubItem list for SubItems */
  254.         MENUNULL        /* filled in by Intuition for drag selections */
  255. };
  256. #define SI_YREGION 1
  257.  
  258. UBYTE XTextOff[]="X Region";
  259. UBYTE XTextOn[]= "XLock on";
  260.  
  261. struct IntuiText MText9 = {
  262.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  263.         0,0,   /* XY origin relative to container TopLeft */
  264.         NULL,   /* font pointer or NULL for default */
  265.         XTextOff,     /* pointer to text */
  266.         NULL    /* next IntuiText structure */
  267. };
  268.  
  269. struct MenuItem Xregion = {
  270.         &Yregion,      /* next SubItem structure */
  271.         97,8,  /* XY of Item hitbox relative to TopLeft of parent hitbox */
  272.         72,8,   /* hit box width and height */
  273.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  274.         0,      /* each bit mutually-excludes a same-level Item */
  275.         (APTR)&MText9,  /* Item render  (IntuiText or Image or NULL) */
  276.         NULL,   /* Select render */
  277.         NULL,   /* alternate command-key */
  278.         NULL,   /* no SubItem list for SubItems */
  279.         MENUNULL        /* filled in by Intuition for drag selections */
  280. };
  281. #define SI_XREGION 0
  282.  
  283. struct IntuiText MText10 = {
  284.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  285.         0,0,    /* XY origin relative to container TopLeft */
  286.         NULL,   /* font pointer or NULL for default */
  287.         "Locks",        /* pointer to text */
  288.         NULL    /* next IntuiText structure */
  289. };
  290.  
  291. struct MenuItem Locks = {
  292.         NULL,   /* next MenuItem structure */
  293.         0,27,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  294.         112,8,  /* hit box width and height */
  295.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  296.         0,      /* each bit mutually-excludes a same-level Item */
  297.         (APTR)&MText10, /* Item render  (IntuiText or Image or NULL) */
  298.         NULL,   /* Select render */
  299.         NULL,   /* alternate command-key */
  300.         &Xregion,      /* SubItem list */
  301.         MENUNULL        /* filled in by Intuition for drag selections */
  302. };
  303. #define MI_LOCKS 3
  304.  
  305. struct IntuiText MText11 = {
  306.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  307.         0,0,    /* XY origin relative to container TopLeft */
  308.         NULL,   /* font pointer or NULL for default */
  309.         "Full Plot",    /* pointer to text */
  310.         NULL    /* next IntuiText structure */
  311. };
  312.  
  313. struct MenuItem Fullplot = {
  314.         &Locks,    /* next MenuItem structure */
  315.         0,18,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  316.         112,8,  /* hit box width and height */
  317.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  318.         0,      /* each bit mutually-excludes a same-level Item */
  319.         (APTR)&MText11, /* Item render  (IntuiText or Image or NULL) */
  320.         NULL,   /* Select render */
  321.         'f',    /* alternate command-key */
  322.         NULL,   /* SubItem list */
  323.         MENUNULL        /* filled in by Intuition for drag selections */
  324. };
  325.  
  326. #define MI_FULLPLOT 2
  327.  
  328. struct IntuiText MText12 = {
  329.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  330.         0,0,    /* XY origin relative to container TopLeft */
  331.         NULL,   /* font pointer or NULL for default */
  332.         "Slide",        /* pointer to text */
  333.         NULL    /* next IntuiText structure */
  334. };
  335.  
  336. struct MenuItem Slide = {
  337.         &Fullplot,     /* next MenuItem structure */
  338.         0,9,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  339.         112,8,  /* hit box width and height */
  340.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  341.         0,      /* each bit mutually-excludes a same-level Item */
  342.         (APTR)&MText12, /* Item render  (IntuiText or Image or NULL) */
  343.         NULL,   /* Select render */
  344.         NULL,   /* alternate command-key */
  345.         NULL,   /* SubItem list */
  346.         MENUNULL        /* filled in by Intuition for drag selections */
  347. };
  348. #define MI_SLIDE 1
  349.  
  350. struct IntuiText MText13 = {
  351.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  352.         0,0,    /* XY origin relative to container TopLeft */
  353.         NULL,   /* font pointer or NULL for default */
  354.         "Zoom", /* pointer to text */
  355.         NULL    /* next IntuiText structure */
  356. };
  357.  
  358. struct MenuItem Zoom = {
  359.         &Slide,     /* next MenuItem structure */
  360.         0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  361.         112,8,  /* hit box width and height */
  362.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  363.         0,      /* each bit mutually-excludes a same-level Item */
  364.         (APTR)&MText13, /* Item render  (IntuiText or Image or NULL) */
  365.         NULL,   /* Select render */
  366.         NULL,   /* alternate command-key */
  367.         NULL,   /* SubItem list */
  368.         MENUNULL        /* filled in by Intuition for drag selections */
  369. };
  370. #define MI_ZOOM 0
  371.  
  372. struct Menu Edit = {
  373.         &Options, /* next Menu structure */
  374.         82,0,   /* XY origin of Menu hit box relative to screen TopLeft */
  375.         48,0,   /* Menu hit box width and height */
  376.         MENUENABLED,    /* Menu flags */
  377.         "Edit", /* text of Menu name */
  378.         &Zoom      /* MenuItem linked list pointer */
  379. };
  380. #define M_EDIT 1
  381.  
  382. struct IntuiText MText14 = {
  383.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  384.         0,0,    /* XY origin relative to container TopLeft */
  385.         NULL,   /* font pointer or NULL for default */
  386.         "Quit", /* pointer to text */
  387.         NULL    /* next IntuiText structure */
  388. };
  389.  
  390. struct MenuItem Quit = {
  391.         NULL,   /* next MenuItem structure */
  392.         0,27,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  393.         80,8,   /* hit box width and height */
  394.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  395.         0,      /* each bit mutually-excludes a same-level Item */
  396.         (APTR)&MText14, /* Item render  (IntuiText or Image or NULL) */
  397.         NULL,   /* Select render */
  398.         'x',    /* alternate command-key */
  399.         NULL,   /* SubItem list */
  400.         MENUNULL        /* filled in by Intuition for drag selections */
  401. };
  402. #define MI_QUIT 3
  403.  
  404. struct IntuiText MText15 = {
  405.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  406.         0,0,    /* XY origin relative to container TopLeft */
  407.         NULL,   /* font pointer or NULL for default */
  408.         "Print",        /* pointer to text */
  409.         NULL    /* next IntuiText structure */
  410. };
  411.  
  412. struct MenuItem Print = {
  413.         &Quit,    /* next MenuItem structure */
  414.         0,18,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  415.         80,8,   /* hit box width and height */
  416.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  417.         0,      /* each bit mutually-excludes a same-level Item */
  418.         (APTR)&MText15, /* Item render  (IntuiText or Image or NULL) */
  419.         NULL,   /* Select render */
  420.         'p',    /* alternate command-key */
  421.         NULL,   /* SubItem list */
  422.         MENUNULL        /* filled in by Intuition for drag selections */
  423. };
  424. #define MI_PRINT 2
  425.  
  426. struct IntuiText MText16 = {
  427.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  428.         0,0,    /* XY origin relative to container TopLeft */
  429.         NULL,   /* font pointer or NULL for default */
  430.         "IntroCAD",     /* pointer to text */
  431.         NULL    /* next IntuiText structure */
  432. };
  433.  
  434. struct MenuItem Introcad = {
  435.         NULL,   /* next SubItem structure */
  436.         65,40,  /* XY of Item hitbox relative to TopLeft of parent hitbox */
  437.         104,8,  /* hit box width and height */
  438.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  439.         0,      /* each bit mutually-excludes a same-level Item */
  440.         (APTR)&MText16, /* Item render  (IntuiText or Image or NULL) */
  441.         NULL,   /* Select render */
  442.         'c',    /* alternate command-key */
  443.         NULL,   /* no SubItem list for SubItems */
  444.         MENUNULL        /* filled in by Intuition for drag selections */
  445. };
  446. #define SI_ICAD 4
  447.  
  448. struct IntuiText MText17 = {
  449.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  450.         0,0,    /* XY origin relative to container TopLeft */
  451.         NULL,   /* font pointer or NULL for default */
  452.         "mCAD", /* pointer to text */
  453.         NULL    /* next IntuiText structure */
  454. };
  455.  
  456. struct MenuItem Mcad = {
  457.         &Introcad,      /* next SubItem structure */
  458.         65,32,  /* XY of Item hitbox relative to TopLeft of parent hitbox */
  459.         104,8,  /* hit box width and height */
  460.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  461.         0,      /* each bit mutually-excludes a same-level Item */
  462.         (APTR)&MText17, /* Item render  (IntuiText or Image or NULL) */
  463.         NULL,   /* Select render */
  464.         'm',    /* alternate command-key */
  465.         NULL,   /* no SubItem list for SubItems */
  466.         MENUNULL        /* filled in by Intuition for drag selections */
  467. };
  468. #define SI_MCAD 3
  469.  
  470. struct IntuiText MText18 = {
  471.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  472.         0,0,    /* XY origin relative to container TopLeft */
  473.         NULL,   /* font pointer or NULL for default */
  474.         "Draw", /* pointer to text */
  475.         NULL    /* next IntuiText structure */
  476. };
  477.  
  478. struct MenuItem Plot = {
  479.         &Mcad,      /* next SubItem structure */
  480.         65,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  481.         104,8,  /* hit box width and height */
  482.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  483.         0,      /* each bit mutually-excludes a same-level Item */
  484.         (APTR)&MText18, /* Item render  (IntuiText or Image or NULL) */
  485.         NULL,   /* Select render */
  486.         'd',    /* alternate command-key */
  487.         NULL,   /* no SubItem list for SubItems */
  488.         MENUNULL        /* filled in by Intuition for drag selections */
  489. };
  490. #define SI_DRAW 2
  491.  
  492. struct IntuiText MText19 = {
  493.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  494.         0,0,    /* XY origin relative to container TopLeft */
  495.         NULL,   /* font pointer or NULL for default */
  496.         "HPLG", /* pointer to text */
  497.         NULL    /* next IntuiText structure */
  498. };
  499.  
  500. struct MenuItem Hplg = {
  501.         &Plot,      /* next SubItem structure */
  502.         65,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  503.         104,8,  /* hit box width and height */
  504.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  505.         0,      /* each bit mutually-excludes a same-level Item */
  506.         (APTR)&MText19, /* Item render  (IntuiText or Image or NULL) */
  507.         NULL,   /* Select render */
  508.         'h',    /* alternate command-key */
  509.         NULL,   /* no SubItem list for SubItems */
  510.         MENUNULL        /* filled in by Intuition for drag selections */
  511. };
  512. #define SI_HPLG 1
  513.  
  514. struct IntuiText MText20 = {
  515.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  516.         0,0,    /* XY origin relative to container TopLeft */
  517.         NULL,   /* font pointer or NULL for default */
  518.         "IFF",  /* pointer to text */
  519.         NULL    /* next IntuiText structure */
  520. };
  521.  
  522. struct MenuItem Iff = {
  523.         &Hplg,      /* next SubItem structure */
  524.         65,8,  /* XY of Item hitbox relative to TopLeft of parent hitbox */
  525.         104,8,  /* hit box width and height */
  526.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  527.         0,      /* each bit mutually-excludes a same-level Item */
  528.         (APTR)&MText20, /* Item render  (IntuiText or Image or NULL) */
  529.         NULL,   /* Select render */
  530.         'i',    /* alternate command-key */
  531.         NULL,   /* no SubItem list for SubItems */
  532.         MENUNULL        /* filled in by Intuition for drag selections */
  533. };
  534. #define SI_IFF 0
  535.  
  536. struct IntuiText MText21 = {
  537.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  538.         0,0,    /* XY origin relative to container TopLeft */
  539.         NULL,   /* font pointer or NULL for default */
  540.         "Save", /* pointer to text */
  541.         NULL    /* next IntuiText structure */
  542. };
  543.  
  544. struct MenuItem Save = {
  545.         &Print,    /* next MenuItem structure */
  546.         0,9,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  547.         80,8,   /* hit box width and height */
  548.         ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  549.         0,      /* each bit mutually-excludes a same-level Item */
  550.         (APTR)&MText21, /* Item render  (IntuiText or Image or NULL) */
  551.         NULL,   /* Select render */
  552.         NULL,   /* alternate command-key */
  553.         &Iff,      /* SubItem list */
  554.         MENUNULL        /* filled in by Intuition for drag selections */
  555. };
  556. #define MI_SAVE 1
  557.  
  558. struct IntuiText MText22 = {
  559.         3,1,COMPLEMENT, /* front and back text pens, drawmode and fill byte */
  560.         0,0,    /* XY origin relative to container TopLeft */
  561.         NULL,   /* font pointer or NULL for default */
  562.         "New",  /* pointer to text */
  563.         NULL    /* next IntuiText structure */
  564. };
  565.  
  566. struct MenuItem New = {
  567.         &Save,    /* next MenuItem structure */
  568.         0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  569.         80,8,   /* hit box width and height */
  570.         ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  571.         0,      /* each bit mutually-excludes a same-level Item */
  572.         (APTR)&MText22, /* Item render  (IntuiText or Image or NULL) */
  573.         NULL,   /* Select render */
  574.         'n',    /* alternate command-key */
  575.         NULL,   /* SubItem list */
  576.         MENUNULL        /* filled in by Intuition for drag selections */
  577. };
  578. #define MI_NEW 0
  579. struct Menu Project = {
  580.         &Edit, /* next Menu structure */
  581.         0,0,    /* XY origin of Menu hit box relative to screen TopLeft */
  582.         75,0,   /* Menu hit box width and height */
  583.         MENUENABLED,    /* Menu flags */
  584.         "Project",      /* text of Menu name */
  585.         &New     /* MenuItem linked list pointer */
  586. };
  587. #define M_PROJECT 0
  588.  
  589.  
  590. /********/
  591. InitWind()
  592. {
  593.    newwindow.Screen = screen; window = OpenWindow(&newwindow);
  594.    rp = window->RPort; vp = &window->WScreen->ViewPort;
  595.    SetDrMd(rp,JAM1); SetAPen(rp,1);
  596.    InitColors();
  597.    SetMenuStrip(window,&Project); ShowTitle(screen,FALSE);
  598.    return(1);
  599. }
  600.  
  601.  
  602. /************/
  603. void CleanUp()
  604. {ClearMenuStrip(window); CloseWindow(window);}
  605.  
  606.  
  607. /************************/
  608. void AttrOnOff(Pict, item)
  609. struct Pict *Pict;
  610. int item;
  611. {
  612.    ClearMenuStrip(window);
  613.    switch(item) {
  614.    case SI_XREGION:
  615.       MText9.IText = (Pict->XRegionLock ? XTextOn : XTextOff);
  616.       break;
  617.    case SI_YREGION:
  618.       MText8.IText = (Pict->YRegionLock ? YTextOn : YTextOff);
  619.       break;
  620.    default: break;
  621.    }
  622.    SetMenuStrip(window, &Project);
  623. }
  624.  
  625.  
  626. /**************************************************************************/
  627. void PToU();
  628.  
  629. USHORT InvisPtr[] = {
  630.    0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0,
  631.    0x0,0x0, 0x0,0x0, 0x0,0x0, 0x0,0x0};
  632.  
  633. static short XHair = FALSE;
  634. static short WhiteBG = FALSE;
  635.  
  636. /*****************/
  637. void PutXHair(x,y)
  638. short x,y;
  639. {Move(rp,0,y); Draw(rp,MAXHORIZ,y); Move(rp,x,0); Draw(rp,x,MAXVERT);}
  640.  
  641. /**************************/
  642. void GetXHair(x,y)
  643. short *x, *y;
  644. {SetPointer(window,InvisPtr,9,9,0,0); SetDrMd(rp,COMPLEMENT); PutXHair(*x,*y);}
  645.  
  646. /***********************/
  647. void KillXHair(x,y)
  648. short x,y;
  649. {ClearPointer(window); PutXHair(x,y); SetDrMd(rp,JAM1);}
  650.  
  651. /*****************************/
  652. void RubberBox(x1, y1, x2, y2)
  653. short *x1, *y1, *x2, *y2;
  654. {
  655.    Move(rp,x1,y1);
  656.    if (XHair) {Draw(rp,x1,y2); Move(rp,x1,y1); Draw(rp,x2,y1);}
  657.    else {Draw(rp,x1,y2); Draw(rp,x2,y2); Draw(rp,x2,y1); Draw(rp,x1,y1);}
  658. }
  659.  
  660. #define NO_OBJECT 0
  661. #define REGION 1
  662. #define LINE 2
  663. #define BOX 3
  664. #define SLIDE 4
  665. extern USHORT chip WaitSprite[];
  666. extern int KEEP_GOING;
  667. extern char filename[150];
  668. extern char StartDir[150];
  669.  
  670.  
  671. /*************/
  672. CheckUser(Pict)
  673. struct Pict *Pict;
  674. {
  675.    ULONG class;
  676.    USHORT code;
  677.    int retval = NOACTION, MouseMoved;
  678.    int screensave();
  679.    short x, y, x0, y0, x1, y1;
  680.    static short RubberObj = NO_OBJECT;
  681.    short RubberBand = FALSE;
  682.    FFP XMin, YMin, XMax, YMax;
  683.    struct PlotRegion *Reg;
  684.    struct Process  *OurTask;
  685.    struct Window   *old_pr_WindowPtr;
  686.    char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
  687.    char Command[180];
  688.    char convert_tool[150];  /* string descibing path to current directory  */
  689.                             /* when started from workbench to locate tools */
  690.  
  691.    AttrOnOff(Pict, SI_XREGION);
  692.    AttrOnOff(Pict, SI_YREGION);
  693.    x = y = 0;
  694.    if (XHair) {SetDrMd(rp, COMPLEMENT); GetXHair(&x,&y); x1 = x; y1 = y;}
  695.    if (WhiteBG) SetRGB4(vp,0,15,15,15);
  696.    do {
  697.       Wait(1 << window->UserPort->mp_SigBit);
  698.  
  699.       while (msg = (struct IntuiMessage *) GetMsg(window->UserPort) ) {
  700.          class = msg->Class;
  701.          MouseMoved = (class == MOUSEMOVE);
  702.          code = msg->Code; x = msg->MouseX; y = msg->MouseY;
  703.          ReplyMsg(msg);
  704.  
  705.          if ((class == MENUPICK) && (code != MENUNULL)) {
  706.             switch (MENUNUM(code)) {
  707.             case M_PROJECT:
  708.                switch(ITEMNUM(code)) {
  709.                case MI_QUIT:        KEEP_GOING=FALSE; retval = QUIT; break;
  710.                case MI_PRINT:       WrtPlt(Pict,FALSE); break;
  711.                case MI_NEW:         KEEP_GOING=TRUE; retval = QUIT; break;
  712.                case MI_SAVE:
  713.                   switch (SUBNUM(code)) {
  714.                   case SI_HPLG:
  715.                      WrtPlt(Pict,TRUE);
  716.                      break;
  717.                   case SI_MCAD:
  718.                      SetPointer(window,WaitSprite,26,14,-4,-4);
  719.                      To_mCAD(Pict,TRUE);
  720.                      ClearPointer(window);
  721.                      break;
  722.                   case SI_IFF:
  723.                      SetPointer(window,WaitSprite,26,14,-4,-4);
  724.                      screensave();
  725.                      ClearPointer(window);
  726.                      break;
  727.                   case SI_DRAW:
  728.                      SetPointer(window,WaitSprite,26,14,-4,-4);
  729.                      strcpy(plotname,filename);
  730.                      strsfn(plotname,def_drive,def_path,def_node,def_extn);
  731.                      strcat(def_drive,def_path);
  732.                      strcat(def_node,".draw");
  733.  
  734.                      OurTask = (struct Process *)FindTask(0L);
  735.                      old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  736.                      OurTask->pr_WindowPtr = (APTR)window;
  737.                      if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
  738.                           {
  739.                              OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  740.                              break;
  741.                            }
  742.  
  743.                      OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  744.                      strmfp(plotname,def_drive,def_node);
  745.                      if (To_mCAD(Pict,FALSE))
  746.                        {
  747.                          strmfp(convert_tool,StartDir,"plot2draw");
  748.                          sprintf(Command,"\"%s\" t:tempfile \"%s\"",convert_tool,plotname);
  749.                          Execute(Command,0,0);
  750.                          DeleteFile("t:tempfile");
  751.                        }
  752.                      ClearPointer(window);
  753.                      break;
  754.                   case SI_ICAD:
  755.  
  756.  
  757.                      SetPointer(window,WaitSprite,26,14,-4,-4);
  758.                      strcpy(plotname,filename);
  759.                      strsfn(plotname,def_drive,def_path,def_node,def_extn);
  760.                      strcat(def_drive,def_path);
  761.                      strcat(def_node,".iCAD");
  762.  
  763.                      OurTask = (struct Process *)FindTask(0L);
  764.                      old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  765.                      OurTask->pr_WindowPtr = (APTR)window;
  766.                      if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
  767.                           {
  768.                              OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  769.                              break;
  770.                            }
  771.                      OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  772.                      strmfp(plotname,def_drive,def_node);
  773.                      if (To_mCAD(Pict,FALSE))
  774.                        {
  775.                          strmfp(convert_tool,StartDir,"txt_2_icad");
  776.                          sprintf(Command,"\"%s\" t:tempfile \"%s\"",convert_tool,plotname);
  777.                          Execute(Command,0,0);
  778.                          DeleteFile("t:tempfile");
  779.                        }
  780.                      ClearPointer(window);
  781.                      break;
  782.                   default: break;
  783.                   }
  784.                   break;
  785.                default: break;
  786.                }
  787.                break;
  788.  
  789.             case M_EDIT:
  790.                switch (ITEMNUM(code)) {
  791.                case MI_ZOOM:        RubberObj = REGION; break;
  792.                case MI_SLIDE:       RubberObj = SLIDE; break;
  793.                case MI_FULLPLOT:    retval = GETDATALIMITS; break;
  794.                case MI_LOCKS:
  795.                   switch (SUBNUM(code)) {
  796.                   case SI_XYREGION:
  797.                      Pict->XRegionLock=Pict->YRegionLock=TRUE;
  798.                      AttrOnOff(Pict, SI_XREGION);
  799.                      AttrOnOff(Pict, SI_YREGION);
  800.                      break;
  801.                   case SI_YREGION:
  802.                      Pict->YRegionLock=!Pict->YRegionLock;
  803.                      AttrOnOff(Pict, SI_YREGION);
  804.                      break;
  805.                   case SI_XREGION:
  806.                      Pict->XRegionLock=!Pict->XRegionLock;
  807.                      AttrOnOff(Pict, SI_XREGION);
  808.                      break;
  809.                   default: break;
  810.                   }
  811.                   break;
  812.                default: break;
  813.                }
  814.                break;
  815.             case M_OPTIONS:
  816.                switch (ITEMNUM(code)) {
  817.                case MI_REDRAW:      retval = REPLOT; break;
  818.                case MI_CROSSHAIR:
  819.                   if (XHair = !XHair) {GetXHair(&x,&y); x1=x; y1=y;}
  820.                   else KillXHair(x1,y1);
  821.                   break;
  822.                case MI_GETHOWTO:     retval = GETHOWTO; break;
  823.                case MI_GRID:        Pict->Grid = !Pict->Grid; retval=REPLOT; break;
  824.                case MI_AXES:        Pict->Axes = !Pict->Axes; retval=REPLOT; break;
  825.                case MI_WHITEBG:
  826.                   if (WhiteBG = !WhiteBG) SetRGB4(vp,0,15,15,15);
  827.                   else SetRGB4(vp,0,15,10,5);
  828.                   break;
  829.                default: break;
  830.                }
  831.                break;
  832.  
  833.             default: break;
  834.  
  835.             } /* switch */
  836.          } /* if ((class == MENUPICK) ...*/
  837.          else if (class == MOUSEBUTTONS) {
  838.                switch (code) {
  839.                case SELECTUP: break;
  840.                case SELECTDOWN:
  841.                   if (RubberObj && !RubberBand) { /* BEGIN RUBBERBAND */
  842.                      RubberBand = TRUE; x0 = x1 = x; y0 = y1 = y;
  843.                      SetDrMd(rp,COMPLEMENT); window->Flags |= RMBTRAP;
  844.                      if (RubberObj == REGION) {
  845.                         RubberBox(x0,y0,x,y);
  846.                      }
  847.                      else if (RubberObj == SLIDE) {
  848.                         Move(rp,x,y); Draw(rp,x,y);
  849.                      }
  850.                   }
  851.                   else { /* END RUBBERBAND */
  852.                      RubberBand = FALSE;
  853.                      if (RubberObj == REGION) {
  854.                         RubberBox(x0,y0,x1,y1);
  855.                         Reg = Pict->CurrReg;
  856.                         if ((abs(x-x0) > 2) && (abs(y-y0) > 2)) {
  857.                            /* zoom in to new region */
  858.                            PToU(Pict,min(x0,x),MAXVERT-max(y0,y),&XMin,&YMin);
  859.                            PToU(Pict,max(x0,x),MAXVERT-min(y0,y),&XMax,&YMax);
  860.                         }
  861.                         else {
  862.                            /* zoom out X 2 */
  863.                            XMin = Reg->XMin - (Reg->XMax - Reg->XMin)/2;
  864.                            XMax = Reg->XMax + (Reg->XMin - XMin);
  865.                            YMin = Reg->YMin - (Reg->YMax - Reg->YMin)/2;
  866.                            YMax = Reg->YMax + (Reg->YMin - YMin);
  867.                         }
  868.                         if (!Pict->XRegionLock)
  869.                            {Reg->XMin = XMin; Reg->XMax = XMax;}
  870.                         if (!Pict->YRegionLock)
  871.                            {Reg->YMin = YMin; Reg->YMax = YMax;}
  872.                         retval = REPLOT;
  873.                      }
  874.                      else if (RubberObj == SLIDE) {
  875.                         Move(rp,x0,y0); Draw(rp,x1,y1);
  876.                         PToU(Pict,x0,MAXVERT-y0,&XMin,&YMin);
  877.                         PToU(Pict,x,MAXVERT-y,&XMax,&YMax);
  878.                         Reg = Pict->CurrReg;
  879.                         if (!Pict->XRegionLock)
  880.                            {Reg->XMin += XMin-XMax; Reg->XMax += XMin-XMax;}
  881.                         if (!Pict->YRegionLock)
  882.                            {Reg->YMin += YMin-YMax; Reg->YMax += YMin-YMax;}
  883.                         retval = REPLOT;
  884.                      }
  885.                      if (!XHair) SetDrMd(rp,JAM1);
  886.                      window->Flags &= 0xFFFFFFFF ^ RMBTRAP;
  887.                   }
  888.                   break;
  889.                case MENUDOWN: /* ABORT RUBBERBAND */
  890.                   RubberBand = FALSE; window->Flags &= 0xFFFFFFFF ^ RMBTRAP;
  891.                   if (RubberObj == REGION) {
  892.                      RubberBox(x0,y0,x1,y1);
  893.                   }
  894.                   else if (RubberObj == SLIDE) {
  895.                      Move(rp,x0,y0); Draw(rp,x1,y1);
  896.                   }
  897.                   break;
  898.                default: break;
  899.             } /* switch (code) */
  900.             break;
  901.          } /* else if (class == MENUBUTTONS) */
  902.       } /* while */
  903.  
  904.       if (MouseMoved && ((x1!=x) || (y1!=y)) ) {
  905.          if (XHair)
  906.                {PutXHair(x1,y1); PutXHair(x,y);}
  907.          if (RubberBand) {
  908.             if (RubberObj == REGION)
  909.                {RubberBox(x0,y0,x1,y1); RubberBox(x0,y0,x,y);}
  910.             else if (RubberObj == SLIDE)
  911.                {Move(rp,x0,y0); Draw(rp,x1,y1); Move(rp,x0,y0); Draw(rp,x,y);}
  912.          }
  913.          x1 = x; y1 = y;
  914.       }
  915.    } while(retval == NOACTION);
  916.  
  917.    SetDrMd(rp, JAM1);
  918.    return(retval);
  919. }
  920.