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
, BOOL filled
)
25 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
27 if (filled
) logbrush
.lbStyle
= BS_SOLID
; else logbrush
.lbStyle
= BS_HOLLOW
;
28 logbrush
.lbColor
= bg
;
30 HBRUSH oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
31 Rectangle(hdc
, x1
, y1
, x2
, y2
);
32 DeleteObject(SelectObject(hdc
, oldBrush
));
33 DeleteObject(SelectObject(hdc
, oldPen
));
36 void Ellp(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, BOOL filled
)
38 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
40 if (filled
) logbrush
.lbStyle
= BS_SOLID
; else logbrush
.lbStyle
= BS_HOLLOW
;
41 logbrush
.lbColor
= bg
;
43 HBRUSH oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
44 Ellipse(hdc
, x1
, y1
, x2
, y2
);
45 DeleteObject(SelectObject(hdc
, oldBrush
));
46 DeleteObject(SelectObject(hdc
, oldPen
));
49 void RRect(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int fg
, int bg
, int thickness
, BOOL filled
)
51 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, thickness
, fg
));
53 if (filled
) logbrush
.lbStyle
= BS_SOLID
; else logbrush
.lbStyle
= BS_HOLLOW
;
54 logbrush
.lbColor
= bg
;
56 HBRUSH oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
57 RoundRect(hdc
, x1
, y1
, x2
, y2
, 16, 16);
58 DeleteObject(SelectObject(hdc
, oldBrush
));
59 DeleteObject(SelectObject(hdc
, oldPen
));
62 void Fill(HDC hdc
, int x
, int y
, int color
)
64 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
65 ExtFloodFill(hdc
, x
, y
, GetPixel(hdc
, x
, y
), FLOODFILLSURFACE
);
66 DeleteObject(SelectObject(hdc
, oldBrush
));
69 void Erase(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int radius
)
71 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
72 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
74 for (a
=0; a
<=100; a
++)
75 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);
76 DeleteObject(SelectObject(hdc
, oldBrush
));
77 DeleteObject(SelectObject(hdc
, oldPen
));
80 void Airbrush(HDC hdc
, short x
, short y
, int color
, int r
)
84 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
);
87 void Brush(HDC hdc
, short x1
, short y1
, short x2
, short y2
, int color
, int style
)
89 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, color
));
90 HBRUSH oldBrush
= SelectObject(hdc
, CreateSolidBrush(color
));
95 for (a
=0; a
<=100; a
++)
96 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);
99 for (a
=0; a
<=100; a
++)
100 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);
103 MoveToEx(hdc
, x1
, y1
, NULL
);
105 SetPixel(hdc
, x2
, y2
, color
);
108 for (a
=0; a
<=100; a
++)
109 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);
112 for (a
=0; a
<=100; a
++)
113 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);
116 for (a
=0; a
<=100; a
++)
117 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);
120 for (a
=0; a
<=100; a
++)
122 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100+5, NULL
);
123 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+5, (y1
*(100-a
)+y2
*a
)/100-3);
127 for (a
=0; a
<=100; a
++)
129 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-2, (y1
*(100-a
)+y2
*a
)/100+3, NULL
);
130 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100-2);
134 for (a
=0; a
<=100; a
++)
136 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100+1, NULL
);
137 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+1, (y1
*(100-a
)+y2
*a
)/100-1);
141 for (a
=0; a
<=100; a
++)
143 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-3, (y1
*(100-a
)+y2
*a
)/100-3, NULL
);
144 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+5, (y1
*(100-a
)+y2
*a
)/100+5);
148 for (a
=0; a
<=100; a
++)
150 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-2, (y1
*(100-a
)+y2
*a
)/100-2, NULL
);
151 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+3, (y1
*(100-a
)+y2
*a
)/100+3);
155 for (a
=0; a
<=100; a
++)
157 MoveToEx(hdc
, (x1
*(100-a
)+x2
*a
)/100-1, (y1
*(100-a
)+y2
*a
)/100-1, NULL
);
158 LineTo(hdc
, (x1
*(100-a
)+x2
*a
)/100+1, (y1
*(100-a
)+y2
*a
)/100+1);
162 DeleteObject(SelectObject(hdc
, oldBrush
));
163 DeleteObject(SelectObject(hdc
, oldPen
));
166 void RectSel(HDC hdc
, short x1
, short y1
, short x2
, short y2
)
168 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
170 logbrush
.lbStyle
= BS_HOLLOW
;
171 logbrush
.lbColor
= 0;
172 logbrush
.lbHatch
= 0;
173 HBRUSH oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
174 Rectangle(hdc
, x1
, y1
, x2
, y2
);
175 DeleteObject(SelectObject(hdc
, oldBrush
));
176 DeleteObject(SelectObject(hdc
, oldPen
));
179 void SelectionFrame(HDC hdc
, int x1
, int y1
, int x2
, int y2
)
181 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_DOT
, 1, 0x00000000));
183 logbrush
.lbStyle
= BS_HOLLOW
;
184 logbrush
.lbColor
= 0;
185 logbrush
.lbHatch
= 0;
186 HBRUSH oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
187 Rectangle(hdc
, x1
, y1
, x2
, y2
);
188 DeleteObject(SelectObject(hdc
, oldBrush
));
189 DeleteObject(SelectObject(hdc
, oldPen
));
190 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00000000));
191 oldBrush
= SelectObject(hdc
, CreateSolidBrush(0x00000000));
192 Rectangle(hdc
, x1
-1, y1
-1, x1
+2, y1
+2);
193 Rectangle(hdc
, x2
-2, y1
-1, x2
+2, y1
+2);
194 Rectangle(hdc
, x1
-1, y2
-2, x1
+2, y2
+1);
195 Rectangle(hdc
, x2
-2, y2
-2, x2
+2, y2
+1);
196 Rectangle(hdc
, (x1
+x2
)/2-1, y1
-1, (x1
+x2
)/2+2, y1
+2);
197 Rectangle(hdc
, (x1
+x2
)/2-1, y2
-2, (x1
+x2
)/2+2, y2
+1);
198 Rectangle(hdc
, x1
-1, (y1
+y2
)/2-1, x1
+2, (y1
+y2
)/2+2);
199 Rectangle(hdc
, x2
-2, (y1
+y2
)/2-1, x2
+1, (y1
+y2
)/2+2);
200 DeleteObject(SelectObject(hdc
, oldBrush
));
201 DeleteObject(SelectObject(hdc
, oldPen
));