home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part03 / turn.c < prev   
C/C++ Source or Header  |  1990-07-02  |  3KB  |  164 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 "alloc.h"
  13. #include "func.h"
  14. #include "object.h"
  15. #include "paintop.h"
  16.  
  17. #define            TOLERANCE    7
  18.  
  19. extern            (*canvas_kbd_proc)();
  20. extern            (*canvas_locmove_proc)();
  21. extern            (*canvas_leftbut_proc)();
  22. extern            (*canvas_middlebut_proc)();
  23. extern            (*canvas_rightbut_proc)();
  24. extern            null_proc();
  25. extern            set_popupmenu();
  26.  
  27. extern int        pointmarker_shown;
  28.  
  29. extern F_compound    objects;
  30. extern F_line        *line_search();
  31. extern F_spline        *spline_search();
  32.  
  33. extern int        init_turn();
  34.  
  35. turn_selected()
  36. {
  37.     canvas_kbd_proc = null_proc;
  38.     canvas_locmove_proc = null_proc;
  39.     canvas_leftbut_proc = init_turn;
  40.     canvas_middlebut_proc = null_proc;
  41.     canvas_rightbut_proc = set_popupmenu;
  42.     set_cursor(&pick15_cursor);
  43.     }
  44.  
  45. init_turn(x, y)
  46. int    x, y;
  47. {
  48.     F_line        *l;
  49.     F_spline    *s;
  50.     int        dummy;
  51.  
  52.     if ((l = line_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
  53.         if (l->type == T_BOX || l->type == T_ARC_BOX) return;
  54.         line_2_spline(l);
  55.         turn_selected();
  56.         }
  57.     else if ((s = spline_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
  58.         spline_2_line(s);
  59.         turn_selected();
  60.         }
  61.     }
  62.  
  63. line_2_spline(l)
  64. F_line    *l;
  65. {
  66.     F_spline    *s;
  67.  
  68.     if (num_points(l->points) < 3) {
  69.         put_msg("Can't turn this line into spline");
  70.         return(-1);
  71.         }
  72.     if (pointmarker_shown) toggle_linepointmarker(l);
  73.     draw_line(l, ERASE);
  74.     delete_line(&objects.lines, l);
  75.  
  76.     if (NULL == (Spline_malloc(s))) {
  77.         put_msg(Err_mem);
  78.         return(-1);
  79.         }
  80.  
  81.     if (l->type == T_POLYGON)
  82.         s->type = T_CLOSED_INTERPOLATED;
  83.     else
  84.         s->type = T_OPEN_INTERPOLATED;
  85.     s->style = l->style;
  86.     s->thickness = l->thickness;
  87.     s->color = l->color;
  88.     s->depth = l->depth;
  89.     s->style_val = l->style_val;
  90.     s->pen = l->pen;
  91.     s->area_fill = l->area_fill;
  92.     s->for_arrow = l->for_arrow;
  93.     s->back_arrow = l->back_arrow;
  94.     s->points = l->points;
  95.     s->controls = NULL;
  96.     s->next = NULL;
  97.  
  98.     l->for_arrow = l->back_arrow = NULL;
  99.     l->pen = 0;
  100.     l->points = NULL;
  101.  
  102.     if (-1 == create_control_list(s)) {
  103.         free(s);
  104.         return(-1);
  105.         }
  106.  
  107.     remake_control_points(s);
  108.     draw_spline(s, PAINT);
  109.     if (pointmarker_shown) toggle_splinepointmarker(s);
  110.     clean_up();
  111.     set_action_object(F_TURN, O_POLYLINE);
  112.     insert_spline(&objects.splines, s);
  113.     set_latestspline(s);
  114.     set_latestline(l);
  115.     return(1);
  116.     }
  117.  
  118. spline_2_line(s)
  119. F_spline    *s;
  120. {
  121.     F_line    *l;
  122.  
  123.     if (pointmarker_shown) toggle_splinepointmarker(s);
  124.     draw_spline(s, ERASE);
  125.     delete_spline(&objects.splines, s);
  126.  
  127.     /* Now we turn s into a line */
  128.     if (NULL == (Line_malloc(l))) {
  129.         put_msg(Err_mem);
  130.         return(-1);
  131.         }
  132.  
  133.     if (s->type == T_OPEN_INTERPOLATED)
  134.         l->type = T_POLYLINE;
  135.     else if (s->type == T_CLOSED_INTERPOLATED)
  136.         l->type = T_POLYGON;
  137.     l->style = s->style;
  138.     l->thickness = s->thickness;
  139.     l->color = s->color;
  140.     l->depth = s->depth;
  141.     l->style_val = s->style_val;
  142.     l->pen = s->pen;
  143.     l->radius = 0;
  144.     l->area_fill = s->area_fill;
  145.     l->for_arrow = s->for_arrow;
  146.     l->back_arrow = s->back_arrow;
  147.     l->points = s->points;
  148.     l->next = NULL;
  149.  
  150.     s->for_arrow = s->back_arrow = NULL;
  151.     s->area_fill = 0;
  152.     s->pen = 0;
  153.     s->points = NULL;
  154.  
  155.     draw_line(l, PAINT);
  156.     if (pointmarker_shown) toggle_linepointmarker(l);
  157.     clean_up();
  158.     set_action_object(F_TURN, O_SPLINE);
  159.     insert_line(&objects.lines, l);
  160.     set_latestspline(s);
  161.     set_latestline(l);
  162.     return(1);
  163.     }
  164.