[Wgui-cvs] wgui/src wg_editbox.cpp,1.93,1.94
Status: Beta
Brought to you by:
greenwire
|
From: Rob W. <gre...@us...> - 2004-09-01 18:57:41
|
Update of /cvsroot/wgui/wgui/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14753/src Modified Files: wg_editbox.cpp Log Message: Fixed a small bug in the drag selection for edit boxes. Index: wg_editbox.cpp =================================================================== RCS file: /cvsroot/wgui/wgui/src/wg_editbox.cpp,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** wg_editbox.cpp 22 Jul 2004 21:17:25 -0000 1.93 --- wg_editbox.cpp 1 Sep 2004 18:57:31 -0000 1.94 *************** *** 137,140 **** --- 137,172 ---- + std::string::size_type CEditBox::GetIndexFromPoint(const CPoint& Point) const // virtual + { + CPoint Offset; + std::vector<CRect> CharRects; + m_pRenderedString->GetMetrics(0, &Offset, &CharRects); + CRect SubRect(m_WindowRect.SizeRect()); + SubRect.Grow(-3); + std::string::size_type index = 0; + CPoint BoundedPoint = Point; + if (BoundedPoint.XPos() < SubRect.Left()) { + BoundedPoint.SetX(SubRect.Left()); + } + if (BoundedPoint.XPos() > SubRect.Right()) { + BoundedPoint.SetX(SubRect.Right()); + } + if (!CharRects.empty()) + { + int xDelta = abs(BoundedPoint.XPos() - (CharRects.front().Left() + Offset.XPos() + SubRect.Left())); + for (unsigned int i = 0; i < m_pRenderedString->GetLength(); ++i) + { + if (abs(BoundedPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)) < xDelta) + { + xDelta = abs(BoundedPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)); + index = i + 1; + } + } + } + + return index; + } + + void CEditBox::Draw(void) const { *************** *** 289,312 **** if (!fSkipCursorPositioning) { ! CPoint Offset; ! std::vector<CRect> CharRects; ! m_pRenderedString->GetMetrics(0, &Offset, &CharRects); ! CRect SubRect(m_WindowRect.SizeRect()); ! SubRect.Grow(-3); ! ! m_SelStart = 0; ! if (!CharRects.empty()) ! { ! int xDelta = abs(WindowPoint.XPos() - (CharRects.front().Left() + Offset.XPos() + SubRect.Left())); ! for (unsigned int i = 0; i < m_pRenderedString->GetLength(); ++i) ! { ! if (abs(WindowPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)) < xDelta) ! { ! xDelta = abs(WindowPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)); ! m_SelStart = i + 1; ! } ! } ! } ! m_DragStart = m_SelStart; m_SelLength = 0; --- 321,325 ---- if (!fSkipCursorPositioning) { ! m_SelStart = GetIndexFromPoint(WindowPoint); m_DragStart = m_SelStart; m_SelLength = 0; *************** *** 370,390 **** if (m_bMouseDown) { ! CPoint Offset; ! std::vector<CRect> CharRects; ! m_pRenderedString->GetMetrics(0, &Offset, &CharRects); ! ! std::string::size_type CursorPos = 0; ! if (!CharRects.empty()) ! { ! int xDelta = abs(WindowPoint.XPos() - (CharRects.front().Left() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)); ! for (unsigned int i = 0; i < m_pRenderedString->GetLength(); ++i) ! { ! if (abs(WindowPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)) < xDelta) ! { ! xDelta = abs(WindowPoint.XPos() - (CharRects.at(i).Right() + Offset.XPos() + SubRect.Left() + m_ScrollOffset)); ! CursorPos = i + 1; ! } ! } ! } if (CursorPos < m_DragStart) --- 383,387 ---- if (m_bMouseDown) { ! std::string::size_type CursorPos = GetIndexFromPoint(WindowPoint); if (CursorPos < m_DragStart) |