MCPcopy Create free account
hub / github.com/WheretIB/nullc / CursorToClient

Method CursorToClient

GUI/RichTextarea.cpp:1439–1455  ·  view source on GitHub ↗

Convert cursor position to local pixel coordinates

Source from the content-addressed store, hash-verified

1437
1438// Convert cursor position to local pixel coordinates
1439void TextareaData::CursorToClient(unsigned int xCursor, unsigned int yCursor, int &xPos, int &yPos)
1440{
1441 // Find the line where the cursor is placed
1442 AreaLine *curr = firstLine;
1443 for(unsigned int i = 0; i < yCursor; i++)
1444 curr = curr->next;
1445
1446 int posInChars = 0;
1447 // Find cursor position in characters
1448 for(unsigned int i = 0; i < xCursor; i++)
1449 posInChars += GetCharShift(curr->data[i].ch, posInChars);
1450
1451 // Start with padding, add position in pixels and subtract horizontal scroll value
1452 xPos = RichTextarea::padLeft + posInChars * RichTextarea::charWidth - shiftCharX * RichTextarea::charWidth;
1453 // Find Y local coordinate
1454 yPos = (yCursor - shiftCharY) * RichTextarea::charHeight + RichTextarea::charHeight / 2;
1455}
1456
1457// Convert local pixel coordinates to cursor position
1458// Position X coordinate is clamped when clampX is set

Callers

nothing calls this directly

Calls 1

GetCharShiftFunction · 0.85

Tested by

no test coverage detected