Symbols are now supported by main label drawing code - @@ to insert a

single @. Currently only 1 symbol per label, at the beginning or end of the
label string, with the remaining text (and image) getting formatted as
usual.  The size of the symbol == lines * labelsize, unless there is
no text in which case the size == height of label area.

Fl_Menu_Item::draw() didn't clear the image field in the Fl_Label
structure.

Removed Fl::enable_symbols(), which is now the default.

Dropped FL_IMAGE_LABEL, FL_PIXMAP_LABEL, and FL_BITMAP_LABEL types,
which are no longer needed.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1561 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2001-08-06 03:17:43 +00:00
parent 7ebaf77cdc
commit 28c0d4ffa1
10 changed files with 148 additions and 93 deletions

View File

@ -47,8 +47,7 @@ TODO - Documentation updates.
- Updated configure stuff to support shared libraries
under AIX (link to -lfltk_s)
TODO - Symbol labels can now contain regular text and
Fl_Browser font and color controls.
- Symbol labels can now contain regular text.
- FLUID now supports relative filenames for the source
and header files you generate.

View File

@ -1,5 +1,5 @@
//
// "$Id: Enumerations.H,v 1.18.2.14.2.4 2001/08/05 23:58:54 easysw Exp $"
// "$Id: Enumerations.H,v 1.18.2.14.2.5 2001/08/06 03:17:43 easysw Exp $"
//
// Enumerations for the Fast Light Tool Kit (FLTK).
//
@ -195,20 +195,15 @@ inline Fl_Boxtype frame(Fl_Boxtype b) {return (Fl_Boxtype)(b|2);}
enum Fl_Labeltype { // labeltypes:
FL_NORMAL_LABEL = 0,
FL_NO_LABEL,
_FL_SYMBOL_LABEL,
_FL_SHADOW_LABEL,
_FL_ENGRAVED_LABEL,
_FL_EMBOSSED_LABEL,
_FL_BITMAP_LABEL,
_FL_PIXMAP_LABEL,
_FL_IMAGE_LABEL,
_FL_MULTI_LABEL,
_FL_ICON_LABEL,
FL_FREE_LABELTYPE
};
extern Fl_Labeltype FL_EXPORT define_FL_SYMBOL_LABEL();
#define FL_SYMBOL_LABEL define_FL_SYMBOL_LABEL()
#define FL_SYMBOL_LABEL FL_NORMAL_LABEL
extern Fl_Labeltype FL_EXPORT define_FL_SHADOW_LABEL();
#define FL_SHADOW_LABEL define_FL_SHADOW_LABEL()
extern Fl_Labeltype FL_EXPORT define_FL_ENGRAVED_LABEL();
@ -369,5 +364,5 @@ enum Fl_Damage {
#endif
//
// End of "$Id: Enumerations.H,v 1.18.2.14.2.4 2001/08/05 23:58:54 easysw Exp $".
// End of "$Id: Enumerations.H,v 1.18.2.14.2.5 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl.H,v 1.8.2.11.2.1 2001/08/02 20:09:25 easysw Exp $"
// "$Id: Fl.H,v 1.8.2.11.2.2 2001/08/06 03:17:43 easysw Exp $"
//
// Main header file for the Fast Light Tool Kit (FLTK).
//
@ -187,7 +187,6 @@ public:
// labeltypes:
static FL_EXPORT void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
static FL_EXPORT void set_labeltype(Fl_Labeltype, Fl_Labeltype from);
static FL_EXPORT void enable_symbols();
// boxtypes:
static FL_EXPORT void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
@ -218,5 +217,5 @@ public:
#endif
//
// End of "$Id: Fl.H,v 1.8.2.11.2.1 2001/08/02 20:09:25 easysw Exp $".
// End of "$Id: Fl.H,v 1.8.2.11.2.2 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu.cxx,v 1.18.2.12.2.1 2001/08/04 20:17:10 easysw Exp $"
// "$Id: Fl_Menu.cxx,v 1.18.2.12.2.2 2001/08/06 03:17:43 easysw Exp $"
//
// Menu code for the Fast Light Tool Kit (FLTK).
//
@ -123,11 +123,13 @@ int Fl_Menu_Item::measure(int* hp, const Fl_Menu_* m) const {
void Fl_Menu_Item::draw(int x, int y, int w, int h, const Fl_Menu_* m,
int selected) const {
Fl_Label l;
l.value = text;
l.type = labeltype_;
l.font = labelsize_ ? labelfont_ : uchar(m ? m->textfont() : FL_HELVETICA);
l.size = labelsize_ ? labelsize_ : m ? m->textsize() : FL_NORMAL_SIZE;
l.color = labelcolor_ ? labelcolor_ : m ? m->textcolor() : int(FL_BLACK);
l.value = text;
l.image = 0;
l.deimage = 0;
l.type = labeltype_;
l.font = labelsize_ ? labelfont_ : uchar(m ? m->textfont() : FL_HELVETICA);
l.size = labelsize_ ? labelsize_ : m ? m->textsize() : FL_NORMAL_SIZE;
l.color = labelcolor_ ? labelcolor_ : m ? m->textcolor() : int(FL_BLACK);
if (!active()) l.color = inactive((Fl_Color)l.color);
Fl_Color color = m ? m->color() : FL_GRAY;
if (selected) {
@ -741,5 +743,5 @@ const Fl_Menu_Item* Fl_Menu_Item::test_shortcut() const {
}
//
// End of "$Id: Fl_Menu.cxx,v 1.18.2.12.2.1 2001/08/04 20:17:10 easysw Exp $".
// End of "$Id: Fl_Menu.cxx,v 1.18.2.12.2.2 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.4 2001/08/05 14:00:15 easysw Exp $"
// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.5 2001/08/06 03:17:43 easysw Exp $"
//
// Base widget class for the Fast Light Tool Kit (FLTK).
//
@ -76,22 +76,24 @@ Fl_Widget::Fl_Widget(int X, int Y, int W, int H, const char* L) {
x_ = X; y_ = Y; w_ = W; h_ = H;
label_.value = L;
label_.type = FL_NORMAL_LABEL;
label_.font = FL_HELVETICA;
label_.size = FL_NORMAL_SIZE;
label_.color = FL_BLACK;
tooltip_ = 0;
callback_ = default_callback;
user_data_ = 0;
type_ = 0;
flags_ = 0;
damage_ = 0;
box_ = FL_NO_BOX;
color_ = FL_GRAY;
color2_ = FL_GRAY;
align_ = FL_ALIGN_CENTER;
when_ = FL_WHEN_RELEASE;
label_.value = L;
label_.image = 0;
label_.deimage = 0;
label_.type = FL_NORMAL_LABEL;
label_.font = FL_HELVETICA;
label_.size = FL_NORMAL_SIZE;
label_.color = FL_BLACK;
tooltip_ = 0;
callback_ = default_callback;
user_data_ = 0;
type_ = 0;
flags_ = 0;
damage_ = 0;
box_ = FL_NO_BOX;
color_ = FL_GRAY;
color2_ = FL_GRAY;
align_ = FL_ALIGN_CENTER;
when_ = FL_WHEN_RELEASE;
parent_ = 0;
if (Fl_Group::current()) Fl_Group::current()->add(this);
@ -229,5 +231,5 @@ int Fl_Widget::contains(const Fl_Widget *o) const {
}
//
// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.4 2001/08/05 14:00:15 easysw Exp $".
// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.5 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_draw.cxx,v 1.6.2.4.2.1 2001/08/05 23:58:54 easysw Exp $"
// "$Id: fl_draw.cxx,v 1.6.2.4.2.2 2001/08/06 03:17:43 easysw Exp $"
//
// Label drawing code for the Fast Light Tool Kit (FLTK).
//
@ -34,8 +34,10 @@
#include <FL/Fl_Image.H>
#include <string.h>
#include <ctype.h>
#define MAXBUF 1024
#define min(a,b) ((a)<(b)?(a):(b))
char fl_draw_shortcut; // set by fl_labeltypes.cxx
@ -84,21 +86,20 @@ expand(const char* from, char* buf, double maxw, int& n, double &width, int wrap
if (c == '\t') {
for (c = (o-buf)%8; c<8 && o<e; c++) *o++ = ' ';
} else if (c == '&' && fl_draw_shortcut && *(p+1)) {
if (*(p+1) == '&') {p++; *o++ = '&';}
else if (fl_draw_shortcut != 2) underline_at = o;
} else if (c < ' ' || c == 127) { // ^X
*o++ = '^';
*o++ = c ^ 0x40;
} else if (c == 0xA0) { // non-breaking space
*o++ = ' ';
} else if (c == '@') { // Symbol???
if (p[1] && p[1] != '@') break;
*o++ = c;
if (p[1]) p++;
} else {
*o++ = c;
}
}
@ -118,32 +119,71 @@ void fl_draw(
const char* e;
char buf[MAXBUF];
int buflen;
char symbol[255], *symptr;
int symwidth, symwhen, symoffset;
// count how many lines and put the last one into the buffer:
int lines;
double width;
for (p=str,lines=0; ;) {
symbol[0] = '\0';
symwidth = 0;
symwhen = 0;
if (str && str[0] == '@' && str[1] && str[1] != '@') {
// Start with a symbol...
for (symptr = symbol;
*str && !isspace(*str) && symptr < (symbol + sizeof(symbol) - 1);
*symptr++ = *str++);
*symptr = '\0';
if (isspace(*str)) str++;
symwidth = min(w,h);
}
for (p = str, lines=0; p;) {
e = expand(p, buf, w, buflen, width, align&FL_ALIGN_WRAP);
lines++;
if (!*e) break;
else if (*e == '@') {
strncpy(symbol, e, sizeof(symbol) - 1);
symbol[sizeof(symbol) - 1] = '\0';
symwidth = min(w,h);
symwhen = 1;
break;
}
p = e;
}
if (symwidth && lines) symwidth = lines * fl_height();
// figure out vertical position of the first line:
int xpos;
int ypos;
int height = fl_height();
int imgh = img ? img->h() : 0;
symoffset = 0;
if (align & FL_ALIGN_BOTTOM) ypos = y+h-(lines-1)*height-imgh;
else if (align & FL_ALIGN_TOP) ypos = y+height;
else ypos = y+(h-lines*height-imgh)/2+height;
// draw the image unless the "text over image" alignment flag is set...
if (img && !(align & FL_ALIGN_TEXT_OVER_IMAGE)) {
if (align & FL_ALIGN_LEFT) xpos = x;
else if (align & FL_ALIGN_RIGHT) xpos = x+w-img->w();
else xpos = x+(w-img->w())/2;
if (img->w() > symoffset) symoffset = img->w();
if (align & FL_ALIGN_LEFT) {
if (!symwhen) xpos = x + symwidth;
else xpos = x;
}
else if (align & FL_ALIGN_RIGHT) {
if (symwhen) xpos = x+w-img->w()-symwidth;
else xpos = x+w-img->w();
}
else {
xpos = x+(w-img->w()-symwidth)/2;
if (!symwhen) xpos += symwidth;
}
img->draw(xpos, ypos - height);
ypos += img->h();
@ -154,27 +194,70 @@ void fl_draw(
for (p=str; ; ypos += height) {
if (lines>1) e = expand(p, buf, w, buflen, width, align&FL_ALIGN_WRAP);
if (align & FL_ALIGN_LEFT) xpos = x;
else if (align & FL_ALIGN_RIGHT) xpos = x+w-int(width+.5);
else xpos = x+int((w-width)/2);
if (width > symoffset) symoffset = (int)(width + 0.5);
if (align & FL_ALIGN_LEFT) {
if (!symwhen) xpos = x + symwidth;
else xpos = x;
}
else if (align & FL_ALIGN_RIGHT) {
if (symwhen) xpos = x+w-int(width+.5) - symwidth;
else xpos = x+w-int(width+.5);
}
else {
xpos = x+int((w-width-symwidth)/2);
if (!symwhen) xpos += symwidth;
}
callthis(buf,buflen,xpos,ypos-desc);
if (underline_at)
callthis("_",1,xpos+int(fl_width(buf,underline_at-buf)),ypos-desc);
if (!*e) break;
if (!*e || *e == '@') break;
p = e;
}
// draw the image if the "text over image" alignment flag is set...
if (img && (align & FL_ALIGN_TEXT_OVER_IMAGE)) {
if (align & FL_ALIGN_LEFT) xpos = x;
else if (align & FL_ALIGN_RIGHT) xpos = x+w-img->w();
else xpos = x+(w-img->w())/2;
if (img->w() > symoffset) symoffset = img->w();
if (align & FL_ALIGN_LEFT) {
if (!symwhen) xpos = x + symwidth;
else xpos = x;
}
else if (align & FL_ALIGN_RIGHT) {
if (symwhen) xpos = x+w-img->w()-symwidth;
else xpos = x+w-img->w();
}
else {
xpos = x+(w-img->w()-symwidth)/2;
if (!symwhen) xpos += symwidth;
}
img->draw(xpos, ypos);
}
// draw the symbol, if any...
if (symwidth) {
if (symwhen) {
// draw to the right
if (align & FL_ALIGN_LEFT) xpos = x + symoffset;
else if (align & FL_ALIGN_RIGHT) xpos = x + w - symwidth;
else xpos = x + (w-symoffset-symwidth)/2+symoffset;
} else {
// draw to the left
if (align & FL_ALIGN_LEFT) xpos = x;
else if (align & FL_ALIGN_RIGHT) xpos = x + w - symwidth - symoffset;
else xpos = x + (w-symoffset-symwidth)/2;
}
if (align & FL_ALIGN_BOTTOM) ypos = y + h - symwidth;
else if (align & FL_ALIGN_TOP) ypos = y;
else ypos = y + (h-symwidth)/2;
fl_draw_symbol(symbol, xpos, ypos, symwidth, symwidth, fl_color());
}
}
void fl_draw(
@ -211,5 +294,5 @@ void fl_measure(const char* str, int& w, int& h) {
}
//
// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.1 2001/08/05 23:58:54 easysw Exp $".
// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.2 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_labeltype.cxx,v 1.6.2.3.2.1 2001/08/05 23:58:54 easysw Exp $"
// "$Id: fl_labeltype.cxx,v 1.6.2.3.2.2 2001/08/06 03:17:43 easysw Exp $"
//
// Label drawing routines for the Fast Light Tool Kit (FLTK).
//
@ -63,16 +63,15 @@ fl_normal_measure(const Fl_Label* o, int& W, int& H) {
static Fl_Label_Draw_F* table[MAX_LABELTYPE] = {
fl_normal_label,
fl_no_label,
fl_normal_label, // _FL_SYMBOL_LABEL,
fl_normal_label, // _FL_SHADOW_LABEL,
fl_normal_label, // _FL_ENGRAVED_LABEL,
fl_normal_label, // _FL_EMBOSSED_LABEL,
fl_no_label, // _FL_BITMAP_LABEL,
fl_no_label, // _FL_PIXMAP_LABEL,
fl_no_label, // _FL_IMAGE_LABEL,
fl_no_label, // _FL_MULTI_LABEL,
fl_no_label, // _FL_ICON_LABEL,
// FL_FREE_LABELTYPE+n:
fl_no_label, fl_no_label, fl_no_label,
fl_no_label, fl_no_label, fl_no_label, fl_no_label,
fl_no_label, fl_no_label, fl_no_label,
fl_no_label, fl_no_label, fl_no_label
};
static Fl_Label_Measure_F* measure[MAX_LABELTYPE];
@ -132,5 +131,5 @@ void Fl_Widget::draw_label(int X, int Y, int W, int H, Fl_Align a) const {
#include <FL/Fl_Input_.H>
//
// End of "$Id: fl_labeltype.cxx,v 1.6.2.3.2.1 2001/08/05 23:58:54 easysw Exp $".
// End of "$Id: fl_labeltype.cxx,v 1.6.2.3.2.2 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_symbols.cxx,v 1.8.2.3 2001/01/22 15:13:41 easysw Exp $"
// "$Id: fl_symbols.cxx,v 1.8.2.3.2.1 2001/08/06 03:17:43 easysw Exp $"
//
// Symbol drawing code for the Fast Light Tool Kit (FLTK).
//
@ -92,7 +92,7 @@ int fl_add_symbol(const char *name, void (*drawit)(Fl_Color), int scalable)
int fl_return_arrow(int x,int y,int w,int h);
// provided for back compatability:
int fl_draw_symbol(const char *label,int x,int y,int w,int h,Fl_Color col) {
int fl_draw_symbol(const char *label,int x,int y,int w,int h,Fl_Color col) {
const char *p = label;
if (*p++ != '@') return 0;
fl_init_symbols();
@ -360,28 +360,6 @@ static void fl_init_symbols(void) {
fl_add_symbol("||", draw_doublebar, 1);
}
////////////////////////////////////////////////////////////////
#include <FL/Fl_Widget.H>
// this is the labeltype function:
extern void fl_normal_label(const Fl_Label*, int, int, int, int, Fl_Align);
static void fl_symbol_label(
const Fl_Label* o, int x, int y, int w, int h, Fl_Align align)
{
if (!fl_draw_symbol(o->value, x, y, w, h, (Fl_Color)o->color))
fl_normal_label(o, x, y, w, h, align);
}
Fl_Labeltype define_FL_SYMBOL_LABEL() {
Fl::set_labeltype(_FL_SYMBOL_LABEL, fl_symbol_label, 0);
return _FL_SYMBOL_LABEL;
}
void Fl::enable_symbols() {
Fl::set_labeltype(FL_NORMAL_LABEL, fl_symbol_label, 0);
}
//
// End of "$Id: fl_symbols.cxx,v 1.8.2.3 2001/01/22 15:13:41 easysw Exp $".
// End of "$Id: fl_symbols.cxx,v 1.8.2.3.2.1 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: forms_compatability.cxx,v 1.5.2.3 2001/01/22 15:13:41 easysw Exp $"
// "$Id: forms_compatability.cxx,v 1.5.2.3.2.1 2001/08/06 03:17:43 easysw Exp $"
//
// Forms compatibility functions for the Fast Light Tool Kit (FLTK).
//
@ -89,8 +89,6 @@ char fl_modal_next; // set by fl_freeze_forms()
void fl_show_form(Fl_Window *f,int place,int b,const char *n) {
Fl::enable_symbols();
f->label(n);
if (!b) f->clear_border();
if (fl_modal_next || b==FL_TRANSIENT) {f->set_modal(); fl_modal_next = 0;}
@ -204,5 +202,5 @@ char *fl_show_simple_input(const char *str1, const char *defstr) {
}
//
// End of "$Id: forms_compatability.cxx,v 1.5.2.3 2001/01/22 15:13:41 easysw Exp $".
// End of "$Id: forms_compatability.cxx,v 1.5.2.3.2.1 2001/08/06 03:17:43 easysw Exp $".
//

View File

@ -311,7 +311,7 @@ fl_show_colormap.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
fl_show_colormap.o: ../FL/Fl_Single_Window.H ../FL/Fl_Window.H
fl_show_colormap.o: ../FL/fl_draw.H ../FL/fl_show_colormap.H ../config.h
fl_symbols.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
fl_symbols.o: ../FL/fl_draw.H ../FL/Fl_Widget.H
fl_symbols.o: ../FL/fl_draw.H
fl_vertex.o: ../FL/fl_draw.H ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/x.H
fl_vertex.o: ../FL/Fl_Window.H ../FL/math.h
forms_compatability.o: ../FL/forms.H ../FL/Fl.H ../FL/Enumerations.H