home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!widget!jgg
- From: jgg@evb.com (John Goodsen)
- Subject: Re: arrow-headed lines in X
- Message-ID: <1992Nov22.173808.3704@evb.com>
- Organization: EVB Software Engineering, Inc.
- Date: Sun, 22 Nov 1992 17:38:08 GMT
- Lines: 77
-
- Here's something I pulled of the net from Paul Brown about
- a year ago. Hope it helps you...
-
- --
- John Goodsen PCIS Programme
- Software Process & Environments Ada Joint Program Office
- EVB Software Engineering goodsenj@ajpo.sei.cmu.edu
- jgg@evb.com
-
-
- ----------------
-
- >
- >I am looking for a way to draw arrow-headed line using MOTIF or
- >other X toolkit or Xlib.
- >
- >Any help will be appreciated.
- >Please e-mail your help as I am not a frequent reader of this group.
- >
- >Thanks in advance.
- >
- >
- >T. Hassan
- >
-
-
- Here is a snippet of some code I developed to draw line segments with
- arrow heads. I don't expect that you'll be able to drop this code in
- someplace and use it, but the parametrization of an arrow head on the
- end of a given line segment can be reverse engineered if you feel like
- taking the time.
-
- -----------------------------------------------------------------------
-
- void pbDrawArrowOnCanvas (canvas, arrow)
- Widget canvas;
- pb_line_ptr arrow;
- {
- XSegment arrow_segments[3];
- double r = .01745329;
- double l = 30.0;
- double theta, alpha = 20.0*r;
-
- /* AVOID FLOATING POINT EXCEPTION... */
- if (!((arrow->pbx2-arrow->pbx1) | (arrow->pby2-arrow->pby1))) return;
-
- /* MAIN LINE SEGMENT */
- arrow_segments[0].x1 = arrow->pbx1; arrow_segments[0].y1 = arrow->pby1;
- arrow_segments[0].x2 = arrow->pbx2; arrow_segments[0].y2 = arrow->pby2;
-
- /* ARROW HEAD */
- theta = atan2 ((double)(arrow->pby2 - arrow->pby1),
- (double)(arrow->pbx2 - arrow->pbx1));
- arrow_segments[1].x1 = arrow->pbx2; arrow_segments[1].y1 = arrow->pby2;
- arrow_segments[1].x1 = arrow->pbx2; arrow_segments[1].y1 = arrow->pby2;
- arrow_segments[1].x2 = arrow->pbx2 - (short)(l*cos(theta - alpha));
- arrow_segments[1].y2 = arrow->pby2 - (short)(l*sin(theta - alpha));
- arrow_segments[2].x1 = arrow->pbx2; arrow_segments[2].y1 = arrow->pby2;
- arrow_segments[2].x2 = arrow->pbx2 - (short)(l*cos(theta + alpha));
- arrow_segments[2].y2 = arrow->pby2 - (short)(l*sin(theta + alpha));
-
- /* DRAW LINE WITH ARROW HEAD */
- XDrawSegments (
- XtDisplay(canvas),
- XtWindow (canvas),
- arrow->Gc,
- arrow_segments,
- 3);
- XFlush(XtDisplay(canvas));
- }
-
- --------------------------------------------------------------------------
-
- Paul Brown
- brown@zen.wes.army.mil
- (601) 634-2109
-
-