Documentation/GdiGraphics
classWORKER

GdiGraphics

jsdoc/objects/gdi.js:452

Typically used inside on_paint.

Note: there are many different ways to get colours: window.GetColourDUI/window.GetColourCUI, RGB function from Helpers.js, utils.ColourPicker and etc.

classWORKERCLONEABLE

MeasureStringInfo

jsdoc/objects/gdi.js:892

Example

include(`${fb.ComponentPath}docs\\Flags.js`);
include(`${fb.ComponentPath}docs\\Helpers.js`);

let sf = StringFormat(StringAlignment.Near, StringAlignment.Near);
let text = utils.ReadTextFile("z:\\info.txt");
let font = window.GetFontDUI(0);

function on_paint(gr) {
    gr.DrawString(text, font, RGB(255, 0, 0), 0, 0, window.Width, window.Height, sf);
    let temp = gr.MeasureString(text, font, 0, 0, window.Width, 10000, sf);
    // If we want to calculate height, we must set the height to be far larger than what
    // the text could possibly be.

    console.log(temp.Height); // 2761.2421875 // far larger than my panel height!
    console.log(temp.Chars); // 7967
}
propertyWORKERreadonly

Chars

jsdoc/objects/gdi.js:918
Chars: number
propertyWORKERreadonly

Height

jsdoc/objects/gdi.js:925
Height: float
propertyWORKERreadonly

Height

jsdoc/objects/gdi.js:986
Height: number = 480

Currect height of device context surface.

propertyWORKERreadonly

Lines

jsdoc/objects/gdi.js:932
Lines: number
propertyWORKERreadonly

Width

jsdoc/objects/gdi.js:953
Width: float
propertyWORKERreadonly

Width

jsdoc/objects/gdi.js:979
Width: number = 640

Currect width of device context surface.

propertyWORKERreadonly

X

jsdoc/objects/gdi.js:939
X: float
propertyWORKERreadonly

Y

jsdoc/objects/gdi.js:946
Y: float
methodWORKER

ApplyTransform

jsdoc/objects/gdi.js:882
ApplyTransform(matrix)

Applies specified transformation matrix of 3x2 size to the current GdiGraphics matrix.
Matrix helpers from the component/docs/Matrix.js will be useful

Parameters

NameTypeDescription
matrixFloat32Array

Array that presents 3x2 matrix for transformation (length = 6)

Example source

methodWORKER

CalcTextHeight

jsdoc/objects/gdi.js:465
CalcTextHeight(str, font)

Calculates text height for GdiDrawText.
Note: this will only calculate the text height of one line.

Parameters

NameTypeDescription
strstring
fontGdiFont

Returns

number
methodWORKER

CalcTextWidth

jsdoc/objects/gdi.js:476
CalcTextWidth(str, font, use_exact)

Calculates text width for GdiDrawText.

Note: When the str contains a kerning pair that is found in the specified font, the return value will be larger than the actual drawn width of the text. If accurate values are required, set use_exact to true.

Parameters

NameTypeDescription
strstring
fontGdiFont
use_exact = falseoptionalboolean

Uses a slower, but more accurate method of calculating text width which accounts for kerning pairs.

Returns

number
methodWORKER

DrawBitmap

jsdoc/objects/gdi.js:518
DrawBitmap(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH)

Compatibility alias of DrawImage.

Parameters

NameTypeDescription
imgGdiBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
methodWORKER

DrawEllipse

jsdoc/objects/gdi.js:491
DrawEllipse(x, y, w, h, line_width, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
line_widthnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

DrawImage

jsdoc/objects/gdi.js:502
DrawImage(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, angle, alpha)

Parameters

NameTypeDescription
imgGdiBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
angle = 0optionalfloat
alpha = 255optionalnumber

Valid values 0-255.

methodWORKER

DrawLine

jsdoc/objects/gdi.js:534
DrawLine(x1, y1, x2, y2, line_width, colour_or_brush)

Parameters

NameTypeDescription
x1number
y1number
x2number
y2number
line_widthnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

DrawLines

jsdoc/objects/gdi.js:545
DrawLines(colour_or_brush, line_width, points)

Draws a connected sequence of lines.

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or GdiBrush object

line_widthnumber
pointsArray<number>

array of connected points [x1, y1, x2, y2, ...]

methodWORKER

DrawPolygon

jsdoc/objects/gdi.js:555
DrawPolygon(colour_or_brush, line_width, points)

Draws a connected sequence of lines with connection of last and first points (unlike DrawLines).

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or GdiBrush object

line_widthnumber
pointsArray<number>

array of connected points [x1, y1, x2, y2, ...]

methodWORKER

DrawRect

jsdoc/objects/gdi.js:580
DrawRect(x, y, w, h, line_width, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
line_widthnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

DrawRoundRect

jsdoc/objects/gdi.js:591
DrawRoundRect(x, y, w, h, arc_width, arc_height, line_width, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
arc_widthnumber
arc_heightnumber
line_widthnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

DrawString

jsdoc/objects/gdi.js:565
DrawString(str, font, colour_or_brush, x, y, w, h, flags)

Should be only used when GdiDrawText is not applicable.

Parameters

NameTypeDescription
strstring
fontGdiFont
colour_or_brush*

colour ARGB or GdiBrush object

xnumber
ynumber
wnumber
hnumber
flags = 0optionalnumber

See StringFormatFlags flags

methodWORKER

DrawText

jsdoc/objects/gdi.js:747
DrawText(str, font, colour, x, y, w, h, format)

Alias of GdiDrawText.

Parameters

NameTypeDescription
strstring
fontGdiFont
colournumber
xnumber
ynumber
wnumber
hnumber
format = 0optionalnumber
methodWORKER

EstimateLineWrap

jsdoc/objects/gdi.js:604
EstimateLineWrap(str, font, max_width)

Parameters

NameTypeDescription
strstring
fontGdiFont
max_widthnumber

Returns

Array<Array> —

index | meaning
[0] text line 1
[1] width of text line 1 (in pixel)
[2] text line 2
[3] width of text line 2 (in pixel)
...
[2n + 2] text line n
[2n + 3] width of text line n (px)

methodWORKER

FillEllipse

jsdoc/objects/gdi.js:621
FillEllipse(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

FillGradRect

jsdoc/objects/gdi.js:631
FillGradRect(x, y, w, h, angle, colour1, colour2, focus)

Note: this may appear buggy depending on rectangle size. The easiest fix is to adjust the "angle" by a degree or two.

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
anglefloat
colour1number
colour2number
focus = 1.0optionalfloat

Specify where the centred colour will be at its highest intensity. Valid values between 0 and 1.

methodWORKER

FillGradRectV2

jsdoc/objects/gdi.js:647
FillGradRectV2(x, y, w, h, angle, stops)

Fills rect with gradient in arbitrary quantity of stops.

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
anglefloat
stopsArray

Specifies gradient stops in form of [pos0, argb0, ..., posN, argbN]

Example

dgr.FillGradRectV2(10, 10, 200, 100, 0, [0.0, 0xFF0000FF, 0.5, 0xFFFF0000, 1.0, 0xFF000000]);
methodWORKER

FillPolygon

jsdoc/objects/gdi.js:661
FillPolygon(colour_or_brush, fillmode, points)

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or GdiBrush object

fillmodenumber

0 alternate, 1 winding.

pointsArray<Array<number>>
methodWORKER

FillRoundRect

jsdoc/objects/gdi.js:669
FillRoundRect(x, y, w, h, arc_width, arc_height, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
arc_widthnumber
arc_heightnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

FillSolidRect

jsdoc/objects/gdi.js:681
FillSolidRect(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

GdiAlphaBlend

jsdoc/objects/gdi.js:691
GdiAlphaBlend(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, alpha)

Parameters

NameTypeDescription
imgGdiRawBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
alpha = 255optionalnumber

Valid values 0-255.

methodWORKER

GdiDrawBitmap

jsdoc/objects/gdi.js:706
GdiDrawBitmap(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH)

Always faster than DrawImage, does not support alpha channel.

Parameters

NameTypeDescription
imgGdiRawBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
methodWORKER

GdiDrawText

jsdoc/objects/gdi.js:722
GdiDrawText(str, font, colour, x, y, w, h, format)

Provides faster and better rendering than DrawString.

Do not use this to draw text on transparent background or with GdiGraphics other than the one passed in on_paint callback: this will result in visual artifacts caused by ClearType hinting.
Use DrawString instead in such cases.

To calculate text dimensions use CalcTextHeight, CalcTextWidth.

Note: uses special rules for & character by default, which consumes the & and causes the next character to be underscored. This behaviour can be changed (or disabled) via format parameter.

Parameters

NameTypeDescription
strstring
fontGdiFont
colournumber
xnumber
ynumber
wnumber
hnumber
format = 0optionalnumber

See flags like DT_LEFT

methodWORKER

GetTransform

jsdoc/objects/gdi.js:856
GetTransform()

Gets GdiGraphics current transformation matrix of 3x2 size (Float32Array(6)) Matrix helpers from the component/docs/Matrix.js will be useful

Returns

Float32Array

Example source

methodWORKER

MeasureString

jsdoc/objects/gdi.js:762
MeasureString(str, font, x, y, w, h, flags)

Calculates text dimensions for DrawString.

Parameters

NameTypeDescription
strstring
fontGdiFont
xnumber
ynumber
wnumber
hnumber
flags = 0optionalnumber

See StringFormatFlags flags

Returns

MeasureStringInfo
methodWORKER

PopClip

jsdoc/objects/gdi.js:791
PopClip()

Restores the clipping region that was active before the matching PushClip call.
Does nothing if the clip stack is empty.
The current transform and other graphics state are not affected.

methodWORKER

PopTransform

jsdoc/objects/gdi.js:850
PopTransform()

Restores current GdiGraphics matrix from internal stack pushed previously by PushTransform.

methodWORKER

PushClip

jsdoc/objects/gdi.js:777
PushClip(x, y, width, height)

Pushes a rectangular clipping region onto the clip stack.
The new clipping region is intersected with the current clipping region.
Calls may be nested and should be paired with PopClip.
The current transform and other graphics state are not affected.

Parameters

NameTypeDescription
xnumber

left coordinate of the clipping rectangle

ynumber

top coordinate of the clipping rectangle

widthnumber

width of the clipping rectangle

heightnumber

height of the clipping rectangle

methodWORKER

PushTransform

jsdoc/objects/gdi.js:844
PushTransform()

Saves current GdiGraphics matrix in internal stack. To restore the matrix use PopTransform.

methodWORKER

ResetTransform

jsdoc/objects/gdi.js:876
ResetTransform()

Resets current GdiGraphics matrix to original identity matrix.

methodWORKER

Rotate

jsdoc/objects/gdi.js:809
Rotate(angle, cx, cy)

Applies rotation matrix to the current GdiGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-rotation

Parameters

NameTypeDescription
anglefloat

Angle of rotation in degrees

cx = 0optionalnumber

Rotation center point x coord

cy = 0optionalnumber

Rotation center point y coord

methodWORKER

Scale

jsdoc/objects/gdi.js:820
Scale(sz, sy, cx, cy)

Parameters

NameTypeDescription
sxfloat

The x-axis scale factor

sy = 0optionalfloat

The y-axis scale factor. If zero sx will be used as sy

cx = 0optionalnumber

Scale center point x coord

cy = 0optionalnumber

Scale center point y coord

methodWORKER

SetInterpolationMode

jsdoc/objects/gdi.js:961
SetInterpolationMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See InterpolationMode enum

methodWORKER

SetSmoothingMode

jsdoc/objects/gdi.js:967
SetSmoothingMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See SmoothingMode enum

methodWORKER

SetTextRenderingHint

jsdoc/objects/gdi.js:973
SetTextRenderingHint(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See TextRenderingHint enum

methodWORKER

SetTransform

jsdoc/objects/gdi.js:866
SetTransform(matrix)

Replaces the current GdiGraphics matrix with specified transformation matrix of 3x2 size.
Matrix helpers from the component/docs/Matrix.js will be useful

Parameters

NameTypeDescription
matrixFloat32Array

Array that presents 3x2 matrix for transformation (length = 6)

Example source

methodWORKER

Skew

jsdoc/objects/gdi.js:832
Skew(angleX, angleY, cx, cy)

Applies skew matrix to the current GdiGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-skew

Parameters

NameTypeDescription
angleXfloat

The x-axis skew angle, which is measured in degrees counterclockwise from the y-axis.

angleYfloat

The y-axis skew angle, which is measured in degrees clockwise from the x-axis.

cx = 0optionalnumber

Skew center point x coord

cy = 0optionalnumber

Skew center point y coord

methodWORKER

Translate

jsdoc/objects/gdi.js:799
Translate(dx, dy)

Parameters

NameTypeDescription
dxnumber
dynumber