[773] | 1 | // "$Id: draw.h 4408 2005-07-09 06:41:56Z spitzak $" |
---|
| 2 | // |
---|
| 3 | // Copyright 1998-2005 by Bill Spitzak and others. |
---|
| 4 | // |
---|
| 5 | // This library is free software; you can redistribute it and/or |
---|
| 6 | // modify it under the terms of the GNU Library General Public |
---|
| 7 | // License as published by the Free Software Foundation; either |
---|
| 8 | // version 2 of the License, or (at your option) any later version. |
---|
| 9 | // |
---|
| 10 | // This library is distributed in the hope that it will be useful, |
---|
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | // Library General Public License for more details. |
---|
| 14 | // |
---|
| 15 | // You should have received a copy of the GNU Library General Public |
---|
| 16 | // License along with this library; if not, write to the Free Software |
---|
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 18 | // USA. |
---|
| 19 | // |
---|
| 20 | // Please report all bugs and problems to "fltk-bugs@fltk.org". |
---|
| 21 | |
---|
| 22 | #ifndef fltk_draw_h |
---|
| 23 | #define fltk_draw_h |
---|
| 24 | |
---|
| 25 | #include "Flags.h" // for alignment values |
---|
| 26 | #include "Color.h" |
---|
| 27 | #include "Rectangle.h" |
---|
| 28 | #include "PixelType.h" |
---|
| 29 | |
---|
| 30 | namespace fltk { |
---|
| 31 | |
---|
| 32 | struct Font; |
---|
| 33 | class Style; |
---|
| 34 | |
---|
| 35 | class FL_API GSave { |
---|
| 36 | void* data[4]; // hopefully big enough for everybody... |
---|
| 37 | public: |
---|
| 38 | GSave(); |
---|
| 39 | ~GSave(); |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | /*! \addtogroup transformation |
---|
| 43 | \{ */ |
---|
| 44 | FL_API void push_matrix(); |
---|
| 45 | FL_API void pop_matrix(); |
---|
| 46 | FL_API void scale(float x, float y); |
---|
| 47 | FL_API void scale(float x); |
---|
| 48 | FL_API void translate(float x, float y); |
---|
| 49 | FL_API void translate(int x, int y); |
---|
| 50 | FL_API void rotate(float d); |
---|
| 51 | FL_API void concat(float, float, float, float, float, float); |
---|
| 52 | FL_API void load_identity(); |
---|
| 53 | |
---|
| 54 | // get and use transformed positions: |
---|
| 55 | FL_API void transform(float& x, float& y); |
---|
| 56 | FL_API void transform_distance(float& x, float& y); |
---|
| 57 | FL_API void transform(int& x, int& y); |
---|
| 58 | FL_API void transform(Rectangle&); |
---|
| 59 | |
---|
| 60 | /*! \} */ |
---|
| 61 | |
---|
| 62 | /*! \addtogroup clipping |
---|
| 63 | \{ */ |
---|
| 64 | FL_API void push_clip(const Rectangle&); |
---|
| 65 | FL_API void clipout(const Rectangle&); |
---|
| 66 | FL_API void pop_clip(); |
---|
| 67 | FL_API void push_no_clip(); |
---|
| 68 | FL_API bool not_clipped(const Rectangle&); |
---|
| 69 | FL_API int intersect_with_clip(Rectangle&); |
---|
| 70 | /*! \} */ |
---|
| 71 | |
---|
| 72 | /*! \addtogroup color |
---|
| 73 | \{ */ |
---|
| 74 | FL_API void setcolor(Color); |
---|
| 75 | extern FL_API Color current_color_; |
---|
| 76 | inline Color getcolor() {return current_color_;} |
---|
| 77 | extern FL_API Color current_bgcolor_; |
---|
| 78 | inline void setbgcolor(Color c) {current_bgcolor_ = c;} |
---|
| 79 | inline Color getbgcolor() {return current_bgcolor_;} |
---|
| 80 | |
---|
| 81 | extern const Style* drawstyle_; |
---|
| 82 | void FL_API drawstyle(const Style* s, Flags); |
---|
| 83 | inline const Style* drawstyle() {return drawstyle_;} |
---|
| 84 | |
---|
| 85 | extern Flags drawflags_; |
---|
| 86 | inline void setdrawflags(Flags f) {drawflags_ = f;} |
---|
| 87 | inline Flags drawflags() {return drawflags_;} |
---|
| 88 | inline Flags drawflags(Flags f) {return drawflags_ & f;} |
---|
| 89 | |
---|
| 90 | // line type: |
---|
| 91 | FL_API void line_style(int, int width=0, char* dashes=0); |
---|
| 92 | enum { |
---|
| 93 | SOLID = 0, |
---|
| 94 | DASH = 1, |
---|
| 95 | DOT = 2, |
---|
| 96 | DASHDOT = 3, |
---|
| 97 | DASHDOTDOT = 4, |
---|
| 98 | |
---|
| 99 | CAP_FLAT = 0x100, |
---|
| 100 | CAP_ROUND = 0x200, |
---|
| 101 | CAP_SQUARE = 0x300, |
---|
| 102 | |
---|
| 103 | JOIN_MITER = 0x1000, |
---|
| 104 | JOIN_ROUND = 0x2000, |
---|
| 105 | JOIN_BEVEL = 0x3000 |
---|
| 106 | }; |
---|
| 107 | /*! \} */ |
---|
| 108 | |
---|
| 109 | /*! \addtogroup path |
---|
| 110 | \{ */ |
---|
| 111 | FL_API void newpath(); |
---|
| 112 | FL_API void addvertex(float x, float y); |
---|
| 113 | FL_API void addvertex(int x, int y); |
---|
| 114 | FL_API void addvertices(int n, const float v[][2]); |
---|
| 115 | FL_API void addvertices(int n, const int v[][2]); |
---|
| 116 | FL_API void addvertices_transformed(int n, const float v[][2]); |
---|
| 117 | FL_API void addcurve(float,float, float,float, float,float, float,float); |
---|
| 118 | FL_API void addarc(float x,float y,float w,float h, float a1, float a2); |
---|
| 119 | FL_API void addpie(const Rectangle& r, float a, float a2); |
---|
| 120 | FL_API void addchord(const Rectangle& r,float a,float a2); |
---|
| 121 | FL_API void closepath(); |
---|
| 122 | |
---|
| 123 | FL_API void drawpoints(); |
---|
| 124 | FL_API void strokepath(); |
---|
| 125 | FL_API void fillpath(); |
---|
| 126 | FL_API void fillstrokepath(Color); |
---|
| 127 | /*! \} */ |
---|
| 128 | |
---|
| 129 | /*! \addtogroup rectangle |
---|
| 130 | \{ */ |
---|
| 131 | FL_API void fillrect(const Rectangle&); |
---|
| 132 | FL_API void strokerect(const Rectangle&); |
---|
| 133 | FL_API void drawpoint(int x, int y); |
---|
| 134 | FL_API void drawpoint(float x, float y); |
---|
| 135 | FL_API void drawline(int x0, int y0, int x1, int y1); |
---|
| 136 | FL_API void drawline(float x0, float y0, float x1, float y1); |
---|
| 137 | /*! \} */ |
---|
| 138 | |
---|
| 139 | /*! \addtogroup font |
---|
| 140 | \{ */ |
---|
| 141 | FL_API void setfont(Font*, float size); |
---|
| 142 | FL_API void setfont(const char*, float size); |
---|
| 143 | FL_API void setfont(const char*, int attributes, float size); |
---|
| 144 | |
---|
| 145 | // change the encoding used to draw bytes (depreciated) |
---|
| 146 | extern FL_API const char* encoding_; |
---|
| 147 | inline const char* get_encoding() {return encoding_;} |
---|
| 148 | FL_API void set_encoding(const char*); |
---|
| 149 | |
---|
| 150 | // information you can get about the current font+size+encoding: |
---|
| 151 | extern FL_API Font* current_font_; |
---|
| 152 | extern FL_API float current_size_; // should be 2x2 transformation matrix |
---|
| 153 | inline Font* getfont() {return current_font_;} |
---|
| 154 | inline float getsize() {return current_size_;} |
---|
| 155 | |
---|
| 156 | // measure things in the current font: |
---|
| 157 | FL_API float getwidth(const char*); |
---|
| 158 | FL_API float getwidth(const char*, int length); |
---|
| 159 | FL_API float getascent(); |
---|
| 160 | FL_API float getdescent(); |
---|
| 161 | |
---|
| 162 | // draw using current font: |
---|
| 163 | FL_API void drawtext_transformed(const char*, int n, float x, float y); |
---|
| 164 | FL_API void drawtext(const char*, float x, float y); |
---|
| 165 | FL_API void drawtext(const char*, int length, float x, float y); |
---|
| 166 | |
---|
| 167 | // the label text formatter: |
---|
| 168 | FL_API void measure(const char*, int& w, int& h, Flags = 0); |
---|
| 169 | FL_API void measure(const char*, int length, int& w, int& h, Flags); |
---|
| 170 | FL_API void drawtext(const char*, const Rectangle&, Flags); |
---|
| 171 | FL_API void drawtext(const char*, int length, const Rectangle&, Flags); |
---|
| 172 | // set where \t characters go in label text formatter: |
---|
| 173 | extern FL_API const int* column_widths_; |
---|
| 174 | inline const int* column_widths() {return column_widths_;} |
---|
| 175 | inline void column_widths(const int* i) {column_widths_ = i;} |
---|
| 176 | // see also Symbol.h for @-sign commands |
---|
| 177 | /*! \} */ |
---|
| 178 | |
---|
| 179 | /*! \addtogroup images |
---|
| 180 | \{ */ |
---|
| 181 | FL_API void drawimage(const uchar*, PixelType, const Rectangle&); |
---|
| 182 | FL_API void drawimage(const uchar*, PixelType, const Rectangle&, int linedelta); |
---|
| 183 | |
---|
| 184 | typedef const uchar* (*DrawImageCallback)(void* data, int x, int y, int w, uchar* buffer); |
---|
| 185 | FL_API void drawimage(DrawImageCallback, void*, PixelType, const Rectangle&); |
---|
| 186 | |
---|
| 187 | FL_API uchar *readimage(uchar *p, PixelType, const Rectangle&); |
---|
| 188 | FL_API uchar *readimage(uchar *p, PixelType, const Rectangle&, int linedelta); |
---|
| 189 | /*! \} */ |
---|
| 190 | |
---|
| 191 | FL_API void scrollrect(const Rectangle&, int dx, int dy, |
---|
| 192 | void (*draw_area)(void*, const Rectangle&), void*); |
---|
| 193 | |
---|
| 194 | // depreciated: |
---|
| 195 | FL_API int draw_xpm(const char*const* data, int x, int y); |
---|
| 196 | FL_API int measure_xpm(const char*const* data, int &w, int &h); |
---|
| 197 | FL_API void overlay_rect(int,int,int,int); |
---|
| 198 | FL_API void overlay_clear(); |
---|
| 199 | //FL_API int draw_symbol(const char* label, int x,int y,int w,int h, Color); |
---|
| 200 | |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | #endif |
---|
| 204 | |
---|
| 205 | // |
---|
| 206 | // End of "$Id: draw.h 4408 2005-07-09 06:41:56Z spitzak $". |
---|
| 207 | // |
---|