diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-03-01 15:10:52 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-03-01 15:11:00 +0100 |
| commit | 0623a8d4b9e8a56cc435dc550c6b56fa1a9607e9 (patch) | |
| tree | 48e6487325011a59b6016d0c43d2c1f78a6f1612 | |
| parent | 37175d17571e075324fb5cb3c651e45b236cd6e5 (diff) | |
Remove duplicated code between derived classes of Fl_Graphics_Driver.
| -rw-r--r-- | FL/Fl_Graphics_Driver.H | 5 | ||||
| -rw-r--r-- | src/Fl_Graphics_Driver.cxx | 24 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver.H | 3 | ||||
| -rw-r--r-- | src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx | 4 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H | 14 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx | 20 | ||||
| -rw-r--r-- | src/drivers/SVG/Fl_SVG_File_Surface.cxx | 26 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx | 1 |
11 files changed, 26 insertions, 75 deletions
diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H index 3bce25fb7..f3ed53d65 100644 --- a/FL/Fl_Graphics_Driver.H +++ b/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 a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index 547526ed3..be8849dd4 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/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 a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H index d322bc8af..4ec7bce82 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H +++ b/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 a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H index 46dba5388..f240e769b 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.H +++ b/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 a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx index 0a92a9b2f..7cd144ce6 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx +++ b/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 a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H index d9051ecbd..388fefd0f 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H +++ b/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 a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx index ab95ce510..6dbad2684 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx +++ b/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 a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx index 3b0b3f058..952c65b3d 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx +++ b/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 a/src/drivers/SVG/Fl_SVG_File_Surface.cxx b/src/drivers/SVG/Fl_SVG_File_Surface.cxx index af63f221d..2ca543745 100644 --- a/src/drivers/SVG/Fl_SVG_File_Surface.cxx +++ b/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 a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index 6340374ae..d3222b2f4 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/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 a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx index 309df9e91..3bb14e93c 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx +++ b/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 |
