home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / windows / x / 19445 < prev    next >
Encoding:
Text File  |  1992-11-22  |  2.5 KB  |  87 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!widget!jgg
  3. From: jgg@evb.com (John Goodsen)
  4. Subject: Re: arrow-headed lines in X
  5. Message-ID: <1992Nov22.173808.3704@evb.com>
  6. Organization: EVB Software Engineering, Inc.
  7. Date: Sun, 22 Nov 1992 17:38:08 GMT
  8. Lines: 77
  9.  
  10. Here's something I pulled of the net from Paul Brown about
  11. a year ago.  Hope it helps you...
  12.  
  13. --
  14. John Goodsen                           PCIS Programme
  15. Software Process & Environments        Ada Joint Program Office       
  16. EVB Software Engineering               goodsenj@ajpo.sei.cmu.edu
  17. jgg@evb.com
  18.  
  19.  
  20. ----------------
  21.  
  22. >
  23. >I am looking for a way to draw arrow-headed line using MOTIF or 
  24. >other X toolkit or Xlib.
  25. >
  26. >Any help will be appreciated.
  27. >Please e-mail your help as I am not a frequent reader of this group.
  28. >
  29. >Thanks in advance.
  30. >
  31. >
  32. >T. Hassan
  33. >
  34.  
  35.  
  36. Here is a snippet of some code I developed to draw line segments with
  37. arrow heads.  I don't expect that you'll be able to drop this code in
  38. someplace and use it, but the parametrization of an arrow head on the
  39. end of a given line segment can be reverse engineered if you feel like
  40. taking the time.
  41.  
  42. -----------------------------------------------------------------------
  43.  
  44. void        pbDrawArrowOnCanvas (canvas, arrow)
  45. Widget      canvas;
  46. pb_line_ptr arrow;
  47. {
  48.  XSegment arrow_segments[3];
  49.  double  r = .01745329;
  50.  double  l = 30.0;
  51.  double  theta, alpha = 20.0*r;
  52.  
  53.  /* AVOID FLOATING POINT EXCEPTION... */
  54.  if (!((arrow->pbx2-arrow->pbx1) | (arrow->pby2-arrow->pby1))) return;
  55.  
  56.  /* MAIN LINE SEGMENT */
  57.  arrow_segments[0].x1 = arrow->pbx1; arrow_segments[0].y1 = arrow->pby1;
  58.  arrow_segments[0].x2 = arrow->pbx2; arrow_segments[0].y2 = arrow->pby2;
  59.  
  60.  /* ARROW HEAD */
  61.  theta = atan2 ((double)(arrow->pby2 - arrow->pby1),
  62.                (double)(arrow->pbx2 - arrow->pbx1));
  63.  arrow_segments[1].x1 = arrow->pbx2; arrow_segments[1].y1 = arrow->pby2;
  64.  arrow_segments[1].x1 = arrow->pbx2; arrow_segments[1].y1 = arrow->pby2;
  65.  arrow_segments[1].x2 = arrow->pbx2 - (short)(l*cos(theta - alpha));
  66.  arrow_segments[1].y2 = arrow->pby2 - (short)(l*sin(theta - alpha));
  67.  arrow_segments[2].x1 = arrow->pbx2; arrow_segments[2].y1 = arrow->pby2;
  68.  arrow_segments[2].x2 = arrow->pbx2 - (short)(l*cos(theta + alpha));
  69.  arrow_segments[2].y2 = arrow->pby2 - (short)(l*sin(theta + alpha));
  70.  
  71.  /* DRAW LINE WITH ARROW HEAD */
  72.  XDrawSegments (
  73.   XtDisplay(canvas),
  74.   XtWindow (canvas),
  75.   arrow->Gc,
  76.   arrow_segments,
  77.   3);
  78.  XFlush(XtDisplay(canvas));
  79. }
  80.  
  81. --------------------------------------------------------------------------
  82.  
  83. Paul Brown
  84. brown@zen.wes.army.mil
  85. (601) 634-2109
  86.  
  87.