fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_labeltype.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Label drawing routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // Drawing code for the (one) common label types.
20 // Other label types (symbols) are in their own source files
21 // to avoid linking if not used.
22 
23 #include <FL/Fl.H>
24 #include <FL/Fl_Widget.H>
25 #include <FL/Fl_Group.H>
26 #include <FL/fl_draw.H>
27 #include <FL/Fl_Image.H>
28 
29 void
30 fl_no_label(const Fl_Label*,int,int,int,int,Fl_Align) {}
31 
32 void
33 fl_normal_label(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align)
34 {
35  fl_font(o->font, o->size);
36  fl_color((Fl_Color)o->color);
37  fl_draw(o->value, X, Y, W, H, align, o->image);
38 }
39 
40 void
41 fl_normal_measure(const Fl_Label* o, int& W, int& H) {
42  fl_font(o->font, o->size);
43  fl_measure(o->value, W, H);
44  if (o->image) {
45  if (o->image->w() > W) W = o->image->w();
46  H += o->image->h();
47  }
48 }
49 
50 #define MAX_LABELTYPE 16
51 
55  fl_normal_label, // _FL_SHADOW_LABEL,
56  fl_normal_label, // _FL_ENGRAVED_LABEL,
57  fl_normal_label, // _FL_EMBOSSED_LABEL,
58  fl_no_label, // _FL_MULTI_LABEL,
59  fl_no_label, // _FL_ICON_LABEL,
60  // FL_FREE_LABELTYPE+n:
64 };
65 
67 
70 {
71  table[t] = f; measure[t] = m;
72 }
73 
75 
77 void Fl_Label::draw(int X, int Y, int W, int H, Fl_Align align) const {
78  if (!value && !image) return;
79  table[type](this, X, Y, W, H, align);
80 }
86 void Fl_Label::measure(int& W, int& H) const {
87  if (!value && !image) {
88  W = H = 0;
89  return;
90  }
91 
93  f(this, W, H);
94 }
95 
99 void Fl_Widget::draw_label() const {
100  int X = x_+Fl::box_dx(box());
101  int W = w_-Fl::box_dw(box());
102  if (W > 11 && align()&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT)) {X += 3; W -= 6;}
103  draw_label(X, y_+Fl::box_dy(box()), W, h_-Fl::box_dh(box()));
104 }
105 
109 void Fl_Widget::draw_label(int X, int Y, int W, int H) const {
110  // quit if we are not drawing a label inside the widget:
111  if ((align()&15) && !(align() & FL_ALIGN_INSIDE)) return;
112  draw_label(X,Y,W,H,align());
113 }
114 
118 void Fl_Widget::draw_label(int X, int Y, int W, int H, Fl_Align a) const {
120  Fl_Label l1 = label_;
121  if (!active_r()) {
122  l1.color = fl_inactive((Fl_Color)l1.color);
123  if (l1.deimage) l1.image = l1.deimage;
124  }
125  l1.draw(X,Y,W,H,a);
126  fl_draw_shortcut = 0;
127 }
128 
129 // include these vars here so they can be referenced without including
130 // Fl_Input_ code:
131 #include <FL/Fl_Input_.H>
132 
133 //
134 // End of "$Id$".
135 //
Fl_Widget::draw_label
void draw_label() const
Definition: fl_labeltype.cxx:99
Fl_Widget.H
fl_font
void fl_font(Fl_Font face, Fl_Fontsize fsize)
Definition: fl_draw.H:509
fl_no_label
void fl_no_label(const Fl_Label *, int, int, int, int, Fl_Align)
Definition: fl_labeltype.cxx:30
FL_ALIGN_LEFT
const Fl_Align FL_ALIGN_LEFT
Definition: Enumerations.H:839
Fl.H
Fl_Widget::align
Fl_Align align() const
Definition: Fl_Widget.H:348
Fl_Widget::x_
int x_
Definition: Fl_Widget.H:107
Fl_Widget::h_
int h_
Definition: Fl_Widget.H:107
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
Fl_Image::h
void h(int H)
Definition: Fl_Image.H:80
Fl::box_dx
static int box_dx(Fl_Boxtype)
Definition: fl_boxtype.cxx:360
fl_color
void fl_color(Fl_Color c)
Definition: fl_draw.H:52
MAX_LABELTYPE
#define MAX_LABELTYPE
Definition: fl_labeltype.cxx:50
Fl_Label::type
uchar type
Definition: Fl_Widget.H:81
H
static int H
Definition: Fl_Tooltip.cxx:76
fl_draw
FL_EXPORT void fl_draw(const char *str, int x, int y)
Definition: fl_font.cxx:70
Fl_Label::draw
void draw(int, int, int, int, Fl_Align) const
Definition: fl_labeltype.cxx:77
fl_normal_label
void fl_normal_label(const Fl_Label *o, int X, int Y, int W, int H, Fl_Align align)
Definition: fl_labeltype.cxx:33
Fl_Label::color
Fl_Color color
Definition: Fl_Widget.H:77
Fl_Image::w
void w(int W)
Definition: Fl_Image.H:76
Fl_Label::image
Fl_Image * image
Definition: Fl_Widget.H:69
Fl_Label_Draw_F
void() Fl_Label_Draw_F(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align)
Definition: Fl.H:83
Fl_Widget::label_
Fl_Label label_
Definition: Fl_Widget.H:108
Fl::box_dh
static int box_dh(Fl_Boxtype)
Definition: fl_boxtype.cxx:397
Fl_Label::deimage
Fl_Image * deimage
Definition: Fl_Widget.H:71
FL_ALIGN_INSIDE
const Fl_Align FL_ALIGN_INSIDE
Definition: Enumerations.H:843
Fl::box_dw
static int box_dw(Fl_Boxtype)
Definition: fl_boxtype.cxx:391
Fl::box_dy
static int box_dy(Fl_Boxtype)
Definition: fl_boxtype.cxx:385
fl_draw.H
utility header to pull drawing functions together
Fl_Widget::flags
unsigned int flags() const
Definition: Fl_Widget.H:147
Fl_Label
Definition: Fl_Widget.H:65
fl_inactive
Fl_Color fl_inactive(Fl_Color c)
Definition: fl_color.cxx:423
Fl_Widget::active_r
int active_r() const
Definition: Fl_Widget.cxx:265
Fl_Label::size
Fl_Fontsize size
Definition: Fl_Widget.H:75
Fl_Widget::y_
int y_
Definition: Fl_Widget.H:107
fl_measure
FL_EXPORT void fl_measure(const char *str, int &x, int &y, int draw_symbols=1)
Definition: fl_draw.cxx:380
fl_draw_shortcut
FL_EXPORT char fl_draw_shortcut
Definition: fl_draw.cxx:36
Fl_Widget::box
Fl_Boxtype box() const
Definition: Fl_Widget.H:363
measure
static Fl_Label_Measure_F * measure[16]
Definition: fl_labeltype.cxx:66
Fl_Label::measure
void measure(int &w, int &h) const
Definition: fl_labeltype.cxx:86
Fl::set_labeltype
static void set_labeltype(Fl_Labeltype, Fl_Label_Draw_F *, Fl_Label_Measure_F *)
Definition: fl_labeltype.cxx:69
Fl_Widget::w_
int w_
Definition: Fl_Widget.H:107
Fl_Labeltype
Fl_Labeltype
Definition: Enumerations.H:763
Fl_Group.H
Fl_Label::value
const char * value
Definition: Fl_Widget.H:67
Fl_Label::font
Fl_Font font
Definition: Fl_Widget.H:73
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
Y
static int Y
Definition: Fl_Tooltip.cxx:76
Fl_Image.H
fl_normal_measure
void fl_normal_measure(const Fl_Label *o, int &W, int &H)
Definition: fl_labeltype.cxx:41
Fl_Widget::SHORTCUT_LABEL
the label contains a shortcut we need to draw
Definition: Fl_Widget.H:162
Fl_Input_.H
FL_ALIGN_RIGHT
const Fl_Align FL_ALIGN_RIGHT
Definition: Enumerations.H:841
Fl_Label_Measure_F
void() Fl_Label_Measure_F(const Fl_Label *label, int &width, int &height)
Definition: Fl.H:86
Fl_Align
unsigned Fl_Align
Definition: Enumerations.H:828
table
static Fl_Label_Draw_F * table[16]
Definition: fl_labeltype.cxx:52