Documentation/GdiGraphics
classWORKER

GdiGraphics

js/foo_uie_jsplitter.js:6794

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

js/foo_uie_jsplitter.js:7234

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

js/foo_uie_jsplitter.js:7260
Chars: number
propertyWORKERreadonly

Height

js/foo_uie_jsplitter.js:7267
Height: float
propertyWORKERreadonly

Height

js/foo_uie_jsplitter.js:7328
Height: number = 480

Currect height of device context surface.

propertyWORKERreadonly

Lines

js/foo_uie_jsplitter.js:7274
Lines: number
propertyWORKERreadonly

Width

js/foo_uie_jsplitter.js:7295
Width: float
propertyWORKERreadonly

Width

js/foo_uie_jsplitter.js:7321
Width: number = 640

Currect width of device context surface.

propertyWORKERreadonly

X

js/foo_uie_jsplitter.js:7281
X: float
propertyWORKERreadonly

Y

js/foo_uie_jsplitter.js:7288
Y: float
methodWORKER

ApplyTransform

js/foo_uie_jsplitter.js:7224
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

js/foo_uie_jsplitter.js:6807
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

js/foo_uie_jsplitter.js:6818
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

js/foo_uie_jsplitter.js:6860
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

js/foo_uie_jsplitter.js:6833
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

js/foo_uie_jsplitter.js:6844
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

js/foo_uie_jsplitter.js:6876
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

js/foo_uie_jsplitter.js:6887
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

js/foo_uie_jsplitter.js:6897
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

js/foo_uie_jsplitter.js:6922
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

js/foo_uie_jsplitter.js:6933
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

js/foo_uie_jsplitter.js:6907
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

js/foo_uie_jsplitter.js:7089
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

js/foo_uie_jsplitter.js:6946
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

js/foo_uie_jsplitter.js:6963
FillEllipse(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

FillGradRect

js/foo_uie_jsplitter.js:6973
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

js/foo_uie_jsplitter.js:6989
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

js/foo_uie_jsplitter.js:7003
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

js/foo_uie_jsplitter.js:7011
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

js/foo_uie_jsplitter.js:7023
FillSolidRect(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

methodWORKER

GdiAlphaBlend

js/foo_uie_jsplitter.js:7033
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

js/foo_uie_jsplitter.js:7048
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

js/foo_uie_jsplitter.js:7064
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

js/foo_uie_jsplitter.js:7198
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

js/foo_uie_jsplitter.js:7104
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

js/foo_uie_jsplitter.js:7133
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

js/foo_uie_jsplitter.js:7192
PopTransform()

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

methodWORKER

PushClip

js/foo_uie_jsplitter.js:7119
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

js/foo_uie_jsplitter.js:7186
PushTransform()

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

methodWORKER

ResetTransform

js/foo_uie_jsplitter.js:7218
ResetTransform()

Resets current GdiGraphics matrix to original identity matrix.

methodWORKER

Rotate

js/foo_uie_jsplitter.js:7151
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

js/foo_uie_jsplitter.js:7162
Scale(sz, sy, cx, cy)

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

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

js/foo_uie_jsplitter.js:7303
SetInterpolationMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See InterpolationMode enum

methodWORKER

SetSmoothingMode

js/foo_uie_jsplitter.js:7309
SetSmoothingMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See SmoothingMode enum

methodWORKER

SetTextRenderingHint

js/foo_uie_jsplitter.js:7315
SetTextRenderingHint(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See TextRenderingHint enum

methodWORKER

SetTransform

js/foo_uie_jsplitter.js:7208
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

js/foo_uie_jsplitter.js:7174
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

js/foo_uie_jsplitter.js:7141
Translate(dx, dy)

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

Parameters

NameTypeDescription
dxnumber
dynumber