Avoid using same name (p) for distinct members of derived classes.

This commit is contained in:
ManoloFLTK 2022-03-21 15:56:50 +01:00
parent bf5b902180
commit d87b62ea69
8 changed files with 51 additions and 34 deletions

View File

@ -243,7 +243,7 @@ protected:
void cache_size_finalize(Fl_Image *img, int &width, int &height);
static unsigned need_pixmap_bg_color;
public:
virtual ~Fl_Graphics_Driver() {} ///< Destructor
virtual ~Fl_Graphics_Driver();
static Fl_Graphics_Driver &default_driver();
/** Current scale factor between FLTK and drawing units: drawing = FLTK * scale() */
float scale() { return scale_; }

View File

@ -54,6 +54,12 @@ Fl_Graphics_Driver::Fl_Graphics_Driver()
xpoint = NULL;
};
/** Destructor */
Fl_Graphics_Driver::~Fl_Graphics_Driver() {
if (xpoint) free(xpoint);
}
/** Return the graphics driver used when drawing to the platform's display */
Fl_Graphics_Driver &Fl_Graphics_Driver::default_driver()
{
@ -532,7 +538,7 @@ void Fl_Graphics_Driver::fixloop() { // remove equal points from closed path
/** see fl_end_loop() */
void Fl_Graphics_Driver::end_loop() {
fixloop();
if (n>2) transformed_vertex((float)xpoint[0].x, (float)xpoint[0].y);
if (n>2) transformed_vertex(xpoint[0].x, xpoint[0].y);
end_line();
}

View File

@ -2,7 +2,7 @@
// Definition of classes Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
// for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2021 by Bill Spitzak and others.
// Copyright 2010-2022 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
@ -59,10 +59,10 @@ protected:
int counts[20];
uchar *mask_bitmap_;
uchar **mask_bitmap() {return &mask_bitmap_;}
POINT *p;
POINT *long_point;
public:
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;}
Fl_GDI_Graphics_Driver();
virtual ~Fl_GDI_Graphics_Driver();
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
char can_do_alpha_blending();
virtual void gc(void *ctxt) { gc_ = (HDC)ctxt; global_gc(); }

View File

@ -1,7 +1,7 @@
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2022 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
@ -75,6 +75,19 @@ static FL_BLENDFUNCTION blendfunc = { 0, 0, 255, 1};
*/
HDC fl_gc = 0;
Fl_GDI_Graphics_Driver::Fl_GDI_Graphics_Driver() {
mask_bitmap_ = NULL;
gc_ = NULL;
long_point = NULL;
depth = -1;
origins = NULL;
}
Fl_GDI_Graphics_Driver::~Fl_GDI_Graphics_Driver() {
if (long_point) free(long_point);
delete[] origins;
}
void Fl_GDI_Graphics_Driver::global_gc()
{
fl_gc = (HDC)gc();
@ -204,19 +217,19 @@ void Fl_GDI_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y,
}
void Fl_GDI_Graphics_Driver::transformed_vertex0(float x, float y) {
if (!n || x != p[n-1].x || y != p[n-1].y) {
if (!n || x != long_point[n-1].x || y != long_point[n-1].y) {
if (n >= p_size) {
p_size = p ? 2*p_size : 16;
p = (POINT*)realloc((void*)p, p_size*sizeof(*p));
p_size = long_point ? 2*p_size : 16;
long_point = (POINT*)realloc((void*)long_point, p_size*sizeof(*long_point));
}
p[n].x = int(x);
p[n].y = int(y);
long_point[n].x = LONG(x);
long_point[n].y = LONG(y);
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--;
while (n>2 && long_point[n-1].x == long_point[0].x && long_point[n-1].y == long_point[0].y) n--;
}
Fl_Region Fl_GDI_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {

View File

@ -59,7 +59,6 @@ protected:
virtual void cache_size(Fl_Image* img, int &width, int &height);
public:
Fl_Quartz_Graphics_Driver();
virtual ~Fl_Quartz_Graphics_Driver() { if (xpoint) free(xpoint); }
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
virtual void gc(void *ctxt) { gc_ = (CGContextRef)ctxt; global_gc(); }
virtual void *gc() {return gc_;}

View File

@ -1,7 +1,7 @@
//
// Definition of class Fl_Xlib_Graphics_Driver for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2020 by Bill Spitzak and others.
// Copyright 2010-2022 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
@ -96,8 +96,7 @@ private:
static GC gc_;
uchar *mask_bitmap_;
uchar **mask_bitmap() {return &mask_bitmap_;}
typedef struct {short x, y;} XPOINT;
XPOINT *p;
XPoint *short_point;
#if USE_XFT
static Window draw_window;
static struct _XftDraw* draw_;

View File

@ -1,7 +1,7 @@
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2022 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
@ -42,7 +42,7 @@ GC fl_gc = 0;
Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
mask_bitmap_ = NULL;
p = NULL;
short_point = NULL;
#if USE_PANGO
Fl_Graphics_Driver::font(0, 0);
#endif
@ -52,7 +52,7 @@ Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
}
Fl_Xlib_Graphics_Driver::~Fl_Xlib_Graphics_Driver() {
if (p) free(p);
if (short_point) free(short_point);
}
@ -85,19 +85,19 @@ void Fl_Xlib_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y,
void Fl_Xlib_Graphics_Driver::transformed_vertex0(float fx, float fy) {
short x = short(fx), y = short(fy);
if (!n || x != p[n-1].x || y != p[n-1].y) {
if (!n || x != short_point[n-1].x || y != short_point[n-1].y) {
if (n >= p_size) {
p_size = p ? 2*p_size : 16;
p = (XPOINT*)realloc((void*)p, p_size*sizeof(*p));
p_size = short_point ? 2*p_size : 16;
short_point = (XPoint*)realloc((void*)short_point, p_size*sizeof(*short_point));
}
p[n].x = x ;
p[n].y = y ;
short_point[n].x = x ;
short_point[n].y = y ;
n++;
}
}
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--;
while (n>2 && short_point[n-1].x == short_point[0].x && short_point[n-1].y == short_point[0].y) n--;
}
// FIXME: should be members of Fl_Xlib_Graphics_Driver

View File

@ -1,7 +1,7 @@
//
// Portable drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2018 by Bill Spitzak and others.
// Copyright 1998-2022 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
@ -29,7 +29,7 @@
void Fl_Xlib_Graphics_Driver::end_points() {
if (n>1) XDrawPoints(fl_display, fl_window, gc_, (XPoint*)p, n, 0);
if (n>1) XDrawPoints(fl_display, fl_window, gc_, short_point, n, 0);
}
void Fl_Xlib_Graphics_Driver::end_line() {
@ -37,13 +37,13 @@ void Fl_Xlib_Graphics_Driver::end_line() {
end_points();
return;
}
if (n>1) XDrawLines(fl_display, fl_window, gc_, (XPoint*)p, n, 0);
if (n>1) XDrawLines(fl_display, fl_window, gc_, short_point, n, 0);
}
void Fl_Xlib_Graphics_Driver::end_loop() {
fixloop();
if (n>2) {
transformed_vertex0(p[0].x , p[0].y );
transformed_vertex0(short_point[0].x , short_point[0].y );
}
end_line();
}
@ -54,13 +54,13 @@ void Fl_Xlib_Graphics_Driver::end_polygon() {
end_line();
return;
}
if (n>2) XFillPolygon(fl_display, fl_window, gc_, (XPoint*)p, n, Convex, 0);
if (n>2) XFillPolygon(fl_display, fl_window, gc_, short_point, n, Convex, 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--;
while (n>gap_+2 && short_point[n-1].x == short_point[gap_].x && short_point[n-1].y == short_point[gap_].y) n--;
if (n > gap_+2) {
transformed_vertex0(p[gap_].x, p[gap_].y);
transformed_vertex0(short_point[gap_].x, short_point[gap_].y);
gap_ = n;
} else {
n = gap_;
@ -73,7 +73,7 @@ void Fl_Xlib_Graphics_Driver::end_complex_polygon() {
end_line();
return;
}
if (n>2) XFillPolygon(fl_display, fl_window, gc_, (XPoint*)p, n, 0, 0);
if (n>2) XFillPolygon(fl_display, fl_window, gc_, short_point, n, 0, 0);
}
// shortcut the closed circles so they use XDrawArc: