2 // "$Id: fl_labeltype.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Label drawing routines for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Drawing code for the (one) common label types.
29 // Other label types (symbols) are in their own source files
30 // to avoid linking if not used.
33 #include <FL/Fl_Widget.H>
34 #include <FL/Fl_Group.H>
35 #include <FL/fl_draw.H>
36 #include <FL/Fl_Image.H>
39 fl_no_label(const Fl_Label
*,int,int,int,int,Fl_Align
) {}
42 fl_normal_label(const Fl_Label
* o
, int X
, int Y
, int W
, int H
, Fl_Align align
)
44 fl_font(o
->font
, o
->size
);
45 fl_color((Fl_Color
)o
->color
);
46 fl_draw(o
->value
, X
, Y
, W
, H
, align
, o
->image
);
50 fl_normal_measure(const Fl_Label
* o
, int& W
, int& H
) {
51 fl_font(o
->font
, o
->size
);
52 fl_measure(o
->value
, W
, H
);
54 if (o
->image
->w() > W
) W
= o
->image
->w();
59 #define MAX_LABELTYPE 16
61 static Fl_Label_Draw_F
* table
[MAX_LABELTYPE
] = {
64 fl_normal_label
, // _FL_SHADOW_LABEL,
65 fl_normal_label
, // _FL_ENGRAVED_LABEL,
66 fl_normal_label
, // _FL_EMBOSSED_LABEL,
67 fl_no_label
, // _FL_MULTI_LABEL,
68 fl_no_label
, // _FL_ICON_LABEL,
69 // FL_FREE_LABELTYPE+n:
70 fl_no_label
, fl_no_label
, fl_no_label
,
71 fl_no_label
, fl_no_label
, fl_no_label
,
72 fl_no_label
, fl_no_label
, fl_no_label
75 static Fl_Label_Measure_F
* measure
[MAX_LABELTYPE
];
77 /** Sets the functions to call to draw and measure a specific labeltype. */
78 void Fl::set_labeltype(Fl_Labeltype t
,Fl_Label_Draw_F
* f
,Fl_Label_Measure_F
*m
)
80 table
[t
] = f
; measure
[t
] = m
;
83 ////////////////////////////////////////////////////////////////
85 /** Draws a label with arbitrary alignment in an arbitrary box. */
86 void Fl_Label::draw(int X
, int Y
, int W
, int H
, Fl_Align align
) const {
87 if (!value
&& !image
) return;
88 table
[type
](this, X
, Y
, W
, H
, align
);
91 Measures the size of the label.
92 \param[in,out] W, H : this is the requested size for the label text plus image;
93 on return, this will contain the size needed to fit the label
95 void Fl_Label::measure(int& W
, int& H
) const {
96 if (!value
&& !image
) {
101 Fl_Label_Measure_F
* f
= ::measure
[type
]; if (!f
) f
= fl_normal_measure
;
105 /** Draws the widget's label at the defined label position.
106 This is the normal call for a widget's draw() method.
108 void Fl_Widget::draw_label() const {
109 int X
= x_
+Fl::box_dx(box());
110 int W
= w_
-Fl::box_dw(box());
111 if (W
> 11 && align()&(FL_ALIGN_LEFT
|FL_ALIGN_RIGHT
)) {X
+= 3; W
-= 6;}
112 draw_label(X
, y_
+Fl::box_dy(box()), W
, h_
-Fl::box_dh(box()));
115 /** Draws the label in an arbitrary bounding box.
116 draw() can use this instead of draw_label(void) to change the bounding box
118 void Fl_Widget::draw_label(int X
, int Y
, int W
, int H
) const {
119 // quit if we are not drawing a label inside the widget:
120 if ((align()&15) && !(align() & FL_ALIGN_INSIDE
)) return;
121 draw_label(X
,Y
,W
,H
,align());
124 /** Draws the label in an arbitrary bounding box with an arbitrary alignment.
125 Anybody can call this to force the label to draw anywhere.
127 void Fl_Widget::draw_label(int X
, int Y
, int W
, int H
, Fl_Align a
) const {
128 if (flags()&SHORTCUT_LABEL
) fl_draw_shortcut
= 1;
129 Fl_Label l1
= label_
;
131 l1
.color
= fl_inactive((Fl_Color
)l1
.color
);
132 if (l1
.deimage
) l1
.image
= l1
.deimage
;
135 fl_draw_shortcut
= 0;
138 // include these vars here so they can be referenced without including
140 #include <FL/Fl_Input_.H>
143 // End of "$Id: fl_labeltype.cxx 7903 2010-11-28 21:06:39Z matt $".