FLTK 1.3.x
|
00001 // 00002 // "$Id: fl_draw.H 8130 2010-12-28 18:14:59Z manolo $" 00003 // 00004 // Portable drawing function header file for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00033 #ifndef fl_draw_H 00034 #define fl_draw_H 00035 00036 #include <FL/x.H> // for Fl_Region 00037 #include <FL/Enumerations.H> // for the color names 00038 #include <FL/Fl_Window.H> // for fl_set_spot() 00039 #include <FL/Fl_Device.H> // for fl_graphics_driver 00040 00041 // Image class... 00042 class Fl_Image; 00043 00044 // Label flags... 00045 FL_EXPORT extern char fl_draw_shortcut; 00046 00051 // Colors: 00061 inline void fl_color(Fl_Color c) {fl_graphics_driver->color(c); } // select indexed color 00063 inline void fl_color(int c) {fl_color((Fl_Color)c);} 00074 inline void fl_color(uchar r, uchar g, uchar b) {fl_graphics_driver->color(r,g,b); } // select actual color 00076 extern FL_EXPORT Fl_Color fl_color_; 00081 inline Fl_Color fl_color() {return fl_color_;} 00087 // clip: 00093 inline void fl_push_clip(int x, int y, int w, int h) {fl_graphics_driver->push_clip(x,y,w,h); } 00095 #define fl_clip fl_push_clip 00096 00099 inline void fl_push_no_clip() {fl_graphics_driver->push_no_clip(); } 00107 inline void fl_pop_clip() {fl_graphics_driver->pop_clip(); } 00118 inline int fl_not_clipped(int x, int y, int w, int h) {return fl_graphics_driver->not_clipped(x,y,w,h); } 00133 inline int fl_clip_box(int x , int y, int w, int h, int& X, int& Y, int& W, int& H) 00134 {return fl_graphics_driver->clip_box(x,y,w,h,X,Y,W,H); } 00136 extern void fl_restore_clip(); 00143 FL_EXPORT void fl_clip_region(Fl_Region r); 00147 extern Fl_Region fl_clip_region(); 00148 00149 00150 // points: 00154 inline void fl_point(int x, int y) { fl_graphics_driver->point(x,y); } 00155 00156 // line type: 00184 inline void fl_line_style(int style, int width=0, char* dashes=0) {fl_graphics_driver->line_style(style,width,dashes); } 00185 enum { 00186 FL_SOLID = 0, 00187 FL_DASH = 1, 00188 FL_DOT = 2, 00189 FL_DASHDOT = 3, 00190 FL_DASHDOTDOT = 4, 00191 00192 FL_CAP_FLAT = 0x100, 00193 FL_CAP_ROUND = 0x200, 00194 FL_CAP_SQUARE = 0x300, 00195 00196 FL_JOIN_MITER = 0x1000, 00197 FL_JOIN_ROUND = 0x2000, 00198 FL_JOIN_BEVEL = 0x3000 00199 }; 00200 00201 // rectangles tweaked to exactly fill the pixel rectangle: 00202 00208 inline void fl_rect(int x, int y, int w, int h) { fl_graphics_driver->rect(x,y,w,h); } 00209 00211 inline void fl_rect(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rect(x,y,w,h);} 00213 inline void fl_rectf(int x, int y, int w, int h) { fl_graphics_driver->rectf(x,y,w,h); } 00215 inline void fl_rectf(int x, int y, int w, int h, Fl_Color c) {fl_color(c); fl_rectf(x,y,w,h);} 00216 00223 /* note: doxygen comment here to avoid triplication in os-speciic files */ 00224 FL_EXPORT void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b); 00225 00226 // line segments: 00230 inline void fl_line(int x, int y, int x1, int y1) {fl_graphics_driver->line(x,y,x1,y1); } 00234 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); } 00235 00236 // closed line segments: 00240 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); } 00244 inline void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) 00245 {fl_graphics_driver->loop(x,y,x1,y1,x2,y2,x3,y3); } 00246 00247 // filled polygons 00251 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); } 00255 inline void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) 00256 { fl_graphics_driver->polygon(x,y,x1,y1,x2,y2,x3,y3); } 00257 00258 // draw rectilinear lines, horizontal segment first: 00262 inline void fl_xyline(int x, int y, int x1) {fl_graphics_driver->xyline(x,y,x1);} 00266 inline void fl_xyline(int x, int y, int x1, int y2) {fl_graphics_driver->xyline(x,y,x1,y2);} 00271 inline void fl_xyline(int x, int y, int x1, int y2, int x3) {fl_graphics_driver->xyline(x,y,x1,y2,x3);} 00272 00273 // draw rectilinear lines, vertical segment first: 00277 inline void fl_yxline(int x, int y, int y1) {fl_graphics_driver->yxline(x,y,y1);} 00281 inline void fl_yxline(int x, int y, int y1, int x2) {fl_graphics_driver->yxline(x,y,y1,x2);} 00286 inline void fl_yxline(int x, int y, int y1, int x2, int y3) {fl_graphics_driver->yxline(x,y,y1,x2,y3);} 00287 00288 // circular lines and pie slices (code in fl_arci.C): 00311 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); } 00324 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); } 00326 FL_EXPORT void fl_chord(int x, int y, int w, int h, double a1, double a2); // nyi 00327 00328 // scalable drawing code (code in fl_vertex.C and fl_arc.C): 00329 FL_EXPORT void fl_push_matrix(); 00330 FL_EXPORT void fl_pop_matrix(); 00331 FL_EXPORT void fl_scale(double x, double y); 00332 FL_EXPORT void fl_scale(double x); 00333 FL_EXPORT void fl_translate(double x, double y); 00334 FL_EXPORT void fl_rotate(double d); 00335 FL_EXPORT void fl_mult_matrix(double a, double b, double c, double d, double x,double y); 00339 inline void fl_begin_points() {fl_graphics_driver->begin_points(); } 00343 inline void fl_begin_line() {fl_graphics_driver->begin_line(); } 00347 inline void fl_begin_loop() {fl_graphics_driver->begin_loop(); } 00351 inline void fl_begin_polygon() {fl_graphics_driver->begin_polygon(); } 00356 inline void fl_vertex(double x, double y) {fl_graphics_driver->vertex(x,y); } 00365 inline void fl_curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3) 00366 {fl_graphics_driver->curve(X0,Y0,X1,Y1,X2,Y2,X3,Y3); } 00375 inline void fl_arc(double x, double y, double r, double start, double end) {fl_graphics_driver->arc(x,y,r,start,end); } 00383 inline void fl_circle(double x, double y, double r) {fl_graphics_driver->circle(x,y,r); } 00387 inline void fl_end_points() {fl_graphics_driver->end_points(); } 00391 inline void fl_end_line() {fl_graphics_driver->end_line(); } 00395 inline void fl_end_loop() {fl_graphics_driver->end_loop(); } 00399 inline void fl_end_polygon() {fl_graphics_driver->end_polygon(); } 00414 inline void fl_begin_complex_polygon() {fl_graphics_driver->begin_complex_polygon(); } 00421 inline void fl_gap() {fl_graphics_driver->gap(); } 00425 inline void fl_end_complex_polygon() {fl_graphics_driver->end_complex_polygon(); } 00426 // get and use transformed positions: 00427 FL_EXPORT double fl_transform_x(double x, double y); 00428 FL_EXPORT double fl_transform_y(double x, double y); 00429 FL_EXPORT double fl_transform_dx(double x, double y); 00430 FL_EXPORT double fl_transform_dy(double x, double y); 00435 inline void fl_transformed_vertex(double xf, double yf) {fl_graphics_driver->transformed_vertex(xf,yf); } 00440 /* NOTE: doxygen comments here to avoid triplication in os-specific sources */ 00441 00442 // Fonts: 00452 inline void fl_font(Fl_Font face, Fl_Fontsize size) { fl_graphics_driver->font(face,size); } 00453 extern FL_EXPORT Fl_Font fl_font_; 00454 00459 inline Fl_Font fl_font() {return fl_font_;} 00461 extern FL_EXPORT Fl_Fontsize fl_size_; 00466 inline Fl_Fontsize fl_size() {return fl_size_;} 00467 00468 // information you can get about the current font: 00473 FL_EXPORT int fl_height(); // using "size" should work ok 00474 FL_EXPORT int fl_height(int font, int size); 00479 FL_EXPORT int fl_descent(); 00481 FL_EXPORT double fl_width(const char* txt); 00483 FL_EXPORT double fl_width(const char* txt, int n); 00487 FL_EXPORT double fl_width(unsigned int); 00496 FL_EXPORT void fl_text_extents(const char*, int& dx, int& dy, int& w, int& h); // NO fltk symbol expansion will be performed 00500 FL_EXPORT void fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); 00501 00502 // font encoding: 00503 // Note: doxygen comments here to avoid duplication for os-sepecific cases 00510 FL_EXPORT const char *fl_latin1_to_local(const char *t, int n=-1); 00517 FL_EXPORT const char *fl_local_to_latin1(const char *t, int n=-1); 00524 FL_EXPORT const char *fl_mac_roman_to_local(const char *t, int n=-1); 00531 FL_EXPORT const char *fl_local_to_mac_roman(const char *t, int n=-1); 00546 FL_EXPORT void fl_draw(const char* str, int x, int y); 00554 FL_EXPORT void fl_draw(int angle, const char* str, int x, int y); 00558 inline void fl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->draw(str,n,x,y); } 00563 inline void fl_draw(int angle,const char* str, int n, int x, int y) {fl_graphics_driver->draw(angle,str,n,x,y); } 00567 inline void fl_rtl_draw(const char* str, int n, int x, int y) {fl_graphics_driver->rtl_draw(str,n,x,y); } 00568 FL_EXPORT void fl_measure(const char* str, int& x, int& y, 00569 int draw_symbols = 1); 00570 FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h, 00571 Fl_Align align, 00572 Fl_Image* img=0, int draw_symbols = 1); 00573 FL_EXPORT void fl_draw(const char* str, int x, int y, int w, int h, 00574 Fl_Align align, 00575 void (*callthis)(const char *,int,int,int), 00576 Fl_Image* img=0, int draw_symbols = 1); 00577 00578 // boxtypes: 00579 FL_EXPORT void fl_frame(const char* s, int x, int y, int w, int h); 00580 FL_EXPORT void fl_frame2(const char* s, int x, int y, int w, int h); 00581 FL_EXPORT void fl_draw_box(Fl_Boxtype, int x, int y, int w, int h, Fl_Color); 00582 00583 // images: 00584 00618 inline void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) 00619 { fl_graphics_driver->draw_image(buf, X, Y, W, H, D, L); } 00620 00625 inline void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0) 00626 { fl_graphics_driver->draw_image_mono(buf, X, Y, W, H, D, L); } 00627 00660 inline void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3) 00661 { fl_graphics_driver->draw_image(cb, data, X, Y, W, H, D); } 00662 00667 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); 00668 00674 /* note: doxygen comment here to avoid triplication in os-speciic files */ 00675 FL_EXPORT char fl_can_do_alpha_blending(); 00676 00694 /* note: doxygen comment here to avoid triplication in os-speciic files */ 00695 FL_EXPORT uchar *fl_read_image(uchar *p,int X,int Y,int W,int H,int alpha=0); 00696 00697 // pixmaps: 00698 FL_EXPORT int fl_draw_pixmap(/*const*/ char* const* data, int x,int y,Fl_Color=FL_GRAY); 00699 FL_EXPORT int fl_draw_pixmap(const char* const* cdata, int x,int y,Fl_Color=FL_GRAY); 00700 FL_EXPORT int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h); 00701 FL_EXPORT int fl_measure_pixmap(const char* const* cdata, int &w, int &h); 00702 00703 // other: 00704 FL_EXPORT void fl_scroll(int X, int Y, int W, int H, int dx, int dy, 00705 void (*draw_area)(void*, int,int,int,int), void* data); 00706 FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut); 00707 FL_EXPORT const char* fl_shortcut_label(unsigned int shortcut, const char **eom); 00708 FL_EXPORT unsigned int fl_old_shortcut(const char* s); 00709 FL_EXPORT void fl_overlay_rect(int x,int y,int w,int h); 00710 FL_EXPORT void fl_overlay_clear(); 00711 FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg=FL_BLACK, Fl_Color bg=FL_WHITE); 00712 FL_EXPORT const char* fl_expand_text(const char* from, char* buf, int maxbuf, 00713 double maxw, int& n, double &width, 00714 int wrap, int draw_symbols = 0); 00715 00716 // XIM: 00718 FL_EXPORT void fl_set_status(int X, int Y, int W, int H); 00720 FL_EXPORT void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win=0); 00722 FL_EXPORT void fl_reset_spot(void); 00723 00724 00725 00726 // XForms symbols: 00727 FL_EXPORT int fl_draw_symbol(const char* label,int x,int y,int w,int h, Fl_Color); 00728 FL_EXPORT int fl_add_symbol(const char* name, void (*drawit)(Fl_Color), int scalable); 00731 #endif 00732 00733 // 00734 // End of "$Id: fl_draw.H 8130 2010-12-28 18:14:59Z manolo $". 00735 //