MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawSetting

Method DrawSetting

src/cheat_gui.cpp:338–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336 }
337
338 void DrawSetting(const Rect r, const SettingDesc *desc) const
339 {
340 const IntSettingDesc *sd = desc->AsIntSetting();
341 int state = this->clicked_setting == sd ? this->clicked : 0;
342
343 bool rtl = _current_text_dir == TD_RTL;
344
345 Rect buttons = r.WithWidth(SETTING_BUTTON_WIDTH, rtl);
346 Rect text = r.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
347 buttons.top += (r.Height() - SETTING_BUTTON_HEIGHT) / 2;
348 text.top += (r.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
349
350 /* We do not allow changes of some items when we are a client in a network game */
351 bool editable = sd->IsEditable();
352
353 auto [min_val, max_val] = sd->GetRange();
354 int32_t value = sd->Read(&GetGameSettings());
355 if (sd->IsBoolSetting()) {
356 /* Draw checkbox for boolean-value either on/off */
357 DrawBoolButton(buttons.left, buttons.top, COLOUR_YELLOW, COLOUR_GREY, value != 0, editable);
358 } else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
359 /* Draw [v] button for settings of an enum-type */
360 DrawDropDownButton(buttons.left, buttons.top, COLOUR_YELLOW, state != 0, editable);
361 } else {
362 /* Draw [<][>] boxes for settings of an integer-type */
363 DrawArrowButtons(buttons.left, buttons.top, COLOUR_YELLOW, state,
364 editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
365 }
366 auto [param1, param2] = sd->GetValueParams(value);
367 DrawString(text.left, text.right, text.top, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), TC_LIGHT_BLUE);
368 }
369
370 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
371 {

Callers

nothing calls this directly

Calls 15

GetCharacterHeightFunction · 0.85
DrawBoolButtonFunction · 0.85
DrawDropDownButtonFunction · 0.85
DrawArrowButtonsFunction · 0.85
AsIntSettingMethod · 0.80
WithWidthMethod · 0.80
IndentMethod · 0.80
TestMethod · 0.80
GetTitleMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70
HeightMethod · 0.45

Tested by

no test coverage detected