|
commit 0623a8d4b9e8a56cc435dc550c6b56fa1a9607e9
Author: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Mon Mar 1 15:10:52 2021 +0100
Commit: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Mon Mar 1 15:11:00 2021 +0100
Remove duplicated code between derived classes of Fl_Graphics_Driver.
FL/Fl_Graphics_Driver.H | 5 ++++-
src/Fl_Graphics_Driver.cxx | 24 ++++++++++++++++----
src/drivers/GDI/Fl_GDI_Graphics_Driver.H | 3 +--
src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H | 1 -
.../OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx | 4 ----
src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H | 14 ------------
src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx | 2 +-
.../Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx | 20 -----------------
src/drivers/SVG/Fl_SVG_File_Surface.cxx | 26 ----------------------
src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 1 -
src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx | 1 -
11 files changed, 26 insertions(+), 75 deletions(-)
diff --git FL/Fl_Graphics_Driver.H FL/Fl_Graphics_Driver.H
index 3bce25f..f3ed53d 100644
--- FL/Fl_Graphics_Driver.H
+++ FL/Fl_Graphics_Driver.H
@@ -173,6 +173,9 @@ protected:
static const int region_stack_max = FL_REGION_STACK_SIZE - 1; ///< For internal use by FLTK
Fl_Region rstack[FL_REGION_STACK_SIZE]; ///< For internal use by FLTK
Fl_Font_Descriptor *font_descriptor_; ///< For internal use by FLTK
+ int p_size;
+ typedef struct { float x; float y; } XPOINT;
+ XPOINT *p;
#ifndef FL_DOXYGEN
enum {LINE, LOOP, POLYGON, POINT_};
inline int vertex_no() { return n; }
@@ -303,6 +306,7 @@ public:
virtual double transform_dx(double x, double y);
virtual double transform_dy(double x, double y);
virtual void transformed_vertex(double xf, double yf);
+ virtual void transformed_vertex0(float x, float y);
virtual void vertex(double x, double y);
virtual void end_points();
virtual void end_line();
@@ -486,7 +490,6 @@ protected:
void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
void transformed_vertex(double xf, double yf);
- virtual void transformed_vertex0(float x, float y);
void vertex(double x, double y);
virtual float override_scale();
virtual void restore_scale(float);
diff --git src/Fl_Graphics_Driver.cxx src/Fl_Graphics_Driver.cxx
index 547526e..be8849d 100644
--- src/Fl_Graphics_Driver.cxx
+++ src/Fl_Graphics_Driver.cxx
@@ -49,6 +49,8 @@ Fl_Graphics_Driver::Fl_Graphics_Driver()
fl_matrix = &m;
font_descriptor_ = NULL;
scale_ = 1;
+ p_size = 0;
+ p = NULL;
};
/** Return the graphics driver used when drawing to the platform's display */
@@ -497,10 +499,14 @@ int Fl_Graphics_Driver::not_clipped(int x, int y, int w, int h) {return 1;}
void Fl_Graphics_Driver::begin_complex_polygon() {}
/** see fl_transformed_vertex() */
-void Fl_Graphics_Driver::transformed_vertex(double xf, double yf) {}
+void Fl_Graphics_Driver::transformed_vertex(double xf, double yf) {
+ transformed_vertex0(float(xf), float(yf));
+}
/** see fl_vertex() */
-void Fl_Graphics_Driver::vertex(double x, double y) {}
+void Fl_Graphics_Driver::vertex(double x, double y) {
+ transformed_vertex(x*m.a + y*m.c + m.x, x*m.b + y*m.d + m.y);
+}
/** see fl_end_points() */
void Fl_Graphics_Driver::end_points() {}
@@ -633,6 +639,18 @@ float Fl_Graphics_Driver::override_scale() { return scale();}
void Fl_Graphics_Driver::restore_scale(float) { }
+void Fl_Graphics_Driver::transformed_vertex0(float x, float y) {
+ if (!n || x != p[n-1].x || y != p[n-1].y) {
+ if (n >= p_size) {
+ p_size = p ? 2*p_size : 16;
+ p = (XPOINT*)realloc((void*)p, p_size*sizeof(*p));
+ }
+ p[n].x = x;
+ p[n].y = y;
+ n++;
+ }
+}
+
/**
\}
\endcond
@@ -980,8 +998,6 @@ void Fl_Scalable_Graphics_Driver::draw_image_mono_unscaled(const uchar* buf, int
void Fl_Scalable_Graphics_Driver::draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D) {}
-void Fl_Scalable_Graphics_Driver::transformed_vertex0(float x, float y) {}
-
float Fl_Scalable_Graphics_Driver::override_scale() {
float s = scale();
if (s != 1.f) {
diff --git src/drivers/GDI/Fl_GDI_Graphics_Driver.H src/drivers/GDI/Fl_GDI_Graphics_Driver.H
index d322bc8..4ec7bce 100644
--- src/drivers/GDI/Fl_GDI_Graphics_Driver.H
+++ src/drivers/GDI/Fl_GDI_Graphics_Driver.H
@@ -49,10 +49,9 @@ protected:
int counts[20];
uchar *mask_bitmap_;
uchar **mask_bitmap() {return &mask_bitmap_;}
- int p_size;
POINT *p;
public:
- Fl_GDI_Graphics_Driver() {mask_bitmap_ = NULL; gc_ = NULL; p_size = 0; p = NULL; depth = -1; origins = NULL;}
+ Fl_GDI_Graphics_Driver() {mask_bitmap_ = NULL; gc_ = NULL; p = NULL; depth = -1; origins = NULL;}
virtual ~Fl_GDI_Graphics_Driver() { if (p) free(p); delete[] origins;}
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
char can_do_alpha_blending();
diff --git src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H
index 46dba53..f240e76 100644
--- src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H
+++ src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H
@@ -51,7 +51,6 @@ public:
int not_clipped(int x, int y, int w, int h);
void restore_clip();
void transformed_vertex(double xf, double yf);
- void vertex(double x, double y);
void begin_points();
void end_points();
void begin_line();
diff --git src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx
index 0a92a9b..7cd144c 100644
--- src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx
+++ src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx
@@ -94,10 +94,6 @@ void Fl_OpenGL_Graphics_Driver::transformed_vertex(double xf, double yf) {
glVertex2d(xf, yf);
}
-void Fl_OpenGL_Graphics_Driver::vertex(double x,double y) {
- transformed_vertex(x*m.a + y*m.c + m.x, x*m.b + y*m.d + m.y);
-}
-
void Fl_OpenGL_Graphics_Driver::circle(double cx, double cy, double r) {
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));
diff --git src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
index d9051ec..388fefd 100644
--- src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
+++ src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
@@ -50,9 +50,6 @@ class Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver {
friend class Fl_Quartz_Font_Descriptor;
protected:
CGContextRef gc_;
- int p_size;
- typedef struct { float x; float y; } XPOINT;
- XPOINT *p;
bool high_resolution_;
float quartz_line_width_;
CGLineCap quartz_line_cap_;
@@ -90,9 +87,7 @@ public:
void XDestroyRegion(Fl_Region r);
void high_resolution(bool b) { high_resolution_ = b; }
protected:
- void transformed_vertex0(float x, float y);
void fixloop();
- // --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/quartz_rect.cxx
void point(int x, int y);
void rect(int x, int y, int w, int h);
void focus_rect(int x, int y, int w, int h);
@@ -114,10 +109,7 @@ protected:
int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
int not_clipped(int x, int y, int w, int h);
void restore_clip();
- // --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
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();
@@ -125,19 +117,13 @@ protected:
void end_complex_polygon();
void gap();
void circle(double x, double y, double r);
- // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed
- // using void Fl_Graphics_Driver::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
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);
- // --- implementation is in src/fl_color.cxx which includes src/cfg_gfx/xxx_color.cxx
void color(Fl_Color c);
void set_color(Fl_Color i, unsigned int c);
Fl_Color color() { return color_; }
void color(uchar r, uchar g, uchar b);
- // --- implementation is in src/fl_font.cxx which includes src/cfg_gfx/xxx_font.cxx
void draw(const char *str, int n, int x, int y);
void draw(const char *str, int n, float x, float y);
void draw(int angle, const char *str, int n, int x, int y);
diff --git src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
index ab95ce5..6dbad26 100644
--- src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
+++ src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
@@ -52,7 +52,7 @@ Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
return new Fl_Quartz_Graphics_Driver();
}
-Fl_Quartz_Graphics_Driver::Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) {
+Fl_Quartz_Graphics_Driver::Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL) {
quartz_line_width_ = 1.f;
quartz_line_cap_ = kCGLineCapButt;
quartz_line_join_ = kCGLineJoinMiter;
diff --git src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx
index 3b0b3f0..952c65b 100644
--- src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx
+++ src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx
@@ -27,14 +27,6 @@
#include <FL/math.h>
-void Fl_Quartz_Graphics_Driver::transformed_vertex(double xf, double yf) {
- transformed_vertex0(float(xf), float(yf));
-}
-
-void Fl_Quartz_Graphics_Driver::vertex(double x,double y) {
- transformed_vertex0(float(x*m.a + y*m.c + m.x), float(x*m.b + y*m.d + m.y));
-}
-
void Fl_Quartz_Graphics_Driver::end_points() {
if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true);
for (int i=0; i<n; i++) {
@@ -130,18 +122,6 @@ void Fl_Quartz_Graphics_Driver::circle(double x, double y,double r) {
CGContextSetShouldAntialias(gc_, false);
}
-void Fl_Quartz_Graphics_Driver::transformed_vertex0(float x, float y) {
- if (!n || x != p[n-1].x || y != p[n-1].y) {
- if (n >= p_size) {
- p_size = p ? 2*p_size : 16;
- p = (XPOINT*)realloc((void*)p, p_size*sizeof(*p));
- }
- p[n].x = x;
- p[n].y = y;
- n++;
- }
-}
-
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--;
}
diff --git src/drivers/SVG/Fl_SVG_File_Surface.cxx src/drivers/SVG/Fl_SVG_File_Surface.cxx
index af63f22..2ca5437 100644
--- src/drivers/SVG/Fl_SVG_File_Surface.cxx
+++ src/drivers/SVG/Fl_SVG_File_Surface.cxx
@@ -53,9 +53,6 @@ class Fl_SVG_Graphics_Driver : public Fl_Graphics_Driver {
uchar red_, green_, blue_;
char *dasharray_; // the dash array as SVG needs it
char *user_dash_array_; // the dash array as FLTK needs it
- int p_size;
- typedef struct { float x; float y; } XPOINT;
- XPOINT *p;
class Clip {
public:
int x, y, w, h; // the clip rectangle
@@ -113,9 +110,6 @@ protected:
void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
void loop(int x0, int y0, int x1, int y1, int x2, int y2);
void point(int x, int y);
- void transformed_vertex0(float x, float y);
- void transformed_vertex(double xf, double yf);
- void vertex(double x,double y);
void end_points();
void end_line();
void fixloop();
@@ -862,26 +856,6 @@ void Fl_SVG_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2
x0, y0, x1, y1, x2, y2, red_, green_, blue_, width_, linejoin_, linecap_, dasharray_);
}
-void Fl_SVG_Graphics_Driver::transformed_vertex0(float x, float y) {
- if (!n || x != p[n-1].x || y != p[n-1].y) {
- if (n >= p_size) {
- p_size = p ? 2*p_size : 16;
- p = (XPOINT*)realloc((void*)p, p_size*sizeof(*p));
- }
- p[n].x = x;
- p[n].y = y;
- n++;
- }
-}
-
-void Fl_SVG_Graphics_Driver::transformed_vertex(double xf, double yf) {
- transformed_vertex0(float(xf), float(yf));
-}
-
-void Fl_SVG_Graphics_Driver::vertex(double x,double y) {
- transformed_vertex0(float(x*m.a + y*m.c + m.x), float(x*m.b + y*m.d + m.y));
-}
-
void Fl_SVG_Graphics_Driver::end_points() {
for (int i=0; i<n; i++) {
fprintf(out_, "<path d=\"M %f %f L %f %f\" fill=\"none\" stroke=\"rgb(%u,%u,%u)\" stroke-width=\"%d\" />\n",
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 6340374..d3222b2 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -94,7 +94,6 @@ private:
static GC gc_;
uchar *mask_bitmap_;
uchar **mask_bitmap() {return &mask_bitmap_;}
- int p_size;
typedef struct {short x, y;} XPOINT;
XPOINT *p;
#if USE_XFT
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
index 309df9e..3bb14e9 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx
@@ -49,7 +49,6 @@ GC fl_gc = 0;
Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
mask_bitmap_ = NULL;
- p_size = 0;
p = NULL;
line_delta_ = 0;
#if USE_PANGO
[ Direct Link to Message ] | |