summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-01-23 21:54:30 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-01-23 21:54:30 +0000
commitbe66d89defefff92dbf683558f9a29f0dfd5c05f (patch)
treecb859539a52b2d26b761daccb3d6d08eb5eae567
parent031bc363a02b46274987ed00a742916ac80345a8 (diff)
Added OpenGL support for dotted lines. Active widget now renders focus rectangle correctly.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11039 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Device.H172
-rw-r--r--src/Fl_Gl_Device_Plugin.cxx2
-rw-r--r--src/cfg_gfx/gdi.H2
-rw-r--r--src/cfg_gfx/gdi_line_style.cxx65
-rw-r--r--src/cfg_gfx/opengl.H10
-rw-r--r--src/cfg_gfx/opengl_line_style.cxx70
-rw-r--r--src/cfg_gfx/quartz.H2
-rw-r--r--src/cfg_gfx/quartz_line_style.cxx98
-rw-r--r--src/cfg_gfx/xlib.H2
-rw-r--r--src/cfg_gfx/xlib_line_style.cxx71
-rw-r--r--src/fl_line_style.cxx153
11 files changed, 403 insertions, 244 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H
index 8bf619ada..3e88db3e8 100644
--- a/FL/Fl_Device.H
+++ b/FL/Fl_Device.H
@@ -162,7 +162,6 @@ protected:
friend class Fl_Pixmap;
friend class Fl_Bitmap;
friend class Fl_RGB_Image;
- friend void fl_line_style(int style, int width, char* dashes);
friend void fl_draw(const char *str, int n, int x, int y);
#ifdef __APPLE__
friend void fl_draw(const char *str, int n, float x, float y);
@@ -178,7 +177,6 @@ protected:
friend void fl_font(Fl_Font face, Fl_Fontsize size);
friend void fl_color(Fl_Color c);
friend void fl_color(uchar r, uchar g, uchar b);
- friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
@@ -190,8 +188,6 @@ protected:
/** \brief The constructor. */
Fl_Graphics_Driver();
- /** \brief see fl_line_style(int style, int width, char* dashes). */
- virtual void line_style(int style, int width=0, char* dashes=0);
/** \brief see fl_draw(const char *str, int n, int x, int y). */
virtual void draw(const char *str, int n, int x, int y) {}
#ifdef __APPLE__
@@ -211,8 +207,6 @@ protected:
virtual void color(Fl_Color c) {color_ = c;}
/** \brief see fl_color(uchar r, uchar g, uchar b). */
virtual void color(uchar r, uchar g, uchar b) {}
- /** \brief see fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3). */
- virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
// Images
@@ -281,116 +275,72 @@ public:
virtual ~Fl_Graphics_Driver() { if (p) free(p); }
// === all code below in this class has been to the reorganisation FL_PORTING process
-protected:
+public:
// --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/xxx_rect.cxx
- friend void fl_point(int x, int y);
- virtual void point(int x, int y) = 0;
- friend void fl_rect(int x, int y, int w, int h);
- virtual void rect(int x, int y, int w, int h) = 0;
- friend void fl_rectf(int x, int y, int w, int h);
- virtual void rectf(int x, int y, int w, int h) = 0;
- friend void fl_line(int x, int y, int x1, int y1);
- virtual void line(int x, int y, int x1, int y1) = 0;
- friend void fl_line(int x, int y, int x1, int y1, int x2, int y2);
- virtual void line(int x, int y, int x1, int y1, int x2, int y2) = 0;
- friend void fl_xyline(int x, int y, int x1);
- virtual void xyline(int x, int y, int x1) = 0;
- friend void fl_xyline(int x, int y, int x1, int y2);
- virtual void xyline(int x, int y, int x1, int y2) = 0;
- friend void fl_xyline(int x, int y, int x1, int y2, int x3);
- virtual void xyline(int x, int y, int x1, int y2, int x3) = 0;
- friend void fl_yxline(int x, int y, int y1);
- virtual void yxline(int x, int y, int y1) = 0;
- friend void fl_yxline(int x, int y, int y1, int x2);
- virtual void yxline(int x, int y, int y1, int x2) = 0;
- friend void fl_yxline(int x, int y, int y1, int x2, int y3);
- virtual void yxline(int x, int y, int y1, int x2, int y3) = 0;
- friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2);
- virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2) = 0;
- friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
- virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) = 0;
- friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2);
- virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2) = 0;
- friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
- virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) = 0;
+ virtual void point(int x, int y) = 0;
+ virtual void rect(int x, int y, int w, int h) = 0;
+ virtual void rectf(int x, int y, int w, int h) = 0;
+ virtual void line(int x, int y, int x1, int y1) = 0;
+ virtual void line(int x, int y, int x1, int y1, int x2, int y2) = 0;
+ virtual void xyline(int x, int y, int x1) = 0;
+ virtual void xyline(int x, int y, int x1, int y2) = 0;
+ virtual void xyline(int x, int y, int x1, int y2, int x3) = 0;
+ virtual void yxline(int x, int y, int y1) = 0;
+ virtual void yxline(int x, int y, int y1, int x2) = 0;
+ virtual void yxline(int x, int y, int y1, int x2, int y3) = 0;
+ virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2) = 0;
+ virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) = 0;
+ virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2) = 0;
+ virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) = 0;
// --- clipping
- friend void fl_push_clip(int x, int y, int w, int h);
- virtual void push_clip(int x, int y, int w, int h) = 0;
- friend int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
- virtual int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) = 0;
- friend int fl_not_clipped(int x, int y, int w, int h);
- virtual int not_clipped(int x, int y, int w, int h) = 0;
- friend void fl_push_no_clip();
- virtual void push_no_clip() = 0;
- friend void fl_pop_clip();
- virtual void pop_clip() = 0;
- friend Fl_Region fl_clip_region();
- virtual Fl_Region clip_region(); // has default implementation
- friend void fl_clip_region(Fl_Region r);
- virtual void clip_region(Fl_Region r); // has default implementation
- friend void fl_restore_clip();
- virtual void restore_clip();
+ virtual void push_clip(int x, int y, int w, int h) = 0;
+ virtual int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H) = 0;
+ virtual int not_clipped(int x, int y, int w, int h) = 0;
+ virtual void push_no_clip() = 0;
+ virtual void pop_clip() = 0;
+ virtual Fl_Region clip_region(); // has default implementation
+ virtual void clip_region(Fl_Region r); // has default implementation
+ virtual void restore_clip();
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
- virtual void transformed_vertex0(COORD_T x, COORD_T y);
- virtual void fixloop();
- friend void fl_push_matrix();
- virtual void push_matrix();
- friend void fl_pop_matrix();
- virtual void pop_matrix();
- friend void fl_mult_matrix(double a, double b, double c, double d, double x, double y);
- virtual void mult_matrix(double a, double b, double c, double d, double x, double y);
- friend void fl_rotate(double d);
- virtual void rotate(double d);
- friend void fl_scale(double x, double y);
- virtual void scale(double x, double y);
- friend void fl_scale(double x);
- virtual void scale(double x);
- friend void fl_translate(double x, double y);
- virtual void translate(double x,double y);
- friend void fl_begin_points();
- virtual void begin_points();
- friend void fl_begin_line();
- virtual void begin_line();
- friend void fl_begin_loop();
- virtual void begin_loop();
- friend void fl_begin_polygon();
- virtual void begin_polygon();
- friend void fl_begin_complex_polygon();
- virtual void begin_complex_polygon() = 0;
- friend double fl_transform_x(double x, double y);
- virtual double transform_x(double x, double y);
- friend double fl_transform_y(double x, double y);
- virtual double transform_y(double x, double y);
- friend double fl_transform_dx(double x, double y);
- virtual double transform_dx(double x, double y);
- friend double fl_transform_dy(double x, double y);
- virtual double transform_dy(double x, double y);
- friend void fl_transformed_vertex(double xf, double yf);
- virtual void transformed_vertex(double xf, double yf) = 0;
- friend void fl_vertex(double x, double y);
- virtual void vertex(double x, double y) = 0;
- friend void fl_end_points();
- virtual void end_points() = 0;
- friend void fl_end_line();
- virtual void end_line() = 0;
- friend void fl_end_loop();
- virtual void end_loop() = 0;
- friend void fl_end_polygon();
- virtual void end_polygon() = 0;
- friend void fl_end_complex_polygon();
- virtual void end_complex_polygon() = 0;
- friend void fl_gap();
- virtual void gap() = 0;
- friend void fl_circle(double x, double y, double r);
- virtual void circle(double x, double y, double r) = 0;
+ virtual void push_matrix();
+ virtual void pop_matrix();
+ virtual void mult_matrix(double a, double b, double c, double d, double x, double y);
+ virtual void rotate(double d);
+ virtual void scale(double x, double y);
+ virtual void scale(double x);
+ virtual void translate(double x,double y);
+ virtual void begin_points();
+ virtual void begin_line();
+ virtual void begin_loop();
+ virtual void begin_polygon();
+ virtual void begin_complex_polygon() = 0;
+ virtual double transform_x(double x, double y);
+ virtual double transform_y(double x, double y);
+ virtual double transform_dx(double x, double y);
+ virtual double transform_dy(double x, double y);
+ virtual void transformed_vertex(double xf, double yf) = 0;
+ virtual void vertex(double x, double y) = 0;
+ virtual void end_points() = 0;
+ virtual void end_line() = 0;
+ virtual void end_loop() = 0;
+ virtual void end_polygon() = 0;
+ virtual void end_complex_polygon() = 0;
+ virtual void gap() = 0;
+ virtual void circle(double x, double y, double r) = 0;
// --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed
- friend void fl_arc(double x, double y, double r, double start, double end);
- virtual void arc(double x, double y, double r, double start, double end);
+ virtual void arc(double x, double y, double r, double start, double end);
// --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx
- friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
- virtual void arc(int x, int y, int w, int h, double a1, double a2) = 0;
- friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
- virtual void pie(int x, int y, int w, int h, double a1, double a2) = 0;
+ virtual void arc(int x, int y, int w, int h, double a1, double a2) = 0;
+ virtual void pie(int x, int y, int w, int h, double a1, double a2) = 0;
+ // --- implementation is in src/fl_curve.cxx which includes src/cfg_gfx/xxx_curve.cxx if needed
+ virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
+ // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
+ virtual void line_style(int style, int width=0, char* dashes=0) = 0;
+
+protected:
+ // --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
+ virtual void transformed_vertex0(COORD_T x, COORD_T y);
+ virtual void fixloop();
};
diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx
index 89a802343..3066a70db 100644
--- a/src/Fl_Gl_Device_Plugin.cxx
+++ b/src/Fl_Gl_Device_Plugin.cxx
@@ -56,7 +56,7 @@ const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device";
#include "cfg_gfx/opengl_rect.cxx"
#include "cfg_gfx/opengl_vertex.cxx"
#include "cfg_gfx/opengl_arci.cxx"
-
+#include "cfg_gfx/opengl_line_style.cxx"
#if defined(__APPLE__)
diff --git a/src/cfg_gfx/gdi.H b/src/cfg_gfx/gdi.H
index 9fe5ab0bc..5fe4ca89b 100644
--- a/src/cfg_gfx/gdi.H
+++ b/src/cfg_gfx/gdi.H
@@ -99,6 +99,8 @@ protected:
// --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx
void arc(int x, int y, int w, int h, double a1, double a2);
void pie(int x, int y, int w, int h, double a1, double a2);
+ // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
+ void line_style(int style, int width=0, char* dashes=0);
};
diff --git a/src/cfg_gfx/gdi_line_style.cxx b/src/cfg_gfx/gdi_line_style.cxx
new file mode 100644
index 000000000..a3ba0a71a
--- /dev/null
+++ b/src/cfg_gfx/gdi_line_style.cxx
@@ -0,0 +1,65 @@
+//
+// "$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_GDI_LINE_STYLE_CXX
+#define FL_CFG_GFX_GDI_LINE_STYLE_CXX
+
+/**
+ \file gdi_line_style.cxx
+ \brief Line style drawing utility hiding different platforms.
+*/
+
+#include "gdi.H"
+
+void Fl_GDI_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;
+
+ // According to Bill, the "default" cap and join should be the
+ // "fastest" mode supported for the platform. I don't know why
+ // they should be different (same graphics cards, etc., right?) MRS
+ static DWORD Cap[4]= {PS_ENDCAP_FLAT, 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?
+ LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()?
+ HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0);
+ if (!newpen) {
+ Fl::error("fl_line_style(): Could not create GDI pen object.");
+ return;
+ }
+ HPEN oldpen = (HPEN)SelectObject(fl_gc, newpen);
+ DeleteObject(oldpen);
+ DeleteObject(fl_current_xmap->pen);
+ fl_current_xmap->pen = newpen;
+}
+
+#endif // FL_CFG_GFX_GDI_LINE_STYLE_CXX
+
+//
+// End of "$Id$".
+//
diff --git a/src/cfg_gfx/opengl.H b/src/cfg_gfx/opengl.H
index a741416f7..b8dd2bb86 100644
--- a/src/cfg_gfx/opengl.H
+++ b/src/cfg_gfx/opengl.H
@@ -62,14 +62,6 @@ public:
void pop_clip();
void restore_clip();
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
- // void push_matrix();
- // void pop_matrix();
- // void mult_matrix(double a, double b, double c, double d, double x, double y);
- // void rotate(double d);
- // double transform_x(double x, double y);
- // double transform_y(double x, double y);
- // double transform_dx(double x, double y);
- // double transform_dy(double x, double y);
void transformed_vertex0(COORD_T x, COORD_T y);
void transformed_vertex(double xf, double yf);
void vertex(double x, double y);
@@ -91,6 +83,8 @@ public:
// --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx
void arc(int x, int y, int w, int h, double a1, double a2);
void pie(int x, int y, int w, int h, double a1, double a2);
+ // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
+ void line_style(int style, int width=0, char* dashes=0);
};
diff --git a/src/cfg_gfx/opengl_line_style.cxx b/src/cfg_gfx/opengl_line_style.cxx
new file mode 100644
index 000000000..798e6af88
--- /dev/null
+++ b/src/cfg_gfx/opengl_line_style.cxx
@@ -0,0 +1,70 @@
+//
+// "$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_OPENGL_LINE_STYLE_CXX
+#define FL_CFG_GFX_OPENGL_LINE_STYLE_CXX
+
+/**
+ \file opengl_line_style.cxx
+ \brief Line style drawing utility hiding different platforms.
+*/
+
+#include "opengl.H"
+#include <FL/gl.H>
+
+extern int fl_line_width_;
+
+// OpenGL implementation does not support custom patterns
+// OpenGL implementation does not support cap and join types
+
+void Fl_OpenGL_Graphics_Driver::line_style(int style, int width, char* dashes) {
+
+ // save line width in global variable for X11 clipping
+ // FIXME: what does this code do?
+ if (width == 0) fl_line_width_ = 1;
+ else fl_line_width_ = width>0 ? width : -width;
+
+ if (width<1) width = 1;
+
+ if (style==FL_SOLID) {
+ glLineStipple(1, 0xFFFF);
+ glDisable(GL_LINE_STIPPLE);
+ } else {
+ switch (style) {
+ case FL_DASH:
+ glLineStipple(width, 0x0F0F); // ....****....****
+ break;
+ case FL_DOT:
+ glLineStipple(width, 0x5555); // .*.*.*.*.*.*.*.*
+ break;
+ case FL_DASHDOT:
+ glLineStipple(width, 0x2727); // ..*..***..*..***
+ break;
+ case FL_DASHDOTDOT:
+ glLineStipple(width, 0x5757); // .*.*.***.*.*.***
+ break;
+ }
+ glEnable(GL_LINE_STIPPLE);
+ }
+}
+
+#endif // FL_CFG_GFX_OPENGL_LINE_STYLE_CXX
+
+//
+// End of "$Id$".
+//
diff --git a/src/cfg_gfx/quartz.H b/src/cfg_gfx/quartz.H
index 584016488..33ef68086 100644
--- a/src/cfg_gfx/quartz.H
+++ b/src/cfg_gfx/quartz.H
@@ -109,6 +109,8 @@ protected:
// --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx
void arc(int x, int y, int w, int h, double a1, double a2);
void pie(int x, int y, int w, int h, double a1, double a2);
+ // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
+ void line_style(int style, int width=0, char* dashes=0);
};
diff --git a/src/cfg_gfx/quartz_line_style.cxx b/src/cfg_gfx/quartz_line_style.cxx
new file mode 100644
index 000000000..8a43180e9
--- /dev/null
+++ b/src/cfg_gfx/quartz_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 "quartz.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$".
+//
diff --git a/src/cfg_gfx/xlib.H b/src/cfg_gfx/xlib.H
index d184d617c..460e02e10 100644
--- a/src/cfg_gfx/xlib.H
+++ b/src/cfg_gfx/xlib.H
@@ -98,6 +98,8 @@ protected:
// --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx
void arc(int x, int y, int w, int h, double a1, double a2);
void pie(int x, int y, int w, int h, double a1, double a2);
+ // --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
+ void line_style(int style, int width=0, char* dashes=0);
};
diff --git a/src/cfg_gfx/xlib_line_style.cxx b/src/cfg_gfx/xlib_line_style.cxx
new file mode 100644
index 000000000..55e759a61
--- /dev/null
+++ b/src/cfg_gfx/xlib_line_style.cxx
@@ -0,0 +1,71 @@
+//
+// "$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_XLIB_LINE_STYLE_CXX
+#define FL_CFG_GFX_XLIB_LINE_STYLE_CXX
+
+/**
+ \file xlib_line_style.cxx
+ \brief Line style drawing utility hiding different platforms.
+*/
+
+#include "xlib.H"
+
+void Fl_Xlib_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;
+
+ 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 // FL_CFG_GFX_XLIB_LINE_STYLE_CXX
+
+//
+// End of "$Id$".
+//
diff --git a/src/fl_line_style.cxx b/src/fl_line_style.cxx
index aae740e4f..e07add50b 100644
--- a/src/fl_line_style.cxx
+++ b/src/fl_line_style.cxx
@@ -21,6 +21,7 @@
\brief Line style drawing utility hiding different platforms.
*/
+#include "config_lib.h"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
@@ -33,135 +34,39 @@
// FIXME: this would probably better be in class Fl::
int fl_line_width_ = 0;
-#ifdef __APPLE_QUARTZ__
-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);
-}
+
+// -----------------------------------------------------------------------------
+
+
+#ifdef FL_CFG_GFX_QUARTZ
+
+# include "cfg_gfx/quartz_line_style.cxx"
+
+#endif
+
+
+// -----------------------------------------------------------------------------
+
+
+#ifdef FL_CFG_GFX_GDI
+
+# include "cfg_gfx/gdi_line_style.cxx"
+
#endif
-void Fl_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;
-
-#if defined(USE_X11)
- 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);
-#elif defined(WIN32)
- // According to Bill, the "default" cap and join should be the
- // "fastest" mode supported for the platform. I don't know why
- // they should be different (same graphics cards, etc., right?) MRS
- static DWORD Cap[4]= {PS_ENDCAP_FLAT, 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?
- LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()?
- HPEN newpen = ExtCreatePen(s1, width, &penbrush, n, n ? a : 0);
- if (!newpen) {
- Fl::error("fl_line_style(): Could not create GDI pen object.");
- return;
- }
- HPEN oldpen = (HPEN)SelectObject(fl_gc, newpen);
- DeleteObject(oldpen);
- DeleteObject(fl_current_xmap->pen);
- fl_current_xmap->pen = newpen;
-#elif defined(__APPLE_QUARTZ__)
- 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_();
-#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: implement line styles here"
-#else
-# error unsupported platform
+
+// -----------------------------------------------------------------------------
+
+
+#ifdef FL_CFG_GFX_XLIB
+
+# include "cfg_gfx/xlib_line_style.cxx"
+
#endif
-}
+// -----------------------------------------------------------------------------
+
//
// End of "$Id$".
//