private Point TextPositionToPoint(Position p) { Point pf = new Point (0, 0); Size sz = StringSize (((string)lines[p.Line]).Substring (0, p.Offset)); Size fullSz = StringSize ((string)lines[p.Line]); switch (Alignment) { case TextAlignment.Left: pf = new Point (clickPoint.X + sz.Width, clickPoint.Y + (sz.Height * p.Line)); break; case TextAlignment.Center: pf = new Point (clickPoint.X + (sz.Width - (fullSz.Width / 2)), clickPoint.Y + (sz.Height * p.Line)); break; case TextAlignment.Right: pf = new Point (clickPoint.X + (sz.Width - fullSz.Width), clickPoint.Y + (sz.Height * p.Line)); break; default: throw new System.ComponentModel.InvalidEnumArgumentException ("Invalid Alignment"); } return pf; }
private Position PointToTextPosition(Point pf) { int dx = pf.X - clickPoint.X; int dy = pf.Y - clickPoint.Y; int line = (int)Math.Floor (dy / (float)this.sizes[0].Height); if (line < 0) { line = 0; } else if (line >= lines.Count) { line = lines.Count - 1; } int offset = FindOffsetPosition (dx, (string)lines[line], line); Position p = new Position (line, offset); if (p.Offset >= ((string)lines[p.Line]).Length) { p.Offset = ((string)lines[p.Line]).Length; } return p; }
private int PositionToIndex(Position p) { int index = 0; for (int i = 0; i < p.Line; i++) index += StringToByteSize(lines[i]) + 1; index += StringToByteSize(lines[p.Line].Substring(0, p.Offset)); return index; }
public Point TextPositionToPoint(Position p) { int index = PositionToIndex (p); var rect = layout.IndexToPos (index); int x = Pango.Units.ToPixels (rect.X) + origin.X; int y = Pango.Units.ToPixels (rect.Y) + origin.Y; return new Point (x, y); }
public void SetCursorPosition(Position position) { linePos = position.Line; textPos = position.Offset; }
public void SetCursorPosition(Position position, bool clearSelection) { linePos = position.Line; textPos = position.Offset; if (clearSelection) selectionRelativeIndex = 0; }