home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part02 / d_spline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  3.1 KB  |  110 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_create.h"
  19. #include "u_elastic.h"
  20. #include "u_list.h"
  21. #include "w_canvas.h"
  22. #include "w_mousefun.h"
  23.  
  24. static int    create_splineobject();
  25. static int    init_spline_drawing();
  26.  
  27. spline_drawing_selected()
  28. {
  29.     set_mousefun("first point", "", "");
  30.     canvas_kbd_proc = null_proc;
  31.     canvas_locmove_proc = null_proc;
  32.     canvas_leftbut_proc = init_spline_drawing;
  33.     canvas_middlebut_proc = null_proc;
  34.     canvas_rightbut_proc = null_proc;
  35.     set_cursor(arrow_cursor);
  36.     reset_action_on();
  37. }
  38.  
  39. static
  40. init_spline_drawing(x, y)
  41.     int            x, y;
  42. {
  43.     if (cur_mode == F_CLOSED_SPLINE) {
  44.     min_num_points = 3;
  45.     init_trace_drawing(x, y);
  46.     canvas_middlebut_save = create_splineobject;
  47.     } else {
  48.     min_num_points = 2;
  49.     init_trace_drawing(x, y);
  50.     canvas_middlebut_proc = create_splineobject;
  51.     }
  52.     return_proc = spline_drawing_selected;
  53. }
  54.  
  55. static
  56. create_splineobject(x, y)
  57.     int            x, y;
  58. {
  59.     F_spline       *spline;
  60.  
  61.     if (x != fix_x || y != fix_y || num_point < min_num_points) {
  62.     get_intermediatepoint(x, y);
  63.     }
  64.     elastic_line();
  65.     if ((spline = create_spline()) == NULL)
  66.     return;
  67.  
  68.     spline->style = cur_linestyle;
  69.     spline->thickness = cur_linewidth;
  70.     spline->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  71.     spline->color = cur_color;
  72.     spline->depth = cur_depth;
  73.     spline->pen = 0;
  74.     spline->fill_style = cur_fillstyle;
  75.     /*
  76.      * The current fill style is saved in all spline objects (but support for
  77.      * filling may not be available in all fig2dev languages).
  78.      */
  79.     spline->points = first_point;
  80.     spline->controls = NULL;
  81.     spline->next = NULL;
  82.     /* initialise for no arrows - updated below if necessary */
  83.     spline->for_arrow = NULL;
  84.     spline->back_arrow = NULL;
  85.     cur_x = cur_y = fix_x = fix_y = 0;    /* used in elastic_moveline */
  86.     elastic_moveline(spline->points);    /* erase control vector */
  87.     if (cur_mode == F_CLOSED_SPLINE) {
  88.     spline->type = T_CLOSED_NORMAL;
  89.     num_point++;
  90.     append_point(first_point->x, first_point->y, &cur_point);
  91.     draw_closed_spline(spline, PAINT);
  92.     } else {            /* It must be F_SPLINE */
  93.     if (autoforwardarrow_mode)
  94.         spline->for_arrow = forward_arrow();
  95.     if (autobackwardarrow_mode)
  96.         spline->back_arrow = backward_arrow();
  97.     spline->type = T_OPEN_NORMAL;
  98.     draw_open_spline(spline, PAINT);
  99.     }
  100.     if (appres.DEBUG) {
  101.     int        xmin, ymin, xmax, ymax;
  102.  
  103.     spline_bound(spline, &xmin, &ymin, &xmax, &ymax);
  104.     elastic_box(xmin, ymin, xmax, ymax);
  105.     }
  106.     add_spline(spline);
  107.     spline_drawing_selected();
  108.     draw_mousefun_canvas();
  109. }
  110.