GH_GraphicsUtil
Utility class with static (Shared) functions that help with colour, shape and text rendering.
Properties
Methods
AppendArc
#Append an arc segment to a GraphicsPath. If the arc cannot be solved, a linear segment is appended instead.
Parameters:
| p0 (Point3d) | Start point of arc. |
| p1 (Point3d) | End point of arc. |
| dir (Vector3d) | Tangent direction at start of arc. |
| path (GraphicsPath) | Path to append to. |
AppendArc
#Append an arc segment to a GraphicsPath. If the arc cannot be solved, a linear segment is appended instead.
Parameters:
| p0 (PointF) | Start point of arc. |
| p1 (PointF) | End point of arc. |
| dir (SizeF) | Tangent direction at start of arc. |
| path (GraphicsPath) | Path to append to. |
BlendColour
#public static Color BlendColour(Color bottom, Color top)
Overlays two colours. The Alpha component of the top colour controls the blend.
BlendInteger
#Calculates a linear blend between two extremes. Although the inputs are unlimited integers, the output is an integer in the byte range (0-255).
Parameters:
| t0 (double) | Value of first extreme. |
| t1 (double) | Value of second extreme. |
| a0 (int) | Integer value at first extreme. |
| a1 (int) | Integer value at second extreme. |
| t (double) | Interpolation parameter. |
Returns: Interpolated value.
Example:This function is useful when you need to link colour alpha amounts to zoom levels:
Sub DrawZoomAwareCircle(ByVal G As Graphics, _
ByVal center As PointF, _
ByVal radius As Single, _
ByVal fill As Color)
'Find the zoom level of the Graphics transform.
Dim zoom As Single = G.Transform.Elements(0)
'Abort if zoom less than 25%
If (zoom < 0.25f) Then Return
'Blend the alpha channel byte between 25% and 95% zoom.
Dim alpha As Int32 = GH_GraphicsUtil.BlendByte(0.25, 0.95, 0, 255, zoom)
G.FillEllipse(center.X - radius, center.Y - radius, _
2.0f * radius, 2.0f * radius, _
New SolidBrush(Color.FromARGB(alpha, fill)))
End SubBoxClosestArcPoint
#Find the closest point on or in a box given a test point. Arc extension is implied.
Parameters:
| pt (PointF) | Sample point. |
| box (RectangleF) | Box to evaluate. |
BoxClosestPoint
#public static Point BoxClosestPoint(Point pt, Rectangle box)
Find the closest point on or in a box given a test point.
BoxClosestPoint
#Find the closest point on or in a box given a test point.
Parameters:
| pt (PointF) | Sample point. |
| box (RectangleF) | Box to evaluate. |
BoxFurthestPoint
#public static Point BoxFurthestPoint(Point pt, Rectangle box)
Find the furthest point on or in a box given a test point.
BoxFurthestPoint
#Find the furthest point on or in a box given a test point.
Parameters:
| pt (PointF) | Sample point. |
| box (RectangleF) | Box to evaluate. |
BoxViewCone
#Computes the graphicspath that represents the viewcone for a point and a rectangle. If the rectangle contains the point, null is returned.
Parameters:
| pt (PointF) | |
| box (RectangleF) |
ColourARGB
#Create a colour from floating ARGB channels (0.0~1.0). Channels are clipped to valid ranges.
ColourARGB
#Create a colour from integer ARGB channels. Channels are clipped to valid ranges.
ColourARGB
#Create a colour from integer RGB channels. Channels are clipped to valid ranges.
CreateColourIcon
#Create a colour swatch icon.
DentHorizontal
#Draws a horizontal dent. A horizontal dent had dark lines along the top and bottom edges.
DentHorizontal
#Draws a horizontal dent. A horizontal dent had dark lines along the top and bottom edges.
DentVertical
#Draws a vertical dent. A vertical dent had dark lines along the left and right edges.
EtchHorizontal
#Draws an etched line segment.
EtchVertical
#Draws an etched line segment.
EtchVertical
#Draws an etched line segment.
FadeColour
#Fade a colour to transparency by linearly blending a parameter between extremes.
ForegroundColour
#Calculates a suitable foreground color. If the background is lighter than 50%, the foreground will be darker, otherwise the foreground will be lighter.
Grid
#Draw a default grid.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| rec (RectangleF) | Grid rectangle. |
| density (int) | Density in both directions. |
Grid
#public static void Grid(Graphics g, RectangleF rec, int densityX, int densityY, Color colorBg, Color colorWire)
Draw a grid.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| rec (RectangleF) | Grid rectangle. |
| densityX (int) | Density in x direction. |
| densityY (int) | Density in y direction. |
| colorBg (Color) | Background colour override, the default is 30/255 white. |
| colorWire (Color) | Grid line colour override, the default is 40/255 black. |
Grid
#Draw a default grid.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| rec (RectangleF) | Grid rectangle. |
| densityX (int) | Density in x direction. |
| densityY (int) | Density in y direction. |
HighlightBrush
#Gets a new brush object that can be used to draw the content of hover and focus rectangles. Caller is responsible for disposing the brush.
HighlightPen
#Gets a new pen object that can be used to draw the edges of hover and focus rectangles. Caller is responsible for disposing the pen.
InvertColour
#public static Color InvertColour(Color col)
Computes the inverted colour. Alpha remains the same.
Parameters:
| col (Color) |
Returns: Colour where RGB channels are set to 255-C.
IsPointInEllipse
#Test whether a point is inside or outside an ellipse.
Parameters:
| ellipse (RectangleF) | Rectangle describing ellipse. |
| point (PointF) | Point to test for inclusion. |
Returns: True if the point is in or on the ellipse.
LimitIntegers
#Limits RGB channels to the 0~255 range,
OffsetColour
#Add a fixed value to all the channels in a colour.
Remarks: The alpha channel of the colour is not offset.
Parameters:
| col (Color) | The colour to mutate |
| redShift (int) | Offset value for red channel (-255 ~ +255). |
| greenShift (int) | Offset value for green channel (-255 ~ +255). |
| blueShift (int) | Offset value for blue channel (-255 ~ +255). |
Returns: The offsetted colour.
RenderBalloonTag
#public static void RenderBalloonTag(Graphics g, string text, Font font, Color backColor, Color foreColor, PointF tip, RectangleF container)
Draw a balloon tag in a container.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| text (string) | Text of tag. |
| font (Font) | Font of tag. |
| backColor (Color) | Background colour of balloon. |
| foreColor (Color) | Foreground colout of balloon edge and text. |
| tip (PointF) | Tip of balloon (should be inside container). |
| container (RectangleF) | Container for balloon. |
RenderBalloonTag
#public static void RenderBalloonTag(Graphics g, string text, Font font, PointF tip, RectangleF container)
Draw a default balloon tag in a container with a Font override.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| text (string) | Text of tag. |
| font (Font) | Font of tag. |
| tip (PointF) | Tip of balloon. |
| container (RectangleF) | Container for balloon. |
RenderBalloonTag
#Draw a default balloon tag in a container.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| text (string) | Text of tag. |
| tip (PointF) | Tip of balloon. |
| container (RectangleF) | Container for balloon. |
RenderCenteredIcon
#Draw an icon centered in a frame. This code is not zoom-aware, but it will perform consistent rounding (to avoid pixel-jitter when moving the frame across the screen). Icon will not be clipped to the frame.
Parameters:
| g (Graphics) | Graphics object to render with. |
| frame (RectangleF) | Frame to center icon in. |
| icon (Image) | Icon to render |
| alpha (double) | Transparency factor. |
RenderCenteredIcon
#obsoleteThis method is obsolete, use a RenderIcon() overload instead.
Draw an icon centered in a frame. This code is not zoom-aware, but it will perform consistent rounding (to avoid pixel-jitter when moving the frame across the screen). Icon will not be clipped to the frame.
Parameters:
| g (Graphics) | Graphics object to render with. |
| frame (RectangleF) | Frame to center icon in. |
| icon (Image) | Icon to render |
| scale (float) |
RenderCenteredIcon
#obsoleteThis method is obsolete, use a RenderIcon() overload instead.
Draw an icon centered in a frame. This code is not zoom-aware, but it will perform consistent rounding (to avoid pixel-jitter when moving the frame across the screen). Icon will not be clipped to the frame.
Parameters:
| g (Graphics) | Graphics object to render with. |
| frame (RectangleF) | Frame to center icon in. |
| icon (Image) | Icon to render |
RenderColourIcon
#Render a colour icon into a graphics context. A colour icon contains a black outer and white inner edge.
RenderColourIcon
#obsoleteUse RenderColourIcon(Graphics, Rectangle, Color, Single) instead.
Render a colour icon into a graphics context. A colour icon contains a black outer and white inner edge.
RenderHighlightBox
#Render a typical blueish highlight rectangle
Parameters:
| g (Graphics) | Graphics object to render with. |
| box (Rectangle) | Dimensions of selection box. |
| cornerRadius (int) | Radius (in pixels) of box corners, use zero or less to render crisp rectangles. |
| drawFill (bool) | If true, the box fill have a blue background. |
| drawEdge (bool) | If true, the box will have a blue edge. |
RenderHighlightBox
#Render a typical blueish highlight rectangle
RenderIcon
#Render an icon into a frame. The icon is positioned in the center and will be drawn at its own size multiplied by the system UiScale, provided it doesn't exceed the frame.
Parameters:
| graphics (Graphics) | Graphics object to draw with. |
| frame (RectangleF) | Limiting frame. |
| icon (Image) | Icon to draw. |
RenderObjectOverlay
#public static void RenderObjectOverlay(Graphics graphics, IGH_DocumentObject obj, RectangleF target)
Render all overlay icons for a specific object. Overlays aren't drawn when the zoom is less than 80%
Parameters:
| graphics (Graphics) | Graphics object to draw with. |
| obj (IGH_DocumentObject) | Object to draw overlay for. |
| target (RectangleF) | Destination area for overlay icons. |
RenderObjectOverlay
#Render all overlay icons for a specific object. Overlays aren't drawn when the zoom is less than 80%
Parameters:
| graphics (Graphics) | Graphics object to draw with. |
| obj (IGH_ObjectProxy) | Proxy to draw overlay for. |
| target (RectangleF) | Destination area for overlay icons. |
RenderRoundBar
#Render a cylinder shaped object with round caps.
Parameters:
| graphics (Graphics) | Graphics object to draw with. |
| rec (RectangleF) | Rectangle containing shape. |
| colour (Color) | Fill colour of shape. |
RenderTag
#public static void RenderTag(Graphics g, string tag, Font font, Color backColor, Color foreColor, RectangleF frame, StringAlignment alignH, StringAlignment alignV)
Render a text tag into a Graphics surface.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| tag (string) | Text to draw. |
| font (Font) | Font to use. |
| backColor (Color) | Tag background colour. |
| foreColor (Color) | Tag foreground colour. |
| frame (RectangleF) | The frame into which the tags should be aligned. |
| alignH (StringAlignment) | Horizontal alignment. |
| alignV (StringAlignment) | Vertical alignment. |
Example:This example shows how to render the 8 corner and edge tags into a rectangle:
Function RenderCornerAndEdgeTags(ByVal G As Graphics, ByVal frame As RectangleF)
Dim font As New Font("Courier New", 8)
Dim bg As Color = Color.White
Dim fg As Color = Color.Black
'Render the 4 corner tags
RenderTag(G, "UL", font, bg, fg, frame, StringAlignment.Near, StringAlignment.Near)
RenderTag(G, "UR", font, bg, fg, frame, StringAlignment.Far, StringAlignment.Near)
RenderTag(G, "LR", font, bg, fg, frame, StringAlignment.Far, StringAlignment.Far)
RenderTag(G, "LL", font, bg, fg, frame, StringAlignment.Near, StringAlignment.Far)
'Render the 4 edge tags
RenderTag(G, "T", font, bg, fg, frame, StringAlignment.Center, StringAlignment.Near)
RenderTag(G, "R", font, bg, fg, frame, StringAlignment.Far, StringAlignment.Center)
RenderTag(G, "B", font, bg, fg, frame, StringAlignment.Center, StringAlignment.Far)
RenderTag(G, "L", font, bg, fg, frame, StringAlignment.Near, StringAlignment.Center)
End FunctionRenderUnscaledIcon
#obsoleteThis method is obsolete, use a RenderIcon() overload instead.
Draws an image file at 1:1 scale centered on the given coordinates.
RenderUnscaledIcon
#obsoleteThis method is obsolete, use a RenderIcon() overload instead.
Draws an image file at 1:1 scale centered on the given coordinates.
RenderVerticalString
#public static void RenderVerticalString(Graphics g, string text, Font font, Color colour, RectangleF rec, StringFormat format)
Render vertical text (rotated 90 degrees counter-clockwise) within a rectangle.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| text (string) | Text to render. |
| font (Font) | Font to render with. |
| colour (Color) | Colour of text content. |
| rec (RectangleF) | |
| format (StringFormat) | Formatting flags. |
RenderWarningIcon
#Render a typical warning icon into a graphics context. A warning icon is an upright yellow triangle.
ShadowHorizontal
#Draws a horizontal shadow edge.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| x0 (float) | Start of shadow edge. |
| x1 (float) | End of shadow edge. |
| y (float) | Elevation of shadow edge. |
| size (float = 10) | Length of cast shadow. |
| below (bool = true) | If true, shadow is drawn below elevation line. |
| darkness (int = 50) | Alpha component of darkness directly underneath the edge. |
ShadowHorizontal
#Draws a horizontal shadow edge.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| x0 (int) | Start of shadow edge. |
| x1 (int) | End of shadow edge. |
| y (int) | Elevation of shadow edge. |
| size (int = 10) | Length of cast shadow. |
| below (bool = true) | If true, shadow is drawn below elevation line. |
| darkness (int = 50) | Alpha component of darkness directly underneath the edge. |
ShadowRectangle
#Draws shadow edges on the interior of a rectangle.
ShadowRectangle
#Draws shadow edges on the interior of a rectangle.
ShadowVertical
#Draws a vertical shadow edge.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| x (float) | Offset of shadow edge. |
| y0 (float) | Start of shadow edge. |
| y1 (float) | End of shadow edge. |
| size (float = 10) | Length of cast shadow. |
| right (bool = true) | If true, shadow is drawn to the right of the elevated line. |
| darkness (int = 50) | Alpha component of darkness directly underneath the edge. |
ShadowVertical
#Draws a vertical shadow edge.
Parameters:
| g (Graphics) | Graphics object to draw with. |
| x (int) | Offset of shadow edge. |
| y0 (int) | Start of shadow edge. |
| y1 (int) | End of shadow edge. |
| size (int = 10) | Length of cast shadow. |
| right (bool = true) | If true, shadow is drawn to the right of the elevated line. |
| darkness (int = 50) | Alpha component of darkness directly underneath the edge. |
SolveArc
#public static bool SolveArc(PointF p0, PointF p1, SizeF dir, ref RectangleF box, ref float angle, ref float sweep)
Create a GDI circular arc definition from start-point, end-point and tangent direction.
TransparencyMatrix
#Create an image transparency matrix for a specific blending factor.
Parameters:
| fade (double) | Alpha fade amount. 0.0=complete transparency, 1.0=original transparency. |