Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add double buffering to frames and toplevels.
Theoretically only needed when drawing background with images, but simpler to do always. Incidentally fixes minor bug in labelframes with redrawing of focus rings, but nobody really used those on labelframes so it was never reported... |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | tip-262 |
Files: | files | file ages | folders |
SHA3-256: |
86db63badc83fbf4052faee929a92942 |
User & Date: | dkf 2019-05-17 20:06:39.845 |
Original Comment: | Add double buffering to frames and toplevels. Theoretically only needed when drawing backgrounds, but simpler to do always. |
Context
2019-05-17
| ||
20:37 | Ugh; misread the code. The highlight ring is drawn first and always on the real window. Because of backgroundless frames. check-in: 0807e606 user: dkf tags: tip-262 | |
20:06 |
Add double buffering to frames and toplevels.
Theoretically only needed when drawing background with images, but simpler to do always. Incidentally fixes minor bug in labelframes with redrawing of focus rings, but nobody really used those on labelframes so it was never reported... check-in: 86db63ba user: dkf tags: tip-262 | |
2019-05-16
| ||
22:22 | Fix some tests. Add some test cases. check-in: 42f90406 user: dkf tags: tip-262 | |
Changes
Changes to generic/tkFrame.c.
︙ | ︙ | |||
97 98 99 100 101 102 103 104 105 106 107 108 109 110 | Tcl_Obj *bgimgPtr; /* Value of -backgroundimage option: specifies * image to display on window's background, or * NULL if none. */ Tk_Image bgimg; /* Derived from bgimgPtr by calling * Tk_GetImage, or NULL if bgimgPtr is * NULL. */ int tile; /* Whether to tile the bgimg. */ } Frame; /* * A data structure of the following type is kept for each labelframe widget * managed by this file: */ | > > > | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | Tcl_Obj *bgimgPtr; /* Value of -backgroundimage option: specifies * image to display on window's background, or * NULL if none. */ Tk_Image bgimg; /* Derived from bgimgPtr by calling * Tk_GetImage, or NULL if bgimgPtr is * NULL. */ int tile; /* Whether to tile the bgimg. */ #ifndef TK_NO_DOUBLE_BUFFERING GC copyGC; /* GC for copying when double-buffering. */ #endif /* TK_NO_DOUBLE_BUFFERING */ } Frame; /* * A data structure of the following type is kept for each labelframe widget * managed by this file: */ |
︙ | ︙ | |||
328 329 330 331 332 333 334 | int objc, Tcl_Obj *const objv[]); static int CreateFrame(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const argv[], enum FrameType type, const char *appName); static void DestroyFrame(void *memPtr); static void DestroyFramePartly(Frame *framePtr); static void DisplayFrame(ClientData clientData); | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | int objc, Tcl_Obj *const objv[]); static int CreateFrame(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const argv[], enum FrameType type, const char *appName); static void DestroyFrame(void *memPtr); static void DestroyFramePartly(Frame *framePtr); static void DisplayFrame(ClientData clientData); static void DrawFrameBackground(Tk_Window tkwin, Pixmap pixmap, int highlightWidth, int borderWidth, Tk_Image bgimg, int bgtile); static void FrameBgImageProc(ClientData clientData, int x, int y, int width, int height, int imgWidth, int imgHeight); static void FrameCmdDeletedProc(ClientData clientData); static void FrameEventProc(ClientData clientData, |
︙ | ︙ | |||
893 894 895 896 897 898 899 900 901 902 903 904 905 906 | if (framePtr->type == TYPE_LABELFRAME) { Tk_FreeTextLayout(labelframePtr->textLayout); if (labelframePtr->textGC != NULL) { Tk_FreeGC(framePtr->display, labelframePtr->textGC); } } if (framePtr->colormap != None) { Tk_FreeColormap(framePtr->display, framePtr->colormap); } if (framePtr->bgimg) { Tk_FreeImage(framePtr->bgimg); } ckfree(framePtr); | > > > > > | 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | if (framePtr->type == TYPE_LABELFRAME) { Tk_FreeTextLayout(labelframePtr->textLayout); if (labelframePtr->textGC != NULL) { Tk_FreeGC(framePtr->display, labelframePtr->textGC); } } #ifndef TK_NO_DOUBLE_BUFFERING if (framePtr->copyGC != NULL) { Tk_FreeGC(framePtr->display, framePtr->copyGC); } #endif /* TK_NO_DOUBLE_BUFFERING */ if (framePtr->colormap != None) { Tk_FreeColormap(framePtr->display, framePtr->colormap); } if (framePtr->bgimg) { Tk_FreeImage(framePtr->bgimg); } ckfree(framePtr); |
︙ | ︙ | |||
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | anyTextLabel = (framePtr->type == TYPE_LABELFRAME) && (labelframePtr->textPtr != NULL) && (labelframePtr->labelWin == NULL); anyWindowLabel = (framePtr->type == TYPE_LABELFRAME) && (labelframePtr->labelWin != NULL); if (framePtr->type == TYPE_LABELFRAME) { /* * The textGC is needed even in the labelWin case, so it's always * created for a labelframe. */ gcValues.font = Tk_FontId(labelframePtr->tkfont); | > > > > > > > > > | 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 | anyTextLabel = (framePtr->type == TYPE_LABELFRAME) && (labelframePtr->textPtr != NULL) && (labelframePtr->labelWin == NULL); anyWindowLabel = (framePtr->type == TYPE_LABELFRAME) && (labelframePtr->labelWin != NULL); #ifndef TK_NO_DOUBLE_BUFFERING gcValues.graphics_exposures = False; gc = Tk_GetGC(tkwin, GCGraphicsExposures, &gcValues); if (framePtr->copyGC != NULL) { Tk_FreeGC(framePtr->display, framePtr->copyGC); } framePtr->copyGC = gc; #endif /* TK_NO_DOUBLE_BUFFERING */ if (framePtr->type == TYPE_LABELFRAME) { /* * The textGC is needed even in the labelWin case, so it's always * created for a labelframe. */ gcValues.font = Tk_FontId(labelframePtr->tkfont); |
︙ | ︙ | |||
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | * If -background is set to "", no interior is drawn. */ if (framePtr->border == NULL) { return; } if (framePtr->type != TYPE_LABELFRAME) { /* * Pass to platform specific draw function. In general, it just draws * a simple rectangle, but it may "theme" the background. */ noLabel: | > > > > > > > > > > > > > > | | < < < < < < < < < < < < < < | 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 | * If -background is set to "", no interior is drawn. */ if (framePtr->border == NULL) { return; } #ifndef TK_NO_DOUBLE_BUFFERING /* * In order to avoid screen flashes, this function redraws the frame into * off-screen memory, then copies it back on-screen in a single operation. * This means there's no point in time where the on-screen image has been * cleared. */ pixmap = Tk_GetPixmap(framePtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); #else pixmap = Tk_WindowId(tkwin); #endif /* TK_NO_DOUBLE_BUFFERING */ if (framePtr->type != TYPE_LABELFRAME) { /* * Pass to platform specific draw function. In general, it just draws * a simple rectangle, but it may "theme" the background. */ noLabel: TkpDrawFrameEx(tkwin, pixmap, framePtr->border, hlWidth, framePtr->borderWidth, framePtr->relief); if (framePtr->bgimg) { DrawFrameBackground(tkwin, pixmap, hlWidth, framePtr->borderWidth, framePtr->bgimg, framePtr->tile); } } else { Labelframe *labelframePtr = (Labelframe *) framePtr; if ((labelframePtr->textPtr == NULL) && (labelframePtr->labelWin == NULL)) { goto noLabel; } /* * Clear the pixmap. */ Tk_Fill3DRectangle(tkwin, pixmap, framePtr->border, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); |
︙ | ︙ | |||
1642 1643 1644 1645 1646 1647 1648 | } else { Tk_MaintainGeometry(labelframePtr->labelWin, framePtr->tkwin, labelframePtr->labelBox.x, labelframePtr->labelBox.y, labelframePtr->labelBox.width, labelframePtr->labelBox.height); } } | | > | | | | | < | < | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 | } else { Tk_MaintainGeometry(labelframePtr->labelWin, framePtr->tkwin, labelframePtr->labelBox.x, labelframePtr->labelBox.y, labelframePtr->labelBox.width, labelframePtr->labelBox.height); } } } #ifndef TK_NO_DOUBLE_BUFFERING /* * Everything's been redisplayed; now copy the pixmap onto the screen and * free up the pixmap. */ XCopyArea(framePtr->display, pixmap, Tk_WindowId(tkwin), framePtr->copyGC, 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(framePtr->display, pixmap); #endif /* TK_NO_DOUBLE_BUFFERING */ } /* *---------------------------------------------------------------------- * * TkpDrawFrame -- * * This procedure draws the rectangular frame area. * * Results: * None. * * Side effects: * Draws inside the tkwin area. * *---------------------------------------------------------------------- */ void TkpDrawFrame( Tk_Window tkwin, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief) { /* * Legacy shim to allow for external callers. Internal ones use * non-exposed TkpDrawFrameEx directly so they can use double-buffering. */ TkpDrawFrameEx(tkwin, Tk_WindowId(tkwin), border, highlightWidth, borderWidth, relief); } /* *-------------------------------------------------------------- * * FrameEventProc -- * |
︙ | ︙ | |||
2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 | * *---------------------------------------------------------------------- */ static void DrawFrameBackground( Tk_Window tkwin, int highlightWidth, int borderWidth, Tk_Image bgimg, int bgtile) { int width, height; /* Area to paint on. */ int imageWidth, imageHeight; /* Dimensions of image. */ | > | 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 | * *---------------------------------------------------------------------- */ static void DrawFrameBackground( Tk_Window tkwin, Pixmap pixmap, int highlightWidth, int borderWidth, Tk_Image bgimg, int bgtile) { int width, height; /* Area to paint on. */ int imageWidth, imageHeight; /* Dimensions of image. */ |
︙ | ︙ | |||
2165 2166 2167 2168 2169 2170 2171 | w = (width + bw) - x; } for (y = bw; y < height + bw; y += imageHeight) { int h = imageHeight; if (y - bw + imageHeight > height) { h = (height + bw) - y; } | | | 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 | w = (width + bw) - x; } for (y = bw; y < height + bw; y += imageHeight) { int h = imageHeight; if (y - bw + imageHeight > height) { h = (height + bw) - y; } Tk_RedrawImage(bgimg, 0, 0, w, h, pixmap, x, y); } } } else { /* * Draw the image centred in the widget (inside the border). */ |
︙ | ︙ | |||
2193 2194 2195 2196 2197 2198 2199 | yOff = (Tk_Height(tkwin) - imageHeight) / 2; h = imageHeight; } else { y = (imageHeight - height) / 2; yOff = bw; h = height; } | | | 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 | yOff = (Tk_Height(tkwin) - imageHeight) / 2; h = imageHeight; } else { y = (imageHeight - height) / 2; yOff = bw; h = height; } Tk_RedrawImage(bgimg, x, y, w, h, pixmap, xOff, yOff); } } /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ |
Changes to generic/tkInt.h.
︙ | ︙ | |||
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 | int *lengthPtr); MODULE_SCOPE void TkUnderlineCharsInContext(Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *string, int numBytes, int x, int y, int firstByte, int lastByte); MODULE_SCOPE void TkpGetFontAttrsForChar(Tk_Window tkwin, Tk_Font tkfont, int c, struct TkFontAttributes *faPtr); MODULE_SCOPE Tcl_Obj * TkNewWindowObj(Tk_Window tkwin); MODULE_SCOPE void TkpShowBusyWindow(TkBusy busy); MODULE_SCOPE void TkpHideBusyWindow(TkBusy busy); MODULE_SCOPE void TkpMakeTransparentWindowExist(Tk_Window tkwin, Window parent); MODULE_SCOPE void TkpCreateBusy(Tk_FakeWin *winPtr, Tk_Window tkRef, Window *parentPtr, Tk_Window tkParent, | > > > | 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | int *lengthPtr); MODULE_SCOPE void TkUnderlineCharsInContext(Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *string, int numBytes, int x, int y, int firstByte, int lastByte); MODULE_SCOPE void TkpGetFontAttrsForChar(Tk_Window tkwin, Tk_Font tkfont, int c, struct TkFontAttributes *faPtr); MODULE_SCOPE void TkpDrawFrameEx(Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief); MODULE_SCOPE Tcl_Obj * TkNewWindowObj(Tk_Window tkwin); MODULE_SCOPE void TkpShowBusyWindow(TkBusy busy); MODULE_SCOPE void TkpHideBusyWindow(TkBusy busy); MODULE_SCOPE void TkpMakeTransparentWindowExist(Tk_Window tkwin, Window parent); MODULE_SCOPE void TkpCreateBusy(Tk_FakeWin *winPtr, Tk_Window tkRef, Window *parentPtr, Tk_Window tkParent, |
︙ | ︙ |
Changes to macosx/tkMacOSXDraw.c.
︙ | ︙ | |||
2023 2024 2025 2026 2027 2028 2029 | } } } /* *---------------------------------------------------------------------- * | | | > | < | | < | 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 | } } } /* *---------------------------------------------------------------------- * * TkpDrawFrameEx -- * * This procedure draws the rectangular frame area. If the user has * requested themeing, it draws with the background theme. * * Results: * None. * * Side effects: * Draws inside the tkwin area. * *---------------------------------------------------------------------- */ void TkpDrawFrameEx( Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief) { if (useThemedToplevel && Tk_IsTopLevel(tkwin)) { static Tk_3DBorder themedBorder = NULL; if (!themedBorder) { themedBorder = Tk_Get3DBorder(NULL, tkwin, "systemWindowHeaderBackground"); } if (themedBorder) { border = themedBorder; } } Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth, highlightWidth, Tk_Width(tkwin) - 2 * highlightWidth, Tk_Height(tkwin) - 2 * highlightWidth, borderWidth, relief); } /* * Local Variables: * mode: objc * c-basic-offset: 4 * fill-column: 79 * coding: utf-8 * End: */ |
Changes to unix/tkUnixDraw.c.
︙ | ︙ | |||
204 205 206 207 208 209 210 | { TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0); } /* *---------------------------------------------------------------------- * | | | > | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | { TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0); } /* *---------------------------------------------------------------------- * * TkpDrawFrameEx -- * * This function draws the rectangular frame area. * * Results: * None. * * Side effects: * Draws inside the tkwin area. * *---------------------------------------------------------------------- */ void TkpDrawFrameEx( Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief) { Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth, highlightWidth, Tk_Width(tkwin) - 2*highlightWidth, Tk_Height(tkwin) - 2*highlightWidth, borderWidth, relief); } /* * Local Variables: * mode: c |
︙ | ︙ |
Changes to win/tkWinDraw.c.
︙ | ︙ | |||
1491 1492 1493 1494 1495 1496 1497 | { TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0); } /* *---------------------------------------------------------------------- * | | | > | | 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 | { TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0); } /* *---------------------------------------------------------------------- * * TkpDrawFrameEx -- * * This function draws the rectangular frame area. * * Results: * None. * * Side effects: * Draws inside the tkwin area. * *---------------------------------------------------------------------- */ void TkpDrawFrameEx( Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief) { Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth, highlightWidth, Tk_Width(tkwin) - 2 * highlightWidth, Tk_Height(tkwin) - 2 * highlightWidth, borderWidth, relief); } /* * Local Variables: * mode: c |
︙ | ︙ |