The effect of the operations is further influenced by the brush style. A solid brush paints all pixels along the path with the foreground color. A dashed brush alternates the foreground and background segments, measured along the length of the path, according to the dash pattern. Foreground segments are painted with foreground color. The filling of background segments is affected by the setting of the Painter’s FillBg() flag: If FillBg() is true, background segments are painted with the background color. If the flag is false, background segments are left unpainted.
If the dash pattern is specified as an integer, the pattern used will be derived from the least-significant sixteen bits of that integer. These are left-shifted until there is a one bit in the sixteenth bit position. A pattern so specified will repeat every 16 pixels. The special integers 0x0 and 0xffff will result in a solid brush pattern.
If the dash pattern is specified as an array of integers, each element must be positive, as it describes the length of a dash segment. An odd number of elements will result in the pattern inverting each time it repeats. For instance, the pattern 0x01110 will produce 011101000101110 when repeated three times.
// Brush Example #include <ivplus/box.h> #include <ivplus/brush.h> #include <ivplus/frame.h> #include <ivplus/glue.h> #include <ivplus/message.h> #include <ivplus/painter.h> #include <ivplus/shape.h> #include <ivplus/world.h> // Define a line thickness used by brush. const int THICK = 6; // Create a derived class from message to make use of a painter and brush. class MyMessage : public Message { public: MyMessage(const char* text) : Message(text) { }; private: void Reconfig(); void Redraw(IntCoord, IntCoord, IntCoord, IntCoord); Painter* painter; }; void MyMessage::Reconfig() { // Create a painter whose attributes are set below. painter = new Painter(output); // Create a brush with the given pattern and width. const Brush* b = new Brush(0xff00, THICK); // Ask painter to use this brush for drawing. painter->SetBrush(b); Message::Reconfig(); // Make some space for drawing, shape is defined in Interactor. shape->width += 2*THICK; shape->height += 2*THICK; }; void MyMessage::Redraw(IntCoord xmin, IntCoord ymin, IntCoord xmax, IntCoord ymax) { // This will draw the text. Message::Redraw(xmin, ymin, xmax, ymax); // Draw a rectangle using attributes of painter. painter->Rect(canvas, THICK/2, THICK/2, shape->width-THICK/2, shape->height-THICK/2); }; int main(int argc, char **argv) { World* world = new World("MyApp", argc, argv); // Create a two line Message. MyMessage* msg = new MyMessage("Brush Example\n Message with a border"); // Enclose the msg in a box with glues around it. VBox* mainbox = new VBox(new VGlue, new HBox(new HGlue, msg, new HGlue), new VGlue); //Map the window. world->InsertApplication(new Frame(mainbox, 1, BevelOut)); //Enter the event loop. world->Run(); return 0; }
brush.h