Fl_Device.H 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. //
  2. // "$Id: Fl_Device.H 7719 2010-10-12 09:25:37Z manolo $"
  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 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, Fl_Display_Device.
  30. */
  31. #ifndef Fl_Device_H
  32. #define Fl_Device_H
  33. #include <FL/x.H>
  34. #include <FL/Fl_Plugin.H>
  35. #include <FL/Fl_Image.H>
  36. #include <FL/Fl_Bitmap.H>
  37. #include <FL/Fl_Pixmap.H>
  38. #include <FL/Fl_RGB_Image.H>
  39. #ifdef WIN32
  40. #include <commdlg.h>
  41. #elif defined(__APPLE__)
  42. #else
  43. #include <stdio.h>
  44. #endif
  45. class Fl_Graphics_Driver;
  46. class Fl_Display_Device;
  47. class Fl_Surface_Device;
  48. /** \brief Points to the driver that currently receives all graphics requests */
  49. FL_EXPORT extern Fl_Graphics_Driver *fl_graphics_driver;
  50. /** \brief Points to the surface that currently receives all graphics requests */
  51. FL_EXPORT extern Fl_Surface_Device *fl_surface;
  52. /** \brief Points to the platform's display */
  53. FL_EXPORT extern Fl_Display_Device *fl_display_device;
  54. /**
  55. signature of image generation callback function.
  56. \param[in] data user data passed to function
  57. \param[in] x,y,w position and width of scan line in image
  58. \param[out] buf buffer for generated image data. You must copy \p w
  59. pixels from scanline \p y, starting at pixel \p x
  60. to this buffer.
  61. */
  62. typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);
  63. /**
  64. \brief All graphical output devices and all graphics systems.
  65. */
  66. class Fl_Device {
  67. protected:
  68. /** \brief The device type */
  69. const char *type_;
  70. /** \brief A string that identifies each subclass of Fl_Device.
  71. *
  72. Function type() applied to a device of this class returns this string.
  73. */
  74. static const char *device_type;
  75. public:
  76. /**
  77. @brief An RTTI emulation of device classes.
  78. *
  79. The type of an instance of an Fl_Device subclass can be checked with code such as:
  80. \code
  81. if ( instance->type() == Fl_Printer::device_type ) { ... }
  82. \endcode
  83. */
  84. inline const char *type() {return type_;};
  85. };
  86. /**
  87. \brief A virtual class subclassed for each graphics driver FLTK uses.
  88. *
  89. The protected virtual methods of this class are those that a graphics driver should implement to
  90. support all of FLTK drawing functions.
  91. <br> The public API for drawing operations is functionally presented in \ref drawing and as function lists
  92. in the \ref fl_drawings and \ref fl_attributes modules.
  93. */
  94. class Fl_Graphics_Driver : public Fl_Device {
  95. protected:
  96. /* ** \brief red color for background and/or mixing if device does not support masking or alpha *
  97. uchar bg_r_;
  98. ** \brief green color for background and/or mixing if device does not support masking or alpha *
  99. uchar bg_g_;
  100. ** \brief blue color for background and/or mixing if device does not support masking or alpha *
  101. uchar bg_b_; */
  102. friend class Fl_Pixmap;
  103. friend class Fl_Bitmap;
  104. friend class Fl_RGB_Image;
  105. friend class Fl_PostScript_Graphics_Driver;
  106. friend void fl_rect(int x, int y, int w, int h);
  107. friend void fl_rectf(int x, int y, int w, int h);
  108. friend void fl_line_style(int style, int width, char* dashes);
  109. friend void fl_xyline(int x, int y, int x1);
  110. friend void fl_xyline(int x, int y, int x1, int y2);
  111. friend void fl_xyline(int x, int y, int x1, int y2, int x3);
  112. friend void fl_yxline(int x, int y, int y1);
  113. friend void fl_yxline(int x, int y, int y1, int x2);
  114. friend void fl_yxline(int x, int y, int y1, int x2, int y3);
  115. friend void fl_line(int x, int y, int x1, int y1);
  116. friend void fl_line(int x, int y, int x1, int y1, int x2, int y2);
  117. friend void fl_draw(const char *str, int n, int x, int y);
  118. #ifdef __APPLE__
  119. friend void fl_draw(const char *str, int n, float x, float y);
  120. #endif
  121. friend void fl_draw(int angle, const char *str, int n, int x, int y);
  122. friend void fl_rtl_draw(const char *str, int n, int x, int y);
  123. friend void fl_font(Fl_Font face, Fl_Fontsize size);
  124. friend void fl_color(Fl_Color c);
  125. friend void fl_color(uchar r, uchar g, uchar b);
  126. friend void fl_point(int x, int y);
  127. friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2);
  128. friend void fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  129. friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  130. friend void fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  131. friend void fl_begin_points();
  132. friend void fl_begin_line();
  133. friend void fl_begin_loop();
  134. friend void fl_begin_polygon();
  135. friend void fl_vertex(double x, double y);
  136. friend void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
  137. friend void fl_circle(double x, double y, double r);
  138. friend void fl_arc(double x, double y, double r, double start, double end);
  139. friend void fl_arc(int x, int y, int w, int h, double a1, double a2);
  140. friend void fl_pie(int x, int y, int w, int h, double a1, double a2);
  141. friend void fl_end_points();
  142. friend void fl_end_line();
  143. friend void fl_end_loop();
  144. friend void fl_end_polygon();
  145. friend void fl_transformed_vertex(double xf, double yf);
  146. friend void fl_push_clip(int x, int y, int w, int h);
  147. friend int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  148. friend int fl_not_clipped(int x, int y, int w, int h);
  149. friend void fl_push_no_clip();
  150. friend void fl_pop_clip();
  151. friend void fl_begin_complex_polygon();
  152. friend void fl_gap();
  153. friend void fl_end_complex_polygon();
  154. friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
  155. friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
  156. friend void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
  157. 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);
  158. /** \brief The constructor. */
  159. Fl_Graphics_Driver() {};
  160. /** \brief see fl_rect(int x, int y, int w, int h). */
  161. virtual void rect(int x, int y, int w, int h);
  162. /** \brief see fl_rectf(int x, int y, int w, int h). */
  163. virtual void rectf(int x, int y, int w, int h);
  164. /** \brief see fl_line_style(int style, int width, char* dashes). */
  165. virtual void line_style(int style, int width=0, char* dashes=0);
  166. /** \brief see fl_xyline(int x, int y, int x1). */
  167. virtual void xyline(int x, int y, int x1);
  168. /** \brief see fl_xyline(int x, int y, int x1, int y2). */
  169. virtual void xyline(int x, int y, int x1, int y2);
  170. /** \brief see fl_xyline(int x, int y, int x1, int y2, int x3). */
  171. virtual void xyline(int x, int y, int x1, int y2, int x3);
  172. /** \brief see fl_yxline(int x, int y, int y1). */
  173. virtual void yxline(int x, int y, int y1);
  174. /** \brief see fl_yxline(int x, int y, int y1, int x2). */
  175. virtual void yxline(int x, int y, int y1, int x2);
  176. /** \brief see fl_yxline(int x, int y, int y1, int x2, int y3). */
  177. virtual void yxline(int x, int y, int y1, int x2, int y3);
  178. /** \brief see fl_line(int x, int y, int x1, int y1). */
  179. virtual void line(int x, int y, int x1, int y1);
  180. /** \brief see fl_line(int x, int y, int x1, int y1, int x2, int y2). */
  181. virtual void line(int x, int y, int x1, int y1, int x2, int y2);
  182. /** \brief see fl_draw(const char *str, int n, int x, int y). */
  183. virtual void draw(const char *str, int n, int x, int y);
  184. /** \brief see fl_draw(int angle, const char *str, int n, int x, int y). */
  185. virtual void draw(int angle, const char *str, int n, int x, int y);
  186. /** \brief see fl_rtl_draw(const char *str, int n, int x, int y). */
  187. virtual void rtl_draw(const char *str, int n, int x, int y);
  188. /** \brief see fl_font(Fl_Font face, Fl_Fontsize size). */
  189. virtual void font(Fl_Font face, Fl_Fontsize size);
  190. /** \brief see fl_color(Fl_Color c). */
  191. virtual void color(Fl_Color c);
  192. /** \brief see fl_color(uchar r, uchar g, uchar b). */
  193. virtual void color(uchar r, uchar g, uchar b);
  194. /** \brief see fl_point(int x, int y). */
  195. virtual void point(int x, int y);
  196. /** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2). */
  197. virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2);
  198. /** \brief see fl_loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
  199. virtual void loop(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  200. /** \brief see fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2). */
  201. virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2);
  202. /** \brief see fl_polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3). */
  203. virtual void polygon(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3);
  204. /** \brief see fl_begin_points(). */
  205. virtual void begin_points();
  206. /** \brief see fl_begin_line(). */
  207. virtual void begin_line();
  208. /** \brief see fl_begin_loop(). */
  209. virtual void begin_loop();
  210. /** \brief see fl_begin_polygon(). */
  211. virtual void begin_polygon();
  212. /** \brief see fl_vertex(double x, double y). */
  213. virtual void vertex(double x, double y);
  214. /** \brief see fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3). */
  215. virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
  216. /** \brief see fl_circle(double x, double y, double r). */
  217. virtual void circle(double x, double y, double r);
  218. /** \brief see fl_arc(double x, double y, double r, double start, double end). */
  219. virtual void arc(double x, double y, double r, double start, double end);
  220. /** \brief see fl_arc(int x, int y, int w, int h, double a1, double a2). */
  221. virtual void arc(int x, int y, int w, int h, double a1, double a2);
  222. /** \brief see fl_pie(int x, int y, int w, int h, double a1, double a2). */
  223. virtual void pie(int x, int y, int w, int h, double a1, double a2);
  224. /** \brief see fl_end_points(). */
  225. virtual void end_points();
  226. /** \brief see fl_end_line(). */
  227. virtual void end_line();
  228. /** \brief see fl_end_loop(). */
  229. virtual void end_loop();
  230. /** \brief see fl_end_polygon(). */
  231. virtual void end_polygon();
  232. /** \brief see fl_begin_complex_polygon(). */
  233. virtual void begin_complex_polygon();
  234. /** \brief see fl_gap(). */
  235. virtual void gap();
  236. /** \brief see fl_end_complex_polygon(). */
  237. virtual void end_complex_polygon();
  238. /** \brief see fl_transformed_vertex(double xf, double yf). */
  239. virtual void transformed_vertex(double xf, double yf);
  240. /** \brief see fl_push_clip(int x, int y, int w, int h). */
  241. virtual void push_clip(int x, int y, int w, int h);
  242. /** \brief see fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H). */
  243. virtual int clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H);
  244. /** \brief see fl_not_clipped(int x, int y, int w, int h). */
  245. virtual int not_clipped(int x, int y, int w, int h);
  246. /** \brief see fl_push_no_clip(). */
  247. virtual void push_no_clip();
  248. /** \brief see fl_pop_clip(). */
  249. virtual void pop_clip();
  250. // Images
  251. /** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
  252. virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
  253. /** \brief see fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
  254. virtual void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
  255. /** \brief see fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D). */
  256. virtual void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
  257. /** \brief see fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D). */
  258. virtual void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
  259. // Image classes
  260. /** \brief Draws an Fl_RGB_Image object to the device.
  261. *
  262. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  263. the image offset by the cx and cy arguments.
  264. */
  265. virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) {};
  266. /** \brief Draws an Fl_Pixmap object to the device.
  267. *
  268. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  269. the image offset by the cx and cy arguments.
  270. */
  271. virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) {};
  272. /** \brief Draws an Fl_Bitmap object to the device.
  273. *
  274. Specifies a bounding box for the image, with the origin (upper left-hand corner) of
  275. the image offset by the cx and cy arguments.
  276. */
  277. virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {};
  278. public:
  279. static const char *device_type;
  280. /** \brief The destructor */
  281. virtual ~Fl_Graphics_Driver() {};
  282. };
  283. #if defined(__APPLE__) || defined(FL_DOXYGEN)
  284. /**
  285. \brief The Mac OS X-specific graphics class.
  286. *
  287. This class is implemented only on the Mac OS X platform.
  288. */
  289. class Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver {
  290. public:
  291. /** \brief The constructor. */
  292. Fl_Quartz_Graphics_Driver() { type_ = device_type; };
  293. static const char *device_type;
  294. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  295. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  296. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  297. };
  298. #endif
  299. #if defined(WIN32) || defined(FL_DOXYGEN)
  300. /**
  301. \brief The MSWindows-specific graphics class.
  302. *
  303. This class is implemented only on the MSWindows platform.
  304. */
  305. class Fl_GDI_Graphics_Driver : public Fl_Graphics_Driver {
  306. public:
  307. /** \brief The constructor. */
  308. Fl_GDI_Graphics_Driver() { type_ = device_type; };
  309. static const char *device_type;
  310. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  311. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  312. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  313. };
  314. #endif
  315. #if !(defined(__APPLE__) || defined(WIN32))
  316. /**
  317. \brief The Xlib-specific graphics class.
  318. *
  319. This class is implemented only on the Xlib platform.
  320. */
  321. class Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver {
  322. public:
  323. /** \brief The constructor. */
  324. Fl_Xlib_Graphics_Driver() { type_ = device_type; };
  325. static const char *device_type;
  326. void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  327. void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
  328. void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
  329. };
  330. #endif
  331. /**
  332. \brief A surface that's susceptible to receive graphical output.
  333. */
  334. class Fl_Surface_Device : public Fl_Device {
  335. /** \brief The graphics driver in use by this surface. */
  336. Fl_Graphics_Driver *_driver;
  337. protected:
  338. /** \brief Constructor that sets the graphics driver to use for the created surface. */
  339. Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver; };
  340. public:
  341. static const char *device_type;
  342. virtual void set_current(void);
  343. /** \brief Sets the graphics driver of this drawing surface. */
  344. inline void driver(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver;};
  345. /** \brief Returns the graphics driver of this drawing surface. */
  346. inline Fl_Graphics_Driver *driver() {return _driver; };
  347. /** \brief the surface that currently receives graphics output */
  348. static Fl_Surface_Device *surface() {return fl_surface; };
  349. /** \brief The destructor. */
  350. virtual ~Fl_Surface_Device() {}
  351. };
  352. /**
  353. \brief A display to which the computer can draw.
  354. */
  355. class Fl_Display_Device : public Fl_Surface_Device {
  356. public:
  357. static const char *device_type;
  358. /** \brief A constructor that sets the graphics driver used by the display */
  359. Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) { type_ = device_type; };
  360. /**
  361. @brief Returns the platform's display device.
  362. */
  363. static Fl_Display_Device *display_device() { return fl_display_device; };
  364. };
  365. #endif // Fl_Device_H
  366. //
  367. // End of "$Id: Fl_Device.H 7719 2010-10-12 09:25:37Z manolo $".
  368. //