Alternate |
Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line ). |
Winding |
Selects winding mode (fills any region with a nonzero winding value ). |
In general, the modes differ only in cases where a complex, overlapping polygon must be filled (for example, A five-sided polygon that forms a five-pointed star with a pentagon in the center ). in such cases, alternate mode fills every other enclosed Region
Within the polygon (that is, the points of the star), but winding mode fills all regions (that is, the points and the Pentagon ).
When the fill mode is alternate, GDI fills the area between odd-numbered and even-numbered polygon sides on each scan line. that is, GDI fills the area between the first and second side, between the third and fourth side, and so on.
When the fill mode is winding, GDI fills any region that has a nonzero winding value. this value is defined as the number of times a pen used to draw the polygon wocould go around the region. the direction of each edge of the polygon is important.
All right, it's okay to exercise English.
In general, the difference between the two models is only when the complex and overlapping multi-deformation needs to be filled, such as the pentagram produced by a Pentagon and the Pentagon in the middle. In this example, the alternate mode fills the surrounding area of each polygon, that is, the angle of the pentagram. However, the winding mode fills all the areas, that is, the angle of the pentagram and the Pentagon in the middle.
When the fill mode is alternate. GDI fills in the even side and odd side of each scanned line. That is to say, GDI fills in the area between the first side and the second side, the area between the third side and the fourth side, and so on. Note that it is filled from an odd number to an even number.
When the fill mode is winding. GDI fills in any areas where the winding value is not 0. This value is defined as the number of times the brush draws a polygon to surround this area. The direction of each polygon edge is very important.
The above is described in msdn. I didn't quite understand it at the beginning, So Baidu read several articles about winding value calculation and alternate. I read the diagram several times and the description of each article on the Internet. Okay, I finally got started. First look at the figure.
Figure 1
The left side is drawn by the alternate mode, and the right side is the winding mode. The red line. Okay, that's the scanning line. We can see that the second article passes through 1, 2. and 3. 4. So fill. Leave it empty. Because only odd to even is entered.
Figure 2
The following describes how to calculate the winding value.
In winding mode, the algorithm is determined by an "internal counter" and "hypothetical line". When the scanning line encounters a clockwise value, 1 is added (OR 1 is subtracted) subtract 1 (or add 1) counterclockwise ). If it is not 0, it is filled. If it is 0, it is not filled.
In this way, in winding mode, overlap area 5 needs to be filled, and 4 does not need to be filled.
The code in the Appendix
Program 5-5 altwind. c/* --------------------------------------------------------------------- altwind. C -- alternate and winding fill modes (c) Charles Petzold, 1998 --------------------------------------------------------------- */# include <windows. h> lresult callback wndproc (hwnd, uint, wparam, lparam); int winapi winmain (hinstance, hinstance hprevinstance, pstr szcmdline, int IC Mdshow) {static tchar szappname [] = text ("altwind"); hwnd; MSG; wndclass. style = cs_hredraw | cs_vredraw; wndclass. lpfnwndproc = wndproc; wndclass. cbclsextra = 0; wndclass. cbwndextra = 0; wndclass. hinstance = hinstance; wndclass. hicon = loadicon (null, idi_application); wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. hbrbackground = (hbrush) getstoc Kobject (white_brush); wndclass. lpszmenuname = NULL; wndclass. lpszclassname = szappname; If (! Registerclass (& wndclass) {MessageBox (null, text ("program requires Windows NT! "), Szappname, mb_iconerror); Return 0;} hwnd = createwindow (szappname, text (" alternate and winding fill Modes "), numbers, cw_usedefault, null, null, hinstance, null); showwindow (hwnd, icmdshow); updatewindow (hwnd); While (getmessage (& MSG, null, 0, 0 )) {translatemessage (& MSG); dispatchmessage (& MSG);} return MSG. wparam;} lresult callback (hwnd, uint message, wparam, lparam) {static point aptfigure [10] = {10, 70, 50, 50, 10, 90, 10, 90, 50, 30, 50, 30,90, 70,90, 70,30, 10,30}; static int cxclient, cyclient; HDC; int I; paintstruct pS; point apt [10]; Switch (Message) {Case wm_size: cxclient = loword (lparam); cyclient = hiword (lparam); Return 0; Case wm_paint: HDC = beginpaint (hwnd, & PS); SelectObject (HDC, getstockobject (gray_brush )); for (I = 0; I <10; I ++) {apt [I]. X = cxclient * aptfigure [I]. x/200; Apt [I]. y = cyclient * aptfigure [I]. y/100;} setpolyfillmode (HDC, alternate); polygon (HDC, APT, 10); for (I = 0; I <10; I ++) {apt [I]. X + = cxclient/2;} setpolyfillmode (HDC, winding); polygon (HDC, APT, 10); endpaint (hwnd, & PS); Return 0; Case wm_destroy: postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam );}