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

Method GetBoundingRect

src/misc_gui.cpp:821–842  ·  view source on GitHub ↗

* Get the bounding rectangle for a range of the query string. * @param w Window the edit box is in. * @param wid Widget index. * @param from Start of the string range. * @param to End of the string range. * @return Rectangle encompassing the string range, relative to the window. */

Source from the content-addressed store, hash-verified

819 * @return Rectangle encompassing the string range, relative to the window.
820 */
821Rect QueryString::GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const
822{
823 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
824
825 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
826
827 bool rtl = _current_text_dir == TD_RTL;
828 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
829 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
830
831 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
832
833 /* Clamp caret position to be inside our current width. */
834 const Textbuf *tb = &this->text;
835 r = ScrollEditBoxTextRect(r, *tb);
836
837 /* Get location of first and last character. */
838 const auto p1 = GetCharPosInString(tb->GetText(), from, FS_NORMAL);
839 const auto p2 = from != to ? GetCharPosInString(tb->GetText(), to, FS_NORMAL) : p1;
840
841 return r.WithX(Clamp(r.left + p1.left, r.left, r.right), Clamp(r.left + p2.right, r.left, r.right));
842}
843
844/**
845 * Get the character that is rendered at a position.

Callers 1

GetTextBoundingRectMethod · 0.80

Calls 10

GetScaledSpriteSizeFunction · 0.85
ScrollEditBoxTextRectFunction · 0.85
GetCharPosInStringFunction · 0.85
ClampFunction · 0.85
HorizontalMethod · 0.80
ShrinkMethod · 0.80
IndentMethod · 0.80
GetCurrentRectMethod · 0.80
WithXMethod · 0.80
GetTextMethod · 0.45

Tested by

no test coverage detected