FLTK 1.3.0
fl_draw.H
Go to the documentation of this file.
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 
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 
51 // Colors:
61 inline void fl_color(Fl_Color c) {fl_graphics_driver->color(c); } // select indexed color
63 inline void fl_color(int c) {fl_color((Fl_Color)c);}
74 inline void fl_color(uchar r, uchar g, uchar b) {fl_graphics_driver->color(r,g,b); } // select actual color
85 // clip:
91 inline void fl_push_clip(int x, int y, int w, int h) {fl_graphics_driver->push_clip(x,y,w,h); }
100 #define fl_clip fl_push_clip
101 
123 inline int fl_not_clipped(int x, int y, int w, int h) {return fl_graphics_driver->not_clipped(x,y,w,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); }
145 inline void fl_clip_region(Fl_Region r) { fl_graphics_driver->clip_region(r); }
149 inline Fl_Region fl_clip_region() { return fl_graphics_driver->clip_region(); }
150 
151 
152 // points:
156 inline void fl_point(int x, int y) { fl_graphics_driver->point(x,y); }
157 
158 // line type:
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,
189  FL_DASH = 1,
190  FL_DOT = 2,
193 
194  FL_CAP_FLAT = 0x100,
195  FL_CAP_ROUND = 0x200,
196  FL_CAP_SQUARE = 0x300,
197 
198  FL_JOIN_MITER = 0x1000,
199  FL_JOIN_ROUND = 0x2000,
200  FL_JOIN_BEVEL = 0x3000
201 };
202 
203 // rectangles tweaked to exactly fill the pixel rectangle:
204 
210 inline void fl_rect(int x, int y, int w, int h) { fl_graphics_driver->rect(x,y,w,h); }
211 
213 inline void fl_rect(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rect(x,y,w,h);}
215 inline void fl_rectf(int x, int y, int w, int h) { fl_graphics_driver->rectf(x,y,w,h); }
217 inline void fl_rectf(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rectf(x,y,w,h);}
218 
225 /* note: doxygen comment here to avoid triplication in os-speciic files */
226 FL_EXPORT void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b);
227 
228 // line segments:
232 inline void fl_line(int x, int y, int x1, int y1) {fl_graphics_driver->line(x,y,x1,y1); }
236 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); }
237 
238 // closed line segments:
242 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); }
246 inline void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
247  {fl_graphics_driver->loop(x,y,x1,y1,x2,y2,x3,y3); }
248 
249 // filled polygons
253 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); }
257 inline void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)
258  { fl_graphics_driver->polygon(x,y,x1,y1,x2,y2,x3,y3); }
259 
260 // draw rectilinear lines, horizontal segment first:
264 inline void fl_xyline(int x, int y, int x1) {fl_graphics_driver->xyline(x,y,x1);}
268 inline void fl_xyline(int x, int y, int x1, int y2) {fl_graphics_driver->xyline(x,y,x1,y2);}
273 inline void fl_xyline(int x, int y, int x1, int y2, int x3) {fl_graphics_driver->xyline(x,y,x1,y2,x3);}
274 
275 // draw rectilinear lines, vertical segment first:
279 inline void fl_yxline(int x, int y, int y1) {fl_graphics_driver->yxline(x,y,y1);}
283 inline void fl_yxline(int x, int y, int y1, int x2) {fl_graphics_driver->yxline(x,y,y1,x2);}
288 inline void fl_yxline(int x, int y, int y1, int x2, int y3) {fl_graphics_driver->yxline(x,y,y1,x2,y3);}
289 
290 // circular lines and pie slices (code in fl_arci.C):
313 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); }
326 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); }
328 FL_EXPORT void fl_chord(int x, int y, int w, int h, double a1, double a2); // nyi
329 
330 // scalable drawing code (code in fl_vertex.C and fl_arc.C):
344 inline void fl_scale(double x, double y) { fl_graphics_driver->scale(x, y); }
349 inline void fl_scale(double x) { fl_graphics_driver->scale(x, x); }
354 inline void fl_translate(double x, double y) { fl_graphics_driver->translate(x, y); }
359 inline void fl_rotate(double d) { fl_graphics_driver->rotate(d); }
366 inline void fl_mult_matrix(double a, double b, double c, double d, double x,double y)
367  { fl_graphics_driver->mult_matrix(a, b, c, d, x, y); }
388 inline void fl_vertex(double x, double y) {fl_graphics_driver->vertex(x,y); }
397 inline void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3)
398  {fl_graphics_driver->curve(X0,Y0,X1,Y1,X2,Y2,X3,Y3); }
407 inline void fl_arc(double x, double y, double r, double start, double end) {fl_graphics_driver->arc(x,y,r,start,end); }
415 inline void fl_circle(double x, double y, double r) {fl_graphics_driver->circle(x,y,r); }
453 inline void fl_gap() {fl_graphics_driver->gap(); }
458 // get and use transformed positions:
463 inline double fl_transform_x(double x, double y) {return fl_graphics_driver->transform_x(x, y); }
468 inline double fl_transform_y(double x, double y) {return fl_graphics_driver->transform_y(x, y); }
473 inline double fl_transform_dx(double x, double y) {return fl_graphics_driver->transform_dx(x, y); }
478 inline double fl_transform_dy(double x, double y) {return fl_graphics_driver->transform_dy(x, y); }
483 inline void fl_transformed_vertex(double xf, double yf) {fl_graphics_driver->transformed_vertex(xf,yf); }
488 /* NOTE: doxygen comments here to avoid triplication in os-specific sources */
489 
490 // Fonts:
500 inline void fl_font(Fl_Font face, Fl_Fontsize size) { fl_graphics_driver->font(face,size); }
501 
506 inline Fl_Font fl_font() {return fl_graphics_driver->font();}
512 
513 // information you can get about the current font:
518 inline int fl_height() {return fl_graphics_driver->height();}
519 FL_EXPORT int fl_height(int font, int size);
524 inline int fl_descent() {return fl_graphics_driver->descent();}
526 FL_EXPORT double fl_width(const char* txt);
528 inline double fl_width(const char* txt, int n) {return fl_graphics_driver->width(txt, n);}
532 inline double fl_width(unsigned int c) {return fl_graphics_driver->width(c);}
541 FL_EXPORT void fl_text_extents(const char*, int& dx, int& dy, int& w, int& h); // NO fltk symbol expansion will be performed
545 inline void fl_text_extents(const char *t, int n, int& dx, int& dy, int& w, int& h)
546  {fl_graphics_driver->text_extents(t, n, dx, dy, w, h);}
547 
548 // font encoding:
549 // Note: doxygen comments here to avoid duplication for os-sepecific cases
556 FL_EXPORT const char *fl_latin1_to_local(const char *t, int n=-1);
563 FL_EXPORT const char *fl_local_to_latin1(const char *t, int n=-1);
570 FL_EXPORT const char *fl_mac_roman_to_local(const char *t, int n=-1);
577 FL_EXPORT const char *fl_local_to_mac_roman(const char *t, int n=-1);
592 FL_EXPORT void fl_draw(const char* str, int x, int y);
600 FL_EXPORT void fl_draw(int angle, const char* str, int x, int y);
604 inline void fl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->draw(str,n,x,y); }
609 inline void fl_draw(int angle,const char* str, int n, int x, int y) {fl_graphics_driver->draw(angle,str,n,x,y); }
613 inline void fl_rtl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->rtl_draw(str,n,x,y); }
614 FL_EXPORT void fl_measure(const char* str, int& x, int& y,
615  int draw_symbols = 1);
616 FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h,
617  Fl_Align align,
618  Fl_Image* img=0, int draw_symbols = 1);
619 FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h,
620  Fl_Align align,
621  void (*callthis)(const char *,int,int,int),
622  Fl_Image* img=0, int draw_symbols = 1);
623 
624 // boxtypes:
625 FL_EXPORT void fl_frame(const char* s, int x, int y, int w, int h);
626 FL_EXPORT void fl_frame2(const char* s, int x, int y, int w, int h);
627 FL_EXPORT void fl_draw_box(Fl_Boxtype, int x, int y, int w, int h, Fl_Color);
628 
629 // images:
630 
666 inline void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0)
667  { fl_graphics_driver->draw_image(buf, X, Y, W, H, D, L); }
668 
673 inline void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0)
674  { fl_graphics_driver->draw_image_mono(buf, X, Y, W, H, D, L); }
675 
709 inline void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3)
710  { fl_graphics_driver->draw_image(cb, data, X, Y, W, H, D); }
711 
716 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);
717 
723 /* note: doxygen comment here to avoid triplication in os-speciic files */
724 FL_EXPORT char fl_can_do_alpha_blending();
725 
743 /* note: doxygen comment here to avoid triplication in os-speciic files */
744 FL_EXPORT uchar *fl_read_image(uchar *p,int X,int Y,int W,int H,int alpha=0);
745 
746 // pixmaps:
747 FL_EXPORT int fl_draw_pixmap(/*const*/ char* const* data, int x,int y,Fl_Color=FL_GRAY);
748 FL_EXPORT int fl_draw_pixmap(const char* const* cdata, int x,int y,Fl_Color=FL_GRAY);
749 FL_EXPORT int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h);
750 FL_EXPORT int fl_measure_pixmap(const char* const* cdata, int &w, int &h);
751 
752 // other:
753 FL_EXPORT void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
754  void (*draw_area)(void*, int,int,int,int), void* data);
755 FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut);
756 FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut, const char **eom);
757 FL_EXPORT unsigned int fl_old_shortcut(const char* s);
758 FL_EXPORT void fl_overlay_rect(int x,int y,int w,int h);
759 FL_EXPORT void fl_overlay_clear();
760 FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg=FL_BLACK, Fl_Color bg=FL_WHITE);
761 FL_EXPORT const char* fl_expand_text(const char* from, char* buf, int maxbuf,
762  double maxw, int& n, double &width,
763  int wrap, int draw_symbols = 0);
764 
765 // XIM:
767 FL_EXPORT void fl_set_status(int X, int Y, int W, int H);
769 FL_EXPORT void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win=0);
771 FL_EXPORT void fl_reset_spot(void);
772 
773 
774 
775 // XForms symbols:
776 FL_EXPORT int fl_draw_symbol(const char* label,int x,int y,int w,int h, Fl_Color);
777 FL_EXPORT int fl_add_symbol(const char* name, void (*drawit)(Fl_Color), int scalable);
780 #endif
781 
782 //
783 // End of "$Id: fl_draw.H 8772 2011-06-02 08:06:09Z manolo $".
784 //