2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/drawing.c
5 * PURPOSE: The drawing functions used by the tools
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
16 Line(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int thickness
)
18 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, color
));
19 MoveToEx(hdc
, x1
, y1
, NULL
);
21 DeleteObject(SelectObject(hdc
, oldPen
));
25 Rect(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
29 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
30 logbrush
.lbStyle
= (style
== 0) ? BS_HOLLOW
: BS_SOLID
;
31 logbrush
.lbColor
= (style
== 2) ? fg
: bg
;
33 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
34 Rectangle(hdc
, x1
, y1
, x2
, y2
);
35 DeleteObject(SelectObject(hdc
, oldBrush
));
36 DeleteObject(SelectObject(hdc
, oldPen
));
40 Ellp(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
44 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
45 logbrush
.lbStyle
= (style
== 0) ? BS_HOLLOW
: BS_SOLID
;
46 logbrush
.lbColor
= (style
== 2) ? fg
: bg
;
48 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
49 Ellipse(hdc
, x1
, y1
, x2
, y2
);
50 DeleteObject(SelectObject(hdc
, oldBrush
));
51 DeleteObject(SelectObject(hdc
, oldPen
));
55 RRect(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, int style
)
59 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
60 logbrush
.lbStyle
= (style
== 0) ? BS_HOLLOW
: BS_SOLID
;
61 logbrush
.lbColor
= (style
== 2) ? fg
: bg
;
63 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
64 RoundRect(hdc
, x1
, y1
, x2
, y2
, 16, 16);
65 DeleteObject(SelectObject(hdc
, oldBrush
));
66 DeleteObject(SelectObject(hdc
, oldPen
));
70 Poly(HDC hdc
, POINT
* lpPoints
, int nCount
, int fg
, int bg
, int thickness
, int style
, BOOL closed
)
74 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
75 logbrush
.lbStyle
= (style
== 0) ? BS_HOLLOW
: BS_SOLID
;
76 logbrush
.lbColor
= (style
== 2) ? fg
: bg
;
78 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
80 Polygon(hdc
, lpPoints
, nCount
);
82 Polyline(hdc
, lpPoints
, nCount
);
83 DeleteObject(SelectObject(hdc
, oldBrush
));
84 DeleteObject(SelectObject(hdc
, oldPen
));
88 Bezier(HDC hdc
, POINT p1
, POINT p2
, POINT p3
, POINT p4
, int color
, int thickness
)
96 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, color
));
97 PolyBezier(hdc
, fourPoints
, 4);
98 DeleteObject(SelectObject(hdc
, oldPen
));
102 Fill(HDC hdc
, int x
, int y
, int color
)
104 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
105 ExtFloodFill(hdc
, x
, y
, GetPixel(hdc
, x
, y
), FLOODFILLSURFACE
);
106 DeleteObject(SelectObject(hdc
, oldBrush
));
110 Erase(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int radius
)
114 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
115 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
116 for(a
= 0; a
<= 100; a
++)
117 Rectangle(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - radius
+ 1,
118 (y1
* (100 - a
) + y2
* a
) / 100 - radius
+ 1, (x1
* (100 - a
) + x2
* a
) / 100 + radius
+ 1,
119 (y1
* (100 - a
) + y2
* a
) / 100 + radius
+ 1);
120 DeleteObject(SelectObject(hdc
, oldBrush
));
121 DeleteObject(SelectObject(hdc
, oldPen
));
125 Replace(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int radius
)
128 for(a
= 0; a
<= 100; a
++)
129 for(y
= (y1
* (100 - a
) + y2
* a
) / 100 - radius
+ 1;
130 y
< (y1
* (100 - a
) + y2
* a
) / 100 + radius
+ 1; y
++)
131 for(x
= (x1
* (100 - a
) + x2
* a
) / 100 - radius
+ 1;
132 x
< (x1
* (100 - a
) + x2
* a
) / 100 + radius
+ 1; x
++)
133 if (GetPixel(hdc
, x
, y
) == fg
)
134 SetPixel(hdc
, x
, y
, bg
);
138 Airbrush(HDC hdc
, short x
, short y
, int color
, int r
)
142 for(b
= -r
; b
<= r
; b
++)
143 for(a
= -r
; a
<= r
; a
++)
144 if ((a
* a
+ b
* b
<= r
* r
) && (rand() % 4 == 0))
145 SetPixel(hdc
, x
+ a
, y
+ b
, color
);
149 Brush(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int style
)
151 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
152 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
157 for(a
= 0; a
<= 100; a
++)
158 Ellipse(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 3, (y1
* (100 - a
) + y2
* a
) / 100 - 3,
159 (x1
* (100 - a
) + x2
* a
) / 100 + 4, (y1
* (100 - a
) + y2
* a
) / 100 + 4);
162 for(a
= 0; a
<= 100; a
++)
163 Ellipse(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 1, (y1
* (100 - a
) + y2
* a
) / 100 - 1,
164 (x1
* (100 - a
) + x2
* a
) / 100 + 3, (y1
* (100 - a
) + y2
* a
) / 100 + 3);
167 MoveToEx(hdc
, x1
, y1
, NULL
);
169 SetPixel(hdc
, x2
, y2
, color
);
172 for(a
= 0; a
<= 100; a
++)
173 Rectangle(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 3, (y1
* (100 - a
) + y2
* a
) / 100 - 3,
174 (x1
* (100 - a
) + x2
* a
) / 100 + 5, (y1
* (100 - a
) + y2
* a
) / 100 + 5);
177 for(a
= 0; a
<= 100; a
++)
178 Rectangle(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 2, (y1
* (100 - a
) + y2
* a
) / 100 - 2,
179 (x1
* (100 - a
) + x2
* a
) / 100 + 3, (y1
* (100 - a
) + y2
* a
) / 100 + 3);
182 for(a
= 0; a
<= 100; a
++)
183 Rectangle(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 1, (y1
* (100 - a
) + y2
* a
) / 100 - 1,
184 (x1
* (100 - a
) + x2
* a
) / 100 + 1, (y1
* (100 - a
) + y2
* a
) / 100 + 1);
187 for(a
= 0; a
<= 100; a
++)
189 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 3, (y1
* (100 - a
) + y2
* a
) / 100 + 5, NULL
);
190 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 5, (y1
* (100 - a
) + y2
* a
) / 100 - 3);
194 for(a
= 0; a
<= 100; a
++)
196 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 2, (y1
* (100 - a
) + y2
* a
) / 100 + 3, NULL
);
197 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 3, (y1
* (100 - a
) + y2
* a
) / 100 - 2);
201 for(a
= 0; a
<= 100; a
++)
203 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 1, (y1
* (100 - a
) + y2
* a
) / 100 + 1, NULL
);
204 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 1, (y1
* (100 - a
) + y2
* a
) / 100 - 1);
208 for(a
= 0; a
<= 100; a
++)
210 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 3, (y1
* (100 - a
) + y2
* a
) / 100 - 3, NULL
);
211 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 5, (y1
* (100 - a
) + y2
* a
) / 100 + 5);
215 for(a
= 0; a
<= 100; a
++)
217 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 2, (y1
* (100 - a
) + y2
* a
) / 100 - 2, NULL
);
218 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 3, (y1
* (100 - a
) + y2
* a
) / 100 + 3);
222 for(a
= 0; a
<= 100; a
++)
224 MoveToEx(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 - 1, (y1
* (100 - a
) + y2
* a
) / 100 - 1, NULL
);
225 LineTo(hdc
, (x1
* (100 - a
) + x2
* a
) / 100 + 1, (y1
* (100 - a
) + y2
* a
) / 100 + 1);
229 DeleteObject(SelectObject(hdc
, oldBrush
));
230 DeleteObject(SelectObject(hdc
, oldPen
));
234 RectSel(HDC hdc
, short x1
, short y1
, short x2
, short y2
)
238 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
239 logbrush
.lbStyle
= BS_HOLLOW
;
240 logbrush
.lbColor
= 0;
241 logbrush
.lbHatch
= 0;
242 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
243 Rectangle(hdc
, x1
, y1
, x2
, y2
);
244 DeleteObject(SelectObject(hdc
, oldBrush
));
245 DeleteObject(SelectObject(hdc
, oldPen
));
249 SelectionFrame(HDC hdc
, int x1
, int y1
, int x2
, int y2
)
253 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
254 logbrush
.lbStyle
= BS_HOLLOW
;
255 logbrush
.lbColor
= 0;
256 logbrush
.lbHatch
= 0;
257 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
258 Rectangle(hdc
, x1
, y1
, x2
, y2
);
259 DeleteObject(SelectObject(hdc
, oldBrush
));
260 DeleteObject(SelectObject(hdc
, oldPen
));
261 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00000000));
262 oldBrush
= SelectObject(hdc
, CreateSolidBrush(0x00000000));
263 Rectangle(hdc
, x1
- 1, y1
- 1, x1
+ 2, y1
+ 2);
264 Rectangle(hdc
, x2
- 2, y1
- 1, x2
+ 2, y1
+ 2);
265 Rectangle(hdc
, x1
- 1, y2
- 2, x1
+ 2, y2
+ 1);
266 Rectangle(hdc
, x2
- 2, y2
- 2, x2
+ 2, y2
+ 1);
267 Rectangle(hdc
, (x1
+ x2
) / 2 - 1, y1
- 1, (x1
+ x2
) / 2 + 2, y1
+ 2);
268 Rectangle(hdc
, (x1
+ x2
) / 2 - 1, y2
- 2, (x1
+ x2
) / 2 + 2, y2
+ 1);
269 Rectangle(hdc
, x1
- 1, (y1
+ y2
) / 2 - 1, x1
+ 2, (y1
+ y2
) / 2 + 2);
270 Rectangle(hdc
, x2
- 2, (y1
+ y2
) / 2 - 1, x2
+ 1, (y1
+ y2
) / 2 + 2);
271 DeleteObject(SelectObject(hdc
, oldBrush
));
272 DeleteObject(SelectObject(hdc
, oldPen
));