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_gtk.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: fl_gtk.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // "GTK" drawing routines for the Fast Light Tool Kit (FLTK).
00005 //
00006 // These box types provide a GTK+ look, based on Red Hat's Bluecurve
00007 // theme...
00008 //
00009 // Copyright 2006-2010 by Michael Sweet.
00010 //
00011 // This library is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU Library General Public
00013 // License as published by the Free Software Foundation; either
00014 // version 2 of the License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA.
00025 //
00026 // Please report all bugs and problems on the following page:
00027 //
00028 //     http://www.fltk.org/str.php
00029 //
00030 
00031 // Box drawing code for an obscure box type.
00032 // These box types are in separate files so they are not linked
00033 // in if not used.
00034 
00035 #include <FL/Fl.H>
00036 #include <FL/fl_draw.H>
00037 
00038 extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
00039 
00040 
00041 static void gtk_color(Fl_Color c) {
00042   if (Fl::draw_box_active()) fl_color(c);
00043   else fl_color(fl_inactive(c));
00044 }
00045 
00046 
00047 static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c) {
00048   gtk_color(fl_color_average(FL_WHITE, c, 0.5));
00049   fl_xyline(x + 2, y + 1, x + w - 3);
00050   fl_yxline(x + 1, y + 2, y + h - 3);
00051 
00052   gtk_color(fl_color_average(FL_BLACK, c, 0.5));
00053   fl_begin_loop();
00054     fl_vertex(x, y + 2);
00055     fl_vertex(x + 2, y);
00056     fl_vertex(x + w - 3, y);
00057     fl_vertex(x + w - 1, y + 2);
00058     fl_vertex(x + w - 1, y + h - 3);
00059     fl_vertex(x + w - 3, y + h - 1);
00060     fl_vertex(x + 2, y + h - 1);
00061     fl_vertex(x, y + h - 3);
00062   fl_end_loop();
00063 }
00064 
00065 
00066 static void gtk_up_box(int x, int y, int w, int h, Fl_Color c) {
00067   gtk_up_frame(x, y, w, h, c);
00068 
00069   gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
00070   fl_xyline(x + 2, y + 2, x + w - 3);
00071   gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
00072   fl_xyline(x + 2, y + 3, x + w - 3);
00073   gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
00074   fl_xyline(x + 2, y + 4, x + w - 3);
00075   gtk_color(c);
00076   fl_rectf(x + 2, y + 5, w - 4, h - 7);
00077   gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
00078   fl_xyline(x + 2, y + h - 4, x + w - 3);
00079   gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
00080   fl_xyline(x + 2, y + h - 3, x + w - 3);
00081   gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
00082   fl_xyline(x + 2, y + h - 2, x + w - 3);
00083   fl_yxline(x + w - 2, y + 2, y + h - 3);
00084 }
00085 
00086 
00087 static void gtk_down_frame(int x, int y, int w, int h, Fl_Color c) {
00088   gtk_color(fl_color_average(FL_BLACK, c, 0.5));
00089   fl_begin_loop();
00090     fl_vertex(x, y + 2);
00091     fl_vertex(x + 2, y);
00092     fl_vertex(x + w - 3, y);
00093     fl_vertex(x + w - 1, y + 2);
00094     fl_vertex(x + w - 1, y + h - 3);
00095     fl_vertex(x + w - 3, y + h - 1);
00096     fl_vertex(x + 2, y + h - 1);
00097     fl_vertex(x, y + h - 3);
00098   fl_end_loop();
00099 
00100   gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
00101   fl_xyline(x + 2, y + 1, x + w - 3);
00102   fl_yxline(x + 1, y + 2, y + h - 3);
00103 
00104   gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
00105   fl_yxline(x + 2, y + h - 2, y + 2, x + w - 2);
00106 }
00107 
00108 
00109 static void gtk_down_box(int x, int y, int w, int h, Fl_Color c) {
00110   gtk_down_frame(x, y, w, h, c);
00111 
00112   gtk_color(c);
00113   fl_rectf(x + 3, y + 3, w - 5, h - 4);
00114   fl_yxline(x + w - 2, y + 3, y + h - 3);
00115 }
00116 
00117 
00118 static void gtk_thin_up_frame(int x, int y, int w, int h, Fl_Color c) {
00119   gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
00120   fl_xyline(x + 1, y, x + w - 2);
00121   fl_yxline(x, y + 1, y + h - 2);
00122 
00123   gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
00124   fl_xyline(x + 1, y + h - 1, x + w - 2);
00125   fl_yxline(x + w - 1, y + 1, y + h - 2);
00126 }
00127 
00128 
00129 static void gtk_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
00130   gtk_thin_up_frame(x, y, w, h, c);
00131 
00132   gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
00133   fl_xyline(x + 1, y + 1, x + w - 2);
00134   gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
00135   fl_xyline(x + 1, y + 2, x + w - 2);
00136   gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
00137   fl_xyline(x + 1, y + 3, x + w - 2);
00138   gtk_color(c);
00139   fl_rectf(x + 1, y + 4, w - 2, h - 8);
00140   gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
00141   fl_xyline(x + 1, y + h - 4, x + w - 2);
00142   gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
00143   fl_xyline(x + 1, y + h - 3, x + w - 2);
00144   gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
00145   fl_xyline(x + 1, y + h - 2, x + w - 2);
00146 }
00147 
00148 
00149 static void gtk_thin_down_frame(int x, int y, int w, int h, Fl_Color c) {
00150   gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
00151   fl_xyline(x + 1, y, x + w - 2);
00152   fl_yxline(x, y + 1, y + h - 2);
00153 
00154   gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
00155   fl_xyline(x + 1, y + h - 1, x + w - 2);
00156   fl_yxline(x + w - 1, y + 1, y + h - 2);
00157 }
00158 
00159 
00160 static void gtk_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
00161   gtk_thin_down_frame(x, y, w, h, c);
00162 
00163   gtk_color(c);
00164   fl_rectf(x + 1, y + 1, w - 2, h - 2);
00165 }
00166 
00167 //------------------------
00168 // new GTK+ style for round buttons
00169 #if 1
00170 
00171 static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
00172   fl_arc(x,y,w,h,a1,a2);
00173 }
00174 
00175 enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
00176 
00177 static void draw(int which, int x,int y,int w,int h, int inset)
00178 {
00179   if (inset*2 >= w) inset = (w-1)/2;
00180   if (inset*2 >= h) inset = (h-1)/2;
00181   x += inset;
00182   y += inset;
00183   w -= 2*inset;
00184   h -= 2*inset;
00185   int d = w <= h ? w : h;
00186   if (d <= 1) return;
00187   void (*f)(int,int,int,int,double,double);
00188   f = (which==FILL) ? fl_pie : fl_arc_i;
00189   if (which >= CLOSED) {
00190     f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
00191     f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
00192   } else if (which == UPPER_LEFT) {
00193     f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
00194     f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
00195   } else { // LOWER_RIGHT
00196     f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
00197     f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
00198   }
00199   if (which == FILL) {
00200     if (w < h)
00201       fl_rectf(x, y+d/2, w, h-(d&-2));
00202     else if (w > h)
00203       fl_rectf(x+d/2, y, w-(d&-2), h);
00204   } else {
00205     if (w < h) {
00206       if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
00207       if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
00208     } else if (w > h) {
00209       if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
00210       if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
00211     }
00212   }
00213 }
00214 
00215 void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
00216   fl_color(c);
00217   draw(FILL,        x,   y, w,   h, 2);
00218 
00219   gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
00220   draw(LOWER_RIGHT, x+1, y, w-2, h, 2);
00221   draw(LOWER_RIGHT, x,   y, w,   h, 3);
00222   gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
00223   draw(LOWER_RIGHT, x+1, y, w-2, h, 1);
00224   draw(LOWER_RIGHT, x,   y, w,   h, 2);
00225   gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
00226   draw(LOWER_RIGHT, x+1, y, w-2, h, 0);
00227   draw(LOWER_RIGHT, x,   y, w,   h, 1);
00228 
00229   gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
00230   draw(UPPER_LEFT,  x,   y, w,   h, 4);
00231   draw(UPPER_LEFT,  x+1, y, w-2, h, 3);
00232   gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
00233   draw(UPPER_LEFT,  x,   y, w,   h, 3);
00234   draw(UPPER_LEFT,  x+1, y, w-2, h, 2);
00235   gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
00236   draw(UPPER_LEFT,  x,   y, w,   h, 2);
00237   draw(UPPER_LEFT,  x+1, y, w-2, h, 1);
00238   gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
00239   draw(UPPER_LEFT,  x,   y, w,   h, 1);
00240   draw(UPPER_LEFT,  x+1, y, w-2, h, 0);
00241 
00242   gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
00243   draw(CLOSED,      x,   y, w,   h, 0);
00244 }
00245 
00246 void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
00247   fl_color(c);
00248   draw(FILL,        x,   y, w,   h, 2);
00249 
00250   gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
00251   draw(UPPER_LEFT,  x,   y, w,   h, 2);
00252   draw(UPPER_LEFT,  x+1, y, w-2, h, 1);
00253   gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
00254   draw(UPPER_LEFT,  x,   y, w,   h, 1);
00255   draw(UPPER_LEFT,  x+1, y, w-2, h, 0);
00256 
00257   gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
00258   draw(CLOSED,      x,   y, w,   h, 0);
00259 }
00260 
00261 #else
00262 
00263 static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
00264   gtk_color(c);
00265   fl_pie(x, y, w, h, 0.0, 360.0);
00266   gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
00267   fl_arc(x, y, w, h, 45.0, 180.0);
00268   gtk_color(fl_color_average(FL_WHITE, c, 0.25f));
00269   fl_arc(x, y, w, h, 180.0, 405.0);
00270   gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
00271   fl_arc(x, y, w, h, 225.0, 360.0);
00272 }
00273 
00274 
00275 static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
00276   gtk_color(c);
00277   fl_pie(x, y, w, h, 0.0, 360.0);
00278   gtk_color(fl_color_average(FL_BLACK, c, 0.2));
00279   fl_arc(x + 1, y, w, h, 90.0, 210.0);
00280   gtk_color(fl_color_average(FL_BLACK, c, 0.6));
00281   fl_arc(x, y, w, h, 0.0, 360.0);
00282 }
00283 
00284 #endif
00285 
00286 Fl_Boxtype fl_define_FL_GTK_UP_BOX() {
00287   fl_internal_boxtype(_FL_GTK_UP_BOX, gtk_up_box);
00288   fl_internal_boxtype(_FL_GTK_DOWN_BOX, gtk_down_box);
00289   fl_internal_boxtype(_FL_GTK_UP_FRAME, gtk_up_frame);
00290   fl_internal_boxtype(_FL_GTK_DOWN_FRAME, gtk_down_frame);
00291   fl_internal_boxtype(_FL_GTK_THIN_UP_BOX, gtk_thin_up_box);
00292   fl_internal_boxtype(_FL_GTK_THIN_DOWN_BOX, gtk_thin_down_box);
00293   fl_internal_boxtype(_FL_GTK_THIN_UP_FRAME, gtk_thin_up_frame);
00294   fl_internal_boxtype(_FL_GTK_THIN_DOWN_FRAME, gtk_thin_down_frame);
00295   fl_internal_boxtype(_FL_GTK_ROUND_UP_BOX, gtk_round_up_box);
00296   fl_internal_boxtype(_FL_GTK_ROUND_DOWN_BOX, gtk_round_down_box);
00297 
00298   return _FL_GTK_UP_BOX;
00299 }
00300 
00301 
00302 //
00303 // End of "$Id: fl_gtk.cxx 7903 2010-11-28 21:06:39Z matt $".
00304 //