|
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_labeltype.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Label 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 // Drawing code for the (one) common label types. 00029 // Other label types (symbols) are in their own source files 00030 // to avoid linking if not used. 00031 00032 #include <FL/Fl.H> 00033 #include <FL/Fl_Widget.H> 00034 #include <FL/Fl_Group.H> 00035 #include <FL/fl_draw.H> 00036 #include <FL/Fl_Image.H> 00037 00038 void 00039 fl_no_label(const Fl_Label*,int,int,int,int,Fl_Align) {} 00040 00041 void 00042 fl_normal_label(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align) 00043 { 00044 fl_font(o->font, o->size); 00045 fl_color((Fl_Color)o->color); 00046 fl_draw(o->value, X, Y, W, H, align, o->image); 00047 } 00048 00049 void 00050 fl_normal_measure(const Fl_Label* o, int& W, int& H) { 00051 fl_font(o->font, o->size); 00052 fl_measure(o->value, W, H); 00053 if (o->image) { 00054 if (o->image->w() > W) W = o->image->w(); 00055 H += o->image->h(); 00056 } 00057 } 00058 00059 #define MAX_LABELTYPE 16 00060 00061 static Fl_Label_Draw_F* table[MAX_LABELTYPE] = { 00062 fl_normal_label, 00063 fl_no_label, 00064 fl_normal_label, // _FL_SHADOW_LABEL, 00065 fl_normal_label, // _FL_ENGRAVED_LABEL, 00066 fl_normal_label, // _FL_EMBOSSED_LABEL, 00067 fl_no_label, // _FL_MULTI_LABEL, 00068 fl_no_label, // _FL_ICON_LABEL, 00069 // FL_FREE_LABELTYPE+n: 00070 fl_no_label, fl_no_label, fl_no_label, 00071 fl_no_label, fl_no_label, fl_no_label, 00072 fl_no_label, fl_no_label, fl_no_label 00073 }; 00074 00075 static Fl_Label_Measure_F* measure[MAX_LABELTYPE]; 00076 00078 void Fl::set_labeltype(Fl_Labeltype t,Fl_Label_Draw_F* f,Fl_Label_Measure_F*m) 00079 { 00080 table[t] = f; measure[t] = m; 00081 } 00082 00084 00086 void Fl_Label::draw(int X, int Y, int W, int H, Fl_Align align) const { 00087 if (!value && !image) return; 00088 table[type](this, X, Y, W, H, align); 00089 } 00095 void Fl_Label::measure(int& W, int& H) const { 00096 if (!value && !image) { 00097 W = H = 0; 00098 return; 00099 } 00100 00101 Fl_Label_Measure_F* f = ::measure[type]; if (!f) f = fl_normal_measure; 00102 f(this, W, H); 00103 } 00104 00108 void Fl_Widget::draw_label() const { 00109 int X = x_+Fl::box_dx(box()); 00110 int W = w_-Fl::box_dw(box()); 00111 if (W > 11 && align()&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT)) {X += 3; W -= 6;} 00112 draw_label(X, y_+Fl::box_dy(box()), W, h_-Fl::box_dh(box())); 00113 } 00114 00118 void Fl_Widget::draw_label(int X, int Y, int W, int H) const { 00119 // quit if we are not drawing a label inside the widget: 00120 if ((align()&15) && !(align() & FL_ALIGN_INSIDE)) return; 00121 draw_label(X,Y,W,H,align()); 00122 } 00123 00127 void Fl_Widget::draw_label(int X, int Y, int W, int H, Fl_Align a) const { 00128 if (flags()&SHORTCUT_LABEL) fl_draw_shortcut = 1; 00129 Fl_Label l1 = label_; 00130 if (!active_r()) { 00131 l1.color = fl_inactive((Fl_Color)l1.color); 00132 if (l1.deimage) l1.image = l1.deimage; 00133 } 00134 l1.draw(X,Y,W,H,a); 00135 fl_draw_shortcut = 0; 00136 } 00137 00138 // include these vars here so they can be referenced without including 00139 // Fl_Input_ code: 00140 #include <FL/Fl_Input_.H> 00141 00142 // 00143 // End of "$Id: fl_labeltype.cxx 7903 2010-11-28 21:06:39Z matt $". 00144 //