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

Function DrawImageTextButtons

src/widget.cpp:382–400  ·  view source on GitHub ↗

* Draw a button with image and rext. * @param r Rectangle of the button. * @param colour Colour of the button. * @param clicked Button is clicked. * @param img Image caption. * @param text_colour Colour of the text. * @param text Text caption. * @param align Alignment of the caption. * @param fs Font size of the text. */

Source from the content-addressed store, hash-verified

380 * @param fs Font size of the text.
381 */
382static inline void DrawImageTextButtons(const Rect &r, Colours colour, bool clicked, SpriteID img, TextColour text_colour, const std::string &text, StringAlignment align, FontSize fs)
383{
384 DrawFrameRect(r, colour, clicked ? FrameFlag::Lowered : FrameFlags{});
385
386 bool rtl = _current_text_dir == TD_RTL;
387 int image_width = img != 0 ? std::max<int>(GetSquareScaledSpriteSize(img).width, r.Shrink(WidgetDimensions::scaled.framerect).Height()) : 0;
388 Rect r_img = r.Shrink(WidgetDimensions::scaled.framerect).WithWidth(image_width, rtl);
389 Rect r_text = r.Shrink(WidgetDimensions::scaled.framerect).Indent(image_width + WidgetDimensions::scaled.hsep_wide, rtl);
390
391 if (img != 0) {
392 DrawSpriteIgnorePadding(img, PAL_NONE, r_img, SA_HOR_CENTER | (align & SA_VERT_MASK));
393 }
394
395 if (!text.empty()) {
396 Dimension d = GetStringBoundingBox(text, fs);
397 Point p = GetAlignedPosition(r_text, d, align);
398 DrawString(r_text.left, r_text.right, p.y, text, text_colour, align, false, fs);
399 }
400}
401
402/**
403 * Draw the label-part of a widget.

Callers 1

DrawMethod · 0.85

Calls 11

DrawSpriteIgnorePaddingFunction · 0.85
GetStringBoundingBoxFunction · 0.85
GetAlignedPositionFunction · 0.85
ShrinkMethod · 0.80
WithWidthMethod · 0.80
IndentMethod · 0.80
DrawFrameRectFunction · 0.70
DrawStringFunction · 0.70
HeightMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected