/// <summary>
        /// Update control label from byte property
        /// </summary>
        private void UpdateLabelFromByte()
        {
            if (Byte != null)
            {
                switch (TypeOfCharacterTable)
                {
                case CharacterTable.ASCII:
                    StringByteLabel.Content = ByteConverters.ByteToChar(Byte.Value);
                    Width = 12;
                    break;

                case CharacterTable.TBLFile:
                    ReadOnlyMode = true;

                    if (_TBLCharacterTable != null)
                    {
                        string content = "#";
                        string MTE     = (ByteConverters.ByteToHex(Byte.Value) + ByteConverters.ByteToHex(ByteNext.Value)).ToUpper();
                        content = _TBLCharacterTable.FindTBLMatch(MTE, true);

                        if (content == "#")
                        {
                            content = _TBLCharacterTable.FindTBLMatch(ByteConverters.ByteToHex(Byte.Value).ToUpper().ToUpper(), true);
                        }

                        StringByteLabel.Content = content;

                        //Adjuste wight
                        if (content.Length == 1)
                        {
                            Width = 12;
                        }
                        else if (content.Length == 2)
                        {
                            Width = 12 + content.Length * 2D;
                        }
                        else if (content.Length > 2)
                        {
                            Width = 12 + content.Length * 3.8D;
                        }
                    }
                    else
                    {
                        goto case CharacterTable.ASCII;
                    }
                    break;
                }
            }
            else
            {
                StringByteLabel.Content = "";
            }
        }
예제 #2
0
        public char Convert(byte[] bytesToConvert)
        {
            if (bytesToConvert == null)
            {
                throw new ArgumentNullException(nameof(bytesToConvert));
            }

            if (bytesToConvert.Length != BytePerChar)
            {
                throw new InvalidOperationException($"The length {nameof(bytesToConvert)} doesn't match {nameof(BytePerChar)}.");
            }

            return(ByteConverters.ByteToChar(bytesToConvert[0]));
        }
        protected override void DrawByte(DrawingContext drawingContext, byte bt, Brush foreground, Point startPoint)
        {
            var ch = ByteConverters.ByteToChar(bt);

#if NET451
            var text = new FormattedText(ch.ToString(), CultureInfo.CurrentCulture,
                                         FlowDirection.LeftToRight, TypeFace, FontSize,
                                         foreground);
            drawingContext.DrawText(text, startPoint);
#endif

#if NET47
            var text = new FormattedText(ch.ToString(), CultureInfo.CurrentCulture,
                                         FlowDirection.LeftToRight, TypeFace, FontSize,
                                         foreground, PixelPerDip);
            drawingContext.DrawText(text, startPoint);
#endif
        }
예제 #4
0
        public static TBLStream CreateDefaultASCII(DefaultCharacterTableType type = DefaultCharacterTableType.ASCII)
        {
            TBLStream tbl = new TBLStream();

            switch (type)
            {
            case DefaultCharacterTableType.ASCII:
                for (byte i = 0; i < 255; i++)
                {
                    DTE dte = new DTE(ByteConverters.ByteToHex(i).ToUpper(), $"{ByteConverters.ByteToChar(i)}");
                    tbl.Add(dte);
                }
                break;
            }

            tbl.AllowEdit = true;
            return(tbl);
        }
        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (KeyValidator.IsIgnoredKey(e.Key))
            {
                e.Handled = true;
                return;
            }
            else if (KeyValidator.IsUpKey(e.Key))
            {
                e.Handled = true;
                MoveUp?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsDownKey(e.Key))
            {
                e.Handled = true;
                MoveDown?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsLeftKey(e.Key))
            {
                e.Handled = true;
                MoveLeft?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsRightKey(e.Key))
            {
                e.Handled = true;
                MoveRight?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsPageDownKey(e.Key))
            {
                e.Handled = true;
                MovePageDown?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsPageUpKey(e.Key))
            {
                e.Handled = true;
                MovePageUp?.Invoke(this, new EventArgs());

                return;
            }
            else if (KeyValidator.IsDeleteKey(e.Key))
            {
                if (!ReadOnlyMode)
                {
                    e.Handled = true;
                    ByteDeleted?.Invoke(this, new EventArgs());

                    return;
                }
            }
            else if (KeyValidator.IsBackspaceKey(e.Key))
            {
                if (!ReadOnlyMode)
                {
                    e.Handled = true;
                    ByteDeleted?.Invoke(this, new EventArgs());

                    MovePrevious?.Invoke(this, new EventArgs());

                    return;
                }
            }
            else if (KeyValidator.IsEscapeKey(e.Key))
            {
                e.Handled = true;
                EscapeKey?.Invoke(this, new EventArgs());
                return;
            }

            //MODIFY ASCII...
            //TODO : MAKE BETTER KEYDETECTION AND EXPORT IN KEYVALIDATOR
            if (!ReadOnlyMode)
            {
                bool isok = false;

                if (Keyboard.GetKeyStates(Key.CapsLock) == KeyStates.Toggled)
                {
                    if (Keyboard.Modifiers != ModifierKeys.Shift && e.Key != Key.RightShift && e.Key != Key.LeftShift)
                    {
                        StringByteLabel.Content = ByteConverters.ByteToChar((byte)KeyInterop.VirtualKeyFromKey(e.Key));
                        isok = true;
                    }
                    else if (Keyboard.Modifiers == ModifierKeys.Shift && e.Key != Key.RightShift && e.Key != Key.LeftShift)
                    {
                        isok = true;
                        StringByteLabel.Content = ByteConverters.ByteToChar((byte)KeyInterop.VirtualKeyFromKey(e.Key)).ToString().ToLower();
                    }
                }
                else
                {
                    if (Keyboard.Modifiers != ModifierKeys.Shift && e.Key != Key.RightShift && e.Key != Key.LeftShift)
                    {
                        StringByteLabel.Content = ByteConverters.ByteToChar((byte)KeyInterop.VirtualKeyFromKey(e.Key)).ToString().ToLower();
                        isok = true;
                    }
                    else if (Keyboard.Modifiers == ModifierKeys.Shift && e.Key != Key.RightShift && e.Key != Key.LeftShift)
                    {
                        isok = true;
                        StringByteLabel.Content = ByteConverters.ByteToChar((byte)KeyInterop.VirtualKeyFromKey(e.Key));
                    }
                }

                //Move focus event
                if (isok)
                {
                    if (MoveNext != null)
                    {
                        Action = ByteAction.Modified;
                        Byte   = ByteConverters.CharToByte(StringByteLabel.Content.ToString()[0]);

                        MoveNext(this, new EventArgs());
                    }
                }
            }
        }