STATORWORKS

ROBOTICS, MICROCONTROLLERS, DESKTOP, GRAPHICS AND MORE


GDIX
DIRECT2D GRAPHICS WRAPPER - REFERENCE

BASIC METHODS
GetVersionNumber Retrieve GDIX version number
Returns: U32 XX integer. i.e. 10 = version 1.0


GetLastErrorString Obtain a string describing the result of the last operation
Returns: str16* Pointer to string


GetCurrentState Obtains the running state of GDIX
Returns: U32 0=uninitialized, 1=ready 2=drawing (between BeginDraw and EndDraw calls)


SetQuality Selects whether to force rendering with old GDI graphics fallback or use Direct2D.
Note that the default is Direct2D with automatic GDI fallback,
if this method is not called.
Calling this method forces a restart of GDIX,
so you have to reload any bitmaps or fonts.
Preferably just call it just once at the beginning, if you need it at all.
Bool high: 0=force use GDI 1= use Direct2D
Returns: none


EnterRegistrationCode Unregistered library draws watermark on rendered images
The paid for livcense number clears the watermark on rendered images
U32 value: numerical code
Returns: none


BeginDraw1 Sets up internals to draw on specified window target.
Must be matched by end_draw() when finished drawing.
HWND hwnd: target window panel
RECT* r: pointer to rectangle defining portion to draw on
Returns:Bool 0=fail 1=success


BeginDraw2 Sets up internals to draw on specified offscreen bitmap target.
Must be matched by end_draw() when finished drawing.
U32 bitmap*: pointer to user bitmap id holder
Returns:Bool 0=fail 1=success


GetRenderData Retrieves pixels from last drawn target.
Must be called after finished drawing with end draw()
RECT source area: Rectangle portion to retrieve pixels from. 0=whole area
U32* dest_address_argb32: Application buffer where pixels should be copied
U32 buffer size: Size in bytes. Must be correct so buffer is not overrun
Returns:Bool 0=fail 1=success


SetAntialias Turns the smoothing of lines and edges on and off.
Default: On
Tip: No antialias produces sharper looking horizontal and vertical lines.
Bool ON: 0=Off 1=On
Returns:0=fail 1=success


GetTargetSize Retrive the current drawing area dimensions
Returns:SIZE (x and y)


SHAPE AND FILL METHODS
FillBackground Fills whole target area with specified color.
Usually called first, right after begin_draw()
U32 color_argb: Color in 32-bit alpha, red, green, blue format
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
Returns:0=fail 1=success


DrawLine1 Line from point 1 to point 2
U32 x1,y1,x2,y2:xy locations for start and end points
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 Thickness: Line width in pixels
Bool Gradient use: 0= none 1=linear 2=Radial
For gradient use, must have previously called setup_linear_gradient() or setup_radial_gradient()
Returns:0=fail 1=success


DrawLine2 Line from point 1 to point 2
POINT p1,p2:Start and end points
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 Thickness: Line width in pixels
Bool Gradient use: 0= none 1=linear 2=Radial
For gradient use, must have previously called setup_linear_gradient() or setup_radial_gradient()
Returns:0=fail 1=success


DrawPolyline Draw multiple concatenated lines in one call
POINT* Origin:Location. Line point cordinates will be with respect to this
F32 Scale x and y: Point location coordinates will be multiplied by these. Use 1.0, 1.0 forn no change.
F32 pointsXY: Pointer to array of point locations, x y in float type.
F32 pointsXY: Pointer to array of point locations, x y in float type.
Examples: POINT points[100]; pass Points[0] or &points
Bool closed:connect figure between the last and first point.
F32 angle: rotate the figure points around the origin provided by angle_origin argument
POINT* angle origin: rotation point for angle argument. This point is with respect to Origin argument
U32 color_argb: Color in 32-bit alpha, red, green, blue format. Examples:
0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 thickness: Line width in pixels
Bool filled: Fill the figure with color, gradient, or bitmap, as per the rest of the arguments
U32 fill_color_argb: Color in 32-bit alpha, red, green, blue format. Same scheme as color_argb argument.
Bool use_gradient: Use the gradient as setup by last call to SetLinearGradient() or SetRadialGradient() methods
0= none 1=linear 2=Radial
U32* bitmap_id: Bitmap to fill figure with. This id number is obtained when calling LoadBitmap methods
RECT* bitmap_source_rect: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


