//ひとつ戻る private void undoButton_Click(object sender, RoutedEventArgs e) { try { //後ろからさかのぼって消えていない線を探す int i; for (i = strokeLines.Count - 1; i >= 0; i--) { if (!strokeLines[i].GetEreased()) { strokeLines[i].SetEreased(true); strokeLines[i].SetEreasedTime(learningLogs.Count + 1); inkCanvas1.Strokes.Clear(); drawAll(); break; } } //動作ログに記録 LearningLog log = new LearningLog(); log.SetStrokeId(strokeLines[i].GetId().ToString()); log.SetBehavior("erase"); learningLogs.Add(log); } catch { MessageBox.Show("ERROR! 一つ戻るの処理過程でエラーが起きました。"); } }
//すべて消去 private void clearButton_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("線をすべて消しますか?", "かくにん", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No) { return; } else { try { for (int i = 0; i < strokeLines.Count(); i++) { //ストローク一つひとつに、erase = trueをセット strokeLines[i].SetEreased(true); //本処理で初めてその線が消える場合のみ、erasedTimeをセット if (strokeLines[i].GetEreasedTime() == -1) { strokeLines[i].SetEreasedTime(learningLogs.Count + 1); } } //動作ログに記録。全消去の時はidの欄をallとする LearningLog log = new LearningLog(); log.SetStrokeId("all"); log.SetBehavior("erase"); learningLogs.Add(log); //キャンバスをクリア inkCanvas1.Strokes.Clear(); } catch { } } }
//描く処理(ペン用) private void inkCanvas1_StylusUp(object sender, StylusEventArgs e) { UIElement el = sender as UIElement; //自由線のとき if (isFreeLine && dragging) { points.Add(e.GetPosition(el)); //点の情報を集め、始点と現在の点をむすぶ StylusPointCollection spc = new StylusPointCollection(); spc.Add(new StylusPoint(prevP.X, prevP.Y)); spc.Add(new StylusPoint(e.GetPosition(el).X, e.GetPosition(el).Y)); Stroke stroke = new Stroke(spc, inkDA); inkCanvas1.Strokes.Add(stroke); //配列strokeLinesに追加 StrokeLine strokeLine = new StrokeLine(); strokeLine.SetId(strokeId); strokeLine.SetPoints(points); strokeLine.SetColor(color); strokeLine.SetWidth((int)inkDA.Width); strokeLine.SetDownNow(false); strokeLine.SetInSpace(false); strokeLine.SetEreasedTime(-1); strokeLines.Add(strokeLine); //動作ログに記録 LearningLog log = new LearningLog(); log.SetStrokeId(strokeId.ToString()); log.SetBehavior("draw"); learningLogs.Add(log); dragging = false; strokeId++; counter = 0; } //直線のとき else if (!isFreeLine && dragging) { strokeId++; 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.SetId(strokeId); strokeLine.SetPoints(points); strokeLine.SetColor(color); strokeLine.SetWidth((int)inkDA.Width); strokeLine.SetDownNow(false); strokeLine.SetInSpace(false); strokeLine.SetEreased(false); strokeLines.Add(strokeLine); dragging = false; counter = 0; } }