diff options
| author | Manolo Gouy <Manolo> | 2010-04-16 20:19:09 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2010-04-16 20:19:09 +0000 |
| commit | 913530758af63f00676c6746988aef8b35b02531 (patch) | |
| tree | d6b59be15047e3c2742158eb5063aca55ea94eba /FL/Fl_Device.H | |
| parent | 0f180e130639f1017e7ca6b668357304632c1a62 (diff) | |
Improved the hierarchy of Fl_Device subclasses to allow separation of platform-specific devices.
This introduces multiple inheritance.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7520 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL/Fl_Device.H')
| -rw-r--r-- | FL/Fl_Device.H | 137 |
1 files changed, 83 insertions, 54 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index 8eaaa0c87..ad8506f1e 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -1,8 +1,8 @@ // // "$Id$" // -// Definition of classes Fl_Device, Fl_Display, Fl_Quartz_Display, Fl_GDI_Display, -// and Fl_Xlib_Display for the Fast Light Tool Kit (FLTK). +// Definition of classes Fl_Device, Fl_Display_Device, Fl_Graphics_Device +// for the Fast Light Tool Kit (FLTK). // // Copyright 2010 by Bill Spitzak and others. // @@ -26,7 +26,7 @@ // http://www.fltk.org/str.php // /** \file Fl_Device.H - \brief declaration of classes Fl_Device, Fl_Display. + \brief declaration of classes Fl_Device, Fl_Display_Device. */ #ifndef Fl_Device_H @@ -45,14 +45,12 @@ #include <stdio.h> #endif -class Fl_Widget; class Fl_Device; -class Fl_Display; -class Fl_Abstract_Printer; +class Fl_Display_Device; /** \brief Points to the device that currently receives all graphics requests */ -FL_EXPORT extern Fl_Device *fl_device; +extern Fl_Device *fl_device; /** \brief Points to the platform's display device */ -FL_EXPORT extern Fl_Display *fl_display_device; +extern Fl_Display_Device *fl_display_device; /** signature of image generation callback function. @@ -71,18 +69,18 @@ typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf); support all of FLTK drawing functions. <br> The preferred FLTK API for drawing operations is the function collection of the \ref fl_drawings and \ref fl_attributes modules. - <br> Alternatively, member functions of the Fl_Device class can be called + <br> Alternatively, methods of the Fl_Device class can be called using the global variable Fl_Device * \ref fl_device that points at all time to the single device (an instance of an Fl_Device subclass) that's currently receiving graphics requests: \code fl_device->rect(x, y, w, h); \endcode - <br>Each member function of the Fl_Device class has the same effect and parameter list as the + <br>Each protected method of the Fl_Device class has the same effect as the function of the \ref fl_drawings and \ref fl_attributes modules which bears the same name - prefixed with fl_ . + prefixed with fl_ and has the same parameter list. */ class Fl_Device { protected: /** \brief The device type */ - int type_; + const char *type_; /** \brief red color for background and/or mixing if device does not support masking or alpha */ uchar bg_r_; /** \brief green color for background and/or mixing if device does not support masking or alpha */ @@ -92,6 +90,7 @@ protected: friend class Fl_Pixmap; friend class Fl_Bitmap; friend class Fl_RGB_Image; + friend class Fl_PS_Device; friend void fl_rect(int x, int y, int w, int h); friend void fl_rectf(int x, int y, int w, int h); friend void fl_line_style(int style, int width, char* dashes); @@ -239,73 +238,103 @@ protected: /** \brief see fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D). */ virtual void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); // Image classes - virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy); - virtual void draw(Fl_Bitmap * bmp,int XP, int YP, int WP, int HP, int cx, int cy); - virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy); - -public: - /** - @brief All implemented graphics output devices. + /** \brief Draws an Fl_RGB_Image object to the device. + * + Specifies a bounding box for the image, with the origin (upper left-hand corner) of + the image offset by the cx and cy arguments. + */ + virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) {}; + /** \brief Draws an Fl_Pixmap object to the device. + * + Specifies a bounding box for the image, with the origin (upper left-hand corner) of + the image offset by the cx and cy arguments. */ - enum device_types { - xlib_display = 0, /**< The X11 display. */ - quartz_display, /**< The Mac OS X display. */ - gdi_display, /**< The MSWindows display. */ - gdi_printer = 256, /**< The MSWindows printer. */ - quartz_printer, /**< The Mac OS X printer. */ - postscript_device /**< The PostScript device. */ - }; + virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) {}; + /** \brief Draws an Fl_Bitmap object to the device. + * + Specifies a bounding box for the image, with the origin (upper left-hand corner) of + the image offset by the cx and cy arguments. + */ + virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {}; + +public: + /** A name that identifies each subclass of Fl_Device */ + static const char *device_type; /** - @brief An RTTI emulation of device classes. It returns values < 256 if it is a display device + @brief An RTTI emulation of device classes. + * + The type of an instance of an Fl_Device subclass can be checked with code such as: + \code + if ( fl_device->type() == Fl_Printer::device_type ) { ... } + \endcode */ - inline int type() {return type_;}; + inline const char *type() {return type_;}; virtual Fl_Device *set_current(void); - + virtual ~Fl_Device() {}; static Fl_Device *current(); /** @brief Returns the platform's display device. */ - static Fl_Display *display_device() { return fl_display_device; }; + static Fl_Display_Device *display_device() { return fl_display_device; }; }; -extern FL_EXPORT Fl_Device *fl_device; -/** - @brief A virtual class subclassed for OS-specific display graphics. - */ -class Fl_Display : public Fl_Device { - friend class Fl_PSfile_Device; +#if defined(__APPLE__) +// The Mac OS X-specific graphics class. +class Fl_Graphics_Device : public Fl_Device { +protected: + Fl_Graphics_Device() { type_ = device_type; }; +public: + static const char *device_type; + 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); }; +typedef Fl_Graphics_Device Fl_Quartz_Device; -#if defined(__APPLE__) || defined(FL_DOXYGEN) -/** - @brief The Mac OS X-specific display graphics class. - */ -class Fl_Quartz_Display : public Fl_Display { +#elif defined(WIN32) +// The MSWindows-specific graphics class. +class Fl_Graphics_Device : public Fl_Device { +protected: + Fl_Graphics_Device() { type_ = device_type; }; public: - Fl_Quartz_Display() { type_ = quartz_display; }; + static const char *device_type; + 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); }; -#endif -#if defined(WIN32) || defined(FL_DOXYGEN) +typedef Fl_Graphics_Device Fl_GDI_Device; + +#else /** - @brief The MSWindows-specific display graphics class. + @brief A class representing OS-specific graphics system. + * + This class is also named Fl_Quartz_Device on Mac OS X, Fl_GDI_Device on MS-Win, Fl_Xlib_Device on X11. + A graphics system can be shared by various devices (e.g., display, printer, clipboard). */ -class Fl_GDI_Display : public Fl_Display { +class Fl_Graphics_Device : public Fl_Device { +protected: + Fl_Graphics_Device() { type_ = device_type; }; public: - Fl_GDI_Display() { type_ = gdi_display; }; + static const char *device_type; + 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); }; +typedef Fl_Graphics_Device Fl_Xlib_Device; #endif -#if !( defined(__APPLE__) || defined(WIN32)) || defined(FL_DOXYGEN) + /** - @brief The X11-specific display graphics class. - */ -class Fl_Xlib_Display : public Fl_Display { + @brief The platform's display. +*/ +class Fl_Display_Device : public Fl_Graphics_Device { public: - Fl_Xlib_Display() { type_ = xlib_display; }; + static const char *device_type; + Fl_Display_Device() { type_ = device_type; }; }; -#endif + #endif // Fl_Device_H |
