Requires: Direct2D.lg32
Sets the foreground and/or the background color using ARGB colours for use with drawing commands.
D2Color [argbFore] [, argbBack]
argbFore, argbBack | : integer expression |
The arguments of D2Color take an ARGB color value. The GB Direct2D library defines the Direct2D ARGB color constants for many colors. The names of these ARGB color constants start with D2C_ and are formatted as D2C_COLORNAME. An alternative is to use the ARGB conversion function.
D2Color command sets the D2ForeColor and/or D2BkColor variables. Instead of using D2Color these variables can be used directly. By default, D2ForeColor is D2C_Black and D2BkColor is D2C_White.
' D2Color sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
OpenW 1, 0, 0, 320, 260, ~15
// Here: create Win_1 render target resources
Set Win1RT = D2GetRT(Me.hWnd, 640, 480) ' window
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2SetRT Win1RT ' or Set D2CurRT = Win1RT
D2BeginDraw
D2Color D2C_Chocolate, D2C_Bisque
D2Clear
D2DefLine , 4
D2Circle 320, 240, 100
D2EndDraw
EndSub
When the the D2Line, D2Box, D2RBox, D2Circle, D2Ellipse commands do not specify a drawing brush, the GB library will create a temporary solidcolor brush based on the foreground color. The background color is only used with D2Clear. By default, all drawing commands are drawed transparently.
An alternative is the D2RGBColor command, which takes RGB formatted color values.
D2Color can only be used between D2BeginDraw and D2EndDraw. The colors are reset (to 0) in the D2EndDraw command.
Exported variables that can set and read the foreground and background color for use with drawing commands.
D2ForeColor = argb or argb = D2ForeColor
D2BkColor = argb or argb = D2BkColor
argb | : integer expression |
The variables must be initialized with an ARGB color value. The GB Direct2D library defines the Direct2D ARGB color constants for many colors. The names of these ARGB color constants start with D2C_ and are formatted as D2C_Colorname. An alternative is to use the ARGB conversion function.
Since D2ForeColor and D2BkColor are exported variables they can be read as well.
D2Preset is the only command that uses the D2BkColor setting.
'
' D2BkColor sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
OpenW 1, 0, 0, 320, 260, ~15
// Here: create Win_1 render target resources
Set Win1RT = D2GetRT( , Me.hWnd, 640, 480) ' window
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2SetRT Win1RT ' or Set D2CurRT = Win1RT
D2BeginDraw
D2BkColor = D2C_Bisque
D2Clear
D2ForeColor = D2C_Chocolate
D2DefLine , 4
D2Circle 320, 240, 100
D2EndDraw
EndSub
When the the D2Line, D2Box, D2RBox, D2Circle, D2Ellipse commands do not specify a drawing brush, the GB library will create a temporary solidcolor brush based on the foreground color. The background color is only used with D2Clear. By default, all drawing commands are drawed transparently.
An alternative is the D2RGBColor command, which takes RGB formatted color values.
D2Color can only be used between D2BeginDraw and D2EndDraw. The colors are reset (to 0) in the D2EndDraw command.
Sets the foreground and/or the background color using RGB colours for use with drawing commands.
D2RGBColor [RGBFore] [, RGBBack]
RGBFore, RGBBack | : integer expression |
The arguments of D2RGBColor take a RGB color value. Internally, the RGB values are converted to ARGB color values where the alpha value is set to zero.
D2RGBColor command sets the D2ForeColor and/or D2BkColor variables. Instead of using D2RGBColor these variables can be used directly. By default, D2ForeColor is D2C_Black and D2BkColor is D2C_White.
'
' D2RGBColor sample (dpi-unaware)
'
$Library "direct2d"
Global Object Win1RT
OpenW 1, 0, 0, 320, 260, ~15
Set Win1RT = D2GetRT(Me.hWnd, 640, 480) ' window
' Here: create Win_1 render target resources
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2SetRT Win1RT ' or Set D2CurRT = Win1RT
D2BeginDraw
D2RGBColor RGB(192, 0, 0), RGB(128, 128, 128) 'red, gray
D2Clear
D2DefLine , 4
D2Circle 320, 240, 100
D2EndDraw
EndSub
When the drawing functions do not specify a drawing brush the GB library will create a temporary solid color brush based on the foreground color. The background color is only used with D2Clear. An alternative for setting the colors is the D2Color command, which takes ARGB formatted color values.
D2RGBColor can only be used between D2BeginDraw and D2EndDraw. The colors are reset (to 0) in the D2EndDraw command.
{Created by Sjouke Hamstra; Last updated: 17/03/2021 by James Gaite}