2 * PROJECT: PAINT for ReactOS
5 * PURPOSE: The drawing functions used by the tools
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
15 void Line(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int thickness
)
17 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, color
));
18 MoveToEx(hdc
, x1
, y1
, NULL
);
20 DeleteObject(SelectObject(hdc
, oldPen
));
23 void Rect(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
27 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
28 if (style
==0) logbrush
.lbStyle
= BS_HOLLOW
; else logbrush
.lbStyle
= BS_SOLID
;
29 if (style
==2) logbrush
.lbColor
= fg
; else logbrush
.lbColor
= bg
;
31 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
32 Rectangle(hdc
, x1
, y1
, x2
, y2
);
33 DeleteObject(SelectObject(hdc
, oldBrush
));
34 DeleteObject(SelectObject(hdc
, oldPen
));
37 void Ellp(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
41 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
42 if (style
==0) logbrush
.lbStyle
= BS_HOLLOW
; else logbrush
.lbStyle
= BS_SOLID
;
43 if (style
==2) logbrush
.lbColor
= fg
; else logbrush
.lbColor
= bg
;
45 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
46 Ellipse(hdc
, x1
, y1
, x2
, y2
);
47 DeleteObject(SelectObject(hdc
, oldBrush
));
48 DeleteObject(SelectObject(hdc
, oldPen
));
51 void RRect(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
55 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
56 if (style
==0) logbrush
.lbStyle
= BS_HOLLOW
; else logbrush
.lbStyle
= BS_SOLID
;
57 if (style
==2) logbrush
.lbColor
= fg
; else logbrush
.lbColor
= bg
;
59 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
60 RoundRect(hdc
, x1
, y1
, x2
, y2
, 16, 16);
61 DeleteObject(SelectObject(hdc
, oldBrush
));
62 DeleteObject(SelectObject(hdc
, oldPen
));
65 void Poly(HDC hdc
, POINT
*lpPoints
, int nCount
, int fg
, int bg
, int thickness
, int style
, BOOL closed
)
69 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
70 if (style
==0) logbrush
.lbStyle
= BS_HOLLOW
; else logbrush
.lbStyle
= BS_SOLID
;
71 if (style
==2) logbrush
.lbColor
= fg
; else logbrush
.lbColor
= bg
;
73 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
75 Polygon(hdc
, lpPoints
, nCount
);
77 Polyline(hdc
, lpPoints
, nCount
);
78 DeleteObject(SelectObject(hdc
, oldBrush
));
79 DeleteObject(SelectObject(hdc
, oldPen
));
82 void Bezier(HDC hdc
, POINT p1
, POINT p2
, POINT p3
, POINT p4
, int color
, int thickness
)
90 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, color
));
91 PolyBezier(hdc
, fourPoints
, 4);
92 DeleteObject(SelectObject(hdc
, oldPen
));
95 void Fill(HDC hdc
, int x
, int y
, int color
)
97 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
98 ExtFloodFill(hdc
, x
, y
, GetPixel(hdc
, x
, y
), FLOODFILLSURFACE
);
99 DeleteObject(SelectObject(hdc
, oldBrush
));
102 void Erase(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int radius
)
106 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
107 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
108 for (a
=0; a
<=100; a
++)
109 Rectangle(hdc
, (x1
*(100-a
)+x2
*a
)/100-radius
+1, (y1
*(100-a
)+y2
*a
)/100-radius
+1, (x1
*(100-a
)+x2
*a
)/100+radius
+1, (y1
*(100-a
)+y2
*a
)/100+radius
+1);
110 DeleteObject(SelectObject(hdc
, oldBrush
));
111 DeleteObject(SelectObject(hdc
, oldPen
));
114 void Replace(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int radius
)
117 for (a
=0; a
<=100; a
++)
118 for (y
=(y1
*(100-a
)+y2
*a
)/100-radius
+1; y
<(y1
*(100-a
)+y2
*a
)/100+radius
+1; y
++)
119 for (x
=(x1
*(100-a
)+x2
*a
)/100-radius
+1; x
<(x1
*(100-a
)+x2
*a
)/100+radius
+1; x
++)
120 if (GetPixel(hdc
, x
, y
)==fg
) SetPixel(hdc
, x
, y
, bg
);
123 void Airbrush(HDC hdc
, short x
, short y
, int color
, int r
)
127 for (b
=-r
; b
<=r
; b
++) for (a
=-r
; a
<=r
; a
++) if ((a
*a
+b
*b
<=r
*r
)&&(rand()%4==0)) SetPixel(hdc
, x
+a
, y
+b
, color
);
130 void Brush(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int style
)
132 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
133 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
138 for (a
=0; a
<=100; a
++)
139 Ellipse(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100-3, (x1
*(100-a
)+x2
*a
)/100+4, (y1
*(100-a
)+y2
*a
)/100+4);
142 for (a
=0; a
<=100; a
++)
143 Ellipse(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100-1, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100+3);
146 MoveToEx(hdc
, x1
, y1
, NULL
);
148 SetPixel(hdc
, x2
, y2
, color
);
151 for (a
=0; a
<=100; a
++)
152 Rectangle(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100-3, (x1
*(100-a
)+x2
*a
)/100+5, (y1
*(100-a
)+y2
*a
)/100+5);
155 for (a
=0; a
<=100; a
++)
156 Rectangle(hdc
, (x1
*(100-a
)+x2
*a
)/100-2, (y1
*(100-a
)+y2
*a
)/100-2, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100+3);
159 for (a
=0; a
<=100; a
++)
160 Rectangle(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100-1, (x1
*(100-a
)+x2
*a
)/100+1, (y1
*(100-a
)+y2
*a
)/100+1);
163 for (a
=0; a
<=100; a
++)
165 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100+5, NULL
);
166 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+5, (y1
*(100-a
)+y2
*a
)/100-3);
170 for (a
=0; a
<=100; a
++)
172 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-2, (y1
*(100-a
)+y2
*a
)/100+3, NULL
);
173 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100-2);
177 for (a
=0; a
<=100; a
++)
179 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100+1, NULL
);
180 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+1, (y1
*(100-a
)+y2
*a
)/100-1);
184 for (a
=0; a
<=100; a
++)
186 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100-3, NULL
);
187 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+5, (y1
*(100-a
)+y2
*a
)/100+5);
191 for (a
=0; a
<=100; a
++)
193 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-2, (y1
*(100-a
)+y2
*a
)/100-2, NULL
);
194 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100+3);
198 for (a
=0; a
<=100; a
++)
200 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100-1, NULL
);
201 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+1, (y1
*(100-a
)+y2
*a
)/100+1);
205 DeleteObject(SelectObject(hdc
, oldBrush
));
206 DeleteObject(SelectObject(hdc
, oldPen
));
209 void RectSel(HDC hdc
, short x1
, short y1
, short x2
, short y2
)
213 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
214 logbrush
.lbStyle
= BS_HOLLOW
;
215 logbrush
.lbColor
= 0;
216 logbrush
.lbHatch
= 0;
217 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
218 Rectangle(hdc
, x1
, y1
, x2
, y2
);
219 DeleteObject(SelectObject(hdc
, oldBrush
));
220 DeleteObject(SelectObject(hdc
, oldPen
));
223 void SelectionFrame(HDC hdc
, int x1
, int y1
, int x2
, int y2
)
227 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
228 logbrush
.lbStyle
= BS_HOLLOW
;
229 logbrush
.lbColor
= 0;
230 logbrush
.lbHatch
= 0;
231 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
232 Rectangle(hdc
, x1
, y1
, x2
, y2
);
233 DeleteObject(SelectObject(hdc
, oldBrush
));
234 DeleteObject(SelectObject(hdc
, oldPen
));
235 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00000000));
236 oldBrush
= SelectObject(hdc
, CreateSolidBrush(0x00000000));
237 Rectangle(hdc
, x1
-1, y1
-1, x1
+2, y1
+2);
238 Rectangle(hdc
, x2
-2, y1
-1, x2
+2, y1
+2);
239 Rectangle(hdc
, x1
-1, y2
-2, x1
+2, y2
+1);
240 Rectangle(hdc
, x2
-2, y2
-2, x2
+2, y2
+1);
241 Rectangle(hdc
, (x1
+x2
)/2-1, y1
-1, (x1
+x2
)/2+2, y1
+2);
242 Rectangle(hdc
, (x1
+x2
)/2-1, y2
-2, (x1
+x2
)/2+2, y2
+1);
243 Rectangle(hdc
, x1
-1, (y1
+y2
)/2-1, x1
+2, (y1
+y2
)/2+2);
244 Rectangle(hdc
, x2
-2, (y1
+y2
)/2-1, x2
+1, (y1
+y2
)/2+2);
245 DeleteObject(SelectObject(hdc
, oldBrush
));
246 DeleteObject(SelectObject(hdc
, oldPen
));