summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-04-07 23:17:33 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-04-07 23:17:33 +0000
commitf899c3897d62bd4f3c2d3bcaaf1ac5447ca8d158 (patch)
tree98d2c3bbfabae8ba92f3f31c825b4de700b391a1 /src
parent0fe65e94c98cee0baf9df8d60bef0137f42fdb92 (diff)
Added new flags for label alignment: FL_LEFT_TOP, FL_RIGHT_TOP, FL_LEFT_BOTTOM, and FL_RIGHT_BOTTOM align outside labels first to the side, then to the top or botton, filling a gap in possible alignment. Also FL_ALIGN_TEXT_NEXT_TO_IMAGE and FL_ALIGN_IMAGE_NEXT_TO_TEXT which do just that, and finally FL_ALIGN_IMAGE_BACKDROP which renders the image in the background and draws the label on top.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7469 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Group.cxx18
-rw-r--r--src/fl_boxtype.cxx21
-rw-r--r--src/fl_draw.cxx59
3 files changed, 75 insertions, 23 deletions
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx
index a5ca1739b..8f02fcf46 100644
--- a/src/Fl_Group.cxx
+++ b/src/Fl_Group.cxx
@@ -745,7 +745,23 @@ void Fl_Group::draw_outside_label(const Fl_Widget& widget) const {
int Y = widget.y();
int W = widget.w();
int H = widget.h();
- if (a & FL_ALIGN_TOP) {
+ if ( (a & 0x0f) == FL_ALIGN_LEFT_TOP ) {
+ a = (a &~0x0f ) | FL_ALIGN_TOP_RIGHT;
+ X = x();
+ W = widget.x()-X-3;
+ } else if ( (a & 0x0f) == FL_ALIGN_LEFT_BOTTOM ) {
+ a = (a &~0x0f ) | FL_ALIGN_BOTTOM_RIGHT;
+ X = x();
+ W = widget.x()-X-3;
+ } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_TOP ) {
+ a = (a &~0x0f ) | FL_ALIGN_TOP_LEFT;
+ X = X+W+3;
+ W = x()+this->w()-X;
+ } else if ( (a & 0x0f) == FL_ALIGN_RIGHT_BOTTOM ) {
+ a = (a &~0x0f ) | FL_ALIGN_BOTTOM_LEFT;
+ X = X+W+3;
+ W = x()+this->w()-X;
+ } else if (a & FL_ALIGN_TOP) {
a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
Y = y();
H = widget.y()-Y;
diff --git a/src/fl_boxtype.cxx b/src/fl_boxtype.cxx
index f4ae05941..c8a824e5c 100644
--- a/src/fl_boxtype.cxx
+++ b/src/fl_boxtype.cxx
@@ -399,14 +399,19 @@ void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) {
//extern Fl_Widget *fl_boxcheat; // hack set by Fl_Window.cxx
/** Draws the widget box according its box style */
void Fl_Widget::draw_box() const {
- int t = box_;
- if (!t) return;
-// if (this == fl_boxcheat) {
-// fl_boxcheat = 0;
-// if (t == FL_FLAT_BOX) return;
-// t += 2; // convert box to frame
-// }
- draw_box((Fl_Boxtype)t, x_, y_, w_, h_, color_);
+ if (box_) draw_box((Fl_Boxtype)box_, x_, y_, w_, h_, color_);
+ draw_backdrop();
+}
+/** If FL_ALIGN_IMAGE_BACKDROP is set, the image or deimage will be drawn */
+void Fl_Widget::draw_backdrop() const {
+ if (align() & FL_ALIGN_IMAGE_BACKDROP) {
+ const Fl_Image *img = image();
+ // if there is no image, we will not draw the deimage either
+ if (img && deimage() && !active_r())
+ img = deimage();
+ if (img)
+ ((Fl_Image*)img)->draw(x_+(w_-img->w())/2, y_+(h_-img->h())/2);
+ }
}
/** Draws a box of type t, of color c at the widget's position and size. */
void Fl_Widget::draw_box(Fl_Boxtype t, Fl_Color c) const {
diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx
index d435bf82b..27f50afad 100644
--- a/src/fl_draw.cxx
+++ b/src/fl_draw.cxx
@@ -186,7 +186,8 @@ void fl_draw(
int x, int y, int w, int h, // bounding box
Fl_Align align,
void (*callthis)(const char*,int,int,int),
- Fl_Image* img, int draw_symbols) {
+ Fl_Image* img, int draw_symbols)
+{
const char* p;
const char* e;
char buf[MAXBUF];
@@ -198,6 +199,9 @@ void fl_draw(
int lines;
double width;
+ // if the image is set as a backdrop, ignore it here
+ if (img && (align & FL_ALIGN_IMAGE_BACKDROP)) img = 0;
+
symbol[0][0] = '\0';
symwidth[0] = 0;
@@ -222,29 +226,36 @@ void fl_draw(
}
symtotal = symwidth[0] + symwidth[1];
+
+ int strw = 0;
+ int strh;
if (str) {
- for (p = str, lines=0; p;) {
+ for (p = str, lines=0; p;) {
e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, width,
- align&FL_ALIGN_WRAP, draw_symbols);
- lines++;
- if (!*e || (*e == '@' && e[1] != '@' && draw_symbols)) break;
- p = e;
- }
+ align&FL_ALIGN_WRAP, draw_symbols);
+ if (strw<width) strw = width;
+ lines++;
+ if (!*e || (*e == '@' && e[1] != '@' && draw_symbols)) break;
+ p = e;
+ }
} else lines = 0;
-
+
if ((symwidth[0] || symwidth[1]) && lines) {
if (symwidth[0]) symwidth[0] = lines * fl_height();
if (symwidth[1]) symwidth[1] = lines * fl_height();
}
symtotal = symwidth[0] + symwidth[1];
+ strh = 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;
+ int imgvert = ((align&FL_ALIGN_TEXT_NEXT_TO_IMAGE)==0);
+ int imgh = img && imgvert ? img->h() : 0;
+ int imgw[2] = {0, 0};
symoffset = 0;
@@ -253,7 +264,7 @@ void fl_draw(
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 (img && imgvert && !(align & FL_ALIGN_TEXT_OVER_IMAGE)) {
if (img->w() > symoffset) symoffset = img->w();
if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0];
@@ -264,6 +275,26 @@ void fl_draw(
ypos += img->h();
}
+ // draw the image to the side of the text
+ if (img && !imgvert /* && (align & !FL_ALIGN_TEXT_NEXT_TO_IMAGE)*/ ) {
+ if (align & FL_ALIGN_TEXT_OVER_IMAGE) { // image is right of text
+ imgw[1] = img->w();
+ if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0] + strw + 1;
+ else if (align & FL_ALIGN_RIGHT) xpos = x + w - symwidth[1] - imgw[1] + 1;
+ else xpos = x + (w - strw - symtotal - imgw[1]) / 2 + symwidth[0] + strw + 1;
+ } else { // image is to the left of the text
+ imgw[0] = img->w();
+ if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0] - 1;
+ else if (align & FL_ALIGN_RIGHT) xpos = x + w - symwidth[1] - strw - imgw[0] - 1;
+ else xpos = x + (w - strw - symtotal - imgw[0]) / 2 - 1;
+ }
+ int yimg = ypos - height;
+ if (align & FL_ALIGN_TOP) ;
+ else if (align & FL_ALIGN_BOTTOM) yimg += strh - img->h() - 1;
+ else yimg += (strh - img->h() - 1) / 2;
+ img->draw(xpos, yimg);
+ }
+
// now draw all the lines:
if (str) {
int desc = fl_descent();
@@ -274,9 +305,9 @@ void fl_draw(
if (width > symoffset) symoffset = (int)(width + 0.5);
- if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0];
- else if (align & FL_ALIGN_RIGHT) xpos = x + w - (int)(width + .5) - symwidth[1];
- else xpos = x + (w - (int)(width + .5) - symtotal) / 2 + symwidth[0];
+ if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0] + imgw[0];
+ else if (align & FL_ALIGN_RIGHT) xpos = x + w - (int)(width + .5) - symwidth[1] - imgw[1];
+ else xpos = x + (w - (int)(width + .5) - symtotal - imgw[0] - imgw[1]) / 2 + symwidth[0] + imgw[0];
callthis(buf,buflen,xpos,ypos-desc);
@@ -289,7 +320,7 @@ void fl_draw(
}
// draw the image if the "text over image" alignment flag is set...
- if (img && (align & FL_ALIGN_TEXT_OVER_IMAGE)) {
+ if (img && imgvert && (align & FL_ALIGN_TEXT_OVER_IMAGE)) {
if (img->w() > symoffset) symoffset = img->w();
if (align & FL_ALIGN_LEFT) xpos = x + symwidth[0];