Typically used inside on_paint.
Use on_paint(dgr) for D2DGraphics members hints in auto-completion list.
Note: there are many different ways to get colours: window.GetColourDUI/window.GetColourCUI, RGB function from Helpers.js, utils.ColourPicker and etc.
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);
console.log(temp.Height);
console.log(temp.Chars);
}
Chars: number
Height: float
Height: number = 480
Currect height of device context surface.
Lines: number
Width: float
Width: number = 640
Currect width of device context surface.
X: float
Y: float
AlphaBlend(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, alpha)
Parameters
| Name | Type | Description |
img | D2DBitmap | |
dstX | number | |
dstY | number | |
dstW | number | |
dstH | number | |
srcX | number | |
srcY | number | |
srcW | number | |
srcH | number | |
alpha = 255optional | number | Valid values 0-255. |
ApplyTransform(matrix)
Applies specified transformation matrix of 3x2 size to the current D2DGraphics matrix.
Matrix3x2 helper class from the component/docs/Matrix.js will be useful
Parameters
| Name | Type | Description |
matrix | Float32Array | Array that presents 3x2 matrix for transformation (length = 6) |
CalcTextHeight(str, font)
Calculates text height for DrawText.
Note: this will only calculate the text height of one line.
Parameters
| Name | Type | Description |
str | string | |
font | D2DFont | |
CalcTextWidth(str, font, use_exact)
Calculates text width for DrawText.
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
| Name | Type | Description |
str | string | |
font | D2DFont | |
use_exact = falseoptional | boolean | Uses a slower, but more accurate method of calculating text width which accounts for kerning pairs. |
DrawEffect(effect, dstX, dstY, srcX, srcY, srcW, srcH, compositionMode)
DrawEllipse(x, y, w, h, line_width, colour_or_brush, style)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
line_width | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
style = DashStyle.Solidoptional | DashStyle | See DashStyle |
DrawImage(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, angle, alpha)
Parameters
| Name | Type | Description |
img | D2DBitmap | |
dstX | number | |
dstY | number | |
dstW | number | |
dstH | number | |
srcX | number | |
srcY | number | |
srcW | number | |
srcH | number | |
angle = 0optional | float | |
alpha = 255optional | number | Valid values 0-255. |
DrawLine(x1, y1, x2, y2, line_width, colour_or_brush, style, startCap, endCap)
DrawLines(colour_or_brush, line_width, points, style)
Parameters
| Name | Type | Description |
colour_or_brush | * | colour ARGB or D2DBrush object |
line_width | number | |
points | Array<Array<number>> | |
style = DashStyle.Solidoptional | DashStyle | See DashStyle |
DrawPolygon(colour_or_brush, line_width, points, style)
Parameters
| Name | Type | Description |
colour_or_brush | * | colour ARGB or D2DBrush object |
line_width | number | |
points | Array<Array<number>> | |
style = DashStyle.Solidoptional | DashStyle | See DashStyle |
DrawRect(x, y, w, h, line_width, colour_or_brush, style)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
line_width | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
style = DashStyle.Solidoptional | DashStyle | See DashStyle |
DrawRoundRect(x, y, w, h, arc_width, arc_height, line_width, colour_or_brush, style)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
arc_width | number | |
arc_height | number | |
line_width | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
style = DashStyle.Solidoptional | DashStyle | See DashStyle |
DrawString(str, font, colour_or_brush, x, y, w, h, flags)
Should be only used when DrawText is not applicable.
Parameters
| Name | Type | Description |
str | string | |
font | D2DFont | |
colour_or_brush | * | colour ARGB or D2DBrush object |
x | number | |
y | number | |
w | number | |
h | number | |
flags = 0optional | number | See StringFormatFlags flags |
DrawStrokedText(str, font, strokeColor, strokeWidth, fillColor, x, y, w, h)
Draws stroked text in clipped rectangle. Flags for formatting text are not supported.
Parameters
| Name | Type | Description |
str | string | |
font | D2DFont | |
strokeColor | number | |
strokeWidth | number | |
x | number | |
y | number | |
w | number | |
h | number | |
DrawText(str, font, colour_or_brush, x, y, w, h, format)
Provides faster and better rendering than DrawString.
Do not use this to draw text on transparent background or with D2DGraphics 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
| Name | Type | Description |
str | string | |
font | D2DFont | |
colour_or_brush | * | colour ARGB or D2DBrush object |
x | number | |
y | number | |
w | number | |
h | number | |
format = 0optional | number | See flags like DT_LEFT |
EstimateLineWrap(str, font, max_width)
Parameters
| Name | Type | Description |
str | string | |
font | D2DFont | |
max_width | number | |
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)
FillEllipse(x, y, w, h, colour_or_brush)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
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
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
angle | float | |
colour1 | number | |
colour2 | number | |
focus = 1.0optional | float | Specify where the centred colour will be at its highest intensity. Valid values between 0 and 1. |
FillGradRectV2(x, y, w, h, angle, stops)
Fills rect with gradient in arbitrary quantity of stops.
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
angle | float | |
stops | Array | 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]);
FillPolygon(colour_or_brush, fillmode, points)
Parameters
| Name | Type | Description |
colour_or_brush | * | colour ARGB or D2DBrush object |
fillmode | number | 0 alternate, 1 winding. |
points | Array<Array<number>> | |
FillRoundRect(x, y, w, h, arc_width, arc_height, colour_or_brush)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
arc_width | number | |
arc_height | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
FillSolidRect(x, y, w, h, colour_or_brush)
Parameters
| Name | Type | Description |
x | number | |
y | number | |
w | number | |
h | number | |
colour_or_brush | * | colour ARGB or D2DBrush object |
GetTransform()
Gets D2DGraphics current transformation matrix of 3x2 size (Float32Array(6))
Matrix3x2 helper class from the component/docs/Matrix.js will be useful
MeasureString(str, font, x, y, w, h, flags)
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.
PopTransform()
Restores D2DGraphics matrix from internal stack pushed previously by PushTransform.
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
| Name | Type | Description |
x | number | left coordinate of the clipping rectangle |
y | number | top coordinate of the clipping rectangle |
width | number | width of the clipping rectangle |
height | number | height of the clipping rectangle |
PushTransform()
Saves current D2DGraphics matrix in internal stack. To restore the matrix use PopTransform.
ResetTransform()
Resets current D2DGraphics matrix to original identity matrix.
Rotate(angle, cx, cy)
Parameters
| Name | Type | Description |
angle | float | Angle of rotation in degrees |
cx = 0optional | number | Rotation center point x coord |
cy = 0optional | number | Rotation center point y coord |
Scale(sz, sy, cx, cy)
Parameters
| Name | Type | Description |
sx | float | The x-axis scale factor |
sy = 0optional | float | The y-axis scale factor. If zero sx will be used as sy |
cx = 0optional | number | Scale center point x coord |
cy = 0optional | number | Scale center point y coord |
SetInterpolationMode(mode)
SetSmoothingMode(mode)
SetTextRenderingHint(mode)
SetTransform(matrix)
Replaces the current D2DGraphics matrix with specified transformation matrix of 3x2 size.
Matrix3x2 helper class from the component/docs/Matrix.js will be useful
Parameters
| Name | Type | Description |
matrix | Float32Array | Array that presents 3x2 matrix for transformation (length = 6) |
Skew(angleX, angleY, cx, cy)
Parameters
| Name | Type | Description |
angleX | float | The x-axis skew angle, which is measured in degrees counterclockwise from the y-axis. |
angleY | float | The y-axis skew angle, which is measured in degrees clockwise from the x-axis. |
cx = 0optional | number | Skew center point x coord |
cy = 0optional | number | Skew center point y coord |
Translate(dx, dy)
Parameters
| Name | Type | Description |
dx | number | |
dy | number | |