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

Method GetCaretPosition

src/misc_gui.cpp:793–811  ·  view source on GitHub ↗

* Get the current caret position. * @param w Window the edit box is in. * @param wid Widget index. * @return Top-left location of the caret, relative to the window. */

Source from the content-addressed store, hash-verified

791 * @return Top-left location of the caret, relative to the window.
792 */
793Point QueryString::GetCaretPosition(const Window *w, WidgetID wid) const
794{
795 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
796
797 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
798
799 bool rtl = _current_text_dir == TD_RTL;
800 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
801 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
802
803 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
804
805 /* Clamp caret position to be inside out current width. */
806 const Textbuf *tb = &this->text;
807 r = ScrollEditBoxTextRect(r, *tb);
808
809 Point pt = {r.left + tb->caretxoffs, r.top};
810 return pt;
811}
812
813/**
814 * Get the bounding rectangle for a range of the query string.

Callers

nothing calls this directly

Calls 6

GetScaledSpriteSizeFunction · 0.85
ScrollEditBoxTextRectFunction · 0.85
HorizontalMethod · 0.80
ShrinkMethod · 0.80
IndentMethod · 0.80
GetCurrentRectMethod · 0.80

Tested by

no test coverage detected