Exemplo n.º 1
0
        //指定したidまでで、消されていないストロークを再描画
        private void drawAll(int limId)
        {
            for (int i = 0; i < limId; i++)
            {
                StrokeLine sl = strokeLines[i];

                //指定されたときまでに消去済みでなく、隠れたスペースに書いていないストローク以外を再描画
                if (!sl.GetInSpace() && (sl.GetEreasedTime() > counter || !sl.GetEreased()))
                {
                    //線の色、幅を取得
                    DrawingAttributes DA = new DrawingAttributes();
                    DA.Color  = sl.GetColor();
                    DA.Width  = sl.GetWidth();
                    DA.Height = sl.GetWidth();
                    inkCanvas1.DefaultDrawingAttributes = DA;

                    //点の情報を集める
                    StylusPointCollection spc = new StylusPointCollection();
                    for (int j = 0; j < sl.GetPoints().Count; j++)
                    {
                        spc.Add(new StylusPoint(sl.GetPoints()[j].X, sl.GetPoints()[j].Y));
                    }
                    Stroke stroke = new Stroke(spc, DA);
                    inkCanvas1.Strokes.Add(stroke);
                }
            }
        }
        //すべての線を再描画
        private void drawAll()
        {
            for (int i = 0; i < strokeLines.Count; i++)
            {
                StrokeLine sl = strokeLines[i];

                //消去済みでないストローク以外を再描画
                if (!sl.GetEreased())
                {
                    //線の色、幅を取得
                    DrawingAttributes DA = new DrawingAttributes();
                    DA.Color  = sl.GetColor();
                    DA.Width  = sl.GetWidth();
                    DA.Height = sl.GetWidth();
                    inkCanvas1.DefaultDrawingAttributes = DA;

                    //点の情報を集める
                    StylusPointCollection spc = new StylusPointCollection();
                    for (int j = 0; j < sl.GetPoints().Count; j++)
                    {
                        spc.Add(new StylusPoint(sl.GetPoints()[j].X, sl.GetPoints()[j].Y));
                    }
                    Stroke stroke = new Stroke(spc, DA);
                    inkCanvas1.Strokes.Add(stroke);
                }
            }

            //線のスタイルを戻す
            inkCanvas1.DefaultDrawingAttributes = inkDA;
        }
        //描く処理(マウスアップ)
        private void inkCanvas1_MouseUp(object sender, MouseButtonEventArgs e)
        {
            UIElement el = sender as UIElement;

            Console.WriteLine("まうすがはなれたよ");

            if (isFreeLine && dragging && counter > 3)
            {
                points.Add(e.GetPosition(el));

                //配列strokeLinesに追加
                StrokeLine strokeLine = new StrokeLine();
                strokeLine.SetPoints(points);
                strokeLine.SetColor(color);
                strokeLine.SetWidth((int)slider1.Value);
                strokeLine.SetDownNow(false);
                strokeLine.SetInSpace(false);
                strokeLines.Add(strokeLine);

                //動作ログに記録
                LearningLog log = new LearningLog();
                log.SetStrokeId(strokeId.ToString());
                log.SetBehavior("draw");
                learningLogs.Add(log);

                dragging = false;
                strokeId++;

                Console.WriteLine(counter.ToString());
                counter = 0;
            }

            else if (!isFreeLine && dragging && counter > 3)
            {
                inkCanvas1.Strokes.Clear();
                drawAll();

                //点の情報を集め、始点と現在の点をむすぶ
                StylusPointCollection spc = new StylusPointCollection();
                spc.Add(new StylusPoint(startP.X, startP.Y));
                spc.Add(new StylusPoint(e.GetPosition(el).X, e.GetPosition(el).Y));
                Stroke stroke = new Stroke(spc, inkDA);
                inkCanvas1.Strokes.Add(stroke);

                //pointsに始点と現在の点を格納
                points = new List <System.Windows.Point>();
                points.Add(startP);
                points.Add(e.GetPosition(el));

                //配列strokeLinesについか
                StrokeLine strokeLine = new StrokeLine();
                strokeLine.SetPoints(points);
                strokeLine.SetColor(color);
                strokeLine.SetWidth((int)slider1.Value);
                strokeLine.SetDownNow(false);
                strokeLine.SetInSpace(false);

                strokeLines.Add(strokeLine);

                dragging = false;
                counter  = 0;
            }

            //1操作終わったので、新たにキャプチャが必要
            needToCapturenow = true;
        }
Exemplo n.º 4
0
        //動作を進める
        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //MessageBox.Show(counter + "操作目 : " + learningLogs[counter].GetStrokeId() + "本目を" + learningLogs[counter].GetBehavior() + "する");

                //一次元目がallなら全消去なのですべて消去する
                if (learningLogs[counter].GetStrokeId().Equals("all"))
                {
                    inkCanvas1.Strokes.Clear();
                }

                //二次元目がdrawのとき
                else if (learningLogs[counter].GetBehavior().Equals("draw"))
                {
                    //ターゲットとなるストロークのidを取ってくる
                    int x = Int16.Parse(learningLogs[counter].GetStrokeId());

                    //strokeLiesの中から該当するidのストロークを探す
                    StrokeLine sl = strokeLines[x];

                    //再描画
                    //線の色、幅を取得
                    DrawingAttributes DA = new DrawingAttributes();
                    DA.Color  = sl.GetColor();
                    DA.Width  = sl.GetWidth();
                    DA.Height = sl.GetWidth();
                    inkCanvas1.DefaultDrawingAttributes = DA;

                    //点の情報を集める
                    StylusPointCollection spc = new StylusPointCollection();
                    for (int j = 0; j < sl.GetPoints().Count; j++)
                    {
                        spc.Add(new StylusPoint(sl.GetPoints()[j].X, sl.GetPoints()[j].Y));
                    }
                    Stroke stroke = new Stroke(spc, DA);
                    inkCanvas1.Strokes.Add(stroke);
                }


                //二次元目がeraseのとき
                else if (learningLogs[counter].GetBehavior().Equals("erase"))
                {
                    //ターゲットとなるストロークのidを取ってくる
                    int x = Int16.Parse(learningLogs[counter].GetStrokeId());

                    //strokeLiesの中から該当するidのストロークを探す
                    StrokeLine sl;
                    for (int i = 0; i < strokeLines.Count; i++)
                    {
                        if (strokeLines[i].GetId() == x)
                        {
                            sl = strokeLines[x];
                            break;
                        }
                    }

                    //いったん全部消し、当該idまで、再描画する
                    inkCanvas1.Strokes.Clear();
                    drawAll(x);
                }
                counter++;
            }
            catch
            {
                MessageBox.Show("最後の動作です。");
            }
        }