Module dcanvas.core.types
Basic data types for usage in dcanvas library.
Contains reference counting support, point and rect structures, character glyph structure, misc utility functions.
Synopsis
import dcanvas .core .types;
// points
Point p(5, 10);
// rectangles
Rect r(5, 13, 120, 200);
writeln(r);
// reference counted objects, useful for RAII / resource management.
class Foo : RefCountedObject {
int[] resource;
~this() {
writeln("freeing Foo resources");
}
}
{
Ref!Foo ref1;
{
Ref!Foo fooRef = new RefCountedObject();
ref1 = fooRef;
}
// RAII: will destroy object when no more references
}
Functions
| Name | Description |
|---|---|
dcharToUpper(ch)
|
|
fromPercentSize(size, baseSize)
|
if size has SIZE_IN_PERCENTS_FLAG bit set, returns percent of baseSize, otherwise returns size unchanged |
fromWStringz(s)
|
conversion from wchar z-string |
isPercentSize(size)
|
returns true if size has SIZE_IN_PERCENTS_FLAG bit set |
isSpecialSize(sz)
|
returns true for WRAP_CONTENT, WRAP_CONTENT, SIZE_UNSPECIFIED |
makePercentSize(percent)
|
make size value with SIZE_IN_PERCENTS_FLAG set |
makePointSize(pt)
|
make size value with SIZE_IN_POINTS_FLAG set |
normalizeEndOfLineCharacters(s)
|
normalize end of line style - convert to '\n' |
overrideScreenDPI()
|
get screen DPI detection override value, if non 0 - this value is used instead of DPI detected by platform, if 0, value detected by platform will be used |
overrideScreenDPI(dpi)
|
call to disable automatic screen DPI detection, use provided one instead (pass 0 to disable override and use value detected by platform) |
parseHexDigit(ch)
|
decodes hex digit (0..9, a..f, A..F), returns uint.max if invalid |
pixelsToPoints(px)
|
convert points (1/72in units) to pixels according to SCREEN_DPI |
pointsToPixels(pt)
|
convert length in points (1/72in units) to pixels according to SCREEN_DPI |
pointsToPixels(rc)
|
rectangle coordinates in points (1/72in units) to pixels according to SCREEN_DPI |
SCREEN_DEVICE_PIXEL_RATIO()
|
get the device pixel ratio (1 or 2) |
SCREEN_DEVICE_PIXEL_RATIO(ratio)
|
set the device pixel ratio detected by platform |
SCREEN_DPI()
|
get current screen DPI used for scaling while drawing |
SCREEN_DPI(dpi)
|
set screen DPI detected by platform |
systemScreenDPI()
|
returns DPI detected by platform w/o override |
toPixels(sz)
|
convert custom size to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) |
toPixels(sz)
|
convert custom size Point to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) |
toPixels(sz)
|
convert custom size Rect to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) |
toUTF8(str)
|
replacement of deprecated std.utf.toUTF8 |
Classes
| Name | Description |
|---|---|
RefCountedObject
|
Base class for reference counted objects, maintains reference counter inplace. |
Structs
| Name | Description |
|---|---|
CalcSaver
|
This struct allows to not execute some code if some variables was not changed since the last check. Used for optimizations. |
Glyph
|
Character glyph. |
MallocBuf
|
C malloc allocated array wrapper |
Point
|
2D point |
Rect
|
2D rectangle |
Ref
|
Reference counting support. |
Enums
| Name | Description |
|---|---|
State
|
widget state bit flags |
SubpixelRenderingMode
|
Subpixel rendering mode for fonts (aka ClearType) |
Manifest constants
| Name | Type | Description |
|---|---|---|
FILL_PARENT
|
layout option, to occupy all available place | |
POINTS_PER_INCH
|
one point is 1/72 of inch | |
SIZE_IN_PERCENTS_FLAG
|
(RESERVED) use in styles to specify size in percents * 100 (e.g. 0 == 0%, 10000 == 100%, 100 = 1%) | |
SIZE_IN_POINTS_FLAG
|
use in styles to specify size in points (1/72 inch) | |
SIZE_UNSPECIFIED
|
use as widget.layout() param to avoid applying of parent size | |
WRAP_CONTENT
|
layout option, for size based on content |
Global variables
| Name | Type | Description |
|---|---|---|
RECT_VALUE_IS_NOT_SET
|
immutable(Rect)
|
constant acting as "rectangle not set" value |