Skip to content

Commit

Permalink
Simplified and unified the drawing of focus ring around the field ele…
Browse files Browse the repository at this point in the history
…ment of the themes "alt" and "default".
  • Loading branch information
csaba committed Oct 24, 2023
1 parent d8c34d6 commit d22fdc9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
8 changes: 4 additions & 4 deletions generic/ttk/ttkClamTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ static void IndicatorElementDraw(
* Update the colors within svgDataCopy
*/

upperBdColorPtr = strstr((char *)svgDataPtr, "9e9a91");
lowerBdColorPtr = strstr((char *)svgDataPtr, "cfcdc8");
bgColorPtr = strstr((char *)svgDataPtr, "ffffff");
fgColorPtr = strstr((char *)svgDataPtr, "000000");
upperBdColorPtr = strstr(svgDataPtr, "9e9a91");
lowerBdColorPtr = strstr(svgDataPtr, "cfcdc8");
bgColorPtr = strstr(svgDataPtr, "ffffff");
fgColorPtr = strstr(svgDataPtr, "000000");

assert(upperBdColorPtr);
assert(lowerBdColorPtr);
Expand Down
36 changes: 18 additions & 18 deletions generic/ttk/ttkDefaultTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,25 +390,25 @@ static void FieldElementDraw(
*/
b.x += 1; b.y += 1; b.width -= 2; b.height -= 2;
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);

/*
* Fill the inner rectangle
*/
GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
} else {
/*
* Draw the outer rectangle
* Draw the field element as usual
*/
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
0, TK_RELIEF_SUNKEN);
DrawFieldBorder(tkwin, d, border, borderColor, b);

/*
* Draw the inner border
* Change the color of the border's outermost pixels
*/
GC borderGC = Tk_GCForColor(borderColor, d);
b.x += 1; b.y += 1; b.width -= 2; b.height -= 2;
DrawCorner(tkwin, d, border, borderGC,
b.x, b.y, b.width, b.height, 0, BRDR);
DrawCorner(tkwin, d, border, borderGC,
b.x, b.y, b.width, b.height, 1, LITE);
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
}

GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
} else {
Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
0, TK_RELIEF_SUNKEN);
Expand Down Expand Up @@ -657,12 +657,12 @@ static void IndicatorElementDraw(
* Update the colors within svgDataCopy
*/

shadeColorPtr = strstr((char *)svgDataPtr, "888888");
highlightColorPtr = strstr((char *)svgDataPtr, "eeeeee");
borderColorPtr = strstr((char *)svgDataPtr, "414141");
bgColorPtr = strstr((char *)svgDataPtr, "d9d9d9");
indicatorColorPtr = strstr((char *)svgDataPtr, "ffffff");
fgColorPtr = strstr((char *)svgDataPtr, "000000");
shadeColorPtr = strstr(svgDataPtr, "888888");
highlightColorPtr = strstr(svgDataPtr, "eeeeee");
borderColorPtr = strstr(svgDataPtr, "414141");
bgColorPtr = strstr(svgDataPtr, "d9d9d9");
indicatorColorPtr = strstr(svgDataPtr, "ffffff");
fgColorPtr = strstr(svgDataPtr, "000000");

assert(shadeColorPtr);
assert(highlightColorPtr);
Expand Down
46 changes: 30 additions & 16 deletions generic/ttk/ttkElements.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,35 @@ static void FieldElementDraw(
XDrawLine(disp, d, focusGC, x1, y1+1, x1, y2-1+w); /* W */
XDrawLine(disp, d, focusGC, x2, y1+1, x2, y2-1+w); /* E */

/*
* Draw the inner rectangle
*/
b.x += 1; b.y += 1; b.width -= 2; b.height -= 2;
}
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);

/*
* If focusWidth > 1 then draw the inner rectangle,
* else the only one replacing the (outer) border
*/
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
/*
* Fill the inner rectangle
*/
GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
} else {
/*
* Draw the field element as usual
*/
int borderWidth = 2;
Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj,
&borderWidth);
Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
borderWidth, TK_RELIEF_SUNKEN);

GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
/*
* Change the color of the border's outermost pixels
*/
XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
}
} else {
int borderWidth = 2;
Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth);

Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
borderWidth, TK_RELIEF_SUNKEN);
}
Expand Down Expand Up @@ -799,17 +813,17 @@ static void IndicatorElementDraw(
* Update the colors within svgDataCopy
*/
if (selected || tristate) {
bgColorPtr = strstr((char *)svgDataPtr, "4a6984");
fgColorPtr = strstr((char *)svgDataPtr, "ffffff");
bgColorPtr = strstr(svgDataPtr, "4a6984");
fgColorPtr = strstr(svgDataPtr, "ffffff");

assert(bgColorPtr);
assert(fgColorPtr);

memcpy(bgColorPtr, bgColorStr, 6);
memcpy(fgColorPtr, fgColorStr, 6);
} else {
bgColorPtr = strstr((char *)svgDataPtr, "ffffff");
borderColorPtr = strstr((char *)svgDataPtr, "888888");
bgColorPtr = strstr(svgDataPtr, "ffffff");
borderColorPtr = strstr(svgDataPtr, "888888");

assert(bgColorPtr);
assert(borderColorPtr);
Expand Down Expand Up @@ -1430,9 +1444,9 @@ static void SliderElementDraw(
/*
* Update the colors within svgDataCopy
*/
innerColorPtr = strstr((char *)svgDataPtr, "4a6984");
outerColorPtr = strstr((char *)svgDataPtr, "ffffff");
borderColorPtr = strstr((char *)svgDataPtr, "c3c3c3");
innerColorPtr = strstr(svgDataPtr, "4a6984");
outerColorPtr = strstr(svgDataPtr, "ffffff");
borderColorPtr = strstr(svgDataPtr, "c3c3c3");
assert(innerColorPtr);
assert(outerColorPtr);
assert(borderColorPtr);
Expand Down

0 comments on commit d22fdc9

Please sign in to comment.