fl_draw.H 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. //
  2. // "$Id: fl_draw.H 12543 2017-11-05 04:18:44Z greg.ercolano $"
  3. //
  4. // Portable drawing function header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /**
  19. \file fl_draw.H
  20. \brief utility header to pull drawing functions together
  21. */
  22. #ifndef fl_draw_H
  23. #define fl_draw_H
  24. #include <FL/Enumerations.H> // for the color names
  25. #include <FL/Fl_Graphics_Driver.H> // for fl_graphics_driver + Fl_Region
  26. // Image class...
  27. class Fl_Image;
  28. class Fl_Window;
  29. // Label flags...
  30. FL_EXPORT extern char fl_draw_shortcut;
  31. /** \addtogroup fl_attributes
  32. @{
  33. */
  34. // Colors:
  35. /**
  36. Sets the color for all subsequent drawing operations.
  37. For colormapped displays, a color cell will be allocated out of
  38. \p fl_colormap the first time you use a color. If the colormap fills up
  39. then a least-squares algorithm is used to find the closest color.
  40. If no valid graphical context (fl_gc) is available,
  41. the foreground is not set for the current window.
  42. \param[in] c color
  43. */
  44. inline void fl_color(Fl_Color c) {fl_graphics_driver->color(c); } // select indexed color
  45. /** for back compatibility - use fl_color(Fl_Color c) instead */
  46. inline void fl_color(int c) {fl_color((Fl_Color)c);}
  47. /**
  48. Sets the color for all subsequent drawing operations.
  49. The closest possible match to the RGB color is used.
  50. The RGB color is used directly on TrueColor displays.
  51. For colormap visuals the nearest index in the gray
  52. ramp or color cube is used.
  53. If no valid graphical context (fl_gc) is available,
  54. the foreground is not set for the current window.
  55. \param[in] r,g,b color components
  56. */
  57. inline void fl_color(uchar r, uchar g, uchar b) {fl_graphics_driver->color(r,g,b); } // select actual color
  58. /**
  59. Returns the last fl_color() that was set.
  60. This can be used for state save/restore.
  61. */
  62. inline Fl_Color fl_color() {return fl_graphics_driver->color();}
  63. /** @} */
  64. /** \addtogroup fl_drawings
  65. @{
  66. */
  67. // clip:
  68. /**
  69. Intersects the current clip region with a rectangle and pushes this
  70. new region onto the stack.
  71. \param[in] x,y,w,h position and size
  72. */
  73. inline void fl_push_clip(int x, int y, int w, int h) {fl_graphics_driver->push_clip(x,y,w,h); }
  74. /**
  75. Intersects the current clip region with a rectangle and pushes this
  76. new region onto the stack (deprecated).
  77. \param[in] x,y,w,h position and size
  78. \deprecated
  79. fl_clip(int, int, int, int) is deprecated and will be removed from future releases.
  80. Please use fl_push_clip(int x, int y, int w, int h) instead.
  81. */
  82. #define fl_clip fl_push_clip
  83. /**
  84. Pushes an empty clip region onto the stack so nothing will be clipped.
  85. */
  86. inline void fl_push_no_clip() {fl_graphics_driver->push_no_clip(); }
  87. /**
  88. Restores the previous clip region.
  89. You must call fl_pop_clip() once for every time you call fl_push_clip().
  90. Unpredictable results may occur if the clip stack is not empty when
  91. you return to FLTK.
  92. */
  93. inline void fl_pop_clip() {fl_graphics_driver->pop_clip(); }
  94. /**
  95. Does the rectangle intersect the current clip region?
  96. \param[in] x,y,w,h position and size of rectangle
  97. \returns non-zero if any of the rectangle intersects the current clip
  98. region. If this returns 0 you don't have to draw the object.
  99. \note
  100. Under X this returns 2 if the rectangle is partially clipped,
  101. and 1 if it is entirely inside the clip region.
  102. */
  103. inline int fl_not_clipped(int x, int y, int w, int h) {return fl_graphics_driver->not_clipped(x,y,w,h); }
  104. /**
  105. Intersects the rectangle with the current clip region and returns the
  106. bounding box of the result.
  107. Returns non-zero if the resulting rectangle is different to the original.
  108. This can be used to limit the necessary drawing to a rectangle.
  109. \p W and \p H are set to zero if the rectangle is completely outside the region.
  110. \param[in] x,y,w,h position and size of rectangle
  111. \param[out] X,Y,W,H position and size of resulting bounding box.
  112. \returns Non-zero if the resulting rectangle is different to the original.
  113. */
  114. inline int fl_clip_box(int x , int y, int w, int h, int& X, int& Y, int& W, int& H)
  115. {return fl_graphics_driver->clip_box(x,y,w,h,X,Y,W,H); }
  116. /** Undoes any clobbering of clip done by your program */
  117. inline void fl_restore_clip() { fl_graphics_driver->restore_clip(); }
  118. /**
  119. Replaces the top of the clipping stack with a clipping region of any shape.
  120. Fl_Region is an operating system specific type.
  121. \param[in] r clipping region
  122. */
  123. inline void fl_clip_region(Fl_Region r) { fl_graphics_driver->clip_region(r); }
  124. /**
  125. Returns the current clipping region.
  126. */
  127. inline Fl_Region fl_clip_region() { return fl_graphics_driver->clip_region(); }
  128. // points:
  129. /**
  130. Draws a single pixel at the given coordinates
  131. */
  132. inline void fl_point(int x, int y) { fl_graphics_driver->point(x,y); }
  133. // line type:
  134. /**
  135. Sets how to draw lines (the "pen").
  136. If you change this it is your responsibility to set it back to the default
  137. using \c fl_line_style(0).
  138. \param[in] style A bitmask which is a bitwise-OR of a line style, a cap
  139. style, and a join style. If you don't specify a dash type you
  140. will get a solid line. If you don't specify a cap or join type
  141. you will get a system-defined default of whatever value is
  142. fastest.
  143. \param[in] width The thickness of the lines in pixels. Zero results in the
  144. system defined default, which on both X and Windows is somewhat
  145. different and nicer than 1.
  146. \param[in] dashes A pointer to an array of dash lengths, measured in pixels.
  147. The first location is how long to draw a solid portion, the next
  148. is how long to draw the gap, then the solid, etc. It is terminated
  149. with a zero-length entry. A \c NULL pointer or a zero-length
  150. array results in a solid line. Odd array sizes are not supported
  151. and result in undefined behavior.
  152. \note Because of how line styles are implemented on Win32 systems,
  153. you \e must set the line style \e after setting the drawing
  154. color. If you set the color after the line style you will lose
  155. the line style settings.
  156. \note The \p dashes array does not work under Windows 95, 98 or Me,
  157. since those operating systems do not support complex line styles.
  158. */
  159. inline void fl_line_style(int style, int width=0, char* dashes=0) {fl_graphics_driver->line_style(style,width,dashes); }
  160. enum {
  161. FL_SOLID = 0, ///< line style: <tt>___________</tt>
  162. FL_DASH = 1, ///< line style: <tt>_ _ _ _ _ _</tt>
  163. FL_DOT = 2, ///< line style: <tt>. . . . . .</tt>
  164. FL_DASHDOT = 3, ///< line style: <tt>_ . _ . _ .</tt>
  165. FL_DASHDOTDOT = 4, ///< line style: <tt>_ . . _ . .</tt>
  166. FL_CAP_FLAT = 0x100, ///< cap style: end is flat
  167. FL_CAP_ROUND = 0x200, ///< cap style: end is round
  168. FL_CAP_SQUARE = 0x300, ///< cap style: end wraps end point
  169. FL_JOIN_MITER = 0x1000, ///< join style: line join extends to a point
  170. FL_JOIN_ROUND = 0x2000, ///< join style: line join is rounded
  171. FL_JOIN_BEVEL = 0x3000 ///< join style: line join is tidied
  172. };
  173. // rectangles tweaked to exactly fill the pixel rectangle:
  174. /**
  175. Draws a 1-pixel border \e inside the given bounding box.
  176. This function is meant for quick drawing of simple boxes. The behavior is
  177. undefined for line widths that are not 1.
  178. */
  179. inline void fl_rect(int x, int y, int w, int h) { fl_graphics_driver->rect(x,y,w,h); }
  180. /**
  181. Draw a dotted rectangle, used to indicate keyboard focus on a widget.
  182. */
  183. inline void fl_focus_rect(int x, int y, int w, int h) { fl_graphics_driver->focus_rect(x, y, w, h); }
  184. /** Draws with passed color a 1-pixel border \e inside the given bounding box */
  185. inline void fl_rect(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rect(x,y,w,h);}
  186. /** Colors with current color a rectangle that exactly fills the given bounding box */
  187. inline void fl_rectf(int x, int y, int w, int h) { fl_graphics_driver->rectf(x,y,w,h); }
  188. /** Colors with passed color a rectangle that exactly fills the given bounding box */
  189. inline void fl_rectf(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rectf(x,y,w,h);}
  190. /**
  191. Colors a rectangle with "exactly" the passed <tt>r,g,b</tt> color.
  192. On screens with less than 24 bits of color this is done by drawing a
  193. solid-colored block using fl_draw_image() so that the correct color
  194. shade is produced.
  195. */
  196. /* note: doxygen comment here to avoid triplication in os-speciic files */
  197. FL_EXPORT void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
  198. // line segments:
  199. /**
  200. Draws a line from (x,y) to (x1,y1)
  201. */
  202. inline void fl_line(int x, int y, int x1, int y1) {fl_graphics_driver->line(x,y,x1,y1); }
  203. /**
  204. Draws a line from (x,y) to (x1,y1) and another from (x1,y1) to (x2,y2)
  205. */
  206. inline void fl_line(int x, int y, int x1, int y1, int x2, int y2) {fl_graphics_driver->line(x,y,x1,y1,x2,y2); }
  207. // closed line segments:
  208. /**
  209. Outlines a 3-sided polygon with lines
  210. */
  211. inline void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {fl_graphics_driver->loop(x,y,x1,y1,x2,y2); }
  212. /**
  213. Outlines a 4-sided polygon with lines
  214. */
  215. inline void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
  216. {fl_graphics_driver->loop(x,y,x1,y1,x2,y2,x3,y3); }
  217. // filled polygons
  218. /**
  219. Fills a 3-sided polygon. The polygon must be convex.
  220. */
  221. inline void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) {fl_graphics_driver->polygon(x,y,x1,y1,x2,y2); }
  222. /**
  223. Fills a 4-sided polygon. The polygon must be convex.
  224. */
  225. inline void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
  226. { fl_graphics_driver->polygon(x,y,x1,y1,x2,y2,x3,y3); }
  227. // draw rectilinear lines, horizontal segment first:
  228. /**
  229. Draws a horizontal line from (x,y) to (x1,y)
  230. */
  231. inline void fl_xyline(int x, int y, int x1) {fl_graphics_driver->xyline(x,y,x1);}
  232. /**
  233. Draws a horizontal line from (x,y) to (x1,y), then vertical from (x1,y) to (x1,y2)
  234. */
  235. inline void fl_xyline(int x, int y, int x1, int y2) {fl_graphics_driver->xyline(x,y,x1,y2);}
  236. /**
  237. Draws a horizontal line from (x,y) to (x1,y), then a vertical from (x1,y) to (x1,y2)
  238. and then another horizontal from (x1,y2) to (x3,y2)
  239. */
  240. inline void fl_xyline(int x, int y, int x1, int y2, int x3) {fl_graphics_driver->xyline(x,y,x1,y2,x3);}
  241. // draw rectilinear lines, vertical segment first:
  242. /**
  243. Draws a vertical line from (x,y) to (x,y1)
  244. */
  245. inline void fl_yxline(int x, int y, int y1) {fl_graphics_driver->yxline(x,y,y1);}
  246. /**
  247. Draws a vertical line from (x,y) to (x,y1), then a horizontal from (x,y1) to (x2,y1)
  248. */
  249. inline void fl_yxline(int x, int y, int y1, int x2) {fl_graphics_driver->yxline(x,y,y1,x2);}
  250. /**
  251. Draws a vertical line from (x,y) to (x,y1) then a horizontal from (x,y1)
  252. to (x2,y1), then another vertical from (x2,y1) to (x2,y3)
  253. */
  254. inline void fl_yxline(int x, int y, int y1, int x2, int y3) {fl_graphics_driver->yxline(x,y,y1,x2,y3);}
  255. // circular lines and pie slices (code in fl_arci.C):
  256. /**
  257. Draw ellipse sections using integer coordinates.
  258. These functions match the rather limited circle drawing code provided by X
  259. and WIN32. The advantage over using fl_arc with floating point coordinates
  260. is that they are faster because they often use the hardware, and they draw
  261. much nicer small circles, since the small sizes are often hard-coded bitmaps.
  262. If a complete circle is drawn it will fit inside the passed bounding box.
  263. The two angles are measured in degrees counter-clockwise from 3 o'clock and
  264. are the starting and ending angle of the arc, \p a2 must be greater or equal
  265. to \p a1.
  266. fl_arc() draws a series of lines to approximate the arc. Notice that the
  267. integer version of fl_arc() has a different number of arguments than the
  268. double version fl_arc(double x, double y, double r, double start, double end)
  269. \param[in] x,y,w,h bounding box of complete circle
  270. \param[in] a1,a2 start and end angles of arc measured in degrees
  271. counter-clockwise from 3 o'clock. \p a2 must be greater
  272. than or equal to \p a1.
  273. */
  274. inline void fl_arc(int x, int y, int w, int h, double a1, double a2) {fl_graphics_driver->arc(x,y,w,h,a1,a2); }
  275. /**
  276. Draw filled ellipse sections using integer coordinates.
  277. Like fl_arc(), but fl_pie() draws a filled-in pie slice.
  278. This slice may extend outside the line drawn by fl_arc();
  279. to avoid this use w - 1 and h - 1.
  280. \param[in] x,y,w,h bounding box of complete circle
  281. \param[in] a1,a2 start and end angles of arc measured in degrees
  282. counter-clockwise from 3 o'clock. \p a2 must be greater
  283. than or equal to \p a1.
  284. */
  285. inline void fl_pie(int x, int y, int w, int h, double a1, double a2) {fl_graphics_driver->pie(x,y,w,h,a1,a2); }
  286. /** fl_chord declaration is a place holder - the function does not yet exist */
  287. FL_EXPORT void fl_chord(int x, int y, int w, int h, double a1, double a2); // nyi
  288. // scalable drawing code (code in fl_vertex.C and fl_arc.C):
  289. /**
  290. Saves the current transformation matrix on the stack.
  291. The maximum depth of the stack is 32.
  292. */
  293. inline void fl_push_matrix() { fl_graphics_driver->push_matrix(); }
  294. /**
  295. Restores the current transformation matrix from the stack.
  296. */
  297. inline void fl_pop_matrix() { fl_graphics_driver->pop_matrix(); }
  298. /**
  299. Concatenates scaling transformation onto the current one.
  300. \param[in] x,y scale factors in x-direction and y-direction
  301. */
  302. inline void fl_scale(double x, double y) {
  303. fl_graphics_driver->mult_matrix(x,0,0,y,0,0);
  304. }
  305. /**
  306. Concatenates scaling transformation onto the current one.
  307. \param[in] x scale factor in both x-direction and y-direction
  308. */
  309. inline void fl_scale(double x) {
  310. fl_graphics_driver->mult_matrix(x,0,0,x,0,0);
  311. }
  312. /**
  313. Concatenates translation transformation onto the current one.
  314. \param[in] x,y translation factor in x-direction and y-direction
  315. */
  316. inline void fl_translate(double x, double y) { fl_graphics_driver->translate(x, y); }
  317. /**
  318. Concatenates rotation transformation onto the current one.
  319. \param[in] d - rotation angle, counter-clockwise in degrees (not radians)
  320. */
  321. inline void fl_rotate(double d) { fl_graphics_driver->rotate(d); }
  322. /**
  323. Concatenates another transformation onto the current one.
  324. \param[in] a,b,c,d,x,y transformation matrix elements such that
  325. <tt> X' = aX + cY + x </tt> and <tt> Y' = bX +dY + y </tt>
  326. */
  327. inline void fl_mult_matrix(double a, double b, double c, double d, double x,double y)
  328. { fl_graphics_driver->mult_matrix(a, b, c, d, x, y); }
  329. /**
  330. Starts drawing a list of points. Points are added to the list with fl_vertex()
  331. */
  332. inline void fl_begin_points() {fl_graphics_driver->begin_points(); }
  333. /**
  334. Starts drawing a list of lines.
  335. */
  336. inline void fl_begin_line() {fl_graphics_driver->begin_line(); }
  337. /**
  338. Starts drawing a closed sequence of lines.
  339. */
  340. inline void fl_begin_loop() {fl_graphics_driver->begin_loop(); }
  341. /**
  342. Starts drawing a convex filled polygon.
  343. */
  344. inline void fl_begin_polygon() {fl_graphics_driver->begin_polygon(); }
  345. /**
  346. Adds a single vertex to the current path.
  347. \param[in] x,y coordinate
  348. */
  349. inline void fl_vertex(double x, double y) {fl_graphics_driver->vertex(x,y); }
  350. /**
  351. Adds a series of points on a Bezier curve to the path.
  352. The curve ends (and two of the points) are at X0,Y0 and X3,Y3.
  353. \param[in] X0,Y0 curve start point
  354. \param[in] X1,Y1 curve control point
  355. \param[in] X2,Y2 curve control point
  356. \param[in] X3,Y3 curve end point
  357. */
  358. inline void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3)
  359. {fl_graphics_driver->curve(X0,Y0,X1,Y1,X2,Y2,X3,Y3); }
  360. /**
  361. Adds a series of points to the current path on the arc of a circle.
  362. You can get elliptical paths by using scale and rotate before calling fl_arc().
  363. \param[in] x,y,r center and radius of circular arc
  364. \param[in] start,end angles of start and end of arc measured in degrees
  365. counter-clockwise from 3 o'clock. If \p end is less than \p start
  366. then it draws the arc in a clockwise direction.
  367. Examples:
  368. \code
  369. // Draw an arc of points
  370. fl_begin_points();
  371. fl_arc(100.0, 100.0, 50.0, 0.0, 180.0);
  372. fl_end_points();
  373. // Draw arc with a line
  374. fl_begin_line();
  375. fl_arc(200.0, 100.0, 50.0, 0.0, 180.0);
  376. fl_end_line();
  377. // Draw filled arc
  378. fl_begin_polygon();
  379. fl_arc(300.0, 100.0, 50.0, 0.0, 180.0);
  380. fl_end_polygon();
  381. \endcode
  382. */
  383. inline void fl_arc(double x, double y, double r, double start, double end) {fl_graphics_driver->arc(x,y,r,start,end); }
  384. /**
  385. fl_circle() is equivalent to fl_arc(x,y,r,0,360), but may be faster.
  386. It must be the \e only thing in the path: if you want a circle as part of
  387. a complex polygon you must use fl_arc()
  388. \param[in] x,y,r center and radius of circle
  389. */
  390. inline void fl_circle(double x, double y, double r) {fl_graphics_driver->circle(x,y,r); }
  391. /**
  392. Ends list of points, and draws.
  393. */
  394. inline void fl_end_points() {fl_graphics_driver->end_points(); }
  395. /**
  396. Ends list of lines, and draws.
  397. */
  398. inline void fl_end_line() {fl_graphics_driver->end_line(); }
  399. /**
  400. Ends closed sequence of lines, and draws.
  401. */
  402. inline void fl_end_loop() {fl_graphics_driver->end_loop(); }
  403. /**
  404. Ends convex filled polygon, and draws.
  405. */
  406. inline void fl_end_polygon() {fl_graphics_driver->end_polygon(); }
  407. /**
  408. Starts drawing a complex filled polygon.
  409. The polygon may be concave, may have holes in it, or may be several
  410. disconnected pieces. Call fl_gap() to separate loops of the path.
  411. To outline the polygon, use fl_begin_loop() and replace each fl_gap()
  412. with fl_end_loop();fl_begin_loop() pairs.
  413. \note
  414. For portability, you should only draw polygons that appear the same
  415. whether "even/odd" or "non-zero" winding rules are used to fill them.
  416. Holes should be drawn in the opposite direction to the outside loop.
  417. */
  418. inline void fl_begin_complex_polygon() {fl_graphics_driver->begin_complex_polygon(); }
  419. /**
  420. Call fl_gap() to separate loops of the path.
  421. It is unnecessary but harmless to call fl_gap() before the first vertex,
  422. after the last vertex, or several times in a row.
  423. */
  424. inline void fl_gap() {fl_graphics_driver->gap(); }
  425. /**
  426. Ends complex filled polygon, and draws.
  427. */
  428. inline void fl_end_complex_polygon() {fl_graphics_driver->end_complex_polygon(); }
  429. // get and use transformed positions:
  430. /**
  431. Transforms coordinate using the current transformation matrix.
  432. \param[in] x,y coordinate
  433. */
  434. inline double fl_transform_x(double x, double y) {return fl_graphics_driver->transform_x(x, y); }
  435. /**
  436. Transforms coordinate using the current transformation matrix.
  437. \param[in] x,y coordinate
  438. */
  439. inline double fl_transform_y(double x, double y) {return fl_graphics_driver->transform_y(x, y); }
  440. /**
  441. Transforms distance using current transformation matrix.
  442. \param[in] x,y coordinate
  443. */
  444. inline double fl_transform_dx(double x, double y) {return fl_graphics_driver->transform_dx(x, y); }
  445. /**
  446. Transforms distance using current transformation matrix.
  447. \param[in] x,y coordinate
  448. */
  449. inline double fl_transform_dy(double x, double y) {return fl_graphics_driver->transform_dy(x, y); }
  450. /**
  451. Adds coordinate pair to the vertex list without further transformations.
  452. \param[in] xf,yf transformed coordinate
  453. */
  454. inline void fl_transformed_vertex(double xf, double yf) {fl_graphics_driver->transformed_vertex(xf,yf); }
  455. /** Copy a rectangular area of the given offscreen buffer into the current drawing destination.
  456. \param x,y position where to draw the copied rectangle
  457. \param w,h size of the copied rectangle
  458. \param pixmap offscreen buffer containing the rectangle to copy
  459. \param srcx,srcy origin in offscreen buffer of rectangle to copy
  460. */
  461. inline void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
  462. fl_graphics_driver->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
  463. }
  464. FL_EXPORT Fl_Offscreen fl_create_offscreen(int w, int h);
  465. FL_EXPORT void fl_begin_offscreen(Fl_Offscreen b);
  466. FL_EXPORT void fl_end_offscreen(void);
  467. FL_EXPORT void fl_delete_offscreen(Fl_Offscreen bitmap);
  468. FL_EXPORT void fl_scale_offscreen(Fl_Offscreen &ctx);
  469. /** @} */
  470. /** \addtogroup fl_attributes
  471. @{ */
  472. /* NOTE: doxygen comments here to avoid triplication in os-specific sources */
  473. // Fonts:
  474. /**
  475. Sets the current font, which is then used in various drawing routines.
  476. You may call this outside a draw context if necessary to call fl_width(),
  477. but on X this will open the display.
  478. The font is identified by a \p face and a \p size.
  479. The size of the font is measured in pixels and not "points".
  480. Lines should be spaced \p size pixels apart or more.
  481. */
  482. inline void fl_font(Fl_Font face, Fl_Fontsize fsize) { fl_graphics_driver->font(face,fsize); }
  483. /**
  484. Returns the \p face set by the most recent call to fl_font().
  485. This can be used to save/restore the font.
  486. */
  487. inline Fl_Font fl_font() {return fl_graphics_driver->font();}
  488. /**
  489. Returns the \p size set by the most recent call to fl_font().
  490. This can be used to save/restore the font.
  491. */
  492. inline Fl_Fontsize fl_size() {return fl_graphics_driver->size();}
  493. // information you can get about the current font:
  494. /**
  495. Returns the recommended minimum line spacing for the current font.
  496. You can also use the value of \p size passed to fl_font()
  497. */
  498. inline int fl_height() {return fl_graphics_driver->height();}
  499. FL_EXPORT int fl_height(int font, int size);
  500. /**
  501. Returns the recommended distance above the bottom of a fl_height() tall box to
  502. draw the text at so it looks centered vertically in that box.
  503. */
  504. inline int fl_descent() {return fl_graphics_driver->descent();}
  505. /** Returns the typographical width of a nul-terminated string
  506. using the current font face and size. */
  507. FL_EXPORT double fl_width(const char* txt);
  508. /** Returns the typographical width of a sequence of \p n characters
  509. using the current font face and size. */
  510. inline double fl_width(const char* txt, int n) {return fl_graphics_driver->width(txt, n);}
  511. /** Returns the typographical width of a single character
  512. using the current font face and size.
  513. \note if a valid fl_gc is NOT found then it uses the first window gc,
  514. or the screen gc if no fltk window is available when called. */
  515. inline double fl_width(unsigned int c) {return fl_graphics_driver->width(c);}
  516. /** Determines the minimum pixel dimensions of a nul-terminated string
  517. using the current fl_font().
  518. Usage: given a string "txt" drawn using fl_draw(txt, x, y) you would determine
  519. its pixel extents on the display using fl_text_extents(txt, dx, dy, wo, ho)
  520. such that a bounding box that exactly fits around the text could be drawn with
  521. fl_rect(x+dx, y+dy, wo, ho). Note the dx, dy values hold the offset of the first
  522. "colored in" pixel of the string, from the draw origin.
  523. Note the desired font and font size must be set with fl_font() before calling
  524. this function.
  525. This differs slightly from fl_measure() in that the dx/dy values are also
  526. returned.
  527. No FLTK symbol expansion will be performed.
  528. Example use:
  529. \code
  530. :
  531. int dx,dy,W,H;
  532. fl_font(FL_HELVETICA, 12); // set font face+size first
  533. fl_text_extents("Some text",dx,dy,W,H); // get width and height of string
  534. printf("text's width=%d, height=%d\n", W,H);
  535. :
  536. \endcode
  537. */
  538. FL_EXPORT void fl_text_extents(const char*, int& dx, int& dy, int& w, int& h); // NO fltk symbol expansion will be performed
  539. /** Determines the minimum pixel dimensions of a sequence of \p n characters
  540. using the current fl_font().
  541. \see fl_text_extents(const char*, int& dx, int& dy, int& w, int& h)
  542. */
  543. inline void fl_text_extents(const char *t, int n, int& dx, int& dy, int& w, int& h)
  544. {fl_graphics_driver->text_extents(t, n, dx, dy, w, h);}
  545. // font encoding:
  546. // Note: doxygen comments here to avoid duplication for os-sepecific cases
  547. /**
  548. Converts text from Windows/X11 latin1 character set to local encoding.
  549. \param[in] t character string (latin1 encoding)
  550. \param[in] n optional number of characters to convert (default is all)
  551. \returns pointer to internal buffer containing converted characters
  552. */
  553. FL_EXPORT const char *fl_latin1_to_local(const char *t, int n=-1);
  554. /**
  555. Converts text from local encoding to Windowx/X11 latin1 character set.
  556. \param[in] t character string (local encoding)
  557. \param[in] n optional number of characters to convert (default is all)
  558. \returns pointer to internal buffer containing converted characters
  559. */
  560. FL_EXPORT const char *fl_local_to_latin1(const char *t, int n=-1);
  561. /**
  562. Converts text from Mac Roman character set to local encoding.
  563. \param[in] t character string (Mac Roman encoding)
  564. \param[in] n optional number of characters to convert (default is all)
  565. \returns pointer to internal buffer containing converted characters
  566. */
  567. FL_EXPORT const char *fl_mac_roman_to_local(const char *t, int n=-1);
  568. /**
  569. Converts text from local encoding to Mac Roman character set.
  570. \param[in] t character string (local encoding)
  571. \param[in] n optional number of characters to convert (default is all)
  572. \returns pointer to internal buffer containing converted characters
  573. */
  574. FL_EXPORT const char *fl_local_to_mac_roman(const char *t, int n=-1);
  575. /** @} */
  576. /** \addtogroup fl_drawings
  577. @{ */
  578. /**
  579. Draws a nul-terminated UTF-8 string starting at the given \p x, \p y location.
  580. Text is aligned to the left and to the baseline of the font.
  581. To align to the bottom, subtract fl_descent() from \p y.
  582. To align to the top, subtract fl_descent() and add fl_height().
  583. This version of fl_draw provides direct access to the text drawing
  584. function of the underlying OS. It does not apply any special handling
  585. to control characters.
  586. */
  587. FL_EXPORT void fl_draw(const char* str, int x, int y);
  588. /**
  589. Draws a nul-terminated UTF-8 string starting at the given \p x, \p y
  590. location and rotating \p angle degrees counter-clockwise.
  591. This version of fl_draw provides direct access to the text drawing
  592. function of the underlying OS and is supported by Xft, Win32 and MacOS
  593. fltk subsets.
  594. */
  595. FL_EXPORT void fl_draw(int angle, const char* str, int x, int y);
  596. /**
  597. Draws starting at the given \p x, \p y location a UTF-8 string of length \p n bytes.
  598. */
  599. inline void fl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->draw(str,n,x,y); }
  600. /**
  601. Draws at the given \p x, \p y location a UTF-8 string of length \p n bytes
  602. rotating \p angle degrees counter-clockwise.
  603. \note When using X11 (Unix, Linux, Cygwin et al.) this needs Xft to work.
  604. Under plain X11 (w/o Xft) rotated text is not supported by FLTK.
  605. A warning will be issued to stderr at runtime (only once) if you
  606. use this method with an angle other than 0.
  607. */
  608. inline void fl_draw(int angle, const char* str, int n, int x, int y) {fl_graphics_driver->draw(angle,str,n,x,y); }
  609. /**
  610. Draws a UTF-8 string of length \p n bytes right to left starting at the given \p x, \p y location.
  611. */
  612. inline void fl_rtl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->rtl_draw(str,n,x,y); }
  613. FL_EXPORT void fl_measure(const char* str, int& x, int& y,
  614. int draw_symbols = 1);
  615. FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h,
  616. Fl_Align align,
  617. Fl_Image* img=0, int draw_symbols = 1);
  618. FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h,
  619. Fl_Align align,
  620. void (*callthis)(const char *,int,int,int),
  621. Fl_Image* img=0, int draw_symbols = 1);
  622. // boxtypes:
  623. FL_EXPORT void fl_frame(const char* s, int x, int y, int w, int h);
  624. FL_EXPORT void fl_frame2(const char* s, int x, int y, int w, int h);
  625. FL_EXPORT void fl_draw_box(Fl_Boxtype, int x, int y, int w, int h, Fl_Color);
  626. // images:
  627. /**
  628. Draws an 8-bit per color RGB or luminance image.
  629. \param[in] buf points at the "r" data of the top-left pixel.
  630. Color data must be in <tt>r,g,b</tt> order.
  631. Luminance data is only one <tt>gray</tt> byte.
  632. \param[in] X,Y position where to put top-left corner of image
  633. \param[in] W,H size of the image
  634. \param[in] D delta to add to the pointer between pixels. It may be
  635. any value greater than or equal to 1, or it can be
  636. negative to flip the image horizontally
  637. \param[in] L delta to add to the pointer between lines (if 0 is
  638. passed it uses \p W * \p D), and may be larger than
  639. \p W * \p D to crop data, or negative to flip the
  640. image vertically
  641. It is highly recommended that you put the following code before the
  642. first <tt>show()</tt> of \e any window in your program to get rid of
  643. the dithering if possible:
  644. \code
  645. Fl::visual(FL_RGB);
  646. \endcode
  647. Gray scale (1-channel) images may be drawn. This is done if
  648. <tt>abs(D)</tt> is less than 3, or by calling fl_draw_image_mono().
  649. Only one 8-bit sample is used for each pixel, and on screens with
  650. different numbers of bits for red, green, and blue only gray colors
  651. are used. Setting \p D greater than 1 will let you display one channel
  652. of a color image.
  653. \par Note:
  654. The X version does not support all possible visuals. If FLTK cannot
  655. draw the image in the current visual it will abort. FLTK supports
  656. any visual of 8 bits or less, and all common TrueColor visuals up
  657. to 32 bits.
  658. */
  659. inline void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0)
  660. { fl_graphics_driver->draw_image(buf, X, Y, W, H, D, L); }
  661. /**
  662. Draws a gray-scale (1 channel) image.
  663. \see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L)
  664. */
  665. inline void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0)
  666. { fl_graphics_driver->draw_image_mono(buf, X, Y, W, H, D, L); }
  667. /**
  668. Draws an image using a callback function to generate image data.
  669. You can generate the image as it is being drawn, or do arbitrary
  670. decompression of stored data, provided it can be decompressed to
  671. individual scan lines easily.
  672. \param[in] cb callback function to generate scan line data
  673. \param[in] data user data passed to callback function
  674. \param[in] X,Y screen position of top left pixel
  675. \param[in] W,H image width and height
  676. \param[in] D data size in bytes (must be greater than 0)
  677. \see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L)
  678. The callback function \p cb is called with the <tt>void*</tt> \p data
  679. user data pointer to allow access to a structure of information about
  680. the image, and the \p x, \p y, and \p w of the scan line desired from
  681. the image. 0,0 is the upper-left corner of the image, not \p x, \p y.
  682. A pointer to a buffer to put the data into is passed. You must copy
  683. \p w pixels from scanline \p y, starting at pixel \p x, to this buffer.
  684. Due to cropping, less than the whole image may be requested. So \p x
  685. may be greater than zero, the first \p y may be greater than zero,
  686. and \p w may be less than \p W. The buffer is long enough to store
  687. the entire \p W * \p D pixels, this is for convenience with some
  688. decompression schemes where you must decompress the entire line at
  689. once: decompress it into the buffer, and then if \p x is not zero,
  690. copy the data over so the \p x'th pixel is at the start of the buffer.
  691. You can assume the \p y's will be consecutive, except the first one
  692. may be greater than zero.
  693. If \p D is 4 or more, you must fill in the unused bytes with zero.
  694. */
  695. inline void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3)
  696. { fl_graphics_driver->draw_image(cb, data, X, Y, W, H, D); }
  697. /**
  698. Draws a gray-scale image using a callback function to generate image data.
  699. \see fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D)
  700. */
  701. inline void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1)
  702. { fl_graphics_driver->draw_image_mono(cb, data, X, Y, W, H, D); }
  703. /**
  704. Checks whether platform supports true alpha blending for RGBA images.
  705. \returns 1 if true alpha blending supported by platform
  706. \returns 0 not supported so FLTK will use screen door transparency
  707. */
  708. inline char fl_can_do_alpha_blending() {return Fl_Graphics_Driver::default_driver().can_do_alpha_blending();}
  709. FL_EXPORT uchar *fl_read_image(uchar *p,int X,int Y,int W,int H,int alpha=0);
  710. // pixmaps:
  711. FL_EXPORT int fl_draw_pixmap(/*const*/ char* const* data, int x,int y,Fl_Color=FL_GRAY);
  712. FL_EXPORT int fl_draw_pixmap(const char* const* cdata, int x,int y,Fl_Color=FL_GRAY);
  713. FL_EXPORT int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h);
  714. FL_EXPORT int fl_measure_pixmap(const char* const* cdata, int &w, int &h);
  715. // other:
  716. FL_EXPORT void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
  717. void (*draw_area)(void*, int,int,int,int), void* data);
  718. FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut);
  719. FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut, const char **eom);
  720. FL_EXPORT unsigned int fl_old_shortcut(const char* s);
  721. FL_EXPORT void fl_overlay_rect(int x,int y,int w,int h);
  722. FL_EXPORT void fl_overlay_clear();
  723. FL_EXPORT void fl_cursor(Fl_Cursor);
  724. FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg, Fl_Color bg=FL_WHITE);
  725. FL_EXPORT const char* fl_expand_text(const char* from, char* buf, int maxbuf,
  726. double maxw, int& n, double &width,
  727. int wrap, int draw_symbols = 0);
  728. // XIM:
  729. /** \todo provide user documentation for fl_set_status function */
  730. FL_EXPORT void fl_set_status(int X, int Y, int W, int H);
  731. /** \todo provide user documentation for fl_set_spot function */
  732. FL_EXPORT void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win=0);
  733. /** \todo provide user documentation for fl_reset_spot function*/
  734. FL_EXPORT void fl_reset_spot(void);
  735. // XForms symbols:
  736. FL_EXPORT int fl_draw_symbol(const char* label,int x,int y,int w,int h, Fl_Color);
  737. FL_EXPORT int fl_add_symbol(const char* name, void (*drawit)(Fl_Color), int scalable);
  738. /** @} */
  739. #endif
  740. //
  741. // End of "$Id: fl_draw.H 12543 2017-11-05 04:18:44Z greg.ercolano $".
  742. //