public Rect CreateBoundingBox(long start, long end, HexBoxDisplaySection section) { var firstRow = start >> 4; var lastRow = end >> 4; long firstColumn; long lastColumn; if (firstRow == lastRow) { firstColumn = start & 0xF; lastColumn = end & 0xF; } else { firstColumn = 0x0; lastColumn = 0xF; } return(CreateSelectionRectangleFromCells(firstRow, firstColumn, lastRow, lastColumn, section)); }
public Geometry CreateSelectionGeometryFromByteRange(long start, long end, HexBoxDisplaySection section) { var firstLine = start >> 4; var lastLine = end >> 4; if (firstLine == lastLine) { return(new RectangleGeometry(CreateSelectionRectangleFromCells(firstLine, start & 0xF, lastLine, end & 0xF, section))); } Geometry lead; Geometry body; Geometry trail; if ((start & 0xF) == 0) { lead = null; } else { lead = new RectangleGeometry(CreateSelectionRectangleFromCells(firstLine, start & 0xF, firstLine, 0xF, section)); firstLine++; } if ((end & 0xF) == 0xF) { trail = null; } else { trail = new RectangleGeometry(CreateSelectionRectangleFromCells(lastLine, 0, lastLine, end & 0xF, section)); lastLine--; } if (lastLine < firstLine) { if (lead == null) { return(trail); } if (trail == null) { return(lead); } return(new CombinedGeometry(GeometryCombineMode.Union, lead, trail)); } body = new RectangleGeometry(CreateSelectionRectangleFromCells(firstLine, 0, lastLine, 0xF, section)); if (lead != null) { body = new CombinedGeometry(GeometryCombineMode.Union, lead, body); } if (trail != null) { body = new CombinedGeometry(GeometryCombineMode.Union, body, trail); } return(body); }
Rect CreateSelectionRectangleFromCells(long firstRow, long firstColumn, long lastRow, long lastColumn, HexBoxDisplaySection section) { double left, right; switch (section) { case HexBoxDisplaySection.Byte: left = _columnPositions[ByteSectionIndex + (firstColumn << 1)]; right = _columnPositions[ByteSectionIndex + 1 + (lastColumn << 1)] + CellWidth; break; case HexBoxDisplaySection.Char: left = _columnPositions[CharSectionIndex + firstColumn]; right = _columnPositions[CharSectionIndex + lastColumn] + CellWidth; break; default: throw new ArgumentOutOfRangeException(nameof(section)); } return(new Rect( left, firstRow * CellHeight, right - left, (lastRow - firstRow + 1) * CellHeight)); }