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

Method DrawWidget

src/newgrf_gui.cpp:2061–2083  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2059 }
2060
2061 void DrawWidget(const Rect &r, WidgetID widget) const override
2062 {
2063 switch (widget) {
2064 case WID_SVP_PRESET_LIST: {
2065 const Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
2066 GfxFillRect(br, PC_BLACK);
2067
2068 uint step_height = this->GetWidget<NWidgetBase>(WID_SVP_PRESET_LIST)->resize_y;
2069 int offset_y = (step_height - GetCharacterHeight(FS_NORMAL)) / 2;
2070 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
2071
2072 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->presets);
2073 for (auto it = first; it != last; ++it) {
2074 int row = static_cast<int>(std::distance(std::begin(this->presets), it));
2075 if (row == this->selected) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
2076
2077 DrawString(tr.left, tr.right, tr.top + offset_y, *it, (row == this->selected) ? TC_WHITE : TC_SILVER);
2078 tr.top += step_height;
2079 }
2080 break;
2081 }
2082 }
2083 }
2084
2085 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2086 {

Callers

nothing calls this directly

Calls 7

GetCharacterHeightFunction · 0.85
ShrinkMethod · 0.80
GfxFillRectFunction · 0.70
DrawStringFunction · 0.70
beginFunction · 0.50

Tested by

no test coverage detected