From bd78fa1c48641649e033818503af5c8e99330226 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 20 Jan 2016 00:11:43 +0000 Subject: Starting to cut out individual graphics function, so that multiple drivers can coexist (cfg_gfx). Found the missing pixels in the OpenGL gfx driver. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11012 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Gl_Window.cxx | 24 +++++++++++++++++++---- src/fl_rect.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++---------- src/gl_draw.cxx | 3 ++- 3 files changed, 67 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 1468d44dc..33a84ace0 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -67,10 +67,14 @@ public: 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); - glVertex2i(x+w-1, y); - glVertex2i(x+w-1, y+h-1); + glVertex2i(x, y-1); + glVertex2i(x+w, y-1); + glVertex2i(x+w, y+h-1); glVertex2i(x, y+h-1); glEnd(); } @@ -79,12 +83,14 @@ public: glVertex2i(x, y); glVertex2i(x1, y1); glEnd(); + point(x1, y1); } void xyline(int x, int y, int x1) { glBegin(GL_LINE_STRIP); glVertex2i(x, y); glVertex2i(x1, y); glEnd(); + point(x1, y); } void xyline(int x, int y, int x1, int y2) { glBegin(GL_LINE_STRIP); @@ -92,6 +98,7 @@ public: glVertex2i(x1, y); glVertex2i(x1, y2); glEnd(); + point(x1, y2); } void xyline(int x, int y, int x1, int y2, int x3) { glBegin(GL_LINE_STRIP); @@ -100,12 +107,14 @@ public: glVertex2i(x1, y2); glVertex2i(x3, y2); glEnd(); + point(x3, y2); } void yxline(int x, int y, int y1) { glBegin(GL_LINE_STRIP); glVertex2i(x, y); glVertex2i(x, y1); glEnd(); + point(x, y1); } void yxline(int x, int y, int y1, int x2) { glBegin(GL_LINE_STRIP); @@ -113,6 +122,7 @@ public: glVertex2i(x, y1); glVertex2i(x2, y1); glEnd(); + point(x2, y1); } void yxline(int x, int y, int y1, int x2, int y3) { glBegin(GL_LINE_STRIP); @@ -121,6 +131,12 @@ public: glVertex2i(x2, y1); glVertex2i(x2, y3); glEnd(); + point(x2, y3); + } + virtual void point(int x, int y) { + glBegin(GL_POINTS); + glVertex2i(x, y); + glEnd(); } /* @@ -682,7 +698,7 @@ void Fl_Gl_Window::draw() { glLoadIdentity(); glOrtho(-0.5, w()-0.5, h()-0.5, -0.5, -1, 1); // glOrtho(0, w(), h(), 0, -1, 1); - glLineWidth(pixels_per_unit()); + glLineWidth(pixels_per_unit()); // should be 1 or 2 (2 if highres OpenGL) Fl_Window::draw(); diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index 9c789e54b..eb23a0d92 100644 --- a/src/fl_rect.cxx +++ b/src/fl_rect.cxx @@ -27,6 +27,7 @@ // that minimal update works. #include +#include "config_lib.h" #include #include #include @@ -546,20 +547,54 @@ void Fl_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int y2, i #endif } -void Fl_Graphics_Driver::point(int x, int y) { -#if defined(USE_X11) - XDrawPoint(fl_display, fl_window, fl_gc, clip_x(x), clip_x(y)); -#elif defined(WIN32) - SetPixel(fl_gc, x, y, fl_RGB()); -#elif defined(__APPLE_QUARTZ__) + +/* + 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) ); -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: implement point" -#else -# error unsupported platform +} + +#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) diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index 2fa8f8380..377914c2c 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -267,7 +267,8 @@ static void gl_draw_invert(const char* str, int n, int x, int y) { void gl_draw( const char* str, // the (multi-line) string int x, int y, int w, int h, // bounding box - Fl_Align align) { + Fl_Align align) +{ fl_draw(str, x, -y-h, w, h, align, gl_draw_invert, NULL, 0); } -- cgit v1.2.3