home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / fractal / fdesi313 / fdes13s / fdesmodi.c < prev    next >
Text File  |  1990-06-22  |  13KB  |  350 lines

  1. /*
  2.         Modify Menu
  3. */
  4. #include <stdio.h>                      /* standard stuff */
  5. #include <graphics.h>                   /* graphics */
  6. #include <dos.h>
  7. #include <string.h>
  8. #include "fdestria.h"
  9. #include "fdesign.h"
  10. #include "fdesequa.h"
  11. #include "fdesfile.h"
  12. #include "fdesmenu.h"
  13. #include "fdesmous.h"
  14. #include "fdesplot.h"
  15.  
  16.  
  17. void grat_on(void)            /* put graticules on screen */
  18. {
  19. int x,y;
  20. int mx,my,mxinc,myinc;     /* for speed-up of for loops */
  21.  
  22.    mx = maxx;
  23.    my = maxy;
  24.    mxinc = mx/GRAT_X;
  25.    myinc = my/GRAT_Y;
  26.  
  27.     for (x=0; x<mx; x += mxinc)
  28.     for (y=0; y<my; y += myinc)
  29.     {
  30.         putpixel(x,y,WHITE);
  31.     }
  32. }
  33.  
  34. void grat_off(void)            /* remove graticules from screen */
  35. {
  36. int x,y;
  37.     for (x=0; x<maxx; x += (maxx/GRAT_X))
  38.     for (y=0; y<maxy; y += (maxy/GRAT_Y))
  39.     {
  40.         putpixel(x,y,BLACK);
  41.     }
  42. }
  43.  
  44. popmenu modifymenu = {
  45.     7 ,
  46.         "Scratch Everything", "Add Triangle", "Delete Triangle", "Adjust Triangle",
  47.         "Grat is On", "Re-Crop", "Main Menu"
  48.     };
  49.  
  50. popmenu modi_quit = {
  51.         2 ,
  52.         "Stay here and continue to modify", "Return to main menu"
  53.         };
  54.  
  55. void recrop(void)               /* re-crop triangles in modify menu screen */
  56. {
  57. int x1,y1,x2,y2;
  58. float top,left,right,bottom;
  59. float scalex,scaley;
  60. float offsetx,offsety;
  61.         /* &&& */
  62.         putmsg(0,0,"Input box for triangles",BLUE,WHITE);
  63.         box_new(&x1,&y1,&x2,&y2);
  64.         clrmsg();
  65.         if ((x1==x2) || (y1==y2)) return;
  66.         triangles_limits(&left,&top,&right,&bottom);
  67.         scalex = (x2-x1)/(right - left);
  68.         scaley = (y2-y1)/(bottom - top);
  69.         if (scalex > scaley) scalex = scaley;
  70.         else scaley = scalex;
  71.         offsetx = -((left+right)/2.0)*scalex + (x2+x1)/2.0;
  72.         offsety = -((bottom+top)/2.0)*scaley + (y2+y1)/2.0;
  73.         IFS_rescale(scalex,offsetx,scaley,offsety,0);
  74.         triangles_use_temp();
  75. }
  76.  
  77.  
  78. void modify_scr(void)
  79. {
  80. int i;
  81.         cleardevice();
  82.         grat_on();
  83.     if (triangle0_is) {
  84.         setcolor(LIGHTRED);
  85.         setlinestyle(DASHED_LINE,0,THICK_WIDTH);
  86.         triangle_show(&triangle0);
  87.     }
  88.     if (num_triangles) {
  89.         setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  90.         for (i = 0; i < num_triangles; i++)
  91.         {
  92.                         setcolor(colors[i%MAXCOLORS_]);
  93.             triangle_show(&triangles[i]);
  94.         }
  95.     }
  96. }
  97. /************************************************************************
  98.     Modify Menu Input
  99. ************************************************************************/
  100. void modify_input(void)
  101. {
  102. float a,b,c;            /* length of triangle side */
  103. int select,rcode,i,done,add_done;
  104. int tr_sel,refok;
  105. int corner;
  106. int save_row,save_col;
  107. mouse_state m;
  108.     modify_scr();
  109.         plot_type = 1;                 /* do a small plot while inputting */
  110.         IFS_changed = 1;
  111.         mouse_idle_job = doIFSrand;     /* do a small plot while inputting */
  112.         done = 0;
  113.     do {
  114.                 select = popup(0,0,&modifymenu,WHITE,BLUE);
  115.         switch (select) {
  116.         case 1:
  117.                         IFS_changed = 1;
  118.                         stpcpy(last_file,"No File");
  119.                         file_modified = 0;
  120.                         mouse_idle_job = mouse_idle;
  121.             refok = 0;
  122.             do {
  123.                 num_triangles = 0;
  124.                 triangle0_is = 0;
  125.                 modify_scr();
  126.                                 putmsg(0,0,"Input reference triangle (big)",BLUE,WHITE);
  127.                 setlinestyle(DASHED_LINE,0,THICK_WIDTH);
  128.                                 triangle_new(&triangle0,LIGHTRED);
  129.                 clrmsg();
  130.                                 a = pt_pt_distance(triangle0.row[0],triangle0.col[0],
  131.                                                    triangle0.row[1],triangle0.col[1]);
  132.                                 b = pt_pt_distance(triangle0.row[1],triangle0.col[1],
  133.                                                    triangle0.row[2],triangle0.col[2]);
  134.                                 c = pt_pt_distance(triangle0.row[2],triangle0.col[2],
  135.                                                    triangle0.row[0],triangle0.col[0]);
  136.                 if ((a!=0)&(b!=0)&(c!=0)) {
  137.                     refok = 1;
  138.                     triangle0_is = 1; }
  139.                 else {
  140.                     putmsg(10,100,
  141.                     "Reference Triangle must have non-zero area",
  142.                     WHITE,BLACK);
  143.                     mouse_click(&m);
  144.                     clrmsg();
  145.                 }
  146.             } while (!refok);
  147.             do {
  148.                 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  149.                                 putmsg(0,0,"Input triangle or end with right button",
  150.                        GREEN,WHITE);
  151.                                 rcode = triangle_new(&triangles[num_triangles],
  152.                                         colors[num_triangles%MAXCOLORS_]);
  153.                 if (((rcode&0x01) != 0) &&
  154.                    (transform_affine(&triangles[num_triangles]) == 0))
  155.                 {
  156.                     putmsg(100,100,
  157.                     "Transform not Affine (a side is too long)",
  158.                     RED,WHITE);
  159.                     mouse_click(&m);
  160.                     clrmsg();
  161.                     clrmsg();
  162.                     modify_scr();
  163.                                         IFS_changed = 1;        /* only for clearing window */
  164.                 }
  165.                 else if ((rcode&0x01) != 0) {
  166.                     num_triangles++;
  167.                     if (num_triangles > 1) {
  168.                         IFS_changed = 1;
  169.                         mouse_idle_job = doIFSrand;
  170.                     }
  171.                     clrmsg();
  172.                 }
  173.                                 else {
  174.                                         clrmsg();
  175.                 }
  176.                         } while ((rcode&0x01) && (num_triangles < MAXFUNC));
  177.             break;
  178.         case 2:    /* add triangle */
  179.             add_done = 0;
  180.                         if (num_triangles < MAXFUNC)
  181.             {
  182.                         file_modified = 1;
  183.             do {
  184.                                 putmsg(0,0,"Add one triangle",BLUE,WHITE);
  185.                 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  186.                                 rcode = triangle_new(&triangles[num_triangles],
  187.                                         colors[num_triangles%MAXCOLORS_]);
  188.                 if (transform_affine(&triangles[num_triangles]) == 0)
  189.                 {
  190.                         putmsg(100,100,"Transform not Affine (a side is too long)",
  191.                         RED,WHITE);
  192.                         mouse_click(&m);
  193.                         clrmsg();
  194.                         clrmsg();
  195.                                                 IFS_changed = 1; /* to clear screen */
  196.                         modify_scr();
  197.                 }
  198.                 else {
  199.                     if ((rcode&0x01) != 0)
  200.                                         {
  201.                                                 num_triangles++;
  202.                                                 if (num_triangles > 1) {
  203.                                                         IFS_changed = 1;
  204.                                                         mouse_idle_job = doIFSrand;
  205.                                                 }
  206.                                         }
  207.                     add_done = 1;
  208.                     clrmsg();
  209.                                         IFS_changed = 1;
  210.                 }
  211.             } while (add_done == 0);
  212.             }
  213.             break;
  214.         case 3:
  215.                         putmsg(0,0,"Select triangle to delete",BLUE,WHITE);
  216.             mouse_click(&m);
  217.             clrmsg();
  218.             tr_sel = pt_closest_triangle(m.col,m.row);
  219. /*            gotoxy(1,13); printf("Selected %d",tr_sel);
  220. */            if (tr_sel == -1) {
  221.                 putmsg(50,100,"Use Scratch Everything to delete Reference Triangle ",
  222.                     WHITE,RED);
  223.                                 mouse_click(&m);
  224.                 clrmsg();
  225.                 break;
  226.             }
  227.             if (tr_sel < (num_triangles-1))
  228.             {
  229.                                 file_modified = 1;
  230.                 if (tr_sel != (num_triangles-1)) {
  231.                     for (i=tr_sel; i<(num_triangles-1); i++) {
  232.                                                 triangles[i].row[0] = triangles[i+1].row[0];
  233.                                                 triangles[i].col[0] = triangles[i+1].col[0];
  234.                                                 triangles[i].row[1] = triangles[i+1].row[1];
  235.                                                 triangles[i].col[1] = triangles[i+1].col[1];
  236.                                                 triangles[i].row[2] = triangles[i+1].row[2];
  237.                                                 triangles[i].col[2] = triangles[i+1].col[2];
  238.                     }
  239.                 }
  240.             }
  241.             num_triangles--;
  242.                         if (num_triangles > 1) {
  243.                 IFS_changed = 1;
  244.                 mouse_idle_job = doIFSrand;
  245.             }
  246.             else {
  247.                 mouse_idle_job = mouse_idle;
  248.             }
  249.                         IFS_changed = 1;
  250.             modify_scr();
  251.             break;
  252.                 case 4: /* adjust triangle */
  253.                         putmsg(0,0,"Select triangle to adjust",BLUE,WHITE);
  254.             mouse_click(&m);
  255.             clrmsg();
  256.             tr_sel = pt_closest_triangle(m.col,m.row);
  257.                         if (tr_sel == -1) {
  258.                                 putmsg(50,100,"Cannot Adjust Reference Triangle ",WHITE,RED);
  259.                 mouse_click(&m);
  260.                 clrmsg();
  261.                 break;
  262.             }
  263.                         else {
  264.                                 putmsg(0,0,"Select Corner to Move",GREEN,WHITE);
  265.                                 mouse_click(&m);
  266.                 corner = triangle_corner(&triangles[tr_sel],m.col,m.row);
  267.                                 clrmsg();
  268.                                 do {
  269.                                         putmsg(0,0,"Click left to move, Click right to end",BLUE,WHITE);
  270.                     rcode = mouse_click_grat(&m);
  271. /*                    rcode = mouse_click(&m); */
  272.                                         save_row = triangles[tr_sel].row[corner];
  273.                                         save_col = triangles[tr_sel].col[corner];
  274.                                         clrmsg();
  275.                                         if (rcode&0x01) {
  276.                                                 triangles[tr_sel].row[corner] = m.row;
  277.                                                 triangles[tr_sel].col[corner] = m.col;
  278.                                                 file_modified = 1;
  279.                         if (transform_affine(&triangles[tr_sel])) {
  280.                                                         IFS_changed = 1;
  281.                                                         modify_scr();
  282.                                                 }
  283.                                                 else {
  284.                                                         triangles[tr_sel].row[corner] = save_row;
  285.                                                         triangles[tr_sel].col[corner] = save_col;
  286.                                                         putmsg(100,100,"Not Affine",RED,WHITE);
  287.                                                         mouse_click(&m);
  288.                                                         clrmsg();
  289.                                                 }
  290.                                         }
  291.                                 } while (!(rcode&0x02));
  292.                         }
  293.                         break;
  294.                 case 5: /* toggle use_grat global variable */
  295.                         if (use_grat)
  296.                         {
  297.                                 use_grat = 0;
  298.                                 modifymenu.item[4] = "Grat is Off";
  299.                         }
  300.                         else
  301.                         {
  302.                                 use_grat = 1;
  303.                                 modifymenu.item[4] = "Grat is On";
  304.                         }
  305.                         break;
  306.                 case 6: /* re-crop */
  307.             recrop();
  308.             modify_scr();
  309.                         break;
  310.                 case 7: /* return/continue */
  311.             if (triangle0_is == 0) {
  312.                                 putmsg(100,100,"Error: No Triangles",RED,WHITE);
  313.                                 delay(1000);
  314.                 clrmsg();
  315.             } else if (num_triangles < 2) {
  316.                 putmsg(10,100,
  317.                                       "Error: At least two transformation triangles required",
  318.                       RED,WHITE);
  319.                                 delay(3000);
  320.                 clrmsg();
  321.             }
  322.             else {
  323.                 cleardevice();
  324.                                 plot_type = 0;
  325.                 mouse_idle_job = mouse_idle;
  326.                                 doIFSrand();
  327.                 done = 1;
  328.             }
  329.                         if (done == 0)
  330.                         {
  331.                                 select = popup(150,150,&modi_quit,WHITE,RED);
  332.                                 if (select == 2)
  333.                                 {
  334.                                         stpcpy(last_file,"No File");
  335.                                         file_modified = 0;
  336.                                         default_fractal();
  337.                                         cleardevice();
  338.                                         plot_type = 0;
  339.                                         mouse_idle_job = mouse_idle;
  340.                                         doIFSrand();
  341.                                         done = 1;
  342.                                 }
  343.                         }
  344.             break;
  345.         }
  346.     } while (!done);
  347. }
  348.  
  349. 
  350.