Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / samples / GDIPlus / src / GDIPlusView.cpp
1 //////////////////////////////////////////////\r
2 // GDIPlusView.cpp\r
3 //  Definitions for the CGDIPlusView class\r
4 \r
5 #include "stdafx.h"\r
6 #include "GDIPlusView.h"\r
7 using namespace Gdiplus;\r
8 \r
9 CGDIPlusView::CGDIPlusView()\r
10 {\r
11         // Initialize GDI+.\r
12         GdiplusStartupInput gdiplusStartupInput;\r
13         GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);\r
14 }\r
15 \r
16 CGDIPlusView::~CGDIPlusView()\r
17 {\r
18         // Shutdown GDI+\r
19         GdiplusShutdown(m_gdiplusToken);\r
20 }\r
21 \r
22 void CGDIPlusView::DrawCappedLine(CDC* pDC) \r
23 {\r
24         Graphics graphics(*pDC);\r
25         // Draw capped line, width 8\r
26         Pen penCapped(Color(255, 0, 0, 255), 8);\r
27         Status stat = penCapped.SetStartCap(LineCapArrowAnchor);\r
28         stat = penCapped.SetEndCap(LineCapRoundAnchor);\r
29         stat = graphics.DrawLine(&penCapped, 10, 175, 300, 175);\r
30 }\r
31 \r
32 void CGDIPlusView::DrawGamaShapes(CDC* pDC)\r
33 {\r
34         Graphics graphics(*pDC);\r
35 \r
36         // Draw Plygons with Gama Corrections\r
37         // Put the points of a polygon in an array.\r
38         GraphicsPath pathGama;\r
39         int yOffset = 200;\r
40         Point points[] = {Point(75,  0  +yOffset), Point(100, 50+yOffset), \r
41                                           Point(150, 50 +yOffset), Point(112, 75+yOffset),\r
42                                           Point(150, 150+yOffset), Point(75,  100+yOffset), \r
43                                           Point(0,   150+yOffset), Point(37,  75+yOffset), \r
44                                           Point(0,   50 +yOffset), Point(50,  50+yOffset)};\r
45 \r
46         // Use the array of points to construct a path.\r
47         pathGama.AddLines(points, 10);\r
48 \r
49         // Use the path to construct a path gradient brush.\r
50         PathGradientBrush pthGrBrushGama(&pathGama);\r
51 \r
52         // Set the color at the center of the path to red.\r
53         pthGrBrushGama.SetCenterColor(Color(255, 255, 0, 0));\r
54 \r
55         // Set the colors of the points in the array.\r
56         Color colorsGama[] = {Color(255, 0, 0, 0),   Color(255, 0, 255, 0),\r
57                                           Color(255, 0, 0, 255), Color(255, 255, 255, 255), \r
58                                           Color(255, 0, 0, 0),   Color(255, 0, 255, 0), \r
59                                           Color(255, 0, 0, 255), Color(255, 255, 255, 255),\r
60                                           Color(255, 0, 0, 0),   Color(255, 0, 255, 0)};\r
61 \r
62         int count = 10;\r
63         pthGrBrushGama.SetSurroundColors(colorsGama, &count);\r
64 \r
65         // Fill the path with the path gradient brush.\r
66         graphics.FillPath(&pthGrBrushGama, &pathGama);\r
67         pthGrBrushGama.SetGammaCorrection(TRUE);\r
68         graphics.TranslateTransform(200.0f, 0.0f);\r
69         graphics.FillPath(&pthGrBrushGama, &pathGama);\r
70 }\r
71 \r
72 void CGDIPlusView::DrawGradientElipse(CDC* pDC)\r
73 {\r
74         Graphics graphics(*pDC);\r
75 \r
76         // Create a path that consists of a single ellipse.\r
77         GraphicsPath path;\r
78         path.AddEllipse(0, 80, 140, 70);\r
79 \r
80         // Use the path to construct a brush.\r
81         PathGradientBrush pthGrBrush(&path);\r
82 \r
83         // Set the color at the center of the path to blue.\r
84         pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));\r
85 \r
86         // Set the color along the entire boundary of the path to aqua.\r
87         Color colors[] = {Color(255, 0, 255, 255)};\r
88         int count = 1;\r
89         pthGrBrush.SetSurroundColors(colors, &count);\r
90 \r
91         graphics.FillEllipse(&pthGrBrush, 0, 80, 140, 70);\r
92 }\r
93 \r
94 void CGDIPlusView::DrawSolidElipse(CDC* pDC)\r
95 {\r
96         Graphics graphics(*pDC);\r
97 \r
98         SolidBrush solidBrush(Color(255, 255, 0, 0));\r
99         graphics.FillEllipse(&solidBrush, 160, 84, 100, 60);\r
100 }\r
101 \r
102 void CGDIPlusView::DrawSolidLine(CDC* pDC) \r
103 {\r
104         Graphics graphics(*pDC);\r
105         \r
106         // Draw solid line\r
107         Pen      penLine(Color(255, 0, 0, 255));\r
108         graphics.DrawLine(&penLine, 10, 70, 200, 70);\r
109 }\r
110 \r
111 void CGDIPlusView::DrawText(CDC* pDC) \r
112 {\r
113         Graphics graphics(*pDC);\r
114 \r
115         // Draw some text\r
116         SolidBrush  brush(Color(255, 0, 0, 255));\r
117         FontFamily  fontFamily(L"Times New Roman");\r
118         Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);\r
119         PointF      pointF(10.0f, 20.0f);\r
120    \r
121         graphics.DrawString(L"GDI+  Example", -1, &font, pointF, &brush);\r
122 }\r
123 \r
124 void CGDIPlusView::OnDraw(CDC* pDC)\r
125 {\r
126         DrawSolidLine(pDC);\r
127         DrawText(pDC);\r
128         DrawCappedLine(pDC);\r
129         DrawGradientElipse(pDC);\r
130         DrawSolidElipse(pDC);\r
131         DrawGamaShapes(pDC); \r
132 }\r
133 \r
134 void CGDIPlusView::OnInitialUpdate()\r
135 {\r
136         // OnInitialUpdate is called immediately after the window is created\r
137         TRACE(_T("View window created\n"));\r
138 }\r
139 \r
140 void CGDIPlusView::PreCreate(CREATESTRUCT &cs)\r
141 {\r
142         // Here we set the defaults used by the create function for the view window\r
143         // Preforming this is optional, but doing so allows us to\r
144         // take more precise control over the window we create.\r
145 \r
146         // Set the extended style\r
147         cs.dwExStyle = WS_EX_CLIENTEDGE;\r
148 }\r
149 \r
150 void CGDIPlusView::RegisterClass(WNDCLASS &wc)\r
151 {\r
152         // Here we set the Window class parameters.\r
153         // Preforming this is optional, but doing so allows us to\r
154         // take more precise control over the type of window we create.\r
155 \r
156         // Set the Window Class name\r
157         wc.lpszClassName = _T("View");\r
158 \r
159         // Set the class style (not to be confused with the window styles set in PreCreate)\r
160         wc.style = CS_DBLCLKS;  // Generate left button double click messages\r
161 }\r
162 \r
163 LRESULT CGDIPlusView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
164 {\r
165 //      switch (uMsg)\r
166 //      {\r
167 \r
168 //      }\r
169 \r
170         // pass unhandled messages on for default processing\r
171         return WndProcDefault(uMsg, wParam, lParam);\r
172 }\r
173 \r

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