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

Function DrawButtonDropdown

src/widget.cpp:766–779  ·  view source on GitHub ↗

* Draw a button with a dropdown (#WWT_DROPDOWN and #NWID_BUTTON_DROPDOWN). * @param r Rectangle containing the widget. * @param colour Background colour of the widget. * @param clicked_button The button-part is clicked. * @param clicked_dropdown The drop-down part is clicked. * @param str Text of the button. * @param align Alignment of the t

Source from the content-addressed store, hash-verified

764 * @note Magic constants are also used in #NWidgetLeaf::ButtonHit.
765 */
766static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, std::string_view str, StringAlignment align)
767{
768 bool rtl = _current_text_dir == TD_RTL;
769
770 Rect text = r.Indent(NWidgetLeaf::dropdown_dimension.width, !rtl);
771 DrawFrameRect(text, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{});
772 if (!str.empty()) {
773 text = text.CentreToHeight(GetCharacterHeight(FS_NORMAL)).Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero);
774 DrawString(text, str, TC_BLACK, align);
775 }
776
777 Rect button = r.WithWidth(NWidgetLeaf::dropdown_dimension.width, !rtl);
778 DrawImageButtons(button, WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
779}
780
781/**
782 * Paint all widgets of a window.

Callers 1

DrawMethod · 0.85

Calls 9

GetCharacterHeightFunction · 0.85
DrawImageButtonsFunction · 0.85
IndentMethod · 0.80
ShrinkMethod · 0.80
CentreToHeightMethod · 0.80
WithWidthMethod · 0.80
DrawFrameRectFunction · 0.70
DrawStringFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected