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)
srcAlphaAn integer, one of the source alpha constants.
alphaFuncAn 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)
regionThe Region to combine with the clipping region.
rectThe Rect to clip to.
pictureThe Picture to clip to.
whereThe origin Point, in the View's coordinate space.
syncA 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.
shapeThe 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,
)
bitmapThe Bitmap to draw.
sourceRectA Rect representing the portion of the bitmap to copy; if omitted, will draw the entire bitmap.
destRectA Rect representing the area of the View to draw into; if omitted, the bitmap will be drawn unscaled.
whereA Point representing the location to draw an unscaled bitmap into; if both
destRectandwhereare amitted, will draw to the current pen location.optionsAn 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)
modeAn 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)
sizeA floating point number, the new size.
fontA Font object.
maskAn 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)
rectA 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()
opacityAn 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)
lineCapOne of the line cap mode constants.
lineJoinOne of the line join mode constants.
miterLimitA 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)
pointA 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)
pointA Point, the new pen location.
x,yFloating 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)
pictureA Picture to record to or play back.
filenameA string, the filename to write to or read from.
offsetAn integer, the offset into the file.
whereThe 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)
scaleA 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)
polygonEither a Polygon or a native list of Points, the polygon to draw.
closedA boolean; if true (the default), a line will be drawn from the last point to the first, closing the polygon.
pointsA native list of Points, the shape to draw.
rectA Rect, the rectangle to draw or to inscribe the ellipse into.
centerA Point, the center
xRadius,yRadiusFloating point numbers, the x and y radii of the ellipse to draw, or in the case of the
RoundRectmethods, the ellipse to use for the corners.startAngle,arcAngleFloating point numbers, the span in degrees along which the arc will travel (i.e., start angle plus arc angle equals end angle)
controlPointsA native list of four Points that define a Bezier curve.
shapeA Shape object.
patternA pattern; defaults to
B_SOLID_HIGH(solid high color).gradientA 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)
charThe character to draw; it must be a single-byte character (no UTF-8).
stringThe string to draw.
locationOptional; the Point to draw the character or string at.
deltaAn optional escapement_delta
locationsOptional; 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()
point1The start Point; can be omitted in
StrokeLine, in which case the line will start from the current pen location.point2The end Point.
patternA pattern; defaults to
B_SOLID_HIGH(solid high color).countAn 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.
colorAn 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)
transformAn 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)
rectA Rect, the invalid rectangle.
DrawAfterChildren
Called after all child Views have finished drawing.
Perl
$view->DrawAfterChildren($rect);
Python
view.DrawAfterChildren(rect)
rectA 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