Haiku API Bindings
Drawing
Not logged in

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)

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)

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,
)

DrawingMode

SetDrawingMode

Gets or sets the drawing mode.

Perl

$view->DrawingMode();
$view->SetDrawingMode($mode);

Python

view.DrawingMode()
view.SetDrawingMode(mode)

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)

InvertRect

Inverts the colors within a rectangle.

Perl

$view->InvertRect($rect);

Python

view.InvertRect(rect)

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()

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)

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)

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)

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)

Scale

SetScale

Gets or sets the scale for drawing operations.

Perl

$view->Scale();
$view->SetScale($scale);

Python

view.Scale()
view.SetScale(scale)

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)

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)

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()

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)

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)

DrawAfterChildren

Called after all child Views have finished drawing.

Perl

$view->DrawAfterChildren($rect);

Python

view.DrawAfterChildren(rect)

CONSTANTS

Font properties

Perl

use HaikuR1::View qw(:font_mask)

Python

Python does not support export tags.