1
0
Fork 0

(svn r25340) [1.3] -Backport from trunk:

- Fix: Loading only 8 bits into a 16 bit variable could cause endianness problems (r25337)
- Fix: Check for zero width space in translations and fail upon finding them [FS#5589] (r25326)
- Fix: [SDL] Keyboard input stopped working after fullscreen toggle [FS#5580] (r25318)
- Fix: Proper size-estimation for numbers with n digits, i.e. not assume a particular number is the widest [FS#5562] (r25314, r25313)
release/1.3
rubidium 2013-06-09 09:38:21 +00:00
parent 02fc90dfbd
commit 3b7a42bbc9
13 changed files with 46 additions and 17 deletions

View File

@ -889,7 +889,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
int count_width = 0; int count_width = 0;
if (show_count) { if (show_count) {
replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE); replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
SetDParamMaxDigits(0, 3); SetDParamMaxDigits(0, 3, FS_SMALL);
count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width; count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width;
} }

View File

@ -600,7 +600,7 @@ struct DepotWindow : Window {
uint min_height = 0; uint min_height = 0;
if (this->type == VEH_TRAIN) { if (this->type == VEH_TRAIN) {
SetDParamMaxValue(0, 1000); SetDParamMaxValue(0, 1000, 0, FS_SMALL);
SetDParam(1, 1); SetDParam(1, 1);
this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
} else { } else {

View File

@ -1621,6 +1621,24 @@ byte GetDigitWidth(FontSize size)
return width; return width;
} }
/**
* Determine the broadest digits for guessing the maximum width of a n-digit number.
* @param [out] front Broadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.)
* @param [out] next Broadest digit, including 0. (Use this digit for all digits, except the first one; or for numbers with only one digit.)
* @param size Font of the digit
*/
void GetBroadestDigit(uint *front, uint *next, FontSize size)
{
int width = -1;
for (char c = '9'; c >= '0'; c--) {
int w = GetCharacterWidth(size, c);
if (w > width) {
width = w;
*next = c - '0';
if (c != '0') *front = c - '0';
}
}
}
void ScreenSizeChanged() void ScreenSizeChanged()
{ {

View File

@ -150,6 +150,7 @@ bool ToggleFullScreen(bool fs);
/* gfx.cpp */ /* gfx.cpp */
byte GetCharacterWidth(FontSize size, uint32 key); byte GetCharacterWidth(FontSize size, uint32 key);
byte GetDigitWidth(FontSize size = FS_NORMAL); byte GetDigitWidth(FontSize size = FS_NORMAL);
void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
/** /**
* Get height of a character for a given font size. * Get height of a character for a given font size.

View File

@ -504,7 +504,7 @@ public:
} }
} else { } else {
/* Draw the label under the data point rather than on the grid line. */ /* Draw the label under the data point rather than on the grid line. */
SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment); SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL);
x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width; x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width;
} }

View File

@ -182,7 +182,7 @@ private:
} }
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROFIT].height); this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3); SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3, FS_SMALL);
this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_TINY_COMMA); this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_TINY_COMMA);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NUMBER].height); this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);

View File

