Site Tools

RhPicture Plug-in GDI Brush Objects

Summary: A description of the GDI Brush objects as exposed through the RhPicture plug-in

GDI+ Brush objects

GDI+ Brush objects are used to draw contents (fills) of geometry. There are several distinct Brush types available in GDI+, some of which are exposed in the RhPicture plug-in:

  • Solid
  • Hatch
  • Texture
  • Linear Gradient

Brush types not available in the RhPicture plug-in:

  • Path Gradient

Note that you do not need a Brush object to draw fills in the RhPicture plug-in. Every method that takes a Brush object is overloaded and can be called with a color instead, in which case you get a simple solid fill:

Dim RhPicture : Set RhPicture = Rhin.GetPluginObject("RhPicture")
Call RhPicture.CreateImage(80, 50, vbWhite)
Call RhPicture.FillCircle(Array(40,25), 20, vbRed)

If you want to draw non-solid fills, you'll have to use an RhPicture Brush object. You can obtain a Brush object by calling one of the Brush creation methods on RhPicture:

Dim RhPicture : Set RhPicture = Rhin.GetPluginObject("RhPicture")
Call RhPicture.CreateImage(80, 50, vbWhite)
Dim BrushObj : Set BrushObj = RhPicture.CreateGradientBrush(Array(0, 0), Array(50,0), vbRed, vbBlack)
Call RhPicture.FillCircle(Array(40,25), 20, BrushObj)

Note that you can store any number of Brush objects in your script and you can reuse them as often as you like. Brush objects are not bound to the RhPicture instance that created them and you can use them on any RhPicture object. There are several Brush creation methods available, one for each type of Brush:

RhPicture.CreateSolidBrush(Color As GDIColor) As GDIBrush
RhPicture.CreateHatchBrush(HatchStyle As Integer, Foreground As GDIColor, Optional Background As GDIColor) As GDIBrush
RhPicture.CreateTextureBrush(Texture As String, Optional WrapMode As Integer) As GDIBrush
RhPicture.CreateGradientBrush(From As GDIPoint, To As GDIPoint, Color1 As GDIColor, Color2 As GDIColor) As GDIBrush
Parameter Type Description
Color GDIColor A GDIColor instance used for the solid fill.
HatchStyle Integer A Hatch style enumeration. See table below for valid values.
Foreground GDIColor The color to assign to the hatch pattern.
Background GDIColor The color to assign to the background of the hatch pattern. If omitted, the hatch is drawn with a transparant background.
Texture String The path of an existing image file to use as texture.
WrapMode Integer The wrapping style enumeration controlling how the texture is tiled. See table below for valid values.
From GDIPoint A 2D coordinate that defines the start of the gradient.
To GDIPoint A 2D coordinate that defines the end of the gradient.
Color1 GDIColor The color at the start of the gradient.
Color2 GDIColor The color at the end of the gradient.

Enumerations explained:

HatchBrush style enumeration constants. GDI+ defines 53 different hatch styles. The zip-file contains all of these.
HatchBrush Constants
Hatch = 0 Hatch = 1 Hatch = 2 Hatch = 3 Hatch = 4
Hatch = 5 Hatch = 6 Hatch = 7 Hatch = 8 Hatch = 9
Hatch = 10 Hatch = 11 Hatch = 12 Hatch = 13 Hatch = 14
Hatch = 15 Hatch = 16 Hatch = 17 Hatch = 18 Hatch = 19
Hatch = 20 Hatch = 21 Hatch = 22 Hatch = 23 Hatch = 24
Hatch = 25 Hatch = 26 Hatch = 27 Hatch = 28 Hatch = 29
Hatch = 30 Hatch = 31 Hatch = 32 Hatch = 33 Hatch = 34
Hatch = 35 Hatch = 36 Hatch = 37 Hatch = 38 Hatch = 39
Hatch = 40 Hatch = 41 Hatch = 42 Hatch = 43 Hatch = 44
Hatch = 45 Hatch = 46 Hatch = 47 Hatch = 48 Hatch = 49
Hatch = 50 Hatch = 51 Hatch = 52

TextureBrush tile constants.
Repeat x & y Mirror x Mirror y Mirror x & y Single tile
Tile = 0 Tile = 1 Tile = 2 Tile = 3 Tile = 4

Linear Gradients explained:

Be careful when using Linear Gradient brushes. The coordinates that define the start and end points of the gradient may be subject to noise. Since gradients are stacked rather than mirrored it is possible you get bleeding colors if you've defined your gradient to fit exactly within your drawing region. It is usually best to make the gradient extend one pixel in each direction:

developer/rhpicture/gdibrush.txt ยท Last modified: 2016/03/18 by sandy