MCPcopy Create free account
hub / github.com/MyGUI/mygui / updateCursorPosition

Method updateCursorPosition

MyGUIEngine/src/MyGUI_EditBox.cpp:1822–1894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1820 }
1821
1822 void EditBox::updateCursorPosition()
1823 {
1824 if (mClientText == nullptr || getClientWidget() == nullptr)
1825 return;
1826
1827 // размер контекста текста
1828 IntSize textSize = mClientText->getTextSize();
1829
1830 // текущее смещение контекста текста
1831 IntPoint point = mClientText->getViewOffset();
1832 // расчетное смещение
1833 IntPoint offset = point;
1834
1835 // абсолютные координаты курсора
1836 IntRect cursor = mClientText->getCursorRect(mCursorPosition);
1837 cursor.right++;
1838
1839 // абсолютные координаты вью
1840 const IntRect& view = getClientWidget()->getAbsoluteRect();
1841
1842 // проверяем и показываем курсор
1843 if (!view.inside(cursor))
1844 {
1845 // горизонтальное смещение
1846 if (textSize.width > view.width())
1847 {
1848 if (cursor.left < view.left)
1849 {
1850 offset.left = point.left - (view.left - cursor.left);
1851 // добавляем смещение, только если курсор не перепрыгнет
1852 if ((float(view.width()) - EDIT_OFFSET_HORZ_CURSOR) > EDIT_OFFSET_HORZ_CURSOR)
1853 offset.left -= int(EDIT_OFFSET_HORZ_CURSOR);
1854 }
1855 else if (cursor.right > view.right)
1856 {
1857 offset.left = point.left + (cursor.right - view.right);
1858 // добавляем смещение, только если курсор не перепрыгнет
1859 if ((float(view.width()) - EDIT_OFFSET_HORZ_CURSOR) > EDIT_OFFSET_HORZ_CURSOR)
1860 offset.left += int(EDIT_OFFSET_HORZ_CURSOR);
1861 }
1862 }
1863
1864 // вертикальное смещение
1865 if (textSize.height > view.height())
1866 {
1867 int delta = 0;
1868 if (cursor.height() > view.height())
1869 {
1870 // if text is bigger than edit height then place it in center
1871 delta = ((cursor.bottom - view.bottom) - (view.top - cursor.top)) / 2;
1872 }
1873 else if (cursor.top < view.top)
1874 {
1875 delta = -(view.top - cursor.top);
1876 }
1877 else if (cursor.bottom > view.bottom)
1878 {
1879 delta = (cursor.bottom - view.bottom);

Callers

nothing calls this directly

Calls 7

getTextSizeMethod · 0.45
getViewOffsetMethod · 0.45
insideMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
setViewOffsetMethod · 0.45
setScrollPositionMethod · 0.45

Tested by

no test coverage detected