DrawPolylineQuick Same as DrawPolyline but uses musch faster method.
Tradeoff is no line-mitter on corners and no figure filling. Just use with thin lines.
Returns:0=fail 1=success


DrawRectangle Draw straight or rounded rectangle
RECT* r: Pointer to user rectangle defining the area of the rectangle.
0=use whole target area
F32 angle: Rotate rectangle around its center, in degrees.
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 thickness: Border width in pixels
offset: Offset the border by these many pixels
Bool filled: fill the figure with color, gradient, or bitmap, as per the rest of the arguments
fill_color_argb: Color in 32-bit alpha, red, green, blue format.
Same scheme as color_argb argument.
Bool Use_gradient: Use the gradient as setup by last call to SetLinearGradient() or SetRadialGradient() methods
0= none 1=linear 2=Radial
U32* bitmap_id: Bitmap to fill figure with. this id number is obtained when calling LoadBitmap methods
U32* bitmap_source_rect: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


DrawEllipse Draw ellipse inscribed in bounding rectangle
RECT* r: Pointer to user rectangle defining the boundaries ellipse, where it gets inscribed.
0=use whole target area
F32 angle: Rotate ellipse around its center, in degrees.
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 thickness: Border width in pixels
offset: Offset the border by these many pixels
Bool filled: fill the figure with color, gradient, or bitmap, as per the rest of the arguments
fill_color_argb: Color in 32-bit alpha, red, green, blue format.
Same scheme as color_argb argument.
Bool Use_gradient: Use the gradient as setup by last call to SetLinearGradient() or SetRadialGradient() methods
0= none 1=linear 2=Radial
U32* bitmap_id: Bitmap to fill figure with. this id number is obtained when calling LoadBitmap methods
U32* bitmap_source_rect: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


DrawArc Draw arc as segment of ellipse inscribed in bounding rectangle
RECT* r: Pointer to user rectangle defining the boundaries of ellipse that defines the arc, where it gets inscribed.
0=use whole target area
F32 angle: Rotate arc around its center, in degrees.
Note that this is after it is inscribed in the boundaries. Use angle start and angle end arguments to change the end points.
F32 angle_start: starting point of the arc. 0= 3o'clock and positve values follow clockwise
F32 angle_end: end point of the arc. 0= 3o'clock and positve values follow clockwise
Bool Pie: 0= simple arc 1=draw lines to center to complete pie figure. Useful for pie charts, etc.
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 thickness: Border width in pixels
offset: Offset the border by these many pixels
Bool filled: fill the figure with color, gradient, or bitmap, as per the rest of the arguments
fill_color_argb: Color in 32-bit alpha, red, green, blue format.
Same scheme as color_argb argument.
Bool Use_gradient: Use the gradient as setup by last call to SetLinearGradient() or SetRadialGradient() methods
0= none 1=linear 2=Radial
U32* bitmap_id: Bitmap to fill figure with. this id number is obtained when calling LoadBitmap methods
U32* bitmap_source_rect: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


DrawPolygon Draw arc as segment of ellipse inscribed in bounding rectangle
RECT* r: Pointer to user rectangle defining the boundaries of ellipse, where polygon gets inscribed.
0=use whole target area
F32 angle: Rotate arc around its center, in degrees.
Note that this is after it is inscribed in the boundaries. Use angle start and angle end arguments to change the end points.
U32 sides: Minimum 5, maximum 32
F32 phase: rotation angle of polygon, within scribing ellipse. This is different than angle argument.
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
F32 thickness: Border width in pixels
offset: Offset the border by these many pixels
Bool filled: fill the figure with color, gradient, or bitmap, as per the rest of the arguments
fill_color_argb: Color in 32-bit alpha, red, green, blue format.
Same scheme as color_argb argument.
Bool Use_gradient: Use the gradient as setup by last call to SetLinearGradient() or SetRadialGradient() methods
0= none 1=linear 2=Radial
U32* bitmap_id: Bitmap to fill figure with. this id number is obtained when calling LoadBitmap methods
U32* bitmap_source_rect: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


