1 |
|
---|
2 |
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Text;
|
---|
6 | using System.Windows.Forms;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Calendar
|
---|
9 | {
|
---|
10 | public class DrawTool : ITool
|
---|
11 | {
|
---|
12 | DateTime m_SelectionStart;
|
---|
13 | bool m_SelectionStarted;
|
---|
14 |
|
---|
15 | public void Reset()
|
---|
16 | {
|
---|
17 | m_SelectionStarted = false;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public void MouseMove(MouseEventArgs e)
|
---|
21 | {
|
---|
22 | if (e == null)
|
---|
23 | throw new ArgumentNullException("e");
|
---|
24 |
|
---|
25 | if (e.Button == MouseButtons.Left)
|
---|
26 | {
|
---|
27 | if (m_SelectionStarted)
|
---|
28 | {
|
---|
29 | DateTime m_Time = m_DayView.GetTimeAt(e.X, e.Y);
|
---|
30 | m_Time = m_Time.AddMinutes(30);
|
---|
31 |
|
---|
32 | if (m_Time < m_SelectionStart)
|
---|
33 | {
|
---|
34 | m_DayView.SelectionStart = m_Time;
|
---|
35 | m_DayView.SelectionEnd = m_SelectionStart;
|
---|
36 | }
|
---|
37 | else
|
---|
38 | {
|
---|
39 | m_DayView.SelectionEnd = m_Time;
|
---|
40 | }
|
---|
41 |
|
---|
42 | m_DayView.Invalidate();
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void MouseUp(MouseEventArgs e)
|
---|
48 | {
|
---|
49 | if (e == null)
|
---|
50 | throw new ArgumentNullException("e");
|
---|
51 |
|
---|
52 | if (e.Button == MouseButtons.Left)
|
---|
53 | {
|
---|
54 | m_DayView.Capture = false;
|
---|
55 | m_SelectionStarted = false;
|
---|
56 |
|
---|
57 | m_DayView.RaiseSelectionChanged(EventArgs.Empty);
|
---|
58 |
|
---|
59 | if (Complete != null)
|
---|
60 | Complete(this, EventArgs.Empty);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void MouseDown(MouseEventArgs e)
|
---|
65 | {
|
---|
66 | if (e == null)
|
---|
67 | throw new ArgumentNullException("e");
|
---|
68 |
|
---|
69 | if (e.Button == MouseButtons.Left)
|
---|
70 | {
|
---|
71 | m_SelectionStart = m_DayView.GetTimeAt(e.X, e.Y);
|
---|
72 |
|
---|
73 | m_DayView.SelectionStart = m_SelectionStart;
|
---|
74 | m_DayView.SelectionEnd = m_SelectionStart.AddMinutes(30);
|
---|
75 |
|
---|
76 | m_SelectionStarted = true;
|
---|
77 |
|
---|
78 | m_DayView.Invalidate();
|
---|
79 | m_DayView.Capture = true;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private DayView m_DayView;
|
---|
84 |
|
---|
85 | public DayView DayView
|
---|
86 | {
|
---|
87 | get { return m_DayView; }
|
---|
88 | set { m_DayView = value; }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public event EventHandler Complete;
|
---|
92 | }
|
---|
93 | }
|
---|