diff options
author | gcramer <remarcg@gmx.net> | 2017-05-01 13:27:42 (GMT) |
---|---|---|
committer | gcramer <remarcg@gmx.net> | 2017-05-01 13:27:42 (GMT) |
commit | ddf5e6ae8f6240fdbee22b4db0c3a5a8575bd7f1 (patch) | |
tree | 8ab27fb7c3f9d0e5d32c2a455994563ef1bf2383 | |
parent | d7863027d290dbf76ffdd924f3ec9d9e3aa92894 (diff) | |
download | tk-ddf5e6ae8f6240fdbee22b4db0c3a5a8575bd7f1.zip tk-ddf5e6ae8f6240fdbee22b4db0c3a5a8575bd7f1.tar.gz tk-ddf5e6ae8f6240fdbee22b4db0c3a5a8575bd7f1.tar.bz2 |
Fix [2433781fff]: Under X11 image/text now will be centered correctly, the old algorithm has an obvious offset bug, it did not take into account the case if the padding is even.bug_2433781
-rw-r--r-- | unix/tkUnixButton.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/unix/tkUnixButton.c b/unix/tkUnixButton.c index 1aeefac..6a99124 100644 --- a/unix/tkUnixButton.c +++ b/unix/tkUnixButton.c @@ -351,6 +351,47 @@ TkpCreateButton( *---------------------------------------------------------------------- */ +static void +ShiftByOffset( + TkButton *butPtr, + int relief, + int *x, /* shift this x coordinate */ + int *y, /* shift this y coordinate */ + int width, /* width of image/text */ + int height) /* height of image/text */ +{ + if (relief != TK_RELIEF_RAISED + && butPtr->type == TYPE_BUTTON + && !Tk_StrictMotif(butPtr->tkwin)) { + int shiftX; + int shiftY; + + /* + * This is an (unraised) button widget, so we offset the text to make + * the button appear to move up and down as the relief changes. + */ + + shiftX = shiftY = (relief == TK_RELIEF_SUNKEN) ? 2 : 1; + + if (relief != TK_RELIEF_RIDGE) { + /* + * Take back one pixel if the padding is even, otherwise the + * content will be displayed too far right/down. + */ + + if ((Tk_Width(butPtr->tkwin) - width) % 2 == 0) { + shiftX -= 1; + } + if ((Tk_Height(butPtr->tkwin) - height) % 2 == 0) { + shiftY -= 1; + } + } + + *x += shiftX; + *y += shiftY; + } +} + void TkpDisplayButton( ClientData clientData) /* Information about widget. */ @@ -366,10 +407,6 @@ TkpDisplayButton( int width = 0, height = 0, fullWidth, fullHeight; int textXOffset, textYOffset; int haveImage = 0, haveText = 0; - int offset; /* 1 means this is a button widget, so we - * offset the text to make the button appear - * to move up and down as the relief - * changes. */ int imageWidth, imageHeight; int imageXOffset = 0, imageYOffset = 0; /* image information that will be used to @@ -432,8 +469,6 @@ TkpDisplayButton( } } - offset = (butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin); - /* * In order to avoid screen flashes, this function redraws the button in a * pixmap, then copies the pixmap to the screen in a single operation. @@ -525,17 +560,7 @@ TkpDisplayButton( butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y); x += butPtr->indicatorSpace; - - x += offset; - y += offset; - if (relief == TK_RELIEF_RAISED) { - x -= offset; - y -= offset; - } else if (relief == TK_RELIEF_SUNKEN) { - x += offset; - y += offset; - } - + ShiftByOffset(butPtr, relief, &x, &y, width, height); imageXOffset += x; imageYOffset += y; @@ -593,16 +618,7 @@ TkpDisplayButton( TkComputeAnchor(butPtr->anchor, tkwin, 0, 0, butPtr->indicatorSpace + width, height, &x, &y); x += butPtr->indicatorSpace; - - x += offset; - y += offset; - if (relief == TK_RELIEF_RAISED) { - x -= offset; - y -= offset; - } else if (relief == TK_RELIEF_SUNKEN) { - x += offset; - y += offset; - } + ShiftByOffset(butPtr, relief, &x, &y, width, height); imageXOffset += x; imageYOffset += y; if (butPtr->image != NULL) { @@ -655,16 +671,7 @@ TkpDisplayButton( butPtr->textHeight, &x, &y); x += butPtr->indicatorSpace; - - x += offset; - y += offset; - if (relief == TK_RELIEF_RAISED) { - x -= offset; - y -= offset; - } else if (relief == TK_RELIEF_SUNKEN) { - x += offset; - y += offset; - } + ShiftByOffset(butPtr, relief, &x, &y, width, height); Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, x, y, 0, -1); Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, |