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

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