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

Function DrawCaption

src/widget.cpp:736–753  ·  view source on GitHub ↗

* Draw a caption bar. * @param r Rectangle of the bar. * @param colour Colour of the window. * @param owner 'Owner' of the window. * @param text_colour Colour of the text. * @param str Text to draw in the bar. * @param align Alignment of the text. * @param fs Font size of the text. */

Source from the content-addressed store, hash-verified

734 * @param fs Font size of the text.
735 */
736void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
737{
738 bool company_owned = owner < MAX_COMPANIES;
739
740 DrawFrameRect(r, colour, FrameFlag::BorderOnly);
741 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
742 DrawFrameRect(ir, colour, company_owned ? FrameFlags{FrameFlag::Lowered, FrameFlag::Darkened, FrameFlag::BorderOnly} : FrameFlags{FrameFlag::Lowered, FrameFlag::Darkened});
743
744 if (company_owned) {
745 GfxFillRect(ir.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(_company_colours[owner], SHADE_NORMAL));
746 }
747
748 if (str.empty()) return;
749
750 Dimension d = GetStringBoundingBox(str);
751 Point p = GetAlignedPosition(r, d, align);
752 DrawString(r.left + WidgetDimensions::scaled.captiontext.left, r.right - WidgetDimensions::scaled.captiontext.left, p.y, str, text_colour, align, false, fs);
753}
754
755/**
756 * Draw a button with a dropdown (#WWT_DROPDOWN and #NWID_BUTTON_DROPDOWN).

Callers 2

DrawWidgetMethod · 0.85
DrawMethod · 0.85

Calls 8

GetColourGradientFunction · 0.85
GetStringBoundingBoxFunction · 0.85
GetAlignedPositionFunction · 0.85
ShrinkMethod · 0.80
DrawFrameRectFunction · 0.70
GfxFillRectFunction · 0.70
DrawStringFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected