Re-ordering a few more functions. It's nice to see how clear functions like rectf() become without the #ifdef mess.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11013 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher
2016-01-20 00:39:46 +00:00
parent bd78fa1c48
commit d3bd470734
3 changed files with 134 additions and 136 deletions
+19 -6
View File
@@ -244,9 +244,9 @@ protected:
/** \brief The constructor. */
Fl_Graphics_Driver();
/** \brief see fl_rect(int x, int y, int w, int h). */
virtual void rect(int x, int y, int w, int h);
virtual void rect(int x, int y, int w, int h) = 0;
/** \brief see fl_rectf(int x, int y, int w, int h). */
virtual void rectf(int x, int y, int w, int h);
virtual void rectf(int x, int y, int w, int h) = 0;
/** \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_xyline(int x, int y, int x1). */
@@ -474,9 +474,14 @@ public:
static Fl_Offscreen create_offscreen_with_alpha(int w, int h);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
virtual void point(int x, int y);
// --- recently moved implementations (see FL_PORTING efforts)
void point(int x, int y);
void rect(int x, int y, int w, int h);
void rectf(int x, int y, int w, int h);
};
// FIXME: add Fl_Quartz_Printer_Graphics_Driver
#elif defined(WIN32) || defined(FL_DOXYGEN)
/**
@@ -510,7 +515,10 @@ public:
void copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
virtual void point(int x, int y);
// --- recently moved implementations (see FL_PORTING efforts)
void point(int x, int y);
void rect(int x, int y, int w, int h);
void rectf(int x, int y, int w, int h);
};
/**
@@ -532,7 +540,9 @@ public:
# pragma message "FL_PORTING: define a native graphics driver Fl_xxx_Graphics_Driver"
class FL_EXPORT Fl_XXX_Graphics_Driver : public Fl_Graphics_Driver {
protected:
virtual void point(int x, int y) { }
// --- recently moved implementations (see FL_PORTING efforts)
void point(int x, int y) { }
void rect(int x, int y, int w, int h) { }
};
#else // X11
@@ -568,7 +578,10 @@ public:
#if ! defined(FL_DOXYGEN)
void copy_offscreen_with_alpha(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
#endif
virtual void point(int x, int y);
// --- recently moved implementations (see FL_PORTING efforts)
void point(int x, int y);
void rect(int x, int y, int w, int h);
void rectf(int x, int y, int w, int h);
};
#endif
+21 -39
View File
@@ -66,18 +66,6 @@ public:
unsigned int c = (r<<24)|(g<<16)|(b<<8);
gl_color(c);
}
void rectf(int x, int y, int w, int h) {
if (w<0) { x = x+w; w = -w; }
if (h<0) { y = y+h; h = -h; }
// OpenGL has the natural origin at the bottom left. Drawing in FLTK
// coordinates requires that we shift the rectangle one pixel up.
glBegin(GL_POLYGON);
glVertex2i(x, y-1);
glVertex2i(x+w, y-1);
glVertex2i(x+w, y+h-1);
glVertex2i(x, y+h-1);
glEnd();
}
void line(int x, int y, int x1, int y1) {
glBegin(GL_LINE_STRIP);
glVertex2i(x, y);
@@ -133,37 +121,31 @@ public:
glEnd();
point(x2, y3);
}
virtual void point(int x, int y) {
// --- recently moved implementations (see FL_PORTING efforts)
void point(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
/*
#ifdef __APPLE__
void draw(const char *str, int n, float x, float y);
#endif
void draw(int angle, const char *str, int n, int x, int y);
void rtl_draw(const char* str, int n, int x, int y);
void font(Fl_Font face, Fl_Fontsize size);
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP);
void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
double width(const char *str, int n);
double width(unsigned int c);
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
int height();
int descent();
#if ! defined(FL_DOXYGEN)
static Fl_Offscreen create_offscreen_with_alpha(int w, int h);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
*/
void rect(int x, int y, int w, int h) {
glBegin(GL_LINE_LOOP);
glVertex2i(x, y);
glVertex2i(x+w, y);
glVertex2i(x+w, y+h);
glVertex2i(x, y+h);
glEnd();
}
void rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
// OpenGL has the natural origin at the bottom left. Drawing in FLTK
// coordinates requires that we shift the rectangle one pixel up.
glBegin(GL_POLYGON);
glVertex2i(x, y-1);
glVertex2i(x+w, y-1);
glVertex2i(x+w, y+h-1);
glVertex2i(x, y+h-1);
glEnd();
}
};
const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver";
+94 -91
View File
@@ -162,50 +162,6 @@ static int clip_x (int x) {
#endif // USE_X11
void Fl_Graphics_Driver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
#if defined(USE_X11)
if (!clip_to_short(x, y, w, h))
XDrawRectangle(fl_display, fl_window, fl_gc, x, y, w-1, h-1);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x+w-1, y);
LineTo(fl_gc, x+w-1, y+h-1);
LineTo(fl_gc, x, y+h-1);
LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__)
if ( (!USINGQUARTZPRINTER) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextStrokeRect(fl_gc, rect);
if ( (!USINGQUARTZPRINTER) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement rect"
#else
# error unsupported platform
#endif
}
void Fl_Graphics_Driver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
#if defined(USE_X11)
if (!clip_to_short(x, y, w, h))
XFillRectangle(fl_display, fl_window, fl_gc, x, y, w, h);
#elif defined(WIN32)
RECT rect;
rect.left = x; rect.top = y;
rect.right = x + w; rect.bottom = y + h;
FillRect(fl_gc, &rect, fl_brush());
#elif defined(__APPLE_QUARTZ__)
CGRect rect = CGRectMake(x - 0.5, y - 0.5, w , h);
CGContextFillRect(fl_gc, rect);
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement rectf"
#else
# error unsupported platform
#endif
}
void Fl_Graphics_Driver::xyline(int x, int y, int x1) {
#if defined(USE_X11)
XDrawLine(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y), clip_x(x1), clip_x(y));
@@ -548,53 +504,6 @@ void Fl_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int y2, i
}
/*
Matt: I wrote individual methods for every class. They are virtual, so the
correct function is called, depending on the active driver.
By having individual methods, multiple drivers can co-exist, for example
Quartz, OpenGL, and a printer driver.
The individual implementations should eventually go into files that are
included into this file, based on the configuration, for example:
src/cfg_gfx/quartz_rect.cxx
src/cfg_gfx/gdi_rect.cxx
src/cfg_gfx/xlib_rect.cxx
Porting the graphics system to a new platform then requires to copy one of
these files and implement the virtual functions. point() is the only function
that *must* be implemented when deriving from 'Fl_Minimal_Graphics_Driver"
(which is still to be written)
*/
#ifdef FL_CFG_GFX_QUARTZ
void Fl_Quartz_Graphics_Driver::point(int x, int y) {
CGContextFillRect(fl_gc, CGRectMake(x - 0.5, y - 0.5, 1, 1) );
}
#endif
#ifdef FL_CFG_GFX_GDI
void Fl_GDI_Graphics_Driver::point(int x, int y) {
SetPixel(fl_gc, x, y, fl_RGB());
}
#endif
#ifdef FL_CFG_GFX_XLIB
void Fl_Xlib_Graphics_Driver::point(int x, int y) {
XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y));
}
#endif
////////////////////////////////////////////////////////////////
#if defined(WIN32)
@@ -814,6 +723,100 @@ int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int
#endif
}
////////////////////////////////////////////////////////////////
/*
Matt: I wrote individual methods for every class. They are virtual, so the
correct function is called, depending on the active driver.
By having individual methods, multiple drivers can co-exist, for example
Quartz, OpenGL, and a printer driver.
The individual implementations should eventually go into files that are
included into this file, based on the configuration, for example:
src/cfg_gfx/quartz_rect.cxx
src/cfg_gfx/gdi_rect.cxx
src/cfg_gfx/xlib_rect.cxx
Porting the graphics system to a new platform then requires to copy one of
these files and implement the virtual functions. point() is the only function
that *must* be implemented when deriving from 'Fl_Minimal_Graphics_Driver"
(which is still to be written)
*/
#ifdef FL_CFG_GFX_QUARTZ
void Fl_Quartz_Graphics_Driver::point(int x, int y) {
CGContextFillRect(fl_gc, CGRectMake(x - 0.5, y - 0.5, 1, 1) );
}
void Fl_Quartz_Graphics_Driver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
// FIXME: there should be a quartz graphics driver for the printer device that makes the USINGQUARTZPRINTER obsolete
if ( (!USINGQUARTZPRINTER) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextStrokeRect(fl_gc, rect);
if ( (!USINGQUARTZPRINTER) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
}
void Fl_Quartz_Graphics_Driver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
CGRect rect = CGRectMake(x - 0.5, y - 0.5, w , h);
CGContextFillRect(fl_gc, rect);
}
#endif
// -----------------------------------------------------------------------------
#ifdef FL_CFG_GFX_GDI
void Fl_GDI_Graphics_Driver::point(int x, int y) {
SetPixel(fl_gc, x, y, fl_RGB());
}
void Fl_GDI_Graphics_Driver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x+w-1, y);
LineTo(fl_gc, x+w-1, y+h-1);
LineTo(fl_gc, x, y+h-1);
LineTo(fl_gc, x, y);
}
void Fl_GDI_Graphics_Driver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
RECT rect;
rect.left = x; rect.top = y;
rect.right = x + w; rect.bottom = y + h;
FillRect(fl_gc, &rect, fl_brush());
}
#endif
// -----------------------------------------------------------------------------
#ifdef FL_CFG_GFX_XLIB
void Fl_Xlib_Graphics_Driver::point(int x, int y) {
XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y));
}
void Fl_Xlib_Graphics_Driver::rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
if (!clip_to_short(x, y, w, h))
XDrawRectangle(fl_display, fl_window, fl_gc, x, y, w-1, h-1);
}
void Fl_Xlib_Graphics_Driver::rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return;
if (!clip_to_short(x, y, w, h))
XFillRectangle(fl_display, fl_window, fl_gc, x, y, w, h);
}
#endif
//
// End of "$Id$".
//