Пример #1
0
        public void Write(ulong offset, byte[] array, long index, int count)
        {
            if (count <= 0)
            {
                return;
            }
            stream.Write(offset, array, index, count);

            var h = OnDocumentModified;

            if (h != null)
            {
                h(this, new HexDocumentModifiedEventArgs(offset, NumberUtils.AddUInt64(offset, (ulong)count - 1)));
            }
        }
Пример #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (hexBox.Selection == null || hexBox.VisibleBytesPerLine < 1)
            {
                return;
            }

            ulong selStart     = hexBox.Selection.Value.StartOffset;
            ulong selEnd       = hexBox.Selection.Value.EndOffset;
            int   lines        = hexBox.VisibleLinesPerPage;
            ulong bpl          = (ulong)hexBox.VisibleBytesPerLine;
            ulong visibleStart = hexBox.TopOffset;
            ulong visibleEnd   = NumberUtils.AddUInt64(NumberUtils.AddUInt64(visibleStart, NumberUtils.MulUInt64(bpl, NumberUtils.SubUInt64((ulong)lines, 1))), NumberUtils.SubUInt64(bpl, 1));

            if (selStart > visibleEnd || selEnd < visibleStart)
            {
                return;
            }

            ulong  offset    = Math.Max(selStart, visibleStart);
            ulong  endOffset = Math.Min(selEnd, visibleEnd);
            double x         = -hexBox.CharacterWidth * hexBox.LeftColumn;
            double y         = (offset - hexBox.TopOffset) / bpl * hexBox.CharacterHeight;
            var    path      = new PathGeometry();
            double hexByteX  = hexBox.GetHexByteColumnIndex() * hexBox.CharacterWidth;
            double asciiX    = hexBox.GetAsciiColumnIndex() * hexBox.CharacterWidth;

            while (offset <= endOffset)
            {
                ulong byteIndex = hexBox.GetLineByteIndex(offset);
                ulong count     = Math.Min(bpl - byteIndex, endOffset - offset + 1);

                double dx      = byteIndex * hexBox.CharacterWidth;
                var    rectGeo = new RectangleGeometry(new Rect(x + dx * 3 + hexByteX + hexBox.CharacterWidth, y, count * hexBox.CharacterWidth * 3 - hexBox.CharacterWidth, hexBox.CharacterHeight));
                rectGeo.Freeze();
                path.AddGeometry(rectGeo);

                if (hexBox.ShowAscii)
                {
                    rectGeo = new RectangleGeometry(new Rect(x + dx + asciiX, y, count * hexBox.CharacterWidth, hexBox.CharacterHeight));
                    rectGeo.Freeze();
                    path.AddGeometry(rectGeo);
                }

                if (offset + bpl - byteIndex < offset)
                {
                    break;
                }
                offset += bpl - byteIndex;
                y      += hexBox.CharacterHeight;
            }

            path.Freeze();
            drawingContext.DrawGeometry(Background, null, path);
        }