On this page:
DC
DC.handle
DC.from_  handle
DC.width
DC.height
DC.size
DC.clear
DC.pen
DC.brush
DC.font
DC.clipping_  region
DC.transformation
DC.scale
DC.translate
DC.rotate
DC.transform
DC.save
DC.restore
DC.save_  and_  restore
DC.point
DC.line
DC.lines
DC.polygon
DC.rectangle
DC.rounded_  rectangle
DC.ellipse
DC.arc
DC.path
DC.text
DC.bitmap
DC.copy
DC.font_  metrics_  key
DC.Bitmap  Overlay
DC.Text  Combine
DC.Fill
DC.Transformation
8.12

1 Drawing Context🔗ℹ

interface

interface DC

Represents a drawing context that renders to some desination, such as a bitmap or the screen.

One way to get a drawing context is Bitmap.make_dc.

property

property (dc :: DC).handle :: Any

 

function

fun DC.from_handle(hand :: Any) :: DC

The DC.handle property returns a Racket object that corresponds to the drawing context for use directly with racket/draw. The DC.from_handle function creates a DC from such a Racket object.

property

property (dc :: DC).width :: NonnegReal

 

property

property (dc :: DC).height :: NonnegReal

 

property

property (dc :: DC).size :: Size

The size of the drawing area: width, height, or both.

method

method (dc :: DC).clear() :: Void

Resets the output to an empty state.

property

property

| (dc :: DC).pen :: Pen

| (dc :: DC).pen := (p :: Pen)

 

property

property

| (dc :: DC).brush :: Brush

| (dc :: DC).brush := (b :: Brush)

 

property

property

| (dc :: DC).font :: Font

| (dc :: DC).font := (f :: Font)

 

property

property

| (dc :: DC).clipping_region :: maybe(Region)

| (dc :: DC).clipping_region := (rgn :: maybe(Region))

 

property

property

| (dc :: DC).transformation :: DC.Transformation

| (dc :: DC).transformation := (rgn :: DC.Transformation)

Properties to get or set the drawing context’s configuration.

method

method (dc :: DC).scale(s :: Real) :: Void

 

method

method (dc :: DC).scale(sx :: Real, sy :: Real) :: Void

 

method

method (dc :: DC).translate(dpt :: PointLike) :: Void

 

method

method (dc :: DC).translate(dx :: Real, dy :: Real) :: Void

 

method

method (dc :: DC).rotate(radians :: Real) :: Void

 

method

method (dc :: DC).transform(t :: DC.Transformation) :: Void

Applies a (further) transformation to the drawing context’s conversion from drawing coordinates to deivice coordinates. In other words, these methods change the result that is returned by the DC.transformation property, and they affect drawing accodingly.

method

method (dc :: DC).save() :: Void

 

method

method (dc :: DC).restore() :: Void

 

expression

dot (dc :: DC).save_and_restore:

  body

  ...

Saves and restores the draw context’s configuration.

The DC.save method pushes the current drawing state (pen, brush, clipping region, and transformation) onto an internal stack, and DC.restore pops the stack and restores the popped drawing state. The DC.save_and_restore form wraps a body sequence to save the drawing state on entry to the sequence and restore it on exit, returning the value(s) produced by the body sequence; entry and exit cover continuation jumps, like try.

method

method (dc :: DC).point(pt :: PointLike)

  :: Void

 

method

method (dc :: DC).line(pt1 :: PointLike, pt2 :: PointLike)

  :: Void

 

method

method (dc :: DC).lines([pt :: PointLike, ...],

                        ~dpt: dpt :: PointLike = Point.zero,

                        ~dx: dx :: Real = 0,

                        ~dy: dy :: Real = 0)

  :: Void

 

method

method (dc :: DC).polygon([pt :: PointLike, ...],

                          ~dpt: dpt :: PointLike = Point.zero,

                          ~dx: dx :: Real = 0,

                          ~dy: dy :: Real = 0,

                          ~fill: fill :: DC.Fill = #'even_odd)

  :: Void

 

method

method (dc :: DC).rectangle(r :: RectLike)

  :: Void

 

method

method (dc :: DC).rounded_rectangle(r :: RectLike,

                                    radius :: Real = -0.25)

  :: Void

 

method

method (dc :: DC).ellipse(r :: RectLike)

  :: Void

 

method

method (dc :: DC).arc(r :: RectLike,

                      start :: Real, end :: Real)

  :: Void

 

method

method (dc :: DC).path(p :: Path,

                       ~dpt: dpt :: PointLike = Point.zero,

                       ~dx: dx :: Real = 0,

                       ~dy: dy :: Real = 0,

                       ~fill: fill :: DC.Fill = #'odd_even)

  :: Void

Draws lines into a drawing context using the current pen. In the case of drawing a polygon, rectangle, rounded rectangle, ellipse, or arc, a shape is fulled using the current brush, too.

Offsets through dpt and also dx or dy are combined.

method

method (dc:: DC).text(str :: String,

                      ~dpt: dpt :: PointLike = Point.zero,

                      ~dx: dx :: Real = 0,

                      ~dy: dy :: Real = 0,

                      ~combine: combine :: DC.TextCombine = #'kern,

                      ~angle: angle :: Real = 0.0)

  :: Void

Draws text into a drawing context using the current font.

method

method (dc :: DC).bitmap(

  bm :: Bitmap,

  ~dpt: dpt :: PointLike = Point.zero,

  ~dx: dx :: Real = 0,

  ~dy: dy :: Real = 0,

  ~source: source :: RectLike = Rect(Point.zero, Bitmap.size(bm)),

  ~style: style :: DC.BitmapOverlay = #'solid,

  ~color: color :: Color = Color("black"),

  ~mask: mask :: maybe(Bitmap) = #false,

) :: Void

Draws a region of a bitmap into the drawing context. The default source region is the entire bitmap.

method

method (dc :: DC).copy(source :: RectLike,

                       dest :: PointLike)

  :: Void

Copies a portion of the draw context’s content to another portion of the drawing context. The source and destination regions can overlap.

method

method (dc :: DC).font_metrics_key() :: Any

Returns a value that changes when the selected font is changed to one with different metrics.

Satisfied by the following symbols:

annotation

DC.TextCombine

Satisfied by the following symbols:

annotation

DC.Fill

Satisfied by the following symbols:

Satisfied by an array of six Reals: