Painter(3X) manual page
Table of Contents
Painter - perform graphics output
#include <ivplus/painter.h>
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.
Painter->Resource
Creates a new painter.
Creates
a new painter, copying all of the graphics state from the passed painter.
Returns the painter’s fill mode.
Draws a B-spline
defined by the n control vertices.
Draws a circle with center <x, y> and radius r.
Fills a rectangle with
opposite corners specified by <x1, y1> and <x2, y2> with the current pattern
and background color.
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.
Draws a closed B-spline defined by the n control vertices. The
last point is connected to the first point.
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.
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.
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.
Draws an ellipse with center <x, y>, horizontal radius xr, and vertical
radius yr.
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.
Draws a filled B-spline defined by the n control
vertices. The last point is connected to the first point.
Draws a filled circle with center <x, y> and
radius r.
Draws a filled ellipse with center <x, y>, horizontal radius xr, and vertical
radius yr.
Fills
the area inside a polygon defined by the n vertices using the current fill
pattern and colors.
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.
Returns a pointer
to the background color. The default background color is determined by the
world’s default properties.
Returns the painter’s
brush. The default brush is the value returned by a call to Brush(0xffff,
0).
Returns a pointer to the foreground color.
The default foreground color is determined by the world’s default properties.
Returns the painter’s text font. The default is determined
by the world’s default properties.
Returns
the origin by which all coordinates are offset.
Returns the painter’s fill pattern.
Returns the current output position’s coordinates.
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).
Returns the
current transformer.
Draws a line on the canvas between two points, starting
at <x1, y1> and ending at <x2, y2> (inclusive).
Sets the current output position of the painter. The output position is
used and updated by Text() and CurveTo().
Draws n-1 connected vectors using the arrays for
starting and ending points.
Set n points to the current foreground color.
Removes
the clipping restrictions so that operations affect the entire canvas.
Sets the point at <x, y> to the
current foreground color.
Draws n closed sets of vectors using the arrays for starting
and closing points.
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.
Draws a rectangle with opposite corners specified by <x1,
y1> and <x2, y2>.
Rotates the painter output angle
degrees.
Scales the pointer output by a factor
of x in the x-axis and y in the y-axis.
Sets
the painter’s brush to brush. The default brush is determined by the world’s
default properties.
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.
Sets the painter’s text font. The default font is determined
by the world’s default properties.
Sets the
origin by which all coordinates are offset. The default origin is <0, 0>.
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.
Sets the painter’s fill pattern. The default is a solid pattern.
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.
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.
Sets
the transformer to be used by the painter.
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.
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.
Draws n characters of the text str at the indicated location using the
current font and text style.
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.
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.
Coordinates
passed to drawing operations are transformed according to the current translation
(cumulative). Painter output will be drawn relative to <dx, dy>.
None.
// 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;
}
painter.h
Bitmap(3X)
, Brush(3X)
, Canvas(3X)
, Color(3X)
, Font(3X)
, Pattern(3X)
,
Raster(3X)
, Resource(3X)
, Transformer(3X)
, World(3X)
.
Table of Contents
- Name
- Synopsis
- Description
- Class Hierarchy
- Constructors
- Public Operations
- boolean BgFilled() const
- void BSpline(Canvas*, IntCoord x[], IntCoord y[], int n)
- void Circle(Canvas*, IntCoord x, IntCoord y, int r)
- void ClearRect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)
- void Clip(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)
- void ClosedBSpline(Canvas*, IntCoord x[], IntCoord y[], int n)
- void Copy(Canvas* src, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2, Canvas* dst, IntCoord x0, IntCoord y0)
- void Curve(Canvas*, IntCoord x0, IntCoord y0, IntCoord x1,
- void CurveTo(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2, IntCoord x3, IntCoord y3)
- void Ellipse(Canvas*, IntCoord x, IntCoord y, int xr, int yr)
- void FillBg(boolean mode)
- void FillBSpline(Canvas*, IntCoord x[], IntCoord y[], int n)
- void FillCircle(Canvas*, IntCoord x, IntCoord y, int r)
- void FillEllipse(Canvas*, IntCoord x, IntCoord y, int xr, int yr)
- void FillPolygon(Canvas*, IntCoord x[], IntCoord y[], int n)
- void FillRect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)
- const Color* GetBgColor() const
- const Brush* GetBrush() const
- const Color* GetFgColor() const
- Font* GetFont()
- void GetOrigin(int& x0, int& y0)
- const Pattern* GetPattern() const
- void GetPosition(int &x, int &y) const
- int GetStyle()
- Transformer * GetTransformer() const
- void Line(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)
- void MoveTo(IntCoord x, IntCoord y)
- void MultiLine(Canvas*, IntCoord x[], IntCoord y[], int n)
- void MultiPoint(Canvas*, IntCoord x[], IntCoord y[], int n)
- void NoClip()
- void Point(Canvas*, IntCoord x, IntCoord y)
- void Polygon(Canvas*, IntCoord x[], IntCoord y[], int n)
- void RasterRect(Canvas*, IntCoord x, IntCoord y, Raster*)
- void Rect(Canvas*, IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2)
- void Rotate(float angle)
- void Scale(float x, float y)
- void SetBrush(const Brush* brush)
- void SetColors(const Color* fg, const Color* bg)
- void SetFont(Font*)
- void SetOrigin(int x0, int y0)
- void SetOverwrite(boolean)
- void SetPattern(const Pattern*)
- void SetPlaneMask(int mask)
- void SetStyle(int style)
- void SetTransformer(Transformer*)
- void Stencil(Canvas*, IntCoord x, IntCoord y, Bitmap* image, Bitmap* mask = nil)
- void Text(Canvas*, const char* str, IntCoord x, IntCoord y)
- void Text(Canvas*, const char* str, int n, IntCoord x, IntCoord y)
- void Text(Canvas*, const char* str)
- void Text(Canvas*, const char* str, int n)
- void Translate(float dx, float dy)
- X Resources
- Examples
- Files
- See Also