FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Device.H
Go to the documentation of this file.

    00001 //
    00002 // "$Id: Fl_Device.H 9706 2012-11-06 20:46:14Z matt $"
    00003 //
    00004 // Definition of classes Fl_Device, Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
    00005 // for the Fast Light Tool Kit (FLTK).
    00006 //
    00007 // Copyright 2010-2012 by Bill Spitzak and others.
    00008 //
    00009 // This library is free software. Distribution and use rights are outlined in
    00010 // the file "COPYING" which should have been included with this file.  If this
    00011 // file is missing or damaged, see the license at:
    00012 //
    00013 //     http://www.fltk.org/COPYING.php
    00014 //
    00015 // Please report all bugs and problems on the following page:
    00016 //
    00017 //     http://www.fltk.org/str.php
    00018 //
    00019
    00025 #ifndef Fl_Device_H
    00026 #define Fl_Device_H
    00027
    00028 #include <FL/x.H>
    00029 #include <FL/Fl_Plugin.H>
    00030 #include <FL/Fl_Image.H>
    00031 #include <FL/Fl_Bitmap.H>
    00032 #include <FL/Fl_Pixmap.H>
    00033 #include <FL/Fl_RGB_Image.H>
    00034 #include <stdlib.h>
    00035
    00036 class Fl_Graphics_Driver;
    00037 class Fl_Font_Descriptor;
    00039 FL_EXPORT extern Fl_Graphics_Driver *fl_graphics_driver;
    00040
    00049 typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);
    00050
    00051 // typedef what the x,y fields in a point are:
    00052 #ifdef WIN32
    00053 typedef int COORD_T;
    00054 #  define XPOINT XPoint
    00055 #elif defined(__APPLE__)
    00056 typedef float COORD_T;
    00057 typedef struct { float x; float y; } QPoint;
    00058 #  define XPOINT QPoint
    00059 extern float fl_quartz_line_width_;
    00060 #else
    00061 typedef short COORD_T;
    00062 #  define XPOINT XPoint
    00063 #endif
    00064
    00068 class FL_EXPORT Fl_Device {
    00069 public:
    00073   static const char *class_id;
    00083   virtual const char *class_name() {return class_id;};
    00090   virtual ~Fl_Device() {};
    00091 };
    00092
    00093 #define FL_REGION_STACK_SIZE 10
    00094 #define FL_MATRIX_STACK_SIZE 32
    00095
    00103 class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
    00104 public:
    00107   struct matrix {double a, b, c, d, x, y;};
    00108 private:
    00109   static const matrix m0;
    00110   Fl_Font font_; // current font
    00111   Fl_Fontsize size_; // current font size
    00112   Fl_Color color_; // current color
    00113   int sptr;
    00114   static const int matrix_stack_size = FL_MATRIX_STACK_SIZE;
    00115   matrix stack[FL_MATRIX_STACK_SIZE];
    00116   matrix m;
    00117   int n, p_size, gap_;
    00118   XPOINT *p;
    00119   int what;
    00120   int fl_clip_state_number;
    00121   int rstackptr;
    00122   static const int region_stack_max = FL_REGION_STACK_SIZE - 1;
    00123   Fl_Region rstack[FL_REGION_STACK_SIZE];
    00124 #ifdef WIN32
    00125   int numcount;
    00126   int counts[20];
    00127 #endif
    00128   Fl_Font_Descriptor *font_descriptor_;
    00129   void transformed_vertex0(COORD_T x, COORD_T y);
    00130   void fixloop();
    00131
    00132 protected:
    00133 #ifndef FL_DOXYGEN
    00134   enum {LINE, LOOP, POLYGON, POINT_};
    00135   inline int vertex_no() { return n; }
    00136   inline XPOINT *vertices() {return p;}
    00137   inline int vertex_kind() {return what;}
    00138 #endif
    00139 /*  ** \brief red color for background and/or mixing if device does not support masking or alpha *
    00140   uchar bg_r_;
    00141   ** \brief green color for background and/or mixing if device does not support masking or alpha *
    00142   uchar bg_g_;
    00143   ** \brief blue color for background and/or mixing if device does not support masking or alpha *
    00144   uchar bg_b_; */
    00145   friend class Fl_Pixmap;
    00146   friend class Fl_Bitmap;
    00147   friend class Fl_RGB_Image;
    00148   friend void fl_rect(int x, int y, int w, int h);
    00149   friend void fl_rectf(int x, int y, int w, int h);
    00150   friend void fl_line_style(int style, int width, char* dashes);
    00151   friend void fl_xyline(int x, int y, int x1);
    00152   friend void fl_xyline(int x, int y, int x1, int y2);
    00153   friend void fl_xyline(int x, int y, int x1, int y2, int x3);
    00154   friend void fl_yxline(int x, int y, int y1);
    00155   friend void fl_yxline(int x, int y, int y1, int x2);
    00156   friend void fl_yxline(int x, int y, int y1, int x2, int y3);
    00157   friend void fl_line(int x, int y, int x1, int y1);
    00158   friend void fl_line(int x, int y, int x1, int y1, int x2, int y2);
    00159   friend void fl_draw(const char *str, int n, int x, int y);
    00160 #ifdef __APPLE__
    00161   friend void fl_draw(const char *str, int n, float x, float y);
    00162 #endif
    00163   friend void fl_draw(int angle, const char *str, int n, int x, int y);
    00164   friend void fl_rtl_draw(const char *str, int n, int x, int y);
    00165   friend void fl_font(Fl_Font face, Fl_Fontsize size);
    00166   friend void fl_color(Fl_Color c);
    00167   friend void fl_color(uchar r, uchar g, uchar b);
    00168   friend void fl_point(int x, int y);
    00169   friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2);
    00170   friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
    00171   friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2);
    00172   friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
    00173   friend void fl_begin_points();
    00174   friend void fl_begin_line();
    00175   friend void fl_begin_loop();
    00176   friend void fl_begin_polygon();
    00177   friend void fl_vertex(double x, double y);
    00178   friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
    00179   friend void fl_circle(double x, double y, double r);
    00180   friend void fl_arc(double x, double y, double r, double start, double end);
    00181   friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
    00182   friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
    00183   friend void fl_end_points();
    00184   friend void fl_end_line();
    00185   friend void fl_end_loop();
    00186   friend void fl_end_polygon();
    00187   friend void fl_transformed_vertex(double xf, double yf);
    00188   friend void fl_push_clip(int x, int y, int w, int h);
    00189   friend int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
    00190   friend int fl_not_clipped(int x, int y, int w, int h);
    00191   friend void fl_push_no_clip();
    00192   friend void fl_pop_clip();
    00193   friend void fl_begin_complex_polygon();
    00194   friend void fl_gap();
    00195   friend void fl_end_complex_polygon();
    00196   friend void fl_push_matrix();
    00197   friend void fl_pop_matrix();
    00198   friend void fl_mult_matrix(double a, double b, double c, double d, double x, double y);
    00199   friend void fl_scale(double x, double y);
    00200   friend void fl_scale(double x);
    00201   friend void fl_translate(double x, double y);
    00202   friend void fl_rotate(double d);
    00203   friend double fl_transform_x(double x, double y);
    00204   friend double fl_transform_y(double x, double y);
    00205   friend double fl_transform_dx(double x, double y);
    00206   friend double fl_transform_dy(double x, double y);
    00207   friend Fl_Region fl_clip_region();
    00208   friend void fl_clip_region(Fl_Region r);
    00209   friend void fl_restore_clip();
    00210
    00211   friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
    00212   friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
    00213   friend void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
    00214   friend FL_EXPORT void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
    00215   friend FL_EXPORT void gl_start();
    00216   friend void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
    00217   matrix *fl_matrix;
    00220   Fl_Graphics_Driver();
    00222   virtual void rect(int x, int y, int w, int h);
    00224   virtual void rectf(int x, int y, int w, int h);
    00226   virtual void line_style(int style, int width=0, char* dashes=0);
    00228   virtual void xyline(int x, int y, int x1);
    00230   virtual void xyline(int x, int y, int x1, int y2);
    00232   virtual void xyline(int x, int y, int x1, int y2, int x3);
    00234   virtual void yxline(int x, int y, int y1);
    00236   virtual void yxline(int x, int y, int y1, int x2);
    00238   virtual void yxline(int x, int y, int y1, int x2, int y3);
    00240   virtual void line(int x, int y, int x1, int y1);
    00242   virtual void line(int x, int y, int x1, int y1, int x2, int y2);
    00244   virtual void draw(const char *str, int n, int x, int y) {}
    00245 #ifdef __APPLE__
    00246   virtual void draw(const char *str, int n, float x, float y) { draw(str, n, (int)(x+0.5), (int)(y+0.5));}
    00247 #endif
    00248
    00249   virtual void draw(int angle, const char *str, int n, int x, int y) {}
    00251   virtual void rtl_draw(const char *str, int n, int x, int y) {};
    00253   virtual void color(Fl_Color c) {color_ = c;}
    00255   virtual void color(uchar r, uchar g, uchar b) {}
    00257   virtual void point(int x, int y);
    00259   virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2);
    00261   virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
    00263   virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
    00265   virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
    00267   virtual void begin_points();
    00269   virtual void begin_line();
    00271   virtual void begin_loop();
    00273   virtual void begin_polygon();
    00275   virtual void vertex(double x, double y);
    00277   virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
    00279   virtual void circle(double x, double y, double r);
    00281   virtual void arc(double x, double y, double r, double start, double end);
    00283   virtual void arc(int x, int y, int w, int h, double a1, double a2);
    00285   virtual void pie(int x, int y, int w, int h, double a1, double a2);
    00287   virtual void end_points();
    00289   virtual void end_line();
    00291   virtual void end_loop();
    00293   virtual void end_polygon();
    00295   virtual void begin_complex_polygon();
    00297   virtual void gap();
    00299   virtual void end_complex_polygon();
    00301   virtual void transformed_vertex(double xf, double yf);
    00303   virtual void push_clip(int x, int y, int w, int h);
    00305   virtual int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
    00307   virtual int not_clipped(int x, int y, int w, int h);
    00309   virtual void push_no_clip();
    00311   virtual void pop_clip();
    00312
    00314   void push_matrix();
    00316   void pop_matrix();
    00318   void mult_matrix(double a, double b, double c, double d, double x, double y);
    00320   inline void scale(double x, double y) { mult_matrix(x,0,0,y,0,0); }
    00322   inline void scale(double x) { mult_matrix(x,0,0,x,0,0); }
    00324   inline void translate(double x,double y) { mult_matrix(1,0,0,1,x,y); }
    00326   void rotate(double d);
    00328   double transform_x(double x, double y);
    00330   double transform_y(double x, double y);
    00332   double transform_dx(double x, double y);
    00334   double transform_dy(double x, double y);
    00336   Fl_Region clip_region();
    00338   void clip_region(Fl_Region r);
    00340   void restore_clip();
    00341
    00342   // Images
    00344   virtual   void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) {}
    00346   virtual   void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0) {}
    00348   virtual   void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3) {}
    00350   virtual   void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1) {}
    00351   // Image classes
    00357   virtual   void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) {}
    00363   virtual   void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) {}
    00369   virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {}
    00370 #if FLTK_ABI_VERSION >= 10301
    00371   virtual
    00372 #endif
    00373   void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
    00374
    00375 public:
    00376   static const char *class_id;
    00377   virtual const char *class_name() {return class_id;};
    00379   virtual void font(Fl_Font face, Fl_Fontsize fsize) {font_ = face; size_ = fsize;}
    00381   Fl_Font font() {return font_; }
    00383   Fl_Fontsize size() {return size_; }
    00385   virtual double width(const char *str, int n) {return 0;}
    00387   virtual inline double width(unsigned int c) { char ch = (char)c; return width(&ch, 1); }
    00389   virtual void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
    00391   virtual int height() {return size();}
    00393   virtual int descent() {return 0;}
    00395   Fl_Color color() {return color_;}
    00397   inline Fl_Font_Descriptor *font_descriptor() { return font_descriptor_;}
    00399   inline void font_descriptor(Fl_Font_Descriptor *d) { font_descriptor_ = d;}
    00401   virtual ~Fl_Graphics_Driver() { if (p) free(p); }
    00402 };
    00403
    00404 #if defined(__APPLE__) || defined(FL_DOXYGEN)
    00405
    00410 class FL_EXPORT Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver {
    00411 public:
    00412   static const char *class_id;
    00413   const char *class_name() {return class_id;};
    00414   void color(Fl_Color c);
    00415   void color(uchar r, uchar g, uchar b);
    00416   void draw(const char* str, int n, int x, int y);
    00417 #ifdef __APPLE__
    00418   void draw(const char *str, int n, float x, float y);
    00419 #endif
    00420   void draw(int angle, const char *str, int n, int x, int y);
    00421   void rtl_draw(const char* str, int n, int x, int y);
    00422   void font(Fl_Font face, Fl_Fontsize size);
    00423   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00424   void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00425   void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
    00426   void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
    00427   void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
    00428   void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
    00429   void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
    00430   double width(const char *str, int n);
    00431   double width(unsigned int c);
    00432   void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
    00433   int height();
    00434   int descent();
    00435 #if ! defined(FL_DOXYGEN)
    00436   static Fl_Offscreen create_offscreen_with_alpha(int w, int h);
    00437 #endif
    00438   void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
    00439 };
    00440 #endif
    00441 #if defined(WIN32) || defined(FL_DOXYGEN)
    00442
    00447 class FL_EXPORT Fl_GDI_Graphics_Driver : public Fl_Graphics_Driver {
    00448 public:
    00449   static const char *class_id;
    00450   const char *class_name() {return class_id;};
    00451   void color(Fl_Color c);
    00452   void color(uchar r, uchar g, uchar b);
    00453   void draw(const char* str, int n, int x, int y);
    00454   void draw(int angle, const char *str, int n, int x, int y);
    00455   void rtl_draw(const char* str, int n, int x, int y);
    00456   void font(Fl_Font face, Fl_Fontsize size);
    00457   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00458   void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00459   void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
    00460   void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
    00461   void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
    00462   void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
    00463   void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
    00464   double width(const char *str, int n);
    00465   double width(unsigned int c);
    00466   void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
    00467   int height();
    00468   int descent();
    00469 #if ! defined(FL_DOXYGEN)
    00470   void copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy);
    00471 #endif
    00472   void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
    00473 };
    00474
    00480 class FL_EXPORT Fl_GDI_Printer_Graphics_Driver : public Fl_GDI_Graphics_Driver {
    00481 public:
    00482   static const char *class_id;
    00483   const char *class_name() {return class_id;};
    00484   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00485 };
    00486 #endif
    00487 #if !(defined(__APPLE__) || defined(WIN32))
    00488
    00493 class Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver {
    00494 public:
    00495   static const char *class_id;
    00496   const char *class_name() {return class_id;};
    00497   void color(Fl_Color c);
    00498   void color(uchar r, uchar g, uchar b);
    00499   void draw(const char* str, int n, int x, int y);
    00500   void draw(int angle, const char *str, int n, int x, int y);
    00501   void rtl_draw(const char* str, int n, int x, int y);
    00502   void font(Fl_Font face, Fl_Fontsize size);
    00503   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00504   void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
    00505   void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
    00506   void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
    00507   void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
    00508   void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
    00509   void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
    00510   double width(const char *str, int n);
    00511   double width(unsigned int c);
    00512   void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
    00513   int height();
    00514   int descent();
    00515   void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
    00516 };
    00517 #endif
    00518
    00522 class FL_EXPORT Fl_Surface_Device : public Fl_Device {
    00524   Fl_Graphics_Driver *_driver;
    00525   static Fl_Surface_Device *_surface; // the surface that currently receives graphics output
    00526 protected:
    00528   Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver; };
    00529 public:
    00530   static const char *class_id;
    00531   const char *class_name() {return class_id;};
    00532   virtual void set_current(void);
    00534   inline void driver(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver;};
    00536   inline Fl_Graphics_Driver *driver() {return _driver; };
    00538   static inline Fl_Surface_Device *surface() {return _surface; };
    00540   virtual ~Fl_Surface_Device() {}
    00541 };
    00542
    00546 class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
    00547   static Fl_Display_Device *_display; // the platform display device
    00548 public:
    00549   static const char *class_id;
    00550   const char *class_name() {return class_id;};
    00552   Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
    00554   static inline Fl_Display_Device *display_device() {return _display;};
    00555 };
    00556
    00562 class FL_EXPORT Fl_Device_Plugin : public Fl_Plugin {
    00563 public:
    00565   Fl_Device_Plugin(const char *pluginName)
    00566   : Fl_Plugin(klass(), pluginName) { }
    00568   virtual const char *klass() { return "fltk:device"; }
    00570   virtual const char *name() = 0;
    00576   virtual int print(Fl_Widget* w, int x, int y, int height) = 0;
    00577 };
    00578
    00579 #endif // Fl_Device_H
    00580
    00581 //
    00582 // End of "$Id: Fl_Device.H 9706 2012-11-06 20:46:14Z matt $".
    00583 //