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.

1032 lines
33KB

  1. /**
  2. \page drawing Drawing Things in FLTK
  3. This chapter covers the drawing functions that are provided with FLTK.
  4. \section sect_WhenCanYouDraw When Can You Draw Things in FLTK?
  5. There are only certain places you can execute drawing code in FLTK.
  6. Calling these functions at other places will result in undefined behavior!
  7. \li The most common place is inside the virtual Fl_Widget::draw() method.
  8. To write code here, you must subclass one of the existing Fl_Widget
  9. classes and implement your own version of draw().
  10. \li You can also create custom \ref common_boxtypes "boxtypes" and
  11. \ref common_labeltype "labeltypes". These involve writing small
  12. procedures that can be called by existing Fl_Widget::draw() methods.
  13. These "types" are identified by an 8-bit index that is stored in the
  14. widget's \p box(), \p labeltype(), and possibly other properties.
  15. \li You can call Fl_Window::make_current() to do incremental update of a
  16. widget. Use Fl_Widget::window() to find the window.
  17. \section sect_DrawingFunctions Drawing Functions
  18. To use the drawing functions you must first include the <FL/fl_draw.H>
  19. header file. FLTK provides the following types of drawing functions:
  20. \li \ref ssect_Boxes
  21. \li \ref ssect_Clipping
  22. \li \ref drawing_colors
  23. \li \ref ssect_Lines
  24. \li \ref ssect_Fast
  25. \li \ref ssect_Complex
  26. \li \ref ssect_Text
  27. \li \ref ssect_Fonts
  28. \li \ref ssect_CharacterEncoding
  29. \li \ref ssect_Overlay
  30. \li \ref drawing_images
  31. \li \ref ssect_DirectImageDrawing
  32. \li \ref ssect_DirectImageReading
  33. \li \ref ssect_Fl_Image
  34. \li \ref ssect_Offscreen
  35. \subsection ssect_Boxes Boxes
  36. FLTK provides three functions that can be used to draw boxes for buttons
  37. and other UI controls. Each function uses the supplied upper-lefthand corner
  38. and width and height to determine where to draw the box.
  39. void fl_draw_box(Fl_Boxtype b, int x, int y, int w, int h, Fl_Color c);
  40. \par
  41. The \p %fl_draw_box() function draws a standard boxtype \p b
  42. in the specified color \p c.
  43. \anchor drawing_fl_frame
  44. void fl_frame(const char *s, int x, int y, int w, int h) <br>
  45. void fl_frame2(const char *s, int x, int y, int w, int h)
  46. \par
  47. The \p %fl_frame() and \p %fl_frame2() functions draw a series of
  48. line segments around the given box. The string \p s must contain groups
  49. of 4 letters which specify one of 24 standard grayscale values,
  50. where 'A' is black and 'X' is white.
  51. The results of calling these functions with a string that is not a
  52. multiple of 4 characters in length are undefined.
  53. \par
  54. The only difference between \p %fl_frame() and \p %fl_frame2()
  55. is the order of the line segments:
  56. - For \p %fl_frame() the order of each set of 4 characters is:
  57. top, left, bottom, right.
  58. - For \p %fl_frame2() the order of each set of 4 characters is:
  59. bottom, right, top, left.
  60. \par
  61. Note that
  62. \ref common_fl_frame "fl_frame(Fl_Boxtype b)"
  63. is described in the \ref common_boxtypes section.
  64. \subsection ssect_Clipping Clipping
  65. You can limit all your drawing to a rectangular region by calling
  66. \p %fl_push_clip(), and put the drawings back by using
  67. \p %fl_pop_clip().
  68. This rectangle is measured in pixels and is unaffected by the current
  69. transformation matrix.
  70. In addition, the system may provide clipping when updating windows
  71. which may be more complex than a simple rectangle.
  72. void fl_push_clip(int x, int y, int w, int h) <br>
  73. void fl_clip(int x, int y, int w, int h)
  74. \par
  75. Intersect the current clip region with a rectangle and push this new
  76. region onto the stack.
  77. \par
  78. The \p %fl_clip() version is deprecated and
  79. will be removed from future releases.
  80. void fl_push_no_clip()
  81. \par
  82. Pushes an empty clip region on the stack so nothing will be clipped.
  83. void fl_pop_clip()
  84. \par
  85. Restore the previous clip region.
  86. \par
  87. \b Note:
  88. You must call \p %fl_pop_clip() once for every time you call
  89. \p %fl_push_clip().
  90. If you return to FLTK with the clip stack not empty unpredictable results
  91. occur.
  92. int fl_not_clipped(int x, int y, int w, int h)
  93. \par
  94. Returns non-zero if any of the rectangle intersects the current clip
  95. region. If this returns 0 you don't have to draw the object.
  96. \par
  97. \b Note:
  98. Under X this returns 2 if the rectangle is partially clipped,
  99. and 1 if it is entirely inside the clip region.
  100. int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H)
  101. \par
  102. Intersect the rectangle <tt>x,y,w,h</tt> with the current
  103. clip region and returns the bounding box of the result in
  104. <tt>X,Y,W,H</tt>. Returns non-zero if the resulting rectangle is
  105. different than the original. This can be used to limit the
  106. necessary drawing to a rectangle. \c W and \c H are
  107. set to zero if the rectangle is completely outside the region.
  108. void fl_clip_region(Fl_Region r) <br>
  109. Fl_Region fl_clip_region()
  110. \par
  111. Replace the top of the clip stack with a clipping region of any shape.
  112. Fl_Region is an operating system specific type. The second form returns
  113. the current clipping region.
  114. \section drawing_colors Colors
  115. FLTK manages colors as 32-bit unsigned integers, encoded as RGBI.
  116. When the RGB bytes are non-zero, the value is treated as RGB.
  117. If these bytes are zero, the I byte will be used as an index
  118. into the colormap.
  119. Values from 0 to 255, i.e. the I index value, represent
  120. colors from the FLTK 1.3.x standard colormap
  121. and are allocated as needed on screens without TrueColor support.
  122. The \b Fl_Color enumeration type defines the
  123. standard colors and color cube for the first 256 colors. All of
  124. these are named with symbols in
  125. \ref enumerations "<FL/Enumerations.H>".
  126. Color values greater than 255 are treated as 24-bit RGB
  127. values. These are mapped to the closest color supported by the
  128. screen, either from one of the 256 colors in the FLTK 1.3.x
  129. colormap or a direct RGB value on TrueColor screens.
  130. Fl_Color fl_rgb_color(uchar r, uchar g, uchar b) <br>
  131. Fl_Color fl_rgb_color(uchar grayscale)
  132. \par
  133. Generate Fl_Color out of specified
  134. 8-bit RGB values or one 8-bit grayscale value.
  135. void fl_color(Fl_Color c) <br>
  136. void fl_color(int c)
  137. \par
  138. Sets the color for all subsequent drawing operations.
  139. Please use the first form:
  140. the second form is only provided for back compatibility.
  141. \par
  142. For colormapped displays, a color cell will be allocated out
  143. of \p fl_colormap the first time you use a color. If the
  144. colormap fills up then a least-squares algorithm is used to find
  145. the closest color.
  146. Fl_Color fl_color()
  147. \par
  148. Returns the last color that was set using \p %fl_color().
  149. This can be used for state save/restore.
  150. void fl_color(uchar r, uchar g, uchar b)
  151. \par
  152. Set the color for all subsequent drawing operations. The
  153. closest possible match to the RGB color is used. The RGB color
  154. is used directly on TrueColor displays. For colormap visuals the
  155. nearest index in the gray ramp or color cube is used.
  156. unsigned Fl::get_color(Fl_Color i) <br>
  157. void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue)
  158. \par
  159. Generate RGB values from a colormap index value \p i.
  160. The first returns the RGB as a 32-bit unsigned integer,
  161. and the second decomposes the RGB into three 8-bit values.
  162. \todo work out why Fl::get_color() does not give links!
  163. Fl::get_system_colors() <br>
  164. Fl::foreground() <br>
  165. Fl::background() <br>
  166. Fl::background2()
  167. \par
  168. The first gets color values from the user preferences or the system,
  169. and the other routines are used to apply those values.
  170. Fl::own_colormap() <br>
  171. Fl::free_color(Fl_Color i, int overlay) <br>
  172. Fl::set_color(Fl_Color i, unsigned c)
  173. \par
  174. \p Fl::own_colormap() is used to install a local colormap [X11 only].
  175. \par
  176. \p Fl::free_color() and \p Fl::set_color() are used to remove and replace
  177. entries from the colormap.
  178. \todo work out why these do not give links!
  179. There are two predefined graphical interfaces for choosing colors.
  180. The function fl_show_colormap() shows a table of colors and returns an
  181. Fl_Color index value.
  182. The Fl_Color_Chooser widget provides a standard RGB color chooser.
  183. As the Fl_Color encoding maps to a 32-bit unsigned integer representing
  184. RGBI, it is also possible to specify a color using a hex constant as a
  185. color map index:
  186. <pre>
  187. // COLOR MAP INDEX
  188. color(0x000000II)
  189. ------ |
  190. | |
  191. | Color map index (8 bits)
  192. Must be zero
  193. </pre>
  194. \code
  195. button->color(0x000000ff); // colormap index #255 (FL_WHITE)
  196. \endcode
  197. or specify a color using a hex constant for the RGB components:
  198. <pre>
  199. // RGB COLOR ASSIGNMENTS
  200. color(0xRRGGBB00)
  201. | | | |
  202. | | | Must be zero
  203. | | Blue (8 bits)
  204. | Green (8 bits)
  205. Red (8 bits)
  206. </pre>
  207. \code
  208. button->color(0xff000000); // RGB: red
  209. button->color(0x00ff0000); // RGB: green
  210. button->color(0x0000ff00); // RGB: blue
  211. button->color(0xffffff00); // RGB: white
  212. \endcode
  213. \note
  214. If TrueColor is not available, any RGB colors will be set to
  215. the nearest entry in the colormap.
  216. \subsection ssect_Lines Line Dashes and Thickness
  217. FLTK supports drawing of lines with different styles and
  218. widths. Full functionality is not available under Windows 95, 98,
  219. and Me due to the reduced drawing functionality these operating
  220. systems provide.
  221. void fl_line_style(int style, int width, char* dashes)
  222. \par
  223. Set how to draw lines (the "pen"). If you change this it is your
  224. responsibility to set it back to the default with
  225. \p fl_line_style(0).
  226. \par
  227. \b Note:
  228. Because of how line styles are implemented on MS Windows systems, you
  229. \e must set the line style \e after setting the drawing color.
  230. If you set the
  231. color after the line style you will lose the line style settings!
  232. \par
  233. \p style is a bitmask which is a bitwise-OR of the following
  234. values. If you don't specify a dash type you will get a solid
  235. line. If you don't specify a cap or join type you will get a
  236. system-defined default of whatever value is fastest.
  237. \par
  238. \li <tt>FL_SOLID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------</tt>
  239. \li <tt>FL_DASH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - - - -</tt>
  240. \li <tt>FL_DOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .......</tt>
  241. \li <tt>FL_DASHDOT&nbsp;&nbsp;&nbsp; - . - .</tt>
  242. \li <tt>FL_DASHDOTDOT - .. -</tt>
  243. \li <tt>FL_CAP_FLAT</tt>
  244. \li <tt>FL_CAP_ROUND</tt>
  245. \li <tt>FL_CAP_SQUARE</tt> (extends past end point 1/2 line width)
  246. \li <tt>FL_JOIN_MITER</tt> (pointed)
  247. \li <tt>FL_JOIN_ROUND</tt>
  248. \li <tt>FL_JOIN_BEVEL</tt> (flat)
  249. \par
  250. \p width is the number of pixels thick to draw the lines.
  251. Zero results in the system-defined default, which on both X and
  252. Windows is somewhat different and nicer than 1.
  253. \par
  254. \p dashes is a pointer to an array of dash lengths, measured in
  255. pixels. The first location is how long to draw a solid portion, the
  256. next is how long to draw the gap, then the solid, etc. It is
  257. terminated with a zero-length entry. A \p NULL pointer or a zero-length
  258. array results in a solid line. Odd array sizes are not supported and
  259. result in undefined behavior.
  260. \par
  261. \b Note:
  262. The dashes array does not work under Windows 95, 98, or Me, since those
  263. operating systems do not support complex line styles.
  264. \subsection ssect_Fast Drawing Fast Shapes
  265. These functions are used to draw almost all the FLTK widgets.
  266. They draw on exact pixel boundaries and are as fast as possible.
  267. Their behavior is duplicated exactly on all platforms FLTK is
  268. ported. It is undefined whether these are affected by the
  269. \ref ssect_Complex "transformation matrix",
  270. so you should only call these while the matrix is set to the
  271. identity matrix (the default).
  272. void fl_point(int x, int y)
  273. \par
  274. Draw a single pixel at the given coordinates.
  275. void fl_rectf(int x, int y, int w, int h) <br>
  276. void fl_rectf(int x, int y, int w, int h)
  277. \par
  278. Color a rectangle that exactly fills the given bounding box.
  279. void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b)
  280. \par
  281. Color a rectangle with "exactly" the passed
  282. <tt>r,g,b</tt> color. On screens with less than 24 bits of
  283. color this is done by drawing a solid-colored block using
  284. \ref drawing_fl_draw_image "fl_draw_image()"
  285. so that the correct color shade is produced.
  286. void fl_rect(int x, int y, int w, int h) <br>
  287. void fl_rect(int x, int y, int w, int h, Fl_Color c)
  288. \par
  289. Draw a 1-pixel border \e inside this bounding box.
  290. void fl_line(int x, int y, int x1, int y1) <br>
  291. void fl_line(int x, int y, int x1, int y1, int x2, int y2)
  292. \par
  293. Draw one or two lines between the given points.
  294. void fl_loop(int x, int y, int x1, int y1, int x2, int y2) <br>
  295. void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
  296. \par
  297. Outline a 3 or 4-sided polygon with lines.
  298. void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) <br>
  299. void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
  300. \par
  301. Fill a 3 or 4-sided polygon. The polygon must be convex.
  302. void fl_xyline(int x, int y, int x1) <br>
  303. void fl_xyline(int x, int y, int x1, int y2) <br>
  304. void fl_xyline(int x, int y, int x1, int y2, int x3)
  305. \par
  306. Draw horizontal and vertical lines. A horizontal line is
  307. drawn first, then a vertical, then a horizontal.
  308. void fl_yxline(int x, int y, int y1) <br>
  309. void fl_yxline(int x, int y, int y1, int x2) <br>
  310. void fl_yxline(int x, int y, int y1, int x2, int y3)
  311. \par
  312. Draw vertical and horizontal lines. A vertical line is drawn
  313. first, then a horizontal, then a vertical.
  314. void fl_arc(int x, int y, int w, int h, double a1, double a2) <br>
  315. void fl_pie(int x, int y, int w, int h, double a1, double a2)
  316. \par
  317. Draw ellipse sections using integer coordinates. These
  318. functions match the rather limited circle drawing code provided
  319. by X and MS Windows. The advantage over using
  320. \ref drawing_fl_arc "fl_arc()"
  321. with floating point
  322. coordinates is that they are faster because they often use the
  323. hardware, and they draw much nicer small circles, since the
  324. small sizes are often hard-coded bitmaps.
  325. \par
  326. If a complete circle is drawn it will fit inside the passed bounding
  327. box. The two angles are measured in degrees counter-clockwise from
  328. 3'oclock and are the starting and ending angle of the arc, \p a2
  329. must be greater or equal to \p a1.
  330. \par
  331. \p %fl_arc() draws a series of lines to approximate the arc.
  332. Notice that the integer version of \p %fl_arc() has a different
  333. number of arguments to the other
  334. \ref drawing_fl_arc "fl_arc()"
  335. function described later in this chapter.
  336. \par
  337. \p %fl_pie() draws a filled-in pie slice. This slice may
  338. extend outside the line drawn by \p %fl_arc(); to avoid this
  339. use \p w-1 and \p h-1.
  340. \todo
  341. add an Fl_Draw_Area_Cb typedef to allow fl_scroll(...) to be doxygenated?
  342. void fl_scroll(int X, int Y, int W, int H, int dx, int dy, void (*draw_area)(void*, int,int,int,int), void* data)
  343. \par
  344. Scroll a rectangle and draw the newly exposed portions. The contents
  345. of the rectangular area is first shifted by \p dx and
  346. \p dy pixels. The callback is then called for every newly
  347. exposed rectangular area,
  348. \subsection ssect_Complex Drawing Complex Shapes
  349. The complex drawing functions let you draw arbitrary shapes
  350. with 2-D linear transformations. The functionality matches that
  351. found in the Adobe&reg; PostScript&tm; language. The
  352. exact pixels that are filled are less defined than for the fast
  353. drawing functions so that FLTK can take advantage of drawing
  354. hardware. On both X and MS Windows the transformed vertices are
  355. rounded to integers before drawing the line segments: this
  356. severely limits the accuracy of these functions for complex
  357. graphics, so use OpenGL when greater accuracy and/or performance
  358. is required.
  359. void fl_push_matrix() <br>
  360. void fl_pop_matrix()
  361. \par
  362. Save and restore the current transformation. The maximum
  363. depth of the stack is 32 entries.
  364. void fl_scale(double x,double y) <br>
  365. void fl_scale(double x) <br>
  366. void fl_translate(double x,double y) <br>
  367. void fl_rotate(double d) <br>
  368. void fl_mult_matrix(double a,double b,double c,double d,double x,double y)
  369. \par
  370. Concatenate another transformation onto the current one. The rotation
  371. angle is in degrees (not radians) and is counter-clockwise.
  372. double fl_transform_x(double x, double y) <br>
  373. double fl_transform_y(double x, double y) <br>
  374. double fl_transform_dx(double x, double y) <br>
  375. double fl_transform_dy(double x, double y) <br>
  376. void fl_transformed_vertex(double xf, double yf)
  377. \par
  378. Transform a coordinate or a distance using the current transformation matrix.
  379. After transforming a coordinate pair, it can be added to the vertex
  380. list without any further translations using \p %fl_transformed_vertex().
  381. void fl_begin_points() <br>
  382. void fl_end_points()
  383. \par
  384. Start and end drawing a list of points. Points are added to
  385. the list with \p %fl_vertex().
  386. void fl_begin_line() <br>
  387. void fl_end_line()
  388. \par
  389. Start and end drawing lines.
  390. void fl_begin_loop() <br>
  391. void fl_end_loop()
  392. \par
  393. Start and end drawing a closed sequence of lines.
  394. void fl_begin_polygon() <br>
  395. void fl_end_polygon()
  396. \par
  397. Start and end drawing a convex filled polygon.
  398. void fl_begin_complex_polygon() <br>
  399. void fl_gap() <br>
  400. void fl_end_complex_polygon()
  401. \par
  402. Start and end drawing a complex filled polygon. This polygon
  403. may be concave, may have holes in it, or may be several
  404. disconnected pieces. Call \p %fl_gap() to separate loops of
  405. the path. It is unnecessary but harmless to call
  406. \p %fl_gap() before the first vertex, after the last one,
  407. or several times in a row.
  408. \par
  409. \p %fl_gap() should only be called between
  410. \p %fl_begin_complex_polygon() and
  411. \p %fl_end_complex_polygon().
  412. To outline the polygon, use
  413. \p %fl_begin_loop() and replace each
  414. \p %fl_gap() with a
  415. \p %fl_end_loop();%fl_begin_loop() pair.
  416. \par
  417. \b Note:
  418. For portability, you should only draw polygons that appear the same whether
  419. "even/odd" or "non-zero" winding rules are used to fill them. Holes should
  420. be drawn in the opposite direction of the outside loop.
  421. void fl_vertex(double x,double y)
  422. \par
  423. Add a single vertex to the current path.
  424. void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3)
  425. \par
  426. Add a series of points on a Bezier curve to the path. The curve ends
  427. (and two of the points) are at <tt>X0,Y0</tt> and <tt>X3,Y3</tt>.
  428. \anchor drawing_fl_arc
  429. void fl_arc(double x, double y, double r, double start, double end)
  430. \par
  431. Add a series of points to the current path on the arc of a
  432. circle; you can get elliptical paths by using scale and rotate
  433. before calling \p %fl_arc().
  434. The center of the circle is given by \p x and \p y,
  435. and \p r is its radius.
  436. \p %fl_arc()
  437. takes \p start and \p end angles that are measured
  438. in degrees counter-clockwise from 3 o'clock.
  439. If \p end is less than \p start then it draws the arc in a clockwise
  440. direction.
  441. void fl_circle(double x, double y, double r)
  442. \par
  443. \p fl_circle(...) is equivalent to \p fl_arc(...,0,360) but may
  444. be faster. It must be the \e only thing in the path: if you want
  445. a circle as part of a complex polygon you must use \p %fl_arc().
  446. \par
  447. \b Note:
  448. \p %fl_circle() draws incorrectly if the transformation is both rotated and
  449. non-square scaled.
  450. \subsection ssect_Text Drawing Text
  451. All text is drawn in the
  452. \ref drawing_fl_font "current font".
  453. It is undefined whether this location or the characters are
  454. modified by the current transformation.
  455. void fl_draw(const char *, int x, int y) <br>
  456. void fl_draw(const char *, int n, int x, int y)
  457. \par
  458. Draw a nul-terminated string or an array of \p n characters
  459. starting at the given location. Text is aligned to the left and to
  460. the baseline of the font. To align to the bottom, subtract
  461. \p %fl_descent() from \p y.
  462. To align to the top, subtract \p %fl_descent() and add \p %fl_height().
  463. This version of \p %fl_draw() provides direct access to
  464. the text drawing function of the underlying OS. It does not apply any
  465. special handling to control characters.
  466. void fl_draw(const char* str, int x, int y, int w, int h, Fl_Align align, Fl_Image* img, int draw_symbols)
  467. \par
  468. Fancy string drawing function which is used to draw all the
  469. labels. The string is formatted and aligned inside the passed
  470. box. Handles '\\t' and '\\n', expands all other control
  471. characters to ^X, and aligns inside or against the edges of the
  472. box described by \p x, \p y, \p w and \p h.
  473. See Fl_Widget::align() for values for \p align.
  474. The value \p FL_ALIGN_INSIDE is ignored, as this function always
  475. prints inside the box.
  476. \par
  477. If \p img is provided and is not \p NULL, the
  478. image is drawn above or below the text as specified by the
  479. \p align value.
  480. \par
  481. The \p draw_symbols argument specifies whether or not
  482. to look for symbol names starting with the "@" character.
  483. \par
  484. The text length is limited to 1024 characters per line.
  485. void fl_measure(const char *str, int& w, int& h, int draw_symbols)
  486. \par
  487. Measure how wide and tall the string will be when printed by
  488. the \p fl_draw(...align) function.
  489. If the incoming \p w is non-zero it will wrap to that width.
  490. int fl_height()
  491. \par
  492. Recommended minimum line spacing for the current font. You
  493. can also just use the value of \p size passed to
  494. \ref drawing_fl_font "fl_font()".
  495. int fl_descent()
  496. \par
  497. Recommended distance above the bottom of a \p %fl_height() tall box to draw
  498. the text at so it looks centered vertically in that box.
  499. double fl_width(const char* txt) <br>
  500. double fl_width(const char* txt, int n) <br>
  501. double fl_width(unsigned int unicode_char)
  502. \par
  503. Return the pixel width of a nul-terminated string, a sequence of \p n
  504. characters, or a single character in the current font.
  505. const char* fl_shortcut_label(int shortcut)
  506. \par
  507. Unparse a shortcut value as used by Fl_Button or Fl_Menu_Item
  508. into a human-readable string like "Alt+N". This only
  509. works if the shortcut is a character key or a numbered function
  510. key. If the shortcut is zero an empty string is returned. The
  511. return value points at a static buffer that is overwritten with
  512. each call.
  513. \subsection ssect_Fonts Fonts
  514. FLTK supports a set of standard fonts based on the Times,
  515. Helvetica/Arial, Courier, and Symbol typefaces, as well as
  516. custom fonts that your application may load. Each font is
  517. accessed by an index into a font table.
  518. Initially only the first 16 faces are filled in. There are
  519. symbolic names for them: FL_HELVETICA,
  520. FL_TIMES, FL_COURIER, and modifier values
  521. FL_BOLD and FL_ITALIC which can be added to
  522. these, and FL_SYMBOL and FL_ZAPF_DINGBATS.
  523. Faces greater than 255 cannot be used in Fl_Widget
  524. labels, since Fl_Widget stores the index as a byte.
  525. \anchor drawing_fl_font
  526. void fl_font(int face, int size)
  527. \par
  528. Set the current font, which is then used by the routines
  529. described above. You may call this outside a draw context if
  530. necessary to call fl_width(), but on X this will open
  531. the display.
  532. \par
  533. The font is identified by a \p face and a \p size.
  534. The size of the font is measured in \p pixels and not "points".
  535. Lines should be spaced \p size pixels apart or more.
  536. int fl_font() <br>
  537. int fl_size()
  538. \par
  539. Returns the face and size set by the most recent call to
  540. \p fl_font(a,b). This can be used to save/restore the font.
  541. \subsection ssect_CharacterEncoding Character Encoding
  542. FLTK 1.3 expects all text in Unicode UTF-8 encoding. UTF-8 is
  543. ASCII compatible for the first 128 characters. International
  544. characters are encoded in multibyte sequences.
  545. FLTK expects individual characters, characters that are not part of
  546. a string, in UCS-4 encoding, which is also ASCII compatible, but
  547. requires 4 bytes to store a Unicode character.
  548. For more information about character encodings, see the chapter on
  549. \ref unicode.
  550. \subsection ssect_Overlay Drawing Overlays
  551. These functions allow you to draw interactive selection rectangles
  552. without using the overlay hardware. FLTK will XOR a single rectangle
  553. outline over a window.
  554. void fl_overlay_rect(int x, int y, int w, int h); <br>
  555. void fl_overlay_clear();
  556. \par
  557. \p %fl_overlay_rect() draws a selection rectangle, erasing any
  558. previous rectangle by XOR'ing it first. \p %fl_overlay_clear()
  559. will erase the rectangle without drawing a new one.
  560. \par
  561. Using these functions is tricky. You should make a widget
  562. with both a \p handle() and \p draw() method.
  563. \p draw() should call \p %fl_overlay_clear() before
  564. doing anything else. Your \p handle() method should call
  565. <tt>window()->make_current()</tt> and then
  566. \p %fl_overlay_rect() after FL_DRAG events, and
  567. should call \p %fl_overlay_clear() after a
  568. FL_RELEASE event.
  569. \section drawing_images Drawing Images
  570. To draw images, you can either do it directly from data in
  571. your memory, or you can create a Fl_Image object. The advantage of
  572. drawing directly is that it is more intuitive, and it is faster
  573. if the image data changes more often than it is redrawn. The
  574. advantage of using the object is that FLTK will cache translated
  575. forms of the image (on X it uses a server pixmap) and thus
  576. redrawing is \e much faster.
  577. \subsection ssect_DirectImageDrawing Direct Image Drawing
  578. The behavior when drawing images when the current
  579. transformation matrix is not the identity is not defined, so you
  580. should only draw images when the matrix is set to the identity.
  581. \anchor drawing_fl_draw_image
  582. void fl_draw_image(const uchar *buf,int X,int Y,int W,int H,int D,int L)<br>
  583. void fl_draw_image_mono(const uchar *buf,int X,int Y,int W,int H,int D,int L)
  584. \par
  585. Draw an 8-bit per color RGB or luminance image. The pointer
  586. points at the "r" data of the top-left pixel. Color
  587. data must be in <tt>r,g,b</tt> order.
  588. The top left corner is given by \p X and \p Y
  589. and the size of the image is given by \p W and \p H.
  590. \p D is the delta to add to the pointer between pixels,
  591. it may be any value greater or equal to \p 3,
  592. or it can be negative to flip the image horizontally.
  593. \p L is the delta to add to the pointer between lines
  594. (if 0 is passed it uses \p W*D).
  595. and may be larger than \p W*D to crop data,
  596. or negative to flip the image vertically.
  597. \par
  598. It is highly recommended that you put the following code before the
  599. first show() of \e any window in your program to get rid
  600. of the dithering if possible:
  601. \code
  602. Fl::visual(FL_RGB);
  603. \endcode
  604. \par
  605. Gray scale (1-channel) images may be drawn. This is done if
  606. <tt>abs(D)</tt> is less than 3, or by calling
  607. \p %fl_draw_image_mono(). Only one 8-bit sample is used for
  608. each pixel, and on screens with different numbers of bits for
  609. red, green, and blue only gray colors are used. Setting
  610. \p D greater than 1 will let you display one channel of a
  611. color image.
  612. \par
  613. \b Note:
  614. The X version does not support all possible visuals.
  615. If FLTK cannot draw the image in the current visual it
  616. will abort. FLTK supports any visual of 8 bits or less,
  617. and all common TrueColor visuals up to 32 bits.
  618. typedef void (*Fl_Draw_Image_Cb)(void *data,int x,int y,int w,uchar *buf) <br>
  619. void fl_draw_image(Fl_Draw_Image_Cb cb,void *data,int X,int Y,int W,int H,int D) <br>
  620. void fl_draw_image_mono(Fl_Draw_Image_Cb cb,void *data,int X,int Y,int W,int H,int D)
  621. \par
  622. Call the passed function to provide each scan line of the
  623. image. This lets you generate the image as it is being drawn,
  624. or do arbitrary decompression of stored data, provided it can be
  625. decompressed to individual scan lines easily.
  626. \par
  627. The callback is called with the \p void* user data
  628. pointer which can be used to point at a structure of information
  629. about the image, and the \p x, \p y, and \p w
  630. of the scan line desired from the image. 0,0 is the upper-left
  631. corner of the image, <I>not <tt>X,Y</tt></I>. A pointer to a
  632. buffer to put the data into is passed. You must copy \p w
  633. pixels from scanline \p y, starting at pixel \p x,
  634. to this buffer.
  635. \par
  636. Due to cropping, less than the whole image may be requested.
  637. So \p x may be greater than zero, the first \p y may
  638. be greater than zero, and \p w may be less than \p W.
  639. The buffer is long enough to store the entire \p W*D
  640. pixels, this is for convenience with some decompression
  641. schemes where you must decompress the entire line at once:
  642. decompress it into the buffer, and then if \p x is not
  643. zero, copy the data over so the \p x'th pixel is at the
  644. start of the buffer.
  645. \par
  646. You can assume the \p y's will be consecutive, except
  647. the first one may be greater than zero.
  648. \par
  649. If \p D is 4 or more, you must fill in the unused bytes
  650. with zero.
  651. int fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg) <br>
  652. int fl_draw_pixmap(const char* const* cdata, int x, int y, Fl_Color bg)
  653. \par
  654. Draws XPM image data, with the top-left corner at the given position.
  655. The image is dithered on 8-bit displays so you won't lose color space
  656. for programs displaying both images and pixmaps. This function returns
  657. zero if there was any error decoding the XPM data.
  658. \par
  659. To use an XPM, do:
  660. \code
  661. #include "foo.xpm"
  662. ...
  663. fl_draw_pixmap(foo, X, Y);
  664. \endcode
  665. \par
  666. Transparent colors are replaced by the optional
  667. Fl_Color argument. To draw with true transparency you must
  668. use the Fl_Pixmap class.
  669. int fl_measure_pixmap(char* const* data, int &w, int &h) <br>
  670. int fl_measure_pixmap(const char* const* cdata, int &w, int &h)
  671. \par
  672. An XPM image contains the dimensions in its data. This
  673. function finds and returns the width and height. The return
  674. value is non-zero if the dimensions were parsed ok and zero if
  675. there was any problem.
  676. \subsection ssect_DirectImageReading Direct Image Reading
  677. FLTK provides a single function for reading from the current
  678. window or off-screen buffer into a RGB(A) image buffer.
  679. uchar* fl_read_image(uchar *p, int X, int Y, int W, int H, int alpha)
  680. \par
  681. Read a RGB(A) image from the current window or off-screen
  682. buffer. The \p p argument points to a buffer that can hold
  683. the image and must be at least \p W*H*3 bytes when reading
  684. RGB images and \p W*H*4 bytes when reading RGBA images. If
  685. \p NULL, \p %fl_read_image() will create an array of
  686. the proper size which can be freed using \p delete[].
  687. \par
  688. The \p alpha parameter controls whether an alpha
  689. channel is created and the value that is placed in the alpha
  690. channel. If 0, no alpha channel is generated.
  691. \subsection ssect_Fl_Image Image Classes
  692. FLTK provides a base image class called Fl_Image which supports
  693. creating, copying, and drawing images of various kinds, along
  694. with some basic color operations. Images can be used as labels
  695. for widgets using the \p image() and \p deimage() methods or drawn directly.
  696. The Fl_Image class does almost nothing by itself, but is instead
  697. supported by three basic image types:
  698. \li Fl_Bitmap
  699. \li Fl_Pixmap
  700. \li Fl_RGB_Image
  701. The Fl_Bitmap class encapsulates a mono-color bitmap image.
  702. The \p draw() method draws the image using the current drawing
  703. color.
  704. The Fl_Pixmap class encapsulates a colormapped image.
  705. The \p draw() method draws the image using the colors in the
  706. file, and masks off any transparent colors automatically.
  707. The Fl_RGB_Image class encapsulates a full-color
  708. (or grayscale) image with 1 to 4 color components. Images with
  709. an even number of components are assumed to contain an
  710. alpha channel that is used for transparency. The transparency
  711. provided by the draw() method is either a 24-bit
  712. blend against the existing window contents or a "screen door"
  713. transparency mask, depending on the platform and screen color depth.
  714. char fl_can_do_alpha_blending()
  715. \par
  716. \p %fl_can_do_alpha_blending() will return 1, if your
  717. platform supports true alpha blending for RGBA images, or 0,
  718. if FLTK will use screen door transparency.
  719. FLTK also provides several image classes based on the three
  720. standard image types for common file formats:
  721. \li Fl_GIF_Image
  722. \li Fl_JPEG_Image
  723. \li Fl_PNG_Image
  724. \li Fl_PNM_Image
  725. \li Fl_XBM_Image
  726. \li Fl_XPM_Image
  727. Each of these image classes load a named file of the
  728. corresponding format. The Fl_Shared_Image class
  729. can be used to load any type of image file - the class examines
  730. the file and constructs an image of the appropriate type.
  731. Finally, FLTK provides a special image class called Fl_Tiled_Image to
  732. tile another image object in the specified area. This class can be
  733. used to tile a background image in a Fl_Group widget, for example.
  734. virtual void Fl_Tiled_Image::copy(); <br>
  735. virtual Fl_Image* Fl_Tiled_Image::copy(int w, int h);
  736. \par
  737. The \p copy() method creates a copy of the image. The second form
  738. specifies the new size of the image - the image is resized using the
  739. nearest-neighbor algorithm.
  740. void Fl_Tiled_Image::draw(int x, int y, int w, int h, int ox, int oy);
  741. \par
  742. The \p draw() method draws the image object.
  743. <tt>x,y,w,h</tt> indicates a destination rectangle.
  744. <tt>ox,oy,w,h</tt> is a source rectangle. This source rectangle
  745. is copied to the destination. The source rectangle may extend
  746. outside the image, i.e. \p ox and \p oy may be
  747. negative and \p w and \p h may be bigger than the
  748. image, and this area is left unchanged.
  749. void Fl_Tiled_Image::draw(int x, int y)
  750. \par
  751. Draws the image with the upper-left corner at <tt>x,y</tt>.
  752. This is the same as doing \p draw(x,y,img->w(),img->h(),0,0).
  753. \subsection ssect_Offscreen Offscreen Drawing
  754. Sometimes it can be very useful to generate a complex drawing
  755. in memory first and copy it to the screen at a later point in
  756. time. This technique can significantly reduce the amount of
  757. repeated drawing. Offscreen drawing functions are declared in <FL/x.H>.
  758. Fl_Double_Window uses offscreen rendering
  759. to avoid flickering on systems that don't support
  760. double-buffering natively.
  761. Fl_Offscreen fl_create_offscreen(int w, int h)
  762. \par
  763. Create an RGB offscreen buffer with \p w*h pixels.
  764. void fl_delete_offscreen(Fl_Offscreen)
  765. \par
  766. Delete a previously created offscreen buffer. All drawings are lost.
  767. void fl_begin_offscreen(Fl_Offscreen)
  768. \par
  769. Send all subsequent drawing commands to this offscreen buffer.
  770. FLTK can draw into a buffer at any time. There is no need to wait for
  771. an Fl_Widget::draw() to occur.
  772. void fl_end_offscreen()
  773. \par
  774. Quit sending drawing commands to this offscreen buffer.
  775. void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, int srcy)
  776. \par
  777. Copy a rectangular area of the size \p w*h from \p srcx,srcy
  778. in the offscreen buffer into the current buffer at \p x,y.
  779. \htmlonly
  780. <hr>
  781. <table summary="navigation bar" width="100%" border="0">
  782. <tr>
  783. <td width="45%" align="LEFT">
  784. <a class="el" href="editor.html">
  785. [Prev]
  786. Designing a Simple Text Editor
  787. </a>
  788. </td>
  789. <td width="10%" align="CENTER">
  790. <a class="el" href="index.html">[Index]</a>
  791. </td>
  792. <td width="45%" align="RIGHT">
  793. <a class="el" href="events.html">
  794. Handling Events
  795. [Next]
  796. </a>
  797. </td>
  798. </tr>
  799. </table>
  800. \endhtmlonly
  801. */