[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Brush(3X) manual page Table of Contents

Name

Brush - defines line style and thickness for Painter

Synopsis

#include <ivplus/brush.h>

Description

Brush defines the line thickness and style for Painter operations that draw lines, curves and unfilled shapes. The effect of these operations is as if a line segment equal in length to the brush’s width were dragged along an infinitely thin path between specified coordinates. At each point along the path the brush is angled perpendicular to the path. As a special case, a brush width of 0 specifies a minimal width line. Many devices can render minimal width lines more quickly than wide lines, but the resultant display may be device dependent.

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.

Class Hierarchy

Brush -> Resource

Constructors

Brush(FloatCoord width)

Defines a solid brush with a specified width.

Brush(int pattern, FloatCoord width)

Defines a brush with a specified line style and width.

Brush(const int* pattern, int count, FloatCoord width)

Defines a brush with a specified line style, dash count and width. The least significant 16 bits of pattern are interpreted as a bit pattern. One bits specify the foreground segments and zero bits specify background segments.

Brush(const int* pattern, int count, FloatCoord width)

Defines a brush with a specified dash pattern, dash count and width. Each element of the pattern array specifies the length of a dash segment. Each element is the inverse of the previous element. The first element specifies the initial dash segment drawn in the foreground color. An odd number of elements means that the pattern will be inverted in alternation as it is rendered.

Public Operations

unsigned int Width () const

Returns the brush’s width in pixels.

BrushRep* rep(Display*) const

Returns a pointer to the BrushRep for the brush. The BrushRep class is a low level interface to X Windows. It is not expected that developers will need details of the BrushRep interface so the BrushRep class is not documented.

X Resources

None.

Examples


//                          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;
}

Files


brush.h

See Also

Painter(3X) , Resource(3X) .


Table of Contents