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.Lenght != 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); }
public void GetHexBitsTest() { Assert.AreEqual(ByteConverters.GetHexBits(0x1), 1); Assert.AreEqual(ByteConverters.GetHexBits(0xf), 1); Assert.AreEqual(ByteConverters.GetHexBits(0x10), 2); }
/// <summary> /// String representation /// </summary> public override string ToString() => $"({ByteConverters.LongToHex(BytePositionInStream)}h){Description}";
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var(success, val) = ByteConverters.IsHexaValue(value.ToString()); return(success ? (object)val : string.Empty); }
private void PositionHexText_TextChanged(object sender, TextChangedEventArgs e) { GoPositionHexaButton.IsEnabled = ByteConverters.IsHexValue(PositionHexText.Text).success; }
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); } } }
/// <summary> /// Chargé le fichier dans l'objet /// </summary> /// <returns>Retoune vrai si le fichier est bien charger</returns> private bool Load() { //Vide la collection _DTEList.Clear(); //ouverture du fichier if (!File.Exists(_FileName)) { FileStream fs = File.Create(_FileName); fs.Close(); } StreamReader TBLFile; try { TBLFile = new StreamReader(_FileName, Encoding.ASCII); } catch { return(false); } if (TBLFile.BaseStream.CanRead) { //lecture du fichier jusqua la fin et séparation par ligne char[] sepEndLine = { '\n' }; //Fin de ligne char[] sepEqual = { '=' }; //Fin de ligne //build strings line StringBuilder textFromFile = new StringBuilder(TBLFile.ReadToEnd()); textFromFile.Insert(textFromFile.Length, '\r'); textFromFile.Insert(textFromFile.Length, '\n'); string[] lines = textFromFile.ToString().Split(sepEndLine); //remplir la collection de DTE : this._DTE foreach (string line in lines) { string[] info = line.Split(sepEqual); //ajout a la collection (ne prend pas encore en charge le Japonais) DTE dte = new DTE(); try { switch (info[0].Length) { case 2: if (info[1].Length == 2) { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.ASCII); } else { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.DualTitleEncoding); } break; case 4: // >2 dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.MultipleTitleEncoding); break; default: continue; } } catch (IndexOutOfRangeException) { switch (info[0].Substring(0, 1)) { case @"/": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndBlock); break; case @"*": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndLine); break; //case @"\": default: continue; } } catch (ArgumentOutOfRangeException) { //Du a une entre qui a 2 = de suite... EX: XX== dte = new DTE(info[0], "=", DTEType.DualTitleEncoding); } _DTEList.Add(dte); } //Load bookmark BookMarks.Clear(); BookMark fav = null; string[] lineSplited; foreach (string line in lines) { try { if (line.Substring(0, 1) == "(") { fav = new BookMark(); lineSplited = line.Split(new char[] { ')' }); fav.Description = lineSplited[1].Substring(0, lineSplited[1].Length - 1); lineSplited = line.Split(new char[] { 'h' }); fav.BytePositionInFile = ByteConverters.HexLiteralToLong(lineSplited[0].Substring(1, lineSplited[0].Length - 1)).position; fav.Marker = ScrollMarker.TBLBookmark; BookMarks.Add(fav); } } catch { } //Nothing to add if error } TBLFile.Close(); return(true); } else { return(false); } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); void DrawOneStep(long offSet, Point startPoint) { var str = string.Empty; switch (DataVisualType) { case DataVisualType.Hexadecimal: str = $"0x{ByteConverters.LongToHex(offSet, SavedBits)}"; break; case DataVisualType.Decimal: str = ByteConverters.LongToString(offSet, SavedBits); break; default: break; } #if NET451 var text = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, TypeFace, FontSize, Foreground); #endif #if NET47 var text = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, TypeFace, FontSize, Foreground, PixelPerDip); #endif drawingContext.DrawText(text, startPoint); } void DrawSteps(Func <int, Point> getOffsetLocation) { for (int i = 0; i < StepsCount; i++) { DrawOneStep( i * StepLength + StartStepIndex, getOffsetLocation(i) ); } } if (Orientation == Orientation.Horizontal) { DrawSteps(step => new Point( (CellMargin.Left + CellMargin.Right + CellSize.Width) * step + CellMargin.Left + CellPadding.Left, CellMargin.Top + CellPadding.Top ) ); } else { #if DEBUG //double lastY = 0; #endif DrawSteps(step => new Point( CellMargin.Left + CellPadding.Left, (CellMargin.Top + CellMargin.Bottom + CellSize.Height) * step + CellMargin.Top + CellPadding.Top)); { #if DEBUG //if(lastY != pot.Y) { // lastY = pot.Y; // System.Diagnostics.Debug.WriteLine(lastY); //} #endif //return pot; } } }
public void ClearConverters() { ByteConverters.Clear(); }
public void AddConverter <T>(T converter) where T : IObjectConverter { ByteConverters.Add(converter); }