diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2016-01-26 21:01:09 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2016-01-26 21:01:09 +0000 |
| commit | ac275b89bcd8333dd1b05bfc9f6fc0accd8e065d (patch) | |
| tree | e4fcd53eee80ae26f2e4500b99bbee9f211a2bd2 /src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx | |
| parent | f1a2730855e544fbc0973aba7e76f18d377a893c (diff) | |
Moved Quartz graphics driver to the new naming scheme
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11057 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx')
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx new file mode 100644 index 000000000..a70a067b6 --- /dev/null +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx @@ -0,0 +1,98 @@ +// +// "$Id$" +// +// Line style code for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2016 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#ifndef FL_CFG_GFX_QUARTZ_LINE_STYLE_CXX +#define FL_CFG_GFX_QUARTZ_LINE_STYLE_CXX + +/** + \file quartz_line_style.cxx + \brief Line style drawing utility hiding different platforms. +*/ + +#include "Fl_Quartz_Graphics_Driver.h" + +float fl_quartz_line_width_ = 1.0f; +static /*enum*/ CGLineCap fl_quartz_line_cap_ = kCGLineCapButt; +static /*enum*/ CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter; +static CGFloat *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); +} + +void Fl_Quartz_Graphics_Driver::line_style(int style, int width, char* dashes) { + + // save line width in global variable for X11 clipping + if (width == 0) fl_line_width_ = 1; + else fl_line_width_ = width>0 ? width : -width; + + 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]; + // when printing kCGLineCapSquare seems better for solid lines + if ( Fl_Surface_Device::surface() != Fl_Display_Device::display_device() && style == FL_SOLID && dashes == NULL ) { + fl_quartz_line_cap_ = kCGLineCapSquare; + } + fl_quartz_line_join_ = Join[(style>>12)&3]; + char *d = dashes; + static CGFloat pattern[16]; + if (d && *d) { + CGFloat *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); + } + CGFloat *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_(); +} + +#endif // FL_CFG_GFX_QUARTZ_LINE_STYLE_CXX + +// +// End of "$Id$". +// |
