home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part06 / drag.c < prev    next >
C/C++ Source or Header  |  1990-07-02  |  7KB  |  337 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "font.h"
  13. #include "object.h"
  14. #include "paintop.h"
  15.  
  16. extern F_pos        last_position, new_position;  /* undo.c   */
  17. extern int        foreground_color, background_color;
  18. extern int        fix_x, fix_y, cur_x, cur_y;
  19.  
  20. extern            (*canvas_kbd_proc)();
  21. extern            (*canvas_locmove_proc)();
  22. extern            (*canvas_leftbut_proc)();
  23. extern            (*canvas_middlebut_proc)();
  24. extern            (*canvas_rightbut_proc)();
  25. extern            null_proc();
  26. extern            set_popupmenu();
  27.  
  28. static            draw_movingbox();
  29. static int        x1off, y1off, x2off, y2off;
  30.  
  31. extern int        (*return_proc)();
  32. extern int         move_line(), place_line();
  33. extern int         move_arc(), place_arc();
  34. extern int         move_spline(), place_spline();
  35. extern int         move_movingbox();
  36. extern int         place_ellipse();
  37. extern int         move_text(), place_text();
  38. extern int         place_compound();
  39.  
  40. static F_arc        *arc;
  41. static F_compound    *cmpnd;
  42. static F_ellipse    *ellipse;
  43. static F_line        *line;
  44. static F_spline        *spline;
  45. static F_text        *text;
  46.  
  47. static
  48. draw_movingbox(op)
  49. int    op;
  50. {
  51.     register int    x1, y1, x2, y2;
  52.  
  53.     x1 = cur_x + x1off;
  54.     x2 = cur_x + x2off;
  55.     y1 = cur_y + y1off;
  56.     y2 = cur_y + y2off;
  57.     draw_rectbox(x1, y1, x2, y2, op);
  58.     }
  59.  
  60. move_movingbox(x, y)
  61. int    x, y;
  62. {
  63.     draw_movingbox(INV_PAINT);
  64.     cur_x = x;
  65.     cur_y = y;
  66.     draw_movingbox(INV_PAINT);
  67.     }
  68.  
  69. /***************************** ellipse section ************************/
  70.  
  71. init_ellipsedragging(e, x, y)
  72. F_ellipse    *e;
  73. int        x, y;
  74. {
  75.     ellipse = e;
  76.     last_position.x = cur_x = x; 
  77.     last_position.y = cur_y = y;
  78.     x1off = (e->center.x - e->radiuses.x) - cur_x; 
  79.     x2off = (e->center.x + e->radiuses.x) - cur_x; 
  80.     y1off = (e->center.y - e->radiuses.y) - cur_y;
  81.     y2off = (e->center.y + e->radiuses.y) - cur_y;
  82.     canvas_locmove_proc = move_movingbox;
  83.     canvas_middlebut_proc = place_ellipse;
  84.     set_action_on();
  85.     draw_movingbox(INV_PAINT);
  86.     }
  87.  
  88. place_ellipse(x, y)
  89. int    x, y;
  90. {
  91.     draw_movingbox(INV_PAINT);
  92.     new_position.x = x;
  93.     new_position.y = y;
  94.     translate_ellipse(ellipse, x - last_position.x, y - last_position.y);
  95.     draw_ellipse(ellipse, foreground_color);
  96.     show_pointmarker();
  97.     set_modifiedflag();
  98.     (*return_proc)();
  99.     }
  100.  
  101. /*****************************  arc  section  *******************/
  102.  
  103. init_arcdragging(a, x, y)
  104. F_arc    *a;
  105. int    x, y;
  106. {
  107.     arc = a;
  108.     fix_x = last_position.x = cur_x = x;
  109.     fix_y = last_position.y = cur_y = y;
  110.     canvas_locmove_proc = move_arc;
  111.     canvas_middlebut_proc = place_arc;
  112.     set_action_on();
  113.     draw_movingarc(arc, INV_PAINT);
  114.     }
  115.  
  116. move_arc(x, y)
  117. int    x, y;
  118. {
  119.     draw_movingarc(arc, INV_PAINT);
  120.     cur_x = x;  
  121.     cur_y = y;
  122.     draw_movingarc(arc, INV_PAINT);
  123.     }
  124.  
  125. place_arc(x, y)
  126. int    x, y;
  127. {
  128.     draw_movingarc(arc, INV_PAINT);
  129.     new_position.x = x;
  130.     new_position.y = y;
  131.     translate_arc(arc, x - fix_x, y - fix_y);
  132.     draw_arc(arc, foreground_color);
  133.     show_pointmarker();
  134.     set_modifiedflag();
  135.     (*return_proc)();
  136.     }
  137.  
  138. draw_movingarc(a, op)
  139. F_arc    *a;
  140. int    op;
  141. {
  142.     int    dx, dy;
  143.  
  144.     dx = cur_x - fix_x;
  145.     dy = cur_y - fix_y;
  146.     pw_vector(canvas_win, a->point[0].x+dx, a->point[0].y+dy,
  147.         a->point[1].x+dx, a->point[1].y+dy, op, 1, SOLID_LINE, 0.0);
  148.     pw_vector(canvas_win, a->point[1].x+dx, a->point[1].y+dy,
  149.         a->point[2].x+dx, a->point[2].y+dy, op, 1, SOLID_LINE, 0.0);
  150.     }
  151.  
  152. /*************************  line  section  **********************/
  153.  
  154. init_linedragging(l, x, y)
  155. F_line    *l;
  156. int    x, y;
  157. {
  158.     line = l;
  159.     last_position.x = cur_x = fix_x = x;
  160.     last_position.y = cur_y = fix_y = y;
  161.     canvas_locmove_proc = move_line;
  162.     canvas_middlebut_proc = place_line;
  163.     set_action_on();
  164.     draw_movingpoint(line->points, INV_PAINT);
  165.     }
  166.  
  167. move_line(x, y)
  168. int    x, y;
  169. {
  170.     draw_movingpoint(line->points, INV_PAINT);
  171.     cur_x = x;  
  172.     cur_y = y;
  173.     draw_movingpoint(line->points, INV_PAINT);
  174.     }
  175.  
  176. place_line(x, y)
  177. int    x, y;
  178. {
  179.     draw_movingpoint(line->points, INV_PAINT);
  180.     new_position.x = x;
  181.     new_position.y = y;
  182.     translate_line(line, x - fix_x, y - fix_y);
  183.     draw_line(line, PAINT);
  184.     show_pointmarker();
  185.     set_modifiedflag();
  186.     (*return_proc)();
  187.     }
  188.  
  189. draw_movingpoint(ps, op)
  190. F_point    *ps;
  191. int    op;
  192. {
  193.     F_point    *p;
  194.     int    dx, dy, x, y, xx, yy;
  195.  
  196.     dx = cur_x - fix_x;
  197.     dy = cur_y - fix_y;
  198.     p = ps;
  199.     x = p->x + dx;
  200.     y = p->y + dy;
  201.     for (p = p->next; p != NULL; x = xx, y = yy, p = p->next) {
  202.         xx = p->x + dx;  yy = p->y +dy;
  203.         pw_vector(canvas_win, x, y, xx, yy, op, 1, SOLID_LINE, 0.0);
  204.         }
  205. }
  206.  
  207. /************************  text section  **************************/
  208.  
  209. static    PR_SIZE    txsize;
  210.  
  211. init_textdragging(t, x, y)
  212. F_text    *t;
  213. int    x, y;
  214. {
  215.  
  216.     text = t;
  217.     fix_x = cur_x = x; 
  218.     fix_y = cur_y = y;
  219.     y1off = t->base_y - y;
  220.     if (t->type == T_CENTER_JUSTIFIED || t->type == T_RIGHT_JUSTIFIED)
  221.         {
  222.         txsize = pf_textwidth(t->font, t->size, strlen(t->cstring), t->cstring);
  223.         if (t->type == T_CENTER_JUSTIFIED)
  224.             x1off =  - txsize.x/2;
  225.         else
  226.             x1off =  - txsize.x;
  227.         fix_x = t->base_x;
  228.         }
  229.     else /* LEFT */
  230.         {
  231.         x1off = 0;
  232.         fix_x = t->base_x;
  233.         }
  234.     canvas_locmove_proc = move_text;
  235.     canvas_middlebut_proc = place_text;
  236.     draw_movingtext();
  237.     set_action_on();
  238.     }
  239.  
  240. move_text(x, y)
  241. int    x, y;
  242. {
  243.     draw_movingtext();
  244.     cur_x = x;
  245.     cur_y = y;
  246.     draw_movingtext();
  247.     }
  248.  
  249. place_text(x, y)
  250. int    x, y;
  251. {
  252.     draw_movingtext();
  253.     new_position.x = x;
  254.     new_position.y = y;
  255.     last_position.x = fix_x; 
  256.     last_position.y = fix_y;
  257.     translate_text(text, x - fix_x, y - fix_y);
  258.     draw_text(text, PAINT);
  259.     set_modifiedflag();
  260.     (*return_proc)();
  261.     }
  262.  
  263. draw_movingtext()
  264. {
  265.     pw_text(canvas_win, cur_x + x1off, cur_y + y1off, INV_PAINT,
  266.         text->font, text->size, text->cstring);
  267.     }
  268.  
  269. /*************************  spline  section  **********************/
  270.  
  271. init_splinedragging(s, x, y)
  272. F_spline    *s;
  273. int        x, y;
  274. {
  275.     spline = s;
  276.     last_position.x = cur_x = fix_x = x;
  277.     last_position.y = cur_y = fix_y = y;
  278.     canvas_locmove_proc = move_spline;
  279.     canvas_middlebut_proc = place_spline;
  280.     set_action_on();
  281.     draw_movingpoint(spline->points, INV_PAINT);
  282.     }
  283.  
  284. move_spline(x, y)
  285. int    x, y;
  286. {
  287.     draw_movingpoint(spline->points, INV_PAINT);
  288.     cur_x = x;  
  289.     cur_y = y;
  290.     draw_movingpoint(spline->points, INV_PAINT);
  291.     }
  292.  
  293. place_spline(x, y)
  294. int    x, y;
  295. {
  296.     draw_movingpoint(spline->points, INV_PAINT);
  297.     translate_spline(spline, x - fix_x, y - fix_y);
  298.     new_position.x = x;
  299.     new_position.y = y;
  300.     draw_spline(spline, PAINT);
  301.     show_pointmarker();
  302.     set_modifiedflag();
  303.     (*return_proc)();
  304.     }
  305.  
  306. /*****************************  Compound section  *******************/
  307.  
  308. init_compounddragging(c, x, y)
  309. F_compound    *c;
  310. int        x, y;
  311. {
  312.     cmpnd = c;
  313.     last_position.x = cur_x = x; 
  314.     last_position.y = cur_y = y;
  315.     x1off = c->nwcorner.x - x;
  316.     x2off = c->secorner.x - x;
  317.     y1off = c->nwcorner.y - y;
  318.     y2off = c->secorner.y - y;
  319.     canvas_locmove_proc = move_movingbox;
  320.     canvas_middlebut_proc = place_compound;
  321.     set_action_on();
  322.     draw_movingbox(INV_PAINT);
  323.     }
  324.  
  325. place_compound(x, y)
  326. int    x, y;
  327. {
  328.     draw_movingbox(INV_PAINT);
  329.     new_position.x = x;
  330.     new_position.y = y;
  331.     translate_compound(cmpnd, x - last_position.x, y - last_position.y);
  332.     draw_compound(cmpnd);
  333.     draw_compoundbox(cmpnd, INV_PAINT);
  334.     set_modifiedflag();
  335.     (*return_proc)();
  336.     }
  337.