|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: fl_boxtype.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Box drawing code 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 // Box drawing code for the common box types and the table of 00034 // boxtypes. Other box types are in separate files so they are not 00035 // linked in if not used. 00036 00037 #include <FL/Fl.H> 00038 #include <FL/Fl_Widget.H> 00039 #include <FL/fl_draw.H> 00040 #include <config.h> 00041 00043 00044 static uchar active_ramp[24] = { 00045 FL_GRAY_RAMP+0, FL_GRAY_RAMP+1, FL_GRAY_RAMP+2, FL_GRAY_RAMP+3, 00046 FL_GRAY_RAMP+4, FL_GRAY_RAMP+5, FL_GRAY_RAMP+6, FL_GRAY_RAMP+7, 00047 FL_GRAY_RAMP+8, FL_GRAY_RAMP+9, FL_GRAY_RAMP+10,FL_GRAY_RAMP+11, 00048 FL_GRAY_RAMP+12,FL_GRAY_RAMP+13,FL_GRAY_RAMP+14,FL_GRAY_RAMP+15, 00049 FL_GRAY_RAMP+16,FL_GRAY_RAMP+17,FL_GRAY_RAMP+18,FL_GRAY_RAMP+19, 00050 FL_GRAY_RAMP+20,FL_GRAY_RAMP+21,FL_GRAY_RAMP+22,FL_GRAY_RAMP+23}; 00051 static uchar inactive_ramp[24] = { 00052 43, 43, 44, 44, 00053 44, 45, 45, 46, 00054 46, 46, 47, 47, 00055 48, 48, 48, 49, 00056 49, 49, 50, 50, 00057 51, 51, 52, 52}; 00058 static int draw_it_active = 1; 00059 00064 int Fl::draw_box_active() { return draw_it_active; } 00065 00066 uchar *fl_gray_ramp() {return (draw_it_active?active_ramp:inactive_ramp)-'A';} 00067 00080 void fl_frame(const char* s, int x, int y, int w, int h) { 00081 uchar *g = fl_gray_ramp(); 00082 if (h > 0 && w > 0) for (;*s;) { 00083 // draw top line: 00084 fl_color(g[(int)*s++]); 00085 fl_xyline(x, y, x+w-1); 00086 y++; if (--h <= 0) break; 00087 // draw left line: 00088 fl_color(g[(int)*s++]); 00089 fl_yxline(x, y+h-1, y); 00090 x++; if (--w <= 0) break; 00091 // draw bottom line: 00092 fl_color(g[(int)*s++]); 00093 fl_xyline(x, y+h-1, x+w-1); 00094 if (--h <= 0) break; 00095 // draw right line: 00096 fl_color(g[(int)*s++]); 00097 fl_yxline(x+w-1, y+h-1, y); 00098 if (--w <= 0) break; 00099 } 00100 } 00101 00114 void fl_frame2(const char* s, int x, int y, int w, int h) { 00115 uchar *g = fl_gray_ramp(); 00116 if (h > 0 && w > 0) for (;*s;) { 00117 // draw bottom line: 00118 fl_color(g[(int)*s++]); 00119 fl_xyline(x, y+h-1, x+w-1); 00120 if (--h <= 0) break; 00121 // draw right line: 00122 fl_color(g[(int)*s++]); 00123 fl_yxline(x+w-1, y+h-1, y); 00124 if (--w <= 0) break; 00125 // draw top line: 00126 fl_color(g[(int)*s++]); 00127 fl_xyline(x, y, x+w-1); 00128 y++; if (--h <= 0) break; 00129 // draw left line: 00130 fl_color(g[(int)*s++]); 00131 fl_yxline(x, y+h-1, y); 00132 x++; if (--w <= 0) break; 00133 } 00134 } 00135 00137 void fl_no_box(int, int, int, int, Fl_Color) {} 00138 00140 void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) { 00141 fl_frame2("WWHH",x,y,w,h); 00142 } 00143 00145 void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c) { 00146 fl_thin_down_frame(x,y,w,h,c); 00147 fl_color(draw_it_active ? c : fl_inactive(c)); 00148 fl_rectf(x+1, y+1, w-2, h-2); 00149 } 00150 00152 void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color) { 00153 fl_frame2("HHWW",x,y,w,h); 00154 } 00155 00157 void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c) { 00158 fl_thin_up_frame(x,y,w,h,c); 00159 fl_color(draw_it_active ? c : fl_inactive(c)); 00160 fl_rectf(x+1, y+1, w-2, h-2); 00161 } 00162 00164 void fl_up_frame(int x, int y, int w, int h, Fl_Color) { 00165 #if BORDER_WIDTH == 1 00166 fl_frame2("HHWW",x,y,w,h); 00167 #else 00168 #if BORDER_WIDTH == 2 00169 fl_frame2("AAWWMMTT",x,y,w,h); 00170 #else 00171 fl_frame("AAAAWWJJUTNN",x,y,w,h); 00172 #endif 00173 #endif 00174 } 00175 00176 #define D1 BORDER_WIDTH 00177 #define D2 (BORDER_WIDTH+BORDER_WIDTH) 00178 00180 void fl_up_box(int x, int y, int w, int h, Fl_Color c) { 00181 fl_up_frame(x,y,w,h,c); 00182 fl_color(draw_it_active ? c : fl_inactive(c)); 00183 fl_rectf(x+D1, y+D1, w-D2, h-D2); 00184 } 00185 00187 void fl_down_frame(int x, int y, int w, int h, Fl_Color) { 00188 #if BORDER_WIDTH == 1 00189 fl_frame2("WWHH",x,y,w,h); 00190 #else 00191 #if BORDER_WIDTH == 2 00192 fl_frame2("WWMMPPAA",x,y,w,h); 00193 #else 00194 fl_frame("NNTUJJWWAAAA",x,y,w,h); 00195 #endif 00196 #endif 00197 } 00198 00200 void fl_down_box(int x, int y, int w, int h, Fl_Color c) { 00201 fl_down_frame(x,y,w,h,c); 00202 fl_color(c); fl_rectf(x+D1, y+D1, w-D2, h-D2); 00203 } 00204 00206 void fl_engraved_frame(int x, int y, int w, int h, Fl_Color) { 00207 fl_frame("HHWWWWHH",x,y,w,h); 00208 } 00209 00211 void fl_engraved_box(int x, int y, int w, int h, Fl_Color c) { 00212 fl_engraved_frame(x,y,w,h,c); 00213 fl_color(draw_it_active ? c : fl_inactive(c)); 00214 fl_rectf(x+2, y+2, w-4, h-4); 00215 } 00216 00218 void fl_embossed_frame(int x, int y, int w, int h, Fl_Color) { 00219 fl_frame("WWHHHHWW",x,y,w,h); 00220 } 00221 00223 void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) { 00224 fl_embossed_frame(x,y,w,h,c); 00225 fl_color(draw_it_active ? c : fl_inactive(c)); 00226 fl_rectf(x+2, y+2, w-4, h-4); 00227 } 00228 00233 void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) { 00234 fl_color(draw_it_active ? FL_BLACK : fl_inactive(FL_BLACK)); 00235 fl_rect(x, y, w, h); 00236 fl_color(draw_it_active ? bgcolor : fl_inactive(bgcolor)); 00237 fl_rectf(x+1, y+1, w-2, h-2); 00238 } 00239 #define fl_border_box fl_rectbound 00244 void fl_border_frame(int x, int y, int w, int h, Fl_Color c) { 00245 fl_color(draw_it_active ? c : fl_inactive(c)); 00246 fl_rect(x, y, w, h); 00247 } 00248 00250 00251 static struct { 00252 Fl_Box_Draw_F *f; 00253 uchar dx, dy, dw, dh; 00254 int set; 00255 } fl_box_table[256] = { 00256 // must match list in Enumerations.H!!! 00257 {fl_no_box, 0,0,0,0,1}, 00258 {fl_rectf, 0,0,0,0,1}, // FL_FLAT_BOX 00259 {fl_up_box, D1,D1,D2,D2,1}, 00260 {fl_down_box, D1,D1,D2,D2,1}, 00261 {fl_up_frame, D1,D1,D2,D2,1}, 00262 {fl_down_frame, D1,D1,D2,D2,1}, 00263 {fl_thin_up_box, 1,1,2,2,1}, 00264 {fl_thin_down_box, 1,1,2,2,1}, 00265 {fl_thin_up_frame, 1,1,2,2,1}, 00266 {fl_thin_down_frame, 1,1,2,2,1}, 00267 {fl_engraved_box, 2,2,4,4,1}, 00268 {fl_embossed_box, 2,2,4,4,1}, 00269 {fl_engraved_frame, 2,2,4,4,1}, 00270 {fl_embossed_frame, 2,2,4,4,1}, 00271 {fl_border_box, 1,1,2,2,1}, 00272 {fl_border_box, 1,1,5,5,0}, // _FL_SHADOW_BOX, 00273 {fl_border_frame, 1,1,2,2,1}, 00274 {fl_border_frame, 1,1,5,5,0}, // _FL_SHADOW_FRAME, 00275 {fl_border_box, 1,1,2,2,0}, // _FL_ROUNDED_BOX, 00276 {fl_border_box, 1,1,2,2,0}, // _FL_RSHADOW_BOX, 00277 {fl_border_frame, 1,1,2,2,0}, // _FL_ROUNDED_FRAME 00278 {fl_rectf, 0,0,0,0,0}, // _FL_RFLAT_BOX, 00279 {fl_up_box, 3,3,6,6,0}, // _FL_ROUND_UP_BOX 00280 {fl_down_box, 3,3,6,6,0}, // _FL_ROUND_DOWN_BOX, 00281 {fl_up_box, 0,0,0,0,0}, // _FL_DIAMOND_UP_BOX 00282 {fl_down_box, 0,0,0,0,0}, // _FL_DIAMOND_DOWN_BOX 00283 {fl_border_box, 1,1,2,2,0}, // _FL_OVAL_BOX, 00284 {fl_border_box, 1,1,2,2,0}, // _FL_OVAL_SHADOW_BOX, 00285 {fl_border_frame, 1,1,2,2,0}, // _FL_OVAL_FRAME 00286 {fl_rectf, 0,0,0,0,0}, // _FL_OVAL_FLAT_BOX, 00287 {fl_up_box, 4,4,8,8,0}, // _FL_PLASTIC_UP_BOX, 00288 {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_DOWN_BOX, 00289 {fl_up_frame, 2,2,4,4,0}, // _FL_PLASTIC_UP_FRAME, 00290 {fl_down_frame, 2,2,4,4,0}, // _FL_PLASTIC_DOWN_FRAME, 00291 {fl_up_box, 2,2,4,4,0}, // _FL_PLASTIC_THIN_UP_BOX, 00292 {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_THIN_DOWN_BOX, 00293 {fl_up_box, 2,2,4,4,0}, // _FL_PLASTIC_ROUND_UP_BOX, 00294 {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_ROUND_DOWN_BOX, 00295 {fl_up_box, 2,2,4,4,0}, // _FL_GTK_UP_BOX, 00296 {fl_down_box, 2,2,4,4,0}, // _FL_GTK_DOWN_BOX, 00297 {fl_up_frame, 2,2,4,4,0}, // _FL_GTK_UP_FRAME, 00298 {fl_down_frame, 2,2,4,4,0}, // _FL_GTK_DOWN_FRAME, 00299 {fl_up_frame, 1,1,2,2,0}, // _FL_GTK_THIN_UP_FRAME, 00300 {fl_down_frame, 1,1,2,2,0}, // _FL_GTK_THIN_DOWN_FRAME, 00301 {fl_up_box, 1,1,2,2,0}, // _FL_GTK_THIN_ROUND_UP_BOX, 00302 {fl_down_box, 1,1,2,2,0}, // _FL_GTK_THIN_ROUND_DOWN_BOX, 00303 {fl_up_box, 2,2,4,4,0}, // _FL_GTK_ROUND_UP_BOX, 00304 {fl_down_box, 2,2,4,4,0}, // _FL_GTK_ROUND_DOWN_BOX, 00305 {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+0 00306 {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+1 00307 {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+2 00308 {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+3 00309 {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+4 00310 {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+5 00311 {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+6 00312 {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+7 00313 }; 00314 00319 int Fl::box_dx(Fl_Boxtype t) {return fl_box_table[t].dx;} 00320 00344 int Fl::box_dy(Fl_Boxtype t) {return fl_box_table[t].dy;} 00345 00350 int Fl::box_dw(Fl_Boxtype t) {return fl_box_table[t].dw;} 00351 00356 int Fl::box_dh(Fl_Boxtype t) {return fl_box_table[t].dh;} 00357 00363 void fl_internal_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f) { 00364 if (!fl_box_table[t].set) { 00365 fl_box_table[t].f = f; 00366 fl_box_table[t].set = 1; 00367 } 00368 } 00369 00371 Fl_Box_Draw_F *Fl::get_boxtype(Fl_Boxtype t) { 00372 return fl_box_table[t].f; 00373 } 00375 void Fl::set_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f, 00376 uchar a, uchar b, uchar c, uchar d) { 00377 fl_box_table[t].f = f; 00378 fl_box_table[t].set = 1; 00379 fl_box_table[t].dx = a; 00380 fl_box_table[t].dy = b; 00381 fl_box_table[t].dw = c; 00382 fl_box_table[t].dh = d; 00383 } 00385 void Fl::set_boxtype(Fl_Boxtype to, Fl_Boxtype from) { 00386 fl_box_table[to] = fl_box_table[from]; 00387 } 00388 00395 void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) { 00396 if (t && fl_box_table[t].f) fl_box_table[t].f(x,y,w,h,c); 00397 } 00398 00399 //extern Fl_Widget *fl_boxcheat; // hack set by Fl_Window.cxx 00401 void Fl_Widget::draw_box() const { 00402 if (box_) draw_box((Fl_Boxtype)box_, x_, y_, w_, h_, color_); 00403 draw_backdrop(); 00404 } 00406 void Fl_Widget::draw_backdrop() const { 00407 if (align() & FL_ALIGN_IMAGE_BACKDROP) { 00408 const Fl_Image *img = image(); 00409 // if there is no image, we will not draw the deimage either 00410 if (img && deimage() && !active_r()) 00411 img = deimage(); 00412 if (img) 00413 ((Fl_Image*)img)->draw(x_+(w_-img->w())/2, y_+(h_-img->h())/2); 00414 } 00415 } 00417 void Fl_Widget::draw_box(Fl_Boxtype t, Fl_Color c) const { 00418 draw_box(t, x_, y_, w_, h_, c); 00419 } 00421 void Fl_Widget::draw_box(Fl_Boxtype t, int X, int Y, int W, int H, Fl_Color c) const { 00422 draw_it_active = active_r(); 00423 fl_box_table[t].f(X, Y, W, H, c); 00424 draw_it_active = 1; 00425 } 00426 00427 // 00428 // End of "$Id: fl_boxtype.cxx 7903 2010-11-28 21:06:39Z matt $". 00429 //