Author: matt
Date: 2010-03-16 15:51:31 -0700 (Tue, 16 Mar 2010)
New Revision: 7280
Log:
Using Fl_Plugin feature to automatically draw OpenGL (sub)windows. No extra 
coding needs to be done. Just call Fl_Printer::print_widget(...). The 
Fl_Gl_Printer device can (and should) be removed or at least made inaccessible.

Modified:
   branches/branch-1.3/FL/Fl_Device.H
   branches/branch-1.3/FL/Fl_Gl_Window.H
   branches/branch-1.3/FL/Fl_Group.H
   branches/branch-1.3/FL/Fl_Widget.H
   branches/branch-1.3/FL/Fl_Window.H
   branches/branch-1.3/src/Fl_Device.cxx
   branches/branch-1.3/src/Fl_Gl_Printer.cxx
   branches/branch-1.3/test/cube.cxx

Modified: branches/branch-1.3/FL/Fl_Device.H
===================================================================
--- branches/branch-1.3/FL/Fl_Device.H  2010-03-16 18:27:19 UTC (rev 7279)
+++ branches/branch-1.3/FL/Fl_Device.H  2010-03-16 22:51:31 UTC (rev 7280)
@@ -7,6 +7,7 @@
 #define Fl_Device_H
 
 #include <FL/x.H>
+#include <FL/Fl_Plugin.H>
 #ifdef WIN32
 #include <Commdlg.h>
 #elif defined(__APPLE__)
@@ -19,6 +20,7 @@
 class Fl_Pixmap;
 class Fl_Bitmap;
 class Fl_Display;
+class Fl_Virtual_Printer;
 extern Fl_Display *fl_display_device;
 typedef void (*Fl_Draw_Image_Cb)(void* ,int,int,int,uchar*);
 
@@ -200,4 +202,18 @@
 };
 #endif
 
+/*
+ This plugin socket allows the integration of new device drivers for special
+ window or screen types. It is currently used to provide an automated printing
+ service for OpenGL windows, if linked with fltk_gl.
+ */
+class Fl_Device_Plugin : public Fl_Plugin {
+public:
+  Fl_Device_Plugin(const char *name)
+  : Fl_Plugin(klass(), name) { }
+  virtual const char *klass() { return "fltk:device"; }
+  virtual const char *name() = 0;
+  virtual int print(Fl_Virtual_Printer*, Fl_Widget*, int x, int y) { return 0; 
}
+};
+
 #endif // Fl_Device_H

Modified: branches/branch-1.3/FL/Fl_Gl_Window.H
===================================================================
--- branches/branch-1.3/FL/Fl_Gl_Window.H       2010-03-16 18:27:19 UTC (rev 
7279)
+++ branches/branch-1.3/FL/Fl_Gl_Window.H       2010-03-16 22:51:31 UTC (rev 
7280)
@@ -205,6 +205,13 @@
   */
   void make_overlay_current();
 
+  /** Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.   
+   \retval NULL if this widget is not derived from Fl_Gl_Window.
+   \note This method is provided to avoid dynamic_cast.
+   \todo More documentation ...
+   */
+  virtual Fl_Gl_Window* as_gl_window() {return this;}
+  
   ~Fl_Gl_Window();
   /**
     Creates a new Fl_Gl_Window widget using the given size, and label string. 

Modified: branches/branch-1.3/FL/Fl_Group.H
===================================================================
--- branches/branch-1.3/FL/Fl_Group.H   2010-03-16 18:27:19 UTC (rev 7279)
+++ branches/branch-1.3/FL/Fl_Group.H   2010-03-16 22:51:31 UTC (rev 7280)
@@ -182,7 +182,7 @@
       \note This method is provided to avoid dynamic_cast.
       \todo More documentation ...
    */
-  virtual Fl_Group* as_group() const { return (Fl_Group*)this; }
+  virtual Fl_Group* as_group() { return this; }
 
   // back compatibility functions:
 

Modified: branches/branch-1.3/FL/Fl_Widget.H
===================================================================
--- branches/branch-1.3/FL/Fl_Widget.H  2010-03-16 18:27:19 UTC (rev 7279)
+++ branches/branch-1.3/FL/Fl_Widget.H  2010-03-16 22:51:31 UTC (rev 7280)
@@ -930,16 +930,23 @@
       \note This method is provided to avoid dynamic_cast.
       \todo More documentation ...
    */
