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)  

fl_round_box.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: fl_round_box.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Round box drawing routines 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 
00028 // Box drawing code for an obscure box type.
00029 // These box types are in separate files so they are not linked
00030 // in if not used.
00031 
00032 #include <FL/Fl.H>
00033 #include <FL/fl_draw.H>
00034 
00035 // A compiler from a certain very large software company will not compile
00036 // the function pointer assignment due to the name conflict with fl_arc.
00037 // This function is to fix that:
00038 void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
00039   fl_arc(x,y,w,h,a1,a2);
00040 }
00041 
00042 enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
00043 
00044 static void draw(int which, int x,int y,int w,int h, int inset, Fl_Color color)
00045 {
00046   if (inset*2 >= w) inset = (w-1)/2;
00047   if (inset*2 >= h) inset = (h-1)/2;
00048   x += inset;
00049   y += inset;
00050   w -= 2*inset;
00051   h -= 2*inset;
00052   int d = w <= h ? w : h;
00053   if (d <= 1) return;
00054   fl_color(color);
00055   void (*f)(int,int,int,int,double,double);
00056   f = (which==FILL) ? fl_pie : fl_arc_i;
00057   if (which >= CLOSED) {
00058     f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
00059     f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
00060   } else if (which == UPPER_LEFT) {
00061     f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
00062     f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
00063   } else { // LOWER_RIGHT
00064     f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
00065     f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
00066   }
00067   if (which == FILL) {
00068     if (w < h)
00069       fl_rectf(x, y+d/2, w, h-(d&-2));
00070     else if (w > h)
00071       fl_rectf(x+d/2, y, w-(d&-2), h);
00072   } else {
00073     if (w < h) {
00074       if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
00075       if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
00076     } else if (w > h) {
00077       if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
00078       if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
00079     }
00080   }
00081 }
00082 
00083 extern uchar* fl_gray_ramp();
00084 
00085 void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
00086   uchar *g = fl_gray_ramp();
00087   draw(FILL,        x,   y, w,   h, 2, bgcolor);
00088   draw(UPPER_LEFT,  x+1, y, w-2, h, 0, (Fl_Color)g['N']);
00089   draw(UPPER_LEFT,  x+1, y, w-2, h, 1, (Fl_Color)g['H']);
00090   draw(UPPER_LEFT,  x,   y, w,   h, 0, (Fl_Color)g['N']);
00091   draw(UPPER_LEFT,  x,   y, w,   h, 1, (Fl_Color)g['H']);
00092   draw(LOWER_RIGHT, x,   y, w,   h, 0, (Fl_Color)g['S']);
00093   draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g['U']);
00094   draw(LOWER_RIGHT, x,   y, w,   h, 1, (Fl_Color)g['U']);
00095   draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g['W']);
00096   draw(CLOSED,      x,   y, w,   h, 2, (Fl_Color)g['A']);
00097 }
00098 
00099 void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
00100   uchar *g = fl_gray_ramp();
00101   draw(FILL,        x,   y, w,   h, 2, bgcolor);
00102   draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g['H']);
00103   draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g['N']);
00104   draw(LOWER_RIGHT, x,   y, w,   h, 1, (Fl_Color)g['H']);
00105   draw(LOWER_RIGHT, x,   y, w,   h, 2, (Fl_Color)g['N']);
00106   draw(UPPER_LEFT,  x,   y, w,   h, 2, (Fl_Color)g['U']);
00107   draw(UPPER_LEFT,  x+1, y, w-2, h, 1, (Fl_Color)g['S']);
00108   draw(UPPER_LEFT,  x,   y, w,   h, 1, (Fl_Color)g['W']);
00109   draw(UPPER_LEFT,  x+1, y, w-2, h, 0, (Fl_Color)g['U']);
00110   draw(CLOSED,      x,   y, w,   h, 0, (Fl_Color)g['A']);
00111 }
00112 
00113 extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
00114 Fl_Boxtype fl_define_FL_ROUND_UP_BOX() {
00115   fl_internal_boxtype(_FL_ROUND_DOWN_BOX, fl_round_down_box);
00116   fl_internal_boxtype(_FL_ROUND_UP_BOX, fl_round_up_box);
00117   return _FL_ROUND_UP_BOX;
00118 }
00119 
00120 //
00121 // End of "$Id: fl_round_box.cxx 7903 2010-11-28 21:06:39Z matt $".
00122 //