protected override void DrawByte(DrawingContext drawingContext, byte bt, Brush foreground, Point startPoint)
        {
            var chs = ByteConverters.ByteToHexCharArray(bt);

            for (int chIndex = 0; chIndex < 2; chIndex++)
            {
#if NET451
                var text = new FormattedText(
                    chs[chIndex].ToString(), CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, TypeFace, FontSize,
                    foreground);
                startPoint.X += CharSize.Width * chIndex;
                drawingContext.DrawText(text,
                                        startPoint
                                        );
#endif
#if NET47
                var text = new FormattedText
                           (
                    chs[chIndex].ToString(), CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, TypeFace, FontSize,
                    foreground, PixelPerDip
                           );

                startPoint.X += CharSize.Width * chIndex;

                drawingContext.DrawText
                (
                    text,
                    startPoint
                );
#endif
            }
        }
Пример #2
0
        /// <summary>
        /// Update the render of text derived bytecontrol from byte property
        /// </summary>
        public override void UpdateTextRenderFromByte()
        {
            if (Byte != null)
            {
                switch (_parent.DataStringVisual)
                {
                case DataVisualType.Hexadecimal:
                    var chArr = ByteConverters.ByteToHexCharArray(Byte.Value);
                    Text = new string(chArr);
                    break;

                case DataVisualType.Decimal:
                    Text = Byte.Value.ToString("d3");
                    break;

                case DataVisualType.Binary:
                    Text = Convert.ToString(Byte.Value, 2).PadLeft(8, '0');
                    break;
                }
            }
            else
            {
                Text = string.Empty;
            }
        }
Пример #3
0
        private void DrawRenderLine(DrawingContext drawingContext, HexTextRenderLine bufferRenderLine)
        {
            if (bufferRenderLine.Data == null)
            {
                return;
            }

            if (GlyphTypeface == null)
            {
                return;
            }

            var fontSize = FontSize;

            var textStartCellPosition = bufferRenderLine.CellStartPosition;

            textStartCellPosition.Y += GlyphTypeface.AdvanceHeights[0] * fontSize + CellMargin.Top + CellPadding.Top;

            var glyphIndexes  = new ushort[bufferRenderLine.Data.Length * 4];
            var advanceWidths = new double[bufferRenderLine.Data.Length * 4];

            for (int i = 0; i < bufferRenderLine.Data.Length; i++)
            {
                ByteConverters.ByteToHexCharArray(bufferRenderLine.Data[i], _cachedHexCharArr);

                GlyphTypeface.CharacterToGlyphMap.TryGetValue(' ', out glyphIndexes[4 * i]);
                GlyphTypeface.CharacterToGlyphMap.TryGetValue(_cachedHexCharArr[0], out glyphIndexes[4 * i + 1]);
                GlyphTypeface.CharacterToGlyphMap.TryGetValue(_cachedHexCharArr[1], out glyphIndexes[4 * i + 2]);
                GlyphTypeface.CharacterToGlyphMap.TryGetValue(' ', out glyphIndexes[4 * i + 3]);

                advanceWidths[4 * i]     = CellMargin.Left + CellPadding.Left;
                advanceWidths[4 * i + 1] = CharSize.Width;
                advanceWidths[4 * i + 2] = CharSize.Width;
                advanceWidths[4 * i + 3] = CellPadding.Right + CellMargin.Right;
            }

#if NET48
            var glyph = new GlyphRun(GlyphTypeface, 0, false, fontSize, (float)PixelPerDip, glyphIndexes, textStartCellPosition, advanceWidths, null, null, null, null, null, null);
#endif

#if NET451
            var glyph = new GlyphRun(GlyphTypeface, 0, false, fontSize, glyphIndexes, textStartCellPosition, advanceWidths, null, null, null, null, null, null);
#endif
            drawingContext.DrawGlyphRun(bufferRenderLine.Foreground, glyph);
        }
Пример #4
0
        protected override void UpdateLabelFromByte()
        {
            if (Byte != null)
            {
                switch (_parent.DataStringVisual)
                {
                case DataVisualType.Hexadecimal:
                    var chArr = ByteConverters.ByteToHexCharArray(Byte.Value);
                    Text = new string(chArr);
                    break;

                case DataVisualType.Decimal:
                    Text = Byte.Value.ToString("d3");
                    break;
                }
            }
            else
            {
                Text = string.Empty;
            }
        }
Пример #5
0
        private void DrawHexForegroundPositions(DrawingContext drawingContext)
        {
            if (GlyphTypeface == null)
            {
                return;
            }

            var hexForegroundPositions = HexForegroundPositions;

#if DEBUG
            //hexForegroundPositions = new IHexBrushPosition[] {new HexBrushPosition{
            //    Position = 0,
            //    FirstCharBrush = Brushes.Red,
            //    SecondCharBrush = Brushes.Blue
            //} };
#endif
            if (hexForegroundPositions == null)
            {
                return;
            }

            var yCharOffset = GlyphTypeface.AdvanceHeights[0] * FontSize + CellMargin.Top + CellPadding.Top;

            foreach (var hexForegroundPosition in hexForegroundPositions)
            {
                if (hexForegroundPosition.Position < 0 || hexForegroundPosition.Position >= Data.Length)
                {
                    continue;
                }

                if (hexForegroundPosition.FirstCharBrush == null && hexForegroundPosition.SecondCharBrush == null)
                {
                    continue;
                }

                var cellPosition = GetCellPosition(hexForegroundPosition.Position);
                if (cellPosition == null)
                {
                    continue;
                }


                var bt = Data[hexForegroundPosition.Position];
                ByteConverters.ByteToHexCharArray(bt, _cachedHexCharArr);

                if (hexForegroundPosition.FirstCharBrush != null)
                {
                    var run = CreateGlyphRunByChar(
                        _cachedHexCharArr[0],
                        new Point {
                        X = cellPosition.Value.X + CellMargin.Left + CellPadding.Left,
                        Y = cellPosition.Value.Y + yCharOffset
                    }
                        );

                    drawingContext.DrawGlyphRun(hexForegroundPosition.FirstCharBrush, run);
                }

                if (hexForegroundPosition.SecondCharBrush != null)
                {
                    var run = CreateGlyphRunByChar(
                        _cachedHexCharArr[1],

                        new Point {
                        X = cellPosition.Value.X + CellMargin.Left + CellPadding.Left + CharSize.Width,
                        Y = cellPosition.Value.Y + yCharOffset
                    }
                        );
                    drawingContext.DrawGlyphRun(hexForegroundPosition.SecondCharBrush, run);
                }
            }
        }