BITMAP METHODS
DrawBitmap1 Render previously loaded bitmap on current drawing target
U32* bitmap_id: Pointer to id of bitmap to use. This id number is obtained when calling LoadBitmap methods
RECT* dest: Pointer to user rectangle defining bitmap render area
0=use whole target area
RECT* source: Pointer to user rectangle defining the area of the bitmap that will be rendered on target area.
0=use whole bitmap
F32 angle: Rotate bitmap render around its center, in degrees.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


DrawBitmap2 Bitmap is atlased from an imaginaty grid. Useful for animation sprites or indexing images
within one same bitmap.
For example, you can create a 512 x 128 bitmap made of 64x64 images, with 8 columns and 2 rows
This method allows you to draw any of the images by specifing the index and number of divisions
U32* bitmap_id: Pointer to id of bitmap to use. This id number is obtained when calling LoadBitmap methods
U32 atlas_index: Atlas grid segment number to use. The order convention here is left to righ and top down
U32 atlas_tiles_x: How many horizontal subdivisions on the bitmap to be considered
U32 atlas_tiles_y: How many horizontal subdivisions on the bitmap to be considered
F32 angle: Rotate bitmap render around its center, in degrees.
F32 bitmap_opacity: Alpha blending of the bitmap. 0.0=0% 1.0 = 100%
Returns:0=fail 1=success


Loadbitmap1 Load bitmap from user file. can be .bmp, .jpg, or .png with alpha
U32* bitmap_id: pointer to user bitmap id variable. Call fills this variable with internal bitmap index number.
Example variable: unsigned int dog_bitmap;
Str16 path: Full path to file, including file name
Returns:0=fail 1=success


Loadbitmap2 Load bitmap from user RAM memory array
Useful for signal processing, direct image modification, effect and experimentation etc.
U32* bitmap_id: pointer to user bitmap id variable. Call fills this variable with internal bitmap index number.
Example variable: unsigned int dog_bitmap;
U32* address_argb32: Pointer to user location with image data. Format must be 32-bit alpha, red, gree, blue
U32* x: Width of bitmap. Make sure X * Y size fits within data array to be read
U32* y: height of bitmap. Make sure X * Y size fits within data array to be read
Bool premultiply_alpha: Set this to 1 when loading data that contain alpha values. Otherwise leave it as 0 for faster process.
Returns:0=fail 1=success


Loadbitmap3 Create empty bitmap with specified color
U32* bitmap_id: pointer to user bitmap id variable. Call fills this variable with internal bitmap index number.
Example variable: unsigned int dog_bitmap;
U32* x: Width of bitmap.
U32* y: Height of bitmap.
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
Returns:0=fail 1=success


GetBitmapSize Obtain bitmap dimensions
U32* bitmap_id: this id number is obtained when calling LoadBitmap methods
Returns:SIZE x y


GetBitmapData Get bitmap pixel data into user RAM array.
U32* bitmap_id: this id number is obtained when calling LoadBitmap methods
U32* dest_address_argb32: pointer to user location to put the image data into. Data format is 32-bit alpha, red, gree, blue
U32 buffer_size: User bufer size. Make sure your buffer matches the requested area's 32bpp * Height * Width
U32* source_area: User rectangle defining requested area from bitmap. 0=get whole bitmap
Returns:0=fail 1=success


UnloadBitmap Frees up system resources related to previously loaded bitmap.
U32* bitmap_id: this id number is obtained when calling LoadBitmap methods
Returns:0=fail 1=success


TEXT STRING METHODS
SetupText Sets up parameters for text rendering, previous to text drawing. Tip: Try to minimize calls to this method, by grouping together rendering of strings that have the same parameters, as opposed to changing styles back and forth.
F32 angle: text string inclination, in degrees.
U32 font_size: Height in pixels
Bool bold: 0=normal 1= bold
Bool italic: 0=normal 1=italic
F32 line_spacing: spacing between lines in multiline text
U32 color_argb: Color in 32-bit alpha, red, green, blue format.
Examples: 0xFFFF0000 =Red 0xFF00FF00=Green 0xFF0000FF=Blue
Bool alignment_horizontal: 0=left 1=center 2=right
Bool alignment_vertical: 0=top 1=center 2=bottom
Bool wrap: 0=clip text outside of bounding rectangle 1=wrap to next line
Bool trim_per_character: When leaving bounding rectangle, 0=trim per word 1=trim per character
Str16 font_name: System font name, or nickname give to previously loaded custom font
Returns:0=fail 1=success


