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

Name

Painter - perform graphics output

Synopsis

#include <ivplus/painter.h>

Description

Painter is a class that provides graphics operations for drawing on a canvas. The state of a painter defines the graphics context for the drawing operations and includes teh following: a brush, foreground and background colors, a fill pattern and mode, a text font, a text style, an output origin and current position, and a transformation matrix.

Class Hierarchy

Painter->Resource

Constructors

Painter()

Creates a new painter.

Painter(Painter&)

Creates a new painter, copying all of the graphics state from the passed painter.

Public Operations

boolean BgFilled() const

Returns the painter’s fill mode.

void BSpline(Canvas*, IntCoord x[], IntCoord y[], int n)

Draws a B-spline defined by the n control vertices.

void Circle(Canvas*, IntCoord x, IntCoord y, int r)

Draws a circle with center <x, y> and radius r.

void ClearRect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)

Fills a rectangle with opposite corners specified by <x1, y1> and <x2, y2> with the current pattern and background color.

void Clip(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)

The Clip() operation restricts output operations to the specified region of the canvas specified by <x1, y1>. Only one clipping region may be in effect at a time.

void ClosedBSpline(Canvas*, IntCoord x[], IntCoord y[], int n)

Draws a closed B-spline defined by the n control vertices. The last point is connected to the first point.

void Copy(Canvas* src, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2, Canvas* dst, IntCoord x0, IntCoord y0)

Reads a region of one canvas into memory, and writes the data from memory into a region of another canvas (or within canvas if src and dst are the same). The point <x0, y0> is the lower-left corner of the destination region. Note that Read() and Write() are superseded by operations that use Rasters.

void Curve(Canvas*, IntCoord x0, IntCoord y0, IntCoord x1,

Paints a Bezier curve on the canvas from the first point <x0, y0> to the last point <x3, y3>, but not going through the intermediate control points <x2, y2>. The curve will lie within the polygon formed by the four points. CurveTo() uses the current position for the first point.

void CurveTo(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2, IntCoord x3, IntCoord y3)

Paints a Bezier curve on the canvas from the first point <x0, y0> (the current position) to the last point <x3, y3>, but not going through the intermediate control points <x2, y2>. The curve will lie within the polygon formed by the four points.

void Ellipse(Canvas*, IntCoord x, IntCoord y, int xr, int yr)

Draws an ellipse with center <x, y>, horizontal radius xr, and vertical radius yr.

void FillBg(boolean mode)

Sets the painter’s fill mode. If mode is true, fill operations will set pixels corresponding to ones, in the current fill pattern, to the foreground color, and pixels corresponding to zeros to the background color. If false, then only foreground pixels will be set. The initial fill mode is true.

void FillBSpline(Canvas*, IntCoord x[], IntCoord y[], int n)

Draws a filled B-spline defined by the n control vertices. The last point is connected to the first point.

void FillCircle(Canvas*, IntCoord x, IntCoord y, int r)

Draws a filled circle with center <x, y> and radius r.

void FillEllipse(Canvas*, IntCoord x, IntCoord y, int xr, int yr)

Draws a filled ellipse with center <x, y>, horizontal radius xr, and vertical radius yr.

void FillPolygon(Canvas*, IntCoord x[], IntCoord y[], int n)

Fills the area inside a polygon defined by the n vertices using the current fill pattern and colors.

void FillRect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)

Draws a filled rectangle with opposite corners specified by <x1, y1> and <x2, y2>. The rectangle is filled using the current pattern and foreground color.

const Color* GetBgColor() const

Returns a pointer to the background color. The default background color is determined by the world’s default properties.

const Brush* GetBrush() const

Returns the painter’s brush. The default brush is the value returned by a call to Brush(0xffff, 0).

const Color* GetFgColor() const

Returns a pointer to the foreground color. The default foreground color is determined by the world’s default properties.

Font* GetFont()

Returns the painter’s text font. The default is determined by the world’s default properties.

void GetOrigin(int& x0, int& y0)

Returns the origin by which all coordinates are offset.

const Pattern* GetPattern() const

Returns the painter’s fill pattern.

void GetPosition(int &x, int &y) const

Returns the current output position’s coordinates.

int GetStyle()

Gets the painter’s text style. A text style is a bit vector. Existing predefined text styles are: Plain, Boldface, Underlined, Reversed, and Outlined (not currently implemented).

Transformer * GetTransformer() const

Returns the current transformer.

void Line(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)

Draws a line on the canvas between two points, starting at <x1, y1> and ending at <x2, y2> (inclusive).

void MoveTo(IntCoord x, IntCoord y)

Sets the current output position of the painter. The output position is used and updated by Text() and CurveTo().

void MultiLine(Canvas*, IntCoord x[], IntCoord y[], int n)

Draws n-1 connected vectors using the arrays for starting and ending points.

void MultiPoint(Canvas*, IntCoord x[], IntCoord y[], int n)

Set n points to the current foreground color.

void NoClip()

Removes the clipping restrictions so that operations affect the entire canvas.

void Point(Canvas*, IntCoord x, IntCoord y)

Sets the point at <x, y> to the current foreground color.

void Polygon(Canvas*, IntCoord x[], IntCoord y[], int n)

Draws n closed sets of vectors using the arrays for starting and closing points.

