From d95a9c61604b290557c28fd82a4bb8404bc57eef Mon Sep 17 00:00:00 2001 From: Juanjo Date: Sat, 27 Jul 2013 22:04:33 +0000 Subject: [PATCH] Add a setting for automatically set min sizing values. --- src/cheat_gui.cpp | 9 ++--- src/gfx.cpp | 2 ++ src/industry_gui.cpp | 2 +- src/lang/english.txt | 2 ++ src/misc_gui.cpp | 4 ++- src/settings_gui.h | 4 +-- src/settings_type.h | 1 + src/table/misc_settings.ini | 5 +++ src/window.cpp | 72 +++++++++++++++++++++++++++++++++++++ src/window_func.h | 1 + 10 files changed, 94 insertions(+), 8 deletions(-) diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 01ea1a488e..db6102476e 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -287,7 +287,7 @@ struct CheatWindow : Window { { const NWidgetBase *wid = this->GetWidget(WID_C_PANEL); - if ((pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) % this->line_height > SETTING_BUTTON_HEIGHT) return; + if ((pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) % this->line_height > (uint)SETTING_BUTTON_HEIGHT) return; uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / this->line_height; uint x = pt.x - wid->pos_x; @@ -300,7 +300,7 @@ struct CheatWindow : Window { int value = (int32)ReadValue(ce->variable, ce->type); int oldvalue = value; - if (btn == CHT_CHANGE_DATE && x >= 20 + SETTING_BUTTON_WIDTH) { + if (btn == CHT_CHANGE_DATE && x >= (20 + (uint)SETTING_BUTTON_WIDTH)) { /* Click at the date text directly. */ SetDParam(0, value); ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); @@ -320,10 +320,11 @@ struct CheatWindow : Window { default: /* Take whatever the function returns */ - value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1); + bool clicked_right = x >= 20 + (uint)(SETTING_BUTTON_WIDTH / 2); + value = ce->proc(value + (clicked_right ? 1 : -1), clicked_right ? 1 : -1); /* The first cheat (money), doesn't return a different value. */ - if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0); + if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + (clicked_right != rtl ? 1 : 0); break; } diff --git a/src/gfx.cpp b/src/gfx.cpp index 13a0d4b8c8..01f29b9fb9 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1165,6 +1165,8 @@ void ScreenSizeChanged() /* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ _cursor.visible = false; + + CheckWindowMinSizings(); } void UndrawMouseCursor() diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index c14265c087..45a62a7fd3 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -840,7 +840,7 @@ public: case EA_RATE: if (pt.y >= this->production_offset_y) { - if ((pt.y - this->production_offset_y) % GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL) > SETTING_BUTTON_HEIGHT) break;; + if ((pt.y - this->production_offset_y) % GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL) > (uint)SETTING_BUTTON_HEIGHT) break;; int row = (pt.y - this->production_offset_y) / GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); for (uint j = 0; j < lengthof(i->produced_cargo); j++) { diff --git a/src/lang/english.txt b/src/lang/english.txt index f1ef46ccf9..c6f76f5cd0 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -972,6 +972,8 @@ STR_GAME_OPTIONS_BASE_MUSIC_STATUS :{RED}{NUM} corr STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP :{BLACK}Additional information about the base music set STR_ERROR_FULLSCREEN_FAILED :{WHITE}Fullscreen mode failed +STR_ERROR_RESET_WINDOWS :{WHITE}All windows have been reseted... +STR_ERROR_AUTOMATIC_SIZING :{WHITE}Sizes of buttons and fonts have changed # Custom currency window diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 62838285a2..d0075fe038 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -631,6 +631,8 @@ static WindowDesc _tool_tips_desc( _nested_tooltips_widgets, lengthof(_nested_tooltips_widgets) ); +uint _tooltip_width = 194; + /** Window for displaying a tooltip. */ struct TooltipsWindow : public Window { @@ -679,7 +681,7 @@ struct TooltipsWindow : public Window /* There is only one widget. */ for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]); - size->width = min(GetStringBoundingBox(this->string_id).width, 194); + size->width = min(GetStringBoundingBox(this->string_id).width, _tooltip_width); size->height = GetStringHeight(this->string_id, size->width); /* Increase slightly to have some space around the box. */ diff --git a/src/settings_gui.h b/src/settings_gui.h index 2ca418b11f..bb2a1ecfe0 100644 --- a/src/settings_gui.h +++ b/src/settings_gui.h @@ -14,8 +14,8 @@ #include "gfx_type.h" -static const int SETTING_BUTTON_WIDTH = 20; ///< Width of setting buttons -static const int SETTING_BUTTON_HEIGHT = 10; ///< Height of setting buttons +extern int SETTING_BUTTON_WIDTH; ///< Width of setting buttons +extern int SETTING_BUTTON_HEIGHT; ///< Height of setting buttons void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right); void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable); diff --git a/src/settings_type.h b/src/settings_type.h index 175ce651cf..f87c6bf354 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -79,6 +79,7 @@ struct GUISettings { bool vehicle_income_warn; ///< if a vehicle isn't generating income, show a warning uint min_button; ///< min size of most button widgets uint min_step; ///< min size of scrollbar/dropdown elements + bool manage_min_sizing; ///< automatically set min_button and min_step bool show_finances; ///< show finances at end of year bool sg_new_nonstop; ///< ttdpatch compatible nonstop handling read from pre v93 savegames bool new_nonstop; ///< ttdpatch compatible nonstop handling diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 0b02e69b8d..fd0207c4f3 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -228,6 +228,11 @@ min = 0 max = 100 cat = SC_EXPERT +[SDTG_BOOL] +name = ""manage_min_sizing"" +var = _settings_client.gui.manage_min_sizing +def = false + [SDTG_VAR] name = ""min_step_size"" type = SLE_UINT diff --git a/src/window.cpp b/src/window.cpp index 8f97693f60..710a9f4140 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -36,6 +36,14 @@ #include "error.h" #include "game/game.hpp" #include "video/video_driver.hpp" +#include "settings_gui.h" +#include "fontcache.h" +#include "error.h" +#include "station_base.h" +#include "waypoint_base.h" +#include "command_func.h" + +#include "table/strings.h" /** Values for _settings_client.gui.auto_scrolling */ enum ViewportAutoscrolling { @@ -1785,6 +1793,70 @@ Window *FindWindowFromPt(int x, int y) return NULL; } +int SETTING_BUTTON_WIDTH = 20; +int SETTING_BUTTON_HEIGHT = 10; + +/** + * Set button size of settings. If automatic sizing is also enabled, it also sets + * the sizing of buttons, scrollbars and font size (recommend restart). + * @todo Check if it can be moved to another file, so we do not need to include error, string and fontcache headers. + * @todo Fix magic numbers 16/18/20/30/32 + */ +void CheckWindowMinSizings() +{ + if (_settings_client.gui.manage_min_sizing) { + /* Fill the min sizing values for the current resolution. */ + uint swap_x = 32; // in longest border, let main toolbar to have 30 buttons. + uint swap_y = 16; // if short border, let main toolbar have 16/18/20 buttons..) + if (_cur_resolution.width < _cur_resolution.height) Swap(swap_x, swap_y); + _settings_client.gui.min_button = min(_cur_resolution.width / swap_x, _cur_resolution.height / swap_y); + _settings_client.gui.min_step = _settings_client.gui.min_button * 3 / 4; + } + + SETTING_BUTTON_HEIGHT = max(GetMinSizing(NWST_STEP) - 10, 10); + SETTING_BUTTON_WIDTH = 2 * SETTING_BUTTON_HEIGHT; + + extern uint _tooltip_width; + _tooltip_width = max(194, 10 * _settings_client.gui.min_button); + + if (!_settings_client.gui.manage_min_sizing) return; + + _freetype.large.size = _settings_client.gui.min_button; + _freetype.medium.size = max(_settings_client.gui.min_step * 2 / 3, 10U); + _freetype.mono.size = _freetype.medium.size; + _freetype.small.size = max(_freetype.medium.size * 2 / 3, 8U); + + InitFreeType(true); + CheckForMissingGlyphs(); + + if (_z_front_window == NULL) return; + + DeleteAllNonVitalWindows(); + + switch (_game_mode) { + default: break; + case GM_MENU: + DeleteWindowById(WC_SELECT_GAME, 0); + extern void ShowSelectGameWindow(); + ShowSelectGameWindow(); + break; + + case GM_NORMAL: + case GM_EDITOR: { + Station *st; + FOR_ALL_STATIONS(st) { st->UpdateVirtCoord(); } + Waypoint *wp; + FOR_ALL_WAYPOINTS(wp) { wp->UpdateVirtCoord(); } + + HideVitalWindows(); + ShowVitalWindows(); + break; + } + } + + ShowErrorMessage(STR_ERROR_RESET_WINDOWS, STR_ERROR_AUTOMATIC_SIZING, WL_WARNING); +} + /** * (re)initialize the windowing system */ diff --git a/src/window_func.h b/src/window_func.h index 453b889789..a0fff7c098 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -29,6 +29,7 @@ int PositionNetworkChatWindow(Window *w); int GetMainViewTop(); int GetMainViewBottom(); +void CheckWindowMinSizings(); void InitWindowSystem(); void UnInitWindowSystem(); void ResetWindowSystem();