* 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. */
| 849 | * @return Index of the character position or -1 if no character is at the position. |
| 850 | */ |
| 851 | ptrdiff_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 | |
| 872 | void QueryString::ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed) |
| 873 | { |
no test coverage detected