home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part02 / d_box.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  2.7 KB  |  105 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 declarations *********************/
  25.  
  26. int        init_box_drawing();
  27. static        create_boxobject(), cancel_box();
  28.  
  29. box_drawing_selected()
  30. {
  31.     set_mousefun("corner point", "", "");
  32.     canvas_kbd_proc = null_proc;
  33.     canvas_locmove_proc = null_proc;
  34.     canvas_leftbut_proc = init_box_drawing;
  35.     canvas_middlebut_proc = null_proc;
  36.     canvas_rightbut_proc = null_proc;
  37.     set_cursor(arrow_cursor);
  38.     reset_action_on();
  39. }
  40.  
  41. init_box_drawing(x, y)
  42.     int            x, y;
  43. {
  44.     cur_x = fix_x = x;
  45.     cur_y = fix_y = y;
  46.     set_mousefun("final point", "", "cancel");
  47.     draw_mousefun_canvas();
  48.     canvas_locmove_proc = resizing_box;
  49.     canvas_leftbut_proc = create_boxobject;
  50.     canvas_middlebut_proc = null_proc;
  51.     canvas_rightbut_proc = cancel_box;
  52.     elastic_box(fix_x, fix_y, cur_x, cur_y);
  53.     set_temp_cursor(null_cursor);
  54.     set_action_on();
  55. }
  56.  
  57. static
  58. cancel_box()
  59. {
  60.     elastic_box(fix_x, fix_y, cur_x, cur_y);
  61.     box_drawing_selected();
  62.     draw_mousefun_canvas();
  63. }
  64.  
  65. static
  66. create_boxobject(x, y)
  67.     int            x, y;
  68. {
  69.     F_line       *box;
  70.     F_point       *point;
  71.  
  72.     elastic_box(fix_x, fix_y, cur_x, cur_y);
  73.  
  74.     if ((point = create_point()) == NULL)
  75.     return;
  76.  
  77.     point->x = x;
  78.     point->y = y;
  79.     point->next = NULL;
  80.  
  81.     if ((box = create_line()) == NULL) {
  82.     free((char *) point);
  83.     return;
  84.     }
  85.     box->type = T_BOX;
  86.     box->style = cur_linestyle;
  87.     box->thickness = cur_linewidth;
  88.     box->color = cur_color;
  89.     box->depth = cur_depth;
  90.     box->pen = 0;
  91.     box->fill_style = cur_fillstyle;
  92.     /* scale dash length by line thickness */
  93.     box->style_val = cur_styleval * (cur_linewidth + 1) / 2;
  94.     box->radius = 0;
  95.     box->points = point;
  96.     append_point(x, fix_y, &point);
  97.     append_point(fix_x, fix_y, &point);
  98.     append_point(fix_x, y, &point);
  99.     append_point(x, y, &point);
  100.     draw_line(box, PAINT);
  101.     add_line(box);
  102.     box_drawing_selected();
  103.     draw_mousefun_canvas();
  104. }
  105.