home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part06 / e_flip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  7.8 KB  |  364 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "resources.h"
  15. #include "mode.h"
  16. #include "object.h"
  17. #include "paintop.h"
  18. #include "u_draw.h"
  19. #include "u_search.h"
  20. #include "u_create.h"
  21. #include "u_list.h"
  22. #include "w_canvas.h"
  23. #include "w_mousefun.h"
  24.  
  25. static int    flip_axis;
  26. static int    copy;
  27. static int    init_flip();
  28. static int    init_copynflip();
  29. static int    init_fliparc();
  30. static int    init_flipcompound();
  31. static int    init_flipellipse();
  32. static int    init_flipline();
  33. static int    init_flipspline();
  34. static int    flip_selected();
  35. static int    flip_search();
  36.  
  37. flip_ud_selected()
  38. {
  39.     flip_axis = UD_FLIP;
  40.     flip_selected();
  41. }
  42.  
  43. flip_lr_selected()
  44. {
  45.     flip_axis = LR_FLIP;
  46.     flip_selected();
  47. }
  48.  
  49. static
  50. flip_selected()
  51. {
  52.     set_mousefun("flip", "copy & flip", "");
  53.     canvas_kbd_proc = null_proc;
  54.     canvas_locmove_proc = null_proc;
  55.     init_searchproc_left(init_flip);
  56.     init_searchproc_middle(init_copynflip);
  57.     canvas_leftbut_proc = object_search_left;
  58.     canvas_middlebut_proc = object_search_middle;
  59.     canvas_rightbut_proc = null_proc;
  60.     set_cursor(pick15_cursor);
  61. }
  62.  
  63. static
  64. init_flip(p, type, x, y, px, py)
  65.     char       *p;
  66.     int            type;
  67.     int            x, y;
  68.     int            px, py;
  69. {
  70.     copy = 0;
  71.     flip_search(p, type, x, y, px, py);
  72. }
  73.  
  74. static
  75. init_copynflip(p, type, x, y, px, py)
  76.     char       *p;
  77.     int            type;
  78.     int            x, y;
  79.     int            px, py;
  80. {
  81.     copy = 1;
  82.     flip_search(p, type, x, y, px, py);
  83. }
  84.  
  85. static
  86. flip_search(p, type, x, y, px, py)
  87.     char       *p;
  88.     int            type;
  89.     int            x, y;
  90.     int            px, py;
  91. {
  92.     switch (type) {
  93.     case O_POLYLINE:
  94.     cur_l = (F_line *) p;
  95.     init_flipline(cur_l, px, py);
  96.     break;
  97.     case O_ARC:
  98.     cur_a = (F_arc *) p;
  99.     init_fliparc(cur_a, px, py);
  100.     break;
  101.     case O_ELLIPSE:
  102.     cur_e = (F_ellipse *) p;
  103.     init_flipellipse(cur_e, px, py);
  104.     break;
  105.     case O_SPLINE:
  106.     cur_s = (F_spline *) p;
  107.     init_flipspline(cur_s, px, py);
  108.     break;
  109.     case O_COMPOUND:
  110.     cur_c = (F_compound *) p;
  111.     init_flipcompound(cur_c, px, py);
  112.     break;
  113.     default:
  114.     return;
  115.     }
  116. }
  117.  
  118. static
  119. init_fliparc(a, px, py)
  120.     F_arc       *a;
  121.     int            px, py;
  122. {
  123.     F_arc       *arc;
  124.  
  125.     set_temp_cursor(wait_cursor);
  126.     arc = copy_arc(a);
  127.     flip_arc(arc, px, py, flip_axis);
  128.     if (copy) {
  129.     add_arc(arc);
  130.     } else {
  131.     toggle_arcmarker(a);
  132.     draw_arc(a, ERASE);
  133.     change_arc(a, arc);
  134.     }
  135.     draw_arc(arc, PAINT);
  136.     toggle_arcmarker(arc);
  137.     reset_cursor();
  138. }
  139.  
  140. static
  141. init_flipcompound(c, px, py)
  142.     F_compound       *c;
  143.     int            px, py;
  144. {
  145.     F_compound       *compound;
  146.  
  147.     set_temp_cursor(wait_cursor);
  148.     compound = copy_compound(c);
  149.     flip_compound(compound, px, py, flip_axis);
  150.     if (copy) {
  151.     add_compound(compound);
  152.     } else {
  153.     toggle_compoundmarker(c);
  154.     draw_compoundelements(c, ERASE);
  155.     change_compound(c, compound);
  156.     }
  157.     draw_compoundelements(compound, PAINT);
  158.     toggle_compoundmarker(compound);
  159.     reset_cursor();
  160. }
  161.  
  162. static
  163. init_flipellipse(old_e, px, py)
  164.     F_ellipse       *old_e;
  165. {
  166.     F_ellipse       *new_e;
  167.  
  168.     new_e = copy_ellipse(old_e);
  169.     flip_ellipse(new_e, px, py, flip_axis);
  170.     if (copy) {
  171.     add_ellipse(new_e);
  172.     } else {
  173.     toggle_ellipsemarker(old_e);
  174.     draw_ellipse(old_e, ERASE);
  175.     change_ellipse(old_e, new_e);
  176.     }
  177.     draw_ellipse(new_e, PAINT);
  178.     toggle_ellipsemarker(new_e);
  179. }
  180.  
  181. static
  182. init_flipline(old_l, px, py)
  183.     F_line       *old_l;
  184.     int            px, py;
  185. {
  186.     F_line       *new_l;
  187.  
  188.     new_l = copy_line(old_l);
  189.     flip_line(new_l, px, py, flip_axis);
  190.     if (copy) {
  191.     add_line(new_l);
  192.     } else {
  193.     toggle_linemarker(old_l);
  194.     draw_line(old_l, ERASE);
  195.     change_line(old_l, new_l);
  196.     }
  197.     draw_line(new_l, PAINT);
  198.     toggle_linemarker(new_l);
  199. }
  200.  
  201. static
  202. init_flipspline(old_s, px, py)
  203.     F_spline       *old_s;
  204.     int            px, py;
  205. {
  206.     F_spline       *new_s;
  207.  
  208.     new_s = copy_spline(old_s);
  209.     flip_spline(new_s, px, py, flip_axis);
  210.     if (copy) {
  211.     add_spline(new_s);
  212.     } else {
  213.     toggle_splinemarker(old_s);
  214.     draw_spline(old_s, ERASE);
  215.     change_spline(old_s, new_s);
  216.     }
  217.     draw_spline(new_s, PAINT);
  218.     toggle_splinemarker(new_s);
  219. }
  220.  
  221. flip_line(l, x, y, flip_axis)
  222.     F_line       *l;
  223.     int            x, y, flip_axis;
  224. {
  225.     F_point       *p;
  226.  
  227.     switch (flip_axis) {
  228.     case UD_FLIP:        /* x axis  */
  229.     for (p = l->points; p != NULL; p = p->next)
  230.         p->y = y + (y - p->y);
  231.     break;
  232.     case LR_FLIP:        /* y axis  */
  233.     for (p = l->points; p != NULL; p = p->next)
  234.         p->x = x + (x - p->x);
  235.     break;
  236.     }
  237.     if (l->type == T_EPS_BOX)
  238.     l->eps->flipped = 1 - l->eps->flipped;
  239. }
  240.  
  241. flip_spline(s, x, y, flip_axis)
  242.     F_spline       *s;
  243.     int            x, y, flip_axis;
  244. {
  245.     F_point       *p;
  246.     F_control       *cp;
  247.  
  248.     switch (flip_axis) {
  249.     case UD_FLIP:        /* x axis  */
  250.     for (p = s->points; p != NULL; p = p->next)
  251.         p->y = y + (y - p->y);
  252.     for (cp = s->controls; cp != NULL; cp = cp->next) {
  253.         cp->ly = y + (y - cp->ly);
  254.         cp->ry = y + (y - cp->ry);
  255.     }
  256.     break;
  257.     case LR_FLIP:        /* y axis  */
  258.     for (p = s->points; p != NULL; p = p->next)
  259.         p->x = x + (x - p->x);
  260.     for (cp = s->controls; cp != NULL; cp = cp->next) {
  261.         cp->lx = x + (x - cp->lx);
  262.         cp->rx = x + (x - cp->rx);
  263.     }
  264.     break;
  265.     }
  266. }
  267.  
  268. flip_text(t, x, y, flip_axis)
  269.     F_text       *t;
  270.     int            x, y, flip_axis;
  271. {
  272.     switch (flip_axis) {
  273.     case UD_FLIP:        /* x axis  */
  274.     t->base_y = y + (y - t->base_y);
  275.     break;
  276.     case LR_FLIP:        /* y axis  */
  277.     t->base_x = x + (x - t->base_x);
  278.     break;
  279.     }
  280. }
  281.  
  282. flip_ellipse(e, x, y, flip_axis)
  283.     F_ellipse       *e;
  284.     int            x, y, flip_axis;
  285. {
  286.     switch (flip_axis) {
  287.     case UD_FLIP:        /* x axis  */
  288.     e->direction ^= 1;
  289.     e->center.y = y + (y - e->center.y);
  290.     e->start.y = y + (y - e->start.y);
  291.     e->end.y = y + (y - e->end.y);
  292.     break;
  293.     case LR_FLIP:        /* y axis  */
  294.     e->direction ^= 1;
  295.     e->center.x = x + (x - e->center.x);
  296.     e->start.x = x + (x - e->start.x);
  297.     e->end.x = x + (x - e->end.x);
  298.     break;
  299.     }
  300.     e->angle = - e->angle;
  301. }
  302.  
  303. flip_arc(a, x, y, flip_axis)
  304.     F_arc       *a;
  305.     int            x, y, flip_axis;
  306. {
  307.     switch (flip_axis) {
  308.     case UD_FLIP:        /* x axis  */
  309.     a->direction ^= 1;
  310.     a->center.y = y + (y - a->center.y);
  311.     a->point[0].y = y + (y - a->point[0].y);
  312.     a->point[1].y = y + (y - a->point[1].y);
  313.     a->point[2].y = y + (y - a->point[2].y);
  314.     break;
  315.     case LR_FLIP:        /* y axis  */
  316.     a->direction ^= 1;
  317.     a->center.x = x + (x - a->center.x);
  318.     a->point[0].x = x + (x - a->point[0].x);
  319.     a->point[1].x = x + (x - a->point[1].x);
  320.     a->point[2].x = x + (x - a->point[2].x);
  321.     break;
  322.     }
  323. }
  324.  
  325. flip_compound(c, x, y, flip_axis)
  326.     F_compound       *c;
  327.     int            x, y, flip_axis;
  328. {
  329.     F_line       *l;
  330.     F_arc       *a;
  331.     F_ellipse       *e;
  332.     F_spline       *s;
  333.     F_text       *t;
  334.     F_compound       *c1;
  335.     int            p, q;
  336.  
  337.     switch (flip_axis) {
  338.     case UD_FLIP:        /* x axis  */
  339.     p = y + (y - c->nwcorner.y);
  340.     q = y + (y - c->secorner.y);
  341.     c->nwcorner.y = min2(p, q);
  342.     c->secorner.y = max2(p, q);
  343.     break;
  344.     case LR_FLIP:        /* y axis  */
  345.     p = x + (x - c->nwcorner.x);
  346.     q = x + (x - c->secorner.x);
  347.     c->nwcorner.x = min2(p, q);
  348.     c->secorner.x = max2(p, q);
  349.     break;
  350.     }
  351.     for (l = c->lines; l != NULL; l = l->next)
  352.     flip_line(l, x, y, flip_axis);
  353.     for (a = c->arcs; a != NULL; a = a->next)
  354.     flip_arc(a, x, y, flip_axis);
  355.     for (e = c->ellipses; e != NULL; e = e->next)
  356.     flip_ellipse(e, x, y, flip_axis);
  357.     for (s = c->splines; s != NULL; s = s->next)
  358.     flip_spline(s, x, y, flip_axis);
  359.     for (t = c->texts; t != NULL; t = t->next)
  360.     flip_text(t, x, y, flip_axis);
  361.     for (c1 = c->compounds; c1 != NULL; c1 = c1->next)
  362.     flip_compound(c1, x, y, flip_axis);
  363. }
  364.