Add a setting for automatically set min sizing values.
This commit is contained in:
@@ -287,7 +287,7 @@ struct CheatWindow : Window {
|
||||
{
|
||||
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int>(GetMinSizing(NWST_STEP) - 10, 10);
|
||||
SETTING_BUTTON_WIDTH = 2 * SETTING_BUTTON_HEIGHT;
|
||||
|
||||
extern uint _tooltip_width;
|
||||
_tooltip_width = max<uint>(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
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ int PositionNetworkChatWindow(Window *w);
|
||||
int GetMainViewTop();
|
||||
int GetMainViewBottom();
|
||||
|
||||
void CheckWindowMinSizings();
|
||||
void InitWindowSystem();
|
||||
void UnInitWindowSystem();
|
||||
void ResetWindowSystem();
|
||||
|
||||
Reference in New Issue
Block a user