You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

640 lines
27KB

  1. //
  2. // "$Id: Fl_Device.H 8529 2011-03-23 12:49:30Z AlbrechtS $"
  3. //
  4. // Definition of classes Fl_Device, Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
  5. // for the Fast Light Tool Kit (FLTK).
  6. //
  7. // Copyright 2010-2011 by Bill Spitzak and others.
  8. //
  9. // This library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Library General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. // Library General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU Library General Public
  20. // License along with this library; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. // USA.
  23. //
  24. // Please report all bugs and problems on the following page:
  25. //
  26. // http://www.fltk.org/str.php
  27. //
  28. /** \file Fl_Device.H
  29. \brief declaration of classes Fl_Device, Fl_Graphics_Driver, Fl_Surface_Device,
  30. Fl_Display_Device, Fl_Device_Plugin.
  31. */
  32. #ifndef Fl_Device_H
  33. #define Fl_Device_H
  34. #include <FL/x.H>
  35. #include <FL/Fl_Plugin.H>
  36. #include <FL/Fl_Image.H>
  37. #include <FL/Fl_Bitmap.H>
  38. #include <FL/Fl_Pixmap.H>
  39. #include <FL/Fl_RGB_Image.H>
  40. #if FLTK_USE_CAIRO
  41. #include <FL/Fl_Cairo.H>
  42. #endif
  43. class Fl_Graphics_Driver;
  44. class Fl_Font_Descriptor;
  45. /** \brief Points to the driver that currently receives all graphics requests */
  46. FL_EXPORT extern Fl_Graphics_Driver *fl_graphics_driver;
  47. /**
  48. signature of image generation callback function.
  49. \param[in] data user data passed to function
  50. \param[in] x,y,w position and width of scan line in image
  51. \param[out] buf buffer for generated image data. You must copy \p w
  52. pixels from scanline \p y, starting at pixel \p x
  53. to this buffer.
  54. */
  55. typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);
  56. // typedef what the x,y fields in a point are:
  57. #ifdef WIN32
  58. typedef int COORD_T;
  59. # define XPOINT XPoint
  60. #elif defined(__APPLE__)
  61. typedef float COORD_T;
  62. typedef struct { float x; float y; } QPoint;
  63. # define XPOINT QPoint
  64. extern float fl_quartz_line_width_;
  65. #else
  66. typedef short COORD_T;
  67. # define XPOINT XPoint
  68. #endif
  69. /**
  70. \brief All graphical output devices and all graphics systems.
  71. */
  72. class FL_EXPORT Fl_Device {
  73. public:
  74. /** A string that identifies each subclass of Fl_Device.
  75. Function class_name() applied to a device of this class returns this string.
  76. */
  77. static const char *class_id;
  78. /**
  79. Returns the name of the class of this object.
  80. The class of an instance of an Fl_Device subclass can be checked with code such as:
  81. \code
  82. if ( instance->class_name() == Fl_Printer::class_id ) { ... }
  83. \endcode
  84. */
  85. virtual const char *class_name() {return class_id;};
  86. /**
  87. Virtual destructor.
  88. The destructor of Fl_Device must be virtual to make the destructors of
  89. derived classes being called correctly on destruction.
  90. */
  91. virtual ~Fl_Device() {};
  92. };
  93. #define FL_REGION_STACK_SIZE 10
  94. #define FL_MATRIX_STACK_SIZE 32
  95. /**
  96. \brief A virtual class subclassed for each graphics driver FLTK uses.
  97. *
  98. The virtual methods of this class are those that a graphics driver should implement to
  99. support all of FLTK drawing functions.
  100. <br> The public API for drawing operations is functionally presented in \ref drawing and as function lists
  101. in the \ref fl_drawings and \ref fl_attributes modules.
  102. */
  103. class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
  104. public:
  105. /** A 2D coordinate transformation matrix
  106. */
  107. struct matrix {double a, b, c, d, x, y;};
  108. private:
  109. static const matrix m0;
  110. static Fl_Font font_; // current font
  111. static Fl_Fontsize size_; // current font size
  112. static Fl_Color color_; // current color
  113. static int sptr;
  114. static const int matrix_stack_size = FL_MATRIX_STACK_SIZE;
  115. static matrix stack[FL_MATRIX_STACK_SIZE];
  116. static matrix m;
  117. protected:
  118. enum {LINE, LOOP, POLYGON, POINT_};
  119. static int n;
  120. static int p_size;
  121. static int gap_;
  122. static XPOINT *p;
  123. static int what;
  124. private:
  125. static int fl_clip_state_number;
  126. static int rstackptr;
  127. static const int region_stack_max = FL_REGION_STACK_SIZE - 1;
  128. static Fl_Region rstack[FL_REGION_STACK_SIZE];
  129. #ifdef WIN32
  130. int numcount;
  131. int counts[20];
  132. #endif
  133. Fl_Font_Descriptor *font_descriptor_;
  134. public:
  135. static matrix *fl_matrix; /**< Points to the current coordinate transformation matrix */
  136. protected:
  137. void transformed_vertex0(COORD_T x, COORD_T y);
  138. void fixloop();
  139. /* ** \brief red color for background and/or mixing if device does not support masking or alpha *
  140. uchar bg_r_;
  141. ** \brief green color for background and/or mixing if device does not support masking or alpha *
  142. uchar bg_g_;
  143. ** \brief blue color for background and/or mixing if device does not support masking or alpha *
  144. uchar bg_b_; */
  145. friend class Fl_Pixmap;
  146. friend class Fl_Bitmap;
  147. friend class Fl_RGB_Image;
  148. friend void fl_rect(int x, int y, int w, int h);
  149. friend void fl_rectf(int x, int y, int w, int h);
  150. friend void fl_line_style(int style, int width, char* dashes);
  151. friend void fl_xyline(int x, int y, int x1);
  152. friend void fl_xyline(int x, int y, int x1, int y2);
  153. friend void fl_xyline(int x, int y, int x1, int y2, int x3);
  154. friend void fl_yxline(int x, int y, int y1);
  155. friend void fl_yxline(int x, int y, int y1, int x2);
  156. friend void fl_yxline(int x, int y, int y1, int x2, int y3);
  157. friend void fl_line(int x, int y, int x1, int y1);
  158. friend void fl_line(int x, int y, int x1, int y1, int x2, int y2);
  159. friend void fl_draw(const char *str, int n, int x, int y);
  160. #ifdef __APPLE__
  161. friend void fl_draw(const char *str, int n, float x, float y);
  162. #endif
  163. friend void fl_draw(int angle, const char *str, int n, int x, int y);
  164. friend void fl_rtl_draw(const char *str, int n, int x, int y);
  165. friend void fl_font(Fl_Font face, Fl_Fontsize size);
  166. friend void fl_color(Fl_Color c);
  167. friend void fl_color(uchar r, uchar g, uchar b);
  168. friend void fl_point(int x, int y);
  169. friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2);
  170. friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  171. friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  172. friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  173. friend void fl_begin_points();
  174. friend void fl_begin_line();
  175. friend void fl_begin_loop();
  176. friend void fl_begin_polygon();
  177. friend void fl_vertex(double x, double y);
  178. friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
  179. friend void fl_circle(double x, double y, double r);
  180. friend void fl_arc(double x, double y, double r, double start, double end);
  181. friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
  182. friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
  183. friend void fl_end_points();
  184. friend void fl_end_line();
  185. friend void fl_end_loop();
  186. friend void fl_end_polygon();
  187. friend void fl_transformed_vertex(double xf, double yf);
  188. friend void fl_push_clip(int x, int y, int w, int h);
  189. friend int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  190. friend int fl_not_clipped(int x, int y, int w, int h);
  191. friend void fl_push_no_clip();
  192. friend void fl_pop_clip();
  193. friend void fl_begin_complex_polygon();
  194. friend void fl_gap();
  195. friend void fl_end_complex_polygon();
  196. friend void fl_push_matrix();
  197. friend void fl_pop_matrix();
  198. friend void fl_mult_matrix(double a, double b, double c, double d, double x, double y);
  199. friend void fl_scale(double x, double y);
  200. friend void fl_scale(double x);
  201. friend void fl_translate(double x, double y);
  202. friend void fl_rotate(double d);
  203. friend double fl_transform_x(double x, double y);
  204. friend double fl_transform_y(double x, double y);
  205. friend double fl_transform_dx(double x, double y);
  206. friend double fl_transform_dy(double x, double y);
  207. friend Fl_Region fl_clip_region();
  208. friend void fl_clip_region(Fl_Region r);
  209. friend void fl_restore_clip();
  210. friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
  211. friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
  212. friend void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
  213. 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);
  214. friend FL_EXPORT void gl_start();
  215. /** \brief The constructor. */
  216. Fl_Graphics_Driver();
  217. /** \brief see fl_rect(int x, int y, int w, int h). */
  218. virtual void rect(int x, int y, int w, int h);
  219. /** \brief see fl_rectf(int x, int y, int w, int h). */
  220. virtual void rectf(int x, int y, int w, int h);
  221. /** \brief see fl_line_style(int style, int width, char* dashes). */
  222. virtual void line_style(int style, int width=0, char* dashes=0);
  223. /** \brief see fl_xyline(int x, int y, int x1). */
  224. virtual void xyline(int x, int y, int x1);
  225. /** \brief see fl_xyline(int x, int y, int x1, int y2). */
  226. virtual void xyline(int x, int y, int x1, int y2);
  227. /** \brief see fl_xyline(int x, int y, int x1, int y2, int x3). */
  228. virtual void xyline(int x, int y, int x1, int y2, int x3);
  229. /** \brief see fl_yxline(int x, int y, int y1). */
  230. virtual void yxline(int x, int y, int y1);
  231. /** \brief see fl_yxline(int x, int y, int y1, int x2). */
  232. virtual void yxline(int x, int y, int y1, int x2);
  233. /** \brief see fl_yxline(int x, int y, int y1, int x2, int y3). */
  234. virtual void yxline(int x, int y, int y1, int x2, int y3);
  235. /** \brief see fl_line(int x, int y, int x1, int y1). */
  236. virtual void line(int x, int y, int x1, int y1);
  237. /** \brief see fl_line(int x, int y, int x1, int y1, int x2, int y2). */
  238. virtual void line(int x, int y, int x1, int y1, int x2, int y2);
  239. /** \brief see fl_draw(const char *str, int n, int x, int y). */
  240. virtual void draw(const char *str, int n, int x, int y) = 0;
  241. #ifdef __APPLE__
  242. virtual void draw(const char *str, int n, float x, float y) = 0;
  243. #endif
  244. /** \brief see fl_draw(int angle, const char *str, int n, int x, int y). */
  245. virtual void draw(int angle, const char *str, int n, int x, int y) = 0;
  246. /** \brief see fl_rtl_draw(const char *str, int n, int x, int y). */
  247. virtual void rtl_draw(const char *str, int n, int x, int y) = 0;
  248. /** \brief see fl_color(Fl_Color c). */
  249. virtual void color(Fl_Color c) {color_ = c;}
  250. /** \brief see fl_color(uchar r, uchar g, uchar b). */
  251. virtual void color(uchar r, uchar g, uchar b) = 0;
  252. /** \brief see fl_point(int x, int y). */
  253. virtual void point(int x, int y);
  254. /** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2). */
  255. virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  256. /** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
  257. virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  258. /** \brief see fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2). */
  259. virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  260. /** \brief see fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
  261. virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  262. /** \brief see fl_begin_points(). */
  263. virtual void begin_points();
  264. /** \brief see fl_begin_line(). */
  265. virtual void begin_line();
  266. /** \brief see fl_begin_loop(). */
  267. virtual void begin_loop();
  268. /** \brief see fl_begin_polygon(). */
  269. virtual void begin_polygon();
  270. /** \brief see fl_vertex(double x, double y). */
  271. virtual void vertex(double x, double y);
  272. /** \brief see fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3). */
  273. virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
  274. /** \brief see fl_circle(double x, double y, double r). */
  275. virtual void circle(double x, double y, double r);
  276. /** \brief see fl_arc(double x, double y, double r, double start, double end). */
  277. virtual void arc(double x, double y, double r, double start, double end);
  278. /** \brief see fl_arc(int x, int y, int w, int h, double a1, double a2). */
  279. virtual void arc(int x, int y, int w, int h, double a1, double a2);
  280. /** \brief see fl_pie(int x, int y, int w, int h, double a1, double a2). */
  281. virtual void pie(int x, int y, int w, int h, double a1, double a2);
  282. /** \brief see fl_end_points(). */
  283. virtual void end_points();
  284. /** \brief see fl_end_line(). */
  285. virtual void end_line();
  286. /** \brief see fl_end_loop(). */
  287. virtual void end_loop();
  288. /** \brief see fl_end_polygon(). */
  289. virtual void end_polygon();
  290. /** \brief see fl_begin_complex_polygon(). */
  291. virtual void begin_complex_polygon();
  292. /** \brief see fl_gap(). */
  293. virtual void gap();
  294. /** \brief see fl_end_complex_polygon(). */
  295. virtual void end_complex_polygon();
  296. /** \brief see fl_transformed_vertex(double xf, double yf). */
  297. virtual void transformed_vertex(double xf, double yf);
  298. /** \brief see fl_push_clip(int x, int y, int w, int h). */
  299. virtual void push_clip(int x, int y, int w, int h);
  300. /** \brief see fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H). */
  301. virtual int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  302. /** \brief see fl_not_clipped(int x, int y, int w, int h). */
  303. virtual int not_clipped(int x, int y, int w, int h);
  304. /** \brief see fl_push_no_clip(). */
  305. virtual void push_no_clip();
  306. /** \brief see fl_pop_clip(). */
  307. virtual void pop_clip();
  308. /** \brief see fl_push_matrix(). */
  309. void push_matrix();
  310. /** \brief see fl_pop_matrix(). */
  311. void pop_matrix();
  312. /** \brief see fl_mult_matrix(double a, double b, double c, double d, double x, double y). */
  313. void mult_matrix(double a, double b, double c, double d, double x, double y);
  314. /** \brief see fl_scale(double x, double y). */
  315. inline void scale(double x, double y) { mult_matrix(x,0,0,y,0,0); }
  316. /** \brief see fl_scale(double x). */
  317. inline void scale(double x) { mult_matrix(x,0,0,x,0,0); }
  318. /** \brief see fl_translate(double x, double y). */
  319. inline void translate(double x,double y) { mult_matrix(1,0,0,1,x,y); }
  320. /** \brief see fl_rotate(double d). */
  321. void rotate(double d);
  322. /** \brief see fl_transform_x(double x, double y). */
  323. double transform_x(double x, double y);
  324. /** \brief see fl_transform_y(double x, double y). */
  325. double transform_y(double x, double y);
  326. /** \brief see fl_transform_dx(double x, double y). */
  327. double transform_dx(double x, double y);
  328. /** \brief see fl_transform_dy(double x, double y). */
  329. double transform_dy(double x, double y);
  330. /** \brief see fl_clip_region(). */
  331. Fl_Region clip_region();
  332. /** \brief see fl_clip_region(Fl_Region r). */
  333. void clip_region(Fl_Region r);
  334. /** \brief see fl_restore_clip(). */
  335. virtual void restore_clip();
  336. // Images
  337. /** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
  338. virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) = 0;
  339. /** \brief see fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
  340. virtual void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0) = 0;
  341. /** \brief see fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D). */
  342. virtual void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3) = 0;
  343. /** \brief see fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D). */
  344. virtual void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1) = 0;
  345. // Image classes
  346. /** \brief Draws an Fl_RGB_Image object to the device.
  347. *
  348. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  349. the image offset by the cx and cy arguments.
  350. */
  351. virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) = 0;
  352. /** \brief Draws an Fl_Pixmap object to the device.
  353. *
  354. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  355. the image offset by the cx and cy arguments.
  356. */
  357. virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) = 0;
  358. /** \brief Draws an Fl_Bitmap object to the device.
  359. *
  360. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  361. the image offset by the cx and cy arguments.
  362. */
  363. virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) = 0;
  364. public:
  365. static const char *class_id;
  366. virtual const char *class_name() {return class_id;};
  367. /** \brief see fl_font(Fl_Font face, Fl_Fontsize size). */
  368. virtual void font(Fl_Font face, Fl_Fontsize size) {font_ = face; size_ = size;}
  369. /** \brief see fl_font(void). */
  370. Fl_Font font() {return font_; }
  371. /** \brief see fl_size(). */
  372. Fl_Fontsize size() {return size_; }
  373. /** \brief see fl_width(const char *str, int n). */
  374. virtual double width(const char *str, int n) = 0;
  375. /** \brief see fl_width(unsigned int n). */
  376. virtual inline double width(unsigned int c) { char ch = (char)c; return width(&ch, 1); }
  377. /** \brief see fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h). */
  378. virtual void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
  379. /** \brief see fl_height(). */
  380. virtual int height() = 0;
  381. /** \brief see fl_descent(). */
  382. virtual int descent() = 0;
  383. /** \brief see fl_color(void). */
  384. Fl_Color color() {return color_;}
  385. /** Returns a pointer to the current Fl_Font_Descriptor for the graphics driver */
  386. inline Fl_Font_Descriptor *font_descriptor() { return font_descriptor_;}
  387. /** Sets the current Fl_Font_Descriptor for the graphics driver */
  388. inline void font_descriptor(Fl_Font_Descriptor *d) { font_descriptor_ = d;}
  389. /** \brief The destructor */
  390. virtual ~Fl_Graphics_Driver() {};
  391. };
  392. #if defined(__APPLE__) || defined(FL_DOXYGEN)
  393. /**
  394. \brief The Mac OS X-specific graphics class.
  395. *
  396. This class is implemented only on the Mac OS X platform.
  397. */
  398. class FL_EXPORT Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver {
  399. public:
  400. static const char *class_id;
  401. const char *class_name() {return class_id;};
  402. void color(Fl_Color c);
  403. void color(uchar r, uchar g, uchar b);
  404. void draw(const char* str, int n, int x, int y);
  405. #ifdef __APPLE__
  406. void draw(const char *str, int n, float x, float y);
  407. #endif
  408. void draw(int angle, const char *str, int n, int x, int y);
  409. void rtl_draw(const char* str, int n, int x, int y);
  410. void font(Fl_Font face, Fl_Fontsize size);
  411. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  412. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  413. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  414. void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
  415. void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
  416. void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
  417. void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
  418. double width(const char *str, int n);
  419. double width(unsigned int c);
  420. void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
  421. int height();
  422. int descent();
  423. };
  424. #endif
  425. #if defined(WIN32) || defined(FL_DOXYGEN)
  426. /**
  427. \brief The MSWindows-specific graphics class.
  428. *
  429. This class is implemented only on the MSWindows platform.
  430. */
  431. class FL_EXPORT Fl_GDI_Graphics_Driver : public Fl_Graphics_Driver {
  432. public:
  433. static const char *class_id;
  434. const char *class_name() {return class_id;};
  435. void color(Fl_Color c);
  436. void color(uchar r, uchar g, uchar b);
  437. void draw(const char* str, int n, int x, int y);
  438. void draw(int angle, const char *str, int n, int x, int y);
  439. void rtl_draw(const char* str, int n, int x, int y);
  440. void font(Fl_Font face, Fl_Fontsize size);
  441. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  442. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  443. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  444. void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
  445. void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
  446. void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
  447. void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
  448. double width(const char *str, int n);
  449. double width(unsigned int c);
  450. void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
  451. int height();
  452. int descent();
  453. };
  454. #endif
  455. #if !(defined(__APPLE__) || defined(WIN32))
  456. /**
  457. \brief The Xlib-specific graphics class.
  458. *
  459. This class is implemented only on the Xlib platform.
  460. */
  461. class Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver {
  462. public:
  463. static const char *class_id;
  464. const char *class_name() {return class_id;};
  465. virtual void color(Fl_Color c);
  466. virtual void color(uchar r, uchar g, uchar b);
  467. void draw(const char* str, int n, int x, int y);
  468. void draw(int angle, const char *str, int n, int x, int y);
  469. void rtl_draw(const char* str, int n, int x, int y);
  470. void font(Fl_Font face, Fl_Fontsize size);
  471. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  472. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  473. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  474. void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
  475. void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
  476. void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
  477. void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
  478. double width(const char *str, int n);
  479. double width(unsigned int c);
  480. void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
  481. int height();
  482. int descent();
  483. };
  484. #if FLTK_USE_CAIRO
  485. class Fl_Cairo_Graphics_Driver : public Fl_Xlib_Graphics_Driver {
  486. public:
  487. // void set_current(void);
  488. Fl_Cairo_Graphics_Driver ( );
  489. /* static const char *class_id; */
  490. /* const char *class_name() {return class_id;}; */
  491. void color(Fl_Color c);
  492. void color(uchar r, uchar g, uchar b);
  493. void color ( Fl_Color c, uchar a );
  494. void color (uchar r, uchar g, uchar b, uchar a );
  495. void line_style(int style, int width=0, char* dashes=0);
  496. void arc( int x, int y, int w, int h, double a1, double a2 );
  497. void pie( int x, int y, int w, int h, double a1, double a2 );
  498. void arc( double x, double y, double r, double a1, double a2 );
  499. void line( int x1, int y1, int x2, int y2 );
  500. void line( int x1, int y1, int x2, int y2, int x3, int y3 );
  501. void rect ( int x, int y, int w, int h );
  502. void end_points ( void );
  503. void rectf ( int x, int y, int w, int h );
  504. void circle ( double x, double y, double r );
  505. void end_line ( void );
  506. void end_loop ( void );
  507. void end_complex_polygon ( void );
  508. void end_polygon ( void );
  509. void curve( double x, double y, double x1, double y1, double x2, double y2, double x3, double y3 );
  510. void loop ( int x, int y, int x1, int y1, int x2, int y2 );
  511. void polygon ( int x, int y, int x1, int y1, int x2, int y2 );
  512. void loop ( int x, int y, int x1, int y1, int x2, int y2, int x3, int y3 );
  513. void polygon ( int x, int y, int x1, int y1, int x2, int y2, int x3, int y3 );
  514. void xyline(int x, int y, int x1);
  515. void xyline(int x, int y, int x1, int y2);
  516. void xyline(int x, int y, int x1, int y2, int x3);
  517. void yxline(int x, int y, int y1);
  518. void yxline(int x, int y, int y1, int x2);
  519. void yxline(int x, int y, int y1, int x2, int y3);
  520. /* void draw(const char* str, int n, int x, int y); */
  521. /* void draw(int angle, const char *str, int n, int x, int y); */
  522. /* void rtl_draw(const char* str, int n, int x, int y); */
  523. /* void font(Fl_Font face, Fl_Fontsize size); */
  524. /* void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy); */
  525. /* void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy); */
  526. /* void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy); */
  527. /* void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0); */
  528. /* void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); */
  529. /* void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); */
  530. /* void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); */
  531. /* double width(const char *str, int n); */
  532. /* double width(unsigned int c); */
  533. /* void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); */
  534. /* int height(); */
  535. /* int descent(); */
  536. };
  537. #endif
  538. #endif
  539. /**
  540. \brief A surface that's susceptible to receive graphical output.
  541. */
  542. class FL_EXPORT Fl_Surface_Device : public Fl_Device {
  543. /** \brief The graphics driver in use by this surface. */
  544. Fl_Graphics_Driver *_driver;
  545. public:
  546. static Fl_Surface_Device *_surface; // the surface that currently receives graphics output
  547. protected:
  548. /** \brief Constructor that sets the graphics driver to use for the created surface. */
  549. Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver; };
  550. public:
  551. static const char *class_id;
  552. const char *class_name() {return class_id;};
  553. virtual void set_current(void);
  554. /** \brief Sets the graphics driver of this drawing surface. */
  555. inline void driver(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver;};
  556. /** \brief Returns the graphics driver of this drawing surface. */
  557. inline Fl_Graphics_Driver *driver() {return _driver; };
  558. /** \brief the surface that currently receives graphics output */
  559. static inline Fl_Surface_Device *surface() {return _surface; };
  560. /** \brief The destructor. */
  561. virtual ~Fl_Surface_Device() {}
  562. };
  563. /**
  564. \brief A display to which the computer can draw.
  565. */
  566. class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
  567. public:
  568. static Fl_Display_Device *_display; // the platform display device
  569. public:
  570. static const char *class_id;
  571. const char *class_name() {return class_id;};
  572. /** \brief A constructor that sets the graphics driver used by the display */
  573. Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
  574. /** Returns the platform display device. */
  575. static inline Fl_Display_Device *display_device() {return _display;};
  576. };
  577. /**
  578. This plugin socket allows the integration of new device drivers for special
  579. window or screen types. It is currently used to provide an automated printing
  580. service for OpenGL windows, if linked with fltk_gl.
  581. */
  582. class FL_EXPORT Fl_Device_Plugin : public Fl_Plugin {
  583. public:
  584. /** \brief The constructor */
  585. Fl_Device_Plugin(const char *name)
  586. : Fl_Plugin(klass(), name) { }
  587. /** \brief Returns the class name */
  588. virtual const char *klass() { return "fltk:device"; }
  589. /** \brief Returns the plugin name */
  590. virtual const char *name() = 0;
  591. /** \brief Prints a widget
  592. \param w the widget
  593. \param x,y offsets where to print relatively to coordinates origin
  594. \param height height of the current drawing area
  595. */
  596. virtual int print(Fl_Widget* w, int x, int y, int height) = 0;
  597. };
  598. #endif // Fl_Device_H
  599. //
  600. // End of "$Id: Fl_Device.H 8529 2011-03-23 12:49:30Z AlbrechtS $".
  601. //