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

Function DrawFrame

src/widget.cpp:601–646  ·  view source on GitHub ↗

* Draw a frame widget. * @param r Rectangle of the frame. * @param colour Colour of the frame. * @param text_colour Colour of the text. * @param str Text of the frame. * @param align Alignment of the text in the frame. * @param fs Font size of the text. */

Source from the content-addressed store, hash-verified

599 * @param fs Font size of the text.
600 */
601static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
602{
603 int x2 = r.left; // by default the left side is the left side of the widget
604
605 if (!str.empty()) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align, false, fs);
606
607 PixelColour c1 = GetColourGradient(colour, SHADE_DARK);
608 PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST);
609
610 /* If the frame has text, adjust the top bar to fit half-way through */
611 Rect inner = r.Shrink(ScaleGUITrad(1));
612 if (!str.empty()) inner.top = r.top + GetCharacterHeight(FS_NORMAL) / 2;
613
614 Rect outer = inner.Expand(WidgetDimensions::scaled.bevel);
615 Rect inside = inner.Shrink(WidgetDimensions::scaled.bevel);
616
617 if (_current_text_dir == TD_LTR) {
618 /* Line from upper left corner to start of text */
619 GfxFillRect(outer.left, outer.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
620 GfxFillRect(inner.left, inner.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
621
622 /* Line from end of text to upper right corner */
623 GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
624 GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
625 } else {
626 /* Line from upper left corner to start of text */
627 GfxFillRect(outer.left, outer.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
628 GfxFillRect(inner.left, inner.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
629
630 /* Line from end of text to upper right corner */
631 GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
632 GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
633 }
634
635 /* Line from upper left corner to bottom left corner */
636 GfxFillRect(outer.left, inner.top, inner.left - 1, inner.bottom, c1);
637 GfxFillRect(inner.left, inside.top, inside.left - 1, inside.bottom, c2);
638
639 /* Line from upper right corner to bottom right corner */
640 GfxFillRect(inside.right + 1, inner.top, inner.right, inside.bottom, c1);
641 GfxFillRect(inner.right + 1, outer.top, outer.right, inner.bottom, c2);
642
643 /* Line from bottom left corner to bottom right corner */
644 GfxFillRect(inner.left, inside.bottom + 1, inner.right, inner.bottom, c1);
645 GfxFillRect(outer.left, inner.bottom + 1, outer.right, outer.bottom, c2);
646}
647
648/**
649 * Draw a shade box.

Callers 1

DrawMethod · 0.85

Calls 8

GetColourGradientFunction · 0.85
GetCharacterHeightFunction · 0.85
ShrinkMethod · 0.80
ExpandMethod · 0.80
DrawStringFunction · 0.70
ScaleGUITradFunction · 0.70
GfxFillRectFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected