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