private void DrawTiming(Canvas canvas) { canvas.Children.Clear(); _timingDatas = TimingMapParser.Parse(txtData.Text); InitDrawParam(); // determine the maximum width from all symbols var max = 0.0; foreach (var timingData in _timingDatas) { var x = GraphicHelper.MeasureTextWidth(timingData.Symbol, 14); if (max < x) { max = x; } } // ensure we draw behind symbol DrawParam.StartX = (int)max; // determine the width of entire diagram max = 0; foreach (var timingData in _timingDatas) { if (max < (int)timingData.Timing.Length) { max = (int)timingData.Timing.Length; } } // re-calculate the size of canvas canvas.Width = DrawParam.StartX + (max * DrawParam.UnitX) + (DrawParam.Margin * 2); canvas.Height = _timingDatas.Count * (DrawParam.UnitY + DrawParam.VerticalSpace) + DrawParam.StartY; _markerDrawer.Draw((int)max); var lineIndex = 0; TimingCharacterDrawer marker = null; // draw content foreach (var timingMap in _timingDatas) { var drawer = new TimingCharacterDrawer(lineIndex, timingMap); if (drawer.IsMarker() == true) { marker = drawer; lineIndex++; continue; } drawer.Draw(); lineIndex++; DrawParam.StartY += DrawParam.VerticalSpace; } if (marker != null) { marker.DrawMarker(lineIndex); } }
public MainViewModel() { DrawParam.StartX = 50; DrawParam.StartY = 50; DrawParam.UnitX = 10; DrawParam.UnitY = 30; DrawParam.Margin = 10; DrawParam.VerticalSpace = 50; DrawParam.MarkHeight = 10; TimingData = InitTimingData; MarkerData = InitMarkerData; TimingDatas = TimingMapParser.Parse(TimingData); EditStatusString = EditStatus.Unchanged.ToString(); MessagingCenter.Subscribe <MessageToken>(this, "message", (item) => { if (item.TokenType == MessageTokenType.KeyChanged) { EditStatus = EditStatus.Modified; TimingDatas = TimingMapParser.Parse(TimingData); UpdateTimingDiagram(); } }); InputCharCommand = new Command((ch) => { Debug.WriteLine("symbol label clicked, parameter: " + ch); }); ChangeSymbolCommand = new Command((arg) => { Debug.WriteLine("symbol label clicked, parameter: " + arg); }); ChangeTimingCommand = new Command((arg) => { Debug.WriteLine("Timing data changed : " + arg); }); PaintSurfaceCommand = new Command((arg) => { var args = arg as SKPaintSurfaceEventArgs; var info = args.Info; var surface = args.Surface; var canvas = surface.Canvas; if (_bitmap == null) { _bitmap = new SKBitmap(info); } if (_drawEngine == null) { _drawEngine = new SkiaDrawEngine(_bitmap); } TimingDatas = TimingMapParser.Parse(TimingData); _bitmap = _drawEngine.Draw(TimingDatas); if (_bitmap != null) { canvas.DrawBitmap(_bitmap, 0, 0); } UpdateTimingDiagram(); }); UpdateTimingDiagram(); }