diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2004-08-31 00:27:40 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2004-08-31 00:27:40 +0000 |
| commit | 57193e52c0ea34a6af53289b72b232e226466bc1 (patch) | |
| tree | 01532958535af427ce9d473f2b1b739ab501d5ea /src/fl_line_style.cxx | |
| parent | 62e1ae69768156c1f4db4a7193f74af944ab34f6 (diff) | |
Quartz for FLTK 1.1:
- added pixmap drawing (no masking yet)
- added bitmap drawing
- added line styles (complete)
todo:
- missing refresh (double test, fluid, others)
- missing pixmap mask
- color_chooser has alignment issues
- images scale instead of beeing scissored
- fonts
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3798 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/fl_line_style.cxx')
| -rw-r--r-- | src/fl_line_style.cxx | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/fl_line_style.cxx b/src/fl_line_style.cxx index 39580d0f5..8242c262a 100644 --- a/src/fl_line_style.cxx +++ b/src/fl_line_style.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_line_style.cxx,v 1.3.2.3.2.15 2004/08/25 00:20:27 matthiaswm Exp $" +// "$Id: fl_line_style.cxx,v 1.3.2.3.2.16 2004/08/31 00:27:40 matthiaswm Exp $" // // Line style code for the Fast Light Tool Kit (FLTK). // @@ -29,6 +29,20 @@ #include "flstring.h" #include <stdio.h> +#ifdef __APPLE_QUARTZ__ +static float fl_quartz_line_width_ = 1.0f; +static enum CGLineCap fl_quartz_line_cap_ = kCGLineCapButt; +static enum CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter; +static float *fl_quartz_line_pattern = 0; +static int fl_quartz_line_pattern_size = 0; +void fl_quartz_restore_line_style_() { + CGContextSetLineWidth(fl_gc, fl_quartz_line_width_); + CGContextSetLineCap(fl_gc, fl_quartz_line_cap_); + CGContextSetLineJoin(fl_gc, fl_quartz_line_join_); + CGContextSetLineDash(fl_gc, 0, fl_quartz_line_pattern, fl_quartz_line_pattern_size); +} +#endif + void fl_line_style(int style, int width, char* dashes) { #ifdef WIN32 // According to Bill, the "default" cap and join should be the @@ -69,20 +83,45 @@ void fl_line_style(int style, int width, char* dashes) { if (style > 2) style = 2; PenPat(styles + style); #elif defined(__APPLE_QUARTZ__) -#warning quartz - // QuickDraw supports pen size and pattern, but no arbitrary line styles. - static Pattern styles[] = { - { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }, // FL_SOLID - { { 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f } }, // FL_DASH - { { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 } } // FL_DOT - }; - - if (!width) width = 1; - PenSize(width, width); - - style &= 0xff; - if (style > 2) style = 2; - PenPat(styles + style); + static enum CGLineCap Cap[4] = { kCGLineCapButt, kCGLineCapButt, + kCGLineCapRound, kCGLineCapSquare }; + static enum CGLineJoin Join[4] = { kCGLineJoinMiter, kCGLineJoinMiter, + kCGLineJoinRound, kCGLineJoinBevel }; + if (width<1) width = 1; + fl_quartz_line_width_ = (float)width; + fl_quartz_line_cap_ = Cap[(style>>8)&3]; + fl_quartz_line_join_ = Join[(style>>12)&3]; + char *d = dashes; + static float pattern[16]; + if (d && *d) { + float *p = pattern; + while (*d) { *p++ = (float)*d++; } + fl_quartz_line_pattern = pattern; + fl_quartz_line_pattern_size = d-dashes; + } else if (style & 0xff) { + char dash, dot, gap; + // adjust lengths to account for cap: + if (style & 0x200) { + dash = char(2*width); + dot = 1; + gap = char(2*width-1); + } else { + dash = char(3*width); + dot = gap = char(width); + } + float *p = pattern; + 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; + } + fl_quartz_line_pattern_size = p-pattern; + fl_quartz_line_pattern = pattern; + } else { + fl_quartz_line_pattern = 0; fl_quartz_line_pattern_size = 0; + } + fl_quartz_restore_line_style_(); #else int ndashes = dashes ? strlen(dashes) : 0; // emulate the WIN32 dash patterns on X @@ -119,5 +158,5 @@ void fl_line_style(int style, int width, char* dashes) { // -// End of "$Id: fl_line_style.cxx,v 1.3.2.3.2.15 2004/08/25 00:20:27 matthiaswm Exp $". +// End of "$Id: fl_line_style.cxx,v 1.3.2.3.2.16 2004/08/31 00:27:40 matthiaswm Exp $". // |
