home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part04 / util.c < prev   
C/C++ Source or Header  |  1990-07-02  |  5KB  |  226 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "object.h"
  13. #include "paintop.h"
  14.  
  15. extern F_compound    objects;
  16.  
  17. /***********  The following extern vars for undo purpose  **************/
  18.  
  19.  
  20. extern int        pointmarker_shown;
  21.  
  22. static u_int    marker_pattern[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  23. mpr_static(pmarker, 5, 5, 1, marker_pattern);
  24.  
  25. tail(ob, tails)
  26. F_compound    *ob, *tails;
  27. {
  28.     F_arc        *a;
  29.     F_compound    *c;
  30.     F_ellipse    *e;
  31.     F_line        *l;
  32.     F_spline    *s;
  33.     F_text        *t;
  34.  
  35.     if (NULL != (a = ob->arcs)) for (; a->next != NULL; a = a->next);
  36.     if (NULL != (c = ob->compounds)) for (; c->next != NULL; c = c->next);
  37.     if (NULL != (e = ob->ellipses)) for (; e->next != NULL; e = e->next);
  38.     if (NULL != (l = ob->lines)) for (; l->next != NULL; l = l->next);
  39.     if (NULL != (s = ob->splines)) for (; s->next != NULL; s = s->next);
  40.     if (NULL != (t = ob->texts)) for (; t->next != NULL; t = t->next);
  41.  
  42.     tails->arcs = a;
  43.     tails->compounds = c;
  44.     tails->ellipses = e;
  45.     tails->lines = l;
  46.     tails->splines = s;
  47.     tails->texts = t;
  48.     }
  49.  
  50. /*
  51. Make pointers in tails point to the last element of each list of l1
  52. and Append the lists in l2 after those in l1.
  53. The tails pointers must be defined prior to calling append.
  54. */
  55. append_objects(l1, l2, tails)
  56. F_compound    *l1, *l2, *tails;
  57. {
  58.     if (tails->arcs)
  59.         tails->arcs->next  = l2->arcs; 
  60.     else
  61.         l1->arcs  = l2->arcs; 
  62.     if (tails->compounds)
  63.         tails->compounds->next  = l2->compounds;
  64.     else
  65.         l1->compounds  = l2->compounds;
  66.     if (tails->ellipses)
  67.         tails->ellipses->next  = l2->ellipses;
  68.     else
  69.         l1->ellipses  = l2->ellipses;
  70.     if (tails->lines)
  71.         tails->lines->next  = l2->lines;
  72.     else
  73.         l1->lines  = l2->lines;
  74.     if (tails->splines)
  75.         tails->splines->next  = l2->splines;
  76.     else
  77.         l1->splines  = l2->splines;
  78.     if (tails->texts)
  79.         tails->texts->next  = l2->texts;
  80.     else
  81.         l1->texts  = l2->texts;
  82.     }
  83.  
  84. /* Cut is the dual of append. */
  85.  
  86. cut_objects(objects, tails)
  87. F_compound    *objects, *tails;
  88. {
  89.     if (tails->arcs)
  90.         tails->arcs->next = NULL;
  91.     else
  92.         objects->arcs = NULL;
  93.     if (tails->compounds)
  94.         tails->compounds->next = NULL;
  95.     else
  96.         objects->compounds = NULL;
  97.     if (tails->ellipses)
  98.         tails->ellipses->next = NULL;
  99.     else
  100.         objects->ellipses = NULL;
  101.     if (tails->lines)
  102.         tails->lines->next = NULL;
  103.     else
  104.         objects->lines = NULL;
  105.     if (tails->splines)
  106.         tails->splines->next = NULL;
  107.     else
  108.         objects->splines = NULL;
  109.     if (tails->texts)
  110.         tails->texts->next = NULL;
  111.     else
  112.         objects->texts = NULL;
  113.     }
  114.  
  115. no_object()
  116. {
  117.     if (objects.texts != NULL) return(0);
  118.     if (objects.lines != NULL) return(0);
  119.     if (objects.ellipses != NULL) return(0);
  120.     if (objects.splines != NULL) return(0);
  121.     if (objects.arcs != NULL) return(0);
  122.     if (objects.compounds != NULL) return(0);
  123.     return(1);
  124.     }
  125.  
  126. show_pointmarker()
  127. {
  128.     if (pointmarker_shown) return;
  129.     pointmarker_shown = 1;
  130.     toggle_pointmarker();
  131.     }
  132.  
  133. erase_pointmarker()
  134. {
  135.     if (! pointmarker_shown) return;
  136.     pointmarker_shown = 0;
  137.     toggle_pointmarker();
  138.     }
  139.  
  140. toggle_pointmarker()
  141. {
  142.     F_ellipse    *e;
  143.     F_arc        *a;
  144.     F_line        *l;
  145.     F_spline    *s;
  146.  
  147.     for (e = objects.ellipses; e != NULL; e = e->next) {
  148.         toggle_ellipsepointmarker(e);
  149.         }
  150.     for (a = objects.arcs; a != NULL; a = a->next) {
  151.         toggle_arcpointmarker(a);
  152.         }
  153.     for (l = objects.lines; l != NULL; l = l->next) {
  154.         toggle_linepointmarker(l);
  155.         }
  156.     for (s = objects.splines; s != NULL; s = s->next) {
  157.         toggle_splinepointmarker(s);
  158.         }
  159.     }
  160.  
  161. toggle_ellipsepointmarker(e)
  162. F_ellipse    *e;
  163. {
  164.     set_marker(canvas_win, e->start.x-2, e->start.y-2, 5, 5, INV_PAINT,
  165.         &pmarker, 0, 0);
  166.     set_marker(canvas_win, e->end.x-2, e->end.y-2, 5, 5, INV_PAINT,
  167.         &pmarker, 0, 0);
  168.     }
  169.  
  170. toggle_arcpointmarker(a)
  171. F_arc    *a;
  172. {
  173.     set_marker(canvas_win, a->point[0].x-2, a->point[0].y-2, 5, 5,
  174.         INV_PAINT, &pmarker, 0, 0);
  175.     set_marker(canvas_win, a->point[1].x-2, a->point[1].y-2, 5, 5,
  176.         INV_PAINT, &pmarker, 0, 0);
  177.     set_marker(canvas_win, a->point[2].x-2, a->point[2].y-2, 5, 5,
  178.         INV_PAINT, &pmarker, 0, 0);
  179.     }
  180.  
  181. toggle_linepointmarker(l)
  182. F_line    *l;
  183. {
  184.     F_point    *p;
  185.     int    fx, fy, x, y;
  186.  
  187.     p = l->points;
  188.     fx = p->x;  fy = p->y;
  189.     for (p = p->next; p!= NULL; p = p->next) {
  190.         x = p->x;  y = p->y;
  191.         set_marker(canvas_win, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
  192.         }
  193.     if (x != fx || y != fy) {
  194.         set_marker(canvas_win, fx-2, fy-2, 5, 5, INV_PAINT, 
  195.             &pmarker, 0, 0);
  196.         }
  197.     }
  198.  
  199. toggle_splinepointmarker(s)
  200. F_spline    *s;
  201. {
  202.     F_point    *p;
  203.     int    fx, fy, x, y;
  204.  
  205.     p = s->points;
  206.     fx = p->x;  fy = p->y;
  207.     for (p = p->next; p!= NULL; p = p->next) {
  208.         x = p->x;  y = p->y;
  209.         set_marker(canvas_win, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
  210.         }
  211.     if (x != fx || y != fy) {
  212.         set_marker(canvas_win, fx-2, fy-2, 5, 5, INV_PAINT, 
  213.             &pmarker, 0, 0);
  214.         }
  215.     }
  216.  
  217. num_points(points)
  218. F_point    *points;
  219. {
  220.     int    n;
  221.     F_point    *p;
  222.  
  223.     for (p = points, n = 0; p != NULL; p = p->next, n++);
  224.     return(n);
  225.     }
  226.