diff --git a/src/framework/graphics/font.h b/src/framework/graphics/font.h index c518b8d3..9580c20b 100644 --- a/src/framework/graphics/font.h +++ b/src/framework/graphics/font.h @@ -81,6 +81,7 @@ public: const Size *getGlyphsSize() const { return m_glyphsSize; } const TexturePtr& getTexture() const { return m_texture; } int getTopMargin() const { return m_topMargin; } + const Size& getGlyphSpacing() const { return m_glyphSpacing; } private: void calculateGlyphsWidthsAutomatically(const Size& glyphSize); diff --git a/src/framework/graphics/textarea.cpp b/src/framework/graphics/textarea.cpp index 44fee80a..691b0cdb 100644 --- a/src/framework/graphics/textarea.cpp +++ b/src/framework/graphics/textarea.cpp @@ -281,4 +281,17 @@ void TextArea::moveCursor(bool right) recalculate(); } - +int TextArea::getTextPos(Point pos) +{ + int textLength = m_text.length(); + dump << " get pos: " << pos << m_drawArea; + for(int i=0;igetTopMargin() + m_font->getGlyphSpacing().height()); + clickGlyphRect.addLeft(m_font->getGlyphSpacing().width()+1); + dump << clickGlyphRect; + if(m_glyphsCoords[i].contains(pos)) + return i; + } + return -1; +} diff --git a/src/framework/graphics/textarea.h b/src/framework/graphics/textarea.h index 75a0f3b2..8061f2d8 100644 --- a/src/framework/graphics/textarea.h +++ b/src/framework/graphics/textarea.h @@ -54,6 +54,8 @@ public: const std::string& getText() const { return m_text; } + int getTextPos(Point pos); + private: void recalculate(); diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index fb80a563..d23553f4 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -47,6 +47,10 @@ void UITextEdit::onInputEvent(const InputEvent& event) m_textArea.moveCursor(true); else if(event.keycode == KC_LEFT) m_textArea.moveCursor(false); + } else if(event.type == EV_MOUSE_LDOWN) { + + } else if(event.type == EV_MOUSE_LUP) { + dump << m_textArea.getTextPos(event.mousePos); } } diff --git a/src/framework/util/rect.h b/src/framework/util/rect.h index 5a609c5b..23c26e49 100644 --- a/src/framework/util/rect.h +++ b/src/framework/util/rect.h @@ -82,6 +82,11 @@ public: inline void setRect(T x, T y, T width, T height) { x1 = x; y1 = y; x2 = (x + width - 1); y2 = (y + height - 1); } inline void setCoords(int left, int top, int right, int bottom) { x1 = left; y1 = top; x2 = right; y2 = bottom; } + inline void addLeft(T add) { x1 -= add; } + inline void addTop(T add) { y1 -= add; } + inline void addRight(T add) { x2 += add; } + inline void addBottom(T add) { y2 += add; } + inline void translate(T x, T y) { x1 += x; y1 += y; x2 += x; y2 += y; } inline void translate(const TPoint &p) { x1 += p.x; y1 += p.y; x2 += p.x; y2 += p.y; } inline void moveTo(T x, T y) { x2 += x - x1; y2 += y - y1; x1 = x; y1 = y; } @@ -135,7 +140,7 @@ public: if(p.x < l || p.x > r) return false; } - int t, b; + T t, b; if(y2 < y1 - 1) { t = y2; b = y1;