From d3bd47073424e5288589fce59ab1dd39ccb1b42a Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 20 Jan 2016 00:39:46 +0000 Subject: 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 --- src/Fl_Gl_Window.cxx | 60 ++++++----------- src/fl_rect.cxx | 185 ++++++++++++++++++++++++++------------------------- 2 files changed, 115 insertions(+), 130 deletions(-) (limited to 'src') diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 33a84ace0..52f91ed18 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -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"; diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index eb23a0d92..7f495da62 100644 --- a/src/fl_rect.cxx +++ b/src/fl_rect.cxx @@ -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$". // -- cgit v1.2.3