home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / d_line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  5.2 KB  |  195 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. extern int    latex_endpoint();
  25.  
  26. /*************************** locally global variables *********************/
  27.  
  28. static int    init_line_drawing();
  29.  
  30. int        create_lineobject();
  31. int        get_intermediatepoint();
  32.  
  33. /**********************     polyline and polygon section  **********************/
  34.  
  35. line_drawing_selected()
  36. {
  37.     canvas_kbd_proc = null_proc;
  38.     canvas_locmove_proc = null_proc;
  39.     canvas_leftbut_proc = init_line_drawing;
  40.     canvas_rightbut_proc = null_proc;
  41.     set_cursor(arrow_cursor);
  42.     reset_action_on();
  43.     if (cur_mode == F_POLYGON) {
  44.     set_mousefun("first point", "", "");
  45.     min_num_points = 3;
  46.     canvas_middlebut_proc = null_proc;
  47.     } else {
  48.     set_mousefun("first point", "single point", "");
  49.     min_num_points = 1;
  50.     num_point = 0;
  51.     fix_x = fix_y = -1;
  52.     canvas_middlebut_proc = create_lineobject;
  53.     }
  54. }
  55.  
  56. static
  57. init_line_drawing(x, y)
  58.     int            x, y;
  59. {
  60.     init_trace_drawing(x, y);
  61. }
  62.  
  63. cancel_line_drawing()
  64. {
  65.     elastic_line();
  66.     cur_x = fix_x;
  67.     cur_y = fix_y;
  68.     if (cur_point != first_point)
  69.     elastic_moveline(first_point);    /* erase control vector */
  70.     free_points(first_point);
  71.     return_proc();
  72.     draw_mousefun_canvas();
  73. }
  74.  
  75. init_trace_drawing(x, y)
  76.     int            x, y;
  77. {
  78.     if ((first_point = create_point()) == NULL)
  79.     return;
  80.  
  81.     cur_point = first_point;
  82.     set_action_on();
  83.     cur_point->x = fix_x = cur_x = x;
  84.     cur_point->y = fix_y = cur_y = y;
  85.     cur_point->next = NULL;
  86.     length_msg(MSG_LENGTH);
  87.     if (latexline_mode || latexarrow_mode) {
  88.     canvas_locmove_proc = latex_line;
  89.     } else if (manhattan_mode || mountain_mode) {
  90.     canvas_locmove_proc = constrainedangle_line;
  91.     } else {
  92.     canvas_locmove_proc = freehand_line;
  93.     }
  94.     canvas_leftbut_proc = get_intermediatepoint;
  95.     canvas_middlebut_save = create_lineobject;
  96.     canvas_rightbut_proc = cancel_line_drawing;
  97.     return_proc = line_drawing_selected;
  98.     num_point = 1;
  99.     set_mousefun("next point", "", "cancel");
  100.     if (num_point >= min_num_points - 1) {
  101.     set_mousefun("next point", "final point", "cancel");
  102.     canvas_middlebut_proc = canvas_middlebut_save;
  103.     }
  104.     draw_mousefun_canvas();
  105.     set_temp_cursor(null_cursor);
  106.     cur_cursor = null_cursor;
  107.     elastic_line();
  108. }
  109.  
  110. get_intermediatepoint(x, y)
  111.     int            x, y;
  112. {
  113.     (*canvas_locmove_proc) (x, y);
  114.     num_point++;
  115.     fix_x = cur_x;
  116.     fix_y = cur_y;
  117.     elastic_line();
  118.     if (cur_cursor != null_cursor) {
  119.     set_temp_cursor(null_cursor);
  120.     cur_cursor = null_cursor;
  121.     }
  122.     win_setmouseposition(canvas_win, cur_x, cur_y);
  123.     append_point(fix_x, fix_y, &cur_point);
  124.     if (num_point == min_num_points - 1) {
  125.     set_mousefun("next point", "final point", "cancel");
  126.     draw_mousefun_canvas();
  127.     canvas_middlebut_proc = canvas_middlebut_save;
  128.     }
  129. }
  130.  
  131. /* come here upon pressing middle button (last point of lineobject) */
  132.  
  133. create_lineobject(x, y)
  134.     int            x, y;
  135. {
  136.     F_line       *line;
  137.     int            dot;
  138.  
  139.     if (num_point == 0) {
  140.     if ((first_point = create_point()) == NULL) {
  141.         line_drawing_selected();
  142.         draw_mousefun_canvas();
  143.         return;
  144.     }
  145.     cur_point = first_point;
  146.     first_point->x = fix_x = cur_x = x;
  147.     first_point->y = fix_y = cur_y = y;
  148.     first_point->next = NULL;
  149.     num_point++;
  150.     } else if (x != fix_x || y != fix_y) {
  151.     get_intermediatepoint(x, y);
  152.     }
  153.     dot = (num_point == 1);
  154.     elastic_line();
  155.     if ((line = create_line()) == NULL) {
  156.     line_drawing_selected();
  157.     draw_mousefun_canvas();
  158.     return;
  159.     }
  160.     line->type = T_POLYLINE;
  161.     line->thickness = cur_linewidth;
  162.     line->fill_style = cur_fillstyle;
  163.     line->style = cur_linestyle;
  164.     line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  165.     line->color = cur_color;
  166.     line->depth = cur_depth;
  167.     line->pen = 0;
  168.     line->points = first_point;
  169.     if (!dot) {
  170.     if (cur_mode == F_POLYGON) {    /* close off polygon */
  171.         line->type = T_POLYGON;
  172.         num_point++;
  173.         append_point(first_point->x, first_point->y, &cur_point);
  174.         elastic_line();
  175.         fix_x = first_point->x;
  176.         fix_y = first_point->y;
  177.         elastic_line();    /* fix last elastic line */
  178.     } else {        /* polyline; draw any arrows */
  179.         if (autoforwardarrow_mode)
  180.         line->for_arrow = forward_arrow();
  181.         /* arrow will be drawn in draw_line below */
  182.         if (autobackwardarrow_mode)
  183.         line->back_arrow = backward_arrow();
  184.         /* arrow will be drawn in draw_line below */
  185.     }
  186.     cur_x = fix_x;
  187.     cur_y = fix_y;
  188.     elastic_moveline(first_point);    /* erase temporary outline */
  189.     }
  190.     draw_line(line, PAINT);    /* draw final */
  191.     add_line(line);
  192.     line_drawing_selected();
  193.     draw_mousefun_canvas();
  194. }
  195.