summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-01-20 00:11:43 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-01-20 00:11:43 +0000
commitbd78fa1c48641649e033818503af5c8e99330226 (patch)
treee56b03e8cb1cd0a6d63a16082eba28a8e0edfc2c
parent9872f7405325019ab925b487dd8988cf9882817d (diff)
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
-rw-r--r--FL/Fl_Device.H7
-rw-r--r--src/Fl_Gl_Window.cxx24
-rw-r--r--src/fl_rect.cxx55
-rw-r--r--src/gl_draw.cxx3
-rw-r--r--test/cube.cxx2
5 files changed, 74 insertions, 17 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H
index aa34199c0..78bfb351f 100644
--- a/FL/Fl_Device.H
+++ b/FL/Fl_Device.H
@@ -285,7 +285,7 @@ protected:
/** \brief see fl_color(uchar r, uchar g, uchar b). */
virtual void color(uchar r, uchar g, uchar b) {}
/** \brief see fl_point(int x, int y). */
- virtual void point(int x, int y);
+ virtual void point(int x, int y) = 0;
/** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2). */
virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2);
/** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
@@ -474,6 +474,7 @@ 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);
};
#elif defined(WIN32) || defined(FL_DOXYGEN)
@@ -509,6 +510,7 @@ 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);
};
/**
@@ -529,6 +531,8 @@ 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) { }
};
#else // X11
@@ -564,6 +568,7 @@ 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);
};
#endif
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 <config.h>
+#include "config_lib.h"
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Printer.H>
@@ -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);
}
diff --git a/test/cube.cxx b/test/cube.cxx
index 7f7d37c4b..9dea82290 100644
--- a/test/cube.cxx
+++ b/test/cube.cxx
@@ -177,7 +177,7 @@ void print_cb(Fl_Widget *w, void *data)
// end of printing demo
int main(int argc, char **argv) {
- Fl::use_high_res_GL(1);
+ //Fl::use_high_res_GL(1);
makeform(argv[0]);
// added to demo printing
form->begin();