Пример #6
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (Byte == null)
            {
                return;
            }

            if (KeyValidation(e))
            {
                return;
            }

            //MODIFY BYTE
            if (!ReadOnlyMode && KeyValidator.IsHexKey(e.Key))
            {
                switch (_parent.DataStringVisual)
                {
                case DataVisualType.Hexadecimal:

                    #region Edit hexadecimal value

                    string key;
                    key = KeyValidator.IsNumericKey(e.Key)
                            ? KeyValidator.GetDigitFromKey(e.Key).ToString()
                            : e.Key.ToString().ToLower();

                    //Update byte
                    var byteValueCharArray = ByteConverters.ByteToHexCharArray(Byte.Value);
                    switch (_keyDownLabel)
                    {
                    case KeyDownLabel.FirstChar:
                        byteValueCharArray[0] = key.ToCharArray()[0];
                        _keyDownLabel         = KeyDownLabel.SecondChar;
                        Action = ByteAction.Modified;
                        Byte   = ByteConverters.HexToByte(
                            byteValueCharArray[0] + byteValueCharArray[1].ToString())[0];
                        break;

                    case KeyDownLabel.SecondChar:
                        byteValueCharArray[1] = key.ToCharArray()[0];
                        _keyDownLabel         = KeyDownLabel.NextPosition;

                        Action = ByteAction.Modified;
                        Byte   = ByteConverters.HexToByte(
                            byteValueCharArray[0] + byteValueCharArray[1].ToString())[0];

                        //Insert byte at end of file
                        if (_parent.Length != BytePositionInFile + 1)
                        {
                            _keyDownLabel = KeyDownLabel.NextPosition;
                            OnMoveNext(new EventArgs());
                        }
                        break;

                    case KeyDownLabel.NextPosition:

                        //byte[] byteToAppend = { (byte)key.ToCharArray()[0] };
                        _parent.AppendByte(new byte[] { 0 });

                        OnMoveNext(new EventArgs());

                        break;
                    }

                    #endregion

                    break;

                case DataVisualType.Decimal:

                    //Not editable at this moment, maybe in future

                    break;
                }
            }

            UpdateCaret();

            base.OnKeyDown(e);
        }
Пример #7
0
        /// <summary>
        /// Update the render of text derived bytecontrol from byte property
        /// </summary>
        public override void UpdateTextRenderFromByte()
        {
            if (Byte != null)
            {
                byte value;
                var  sign_positive = true;
                var  prefix        = "";

                switch (_parent.DataStringState)
                {
                case DataVisualState.Default:
                    value = Byte.Value;
                    break;

                case DataVisualState.Origin:
                    value = OriginByte.Value;
                    break;

                case DataVisualState.Changes:
                    if (Byte.Value.CompareTo(OriginByte.Value) < 0)
                    {
                        sign_positive = false;
                        value         = (byte)(OriginByte.Value - Byte.Value);
                    }
                    else
                    {
                        value = (byte)(Byte.Value - OriginByte.Value);
                    }

                    break;

                case DataVisualState.ChangesPercent:
                    prefix = "%";
                    if (Byte.Value.CompareTo(OriginByte.Value) < 0)
                    {
                        sign_positive = false;
                        value         = (byte)((OriginByte.Value - Byte.Value) * 100 / byte.MaxValue);
                    }
                    else
                    {
                        value = (byte)((Byte.Value - OriginByte.Value) * 100 / byte.MaxValue);
                    }

                    break;

                default:
                    goto case DataVisualState.Default;
                }

                if (_parent.DataStringState == DataVisualState.ChangesPercent)
                {
                    Text = $"{(sign_positive ? "" : "-")}{prefix}{value:d2}";
                }
                else
                {
                    switch (_parent.DataStringVisual)
                    {
                    case DataVisualType.Hexadecimal:
                        var chArr = ByteConverters.ByteToHexCharArray(value);
                        Text = $"{(sign_positive ? "" : "-")}{prefix}{new string(chArr)}";
                        break;

                    case DataVisualType.Decimal:
                        Text = $"{(sign_positive ? "" : "-")}{prefix}{value:d3}";
                        break;

                    case DataVisualType.Binary:
                        Text = $"{(sign_positive ? "" : "-")}{prefix}{Convert.ToString(value, 2).PadLeft(8, '0')}";
                        break;
                    }
                }
            }
            else
            {
                Text = string.Empty;
            }
        }