DrawText1 Render text string with parameters as per previous call to SetupText() method
RECT* r: Pointer to user rectangle defining the clipping and wrapping area for the text
Str16 string: Text string. Can be ASCII or UTF-8. Examples: L"ABCD" or L"新闻主".
Where L is the visual studio prefix for wide character strings.
Returns:0=fail 1=success


LoadCustomFont1 Load user font file from storage
Str16 file_path: Full path, including file name. Can be .ttf or .otf font files
Str16 nickname: User chosen familiar name for this custom font. Use this when calling SetupText() to use this font.
Returns:0=fail 1=success


LoadCustomFont2 Load user font file from Windows executable resource data.
Please refer to the GDIX demo project to see how to embedd font files in your executable.
Note that you must check that the author for the given font allows this kind of embedded distribution.
U32 resourceID: Font id as user defined in Resource.h and resource.rc files
Str16 nickname: User chosen familiar name for this custom font. Use this when calling SetupText() to use this font.
Returns:0=fail 1=success


UnloadCustomFont Frees up system resources related to previously loaded custom font.
Str16 nickname: User chosen familiar name given when the font was loaded
Returns:0=fail 1=success


GetTextWidth Obtains the width in pixels for a given string, with parameters as per a previous call to SetupText() method You need to test this with your particular fonts as there are quite a lot of variations.
Str16 string: Text string. Can be ASCII or UTF-8. Examples: L"ABCD" or L"新闻主".
Where L is the visual studio prefix for wide character strings.
Returns:0=fail 1=success


COLOR GRADIENT METHODS
SetLinearGradient Sets pararmeters for linear gradient filling of figures
RECT* r: Pointer to user rectangle defining the gradient.
The top-left and bottom right points of the rectangle define the start point and end point.
gradient_point* points: Array of stop points of the gradient. Each point has the form: struct{float stop, color_argb32}
Where stop is a number between 0.0 and 1.0, which correspond to the start and end points of the gradient
and color is 32-bits alpha, red, green, blue.
U32 count: Number of stops in the array
F32 alpha: overall translucency of the gradient.
0.0=transparent 1.0=solid
Returns:0=fail 1=success


SetRadialGradient Sets pararmeters for Radial gradient filling of figures
RECT* r: Pointer to user rectangle defining the gradient. The starting origin point of the gradient is within the rectangle, and the rectangle itself bounds the whole gradient.
gradient_point* points: Array of stop points of the gradient. Each point has the form: struct{float stop, color_argb32}
Where stop is a number between 0.0 and 1.0, which correspond to the start and end points of the gradient
and color is 32-bits alpha, red, green, blue.
POINT* origin_x y start point of the gradient. This doesn't have to be on the center of the rectangle, it can be offset.
this is given as a fraction of distance from the center to the bounding rectangle
examples: 0,0 = middle 0.25, 0 = a quarter to the right 1.0, 0 = right side
gradient_point* points: Array of stop points of the gradient. Each point has the form: struct{float stop, color_argb32}
Where stop is a number between 0.0 and 1.0, which correspond to the origin and bounding rectangle of the gradient and color is 32-bits alpha, red, green, blue.
U32 count: Number of stops in the array
F32 alpha: overall translucency of the gradient.
0.0=transparent 1.0=solid
Returns:0=fail 1=success


MASK METHODS
MaskSetRectangle Set a clipping rectangle on the drawing area target.
This just sets it up, to activate it call MaskEnable() method
RECT* rect: Pointer to user rectangle defining the clipping area
Returns:0=fail 1=success


MaskSetBitmap Set an arbitary clipping pattern based on a previoulsy loaded or rendered bitmap.
This just sets it up, to activate it call MaskEnable() method
U32* bitmap_id: Bitmap to use as mask. this id number is obtained when calling LoadBitmap methods Black color clips drawing operations. White color keeps drawing operations Currently no colorization feature performed. Limited to black and white.
RECT* rect: Pointer to user rectangle defining the clipping area
Returns:0=fail 1=success


Mask Enable
Bool On: 0=off 1=on
Returns:0=fail 1=success