setfillstyle
This function is used to set current device fill style.
void setfillstyle(
FILLSTYLE* pstyle
);
void setfillstyle(
int style,
long hatch = NULL,
IMAGE* ppattern = NULL
);
void setfillstyle(
BYTE* ppattern8x8
);
Parameters
pstyle
A pointer to fill the style FILL FILLSTYLE.
style
Specify the fill style. Can be the following macro or value:
Macro | Value | Description |
---|---|---|
BS_SOLID | 0 | Solid filling. |
BS_NULL | 1 | Do not fill. |
BS_HATCHED | 2 | Pattern fill. |
BS_PATTERN | 3 | Custom hatch. |
BS_DIBPATTERN | 5 | Custom image fill. |
hatch
Specifies a hatch pattern, which is only valid if the style is BS-HATCHED. The color of the fill pattern is set by the function setfillcolor, and the background area is set by the function setbkmode using the background color or by the function setbkmode. The hatch parameter can be the following macro or value:
Macro | Value | Description |
---|---|---|
HS_HORIZONTAL | 0 | |
HS_VERTICAL | 1 | |
HS_FDIAGONAL | 2 | |
HS_BDIAGONAL | 3 | |
HS_CROSS | 4 | |
HS_DIAGCROSS | 5 |
ppattern
Specify a custom hatch pattern or image, only valid if the style is BS-PATTERN or BS-DIBPATTERN.
When the style is BS-PATTERN, the IMAGE object that the ppattern points to represents a custom hatch pattern, and black (BLACK) in image corresponds to the background area, and non-black corresponds to the pattern area. The color of the pattern area is set by the function settextcolor.
When style is BS-DIBPATTERN, the IMAGE object that the ppattern points to represents a custom fill image, which is populated by the fill unit.
ppattern8x8
Specify a custom hatch pattern that works the same as BS-PATTERN, which defines the hatch pattern for the 8 x 8 area with an BYTE8 array. In the array, each element represents a row of styles, and the BYTE type has 8 bits, representing the state of each point from left to low, which makes up 8 x 8 fill cells that flatten the fill unit to implement the fill. The corresponding binary bit is 0 for the background area and 1 for the pattern area.
Return Value
None
Examples
The following snippet sets solid padding:
setfillstyle(BS_SOLID);
The following snippet sets the fill pattern as slash fill:
setfillstyle(BS_HATCHED, HS_BDIAGONAL);
The following snippet sets a custom image fill (a fill image specified by res\bk.jpg):
IMAGE img;
loadimage(&img, _T("res\\bk.jpg"));
setfillstyle(BS_DIBPATTERN, NULL, &img);
The following full code sets a custom fill pattern (small rectangle fill) and fills a triangle with that pattern:
#include <conio.h>
#include <graphics.h>
int main()
{
// Create a drawing windo
initgraph(640, 480);
// Define a fill unit
IMAGE img(10, 8);
// Draw a fill unit
SetWorkingImage(&img); // Set the drawing target to an img object.
setbkcolor(BLACK); // Black area is background color
cleardevice();
setfillcolor(WHITE); // White area is a custom color
solidrectangle(1, 1, 8, 5);
SetWorkingImage(NULL); // Recovery drawing target is the default graphics window
// Set the fill style as a custom fill pattern
setfillstyle(BS_PATTERN, NULL, &img);
// Set the fill color of a custom pattern
settextcolor(GREEN);
// Draw borderless fill triangles
POINT pts[] = { {50, 50}, {50, 200}, {300, 50} };
solidpolygon(pts, 3);
// Press any key to exit
_getch();
closegraph();
}
The following snippet sets a custom fill pattern (circular hatch):
setfillstyle((BYTE*)"\x3e\x41\x80\x80\x80\x80\x80\x41");
The following snippet sets a custom fill pattern (thin slash clip thick slash pattern fill):
setfillstyle((BYTE*)"\x5a\x2d\x96\x4b\xa5\xd2\x69\xb4");