FS#3033 - Close Button in window bar doesn't show X anymore

Attached to Project: OpenTTD
Opened by Ingo von Borstel (planetmaker) - Monday, 13 July 2009, 16:01 GMT
Last edited by Remko Bijker (Rubidium) - Sunday, 02 August 2009, 13:38 GMT
Type Bug
Category Interface
Status Closed
Assigned To No-one
Operating System All
Severity Very Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


The "X" string for the close button seems to be too long to fit properly into the close button of windows as shown in the attached screenshot. It goes for all windows. Tested in r16800.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Sunday, 02 August 2009, 13:38 GMT
Reason for closing:  Deferred
Additional comments about closing:  Will, as described be automatically fixed once  FS#1905  is done. Also OpenGFX has a narrower close sprite.
Comment by Remko Bijker (Rubidium) - Monday, 13 July 2009, 16:16 GMT
  • Field changed: Status (New → Confirmed)
  • Field changed: Severity (Low → Very Low)
Will eventually be fixed once the GUI rework is done.
Comment by Remko Bijker (Rubidium) - Monday, 13 July 2009, 16:26 GMT
For what it's worth, it only happens with OpenGFX
Comment by Alberth (Alberth) - Tuesday, 14 July 2009, 16:55 GMT
That was most helpful Rubidium, thank you for finding that out.

An analysis of the problem:
In r16798, the closebox rendering has been changed as follows:
@@ -518,7 +525,7 @@
assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross
DrawFrameRect(r.left,, r.right, r.bottom, colour, FR_NONE);
- DrawString(r.left, r.right, + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_CENTER);

In other words, the amount of space for the closebox string has been reduced by WD_CLOSEBOX_RIGHT pixels (which has the value 1). This constant has been calculated such that


(computation is near line 1987 in widget.cpp, search for NWidgetLeaf::closebox_dimension). This value 11 comes from the current width of the closebox widgets, see output of "grep WWT_CLOSEBOX src/*.cpp | grep CROSS | grep -v NWidget" (gives the WWT_CLOSEBOX widgets in many hardcoded widget arrays in the game).

When printing NWidgetLeaf::closebox_dimension.width after computing it near line 1987, ttdx graphics gives
Closebox dimension=11x14, STR_BLACK_CROSS=155 STR_SILVER_CROSS=156

while OpenGFX graphics gives
Closebox dimension=12x14, STR_BLACK_CROSS=155 STR_SILVER_CROSS=156

The OpenGFX closebox string is 1 pixel wider, and since r16798 cannot be printed anymore since all additional room for printing has been removed with the WD_CLOSEBOX_* constants. The program replaces the X with "..." to denote that the string was chopped which is what you see in 'close_button.png'. This is confirmed by the fact that the X does get printed with the rail toolbar and the town directory window, which both have dynamically resizing widgets, and by the fact that the X gets printed again after removal of "- WD_CLOSEBOX_RIGHT" around line 528.
For comparison, I have made a closeup of the closebox at r16304 and r16825 for both graphics sets, see 'closebox_overview' (where the bottom right picture was obtained after the hack discussed above.

As for solutions, there seem to exist at least 3 directions which are not mutually exclusive:
- Wait for all windows to be using nested widgets.
- Reduce the width of the X in the opengfx set.
- Remove the " - WD_CLOSEBOX_RIGHT" from the closebox rendering function. In this case however, the closebox does look weirdly placed imho.
Note that the last option does not affect the nested widgets, as around line 1987, the constant does get used to compute the correct width of the closebox.
Comment by Ammler (Ammler) - Thursday, 23 July 2009, 19:15 GMT
As of revision r145 of OpenGFX, I reduced the close-x 1px on right and bottom, so it should fit again old windows. (and new) (Download:
If the new x is ok, no further action is needed in that case. :-)