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

Method DrawWidget

src/script/script_gui.cpp:352–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350 }
351
352 void DrawWidget(const Rect &r, WidgetID widget) const override
353 {
354 if (widget != WID_SCRS_BACKGROUND) return;
355
356 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
357 bool rtl = _current_text_dir == TD_RTL;
358 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
359 Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
360
361 int y = r.top;
362 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
363 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
364
365 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
366 for (auto it = first; it != last; ++it) {
367 const ScriptConfigItem &config_item = **it;
368 int current_value = this->script_config->GetSetting(config_item.name);
369 bool editable = this->IsEditableItem(config_item);
370
371 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
372 DrawBoolButton(br.left, y + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, editable);
373 } else {
374 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
375 if (config_item.complete_labels) {
376 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, editable);
377 } else {
378 DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
379 }
380 }
381
382 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
383 y += this->line_height;
384 }
385 }
386
387 void OnPaint() override
388 {

Callers

nothing calls this directly

Calls 15

IsEditableItemMethod · 0.95
GetCharacterHeightFunction · 0.85
DrawBoolButtonFunction · 0.85
DrawDropDownButtonFunction · 0.85
DrawArrowButtonsFunction · 0.85
ShrinkMethod · 0.80
WithWidthMethod · 0.80
IndentMethod · 0.80
TestMethod · 0.80
beginFunction · 0.50
DrawStringFunction · 0.50

Tested by

no test coverage detected