@ -226,7 +226,7 @@ static const SaveLoad _old_station_desc[] = {
static uint16 _waiting_acceptance; static uint16 _waiting_acceptance;
static uint16 _cargo_source; static uint16 _cargo_source;
static uint32 _cargo_source_xy; static uint32 _cargo_source_xy;
static uint16 _cargo_days; static uint8 _cargo_days;
static Money _cargo_feeder_share; static Money _cargo_feeder_share;
static const SaveLoad _station_speclist_desc[] = { static const SaveLoad _station_speclist_desc[] = {

View File

@ -723,6 +723,7 @@ void StringReader::HandleString(char *str)
WChar c; WChar c;
Utf8Decode(&c, tmp); Utf8Decode(&c, tmp);
if (c <= 0x001F || // ASCII control character range if (c <= 0x001F || // ASCII control character range
c == 0x200B || // Zero width space
(c >= 0xE000 && c <= 0xF8FF) || // Private range (c >= 0xE000 && c <= 0xF8FF) || // Private range
(c >= 0xFFF0 && c <= 0xFFFF)) { // Specials range (c >= 0xFFF0 && c <= 0xFFFF)) { // Specials range
strgen_fatal("Unwanted UTF-8 character U+%04X in sequence '%s'", c, s); strgen_fatal("Unwanted UTF-8 character U+%04X in sequence '%s'", c, s);

View File

@ -96,28 +96,31 @@ void StringParameters::ShiftParameters(uint amount)
* @param max_value The biggest value which shall be displayed. * @param max_value The biggest value which shall be displayed.
* For the result only the number of digits of \a max_value matter. * For the result only the number of digits of \a max_value matter.
* @param min_count Minimum number of digits independent of \a max. * @param min_count Minimum number of digits independent of \a max.
* @param size Font of the number
*/ */
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count) void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
{ {
uint num_digits = 1; uint num_digits = 1;
while (max_value >= 10) { while (max_value >= 10) {
num_digits++; num_digits++;
max_value /= 10; max_value /= 10;
} }
SetDParamMaxDigits(n, max(min_count, num_digits)); SetDParamMaxDigits(n, max(min_count, num_digits), size);
} }
/** /**
* Set DParam n to some number that is suitable for string size computations. * Set DParam n to some number that is suitable for string size computations.
* @param n Index of the string parameter. * @param n Index of the string parameter.
* @param count Number of digits which shall be displayable. * @param count Number of digits which shall be displayable.
* @param size Font of the number
*/ */
void SetDParamMaxDigits(uint n, uint count) void SetDParamMaxDigits(uint n, uint count, FontSize size)
{ {
static const uint biggest_digit = 8; ///< Digit with the biggest string width. uint front, next;
uint64 val = biggest_digit; GetBroadestDigit(&front, &next, size);
uint64 val = count > 1 ? front : next;
for (; count > 1; count--) { for (; count > 1; count--) {
val = 10 * val + biggest_digit; val = 10 * val + next;
} }
SetDParam(n, val); SetDParam(n, val);
} }

View File

@ -155,8 +155,8 @@ static inline void SetDParam(uint n, uint64 v)
_global_string_params.SetParam(n, v); _global_string_params.SetParam(n, v);
} }
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0); void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
void SetDParamMaxDigits(uint n, uint count); void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
void SetDParamStr(uint n, const char *str); void SetDParamStr(uint n, const char *str);

View File

@ -200,7 +200,7 @@ struct TimetableWindow : Window {
{ {
switch (widget) { switch (widget) {
case WID_VT_ARRIVAL_DEPARTURE_PANEL: case WID_VT_ARRIVAL_DEPARTURE_PANEL:
SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR); SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width; this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width;
this->deparr_abbr_width = max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width); this->deparr_abbr_width = max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width);
size->width = WD_FRAMERECT_LEFT + this->deparr_abbr_width + 10 + this->deparr_time_width + WD_FRAMERECT_RIGHT; size->width = WD_FRAMERECT_LEFT + this->deparr_abbr_width + 10 + this->deparr_time_width + WD_FRAMERECT_RIGHT;

View File

@ -340,6 +340,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO);
ClaimMousePointer(); ClaimMousePointer();
SetupKeyboard();
} }
} }
/* Remember if we wanted a hwpalette. We can't reliably query /* Remember if we wanted a hwpalette. We can't reliably query
@ -649,15 +650,19 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
DEBUG(driver, 1, "SDL: using driver '%s'", buf); DEBUG(driver, 1, "SDL: using driver '%s'", buf);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
SetupKeyboard();
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_CALL SDL_EnableUNICODE(1);
_draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL;
return NULL; return NULL;
} }
void VideoDriver_SDL::SetupKeyboard()
{
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_CALL SDL_EnableUNICODE(1);
}
void VideoDriver_SDL::Stop() void VideoDriver_SDL::Stop()
{ {
SdlClose(SDL_INIT_VIDEO); SdlClose(SDL_INIT_VIDEO);

View File

@ -37,6 +37,7 @@ public:
private: private:
int PollEvent(); int PollEvent();
bool CreateMainSurface(uint w, uint h); bool CreateMainSurface(uint w, uint h);
void SetupKeyboard();
}; };
/** Factory for the SDL video driver. */ /** Factory for the SDL video driver. */