Skip to content

Commit

Permalink
Using the application's TkMainInfo struct for sharing the data of the…
Browse files Browse the repository at this point in the history
… trough's inner box in a thread-safe manner when drawing the ttk::slider widget of the "default" theme.
  • Loading branch information
csaba committed May 15, 2024
2 parents 9297c10 + b8070d0 commit d0671e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions generic/tkInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ typedef struct TkMainInfo {
#endif
unsigned int ttkNbTabsStickBit;
/* Information used by ttk::notebook. */
int troughInnerX, troughInnerY, troughInnerWidth, troughInnerHeight;
/* Information used by ttk::scale. */
} TkMainInfo;

/*
Expand Down
41 changes: 25 additions & 16 deletions generic/ttk/ttkElements.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,6 @@ static void TroughElementSize(
}
}

static Ttk_Box troughInnerBox;

static void TroughElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord, Tk_Window tkwin,
Expand All @@ -1224,6 +1222,7 @@ static void TroughElementDraw(
Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj);
int borderWidth = 1, grooveWidth = -1, relief = TK_RELIEF_SUNKEN;
Ttk_Orient orient;
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &grooveWidth);
Expand All @@ -1239,10 +1238,15 @@ static void TroughElementDraw(
b.width = grooveWidth;
}

troughInnerBox.x = b.x + borderWidth;
troughInnerBox.y = b.y + borderWidth;
troughInnerBox.width = b.width - 2*borderWidth;
troughInnerBox.height = b.height - 2*borderWidth;
/*
* Save the data of the trough's inner box for later
*/
if (mainInfoPtr != NULL) {
mainInfoPtr->troughInnerX = b.x + borderWidth;
mainInfoPtr->troughInnerY = b.y + borderWidth;
mainInfoPtr->troughInnerWidth = b.width - 2*borderWidth;
mainInfoPtr->troughInnerHeight = b.height - 2*borderWidth;
}
}

Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
Expand Down Expand Up @@ -1385,6 +1389,7 @@ static void SliderElementDraw(
{
double scalingLevel = TkScalingLevel(tkwin);
int dim = SLIDER_DIM * scalingLevel;
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

SliderElement *slider = (SliderElement *)elementRecord;
Ttk_Orient orient;
Expand Down Expand Up @@ -1426,16 +1431,20 @@ static void SliderElementDraw(
* Fill the thin trough area preceding the
* slider's center with the inner color
*/
Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
switch (orient) {
case TTK_ORIENT_HORIZONTAL:
XFillRectangle(disp, d, gc, troughInnerBox.x, troughInnerBox.y,
b.x + dim/2 - 1, troughInnerBox.height);
break;
case TTK_ORIENT_VERTICAL:
XFillRectangle(disp, d, gc, troughInnerBox.x, troughInnerBox.y,
troughInnerBox.width, b.y + dim/2 - 1);
break;
if (mainInfoPtr != NULL) {
Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
switch (orient) {
case TTK_ORIENT_HORIZONTAL:
XFillRectangle(disp, d, gc,
mainInfoPtr->troughInnerX, mainInfoPtr->troughInnerY,
b.x + dim/2 - 1, mainInfoPtr->troughInnerHeight);
break;
case TTK_ORIENT_VERTICAL:
XFillRectangle(disp, d, gc,
mainInfoPtr->troughInnerX, mainInfoPtr->troughInnerY,
mainInfoPtr->troughInnerWidth, b.y + dim/2 - 1);
break;
}
}

/*
Expand Down

0 comments on commit d0671e7

Please sign in to comment.