* 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. */
| 380 | * @param fs Font size of the text. |
| 381 | */ |
| 382 | static 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. |
no test coverage detected