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

Method GetCharAtPosition

src/misc_gui.cpp:851–870  ·  view source on GitHub ↗

* Get the character that is rendered at a position. * @param w Window the edit box is in. * @param wid Widget index. * @param pt Position to test. * @return Index of the character position or -1 if no character is at the position. */

Source from the content-addressed store, hash-verified

849 * @return Index of the character position or -1 if no character is at the position.
850 */
851ptrdiff_t QueryString::GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
852{
853 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
854
855 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
856
857 bool rtl = _current_text_dir == TD_RTL;
858 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
859 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
860
861 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
862
863 if (!IsInsideMM(pt.y, r.top, r.bottom)) return -1;
864
865 /* Clamp caret position to be inside our current width. */
866 const Textbuf *tb = &this->text;
867 r = ScrollEditBoxTextRect(r, *tb);
868
869 return ::GetCharAtPosition(tb->GetText(), pt.x - r.left);
870}
871
872void QueryString::ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed)
873{

Callers 2

GetHyperlinkMethod · 0.45

Calls 9

GetScaledSpriteSizeFunction · 0.85
IsInsideMMFunction · 0.85
ScrollEditBoxTextRectFunction · 0.85
GetCharAtPositionFunction · 0.85
HorizontalMethod · 0.80
ShrinkMethod · 0.80
IndentMethod · 0.80
GetCurrentRectMethod · 0.80
GetTextMethod · 0.45

Tested by

no test coverage detected