mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
If you resize the window so it's smaller than default the text might still not fit
This commit is contained in:
parent
1ea634fcba
commit
b1a830491a
30
src/gfx.cpp
30
src/gfx.cpp
@ -821,6 +821,36 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio
|
|||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates height of string (in pixels). The string is changed to a multiline string if needed.
|
||||||
|
* @param str string to check
|
||||||
|
* @param maxw maximum string width
|
||||||
|
* @return height of pixels of string when it is drawn
|
||||||
|
*/
|
||||||
|
int GetStringHeight(const char *str, int maxw)
|
||||||
|
{
|
||||||
|
char buffer[DRAW_STRING_BUFFER];
|
||||||
|
|
||||||
|
strecpy(buffer, str, lastof(buffer));
|
||||||
|
|
||||||
|
uint32 tmp = FormatStringLinebreaks(buffer, lastof(buffer), maxw);
|
||||||
|
|
||||||
|
return GetMultilineStringHeight(buffer, GB(tmp, 0, 16), FS_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate string bounding box for multi-line strings.
|
||||||
|
* @param str String to check.
|
||||||
|
* @param suggestion Suggested bounding box.
|
||||||
|
* @return Bounding box for the multi-line string, may be bigger than \a suggestion.
|
||||||
|
*/
|
||||||
|
Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion)
|
||||||
|
{
|
||||||
|
Dimension box = {suggestion.width, GetStringHeight(str, suggestion.width)};
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw string, possibly over multiple lines.
|
* Draw string, possibly over multiple lines.
|
||||||
*
|
*
|
||||||
|
@ -125,6 +125,7 @@ Dimension GetStringBoundingBox(StringID strid);
|
|||||||
uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL);
|
uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize start_fontsize = FS_NORMAL);
|
||||||
int GetStringHeight(StringID str, int maxw);
|
int GetStringHeight(StringID str, int maxw);
|
||||||
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
|
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
|
||||||
|
Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion);
|
||||||
void LoadStringWidthTable(bool monospace = false);
|
void LoadStringWidthTable(bool monospace = false);
|
||||||
|
|
||||||
void DrawDirtyBlocks();
|
void DrawDirtyBlocks();
|
||||||
|
@ -211,7 +211,17 @@ struct NewGRFParametersWindow : public Window {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NP_DESCRIPTION:
|
case WID_NP_DESCRIPTION:
|
||||||
size->height = max<uint>(size->height, FONT_HEIGHT_NORMAL * 4 + WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM);
|
/* Minimum size of 4 lines. The 500 is the default size of the window. */
|
||||||
|
Dimension suggestion = {500 - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT, FONT_HEIGHT_NORMAL * 4 + WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM};
|
||||||
|
for (uint i = 0; i < this->grf_config->param_info.Length(); i++) {
|
||||||
|
const GRFParameterInfo *par_info = this->grf_config->param_info[i];
|
||||||
|
if (par_info == NULL) continue;
|
||||||
|
const char *desc = GetGRFStringFromGRFText(par_info->desc);
|
||||||
|
if (desc == NULL) continue;
|
||||||
|
const Dimension d = GetStringMultiLineBoundingBox(desc, suggestion);
|
||||||
|
suggestion = maxdim(d, suggestion);
|
||||||
|
}
|
||||||
|
size->height = suggestion.height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user