void RasterRect(Canvas*, IntCoord x, IntCoord y, Raster*)

Renders the raster with its lower-left corner at the position <x, y>. The current transformation matrix is applied to the raster. If the matrix specifies a transformation involving rotation or scaling, the resulting operation may proceed much more slowly than normal.

void Rect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)

Draws a rectangle with opposite corners specified by <x1, y1> and <x2, y2>.

void Rotate(float angle)

Rotates the painter output angle degrees.

void Scale(float x, float y)

Scales the pointer output by a factor of x in the x-axis and y in the y-axis.

void SetBrush(const Brush* brush)

Sets the painter’s brush to brush. The default brush is determined by the world’s default properties.

void SetColors(const Color* fg, const Color* bg)

Sets the painter’s colors. If either argument is nil, then the corresponding color is not changed. Defaults are determined by the world’s default properties.

void SetFont(Font*)

Sets the painter’s text font. The default font is determined by the world’s default properties.

void SetOrigin(int x0, int y0)

Sets the origin by which all coordinates are offset. The default origin is <0, 0>.

void SetOverwrite(boolean)

Sets whether a painter is allowed to write in subcanvases. If true, drawing operations will be able to write over the canvases of component interactors. If false, drawing operations will be clipped by any subcanvases. The default is false.

void SetPattern(const Pattern*)

Sets the painter’s fill pattern. The default is a solid pattern.

void SetPlaneMask(int mask)

Sets which bit planes are affected by drawing operations. If the Kth bit of mask is set, then display operations will draw on plane K.

void SetStyle(int style)

Sets the painter’s text style. A text style is a bit vector that can be assembled from the predefined style constants: Plain, Boldface, Underlined, Reversed, and Outlined (not currently implemented). The default style is Plain.

void SetTransformer(Transformer*)

Sets the transformer to be used by the painter.

void Stencil(Canvas*, IntCoord x, IntCoord y, Bitmap* image, Bitmap* mask = nil)

Paints foreground and background colors through a stencil formed by positioning the image and mask bitmaps with their origins at the point <x, y>. The foreground color is painted where the image bitmap has a true value and background color where image is false. However, only pixels corresponding to a true value in the mask bitmap are affected. A nil mask is equivalent to a mask of the same size and shape as image and containing all true values. The current transformation matrix is applied to both the image and mask bitmaps. If the matrix specifies a transformation involving rotation or scaling, the resulting operation may proceed much more slowly than normal.

void Text(Canvas*, const char* str, IntCoord x, IntCoord y)

Draws a string of text using the current font and text style. The <x, y> coordinates specify the lower-left corner of the bounding box of the text. The width of the bounding box is the width of the string as reported by the Font::Width() operation, and the height of the bounding box is the font height. Most fonts will result in output which only affects pixels within the bounding box. The current transformation matrix is applied to both the positions and the shapes of characters drawn. If the matrix specifies a transformation involving rotation or scaling, the resulting operation may proceed much more slowly than normal. If background fill mode is on, then the characters are drawn in the foreground color, and other pixels within the bounding box are set to the background color. If background fill mode is off, only the foreground pixels are set. If no coordinates are specified, then the current position (defined by MoveTo()) is used and updated to reflect the lower-right corner of the bounding box.

void Text(Canvas*, const char* str, int n, IntCoord x, IntCoord y)

Draws n characters of the text str at the indicated location using the current font and text style.

void Text(Canvas*, const char* str)

Draws a string of text using the current font and text style. The current position (defined by MoveTo()) is used and updated to reflect the lower-right corner of the bounding box.

void Text(Canvas*, const char* str, int n)

Draws n characters of the text str using the current font and text style. The current position (defined by MoveTo()) is used and updated to reflect the lower-right corner of the bounding box.

void Translate(float dx, float dy)

Coordinates passed to drawing operations are transformed according to the current translation (cumulative). Painter output will be drawn relative to <dx, dy>.

X Resources

None.

Examples


//                          Painter 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(); // can also use new Painter(output);
   // Make a new background color.
   const Color* bg = output->GetBgColor();
   // Use the same fg color as the Interactor::output.
   const Color* fg = output->GetFgColor();
   // Set the painter foreground and background colors.
   painter->SetColors(fg, bg);
   // 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)
{
   // Create the world to get the connection with the display.
   World* world = new World("MyApp", argc, argv);
   // Create a two line message.
   MyMessage* msg = new MyMessage("Painter Example\n Message with a border");
   // Create glues with natural size of 10 and infinite stretchability.
   VGlue* vglue = new VGlue(10);
   HGlue* hglue = new HGlue(10);
   // Enclose the msg in a box with glues around it.
   VBox* mainbox = new VBox(new VGlue(10), new HBox(new HGlue(10), msg,

                                                    new HGlue(10)), 
                            new VGlue(10));
   // Map the window.
   world->InsertApplication(new Frame(mainbox, 1, BevelOut));
   // Enter the event loop.
   world->Run();
   return 0;
}

Files


painter.h

See Also

Bitmap(3X) , Brush(3X) , Canvas(3X) , Color(3X) , Font(3X) , Pattern(3X) , Raster(3X) , Resource(3X) , Transformer(3X) , World(3X) .


Table of Contents