Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / tutorials / Tutorial5 / View.cpp
1 //////////////////////////////////////////////\r
2 // View.cpp\r
3 //  Definitions for the CView class\r
4 \r
5 #include "view.h"\r
6 #include "resource.h"\r
7 \r
8 \r
9 CView::CView()\r
10 {\r
11 }\r
12 \r
13 void CView::DrawLine(int x, int y)\r
14 {\r
15         CClientDC dcClient(this);\r
16         dcClient.MoveTo(m_points.back().x, m_points.back().y);\r
17         dcClient.LineTo(x, y);\r
18 }\r
19 \r
20 void CView::OnDraw(CDC* pDC)\r
21 {\r
22         if (m_points.size() > 0)\r
23         {\r
24                 bool bDraw = false;  //Start with the pen up\r
25 \r
26                 for (unsigned int i = 0 ; i < m_points.size(); i++)\r
27                 {\r
28                         if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y);\r
29                         else pDC->MoveTo(m_points[i].x, m_points[i].y);\r
30                         bDraw = m_points[i].PenDown;\r
31                 }\r
32         }\r
33 }\r
34 \r
35 void CView::StorePoint(int x, int y, bool PenDown)\r
36 {\r
37         PlotPoint P1;\r
38         P1.x = x;\r
39         P1.y = y;\r
40         P1.PenDown = PenDown;\r
41 \r
42         m_points.push_back(P1); //Add the point to the vector\r
43 }\r
44 \r
45 void CView::OnLButtonDown(LPARAM lParam)\r
46 {\r
47         // Capture mouse input.\r
48         SetCapture();\r
49 \r
50         StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
51 }\r
52 \r
53 void CView::OnLButtonUp(LPARAM lParam)\r
54 {\r
55         {\r
56                 //Release the capture on the mouse\r
57                 ReleaseCapture();\r
58 \r
59                 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);\r
60         }\r
61 }\r
62 \r
63 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)\r
64 {\r
65         // hold down the left mouse button and move mouse to draw lines.\r
66         if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )\r
67         {\r
68                 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));\r
69                 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
70         }\r
71 }\r
72 \r
73 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
74 {\r
75         switch (uMsg)\r
76         {\r
77         case WM_LBUTTONDOWN:\r
78                 OnLButtonDown(lParam);\r
79                 break;\r
80 \r
81         case WM_MOUSEMOVE:\r
82                 OnMouseMove(wParam, lParam);\r
83         break;\r
84 \r
85     case WM_LBUTTONUP:\r
86                 OnLButtonUp(lParam);\r
87                 break;\r
88 \r
89         // Note: No need to handle WM_DESTROY. The frame does this for us.\r
90         //      case WM_DESTROY:\r
91         //      ::PostQuitMessage(0);\r
92         //      break;\r
93         }\r
94 \r
95         //Use the default message handling for remaining messages\r
96         return WndProcDefault(uMsg, wParam, lParam);\r
97 }\r
98 \r
99 \r
100 \r
101 \r

UCC git Repository :: git.ucc.asn.au