summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:53 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:53 +0000
commit30867c487f17ca13744977c7873f4e1cf214fd33 (patch)
tree7b7c7bcf951dba613468a4431c0f7510be76180a /src/misc_gui.cpp
parente2ec0ddb030afd4e7bdf08d1a8f3cb9361388eae (diff)
downloadopenttd-30867c487f17ca13744977c7873f4e1cf214fd33.tar.xz
(svn r25691) -Add: [OSX] Support for mouse selection in the IME composition string.
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index b309693bf..d771f92ee 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -854,6 +854,39 @@ Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, co
return r;
}
+/**
+ * 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 Pointer to the character at the position or NULL if no character is at the position.
+ */
+const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const
+{
+ const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
+
+ assert((wi->type & WWT_MASK) == WWT_EDITBOX);
+
+ bool rtl = _current_text_dir == TD_RTL;
+ Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
+ int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
+
+ int left = wi->pos_x + (rtl ? clearbtn_width : 0);
+ int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
+
+ int top = wi->pos_y + WD_FRAMERECT_TOP;
+ int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
+
+ if (!IsInsideMM(pt.y, top, bottom)) return NULL;
+
+ /* Clamp caret position to be inside our current width. */
+ const Textbuf *tb = &this->text;
+ int delta = min(0, (right - left) - tb->pixels - 10);
+ if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
+
+ return ::GetCharAtPosition(tb->buf, pt.x - delta - left);
+}
+
void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
{
const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);