BPicture

Derived from: public BArchivable

Declared in: be/interface/Picture.h

Library: libbe.so

[method summary]

A BPicture object represents a set of drawing instructions that are executed when the object is passed to BView's DrawPicture() function. Because it contains drawing instructions rather than an actual image, a BPicture (unlike a BBitmap) is independent of the resolution of the display device.


Recording a Picture

Drawing instructions are captured by bracketing them with calls to a BView's BeginPicture() and EndPicture() functions. A BPicture object is passed to BeginPicture(); EndPicture() returns the same object, fully initialized. For example:

   BPicture *myPict;
   someView->BeginPicture(new BPicture);
   /* drawing code goes here */
   myPict = someView->EndPicture();

The BPicture object records all of the drawing instructions given to the BView following the BeginPicture() call and preceding the EndPicture() call. Only drawing that the BView does is recorded; drawing done by children and other views attached to the window is ignored, as is everything except drawing code.

Drawing instructions that are captured between BeginPicture() and EndPicture() do not also produce a rendered image; ignored instructions may be rendered if they draw into the visible region of an on-screen window.

Any picture data in the BPicture passed to BeginPicture() is cleared; if you'd instead like to append to the BPicture, begin the picture recording with AppendPicture() instead. As with BeginPicture(), each AppendPicture() must have a corresponding EndPicture().


The Picture Definition

The picture captures everything that affects the image that's drawn. It takes a snapshot of the BView's graphics parameters--the pen size, high and low colors, font size, and so on--at the time BeginPicture() is called. It then captures all subsequent modifications to those parameters, such as calls to MovePenTo(), SetLowColor(), and SetFontSize().

The picture records all primitive drawing instruction (DrawBitmap(), StrokeEllipse(), FillRect(), etc.) and can even include calls to DrawPicture().

The BPicture records the graphic state at the time the picture instructions were recorded, and uses that state when the picture is drawn. You don't have to explicitly set the graphic state during the recording.

The picture makes its own copy of any data that's passed during the recording session, including bitmaps passed to DrawBitmap() and picture data passed to DrawPicture().

See also: BView::BeginPicture(), BView::DrawPicture(), the BPictureButton class


Constructor and Destructor


BPicture()

      BPicture(void)
      BPicture(const BPicture &picture)
      BPicture(BMessage *archive)

Initializes the BPicture object by ensuring that it's empty, or by copying data from another picture or archive of a BPicture object.


~BPicture()

      virtual ~BPicture()

Destroys the Application Server's record of the BPicture object and deletes all its picture data.


Static Functions


Instantiate()

      static BArchivable *Instantiate(BMessage *archive) 

Returns a new BPicture object, allocated by new and created with the version of the constructor that takes a BMessage archive. However, if the archive message doesn't contain BPicture data, this function returns NULL.

See also: BArchivable::Instantiate(), instantiate_object(), Archive()


Member Functions


Archive()

      virtual status_t Archive(BMessage *archive, bool deep = true) const

Calls the inherited version of Archive(), then adds the picture data to the BMessage archive.

See also: BArchivable::Archive(), Instantiate() static function


Play()

      virtual status_t *Play(void **callBackTable, int32 tableEntries, void *user) 

Plays back a picture using a user's rendering functions. The functions are passed in callBackTable, an array of function pointers. tableEntries contains the number of functions in the table. The functions perform various tasks such as drawing lines and text. user is passed to each function, providing a hook for passing additional data to the call back functions. The functions, along with their positions in the call back table, are detailed below.

Index Function prototype
0 no operation
1 MovePenBy(void *user, BPoint delta)
2 StrokeLine(void *user, BPoint start, BPoint end)
3 StrokeRect(void *user, BRect rect)
4 FillRect(void *user, BRect rect)
5 StrokeRoundRect(void *user, BRect rect, BPoint radii)
6 FillRoundRect(void *user, BRect rect, BPoint radii)
7 StrokeBezier(void *user, BPoint *control)
8 FillBezier(void *user, BPoint *control)
9 StrokeArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta)
10 FillArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta)
11 StrokeEllipse(void *user, BPoint center, BPoint radii)
12 FillEllipse(void *user, BPoint center, BPoint radii)
13 StrokePolygon(void *user, int32 numPoints, BPoint *points, bool isClosed)
14 FillPolygon(void *user, int32 numPoints, BPoint *points, bool isClosed)
15 Reserved
16 Reserved
17 DrawString(void *user, char *string, float deltax, float deltay)
18 DrawPixels(void *user, BRect src, BRect dest, int32 width, int32 height,
int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data)
19 Reserved
20 SetClippingRects(void *user, BRect *rects, uint32 numRects)
21 Reserved
22 PushState(void *user)
23 PopState(void *user)
24 EnterStateChange(void *user)
25 ExitStateChange(void *user)
26 EnterFontState(void *user)
27 ExitFontState(void *user)
28 SetOrigin(void *user, BPoint pt)
29 SetPenLocation(void *user, BPoint pt)
30 SetDrawingMode(void *user, drawing_mode mode)
31 SetLineMode(void *user, cap_mode capMode, join_mode joinMode,
float miterLimit)
32 SetPenSize(void *user, float size)
33 SetForeColor(void *user, rgb_color color)
34 SetBackColor(void *user, rgb_color color)
35 SetStipplePattern(void *user, pattern p)
36 SetScale(void *user, float scale)
37 SetFontFamily(void *user, char *family)
38 SetFontStyle(void *user, char *style)
39 SetFontSpacing(void *user, int32 spacing)
40 SetFontSize(void *user, float size)
41 SetFontRotate(void *user, float rotation)
42 SetFontEncoding(void *user, int32 encoding)
43 SetFontFlags(void *user, int32 flags)
44 SetFontShear(void *user, float shear)
45 Reserved
46 SetFontFace(void *user, int32 flags)

While many of these functions are similar to those found in BView, there are some important differences:

degrees = (rotation*180.0)/3.14159265369);


Archived Fields

The Archive() function adds the following fields to its BMessage argument:

Field Type code Meaning
"_ver" B_INT32_TYPE Always 1.
"_endian" B_INT8_TYPE Endianness of the data. Always B_HOST_IS_BENDIAN.
"_data" B_RAW_TYPE The BPicture data.






The Be Book, in lovely HTML, for BeOS Release 4.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified August 3, 1998.