/// <summary> /// 文字列にシリアライズされた手描き入力を復元する. /// </summary> /// <param name="text"></param> /// <returns></returns> private static InputTraceBase ParseTrace(string text) { JsonArray jsonArray; if (!JsonArray.TryParse(text, out jsonArray)) { return(null); } InputTraceKind kind; if (!Enum.TryParse(jsonArray.GetStringAt(0), out kind)) { return(null); } InputTraceBase trace; switch (kind) { case InputTraceKind.BeginStroke: trace = new BeginStrokeTrace(); break; case InputTraceKind.MoveStroke: trace = new MoveStrokeTrace(); break; case InputTraceKind.EndStroke: trace = new EndStrokeTrace(); break; case InputTraceKind.RemoveStroke: trace = new RemoveStrokeTrace(); break; case InputTraceKind.SetStrokeColor: trace = new SetStrokeColorTrace(); break; case InputTraceKind.SetStrokeThickness: trace = new SetStrokeThicknessTrace(); break; case InputTraceKind.SetBackgroundColor: trace = new SetBackgroundColorTrace(); break; case InputTraceKind.SetImage: trace = new SetImageTrace(); break; default: return(null); } trace.LoadFromJson(jsonArray); return(trace); }
/// <summary> /// 手描きの入力が移動しているときに呼び出す. /// </summary> /// <param name="pointer"></param> private void MoveStroke(MoveStrokeTrace trace) { var elem = GetCanvasElement <Windows.UI.Xaml.Shapes.Polyline>(trace.Index); if (elem == null) { return; } elem.Points.Add(trace.Position); }
/// <summary> /// 手描き描画用CanvasのPointerMovedイベントを処理する. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainCanvas_PointerMoved(object sender, PointerRoutedEventArgs e) { // 編集中以外は無視する if (!this.isEditingInternal) { return; } Windows.UI.Xaml.Shapes.Polyline line; if (!this.pressedPointerDictionay.TryGetValue(e.Pointer.PointerId, out line)) { BeginStrokeTrace beginTrace; if (!this.strokeCandidateDictionary.TryGetValue(e.Pointer.PointerId, out beginTrace)) { return; } if (!CallBeginTraceIfMovingEnough(e)) { return; } if (!this.pressedPointerDictionay.TryGetValue(e.Pointer.PointerId, out line)) { return; } } var pointerPoint = e.GetCurrentPoint(this.MainCanvas); var trace = new MoveStrokeTrace() { Index = (uint)line.Tag, Position = pointerPoint.Position, Timestamp = DateTimeOffset.UtcNow.Ticks, }; // this.Item.InputRecorder.Add(trace); this.inputRecorderForNewTrace.Add(trace); MoveStroke(trace); }