Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <summary>
        ///  PointerPressedされた場所から十分に移動したら手描き入力開始として処理する.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool CallBeginTraceIfMovingEnough(PointerRoutedEventArgs e)
        {
            BeginStrokeTrace trace;

            if (!this.strokeCandidateDictionary.TryGetValue(e.Pointer.PointerId, out trace))
            {
                return(false);
            }

            var distance     = this.StrokeThickness;
            var pointerPoint = e.GetCurrentPoint(this.MainCanvas);

            if ((Math.Abs(trace.Position.X - pointerPoint.Position.X) < distance) &&
                (Math.Abs(trace.Position.Y - pointerPoint.Position.Y) < distance))
            {
                return(false);
            }

            this.strokeCandidateDictionary.Remove(e.Pointer.PointerId);

            var timestamp = trace.Timestamp;

            trace.Index = this.Item.InputRecorder.GetNextStrokeIndex();

            // this.Item.InputRecorder.Add(trace);
            this.inputRecorderForNewTrace.Add(trace);
            var elem = BeginStroke(trace);

            this.pressedPointerDictionay.Add(e.Pointer.PointerId, elem);

            // properties
            // - color
            // - thickness
            var colortrace = new SetStrokeColorTrace()
            {
                Timestamp = timestamp,
                Index     = trace.Index,
                Color     = this.StrokeColor,
            };

            SetStrokeColor(colortrace);
            // this.Item.InputRecorder.Add(colortrace);
            this.inputRecorderForNewTrace.Add(colortrace);

            var thicknesstrace = new SetStrokeThicknessTrace()
            {
                Timestamp = timestamp,
                Index     = trace.Index,
                Thickness = this.StrokeThickness,
            };

            SetStrokeThickness(thicknesstrace);
            // this.Item.InputRecorder.Add(thicknesstrace);
            this.inputRecorderForNewTrace.Add(thicknesstrace);

            return(true);
        }
Exemple #3
0
        /// <summary>
        ///  手描き入力の太さを設定する.
        /// </summary>
        /// <param name="trace"></param>
        private void SetStrokeThickness(SetStrokeThicknessTrace trace)
        {
            var elem = GetCanvasElement <Windows.UI.Xaml.Shapes.Polyline>(trace.Index);

            if (elem == null)
            {
                return;
            }

            elem.StrokeThickness = trace.Thickness;
        }