mirror of
https://github.com/fltk/fltk.git
synced 2026-06-04 15:32:12 +08:00
Hiding fl_vertex form public view
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11031 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+49
-70
@@ -145,9 +145,7 @@ protected:
|
||||
// not needed in X11
|
||||
#endif
|
||||
Fl_Font_Descriptor *font_descriptor_;
|
||||
void transformed_vertex0(COORD_T x, COORD_T y);
|
||||
void fixloop();
|
||||
|
||||
|
||||
protected:
|
||||
#ifndef FL_DOXYGEN
|
||||
enum {LINE, LOOP, POLYGON, POINT_};
|
||||
@@ -180,35 +178,13 @@ 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_begin_points();
|
||||
friend void fl_begin_line();
|
||||
friend void fl_begin_loop();
|
||||
friend void fl_begin_polygon();
|
||||
friend void fl_vertex(double x, double y);
|
||||
friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
|
||||
friend void fl_circle(double x, double y, double r);
|
||||
friend void fl_arc(double x, double y, double r, double start, double end);
|
||||
friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
|
||||
friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
|
||||
friend void fl_end_points();
|
||||
friend void fl_end_line();
|
||||
friend void fl_end_loop();
|
||||
friend void fl_end_polygon();
|
||||
friend void fl_transformed_vertex(double xf, double yf);
|
||||
friend void fl_begin_complex_polygon();
|
||||
friend void fl_gap();
|
||||
friend void fl_end_complex_polygon();
|
||||
friend void fl_push_matrix();
|
||||
friend void fl_pop_matrix();
|
||||
friend void fl_mult_matrix(double a, double b, double c, double d, double x, double y);
|
||||
friend void fl_scale(double x, double y);
|
||||
friend void fl_scale(double x);
|
||||
friend void fl_translate(double x, double y);
|
||||
friend void fl_rotate(double d);
|
||||
friend double fl_transform_x(double x, double y);
|
||||
friend double fl_transform_y(double x, double y);
|
||||
friend double fl_transform_dx(double x, double y);
|
||||
friend double fl_transform_dy(double x, double y);
|
||||
|
||||
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);
|
||||
@@ -241,65 +217,21 @@ 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_begin_points(). */
|
||||
virtual void begin_points();
|
||||
/** \brief see fl_begin_line(). */
|
||||
virtual void begin_line();
|
||||
/** \brief see fl_begin_loop(). */
|
||||
virtual void begin_loop();
|
||||
/** \brief see fl_begin_polygon(). */
|
||||
virtual void begin_polygon();
|
||||
/** \brief see fl_vertex(double x, double y). */
|
||||
virtual void vertex(double x, double y);
|
||||
/** \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);
|
||||
/** \brief see fl_circle(double x, double y, double r). */
|
||||
virtual void circle(double x, double y, double r);
|
||||
/** \brief see 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);
|
||||
/** \brief see 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);
|
||||
/** \brief see 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);
|
||||
/** \brief see fl_end_points(). */
|
||||
virtual void end_points();
|
||||
/** \brief see fl_end_line(). */
|
||||
virtual void end_line();
|
||||
/** \brief see fl_end_loop(). */
|
||||
virtual void end_loop();
|
||||
/** \brief see fl_end_polygon(). */
|
||||
virtual void end_polygon();
|
||||
/** \brief see fl_begin_complex_polygon(). */
|
||||
virtual void begin_complex_polygon();
|
||||
/** \brief see fl_gap(). */
|
||||
virtual void gap();
|
||||
/** \brief see fl_end_complex_polygon(). */
|
||||
virtual void end_complex_polygon();
|
||||
/** \brief see fl_transformed_vertex(double xf, double yf). */
|
||||
virtual void transformed_vertex(double xf, double yf);
|
||||
|
||||
/** \brief see fl_push_matrix(). */
|
||||
void push_matrix();
|
||||
/** \brief see fl_pop_matrix(). */
|
||||
void pop_matrix();
|
||||
/** \brief see fl_mult_matrix(double a, double b, double c, double d, double x, double y). */
|
||||
void mult_matrix(double a, double b, double c, double d, double x, double y);
|
||||
/** \brief see fl_scale(double x, double y). */
|
||||
inline void scale(double x, double y) { mult_matrix(x,0,0,y,0,0); }
|
||||
/** \brief see fl_scale(double x). */
|
||||
inline void scale(double x) { mult_matrix(x,0,0,x,0,0); }
|
||||
/** \brief see fl_translate(double x, double y). */
|
||||
inline void translate(double x,double y) { mult_matrix(1,0,0,1,x,y); }
|
||||
/** \brief see fl_rotate(double d). */
|
||||
void rotate(double d);
|
||||
/** \brief see fl_transform_x(double x, double y). */
|
||||
double transform_x(double x, double y);
|
||||
/** \brief see fl_transform_y(double x, double y). */
|
||||
double transform_y(double x, double y);
|
||||
/** \brief see fl_transform_dx(double x, double y). */
|
||||
double transform_dx(double x, double y);
|
||||
/** \brief see fl_transform_dy(double x, double y). */
|
||||
double transform_dy(double x, double y);
|
||||
|
||||
// Images
|
||||
/** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
|
||||
@@ -368,7 +300,7 @@ public:
|
||||
|
||||
// === all code below in this class has been to the reorganisation FL_PORTING process
|
||||
protected:
|
||||
// --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/quartz_rect.cxx
|
||||
// --- 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);
|
||||
@@ -416,6 +348,53 @@ protected:
|
||||
virtual void clip_region(Fl_Region r); // has default implementation
|
||||
friend void fl_restore_clip();
|
||||
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_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();
|
||||
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);
|
||||
friend void fl_vertex(double x, double y);
|
||||
virtual void vertex(double x, double y);
|
||||
friend void fl_end_points();
|
||||
virtual void end_points();
|
||||
friend void fl_end_line();
|
||||
virtual void end_line();
|
||||
friend void fl_end_loop();
|
||||
virtual void end_loop();
|
||||
friend void fl_end_polygon();
|
||||
virtual void end_polygon();
|
||||
friend void fl_end_complex_polygon();
|
||||
virtual void end_complex_polygon();
|
||||
friend void fl_gap();
|
||||
virtual void gap();
|
||||
friend void fl_circle(double x, double y, double r);
|
||||
virtual void circle(double x, double y, double r);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Portable drawing routines 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_VERTEX_CXX
|
||||
#define FL_CFG_GFX_GDI_VERTEX_CXX
|
||||
|
||||
/**
|
||||
\file gdi_vertex.cxx
|
||||
\brief Portable drawing code for drawing arbitrary shapes with
|
||||
simple 2D transformations, implemented for MSWindows GDI.
|
||||
*/
|
||||
|
||||
#include "gdi.H"
|
||||
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/x.H>
|
||||
#include <FL/math.h>
|
||||
|
||||
|
||||
void Fl_GDI_Graphics_Driver::transformed_vertex(double xf, double yf) {
|
||||
transformed_vertex0(COORD_T(rint(xf)), COORD_T(rint(yf)));
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::vertex(double x,double y) {
|
||||
transformed_vertex0(COORD_T(x*m.a + y*m.c + m.x), COORD_T(x*m.b + y*m.d + m.y));
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::end_points() {
|
||||
for (int i=0; i<n; i++) SetPixel(fl_gc, p[i].x, p[i].y, fl_RGB());
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::end_line() {
|
||||
if (n < 2) {
|
||||
end_points();
|
||||
return;
|
||||
}
|
||||
if (n>1) Polyline(fl_gc, p, n);
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::fixloop() { // remove equal points from closed path
|
||||
while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::end_loop() {
|
||||
fixloop();
|
||||
if (n>2) transformed_vertex((COORD_T)p[0].x, (COORD_T)p[0].y);
|
||||
end_line();
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::end_polygon() {
|
||||
fixloop();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n>2) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
Polygon(fl_gc, p, n);
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::begin_complex_polygon() {
|
||||
begin_polygon();
|
||||
gap_ = 0;
|
||||
numcount = 0;
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::gap() {
|
||||
while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--;
|
||||
if (n > gap_+2) {
|
||||
transformed_vertex((COORD_T)p[gap_].x, (COORD_T)p[gap_].y);
|
||||
counts[numcount++] = n-gap_;
|
||||
gap_ = n;
|
||||
} else {
|
||||
n = gap_;
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_GDI_Graphics_Driver::end_complex_polygon() {
|
||||
gap();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n>2) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
PolyPolygon(fl_gc, p, counts, numcount);
|
||||
}
|
||||
}
|
||||
|
||||
// shortcut the closed circles so they use XDrawArc:
|
||||
// warning: these do not draw rotated ellipses correctly!
|
||||
// See fl_arc.c for portable version.
|
||||
|
||||
void Fl_GDI_Graphics_Driver::circle(double x, double y,double r) {
|
||||
double xt = transform_x(x,y);
|
||||
double yt = transform_y(x,y);
|
||||
double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a));
|
||||
double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d));
|
||||
int llx = (int)rint(xt-rx);
|
||||
int w = (int)rint(xt+rx)-llx;
|
||||
int lly = (int)rint(yt-ry);
|
||||
int h = (int)rint(yt+ry)-lly;
|
||||
|
||||
if (what==POLYGON) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
Pie(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
|
||||
} else
|
||||
Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
|
||||
}
|
||||
|
||||
#endif FL_CFG_GFX_GDI_VERTEX_CXX
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
@@ -61,6 +61,31 @@ public:
|
||||
void push_no_clip();
|
||||
void pop_clip();
|
||||
void restore_clip();
|
||||
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
|
||||
// void transformed_vertex0(COORD_T x, COORD_T y);
|
||||
// void fixloop();
|
||||
// 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);
|
||||
// void begin_points();
|
||||
// void begin_line();
|
||||
// void begin_loop();
|
||||
// void begin_polygon();
|
||||
// void begin_complex_polygon();
|
||||
// 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_vertex(double xf, double yf);
|
||||
// void vertex(double x, double y);
|
||||
// void end_points();
|
||||
// void end_line();
|
||||
// void end_loop();
|
||||
// void end_polygon();
|
||||
// void end_complex_polygon();
|
||||
// void gap();
|
||||
// void circle(double x, double y, double r);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -93,6 +93,18 @@ protected:
|
||||
void push_no_clip();
|
||||
void pop_clip();
|
||||
void restore_clip();
|
||||
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
|
||||
void fixloop();
|
||||
void begin_complex_polygon();
|
||||
void transformed_vertex(double xf, double yf);
|
||||
void vertex(double x, double y);
|
||||
void end_points();
|
||||
void end_line();
|
||||
void end_loop();
|
||||
void end_polygon();
|
||||
void end_complex_polygon();
|
||||
void gap();
|
||||
void circle(double x, double y, double r);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Portable drawing routines 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_VERTEX_CXX
|
||||
#define FL_CFG_GFX_QUARTZ_VERTEX_CXX
|
||||
|
||||
/**
|
||||
\file quartz_vertex.cxx
|
||||
\brief Portable drawing code for drawing arbitrary shapes with
|
||||
simple 2D transformations, implemented for OS X Quartz.
|
||||
*/
|
||||
|
||||
#include "quartz.H"
|
||||
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/x.H>
|
||||
#include <FL/math.h>
|
||||
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::transformed_vertex(double xf, double yf) {
|
||||
transformed_vertex0(COORD_T(xf), COORD_T(yf));
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::vertex(double x,double y) {
|
||||
transformed_vertex0(COORD_T(x*m.a + y*m.c + m.x), COORD_T(x*m.b + y*m.d + m.y));
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::end_points() {
|
||||
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
|
||||
for (int i=0; i<n; i++) {
|
||||
CGContextMoveToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextStrokePath(fl_gc);
|
||||
}
|
||||
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::end_line() {
|
||||
if (n < 2) {
|
||||
end_points();
|
||||
return;
|
||||
}
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextStrokePath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::fixloop() { // remove equal points from closed path
|
||||
while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::end_loop() {
|
||||
fixloop();
|
||||
if (n>2) transformed_vertex((COORD_T)p[0].x, (COORD_T)p[0].y);
|
||||
end_line();
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::end_polygon() {
|
||||
fixloop();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextClosePath(fl_gc);
|
||||
CGContextFillPath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::begin_complex_polygon() {
|
||||
begin_polygon();
|
||||
gap_ = 0;
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::gap() {
|
||||
while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--;
|
||||
if (n > gap_+2) {
|
||||
transformed_vertex((COORD_T)p[gap_].x, (COORD_T)p[gap_].y);
|
||||
gap_ = n;
|
||||
} else {
|
||||
n = gap_;
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::end_complex_polygon() {
|
||||
gap();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextClosePath(fl_gc);
|
||||
CGContextFillPath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
}
|
||||
|
||||
void Fl_Quartz_Graphics_Driver::circle(double x, double y,double r) {
|
||||
double xt = transform_x(x,y);
|
||||
double yt = transform_y(x,y);
|
||||
double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a));
|
||||
double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d));
|
||||
int llx = (int)rint(xt-rx);
|
||||
int w = (int)rint(xt+rx)-llx;
|
||||
int lly = (int)rint(yt-ry);
|
||||
int h = (int)rint(yt+ry)-lly;
|
||||
|
||||
// Quartz warning: circle won't scale to current matrix!
|
||||
// Last argument must be 0 (counter-clockwise) or it draws nothing under __LP64__ !!!!
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 0);
|
||||
(what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
}
|
||||
|
||||
#endif // FL_CFG_GFX_QUARTZ_VERTEX_CXX
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
@@ -82,6 +82,18 @@ protected:
|
||||
void push_no_clip();
|
||||
void pop_clip();
|
||||
void restore_clip();
|
||||
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
|
||||
void fixloop();
|
||||
void begin_complex_polygon();
|
||||
void transformed_vertex(double xf, double yf);
|
||||
void vertex(double x, double y);
|
||||
void end_points();
|
||||
void end_line();
|
||||
void end_loop();
|
||||
void end_polygon();
|
||||
void end_complex_polygon();
|
||||
void gap();
|
||||
void circle(double x, double y, double r);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Portable drawing routines 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_VERTEX_CXX
|
||||
#define FL_CFG_GFX_XLIB_VERTEX_CXX
|
||||
|
||||
/**
|
||||
\file xlib_vertex.cxx
|
||||
\brief Portable drawing code for drawing arbitrary shapes with
|
||||
simple 2D transformations, implemented for X11 Xlib.
|
||||
*/
|
||||
|
||||
#include "xlib.H"
|
||||
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/x.H>
|
||||
#include <FL/math.h>
|
||||
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::transformed_vertex(double xf, double yf) {
|
||||
transformed_vertex0(COORD_T(rint(xf)), COORD_T(rint(yf)));
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::vertex(double x,double y) {
|
||||
transformed_vertex0(COORD_T(x*m.a + y*m.c + m.x), COORD_T(x*m.b + y*m.d + m.y));
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::end_points() {
|
||||
if (n>1) XDrawPoints(fl_display, fl_window, fl_gc, p, n, 0);
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::end_line() {
|
||||
if (n < 2) {
|
||||
end_points();
|
||||
return;
|
||||
}
|
||||
if (n>1) XDrawLines(fl_display, fl_window, fl_gc, p, n, 0);
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::fixloop() { // remove equal points from closed path
|
||||
while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::end_loop() {
|
||||
fixloop();
|
||||
if (n>2) transformed_vertex((COORD_T)p[0].x, (COORD_T)p[0].y);
|
||||
end_line();
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::end_polygon() {
|
||||
fixloop();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, Convex, 0);
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::begin_complex_polygon() {
|
||||
begin_polygon();
|
||||
gap_ = 0;
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::gap() {
|
||||
while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--;
|
||||
if (n > gap_+2) {
|
||||
transformed_vertex((COORD_T)p[gap_].x, (COORD_T)p[gap_].y);
|
||||
gap_ = n;
|
||||
} else {
|
||||
n = gap_;
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::end_complex_polygon() {
|
||||
gap();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, 0, 0);
|
||||
}
|
||||
|
||||
// shortcut the closed circles so they use XDrawArc:
|
||||
// warning: these do not draw rotated ellipses correctly!
|
||||
// See fl_arc.c for portable version.
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::circle(double x, double y,double r) {
|
||||
double xt = transform_x(x,y);
|
||||
double yt = transform_y(x,y);
|
||||
double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a));
|
||||
double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d));
|
||||
int llx = (int)rint(xt-rx);
|
||||
int w = (int)rint(xt+rx)-llx;
|
||||
int lly = (int)rint(yt-ry);
|
||||
int h = (int)rint(yt+ry)-lly;
|
||||
|
||||
(what == POLYGON ? XFillArc : XDrawArc)
|
||||
(fl_display, fl_window, fl_gc, llx, lly, w, h, 0, 360*64);
|
||||
}
|
||||
|
||||
#endif FL_CFG_GFX_XLIB_VERTEX_CXX
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
+25
-172
@@ -35,6 +35,7 @@
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
#include "config_lib.h"
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/x.H>
|
||||
#include <FL/Fl.H>
|
||||
@@ -106,187 +107,39 @@ void Fl_Graphics_Driver::transformed_vertex0(COORD_T x, COORD_T y) {
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::transformed_vertex(double xf, double yf) {
|
||||
#ifdef __APPLE_QUARTZ__
|
||||
transformed_vertex0(COORD_T(xf), COORD_T(yf));
|
||||
#else
|
||||
transformed_vertex0(COORD_T(rint(xf)), COORD_T(rint(yf)));
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef FL_CFG_GFX_QUARTZ
|
||||
|
||||
# include "cfg_gfx/quartz_vertex.cxx"
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::vertex(double x,double y) {
|
||||
transformed_vertex0(COORD_T(x*m.a + y*m.c + m.x), COORD_T(x*m.b + y*m.d + m.y));
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::end_points() {
|
||||
#if defined(USE_X11)
|
||||
if (n>1) XDrawPoints(fl_display, fl_window, fl_gc, p, n, 0);
|
||||
#elif defined(WIN32)
|
||||
for (int i=0; i<n; i++) SetPixel(fl_gc, p[i].x, p[i].y, fl_RGB());
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
|
||||
for (int i=0; i<n; i++) {
|
||||
CGContextMoveToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextStrokePath(fl_gc);
|
||||
}
|
||||
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement end_points"
|
||||
#else
|
||||
# error unsupported platform
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef FL_CFG_GFX_GDI
|
||||
|
||||
# include "cfg_gfx/gdi_vertex.cxx"
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::end_line() {
|
||||
if (n < 2) {
|
||||
end_points();
|
||||
return;
|
||||
}
|
||||
#if defined(USE_X11)
|
||||
if (n>1) XDrawLines(fl_display, fl_window, fl_gc, p, n, 0);
|
||||
#elif defined(WIN32)
|
||||
if (n>1) Polyline(fl_gc, p, n);
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextStrokePath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement end_line"
|
||||
#else
|
||||
# error unsupported platform
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef FL_CFG_GFX_XLIB
|
||||
|
||||
# include "cfg_gfx/xlib_vertex.cxx"
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::fixloop() { // remove equal points from closed path
|
||||
while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::end_loop() {
|
||||
fixloop();
|
||||
if (n>2) transformed_vertex((COORD_T)p[0].x, (COORD_T)p[0].y);
|
||||
end_line();
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void Fl_Graphics_Driver::end_polygon() {
|
||||
fixloop();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
#if defined(USE_X11)
|
||||
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, Convex, 0);
|
||||
#elif defined(WIN32)
|
||||
if (n>2) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
Polygon(fl_gc, p, n);
|
||||
}
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextClosePath(fl_gc);
|
||||
CGContextFillPath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement end_polygon"
|
||||
#else
|
||||
# error unsupported platform
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::begin_complex_polygon() {
|
||||
begin_polygon();
|
||||
gap_ = 0;
|
||||
#if defined(WIN32)
|
||||
numcount = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::gap() {
|
||||
while (n>gap_+2 && p[n-1].x == p[gap_].x && p[n-1].y == p[gap_].y) n--;
|
||||
if (n > gap_+2) {
|
||||
transformed_vertex((COORD_T)p[gap_].x, (COORD_T)p[gap_].y);
|
||||
#if defined(WIN32)
|
||||
counts[numcount++] = n-gap_;
|
||||
#endif
|
||||
gap_ = n;
|
||||
} else {
|
||||
n = gap_;
|
||||
}
|
||||
}
|
||||
|
||||
void Fl_Graphics_Driver::end_complex_polygon() {
|
||||
gap();
|
||||
if (n < 3) {
|
||||
end_line();
|
||||
return;
|
||||
}
|
||||
#if defined(USE_X11)
|
||||
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, 0, 0);
|
||||
#elif defined(WIN32)
|
||||
if (n>2) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
PolyPolygon(fl_gc, p, counts, numcount);
|
||||
}
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
if (n<=1) return;
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
|
||||
for (int i=1; i<n; i++)
|
||||
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
|
||||
CGContextClosePath(fl_gc);
|
||||
CGContextFillPath(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement end_complex_polygon"
|
||||
#else
|
||||
# error unsupported platform
|
||||
#endif
|
||||
}
|
||||
|
||||
// shortcut the closed circles so they use XDrawArc:
|
||||
// warning: these do not draw rotated ellipses correctly!
|
||||
// See fl_arc.c for portable version.
|
||||
|
||||
void Fl_Graphics_Driver::circle(double x, double y,double r) {
|
||||
double xt = transform_x(x,y);
|
||||
double yt = transform_y(x,y);
|
||||
double rx = r * (m.c ? sqrt(m.a*m.a+m.c*m.c) : fabs(m.a));
|
||||
double ry = r * (m.b ? sqrt(m.b*m.b+m.d*m.d) : fabs(m.d));
|
||||
int llx = (int)rint(xt-rx);
|
||||
int w = (int)rint(xt+rx)-llx;
|
||||
int lly = (int)rint(yt-ry);
|
||||
int h = (int)rint(yt+ry)-lly;
|
||||
|
||||
#if defined(USE_X11)
|
||||
(what == POLYGON ? XFillArc : XDrawArc)
|
||||
(fl_display, fl_window, fl_gc, llx, lly, w, h, 0, 360*64);
|
||||
#elif defined(WIN32)
|
||||
if (what==POLYGON) {
|
||||
SelectObject(fl_gc, fl_brush());
|
||||
Pie(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
|
||||
} else
|
||||
Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
// Quartz warning: circle won't scale to current matrix!
|
||||
// Last argument must be 0 (counter-clockwise) or it draws nothing under __LP64__ !!!!
|
||||
CGContextSetShouldAntialias(fl_gc, true);
|
||||
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 0);
|
||||
(what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
|
||||
CGContextSetShouldAntialias(fl_gc, false);
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement circle"
|
||||
#else
|
||||
# error unsupported platform
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
|
||||
Reference in New Issue
Block a user