Skip to content

Instantly share code, notes, and snippets.

@Grabacr07
Last active November 30, 2018 23:02
Show Gist options
  • Select an option

  • Save Grabacr07/8911896 to your computer and use it in GitHub Desktop.

Select an option

Save Grabacr07/8911896 to your computer and use it in GitHub Desktop.
@hivesbee 誕生日おめでとう
public partial class MainWindow : Window
{
/// <summary>
/// D&D の軌跡のコレクションのコレクション。
/// </summary>
private readonly List<List<Point>> points = new List<List<Point>>();
public MainWindow()
{
InitializeComponent();
Observable.FromEventPattern<MouseEventHandler, MouseEventArgs>(
h => this.MouseMove += h,
h => this.MouseMove -= h)
.SkipUntil(Observable
.FromEventPattern<MouseButtonEventHandler, MouseButtonEventArgs>(
h => this.MouseDown += h,
h => this.MouseDown -= h)
.Do(_ => this.CaptureMouse()))
.TakeUntil(Observable
.FromEventPattern<MouseButtonEventHandler, MouseButtonEventArgs>(
h => this.MouseUp += h,
h => this.MouseUp -= h)
.Do(_ => this.ReleaseMouseCapture()))
.Select(x => x.EventArgs.GetPosition(null))
.Do(x => this.TextBlock.Text = string.Format("X: {0}, Y:{1}", x.X, x.Y))
.Aggregate(new List<Point>(), (l, x) => { l.Add(x); return l; })
.Finally(() => this.TextBlock.Text = "Completed")
.Repeat()
.Subscribe(x => this.points.Add(x));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment