scroll mode for very long start menus
[reactos.git] / reactos / apps / tests / shaptest / shaptest.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * AUTHOR: See gditest-- (initial changes by Mark Tempel)
4 * shaptest
5 *
6 * This is a windowed application that should draw two polygons. One
7 * is drawn with ALTERNATE fill, the other is drawn with WINDING fill.
8 * This is used to test out the Polygon() implementation.
9 */
10
11 #include <windows.h>
12 #include <stdio.h>
13 #include <assert.h>
14
15 #ifndef ASSERT
16 #define ASSERT assert
17 #endif
18
19 #define nelem(x) (sizeof (x) / sizeof *(x))
20
21 HFONT tf;
22 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
23
24 void PolygonTest ( HDC hdc )
25 {
26 HPEN Pen, OldPen;
27 HBRUSH RedBrush, OldBrush;
28 DWORD Mode;
29 POINT PointsAlternate[] =
30 {
31 { 20, 80 },
32 { 60, 20 },
33 { 90, 80 },
34 { 20, 40 },
35 { 100, 40 }
36 };
37 POINT PointsWinding[] =
38 {
39 { 130, 80 },
40 { 170, 20 },
41 { 200, 80 },
42 { 130, 40 },
43 { 210, 40 }
44 };
45 POINT Tri1[] =
46 {
47 { 3, 3 },
48 { 5, 3 },
49 { 3, 5 }
50 };
51 POINT Tri2[] =
52 {
53 { 7, 3 },
54 { 7, 7 },
55 { 3, 7 },
56 };
57 POINT Square1[] =
58 {
59 { 1, 15 },
60 { 3, 15 },
61 { 3, 17 },
62 { 1, 17 }
63 };
64 POINT Square2[] =
65 {
66 { 5, 15 },
67 { 7, 15 },
68 { 7, 17 },
69 { 5, 17 }
70 };
71 POINT Square3[] =
72 {
73 { 1, 23 },
74 { 3, 23 },
75 { 3, 25 },
76 { 1, 25 }
77 };
78 POINT Square4[] =
79 {
80 { 5, 23 },
81 { 7, 23 },
82 { 7, 25 },
83 { 5, 25 }
84 };
85 POINT Square5[] =
86 {
87 { 1, 31 },
88 { 3, 31 },
89 { 3, 33 },
90 { 1, 33 }
91 };
92 POINT Square6[] =
93 {
94 { 5, 31 },
95 { 7, 31 },
96 { 7, 33 },
97 { 5, 33 }
98 };
99
100 //create a pen to draw the shape
101 Pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff));
102 ASSERT(Pen);
103 RedBrush = CreateSolidBrush(RGB(0xff, 0, 0));
104 ASSERT(RedBrush);
105
106 OldPen = (HPEN)SelectObject(hdc, Pen);
107 OldBrush = (HBRUSH)SelectObject(hdc, RedBrush);
108
109 Mode = GetPolyFillMode(hdc);
110
111 RoundRect ( hdc, 32, 8, 48, 24, 8, 8 );
112
113 SetPolyFillMode(hdc, ALTERNATE);
114 Polygon(hdc,PointsAlternate,nelem(PointsAlternate));
115
116 SetPolyFillMode(hdc, WINDING);
117 Polygon(hdc,PointsWinding,nelem(PointsWinding));
118
119 Rectangle ( hdc, 1, 1, 10, 10 );
120 Polygon(hdc,Tri1,nelem(Tri1));
121 Polygon(hdc,Tri2,nelem(Tri2));
122
123 Rectangle ( hdc, 1, 11, 4, 14 );
124 Rectangle ( hdc, 5, 11, 8, 14 );
125 Rectangle ( hdc, 9, 11, 12, 14 );
126 Rectangle ( hdc, 13, 11, 16, 14 );
127 Polygon(hdc,Square1,nelem(Square1));
128 Polygon(hdc,Square2,nelem(Square2));
129 Rectangle ( hdc, 1, 19, 4, 22 );
130 Rectangle ( hdc, 5, 19, 8, 22 );
131 Rectangle ( hdc, 9, 19, 12, 22 );
132 Rectangle ( hdc, 13, 19, 16, 22 );
133 Polygon(hdc,Square3,nelem(Square3));
134 Polygon(hdc,Square4,nelem(Square4));
135 Rectangle ( hdc, 1, 27, 4, 30 );
136 Rectangle ( hdc, 5, 27, 8, 30 );
137 Rectangle ( hdc, 9, 27, 12, 30 );
138 Rectangle ( hdc, 13, 27, 16, 30 );
139
140 // switch to null pen to make surey they display correctly
141 DeleteObject ( SelectObject(hdc, OldPen) );
142 Pen = CreatePen ( PS_NULL, 0, 0 );
143 ASSERT(Pen);
144 OldPen = (HPEN)SelectObject(hdc, Pen);
145
146 Polygon(hdc,Square5,nelem(Square5));
147 Polygon(hdc,Square6,nelem(Square6));
148 Rectangle ( hdc, 1, 35, 4, 38 );
149 Rectangle ( hdc, 5, 35, 8, 38 );
150 Rectangle ( hdc, 9, 35, 12, 38 );
151 Rectangle ( hdc, 13, 35, 16, 38 );
152
153 //cleanup
154 SetPolyFillMode(hdc, Mode);
155 DeleteObject ( SelectObject(hdc, OldPen) );
156 DeleteObject ( SelectObject(hdc, OldBrush) );
157 }
158
159
160 void shaptest( HDC hdc )
161 {
162 //Test the Polygon routine.
163 PolygonTest(hdc);
164 }
165
166
167 int WINAPI
168 WinMain(HINSTANCE hInstance,
169 HINSTANCE hPrevInstance,
170 LPSTR lpszCmdLine,
171 int nCmdShow)
172 {
173 WNDCLASS wc;
174 MSG msg;
175 HWND hWnd;
176
177 wc.lpszClassName = "ShapTestClass";
178 wc.lpfnWndProc = MainWndProc;
179 wc.style = CS_VREDRAW | CS_HREDRAW;
180 wc.hInstance = hInstance;
181 wc.hIcon = (HICON)LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
182 wc.hCursor = (HCURSOR)LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
183 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
184 wc.lpszMenuName = NULL;
185 wc.cbClsExtra = 0;
186 wc.cbWndExtra = 0;
187 if (RegisterClass(&wc) == 0)
188 {
189 fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
190 (unsigned int)GetLastError());
191 return(1);
192 }
193
194 hWnd = CreateWindow("ShapTestClass",
195 "Shaptest",
196 WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
197 0,
198 0,
199 CW_USEDEFAULT,
200 CW_USEDEFAULT,
201 NULL,
202 NULL,
203 hInstance,
204 NULL);
205 if (hWnd == NULL)
206 {
207 fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
208 (unsigned int)GetLastError());
209 return(1);
210 }
211
212 tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
213 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
214 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
215
216 ShowWindow(hWnd, nCmdShow);
217
218 while(GetMessage(&msg, NULL, 0, 0))
219 {
220 TranslateMessage(&msg);
221 DispatchMessage(&msg);
222 }
223
224 DeleteObject(tf);
225
226 return msg.wParam;
227 }
228
229 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
230 {
231 PAINTSTRUCT ps;
232 HDC hDC;
233
234 switch(msg)
235 {
236
237 case WM_PAINT:
238 hDC = BeginPaint(hWnd, &ps);
239 shaptest( hDC );
240 EndPaint(hWnd, &ps);
241 break;
242
243 case WM_DESTROY:
244 PostQuitMessage(0);
245 break;
246
247 default:
248 return DefWindowProc(hWnd, msg, wParam, lParam);
249 }
250 return 0;
251 }
252