diff options
| -rw-r--r-- | FL/Fl.H | 30 | ||||
| -rw-r--r-- | ide/Xcode4/FLTK.xcodeproj/project.pbxproj | 2 | ||||
| -rw-r--r-- | src/Fl.cxx | 81 | ||||
| -rw-r--r-- | src/Fl_Gl_Window.cxx | 139 | ||||
| -rw-r--r-- | src/config_lib.h | 92 | ||||
| -rw-r--r-- | src/gl_draw.cxx | 3 | ||||
| -rw-r--r-- | test/cube.cxx | 10 |
7 files changed, 354 insertions, 3 deletions
@@ -137,7 +137,35 @@ class FL_EXPORT Fl { private: static int use_high_res_GL_; - + +public: // run time information about compile time configuration + /** \defgroup cfg_gfx runtime graphics driver configuration */ + /** @{ */ + static bool cfg_gfx_xlib; ///< X11 Xlib rendering available, usually on Linux systems + static bool cgf_gfx_quartz; ///< Quartz rendering available, usually on OS X systems + static bool cfg_gfx_gdi; ///< GDI redering available, usually on MSWindows systems + static bool cfg_gfx_opengl; ///< OpenGL redering available, available on many platforms + static bool cfg_gfx_cairo; ///< Cairo redering available, available on many platforms + static bool cfg_gfx_directx;///< DirectX redering available, available on many platforms + /** @} */ + /** \defgroup cfg_prn runtime printer driver configuration */ + /** @{ */ + static bool cfg_prn_ps; ///< PostScript rendering available, usually on Linux systems + static bool cgf_prn_quartz; ///< Quartz rendering available, usually on OS X systems + static bool cfg_prn_gdi; ///< GDI redering available, usually on MSWindows systems + /** @} */ + /** \defgroup cfg_win runtime window and event manager configuration */ + /** @{ */ + static bool cfg_win_x11; ///< X11 window management available, usually on Linux systems + static bool cgf_win_cocoa; ///< Cocoa window management available, usually on OS X systems + static bool cfg_win_win32; ///< WIN32 window management available, on low level MSWindows + /** @} */ + /** \defgroup cfg_sys runtime system configuration */ + /** @{ */ + static bool cfg_sys_posix; ///< Posix system available, usually on Linux and OS X systems, but also Cygwin + static bool cfg_sys_win32; ///< WIN32 system available, on MSWindows + /** @} */ + public: // should be private! #ifndef FL_DOXYGEN static int e_number; diff --git a/ide/Xcode4/FLTK.xcodeproj/project.pbxproj b/ide/Xcode4/FLTK.xcodeproj/project.pbxproj index ceabcd975..dfed73ac0 100644 --- a/ide/Xcode4/FLTK.xcodeproj/project.pbxproj +++ b/ide/Xcode4/FLTK.xcodeproj/project.pbxproj @@ -4747,6 +4747,7 @@ C9EDD5B11274C4FA00ADB21C /* Fl_PostScript.H */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Fl_PostScript.H; path = ../../FL/Fl_PostScript.H; sourceTree = SOURCE_ROOT; }; C9F1464F0E6A4DCD77AF72B8 /* Fl_Function_Type.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_Function_Type.cxx; path = ../../fluid/Fl_Function_Type.cxx; sourceTree = SOURCE_ROOT; }; C9F9C0DD12CFCDAC0067ADCC /* rgb.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = rgb.txt; path = ../../test/rgb.txt; sourceTree = SOURCE_ROOT; }; + C9FCF4D61C4ADE4800BE15FD /* config_lib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config_lib.h; path = ../../src/config_lib.h; sourceTree = "<group>"; }; CAEC632CEFC2CA7592EF9D74 /* image.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = image.app; sourceTree = BUILT_PRODUCTS_DIR; }; CB23A4CE90D5A89FA2640A78 /* label.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = label.app; sourceTree = BUILT_PRODUCTS_DIR; }; CC0C80DA4DD31B6B2DB91096 /* CodeEditor.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CodeEditor.cxx; path = ../../fluid/CodeEditor.cxx; sourceTree = SOURCE_ROOT; }; @@ -5671,6 +5672,7 @@ isa = PBXGroup; children = ( B04F6E032ADAF0A16A860A2E /* Headers */, + C9FCF4D61C4ADE4800BE15FD /* config_lib.h */, 7F66B1D612BB924C00C67B59 /* Fl_cocoa.mm */, 7F66B1D712BB924C00C67B59 /* Fl_Native_File_Chooser_MAC.mm */, 7F66B1D812BB924C00C67B59 /* Fl_Quartz_Printer.mm */, diff --git a/src/Fl.cxx b/src/Fl.cxx index db4e8de4e..3de2de770 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -21,7 +21,7 @@ // mostly to get around the single active context in QD and // to implement clipping. This should be changed into pure // Quartz calls in the near future. -#include <config.h> +#include "config_lib.h" /* We require Windows 2000 features (e.g. VK definitions) */ #if defined(WIN32) @@ -76,6 +76,85 @@ void fl_cleanup_dc_list(void); extern double fl_mac_flush_and_wait(double time_to_wait); #endif // WIN32 + +// +// Runtime configuartion flags +// +#ifdef FL_CFG_GFX_XLIB +bool Fl::cfg_gfx_xlib = 1; +#else +bool Fl::cfg_gfx_xlib = 0; +#endif +#ifdef FL_CFG_GFX_QUARTZ +bool Fl::cgf_gfx_quartz = 1; +#else +bool Fl::cgf_gfx_quartz = 0; +#endif +#ifdef FL_CFG_GFX_GDI +bool Fl::cfg_gfx_gdi = 1; +#else +bool Fl::cfg_gfx_gdi = 0; +#endif +#ifdef FL_CFG_GFX_OPENGL +bool Fl::cfg_gfx_opengl = 1; +#else +bool Fl::cfg_gfx_opengl = 0; +#endif +#ifdef FL_CFG_GFX_CAIRO +bool Fl::cfg_gfx_cairo = 1; +#else +bool Fl::cfg_gfx_cairo = 0; +#endif +#ifdef FL_CFG_GFX_DIRECTX +bool Fl::cfg_gfx_directx = 1; +#else +bool Fl::cfg_gfx_directx = 0; +#endif + +#ifdef FL_CFG_PRN_PS +bool Fl::cfg_prn_ps = 1; +#else +bool Fl::cfg_prn_ps = 0; +#endif +#ifdef FL_CFG_PRN_QUARTZ +bool Fl::cgf_prn_quartz = 1; +#else +bool Fl::cgf_prn_quartz = 0; +#endif +#ifdef FL_CFG_PRN_GDI +bool Fl::cfg_prn_gdi = 1; +#else +bool Fl::cfg_prn_gdi = 0; +#endif + +#ifdef FL_CFG_WIN_X11 +bool Fl::cfg_win_x11 = 1; +#else +bool Fl::cfg_win_x11 = 0; +#endif +#ifdef FL_CFG_WIN_COCOA +bool Fl::cgf_win_cocoa = 1; +#else +bool Fl::cgf_win_cocoa = 0; +#endif +#ifdef FL_CFG_WIN_WIN32 +bool Fl::cfg_win_win32 = 1; +#else +bool Fl::cfg_win_win32 = 0; +#endif + +#ifdef FL_SYS_POSIX +bool Fl::cfg_sys_posix = 1; +#else +bool Fl::cfg_sys_posix = 0; +#endif +#ifdef FL_SYS_WIN32 +bool Fl::cfg_sys_win32 = 1; +#else +bool Fl::cfg_sys_win32 = 0; +#endif + + // // Globals... // diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 02d238332..4fe8ca13e 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -17,6 +17,7 @@ // #include "flstring.h" +#include "config_lib.h" #if HAVE_GL extern int fl_gl_load_plugin; @@ -29,6 +30,7 @@ extern int fl_gl_load_plugin; #include <OpenGL/OpenGL.h> #endif #include <FL/Fl_Gl_Window.H> +#include <FL/Fl_Device.H> #include <stdlib.h> #include <FL/fl_utf8.h> @@ -38,6 +40,123 @@ extern int fl_gl_load_plugin; #else #endif + +// ------ this should be in a separate file! ----------------------------------- +#ifdef FL_CFG_GFX_OPENGL + +#include <FL/Fl_Device.h> + +/** + \brief OpenGL pecific graphics class. + * + This class is implemented only on the Mac OS X platform. + */ +class FL_EXPORT Fl_OpenGL_Graphics_Driver : public Fl_Graphics_Driver { +public: + static const char *class_id; + const char *class_name() {return class_id;}; + void draw(const char* str, int n, int x, int y) { + gl_draw(str, n, x, y); + } + void color(Fl_Color c) { + gl_color(c); + } + void color(uchar r, uchar g, uchar b) { + unsigned int c = (r<<24)|(g<<16)|(b<<8); + gl_color(c); + } + void rectf(int x, int y, int w, int h) { + glBegin(GL_POLYGON); + glVertex2i(x, y); + glVertex2i(x+w-1, y); + glVertex2i(x+w-1, 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); + glVertex2i(x1, y1); + glEnd(); + } + void xyline(int x, int y, int x1) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glEnd(); + } + void xyline(int x, int y, int x1, int y2) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glVertex2i(x1, y2); + glEnd(); + } + void xyline(int x, int y, int x1, int y2, int x3) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x1, y); + glVertex2i(x1, y2); + glVertex2i(x3, y2); + glEnd(); + } + void yxline(int x, int y, int y1) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glEnd(); + } + void yxline(int x, int y, int y1, int x2) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glVertex2i(x2, y1); + glEnd(); + } + void yxline(int x, int y, int y1, int x2, int y3) { + glBegin(GL_LINE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y1); + glVertex2i(x2, y1); + glVertex2i(x2, y3); + 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); +*/ +}; + +const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver"; + +Fl_OpenGL_Graphics_Driver fl_opengl_graphics_driver; + +#endif +// ------ end of separate file! ------------------------------------------------ + + //////////////////////////////////////////////////////////////// // The symbol SWAP_TYPE defines what is in the back buffer after doing @@ -539,7 +658,25 @@ void Fl_Gl_Window::draw_overlay() {} buffers are swapped after this function is completed. */ void Fl_Gl_Window::draw() { - Fl::fatal("Fl_Gl_Window::draw() *must* be overriden. Please refer to the documentation."); +#ifdef FL_CFG_GFX_OPENGL + Fl_Graphics_Driver *prev_driver = fl_graphics_driver; + fl_graphics_driver = &fl_opengl_graphics_driver; + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glPushMatrix(); + 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()); + + Fl_Window::draw(); + + glPopMatrix(); + glPushAttrib(GL_ENABLE_BIT); + fl_graphics_driver = prev_driver; +#else + Fl::fatal("Fl_Gl_Window::draw() *must* be overriden. Please refer to the documentation."); +#endif } diff --git a/src/config_lib.h b/src/config_lib.h new file mode 100644 index 000000000..6e5c8738b --- /dev/null +++ b/src/config_lib.h @@ -0,0 +1,92 @@ +/* + * "$Id$" + * + * Configuration file for the Fast Light Tool Kit (FLTK). + * + * Copyright 1998-2011 by Bill Spitzak and others. + */ + +#ifndef FL_CONFIG_LIB_H +#define FL_CONFIG_LIB_H + +#include <config.h> + + +// find the right graphics configuration +#if !defined(FL_CFG_GFX_XLIB) && !defined(FL_CFG_GFX_QUARTZ) && !defined(FL_CFG_GFX_GDI) + +#ifdef __APPLE__ +# define FL_CFG_GFX_QUARTZ +# ifdef HAVE_GL +# define FL_CFG_GFX_OPENGL +# endif +#elif defined(WIN32) +# define FL_CFG_GFX_GDI +# ifdef HAVE_GL +# define FL_CFG_GFX_OPENGL +# endif +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: please choose a core graphics library +#else // X11 +# define FL_CFG_GFX_XLIB +# ifdef HAVE_GL +# define FL_CFG_GFX_OPENGL +# endif +#endif + +#endif + + +// find the right printer driver configuration +#if !defined(FL_CFG_PRN_PS) && !defined(FL_CFG_PRN_QUARTZ) && !defined(FL_CFG_PRN_WIN32) + +#ifdef __APPLE__ +# define FL_CFG_PRN_QUARTZ +#elif defined(WIN32) +# define FL_CFG_WIN_WIN32 +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: please choose a graphics driver library +#else // X11 +# define FL_CFG_GFX_PS +#endif + +#endif + + +// find the right window manager configuration +#if !defined(FL_CFG_WIN_X11) && !defined(FL_CFG_WIN_COCOA) && !defined(FL_CFG_WIN_WIN32) + +#ifdef __APPLE__ +# define FL_CFG_WIN_COCOA +#elif defined(WIN32) +# define FL_CFG_WIN_WIN32 +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: please choose a window management library +#else // X11 +# define FL_CFG_GFX_X11 +#endif + +#endif + + +// find the right system configuration +#if !defined(FL_CFG_SYS_POSIX) && !defined(FL_CFG_SYS_WIN32) + +#ifdef __APPLE__ +# define FL_CFG_SYS_POSIX +#elif defined(WIN32) +# define FL_CFG_SYS_WIN32 +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: please choose a system library +#else // X11 +# define FL_CFG_SYS_POSIX +#endif + +#endif + + +#endif + +/* + * End of "$Id$". + */ diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index d8500ac75..2fa8f8380 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -469,6 +469,8 @@ void gl_texture_fifo::display_texture(int rank) // pre-computes a string texture int gl_texture_fifo::compute_texture(const char* str, int n) { + Fl_Graphics_Driver *prev_driver = fl_graphics_driver; + fl_graphics_driver = Fl_Display_Device::display_device()->driver(); current = (current + 1) % size_; if (current > last) last = current; if ( fifo[current].utf8 ) free(fifo[current].utf8); @@ -510,6 +512,7 @@ int gl_texture_fifo::compute_texture(const char* str, int n) } else { fifo[current].ratio = float(fifo[current].width)/glutStrokeLength(GLUT_STROKE_ROMAN, (uchar*)fifo[current].utf8); } + fl_graphics_driver = prev_driver; return current; } diff --git a/test/cube.cxx b/test/cube.cxx index 9f4cf0aa6..7f7d37c4b 100644 --- a/test/cube.cxx +++ b/test/cube.cxx @@ -99,6 +99,7 @@ void cube_box::draw() { glFrustum(-1,1,-1,1,2,10000); glTranslatef(0,0,-10); gl_font(FL_HELVETICA_BOLD, 16 ); + glClearColor(0.4, 0.4, 0.4, 0); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); @@ -113,6 +114,10 @@ void cube_box::draw() { glDisable(GL_DEPTH_TEST); gl_draw(wire ? "Cube: wire" : "Cube: flat", -4.5f, -4.5f ); glEnable(GL_DEPTH_TEST); + + // if an OpenGL graphics driver is installed, give it a chance + // to draw additional graphics + if (Fl::cfg_gfx_opengl) Fl_Gl_Window::draw(); } int cube_box::handle(int e) { @@ -140,6 +145,11 @@ void makeform(const char *name) { flat = new Fl_Radio_Light_Button(390,50,100,30,"Flat"); button = new Fl_Button(390,340,100,30,"Exit"); cube = new cube_box(23,23,344,344, 0); + if (Fl::cfg_gfx_opengl) { // try to overlay a button onto an OpenGL window + cube->begin(); + /*Fl_Button *test =*/ new Fl_Button(35, 105, 100, 30, "Test"); + cube->end(); + } cube2 = new cube_box(513,23,344,344, 0); Fl_Box *b = new Fl_Box(FL_NO_BOX,cube->x(),size->y(), cube->w(),size->h(),0); |