-  virtual Fl_Group* as_group() const {return 0;}
+  virtual Fl_Group* as_group() {return 0;}
 
   /** Returns an Fl_Window pointer if this widget is an Fl_Window.
+   
+   \retval NULL if this widget is not derived from Fl_Window.
+   \note This method is provided to avoid dynamic_cast.
+   \todo More documentation ...
+   */
+  virtual Fl_Window* as_window() {return 0;}
   
-      \retval NULL if this widget is not derived from Fl_Window.
-      \note This method is provided to avoid dynamic_cast.
-      \todo More documentation ...
+  /** Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.   
+   \retval NULL if this widget is not derived from Fl_Gl_Window.
+   \note This method is provided to avoid dynamic_cast.
+   \todo More documentation ...
    */
-  virtual Fl_Window* as_window() const {return 0;}
-
+  virtual class Fl_Gl_Window* as_gl_window() {return 0;}
+  
   /** For back compatibility only.
       \deprecated Use selection_color() instead.
   */

Modified: branches/branch-1.3/FL/Fl_Window.H
===================================================================
--- branches/branch-1.3/FL/Fl_Window.H  2010-03-16 18:27:19 UTC (rev 7279)
+++ branches/branch-1.3/FL/Fl_Window.H  2010-03-16 22:51:31 UTC (rev 7280)
@@ -421,7 +421,7 @@
       \note This method is provided to avoid dynamic_cast.
       \todo More documentation ...
    */
-  virtual Fl_Window* as_window() const { return (Fl_Window*)this; }
+  virtual Fl_Window* as_window() { return this; }
 
   // for back-compatibility only:
   /**

Modified: branches/branch-1.3/src/Fl_Device.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Device.cxx       2010-03-16 18:27:19 UTC (rev 
7279)
+++ branches/branch-1.3/src/Fl_Device.cxx       2010-03-16 22:51:31 UTC (rev 
7280)
@@ -52,7 +52,16 @@
 #else
   _XGC *save_gc = fl_gc;       // FIXME
 #endif
-  widget->draw();
+  // we do some trickery to recognize OpenGL windows and draw them via a plugin
+  int drawn_by_plugin = 0;
+  if (widget->as_gl_window()) {
+    Fl_Plugin_Manager pm("fltk:device");  
+    Fl_Device_Plugin *pi = 
(Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+    if (pi) drawn_by_plugin = pi->print(this, widget, 0, 0);
+  }
+  if (!drawn_by_plugin)
+    widget->draw(); 
+  
   fl_gc = save_gc;
   if (is_window) fl_pop_clip();
   // find subwindows of widget and print them

Modified: branches/branch-1.3/src/Fl_Gl_Printer.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Gl_Printer.cxx   2010-03-16 18:27:19 UTC (rev 
7279)
+++ branches/branch-1.3/src/Fl_Gl_Printer.cxx   2010-03-16 22:51:31 UTC (rev 
7280)
@@ -89,3 +89,25 @@
   free(baseAddress);
 #endif // __APPLE__
 }
+
+/*
+ This class will make sure that OpenGL printing is availbale if fltk_gl
+ was linked to the programm.
+ */
+class Fl_Gl_Device_Plugin : public Fl_Device_Plugin {
+public:
+  Fl_Gl_Device_Plugin() : Fl_Device_Plugin(name()) { }
+  virtual const char *name() { return "opengl.device.fltk.org"; }
+  virtual int print(Fl_Virtual_Printer *p, Fl_Widget *w, int x, int y) {
+    Fl_Gl_Window *glw = w->as_gl_window();
+    if (!glw) return 0;
+    // FIXME: this is a dangerous cast! Remove Fl_Gl_Printer entirely and add 
+    // FIXME: a static function (may be a friend of Fl_Printer).
+    Fl_Gl_Printer *glp = (Fl_Gl_Printer*)p;
+    glp->print_gl_window(glw, x, y);
+    return 1; 
+  }
+};
+
+static Fl_Gl_Device_Plugin Gl_Device_Plugin;
+

Modified: branches/branch-1.3/test/cube.cxx
===================================================================
--- branches/branch-1.3/test/cube.cxx   2010-03-16 18:27:19 UTC (rev 7279)
+++ branches/branch-1.3/test/cube.cxx   2010-03-16 22:51:31 UTC (rev 7280)
@@ -168,7 +168,7 @@
   if(!win) return;
   if( printer.start_job(1) ) return;
   if( printer.start_page() ) return;
-  printer.scale(0.68,0.68);
+  printer.scale(0.5,0.5);
   printer.print_widget( win );
   printer.print_gl_window( cube, cube->x(), cube->y() );
   printer.print_gl_window( cube2, cube2->x(), cube2->y() );

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to