private void RenderRowViewWithCursor( Graphics g, DocumentRowView view, float offset, int cursor, CharacterRange selectionRange) { for (int i = 0, last = view.parts.Length - 1; i <= last; ++i) { var atom = view.parts[i]; var atomRaw = view.partRaws[i]; if (i == last && cursor >= atom.range.Length) { cursor = atom.range.Length - 1; } var trio = intersectAtomWithSelection(atom.range, selectionRange); if (trio.first.Length > 0) { trio.first.First -= atom.range.First; var thisStyle = atom.style; var offsetChange = DrawStringPart(trio.first, g, atomRaw, thisStyle, offset).Width; cursor -= drawCursor(cursor, trio.first, offset, g, atomRaw, thisStyle); offset += offsetChange; } if (trio.second.Length > 0) { trio.second.First -= atom.range.First; var thisStyle = atom.style.Combine(selectionStyle); var offsetChange = DrawStringPart(trio.second, g, atomRaw, thisStyle, offset).Width; cursor -= drawCursor(cursor, trio.second, offset, g, atomRaw, thisStyle); offset += offsetChange; } if (trio.third.Length > 0) { trio.third.First -= atom.range.First; var thisStyle = atom.style; var offsetChange = DrawStringPart(trio.third, g, atomRaw, atom.style, offset).Width; cursor -= drawCursor(cursor, trio.third, offset, g, atomRaw, thisStyle); offset += offsetChange; } } renderStuff.LineFrame = offset; }
private void prepare(Graphics g, DocumentRowView view) { view.parts = document.getStylizedRow(view.row.Index); SizeF sum = SizeF.Empty; var partRawList = new List <string>(); var partSizeList = new List <SizeF>(); foreach (var atom in view.parts) { var atomSize = measure(g, view.row, atom); sum.Width += atomSize.Width; if (sum.Height < atomSize.Height) { sum.Height = atomSize.Height; } partRawList.Add(view.row.Raw.Substring(atom.range.First, atom.range.Length)); partSizeList.Add(atomSize); } view.partRaws = partRawList.ToArray(); view.partSizes = partSizeList.ToArray(); view.bounds.Size = sum; var prevView = getDocumentRowView(view.row.Index - 1); if (prevView != null) { view.bounds.Y = prevView.bounds.Bottom; } view.dirty = false; }
public Point GetNearestCaretPosition(Point viewScreenPoint) { if (Document == null) { return(Point.Empty); } PointF pt = viewScreenPoint; pt.X += renderStuff.LeftOffset; DocumentRowView candidate = null; for (int o = renderStuff.FirstRow; o <= renderStuff.LastRow && candidate == null; ++o) { DocumentRowView rowView = renderList[o]; if (rowView.bounds.Size.Height > pt.Y) { candidate = rowView; } pt.Y -= rowView.bounds.Size.Height; } if (candidate == null) { candidate = renderList[renderStuff.LastRow]; } StylizedRowElement atom = null; float partOffset = pt.X; for (int i = 0; i < candidate.partSizes.Length; ++i) { if (partOffset < candidate.partSizes[i].Width) { atom = candidate.parts[i]; break; } partOffset -= candidate.partSizes[i].Width; } if (atom == null) { atom = candidate.parts[candidate.parts.Length - 1]; } Point res = new Point(); res.Y = candidate.row.Index; res.X = findCharacterPositionInPart(candidate.row, atom, pt.X); return(res); }
private float findCharacterPositionOffset(DocumentRowView rowView, int letterOffset) { float result = 0; for (int i = 0; i < rowView.parts.Length && letterOffset > 0; ++i) { StylizedRowElement atom = rowView.parts[i]; if (atom.range.Length <= letterOffset) { result += rowView.partSizes[i].Width; } else { CharacterRange range = new CharacterRange(0, letterOffset); string test = rowView.row.Raw.Substring(range.First, range.Length); result += MeasureStringPart(range, test, atom.style).Size.Width; } letterOffset -= atom.range.Length; } return(result); }
private void RenderRowView( Graphics g, DocumentRowView view, float offset, CharacterRange selectionRange) { for (var i = 0; i < view.parts.Length; ++i) { var atom = view.parts[i]; var atomRaw = view.partRaws[i]; var trio = intersectAtomWithSelection(atom.range, selectionRange); if (trio.first.Length > 0) { trio.first.First -= atom.range.First; offset += DrawStringPart(trio.first, g, atomRaw, atom.style, offset).Width; } if (trio.second.Length > 0) { trio.second.First -= atom.range.First; Style thisStyle = atom.style.Combine(selectionStyle); offset += DrawStringPart(trio.second, g, atomRaw, thisStyle, offset).Width; } if (trio.third.Length > 0) { trio.third.First -= atom.range.First; offset += DrawStringPart(trio.third, g, atomRaw, atom.style, offset).Width; } } renderStuff.LineFrame = offset; }
private void RenderRowViewWithCursor( Graphics g, DocumentRowView view, float offset, int cursor, CharacterRange selectionRange) { for (int i = 0, last = view.parts.Length - 1; i <= last; ++i) { StylizedRowElement atom = view.parts[i]; string atomRaw = view.partRaws[i]; if (i == last && cursor >= atom.range.Length) { cursor = atom.range.Length - 1; } CharacterRangeTrio trio = intersectAtomWithSelection(atom.range, selectionRange); if (trio.first.Length > 0) { trio.first.First -= atom.range.First; Style thisStyle = atom.style; float offsetChange = DrawStringPart(trio.first, g, atomRaw, thisStyle, offset).Width; cursor -= drawCursor(cursor, trio.first, offset, g, atomRaw, thisStyle); offset += offsetChange; } if (trio.second.Length > 0) { trio.second.First -= atom.range.First; Style thisStyle = atom.style.combine(selectionStyle); float offsetChange = DrawStringPart(trio.second, g, atomRaw, thisStyle, offset).Width; cursor -= drawCursor(cursor, trio.second, offset, g, atomRaw, thisStyle); offset += offsetChange; } if (trio.third.Length > 0) { trio.third.First -= atom.range.First; Style thisStyle = atom.style; float offsetChange = DrawStringPart(trio.third, g, atomRaw, atom.style, offset).Width; cursor -= drawCursor(cursor, trio.third, offset, g, atomRaw, thisStyle); offset += offsetChange; } } renderStuff.LineFrame = offset; }
private void RenderRowView( Graphics g, DocumentRowView view, float offset, CharacterRange selectionRange) { for (int i = 0; i < view.parts.Length; ++i) { StylizedRowElement atom = view.parts[i]; string atomRaw = view.partRaws[i]; CharacterRangeTrio trio = intersectAtomWithSelection(atom.range, selectionRange); if (trio.first.Length > 0) { trio.first.First -= atom.range.First; offset += DrawStringPart(trio.first, g, atomRaw, atom.style, offset).Width; } if (trio.second.Length > 0) { trio.second.First -= atom.range.First; Style thisStyle = atom.style.combine(selectionStyle); offset += DrawStringPart(trio.second, g, atomRaw, thisStyle, offset).Width; } if (trio.third.Length > 0) { trio.third.First -= atom.range.First; offset += DrawStringPart(trio.third, g, atomRaw, atom.style, offset).Width; } } renderStuff.LineFrame = offset; }
private void prepare(Graphics g, DocumentRowView view) { view.parts = document.getStylizedRow(view.row.Index); SizeF sum = SizeF.Empty; List<string> partRawList = new List<string>(); List<SizeF> partSizeList = new List<SizeF>(); foreach (StylizedRowElement atom in view.parts) { SizeF atomSize = measure(g, view.row, atom); sum.Width += atomSize.Width; if (sum.Height < atomSize.Height) sum.Height = atomSize.Height; partRawList.Add(view.row.Raw.Substring(atom.range.First, atom.range.Length)); partSizeList.Add(atomSize); } view.partRaws = partRawList.ToArray(); view.partSizes = partSizeList.ToArray(); view.bounds.Size = sum; DocumentRowView prevView = getDocumentRowView(view.row.Index - 1); if (prevView != null) view.bounds.Y = prevView.bounds.Bottom; view.dirty = false; }
private float measureCaretLeftOffset() { DocumentRowView rowView = getDocumentRowView(Position.Y); return((rowView == null) ? 0 : findCharacterPositionOffset(rowView, Position.X)); }
private float findCharacterPositionOffset(DocumentRowView rowView, int letterOffset) { float result = 0; for (int i = 0; i < rowView.parts.Length && letterOffset > 0; ++i) { StylizedRowElement atom = rowView.parts[i]; if (atom.range.Length <= letterOffset) { result += rowView.partSizes[i].Width; } else { CharacterRange range = new CharacterRange(0, letterOffset); string test = rowView.row.Raw.Substring(range.First, range.Length); result += MeasureStringPart(range, test, atom.style).Size.Width; } letterOffset -= atom.range.Length; } return result; }