diff options
| author | No Author <No Author> | 2000-04-27 00:30:08 +0000 |
|---|---|---|
| committer | No Author <No Author> | 2000-04-27 00:30:08 +0000 |
| commit | 0f36c495f9d2c4b41e61ca35684e8968fb70ee54 (patch) | |
| tree | 1f69675dff67f2c03097c8c269eb341600701299 | |
| parent | 5d7d40fd35588f2d37012ec30fc34fa955bfbb31 (diff) | |
This commit was manufactured by cvs2svn to create branch 'branch-1.0'.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1099 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | src/fl_line_style.cxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/fl_line_style.cxx b/src/fl_line_style.cxx new file mode 100644 index 000000000..21ee5b424 --- /dev/null +++ b/src/fl_line_style.cxx @@ -0,0 +1,63 @@ +// fl_line_style.cxx + +#include <FL/fl_draw.H> +#include <FL/x.H> +#include <string.h> +#include <stdio.h> + +void fl_line_style(int style, int width, char* dashes) { +#ifdef WIN32 + static DWORD Cap[4]= {PS_ENDCAP_ROUND, PS_ENDCAP_FLAT, PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE}; + static DWORD Join[4]={PS_JOIN_ROUND, PS_JOIN_MITER, PS_JOIN_ROUND, PS_JOIN_BEVEL}; + int s1 = PS_GEOMETRIC | Cap[(style>>8)&3] | Join[(style>>12)&3]; + DWORD a[16]; int n = 0; + if (dashes && dashes[0]) { + s1 |= PS_USERSTYLE; + for (n = 0; n < 16 && *dashes; n++) a[n] = *dashes++; + } else { + s1 |= style & 0xff; // allow them to pass any low 8 bits for style + } + if ((style || n) && !width) width = 1; // fix cards that do nothing for 0? + static LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()? + HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0); + if (!newpen) { + // CET - FIXME - remove this debug fprintf()? + fprintf(stderr, "fl_line_style(): Could not create GDI pen object.\n"); + return; + } + HPEN oldpen = (HPEN)SelectObject(fl_gc, newpen); + DeleteObject(oldpen); + fl_current_xmap.pen = newpen; +#else + int ndashes = dashes ? strlen(dashes) : 0; + // emulate the WIN32 dash patterns on X + char buf[7]; + if (!ndashes && (style&0xff)) { + int w = width ? width : 1; + char dash, dot, gap; + // adjust lengths to account for cap: + if (style & 0x200) { + dash = char(2*w); + dot = 1; // unfortunately 0 does not work + gap = char(2*w-1); + } else { + dash = char(3*w); + dot = gap = char(w); + } + char* p = dashes = buf; + switch (style & 0xff) { + case FL_DASH: *p++ = dash; *p++ = gap; break; + case FL_DOT: *p++ = dot; *p++ = gap; break; + case FL_DASHDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; break; + case FL_DASHDOTDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; *p++ = dot; *p++ = gap; break; + } + ndashes = p-buf; + } + static int Cap[4] = {CapButt, CapButt, CapRound, CapProjecting}; + static int Join[4] = {JoinMiter, JoinMiter, JoinRound, JoinBevel}; + XSetLineAttributes(fl_display, fl_gc, width, + ndashes ? LineOnOffDash : LineSolid, + Cap[(style>>8)&3], Join[(style>>12)&3]); + if (ndashes) XSetDashes(fl_display, fl_gc, 0, dashes, ndashes); +#endif +} |
