Graphics context object for drawing operations
Remarks: This class allows you to draw on either a Bitmap or a Drawable control.
Constructors
Graphics
#Initializes a new instance of the Generator class to draw on the given
imageRemarks: To commit the changes to the Bitmap, the Graphics object must be disposed or used with a using block.
Parameters:
| image (Bitmap) | Image to draw on using this graphics context |
Graphics
#public Graphics(IHandler handler)
Initializes a new instance of the Graphics class with the specified platform
handlerParameters:
| handler (Graphics.IHandler) | Platform handler to use for this instance |
Properties
ClipBounds
#Gets the bounds of the clipping region
Remarks: This rectangle will encompass all parts of the clipping region, which may not be rectangular in shape
Value: The clip bounds applied to drawing operations
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.
CurrentTransform
#Gets a copy of the current transform.
Remarks: The current transform is initially an identity matrix. Any transform operations performed on this object will change this value.
Value: The current transform matrix.
DPI
#Gets the dots per inch of the current graphics context. Usually 96 for windows and 72 for other systems
IsDisposed
Gets or sets a value indicating whether this Widget has been disposed.
Remarks: When the widget is disposed, it can no longer be used.
Value:
true if this instance has been disposed; otherwise, false.IsRetained
#Gets a value indicating the graphics sub-system is a retained system (e.g. WPF)
Remarks: Retained mode systems may have different behaviour characteristics, which may impact how often the screen is updated or other code.
NativeHandle
public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
PixelsPerPoint
#Gets the scale of points to pixels. Multiply by point value to get pixel size
Remarks: A value of 1.0 indicates that one pixel equals one point. Windows is usually 1 1/3 (96 dpi) while other systems are usually 1.0 (e.g. linux, os x)
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object
PointsPerPixel
#Gets the scale of points per pixel. Multiply by pixel size to get point value (e.g. to set font size in pixels).
Remarks: A value of 1.0 indicates that one point equals one pixel. Windows is usually 0.75 (96 dpi) while other systems are usually 1.0 (e.g. linux, os x)
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
Example:
// in your UI
var control = new Button { Style = "mystyle" };
// in your platform assembly
using Eto.Mac.Forms.Controls;
Styles.AddHandler<ButtonHandler>("mystyle", handler => {
// this is where you can use handler.Control to set properties, handle events, etc.
handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});Methods
Clear
#Resets all pixels in the ClipBounds region with the specified
colorParameters:
| color (Color) | Color to clear the graphics context |
Clear
#Resets all pixels in the ClipBounds region with the specified
brushParameters:
| brush (SolidBrush = null) | Brush to clear the graphics context |
Dispose
public void Dispose()
Disposes of this widget, supressing the finalizer
Parameters:
| disposing (bool) | True if the caller called Widget.Dispose() manually, false if being called from a finalizer |
DrawArc
#Draws a 1 pixel wide arc with the specified
colorParameters:
| color (Color) | Color of the arc |
| x (float) | X co-ordinate of the upper left corner of the arc |
| y (float) | Y co-ordinate of the upper left corner of the arc |
| width (float) | Width of the arc |
| height (float) | Height of the arc |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the arc |
DrawArc
#Draws a 1 pixel wide arc with the specified
colorParameters:
| color (Color) | Color of the arc |
| rectangle (RectangleF) | Location of the arc |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the arc |
DrawArc
#Draws an arc with the specified
penParameters:
| pen (Pen) | Pen to draw the arc |
| x (float) | X co-ordinate of the upper left corner of the arc |
| y (float) | Y co-ordinate of the upper left corner of the arc |
| width (float) | Width of the arc |
| height (float) | Height of the arc |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the arc |
DrawArc
#Draws an arc with the specified
penParameters:
| pen (Pen) | Pen to draw the arc |
| rectangle (RectangleF) | Location of the arc |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the arc |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the arc |
DrawEllipse
#Draws a 1 pixel wide ellipse outline with the specified
colorDrawEllipse
#Draws a 1 pixel wide ellipse outline with the specified
colorParameters:
| color (Color) | Color to outline the ellipse |
| rectangle (RectangleF) | Location for the ellipse |
DrawEllipse
#Draws an ellipse with the specified
penDrawEllipse
#Draws an ellipse outline with the specified
penParameters:
| pen (Pen) | Pen to outline the ellipse |
| rectangle (RectangleF) | Location for the ellipse |
DrawImage
#Draws the specified
image in a rectangleDrawImage
#Draws the specified
image in a rectangleRemarks: This will scale the image to the specified width and height using the ImageInterpolation mode
Parameters:
| image (Image) | Image to draw |
| rectangle (RectangleF) | Where to draw the image |
DrawImage
#Draws the
source portion of an image, scaling to the specified destinationParameters:
| image (Image) | Image to draw |
| source (RectangleF) | Source rectangle of the image portion to draw |
| destination (PointF) | Destination rectangle of where to draw the portion |
DrawImage
#Draws the
source portion of an image, scaling to the specified destinationParameters:
| image (Image) | Image to draw |
| source (RectangleF) | Source rectangle of the image portion to draw |
| destination (RectangleF) | Destination rectangle of where to draw the portion |
DrawInsetRectangle
#public void DrawInsetRectangle(Color topLeftColor, Color bottomRightColor, RectangleF rectangle, int width = 1)
Draws an rectangle with colors on the top/left and bottom/right with the given
widthParameters:
| topLeftColor (Color) | Color for top/left edges |
| bottomRightColor (Color) | Color for bottom/right edges |
| rectangle (RectangleF) | Outside of inset rectangle to draw |
| width (int = 1) | Width of the rectangle, in pixels |
DrawLine
#Draws a 1 pixel wide line with the specified
colorDrawLine
#Draws a 1 pixel wide line with the specified
colorDrawLine
#Draws a line with the specified
penDrawLine
#Draws a line with the specified
penDrawLines
#Draws a 1 pixel wide set of lines with the specified
pointsParameters:
| color (Color) | Color to draw the lines |
| points (IEnumerable<PointF>) | Points for each of the lines |
DrawLines
#Draws a set of lines with the specified
pointsParameters:
| pen (Pen) | Pen to draw the lines with |
| points (IEnumerable<PointF>) | Points for each of the lines |
DrawPath
#Draws a 1 pixel outline of the specified
pathParameters:
| color (Color) | Draw color |
| path (IGraphicsPath) | Path to draw |
DrawPath
#Draws the specified
pathParameters:
| pen (Pen) | Pen to outline the path |
| path (IGraphicsPath) | Path to draw |
DrawPolygon
#Draws a 1 pixel wide outline of a polygon with the specified
pointsDrawRectangle
#Draws a 1 pixel wide outline of a rectangle with the specified
colorDrawRectangle
#Draws a 1 pixel wide outline of a rectangle with the specified
colorParameters:
| color (Color) | Color for the outline |
| rectangle (RectangleF) | Where to draw the rectangle |
DrawRectangle
#Draws a rectangle
DrawRectangle
#Draws a rectangle
Parameters:
| pen (Pen) | Pen to outline the rectangle |
| rectangle (RectangleF) | Where to draw the rectangle |
DrawText
#Draws text with the specified
font, brush and locationDrawText
#Draws text with the specified
font, brush and locationDrawText
#public void DrawText(Font font, Brush brush, RectangleF frame, string text, FormattedTextWrapMode wrap = FormattedTextWrapMode.Word, FormattedTextAlignment alignment = FormattedTextAlignment.Left, FormattedTextTrimming trimming = FormattedTextTrimming.WordEllipsis)
Draws text in a rectangle with the specified formatted text trimming
Parameters:
| font (Font) | Font to draw the text with |
| brush (Brush) | Brush to fill the text path |
| frame (RectangleF) | Frame for the text to be drawn into |
| text (string) | String to draw |
| wrap (FormattedTextWrapMode = FormattedTextWrapMode.Word) | Wrap mode for the text |
| alignment (FormattedTextAlignment = FormattedTextAlignment.Left) | Alignment of the text in the specified rectangle |
| trimming (FormattedTextTrimming = FormattedTextTrimming.WordEllipsis) | Trimming to apply if the text does not fit in the supplied rectangle |
DrawText
#Draws text with the specified
font, color and locationDrawText
#Draws text with the specified
font, color and locationDrawText
#Draws text with the specified
font, brush and locationParameters:
| font (Font) | Font to draw the text with |
| brush (SolidBrush) | Brush to stroke the text |
| x (float) | X co-ordinate of where to start drawing the text |
| y (float) | Y co-ordinate of where to start drawing the text |
| text (string) | Text string to draw |
DrawText
#Draws text with the specified
font, brush and locationParameters:
| font (Font) | Font to draw the text with |
| brush (SolidBrush) | Brush to stroke the text |
| location (PointF) | Location of where to start drawing the text |
| text (string) | Text string to draw |
DrawText
#Draws formatted text at the specified location
Parameters:
| formattedText (FormattedText) | Formatted text to draw |
| location (PointF) | Location to draw the text |
FillEllipse
#Fills an ellipse with the specified
brushFillEllipse
#Fills an ellipse with the specified
brushParameters:
| brush (Brush) | Brush to fill the ellipse |
| rectangle (RectangleF) | Location for the ellipse |
FillEllipse
#Fills an ellipse with the specified
colorFillEllipse
#Fills an ellipse with the specified
colorParameters:
| color (Color) | Fill color |
| rectangle (RectangleF) | Location for the ellipse |
FillPath
#Fills the specified
pathParameters:
| brush (Brush) | Brush to fill the path |
| path (IGraphicsPath) | Path to fill |
FillPie
#Fills a pie with the specified
brushParameters:
| brush (Brush) | Brush to fill the pie |
| x (float) | X co-ordinate of the upper left corner of the pie |
| y (float) | Y co-ordinate of the upper left corner of the pie |
| width (float) | Width of the pie |
| height (float) | Height of the pie |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the pie |
FillPie
#Fills a pie with the specified
brushParameters:
| brush (Brush) | Brush to fill the pie |
| rectangle (RectangleF) | Location of the pie |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the pie |
FillPie
#Fills a pie with the specified
colorParameters:
| color (Color) | Fill color |
| x (float) | X co-ordinate of the upper left corner of the pie |
| y (float) | Y co-ordinate of the upper left corner of the pie |
| width (float) | Width of the pie |
| height (float) | Height of the pie |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the pie |
FillPie
#Fills a pie with the specified
colorParameters:
| color (Color) | Fill color |
| rectangle (RectangleF) | Location of the pie |
| startAngle (float) | Elliptical (skewed) angle in degrees from the x-axis to the starting point of the pie |
| sweepAngle (float) | Angle in degrees from the startAngle to the ending point of the pie |
FillRectangle
#Fills a rectangle with the specified
brushFillRectangle
#Fills a rectangle with the specified
brushParameters:
| brush (Brush) | Brush to fill the rectangle |
| rectangle (RectangleF) | Location for the rectangle |
FillRectangle
#Fills a rectangle with the specified
colorFillRectangle
#Fills a rectangle with the specified
colorParameters:
| color (Color) | Fill color |
| rectangle (RectangleF) | Location for the rectangle |
FillRectangles
#Fills the specified
rectanglesParameters:
| brush (Brush) | Brush to fill the rectangles |
| rectangles (IEnumerable<RectangleF>) | Enumeration of rectangles to fill |
FillRectangles
#Fills the specified
rectanglesParameters:
| color (Color) | Color to fill the rectangles |
| rectangles (IEnumerable<RectangleF>) | Enumeration of rectangles to fill |
Flush
#public void Flush()
Flushes the drawing (for some platforms)
Remarks: Flushing the drawing will force any undrawn changes to be shown to the user. Typically when you are doing a lot of drawing, you may want to flush the changed periodically so that the user does not think the UI is unresponsive. Some platforms may not have the concept of flushing the graphics, so this would do nothing
GetCallback
Gets an instance of an object used to perform callbacks to the widget from handler implementations
Remarks: The callback should implement the parent class' Widget.ICallback interface so that there only needs to be a single callback for the entire hierarchy. This should return a static instance to avoid having overhead for each instance of your control.
Returns: The callback instance to use for this widget
Initialize
protected void Initialize()
Initializes the widget handler
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.
MeasureString
#Measures the string with the given
fontReturns: Size representing the dimensions of the entire text would take to draw given the specified
fontMultiplyTransform
#Multiplies the co-ordinate system with the given
matrixParameters:
| matrix (IMatrix) | Matrix to multiply the co-ordinate system with |
inherited fromWidget
RestoreTransform
#public void RestoreTransform()
Restores the transform state
Remarks: This restores the transform state from a previous SaveTransform() call. You must balance calls to SaveTransform() with calls to this method.
RotateTransform
#Rotates the co-ordinate system by the given
angleParameters:
| angle (float) | Angle in degrees to rotate the co-ordinates |
SaveTransform
#public void SaveTransform()
Saves the current transform state
Remarks: This saves the current transform state that can be changed by any of the transform calls, which can then be restored using RestoreTransform()
SaveTransformState
#Gets an object that will restore to the current transform state when disposed.
Remarks: This saves the current transform state that can be changed by any of the transform calls. This is useful when calling into untrusted code that can leave the transform unbalanced. It also ensures that RestoreTransform() requires a matching SaveTransform(), until the return value is disposed. Disposing the return value guarantees that the transform state is restored to when this method was called.
Example:This example shows how you can reliably restore state in a code block:
using (graphics.SaveTransformState())
{
// ...
graphics.SaveTransform();
graphics.MultiplyTransform(...);
// ... other messy drawing code that doesn't call RestoreTransform()
}ScaleTransform
#Scales the co-ordinate system by a factor
Parameters:
| scale (float) | Amount to scale in both the horizontal and vertical axis |
ScaleTransform
#Scales the co-ordinate system by a factor
ScaleTransform
#Scales the co-ordinate system by a factor
Parameters:
| scale (SizeF) | Amount to scale in the horizontal and vertical axis |
SetClip
#Sets the clip region to the specified
pathRemarks: The previous clipping region will be cleared after this call The path specified is translated by the current transform, but is not affected by subsequent transform operations.
Parameters:
| path (IGraphicsPath) | Path to specify the clip region |
SetClip
#Sets the clip region to the specified
rectangleRemarks: The previous clipping region will be cleared after this call. The rectangle specified is translated by the current transform, but is not affected by subsequent transform operations.
Parameters:
| rectangle (RectangleF) | Rectangle for the clipping region |
ToString
Gets a string that represents the current object with its ID if specified.
Returns: A string value indicating the type and ID (if specified) of this widget.
Overrides: Object.ToString
TranslateTransform
#Translates the origin of the co-ordinate system by the given offset
Events
inherited fromWidget