Documentation/GdiGraphics
class

GdiGraphics

js/foo_uie_jsplitter.js:4526

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.

class

MeasureStringInfo

js/foo_uie_jsplitter.js:4890

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
}
propertyreadonly

Chars

js/foo_uie_jsplitter.js:4914
Chars: number
propertyreadonly

Height

js/foo_uie_jsplitter.js:4920
Height: float
propertyreadonly

Height

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

Currect height of device context surface.

propertyreadonly

Lines

js/foo_uie_jsplitter.js:4926
Lines: number
propertyreadonly

Width

js/foo_uie_jsplitter.js:4944
Width: float
propertyreadonly

Width

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

Currect width of device context surface.

propertyreadonly

X

js/foo_uie_jsplitter.js:4932
X: float
propertyreadonly

Y

js/foo_uie_jsplitter.js:4938
Y: float
method

ApplyTransform

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

method

CalcTextHeight

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

CalcTextWidth

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

DrawEllipse

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

method

DrawImage

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

method

DrawLine

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

method

DrawPolygon

js/foo_uie_jsplitter.js:4597
DrawPolygon(colour_or_brush, line_width, points)

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or GdiBrush object

line_widthnumber
pointsArray<Array<number>>
method

DrawRect

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

method

DrawRoundRect

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

method

DrawString

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

method

EstimateLineWrap

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

method

FillEllipse

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

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

method

FillGradRect

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

method

FillGradRectV2

js/foo_uie_jsplitter.js:4680
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]);
method

FillPolygon

js/foo_uie_jsplitter.js:4693
FillPolygon(colour_or_brush, fillmode, points)

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or GdiBrush object

fillmodenumber

0 alternate, 1 winding.

pointsArray<Array<number>>
method

FillRoundRect

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

method

FillSolidRect

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

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or GdiBrush object

method

GdiAlphaBlend

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

method

GdiDrawBitmap

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

GdiDrawText

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

method

GetTransform

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

method

MeasureString

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

PopClip

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

method

PopTransform

js/foo_uie_jsplitter.js:4853
PopTransform()

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

method

PushClip

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

method

PushTransform

js/foo_uie_jsplitter.js:4848
PushTransform()

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

method

ResetTransform

js/foo_uie_jsplitter.js:4876
ResetTransform()

Resets current GdiGraphics matrix to original identity matrix.

method

Rotate

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

method

Scale

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

method

SetInterpolationMode

js/foo_uie_jsplitter.js:4951
SetInterpolationMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See InterpolationMode enum

method

SetSmoothingMode

js/foo_uie_jsplitter.js:4956
SetSmoothingMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See SmoothingMode enum

method

SetTextRenderingHint

js/foo_uie_jsplitter.js:4961
SetTextRenderingHint(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See TextRenderingHint enum

method

SetTransform

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

method

Skew

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

method

Translate

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