Documentation | InterfaceKit | Drawing
SYNOPSIS
Perl
use HaikuR1::Application; use HaikuR1::Window; use HaikuR1::View
Python
from HaikuR1.ApplicationKit import Application from HaikuR1.InterfaceKit import Window from HaikuR1.InterfaceKit import View
DESCRIPTION
This document contains the View functions that have to do with drawing - both the functions that actually do the drawing and the functions that relate to the drawing state.
These functions are mainly useful for:
However, the font and color methods may also be of more general use if you want to change only those aspects of a View, without otherwise customizing its behavior.
For more information on these methods, see https://www.haiku-os.org/legacy-docs/bebook/BView.html#BView_Graphics and https://www.haiku-os.org/legacy-docs/bebook/BView.html#BView_Drawing.
METHODS
Blending Mode
GetBlendingMode
SetBlendingMode
Gets or sets the blending mode.
Perl
$view->GetBlendingMode(); $view->SetBlendingMode($srcAlpha, $alphaFunc);
Python
view.GetBlendingMode() view.SetBlendingMode(srcAlpha, alphaFunc)
srcAlpha
An integer, one of the source alpha constants.
alphaFunc
An integer, one of the alpha function constants.
Clipping
GetClippingRegion
ConstrainClippingRegion
ClipToRect
ClipToInverseRect
ClipToPicture
ClipToInversePicture
ClipToShape
ClipToInverseShape
GetClippingRegion
returns the current clipping Region (the area where
the View is allowed to draw).
ConstrainClippingRegion
combines the given Region with the View's internal
clipping region; the Viewmay only draw on the intersection of the two regions.
ClipToPicture
combines the View's clipping Region with the given
Picture; the View will only be able to draw on pixels that are contained
within the View's clipping region and are drawn by the Picture.
ClipToInversePicture
is like ClipToPicture
, but the View will only be
able to draw on picutres that are not drawn by the Picture.
Perl
$view->GetClippingRegion(); $view->ConstrainClippingRegion($region); $view->ClipToRect($rect); $view->ClipToInverseRect($rect); $view->ClipToPicture($picture, $where, $sync); $view->ClipToInversePicture($picture, $where, $sync); $view->ClipToShape($shape); $view->ClipToInverseShape($shape);
Python
view.GetClippingRegion() view.ConstrainClippingRegion(region) view.ClipToRect(rect) view.ClipToInverseRect(rect) view.ClipToPicture(picture, where, sync) view.ClipToInversePicture(picture, where, sync) view.ClipToShape(shape) view.ClipToInverseShape(shape)
region
The Region to combine with the clipping region.
rect
The Rect to clip to.
picture
The Picture to clip to.
where
The origin Point, in the View's coordinate space.
sync
A boolean, if true (the default), then the function will not return until the it is complete; otherwise the it will return immediately and the function will complete asynchronously.
shape
The Shape to clip to.
Colors
ViewColor
SetViewColor
HighColor
SetHighColor
LowColor
SetLowColor
ViewUIColor
SetViewUIColor
HighUIColor
SetHighUIColor
LowUIColor
SetLowUIColor
HasDefaultColors
HasSystemColors
AdoptParentColors
AdoptSystemColors
AdoptViewColors
The Color
and UIColor
methods get or set the given color for the View.
The "view color" is the background color for the view. The "high" and "low"
colors refer to the pattern argument taken by many drawing operations.
The Set*X*Color
methods also serve as hooks (unlike the Set*X*UIColor
.
The Has
methods test whether the View has the indicated color scheme.
The Adopt
methods set the View's color scheme to the given scheme.
Perl
$view->ViewColor(); $view->SetViewColor($color); $view->HighColor(); $view->SetHighColor($color); $view->LowColor(); $view->SetLowColor($color); $view->ViewUIColor(); $view->SetViewUIColor($ui_color); $view->HighUIColor(); $view->SetHighUIColor($ui_color); $view->LowUIColor(); $view->SetLowUIColor($ui_color); $view->HasDefaultColors(); $view->HasSystemColors(); $view->AdoptParentColors(); $view->AdoptSystemColors(); $view->AdoptViewColors($view);
Python
view.ViewColor() view.SetViewColor(color) view.HighColor() view.SetHighColor(color) view.LowColor() view.SetLowColor(color) view.ViewUIColor() view.SetViewUIColor(ui_color) view.HighUIColor() view.SetHighUIColor(ui_color) view.LowUIColor() view.SetLowUIColor(ui_color) view.HasDefaultColors() view.HasSystemColors() view.AdoptParentColors() view.AdoptSystemColors() view.AdoptViewColors(view)
DrawBitmap
DrawBitmapAsync
Draws a Bitmap onto the View.
DrawBitmap
will not return until the bitmap has been drawn;
DrawBitmapAsync
will return immediately and the bitmap will be drawn
asynchronously.
Perl
$view->DrawBitmap($bitmap); $view->DrawBitmap( bitmap => $bitmap, sourceRect => $bitmapRect, destRect => $viewRect, options => $options, ); $view->DrawBitmap( bitmap => $bitmap, where => $where, ); $view->DrawBitmapAsync($bitmap); $view->DrawBitmapAsync( bitmap => $bitmap, sourceRect => $bitmapRect, destRect => $viewRect, options => $options, ); $view->DrawBitmapAsync( bitmap => $bitmap, where => $where, );
Python
view.DrawBitmap(bitmap) view.DrawBitmap( bitmap = bitmap, sourceRect = bitmapRect, destRect = viewRect, options = options, ) view.DrawBitmap( bitmap = bitmap, where = where, ) view.DrawBitmapAsync(bitmap) view.DrawBitmapAsync( bitmap = bitmap, sourceRect = bitmapRect, destRect = viewRect, options = options, ) view.DrawBitmapAsync( bitmap = bitmap, where = where, )
bitmap
The Bitmap to draw.
sourceRect
A Rect representing the portion of the bitmap to copy; if omitted, will draw the entire bitmap.
destRect
A Rect representing the area of the View to draw into; if omitted, the bitmap will be drawn unscaled.
where
A Point representing the location to draw an unscaled bitmap into; if both
destRect
andwhere
are amitted, will draw to the current pen location.options
An integer, additional options, one or more of the bitmap drawing options constants.
DrawingMode
SetDrawingMode
Gets or sets the drawing mode.
Perl
$view->DrawingMode(); $view->SetDrawingMode($mode);
Python
view.DrawingMode() view.SetDrawingMode(mode)
mode
An integer, one of the drawing mode constants.
Font
GetFont
SetFont
SetFontSize
These functions do what you expect.
Perl
$view->GetFont(); $view->SetFont($font, $mask); $view->SetFontSize($size);
Python
view.GetFont() view.SetFont(font, mask) view.SetFontSize(size)
size
A floating point number, the new size.
font
A Font object.
mask
An integer, one or more ofthe font properties constants; defaults to
B_FONT_ALL
.
InvertRect
Inverts the colors within a rectangle.
Perl
$view->InvertRect($rect);
Python
view.InvertRect(rect)
rect
A Rect, the rectangle
Layers
BeginLayer
EndLayer
Allows a "layer" of drawing operations to be drawn with a given opacity.
Perl
$view->BeginLayer($opacity); $view->EndLayer();
Python
view.BeginLayer(opacity) view.EndLayer()
opacity
An integer, the opacity level.
Line settings
LineCapMode
LineJoinMode
LineMiterLimit
SetLineMode
Gets or sets the line cap and line join modes and the line miter limit.
Perl
$view->LineCapMode(); $view->LineJoinMode(); $view->LineMiterLimit(); $view->SetLineMode($lineCap, $lineJoin, $miterLimit);
Python
view.LineCapMode() view.LineJoinMode() view.LineMiterLimit() view.SetLineMode(lineCap, lineJoin, miterLimit)
lineCap
One of the line cap mode constants.
lineJoin
One of the line join mode constants.
miterLimit
A floating point number; defaults to
B_DEFAULT_MITER_LIMIT
.
Origin
SetOrigin
Gets or sets the origin of the View's coordinate space.
Perl
$view->Origin(); $view->SetOrigin($point);
Python
view.Origin() view.SetOrigin(point)
point
A Point, the origin.
PenLocation
MovePenTo
MovePenBy
Gets or sets the pen location.
Many of the drawing operations will change the pen location; this method moves it without drawing.
Perl
$view->PenLocation(); $view->MovePenTo($point); $view->MovePenTo($x, $y); $view->MovePenBy($x, $y);
Python
view.PenLocation() view.MovePenTo(point) view.MovePenTo(x, y) view.MovePenBy(x, y)
point
A Point, the new pen location.
x
,y
Floating point numbers, the new coordinates or the offsets to the new coordinates.
PenSize
SetPenSize
Gets or sets the pen size.
Perl
$view->PenSize(); $view->SetPenSize($size);
Python
view.PenSize() view.SetPenSize(size)
A floating point number, the new size.
Recording and Playback
BeginPicture
AppendToPicture
SetDiskMode
EndPicture
DrawPicture
The first three operations begin a recording session; drawing operations will be saved instead of being drawn to the View.
BeginPicture
will clear the given Picture; AppendToPicture
will not.
SetDiskMode
stores the drawing operations to a file instead of to a Picture
object. (However, in the current version of Haiku, this method does nothing.)
EndPicture
stops the recording session and returns a copy of the Picture.
DrawPicture
plays back a recorded series of drwaing operations. Note that
even though SetDiskMode
is not yet implemented, the file version of
DrawPicture
is.
The Async
version of DrawPicture
retruns immediately, without waiting
for the picture to be drawn.
Perl
$view->BeginPicture($picture); $view->SetDiskMode($filename, $offset); $view->AppendToPicture($picture); $view->EndPicture(); $view->DrawPicture($picture, $where); $view->DrawPicture($filename, $offset, $where); $view->DrawPictureAsync($picture, $where); $view->DrawPictureAsync($filename, $offset, $where);
Python
view.BeginPicture(picture) view.SetDiskMode(filename, offset) view.AppendToPicture(picture) view.EndPicture() view.DrawPicture(picture, where) view.DrawPicture(filename, offset, where) view.DrawPictureAsync(picture, where) view.DrawPictureAsync(filename, offset, where)
picture
A Picture to record to or play back.
filename
A string, the filename to write to or read from.
offset
An integer, the offset into the file.
where
The Point where the picture should start; defaults to current pen location.
Scale
SetScale
Gets or sets the scale for drawing operations.
Perl
$view->Scale(); $view->SetScale($scale);
Python
view.Scale() view.SetScale(scale)
scale
A floating point number, the scaling constant.
Shapes
StrokePolygon
FillPolygon
StrokeTriangle
FillTriangle
StrokeRect
FillRect
FillRegion
StrokeRoundRect
FillRoundRect
StrokeEllipse
FillEllipse
StrokeArc
FillArc
StrokeBezier
FillBezier
StrokeShape
FillShape
Strokes (draws the outline) or fills (draws and colors in) the given shape
Perl
# polygon $view->StrokePolygon($polygon, $closed, $pattern); $view->FillPolygon($polygon, $pattern); $view->FillPolygon($polygon, $gradient); # triangle $view->StrokeTriangle($points, $pattern); $view->FillTriangle($points, $pattern); $view->FillTriangle($points, $gradient); # rect $view->StrokeRect($rect, $pattern); $view->FillRect($rect, $pattern); $view->FillRect($rect, $gradient); # region $view->FillRegion($region, $pattern); $view->FillRegion($region, $gradient); # round rect $view->StrokeRoundRect($rect, $xRadius, $yRadius, $pattern); $view->FillRoundRect($rect, $xRadius, $yRadius, $pattern); $view->FillRoundRect($rect, $xRadius, $yRadius, $gradient); # ellipse (from center and radii) $view->StrokeEllipse($center, $xRadius, $yRadius, $pattern); $view->FillEllipse($center, $xRadius, $yRadius, $pattern); $view->FillEllipse($center, $xRadius, $yRadius, $gradient); # ellipse (inscribed into rect) $view->StrokeEllipseFromRect($rect, $pattern); $view->FillEllipse($rect, $pattern); $view->FillEllipse($rect, $gradient); # ellipse arc (from center and radii) $view->StrokeArc($center, $xRadius, $yRadius, $startAngle, $arcAngle, $pattern); $view->FllArc($center, $xRadius, $yRadius, $startAngle, $arcAngle, $pattern); $view->FllArc($center, $xRadius, $yRadius, $startAngle, $arcAngle, $gradient); # ellipse arc (inscribed into rect) $view->StrokeArc($rect, $startAngle, $arcAngle, $pattern); $view->FllArc($rect, $startAngle, $arcAngle, $pattern); $view->FllArc($rect, $startAngle, $arcAngle, $gradient); # bezier curve $view->StrokeBezier($controlPoints, $pattern); $view->FillBezier($controlPoints, $pattern); $view->FillBezier($controlPoints, $gradient); # Shape object $view->StrokeShape($shape, $pattern); $view->FillShape($shape, $pattern); $view->FillShape($shape, $gradient);
Python
# polygon view.StrokePolygon(polygon, closed, pattern) view.FillPolygon(polygon, pattern) view.FillPolygon(polygon, gradient) # triangle view.StrokeTriangle(points, pattern) view.FillTriangle(points, pattern) view.FillTriangle(points, gradient) # rect view.StrokeRect(rect, pattern) view.FillRect(rect, pattern) view.FillRect(rect, gradient) # region view.FillRegion(region, pattern) view.FillRegion(region, gradient) # round rect view.StrokeRoundRect(rect, xRadius, yRadius, pattern) view.FillRoundRect(rect, xRadius, yRadius, pattern) view.FillRoundRect(rect, xRadius, yRadius, gradient) # ellipse (from center and radii) view.StrokeEllipse(center, xRadius, yRadius, pattern) view.FillEllipse(center, xRadius, yRadius, pattern) view.FillEllipse(center, xRadius, yRadius, gradient) # ellipse (inscribed into rect) view.StrokeEllipseFromRect(rect, pattern) view.FillEllipse(rect, pattern) view.FillEllipse(rect, gradient) # ellipse arc (from center and radii) view.StrokeArc(center, xRadius, yRadius, startAngle, arcAngle, pattern) view.FllArc(center, xRadius, yRadius, startAngle, arcAngle, pattern) view.FllArc(center, xRadius, yRadius, startAngle, arcAngle, gradient) # ellipse arc (inscribed into rect) view.StrokeArc(rect, startAngle, arcAngle, pattern) view.FllArc(rect, startAngle, arcAngle, pattern) view.FllArc(rect, startAngle, arcAngle, gradient) # bezier curve view.StrokeBezier(controlPoints, pattern) view.FillBezier(controlPoints, pattern) view.FillBezier(controlPoints, gradient) # Shape object view.StrokeShape(shape, pattern) view.FillShape(shape, pattern) view.FillShape(shape, gradient)
polygon
Either a Polygon or a native list of Points, the polygon to draw.
closed
A boolean; if true (the default), a line will be drawn from the last point to the first, closing the polygon.
points
A native list of Points, the shape to draw.
rect
A Rect, the rectangle to draw or to inscribe the ellipse into.
center
A Point, the center
xRadius
,yRadius
Floating point numbers, the x and y radii of the ellipse to draw, or in the case of the
RoundRect
methods, the ellipse to use for the corners.startAngle
,arcAngle
Floating point numbers, the span in degrees along which the arc will travel (i.e., start angle plus arc angle equals end angle)
controlPoints
A native list of four Points that define a Bezier curve.
shape
A Shape object.
pattern
A pattern; defaults to
B_SOLID_HIGH
(solid high color).gradient
A Gradient to use (instead of a pattern).
Strings
DrawChar
DrawString
These methods do what you expect.
Perl
$view->DrawChar($char, $location); $view->DrawString($string, $location); $view->DrawString($string, $delta); $view->DrawString($string, $location, $delta); $view->DrawString($string, $locations);
Python
view.DrawChar(char, location) view.DrawString(string, location) view.DrawString(string, delta) view.DrawString(string, location, delta) view.DrawString(string, locations)
char
The character to draw; it must be a single-byte character (no UTF-8).
string
The string to draw.
location
Optional; the Point to draw the character or string at.
delta
An optional escapement_delta
locations
Optional; a native list of Points to draw the string at.
StrokeLine
BeginLineArray
AddLine
EndLineArray
StrokeLine
draws a single line.
The other methods are a more efficient way of drawing multiple lines. The
lines are drawn at all once by EndLineArray
.
Perl
$view->StrokeLine($point1, $point2, $pattern); $view->StrokeLine($point2, $pattern); $view->BeginLineArray($count); $view->AddLine($point1, $point2, $color); $view->EndLineArray();
Python
view.StrokeLine(point1, point2, pattern) view.StrokeLine(point2, pattern) view.BeginLineArray(count) view.AddLine(point1, point2, color) view.EndLineArray()
point1
The start Point; can be omitted in
StrokeLine
, in which case the line will start from the current pen location.point2
The end Point.
pattern
A pattern; defaults to
B_SOLID_HIGH
(solid high color).count
An integer, the maximum number of lines that will be in this array. For memory purposes, it's good to keep this as close as possible to the actual number of lines you will draw; i.e., if you know in advance how many lines it will be, use that number; if there's wiggle room, don't give yourself a huge buffer just in case. The BeBook says that setting a value higher than 256 can affect memory performance.
color
An rgb_color, the line color.
Transformations
Transform
SetTransform
TranslateBy
ScaleBy
RotateBy
Sets the transform.
Perl
$view->Transform(); $view->SetTransform($transform); $view->TranslateBy($x, $y); $view->ScaleBy($x, $y); $view->RotateBy($angleRadians);
Python
view.Transform() view.SetTransform(transform) view.TranslateBy(x, y) view.ScaleBy(x, y) view.RotateBy(angleRadians)
transform
An AffineTransform object.
View state
PushState
PopState
PushState
pushes the current state onto the state stack, creating a new
stack context. PopState
pops the most recent state from the state stack,
replacing the current stack context.
Perl
$view->PushState(); $view->PopState();
Python
view.PushState() view.PopState()
HOOKS
Draw
Draws the View.
Perl
$view->Draw($rect);
Python
view.Draw(rect)
rect
A Rect, the invalid rectangle.
DrawAfterChildren
Called after all child Views have finished drawing.
Perl
$view->DrawAfterChildren($rect);
Python
view.DrawAfterChildren(rect)
rect
A Rect, the invalid rectangle.
CONSTANTS
Font properties
Perl
use HaikuR1::View qw(:font_mask)
Python
Python does not support export tags.
- B_FONT_FAMILY_AND_STYLE
- B_FONT_SIZE
- B_FONT_SHEAR
- B_FONT_ROTATION
- B_FONT_SPACING
- B_FONT_ENCODING
- B_FONT_FACE
- B_FONT_FLAGS
- B_FONT_FALSE_BOLD_WIDTH
- B_FONT_ALL