home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part03 / d_arc.c next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  4.3 KB  |  177 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. /********************** DECLARATIONS ********************/
  14.  
  15. /* IMPORTS */
  16.  
  17. #include "fig.h"
  18. #include "resources.h"
  19. #include "mode.h"
  20. #include "object.h"
  21. #include "paintop.h"
  22. #include "u_create.h"
  23. #include "u_elastic.h"
  24. #include "u_list.h"
  25. #include "w_canvas.h"
  26. #include "w_mousefun.h"
  27.  
  28. /* LOCAL */
  29.  
  30. F_pos        point[3];
  31.  
  32. static int    create_arcobject();
  33. static int    get_arcpoint();
  34. static int    init_arc_drawing();
  35. static int    cancel_arc();
  36.  
  37. arc_drawing_selected()
  38. {
  39.     set_mousefun("first point", "", "");
  40.     canvas_kbd_proc = null_proc;
  41.     canvas_locmove_proc = null_proc;
  42.     canvas_leftbut_proc = init_arc_drawing;
  43.     canvas_middlebut_proc = null_proc;
  44.     canvas_rightbut_proc = null_proc;
  45.     set_cursor(arrow_cursor);
  46.     reset_action_on();
  47. }
  48.  
  49. static
  50. init_arc_drawing(x, y)
  51.     int            x, y;
  52. {
  53.     set_mousefun("mid point", "", "cancel");
  54.     draw_mousefun_canvas();
  55.     canvas_rightbut_proc = cancel_arc;
  56.     num_point = 0;
  57.     point[num_point].x = fix_x = cur_x = x;
  58.     point[num_point++].y = fix_y = cur_y = y;
  59.     canvas_locmove_proc = freehand_line;
  60.     canvas_leftbut_proc = get_arcpoint;
  61.     canvas_middlebut_proc = null_proc;
  62.     elastic_line();
  63.     set_temp_cursor(null_cursor);
  64.     set_action_on();
  65. }
  66.  
  67. static
  68. cancel_arc()
  69. {
  70.     elastic_line();
  71.     if (num_point == 2) {
  72.     /* erase initial part of line */
  73.     cur_x = point[0].x;
  74.     cur_y = point[0].y;
  75.     elastic_line();
  76.     }
  77.     arc_drawing_selected();
  78.     draw_mousefun_canvas();
  79. }
  80.  
  81. static
  82. get_arcpoint(x, y)
  83.     int            x, y;
  84. {
  85.     if (x == fix_x && y == fix_y)
  86.     return;
  87.  
  88.     if (num_point == 1) {
  89.     set_mousefun("final point", "", "cancel");
  90.     draw_mousefun_canvas();
  91.     }
  92.     if (num_point == 2) {
  93.     create_arcobject(x, y);
  94.     return;
  95.     }
  96.     elastic_line();
  97.     cur_x = x;
  98.     cur_y = y;
  99.     elastic_line();
  100.     point[num_point].x = fix_x = x;
  101.     point[num_point++].y = fix_y = y;
  102.     elastic_line();
  103. }
  104.  
  105. static
  106. create_arcobject(lx, ly)
  107.     int            lx, ly;
  108. {
  109.     F_arc       *arc;
  110.     int            x, y, i;
  111.     float        xx, yy;
  112.  
  113.     elastic_line();
  114.     cur_x = lx;
  115.     cur_y = ly;
  116.     elastic_line();
  117.     point[num_point].x = lx;
  118.     point[num_point++].y = ly;
  119.     x = point[0].x;
  120.     y = point[0].y;
  121.     /* erase previous line segment(s) if necessary */
  122.     for (i = 1; i < num_point; i++) {
  123.     pw_vector(canvas_win, x, y, point[i].x, point[i].y, INV_PAINT,
  124.           1, RUBBER_LINE, 0.0, DEFAULT_COLOR);
  125.     x = point[i].x;
  126.     y = point[i].y;
  127.     }
  128.     if (!compute_arccenter(point[0], point[1], point[2], &xx, &yy)) {
  129.     put_msg("Invalid ARC geometry");
  130.     arc_drawing_selected();
  131.     draw_mousefun_canvas();
  132.     return;
  133.     }
  134.     if ((arc = create_arc()) == NULL) {
  135.     arc_drawing_selected();
  136.     draw_mousefun_canvas();
  137.     return;
  138.     }
  139.     arc->type = T_3_POINTS_ARC;
  140.     arc->style = cur_linestyle;
  141.     arc->thickness = cur_linewidth;
  142.     /* scale dash length according to linethickness */
  143.     arc->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  144.     arc->pen = 0;
  145.     arc->fill_style = cur_fillstyle;
  146.     arc->color = cur_color;
  147.     arc->depth = cur_depth;
  148.     arc->direction = compute_direction(point[0], point[1], point[2]);
  149.     if (autoforwardarrow_mode)
  150.     arc->for_arrow = forward_arrow();
  151.     else
  152.     arc->for_arrow = NULL;
  153.     if (autobackwardarrow_mode)
  154.     arc->back_arrow = backward_arrow();
  155.     else
  156.     arc->back_arrow = NULL;
  157.     arc->center.x = xx;
  158.     arc->center.y = yy;
  159.     arc->point[0].x = point[0].x;
  160.     arc->point[0].y = point[0].y;
  161.     arc->point[1].x = point[1].x;
  162.     arc->point[1].y = point[1].y;
  163.     arc->point[2].x = point[2].x;
  164.     arc->point[2].y = point[2].y;
  165.     arc->next = NULL;
  166.     draw_arc(arc, PAINT);
  167.     if (appres.DEBUG) {
  168.     int        xmin, ymin, xmax, ymax;
  169.  
  170.     arc_bound(arc, &xmin, &ymin, &xmax, &ymax);
  171.     elastic_box(xmin, ymin, xmax, ymax);
  172.     }
  173.     add_arc(arc);
  174.     arc_drawing_selected();
  175.     draw_mousefun_canvas();
  176. }
  177.