home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part07 / d_ellipse.c next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  8.8 KB  |  342 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. /*************************  local procedures  ********************/
  25.  
  26. static int    init_ellipsebyradius_drawing();
  27. static int    init_ellipsebydiameter_drawing();
  28. static int    init_circlebyradius_drawing();
  29. static int    init_circlebydiameter_drawing();
  30. static int    create_ellipsebydia();
  31. static int    create_ellipsebyrad();
  32. static int    create_circlebyrad();
  33. static int    create_circlebydia();
  34. static int    cancel_ellipsebydia();
  35. static int    cancel_ellipsebyrad();
  36. static int    cancel_circlebyrad();
  37. static int    cancel_circlebydia();
  38.  
  39. ellipsebyradius_drawing_selected()
  40. {
  41.     canvas_kbd_proc = null_proc;
  42.     canvas_locmove_proc = null_proc;
  43.     canvas_leftbut_proc = init_ellipsebyradius_drawing;
  44.     canvas_middlebut_proc = null_proc;
  45.     canvas_rightbut_proc = null_proc;
  46.     set_cursor(arrow_cursor);
  47.     set_mousefun("center point", "", "");
  48.     reset_action_on();
  49. }
  50.  
  51. static
  52. init_ellipsebyradius_drawing(x, y)
  53.     int            x, y;
  54. {
  55.     cur_x = fix_x = x;
  56.     cur_y = fix_y = y;
  57.     cur_angle = cur_elltextangle/180.0*M_PI;
  58.     center_marker(fix_x, fix_y);
  59.     set_mousefun("corner point", "", "cancel");
  60.     draw_mousefun_canvas();
  61.     canvas_locmove_proc = resizing_ebr;
  62.     canvas_rightbut_proc = cancel_ellipsebyrad;
  63.     canvas_leftbut_proc = create_ellipsebyrad;
  64.     set_temp_cursor(null_cursor);
  65.     elastic_ebr();
  66.     set_action_on();
  67. }
  68.  
  69. static
  70. cancel_ellipsebyrad()
  71. {
  72.     elastic_ebr();
  73.     center_marker(fix_x, fix_y);
  74.     ellipsebyradius_drawing_selected();
  75.     draw_mousefun_canvas();
  76. }
  77.  
  78. static
  79. create_ellipsebyrad(x, y)
  80.     int            x, y;
  81. {
  82.     F_ellipse       *ellipse;
  83.  
  84.     elastic_ebr();
  85.     center_marker(fix_x, fix_y);
  86.     if ((ellipse = create_ellipse()) == NULL)
  87.     return;
  88.  
  89.     ellipse->type = T_ELLIPSE_BY_RAD;
  90.     ellipse->style = cur_linestyle;
  91.     ellipse->thickness = cur_linewidth;
  92.     ellipse->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  93.     ellipse->angle = cur_elltextangle/180.0*M_PI;    /* convert to radians */
  94.     ellipse->color = cur_color;
  95.     ellipse->depth = cur_depth;
  96.     ellipse->pen = 0;
  97.     ellipse->fill_style = cur_fillstyle;
  98.     ellipse->direction = 1;
  99.     ellipse->center.x = fix_x;
  100.     ellipse->center.y = fix_y;
  101.     ellipse->radiuses.x = abs(x - fix_x);
  102.     ellipse->radiuses.y = abs(y - fix_y);
  103.     ellipse->start.x = fix_x;
  104.     ellipse->start.y = fix_y;
  105.     ellipse->end.x = x;
  106.     ellipse->end.y = y;
  107.     ellipse->next = NULL;
  108.     draw_ellipse(ellipse, PAINT);
  109.     add_ellipse(ellipse);
  110.     ellipsebyradius_drawing_selected();
  111.     draw_mousefun_canvas();
  112. }
  113.  
  114. ellipsebydiameter_drawing_selected()
  115. {
  116.     set_mousefun("first corner", "", "");
  117.     canvas_kbd_proc = null_proc;
  118.     canvas_locmove_proc = null_proc;
  119.     canvas_leftbut_proc = init_ellipsebydiameter_drawing;
  120.     canvas_middlebut_proc = null_proc;
  121.     canvas_rightbut_proc = null_proc;
  122.     set_cursor(arrow_cursor);
  123.     reset_action_on();
  124. }
  125.  
  126. static
  127. init_ellipsebydiameter_drawing(x, y)
  128.     int            x, y;
  129. {
  130.     cur_x = fix_x = x;
  131.     cur_y = fix_y = y;
  132.     cur_angle = cur_elltextangle/180.0*M_PI;
  133.     center_marker(fix_x, fix_y);
  134.     set_mousefun("final corner", "", "cancel");
  135.     draw_mousefun_canvas();
  136.     canvas_locmove_proc = resizing_ebd;
  137.     canvas_rightbut_proc = cancel_ellipsebydia;
  138.     canvas_leftbut_proc = create_ellipsebydia;
  139.     set_temp_cursor(null_cursor);
  140.     elastic_ebd();
  141.     set_action_on();
  142. }
  143.  
  144. static
  145. cancel_ellipsebydia()
  146. {
  147.     elastic_ebd();
  148.     center_marker(fix_x, fix_y);
  149.     ellipsebydiameter_drawing_selected();
  150.     draw_mousefun_canvas();
  151. }
  152.  
  153. static
  154. create_ellipsebydia(x, y)
  155.     int            x, y;
  156. {
  157.     F_ellipse       *ellipse;
  158.  
  159.     elastic_ebd();
  160.     center_marker(fix_x, fix_y);
  161.     if ((ellipse = create_ellipse()) == NULL)
  162.     return;
  163.  
  164.     ellipse->type = T_ELLIPSE_BY_DIA;
  165.     ellipse->style = cur_linestyle;
  166.     ellipse->thickness = cur_linewidth;
  167.     ellipse->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  168.     ellipse->angle = cur_elltextangle/180.0*M_PI;    /* convert to radians */
  169.     ellipse->color = cur_color;
  170.     ellipse->depth = cur_depth;
  171.     ellipse->pen = 0;
  172.     ellipse->fill_style = cur_fillstyle;
  173.     ellipse->direction = 1;
  174.     ellipse->center.x = (fix_x + x) / 2;
  175.     ellipse->center.y = (fix_y + y) / 2;
  176.     ellipse->radiuses.x = abs(ellipse->center.x - fix_x);
  177.     ellipse->radiuses.y = abs(ellipse->center.y - fix_y);
  178.     ellipse->start.x = fix_x;
  179.     ellipse->start.y = fix_y;
  180.     ellipse->end.x = x;
  181.     ellipse->end.y = y;
  182.     ellipse->next = NULL;
  183.     draw_ellipse(ellipse, PAINT);
  184.     add_ellipse(ellipse);
  185.     ellipsebydiameter_drawing_selected();
  186.     draw_mousefun_canvas();
  187. }
  188.  
  189. /***************************  circle  section  ************************/
  190.  
  191. circlebyradius_drawing_selected()
  192. {
  193.     set_mousefun("center point", "", "");
  194.     canvas_kbd_proc = null_proc;
  195.     canvas_locmove_proc = null_proc;
  196.     canvas_leftbut_proc = init_circlebyradius_drawing;
  197.     canvas_middlebut_proc = null_proc;
  198.     canvas_rightbut_proc = null_proc;
  199.     set_cursor(arrow_cursor);
  200.     reset_action_on();
  201. }
  202.  
  203. static
  204. init_circlebyradius_drawing(x, y)
  205.     int            x, y;
  206. {
  207.     cur_x = fix_x = x;
  208.     cur_y = fix_y = y;
  209.     center_marker(fix_x, fix_y);
  210.     set_mousefun("set radius", "", "cancel");
  211.     draw_mousefun_canvas();
  212.     canvas_locmove_proc = resizing_cbr;
  213.     canvas_rightbut_proc = cancel_circlebyrad;
  214.     canvas_leftbut_proc = create_circlebyrad;
  215.     set_temp_cursor(null_cursor);
  216.     elastic_cbr();
  217.     set_action_on();
  218. }
  219.  
  220. static
  221. cancel_circlebyrad()
  222. {
  223.     elastic_cbr();
  224.     center_marker(fix_x, fix_y);
  225.     circlebyradius_drawing_selected();
  226.     draw_mousefun_canvas();
  227. }
  228.  
  229. static
  230. create_circlebyrad(x, y)
  231.     int            x, y;
  232. {
  233.     F_ellipse       *c;
  234.     int            rx, ry;
  235.  
  236.     elastic_cbr();
  237.     center_marker(fix_x, fix_y);
  238.     if ((c = create_ellipse()) == NULL)
  239.     return;
  240.  
  241.     c->type = T_CIRCLE_BY_RAD;
  242.     c->style = cur_linestyle;
  243.     c->thickness = cur_linewidth;
  244.     c->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  245.     c->angle = 0.0;
  246.     c->color = cur_color;
  247.     c->depth = cur_depth;
  248.     c->pen = 0;
  249.     c->fill_style = cur_fillstyle;
  250.     c->direction = 1;
  251.     c->center.x = fix_x;
  252.     c->center.y = fix_y;
  253.     rx = fix_x - x;
  254.     ry = fix_y - y;
  255.     c->radiuses.x = c->radiuses.y = round(sqrt((double) (rx * rx + ry * ry)));
  256.     c->start.x = fix_x;
  257.     c->start.y = fix_y;
  258.     c->end.x = x;
  259.     c->end.y = y;
  260.     c->next = NULL;
  261.     draw_ellipse(c, PAINT);
  262.     add_ellipse(c);
  263.     circlebyradius_drawing_selected();
  264.     draw_mousefun_canvas();
  265. }
  266.  
  267. circlebydiameter_drawing_selected()
  268. {
  269.     set_mousefun("diameter point", "", "");
  270.     canvas_kbd_proc = null_proc;
  271.     canvas_locmove_proc = null_proc;
  272.     canvas_leftbut_proc = init_circlebydiameter_drawing;
  273.     canvas_middlebut_proc = null_proc;
  274.     canvas_rightbut_proc = null_proc;
  275.     set_cursor(arrow_cursor);
  276.     reset_action_on();
  277. }
  278.  
  279. static
  280. init_circlebydiameter_drawing(x, y)
  281.     int            x, y;
  282. {
  283.     cur_x = fix_x = x;
  284.     cur_y = fix_y = y;
  285.     center_marker(fix_x, fix_y);
  286.     set_mousefun("final point", "", "cancel");
  287.     draw_mousefun_canvas();
  288.     canvas_locmove_proc = resizing_cbd;
  289.     canvas_leftbut_proc = create_circlebydia;
  290.     canvas_rightbut_proc = cancel_circlebydia;
  291.     set_temp_cursor(null_cursor);
  292.     elastic_cbd();
  293.     set_action_on();
  294. }
  295.  
  296. static
  297. cancel_circlebydia()
  298. {
  299.     elastic_cbd();
  300.     center_marker(fix_x, fix_y);
  301.     circlebydiameter_drawing_selected();
  302.     draw_mousefun_canvas();
  303. }
  304.  
  305. static
  306. create_circlebydia(x, y)
  307.     int            x, y;
  308. {
  309.     F_ellipse       *c;
  310.     int            rx, ry;
  311.  
  312.     elastic_cbd();
  313.     center_marker(fix_x, fix_y);
  314.     if ((c = create_ellipse()) == NULL)
  315.     return;
  316.  
  317.     c->type = T_CIRCLE_BY_DIA;
  318.     c->style = cur_linestyle;
  319.     c->thickness = cur_linewidth;
  320.     c->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  321.     c->angle = 0.0;
  322.     c->color = cur_color;
  323.     c->depth = cur_depth;
  324.     c->pen = 0;
  325.     c->fill_style = cur_fillstyle;
  326.     c->direction = 1;
  327.     c->center.x = (fix_x + x) / 2 + .5;
  328.     c->center.y = (fix_y + y) / 2 + .5;
  329.     rx = x - c->center.x;
  330.     ry = y - c->center.y;
  331.     c->radiuses.x = c->radiuses.y = round(sqrt((double) (rx * rx + ry * ry)));
  332.     c->start.x = fix_x;
  333.     c->start.y = fix_y;
  334.     c->end.x = x;
  335.     c->end.y = y;
  336.     c->next = NULL;
  337.     draw_ellipse(c, PAINT);
  338.     add_ellipse(c);
  339.     circlebydiameter_drawing_selected();
  340.     draw_mousefun_canvas();
  341. }
  342.