From 28c0d4ffa1ccd9828f00be1c96405484b5e5d681 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 6 Aug 2001 03:17:43 +0000 Subject: 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 --- src/fl_draw.cxx | 119 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 18 deletions(-) (limited to 'src/fl_draw.cxx') diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx index 10d5a24e9..bbffe6791 100644 --- a/src/fl_draw.cxx +++ b/src/fl_draw.cxx @@ -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 #include +#include #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 && oh() : 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 $". // -- cgit v1.2.3