[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | DECWINDOWS 26-JAN-89 to 29-NOV-90 |
Notice: | See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit |
Moderator: | STAR::VATNE |
|
Created: | Mon Oct 30 1989 |
Last Modified: | Mon Dec 31 1990 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3726 |
Total number of notes: | 19516 |
2239.0. "Multicolored Line Style ?" by WPOMM2::ZAMBOTTI () Fri Feb 09 1990 01:30
Hi again,
got a challange for you gun X programmers.
I would like to set a Dashed Line Style such that I can draw multi colored
lines.
For instance with XSetDash you can specify the the length of dash elements but
you cannot specify the colors that will be used. Although you can chose a
line style of LineDoubleDash and specify the foreground and background colors
you cannot chose more than two colors for your line.
I would like to be able to draw a line which has 4 dash segments each of
varying length and each of varying color :
Segment # Length Color
1 4 Red
2 6 Green
3 4 Blue
4 2 Black
What I tried was setting the Line style to LineDoubleDash and the Fill style to
FillTiled. I then created a Pixmap with a width of the total length of all the
segments and a height of only 1 pixel high and colored that Pixmap as decribed
in the the above chart. But my FillStyle always seems to be ignored. A piece
of code to demonstrate what I tried follows :
char DashList[] = { 4, 6, 4, 2 } ;
Pixmap LineTile ;
LineTile = XCreatePixmap(Disp, Win1, 16, 1,
XDefaultDepth(Disp, XDefaultScreen(Disp))) ;
XSetForeground(Disp, LineGC, MyRedPixelValue)
XDrawLine(Disp, LineTile, LineGC, 0, 0, 3, 0) ;
XSetForeground(Disp, LineGC, MGreenPixelValue)
XDrawLine(Disp, LineTile, LineGC, 4, 0, 9, 0) ;
XSetForeground(Disp, LineGC, MBluePixelValue)
XDrawLine(Disp, LineTile, LineGC, 10, 0, 13, 0) ;
XSetForeground(Disp, LineGC, MBlackPixelValue) ;
XDrawLine(Disp, LineTile, LineGC, 14, 0, 15, 0) ;
XSetDashes(Disp, LineGC, 0, DashList, 4) ;
XSetTile(Disp, LineGC, LineTile) ;
XSetLineAttributes(Disp, LineGC, 0, LineDoubleDash, CapButt, JoinMiter) ;
XSetFillStyle(Disp, LineGC, FillTiled) ; /* this line doesn't do anything */
But when I next draw a line it is not multi colored just fore/back ground
colored.
Anyone have any tips?
Walter Zambotti
T.R | Title | User | Personal Name | Date | Lines |
---|
2239.1 | Keep-It-Simple | DECWIN::KLEIN | | Fri Feb 09 1990 12:17 | 32 |
| It would probably be most efficient to simply draw 4 dashed lines, each
with the appropriate dash pattern for that color. The trick lies in
getting them to overlay without erasing one another. But this isn't
really hard to solve.
The first XDrawLine would have a normal draw mode, and would draw the
dedraw the background and the first foreground color.
values.function = GXcopy;
values.foreground = firstColor;
values.background = w->core.background_pixel;
values.line_style = LineOnOffDash;
The other three lines would be drawn in GXinvert mode, with a background
color of 0 and a foreground color which is the XOR of the background color
and the appropriate foreground color for each of the other three colors.
Also change the dash pattern before drawing each line so that only the pixels
in that color are "on" and the others are "off", but keep the overall dash
pattern length the same.
Thus, each of the last three XDrawLine calls would flip the appropriate
pixels from background to the desired foreground and would leave the
other pixels (the "off" pixels) alone, since XOR with 0 is a NOOP.
As long as each pixel in the line is included at most once in any XDrawLine's
"on" pattern, the GXinvert approach will work fine.
I think this will be an efficient approach, since it uses simple (and
optimized) line drawing server code.
-steve-
|